📄 transports.cxx
字号:
/* * transports.cxx * * H.323 transports handler * * Open H323 Library * * Copyright (c) 1998-2000 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Open H323 Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions of this code were written with the assisance of funding from * Vovida Networks, Inc. http://www.vovida.com. * * Contributor(s): ______________________________________. * * $Log: transports.cxx,v $ * Revision 1.49 2000/07/10 16:11:49 robertj * Fixed inclusion of interfaces with no IP address in GK registration. * Fixed possible crash when closing connection during H.245 TCP connect wait. * * Revision 1.48 2000/06/20 02:38:28 robertj * Changed H323TransportAddress to default to IP. * * Revision 1.47 2000/06/07 05:48:06 robertj * Added call forwarding. * * Revision 1.46 2000/05/23 02:38:15 robertj * Shortened the linger onTCP close to 3 seconds, should be adequate for lst end session transmit. * * Revision 1.45 2000/05/22 05:21:36 robertj * Fixed race condition where controlChannel variable could be used before set. * * Revision 1.44 2000/05/10 05:14:53 robertj * Fixed memory leak when doing GK discovery. * * Revision 1.43 2000/05/08 14:07:35 robertj * Improved the provision and detection of calling and caller numbers, aliases and hostnames. * * Revision 1.42 2000/05/05 04:37:50 robertj * Changed TCP transmit of PDU to not use Nagle algorithm delay, this gives * a significant performance benefit for packet based stuff on stream based TCP. * * Revision 1.41 2000/05/02 04:32:28 robertj * Fixed copyright notice comment. * * Revision 1.40 2000/04/19 01:59:21 robertj * Improved some debugging messages. * Added code to restore transport state if gatekeeper discovery fails. * * Revision 1.39 2000/04/14 17:32:39 robertj * Changed transport to return some error number when getting malformed TPKT. * * Revision 1.38 2000/04/11 03:57:25 robertj * Fixed uninitialised variabel giving random port numbers for some PDU's (rare). * * Revision 1.37 2000/04/10 17:41:46 robertj * Changed transport address so does not do reverse DNS lookup, can really slow things down on some systems. * * Revision 1.36 2000/03/29 02:14:46 robertj * Changed TerminationReason to CallEndReason to use correct telephony nomenclature. * Added CallEndReason for capability exchange failure. * * Revision 1.35 2000/03/25 02:02:25 robertj * Added adjustable caller name on connection by connection basis. * * Revision 1.34 2000/02/09 00:00:53 robertj * Fixed TCP listener socket error message going to stderr, should go through PTRACE. * * Revision 1.33 2000/01/29 07:13:33 robertj * Fixed possible incorect port being used when GK RAS send address set to the * IP address of the responding GK, thanks Stefan Ditscheid. * * Revision 1.32 2000/01/07 08:24:01 robertj * Added transport independent MakeCall requiring change to transport string format * * Revision 1.31 1999/12/09 21:46:42 robertj * Fixed detection of bound interface in gatekeeper discovery (can't use getsockname!) * * Revision 1.30 1999/12/09 20:25:41 robertj * Changed UDP transport to only do gatekeeper discovery on bound interface (if present) * * Revision 1.29 1999/11/22 00:56:35 robertj * Improved reason display for connection failure. * * Revision 1.28 1999/11/18 12:51:20 robertj * Fixed bug that termination connections incorrectly while awaiting answer. * * Revision 1.27 1999/11/06 05:37:45 robertj * Complete rewrite of termination of connection to avoid numerous race conditions. * * Revision 1.26 1999/10/28 11:17:38 robertj * Fixed bug causing delete of deleted object, thanks Benny Prijono * * Revision 1.25 1999/10/16 03:47:49 robertj * Fixed termination of gatekeeper RAS thread problem * * Revision 1.24 1999/10/14 12:04:11 robertj * Fixed ability to hang up call when still doing TCP connect. * * Revision 1.23 1999/10/13 04:32:41 robertj * Fixed missing port number from gatekeeper discovery. * Added removal of redundent transport listeners in H225 PDU. * * Revision 1.22 1999/10/10 14:12:06 robertj * Fixed failure to clean up connection if call is refused by user. * * Revision 1.21 1999/10/10 08:59:47 robertj * no message * * Revision 1.20 1999/09/27 01:37:23 robertj * BeOS port issues * * Revision 1.19 1999/09/17 07:26:17 robertj * Fixed attempt to broadcast to down interfaces or ones not bound to IP protocol. * * Revision 1.18 1999/09/14 08:19:37 robertj * Fixed timeout on retry of gatekeeper discover and added more tracing. * * Revision 1.17 1999/09/14 06:52:54 robertj * Added better support for multi-homed client hosts. * * Revision 1.16 1999/09/10 09:43:59 robertj * Removed attempt at determining local interface for gatekeeper, so still has problem on multi-homed hosts. * * Revision 1.15 1999/09/02 15:25:39 robertj * Old GNU C ompiler compatibility * * Revision 1.14 1999/08/31 12:34:19 robertj * Added gatekeeper support. * * Revision 1.13 1999/08/31 11:37:30 robertj * Fixed problem with apparently randomly losing signalling channel. * * Revision 1.12 1999/08/25 05:12:23 robertj * Changed MakeCall, so immediately spawns thread, no black on TCP connect. * * Revision 1.11 1999/07/23 02:37:53 robertj * Fixed problems with hang ups and crash closes of connections. * * Revision 1.10 1999/07/22 14:34:16 robertj * Fixed shut down problem, terminate packets being flushed on exit. * * Revision 1.9 1999/07/15 14:45:36 robertj * Added propagation of codec open error to shut down logical channel. * Fixed control channel start up bug introduced with tunnelling. * * Revision 1.8 1999/07/14 06:06:14 robertj * Fixed termination problems (race conditions) with deleting connection object. * * Revision 1.7 1999/07/09 06:09:52 robertj * Major implementation. An ENORMOUS amount of stuff added everywhere. * * Revision 1.6 1999/06/25 10:25:35 robertj * Added maintentance of callIdentifier variable in H.225 channel. * * Revision 1.5 1999/06/22 13:42:05 robertj * Added user question on listener version to accept incoming calls. * * Revision 1.4 1999/06/14 08:42:30 robertj * GNU C++ compatibility * * Revision 1.3 1999/06/13 12:41:14 robertj * Implement logical channel transmitter. * Fixed H245 connect on receiving call. * * Revision 1.2 1999/06/09 06:18:01 robertj * GCC compatibiltiy. * * Revision 1.1 1999/06/09 05:26:20 robertj * Major restructuring of classes. * */#include <ptlib.h>#include "h323.h"#include "h323pdu.h"class H225TransportThread : public PThread{ PCLASSINFO(H225TransportThread, PThread) public: H225TransportThread(H323EndPoint & endpoint, H323Transport & transport); protected: void Main(); H323Transport & transport;};class H245TransportThread : public PThread{ PCLASSINFO(H245TransportThread, PThread) public: H245TransportThread(H323EndPoint & endpoint, H323Connection & connection, H323Transport & transport); protected: void Main(); H323Connection & connection; H323Transport & transport;};#define new PNEW/////////////////////////////////////////////////////////////////////////////H225TransportThread::H225TransportThread(H323EndPoint & endpoint, H323Transport & t) : PThread(endpoint.GetSignallingThreadStackSize(), NoAutoDeleteThread), transport(t){ transport.AttachThread(this); Resume();}void H225TransportThread::Main(){ PTRACE(3, "H225\tStarted accept thread"); H323Connection * connection = transport.HandleFirstSignallingChannelPDU(); if (connection != NULL) connection->HandleSignallingChannel();}/////////////////////////////////////////////////////////////////////////////H245TransportThread::H245TransportThread(H323EndPoint & endpoint, H323Connection & c, H323Transport & t) : PThread(endpoint.GetSignallingThreadStackSize(), NoAutoDeleteThread), connection(c), transport(t){ transport.AttachThread(this); Resume();}void H245TransportThread::Main(){ PTRACE(3, "H245\tStarted thread"); if (transport.AcceptControlChannel(connection)) connection.HandleControlChannel();}/////////////////////////////////////////////////////////////////////////////static const char IpPrefix[] = "ip$";H323TransportAddress::H323TransportAddress(const char * cstr) : PString(cstr){ Validate();}H323TransportAddress::H323TransportAddress(const PString & str) : PString(str){ Validate();}H323TransportAddress::H323TransportAddress(const H225_TransportAddress & transport){ switch (transport.GetTag()) { case H225_TransportAddress::e_ipAddress : { const H225_TransportAddress_ipAddress & ip = transport; sprintf("%s%u.%u.%u.%u:%u", IpPrefix, ip.m_ip[0], ip.m_ip[1], ip.m_ip[2], ip.m_ip[3], (unsigned)ip.m_port); break; } }}H323TransportAddress::H323TransportAddress(const H245_TransportAddress & transport){ switch (transport.GetTag()) { case H245_TransportAddress::e_unicastAddress : { const H245_UnicastAddress & unicast = transport; switch (transport.GetTag()) { case H245_UnicastAddress::e_iPAddress : { const H245_UnicastAddress_iPAddress & ip = unicast; sprintf("%s%u.%u.%u.%u:%u", IpPrefix, ip.m_network[0], ip.m_network[1], ip.m_network[2], ip.m_network[3], (unsigned)ip.m_tsapIdentifier); break; } } break; } }}H323TransportAddress::H323TransportAddress(const PIPSocket::Address & ip, WORD port) : PString(IpPrefix){ *this += ip.AsString(); if (port != 0) sprintf(":%u", port);}void H323TransportAddress::Validate(){ if (IsEmpty()) return; if (Find('$') == P_MAX_INDEX) { Splice(IpPrefix, 0, 0); return; } if (strncmp(theArray, IpPrefix, 3) == 0) { return; } *this = PString();}BOOL H323TransportAddress::SetPDU(H225_TransportAddress & pdu) const{ PIPSocket::Address ip; WORD port = H323ListenerTCP::DefaultSignalPort; if (GetIpAndPort(ip, port)) { pdu.SetTag(H225_TransportAddress::e_ipAddress); H225_TransportAddress_ipAddress & addr = pdu; for (PINDEX i = 0; i < 4; i++) addr.m_ip[i] = ip[i]; addr.m_port = port; return TRUE; } return FALSE;}BOOL H323TransportAddress::SetPDU(H245_TransportAddress & pdu) const{ PIPSocket::Address ip; WORD port = 0; if (GetIpAndPort(ip, port)) { pdu.SetTag(H245_TransportAddress::e_unicastAddress); H245_UnicastAddress & unicast = pdu; unicast.SetTag(H245_UnicastAddress::e_iPAddress); H245_UnicastAddress_iPAddress & addr = unicast; for (PINDEX i = 0; i < 4; i++) addr.m_network[i] = ip[i]; addr.m_tsapIdentifier = port; return TRUE; } return FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -