diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-19 00:19:29 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-01-19 00:19:29 +0000 |
commit | f8247040e6231c4b3b5099ea3a526348b7941566 (patch) | |
tree | 0cc92ad6ebf6ae49a62f6e7ef8ec819121d63630 /trunk/channels/h323/compat_h323.cxx | |
parent | d88e56c61ce2042544c1a8a71c93b69ab2e6ffba (diff) |
Creating tag for the release of asterisk-1.6.0-beta1v1.6.0-beta1
git-svn-id: http://svn.digium.com/svn/asterisk/tags/1.6.0-beta1@99163 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'trunk/channels/h323/compat_h323.cxx')
-rw-r--r-- | trunk/channels/h323/compat_h323.cxx | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/trunk/channels/h323/compat_h323.cxx b/trunk/channels/h323/compat_h323.cxx new file mode 100644 index 000000000..eec7361b2 --- /dev/null +++ b/trunk/channels/h323/compat_h323.cxx @@ -0,0 +1,138 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +/* + * ast_h323.cpp + * + * OpenH323 Channel Driver for ASTERISK PBX. + * By Jeremy McNamara + * For The NuFone Network + * + * chan_h323 has been derived from code created by + * Michael Manousos and Mark Spencer + * + * This file is part of the chan_h323 driver for Asterisk + * + * chan_h323 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * chan_h323 is distributed WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Version Info: $Id$ + */ +#include <ptlib.h> +#include <h323.h> +#include <transports.h> + +#include "ast_h323.h" + +#if VERSION(OPENH323_MAJOR,OPENH323_MINOR,OPENH323_BUILD) < VERSION(1,17,3) +MyH323TransportTCP::MyH323TransportTCP( + H323EndPoint & endpoint, + PIPSocket::Address binding, + BOOL listen) + : H323TransportTCP(endpoint, binding, listen) +{ +} + +BOOL MyH323TransportTCP::Connect() +{ + if (IsListening()) + return TRUE; + + PTCPSocket * socket = new PTCPSocket(remotePort); + Open(socket); + + channelPointerMutex.StartRead(); + + socket->SetReadTimeout(10000/*endpoint.GetSignallingChannelConnectTimeout()*/); + + localPort = endpoint.GetNextTCPPort(); + WORD firstPort = localPort; + for (;;) { + PTRACE(4, "H323TCP\tConnecting to " + << remoteAddress << ':' << remotePort + << " (local port=" << localPort << ')'); + if (socket->Connect(localAddress, localPort, remoteAddress)) + break; + + int errnum = socket->GetErrorNumber(); + if (localPort == 0 || (errnum != EADDRINUSE && errnum != EADDRNOTAVAIL)) { + PTRACE(1, "H323TCP\tCould not connect to " + << remoteAddress << ':' << remotePort + << " (local port=" << localPort << ") - " + << socket->GetErrorText() << '(' << errnum << ')'); + channelPointerMutex.EndRead(); + return SetErrorValues(socket->GetErrorCode(), errnum); + } + + localPort = endpoint.GetNextTCPPort(); + if (localPort == firstPort) { + PTRACE(1, "H323TCP\tCould not bind to any port in range " << + endpoint.GetTCPPortBase() << " to " << endpoint.GetTCPPortMax()); + channelPointerMutex.EndRead(); + return SetErrorValues(socket->GetErrorCode(), errnum); + } + } + + socket->SetReadTimeout(PMaxTimeInterval); + + channelPointerMutex.EndRead(); + + return OnOpen(); +} +#endif + +BOOL MyH323TransportUDP::DiscoverGatekeeper(H323Gatekeeper &gk, H323RasPDU &pdu, const H323TransportAddress &address) +{ + PThread *thd = PThread::Current(); + + /* If we run in OpenH323's thread use it instead of creating new one */ + if (thd) + return H323TransportUDP::DiscoverGatekeeper(gk, pdu, address); + + /* Make copy of arguments to pass them into thread */ + discoverGatekeeper = &gk; + discoverPDU = &pdu; + discoverAddress = &address; + + /* Assume discovery thread isn't finished */ + discoverReady = FALSE; + + /* Create discovery thread */ + thd = PThread::Create(PCREATE_NOTIFIER(DiscoverMain), 0, + PThread::NoAutoDeleteThread, + PThread::NormalPriority, + "GkDiscovery:%x"); + + /* Wait until discovery thread signal us its finished */ + for(;;) { + discoverMutex.Wait(); + if (discoverReady) /* Thread has been finished */ + break; + discoverMutex.Signal(); + } + discoverMutex.Signal(); + + /* Cleanup/delete thread */ + thd->WaitForTermination(); + delete thd; + + return discoverResult; +} + +void MyH323TransportUDP::DiscoverMain(PThread &thread, INT arg) +{ + PWaitAndSignal m(discoverMutex); + + discoverResult = H323TransportUDP::DiscoverGatekeeper(*discoverGatekeeper, *discoverPDU, *discoverAddress); + discoverReady = TRUE; +} |