From 3786b22abe95b0bf3bba4d4dd894d9268fcfe8be Mon Sep 17 00:00:00 2001 From: paulc Date: Thu, 30 Mar 2006 00:21:37 +0000 Subject: [PATCH] Fixes in Windows git-svn-id: http://voip.null.ro/svn/yate@730 acf43c95-373e-0410-b603-e72c3f656dc1 --- ChangeLog | 2 ++ engine/Socket.cpp | 6 +++++- modules/conference.cpp | 8 ++++---- modules/extmodule.cpp | 35 ++++++++++++++++++++++++++++++----- modules/wpchan.cpp | 4 ++-- modules/wpchanw.cpp | 38 +++++++++++++++++++++----------------- modules/yradius.cpp | 6 +++--- windows/YATE.dsw | 21 +++++++++++++++++++++ yateclass.h | 1 + 9 files changed, 89 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9dcf417f..869479d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ Thu Mar 30 2006 Paul Chitescu - Added many options that can be set per external module instance - Updated the PHP libraries to support the new functions - Changed the return values of GetEvent() to comply with typechecks in PHP5 +- Added extmodule and yradius to the Visual C++ workspace +- Made some fixes for Windows, solved some bugs exposed by the compiler Wed Mar 29 2006 Paul Chitescu - Modified conference based on Andrew McDonald's idea of N-way mixing diff --git a/engine/Socket.cpp b/engine/Socket.cpp index 3ce0bb35..e3c4849f 100644 --- a/engine/Socket.cpp +++ b/engine/Socket.cpp @@ -436,7 +436,11 @@ bool File::canRetry() const { if (!m_error) return true; - return (m_error == EAGAIN) || (m_error == EINTR) || (m_error == EWOULDBLOCK); + return (m_error == EAGAIN) || (m_error == EINTR) +#ifndef _WINDOWS + || (m_error == EWOULDBLOCK) +#endif + ; } bool File::setBlocking(bool block) diff --git a/modules/conference.cpp b/modules/conference.cpp index c67ecf54..67448dbe 100644 --- a/modules/conference.cpp +++ b/modules/conference.cpp @@ -236,7 +236,7 @@ ConfRoom::ConfRoom(const String& name, const NamedList& params) m_rate = params.getIntValue("rate",m_rate); m_maxusers = params.getIntValue("maxusers",m_maxusers); m_notify = params.getValue("notify"); - m_lonely = params.getValue("lonely"); + m_lonely = params.getBoolValue("lonely"); s_rooms.append(this); // create outgoing call to room record utility channel const char* callto = params.getValue("record"); @@ -422,9 +422,9 @@ void ConfConsumer::Consume(const DataBlock& data, unsigned long tStamp) // use square of the energy as extracting the square root is expensive sum2 = (sum2 * DECAY_STORE + (int64_t)(samp*samp) * ATTACK_RATE) / DECAY_TOTAL; if (min2 > sum2) - min2 = sum2; + min2 = (unsigned int)sum2; } - m_energy2 = sum2; + m_energy2 = (unsigned int)sum2; // TODO: find a better algorithm to adjust the noise threshold min2 += min2 >> SHIFT_LEVEL; // try to keep noise threshold slightly above minimum energy @@ -468,7 +468,7 @@ void ConfConsumer::consumed(const int* mixed, unsigned int samples) int64_t sum2 = m_energy2; while (n--) sum2 = (sum2 * DECAY_STORE) / DECAY_TOTAL; - m_energy2 = sum2; + m_energy2 = (unsigned int)sum2; } return; } diff --git a/modules/extmodule.cpp b/modules/extmodule.cpp index ae6c9bf0..38b8d717 100644 --- a/modules/extmodule.cpp +++ b/modules/extmodule.cpp @@ -24,10 +24,18 @@ */ #include + +#ifdef _WINDOWS + +#include + +#else #include #include #include +#endif + #include #include #include @@ -280,9 +288,16 @@ private: static bool runProgram(const char *script, const char *args) { +#ifdef _WINDOWS + int pid = ::_spawnl(_P_DETACH,script,args,NULL); + if (pid < 0) { + Debug(DebugWarn, "Failed to _spawnl(): %d: %s", errno, strerror(errno)); + return false; + } +#else int pid = ::fork(); if (pid < 0) { - Debug(DebugWarn, "Failed to fork(): %s", strerror(errno)); + Debug(DebugWarn, "Failed to fork(): %d: %s", errno, strerror(errno)); return false; } if (!pid) { @@ -291,6 +306,7 @@ static bool runProgram(const char *script, const char *args) // Try to immunize child from ^C and ^\ the console may receive ::signal(SIGINT,SIG_IGN); ::signal(SIGQUIT,SIG_IGN); + // And restore default handlers for other signals ::signal(SIGTERM,SIG_DFL); ::signal(SIGHUP,SIG_DFL); @@ -301,10 +317,11 @@ static bool runProgram(const char *script, const char *args) if (debugAt(DebugInfo)) ::fprintf(stderr, "Execing program '%s' '%s'\n", script, args); ::execl(script, script, args, (char *)NULL); - ::fprintf(stderr, "Failed to execute '%s': %s\n", script, strerror(errno)); + ::fprintf(stderr, "Failed to execute '%s': %d: %s\n", script, errno, strerror(errno)); // Shit happened. Die as quick and brutal as possible ::_exit(1); } +#endif Debug(DebugInfo,"Launched external program %s", script); return true; } @@ -353,7 +370,7 @@ void ExtModSource::run() int64_t dly = tpos - Time::now(); if (dly > 0) { XDebug("ExtModSource",DebugAll,"Sleeping for " FMT64 " usec",dly); - Thread::usleep(dly); + Thread::usleep((unsigned long)dly); } if (r <= 0) continue; @@ -361,7 +378,7 @@ void ExtModSource::run() Forward(buf,m_total/2); buf.clear(false); m_total += r; - tpos += (r*1000000ULL/m_brate); + tpos += (r*(u_int64_t)1000000/m_brate); } while (r > 0); Debug(DebugAll,"ExtModSource [%p] end of data total=%u",this,m_total); m_chan->setRunning(false); @@ -763,8 +780,10 @@ void ExtModReceiver::die(bool clearChan) // Now terminate the process and close its stdout pipe closeIn(); +#ifndef _WINDOWS if (m_pid > 0) ::kill(m_pid,SIGTERM); +#endif if (chan && clearChan) chan->disconnect(); unuse(); @@ -806,7 +825,7 @@ bool ExtModReceiver::received(Message &msg, int id) while (ok) { Thread::yield(); lock(); - ok = m_waiting.find(&h); + ok = (m_waiting.find(&h) != 0); if (ok && tout && (Time::now() > tout)) { Debug(DebugWarn,"Message '%s' did not return in %d msec [%p]", msg.c_str(),m_timeout,this); @@ -825,6 +844,9 @@ bool ExtModReceiver::received(Message &msg, int id) bool ExtModReceiver::create(const char *script, const char *args) { +#ifdef _WINDOWS + return false; +#else String tmp(script); int pid; HANDLE ext2yate[2]; @@ -898,6 +920,7 @@ bool ExtModReceiver::create(const char *script, const char *args) closeAudio(); m_pid = pid; return true; +#endif } void ExtModReceiver::cleanup() @@ -905,6 +928,7 @@ void ExtModReceiver::cleanup() #ifdef DEBUG Debugger debug(DebugAll,"ExtModReceiver::cleanup()"," [%p]",this); #endif +#ifndef _WINDOWS // We must call waitpid from here - same thread we started the child if (m_pid > 0) { // No thread switching if possible @@ -923,6 +947,7 @@ void ExtModReceiver::cleanup() Debug(DebugMild,"Failed waitpid on %d: %s",m_pid,strerror(errno)); m_pid = 0; } +#endif unuse(); } diff --git a/modules/wpchan.cpp b/modules/wpchan.cpp index edc90109..f24b21dc 100644 --- a/modules/wpchan.cpp +++ b/modules/wpchan.cpp @@ -359,8 +359,8 @@ WpData::WpData(WpSpan* span, const char* card, const char* device, Configuration m_samples = cfg.getIntValue("general","samples",m_samples); m_samples = cfg.getIntValue(sect,"samples",m_samples); - m_swap = cfg.getIntValue("general","bitswap",m_swap); - m_swap = cfg.getIntValue(sect,"bitswap",m_swap); + m_swap = cfg.getBoolValue("general","bitswap",m_swap); + m_swap = cfg.getBoolValue(sect,"bitswap",m_swap); } WpData::~WpData() diff --git a/modules/wpchanw.cpp b/modules/wpchanw.cpp index 2b7f6c37..fa015086 100644 --- a/modules/wpchanw.cpp +++ b/modules/wpchanw.cpp @@ -1,8 +1,8 @@ /** - * wpchan.cpp + * wpchanw.cpp * This file is part of the YATE Project http://YATE.null.ro * - * Wanpipe PRI cards telephony driver + * Wanpipe PRI cards telephony driver for Windows * * Yet Another Telephony Engine - a fully featured software PBX and IVR * Copyright (C) 2004, 2005 Null Team @@ -115,13 +115,14 @@ private: class WpData : public Thread { public: - WpData(WpSpan* span, const char* card, const char* device, Thread::Priority prio); + WpData(WpSpan* span, const char* card, const char* device, Configuration& cfg, const String& sect); ~WpData(); virtual void run(); private: WpSpan* m_span; HANDLE m_fd; WpChan **m_chans; + bool m_swap; }; class WpReader : public Thread @@ -165,6 +166,14 @@ INIT_PLUGIN(WpDriver); #define WP_BUFFER 8188 // maximum length of data = 8K - 4 +static Thread::Priority cfgPriority(Configuration& cfg, const String& sect) +{ + String tmp(cfg.getValue(sect,"thread")); + if (tmp.null()) + tmp = cfg.getValue("general","thread"); + return Thread::priority(tmp); +} + static void dump_buffer(const void* buf, int len) { String s; @@ -435,15 +444,17 @@ void WpConsumer::Consume(const DataBlock &data, unsigned long tStamp) -WpData::WpData(WpSpan* span, const char* card, const char* device, Thread::Priority prio) - : Thread("WpData",prio), m_span(span), m_fd(INVALID_HANDLE_VALUE), m_chans(0) +WpData::WpData(WpSpan* span, const char* card, const char* device, Configuration& cfg, const String& sect) + : Thread("WpData",cfgPriority(cfg,sect)), m_span(span), m_fd(INVALID_HANDLE_VALUE), m_chans(0), m_swap(true) { - DDebug(&__plugin,DebugAll,"WpData::WpData(%p) [%p]",span,this); + DDebug(&__plugin,DebugAll,"WpData::WpData(%p,'%s','%s') [%p]",span,card,device,this); HANDLE fd = wp_open(card,device); if (fd != INVALID_HANDLE_VALUE) { m_fd = fd; m_span->m_data = this; } + m_swap = cfg.getBoolValue("general","bitswap",m_swap); + m_swap = cfg.getBoolValue(sect,"bitswap",m_swap); } WpData::~WpData() @@ -491,7 +502,7 @@ void WpData::run() for (b = 0; b < bchans; b++) { WpSource *s = m_chans[b]->m_wp_s; if (s) - s->put(PriDriver::bitswap(*dat)); + s->put(m_swap ? PriDriver::bitswap(*dat) : *dat); dat++; } } @@ -508,7 +519,8 @@ void WpData::run() for (int n = samp; n > 0; n--) { for (b = 0; b < bchans; b++) { WpConsumer *c = m_chans[b]->m_wp_c; - *dat++ = PriDriver::bitswap(c ? c->get() : 0xff); + unsigned char d = c ? c->get() : 0xff; + *dat++ = m_swap ? PriDriver::bitswap(d) : d; } } m_span->unlock(); @@ -551,14 +563,6 @@ bool WpChan::openData(const char* format, int echoTaps) return true; } -static Thread::Priority cfgPriority(Configuration& cfg, const String& sect) -{ - String tmp(cfg.getValue(sect,"thread")); - if (tmp.null()) - tmp = cfg.getValue("general","thread"); - return Thread::priority(tmp); -} - PriSpan* WpDriver::createSpan(PriDriver* driver, int span, int first, int chans, Configuration& cfg, const String& sect) { @@ -579,7 +583,7 @@ PriSpan* WpDriver::createSpan(PriDriver* driver, int span, int first, int chans, WpWriter* wr = new WpWriter(ps,card,dev); WpReader* rd = new WpReader(ps,card,dev); dev = cfg.getValue(sect,"bgroup","IF1"); - WpData* dat = new WpData(ps,card,dev,cfgPriority(cfg,sect)); + WpData* dat = new WpData(ps,card,dev,cfg,sect); wr->startup(); rd->startup(); dat->startup(); diff --git a/modules/yradius.cpp b/modules/yradius.cpp index 0c9beb20..74f10be0 100644 --- a/modules/yradius.cpp +++ b/modules/yradius.cpp @@ -271,7 +271,7 @@ public: bool packTo(DataBlock& data) const; bool getString(String& retval) const; inline bool isValid() const - { return m_type; } + { return (m_type != 0); } inline bool isVendor() const { return (m_type && (m_type->code == 26)) && (m_vendor == 0); } inline int vendor() const @@ -738,7 +738,7 @@ bool RadAttrib::getString(String& retval) const } break; case a_int: - retval = ntohl(*(int32_t*)m_value.data()); + retval = (int)ntohl(*(int32_t*)m_value.data()); break; default: return false; @@ -747,7 +747,7 @@ bool RadAttrib::getString(String& retval) const } -unsigned char RadiusClient::s_sessionId = (Time::now() & 0xff); +unsigned char RadiusClient::s_sessionId = (unsigned char)(Time::now() & 0xff); RadiusClient::~RadiusClient() { diff --git a/windows/YATE.dsw b/windows/YATE.dsw index 3001c613..e07c7ec9 100644 --- a/windows/YATE.dsw +++ b/windows/YATE.dsw @@ -194,6 +194,12 @@ Package=<4> Begin Project Dependency Project_Dep_Name _dbpbx End Project Dependency + Begin Project Dependency + Project_Dep_Name _yradius + End Project Dependency + Begin Project Dependency + Project_Dep_Name _extmodule + End Project Dependency }}} ############################################################################### @@ -582,6 +588,21 @@ Package=<4> ############################################################################### +Project: "_yradius"=.\_yradius.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name Libyate + End Project Dependency +}}} + +############################################################################### + Project: "_yrtpchan"=.\_yrtpchan.dsp - Package Owner=<4> Package=<5> diff --git a/yateclass.h b/yateclass.h index b45d6e6e..545ad63d 100644 --- a/yateclass.h +++ b/yateclass.h @@ -72,6 +72,7 @@ typedef signed __int64 int64_t; typedef unsigned __int64 u_int64_t; typedef unsigned __int64 uint64_t; +typedef int pid_t; typedef int socklen_t; typedef unsigned long in_addr_t;