transports.h

Go to the documentation of this file.
00001 /*
00002  * transports.h
00003  *
00004  * H.323 protocol handler
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1998-2000 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions of this code were written with the assisance of funding from
00025  * Vovida Networks, Inc. http://www.vovida.com.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Log: transports.h,v $
00030  * Revision 1.48  2005/11/30 13:05:01  csoutheren
00031  * Changed tags for Doxygen
00032  *
00033  * Revision 1.47  2005/11/21 21:07:41  shorne
00034  * Added GnuGK Nat support
00035  *
00036  * Revision 1.46  2005/01/16 20:39:43  csoutheren
00037  * Fixed problem with IPv6 INADDR_ANY
00038  *
00039  * Revision 1.45  2004/08/24 08:11:25  csoutheren
00040  * Added initial support for receiving broadcasts on Linux
00041  *
00042  * Revision 1.44  2004/05/13 02:26:13  dereksmithies
00043  * Fixes so make docs does not generate warning messages about brackets.
00044  *
00045  * Revision 1.43  2003/12/29 13:28:45  dominance
00046  * fixed docbook syntax trying to generate LaTeX formula with ip$10.x.x.x.
00047  *
00048  * Revision 1.42  2003/04/10 09:44:55  robertj
00049  * Added associated transport to new GetInterfaceAddresses() function so
00050  *   interfaces can be ordered according to active transport links. Improves
00051  *   interoperability.
00052  * Replaced old listener GetTransportPDU() with GetInterfaceAddresses()
00053  *   and H323SetTransportAddresses() functions.
00054  *
00055  * Revision 1.41  2003/04/10 01:03:25  craigs
00056  * Added functions to access to lists of interfaces
00057  *
00058  * Revision 1.40  2003/03/21 05:24:02  robertj
00059  * Added setting of remote port in UDP transport constructor.
00060  *
00061  * Revision 1.39  2003/02/06 04:29:23  robertj
00062  * Added more support for adding things to H323TransportAddressArrays
00063  *
00064  * Revision 1.38  2002/11/21 06:39:56  robertj
00065  * Changed promiscuous mode to be three way. Fixes race condition in gkserver
00066  *   which can cause crashes or more PDUs to be sent to the wrong place.
00067  *
00068  * Revision 1.37  2002/11/10 08:10:43  robertj
00069  * Moved constants for "well known" ports to better place (OPAL change).
00070  *
00071  * Revision 1.36  2002/09/16 01:14:15  robertj
00072  * Added #define so can select if #pragma interface/implementation is used on
00073  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00074  *
00075  * Revision 1.35  2002/07/22 09:40:15  robertj
00076  * Added ability to automatically convert string arrays, lists sorted lists
00077  *   directly to H323TransportAddressArray.
00078  *
00079  * Revision 1.34  2002/07/02 10:02:29  robertj
00080  * Added H323TransportAddress::GetIpAddress() so don't have to provide port
00081  *   when you don't need it as in GetIpAndPort(),.
00082  *
00083  * Revision 1.33  2002/06/28 03:34:25  robertj
00084  * Fixed issues with address translation on gatekeeper RAS channel.
00085  *
00086  * Revision 1.32  2002/06/12 03:51:59  robertj
00087  * Added function to compare two transport addresses in a more intelligent
00088  *   way that strict string comparison. Takes into account wildcarding.
00089  *
00090  * Revision 1.31  2002/02/11 04:20:25  robertj
00091  * Fixed documentation errors, thanks Horacio J. Peņa
00092  *
00093  * Revision 1.30  2002/02/05 23:29:23  robertj
00094  * Changed default for H.323 listener to reuse addresses.
00095  *
00096  * Revision 1.29  2001/12/22 01:48:12  robertj
00097  * Added ability to use local and remote port from transport channel as well
00098  *   as explicit port in H.245 address PDU setting routine.
00099  * Added PrintOn() to listener and transport for tracing purposes.
00100  *
00101  * Revision 1.28  2001/07/17 04:44:29  robertj
00102  * Partial implementation of T.120 and T.38 logical channels.
00103  *
00104  * Revision 1.27  2001/06/25 02:30:46  robertj
00105  * Allowed TCP listener socket to be opened in non-exclusive mode
00106  *   (ie SO_REUSEADDR) to avoid daemon restart problems.
00107  *
00108  * Revision 1.26  2001/06/22 00:14:14  robertj
00109  * Added ConnectTo() function to conencto specific address.
00110  * Added promiscuous mode for UDP channel.
00111  *
00112  * Revision 1.25  2001/05/17 06:37:02  robertj
00113  * Added multicast gatekeeper discovery support.
00114  *
00115  * Revision 1.24  2001/04/09 08:43:39  robertj
00116  * Added ability to get transport address for a listener.
00117  *
00118  * Revision 1.23  2001/03/02 06:59:57  robertj
00119  * Enhanced the globally unique identifier class.
00120  *
00121  * Revision 1.22  2001/02/09 05:16:24  robertj
00122  * Added #pragma interface for GNU C++.
00123  *
00124  * Revision 1.21  2001/01/23 05:08:04  robertj
00125  * Fixed bug when trying to clear call while waiting on H.245 channel connect, thanks Yura Aksyonov.
00126  *
00127  * Revision 1.20  2000/10/20 06:18:58  robertj
00128  * Fixed very small race condition on creating new connectionon incoming call.
00129  * Fixed memory/socket leak if do TCP connect and don't send valid setup PDU.
00130  *
00131  * Revision 1.19  2000/10/04 05:59:09  robertj
00132  * Minor reorganisation of the H.245 secondary channel start up to make it simpler
00133  *    to override its behaviour.
00134  *
00135  * Revision 1.18  2000/09/25 12:59:16  robertj
00136  * Added StartListener() function that takes a H323TransportAddress to start
00137  *     listeners bound to specific interfaces.
00138  *
00139  * Revision 1.17  2000/09/22 01:35:03  robertj
00140  * Added support for handling LID's that only do symmetric codecs.
00141  *
00142  * Revision 1.16  2000/06/07 05:47:55  robertj
00143  * Added call forwarding.
00144  *
00145  * Revision 1.15  2000/05/22 05:21:36  robertj
00146  * Fixed race condition where controlChannel variable could be used before set.
00147  *
00148  * Revision 1.14  2000/05/18 11:53:34  robertj
00149  * Changes to support doc++ documentation generation.
00150  *
00151  * Revision 1.13  2000/05/08 14:07:26  robertj
00152  * Improved the provision and detection of calling and caller numbers, aliases and hostnames.
00153  *
00154  * Revision 1.12  2000/05/02 04:32:25  robertj
00155  * Fixed copyright notice comment.
00156  *
00157  * Revision 1.11  1999/11/06 05:37:44  robertj
00158  * Complete rewrite of termination of connection to avoid numerous race conditions.
00159  *
00160  * Revision 1.10  1999/10/16 03:47:57  robertj
00161  * Fixed termination of gatekeeper RAS thread problem
00162  *
00163  * Revision 1.9  1999/10/10 08:59:47  robertj
00164  * Fixed race condition in connection shutdown
00165  *
00166  * Revision 1.8  1999/09/14 06:52:54  robertj
00167  * Added better support for multi-homed client hosts.
00168  *
00169  * Revision 1.7  1999/09/10 09:43:59  robertj
00170  * Removed attempt at determining local interface for gatekeeper, so still has problem on multi-homed hosts.
00171  *
00172  * Revision 1.6  1999/08/31 12:34:18  robertj
00173  * Added gatekeeper support.
00174  *
00175  * Revision 1.5  1999/08/25 05:14:21  robertj
00176  * Fixed problem with calling modal dialog from a background thread.
00177  *
00178  * Revision 1.4  1999/07/14 06:06:14  robertj
00179  * Fixed termination problems (race conditions) with deleting connection object.
00180  *
00181  * Revision 1.3  1999/07/09 06:09:49  robertj
00182  * Major implementation. An ENORMOUS amount of stuff added everywhere.
00183  *
00184  * Revision 1.2  1999/06/13 12:41:14  robertj
00185  * Implement logical channel transmitter.
00186  * Fixed H245 connect on receiving call.
00187  *
00188  * Revision 1.1  1999/06/09 05:26:20  robertj
00189  * Major restructuring of classes.
00190  *
00191  */
00192 
00193 #ifndef __TRANSPORTS_H
00194 #define __TRANSPORTS_H
00195 
00196 #ifdef P_USE_PRAGMA
00197 #pragma interface
00198 #endif
00199 
00200 
00201 #include <ptlib/sockets.h>
00202 
00203 
00204 class H225_Setup_UUIE;
00205 class H225_TransportAddress;
00206 class H225_ArrayOf_TransportAddress;
00207 class H225_TransportAddress_ipAddress;
00208 
00209 class H245_TransportAddress;
00210 
00211 class H323SignalPDU;
00212 class H323RasPDU;
00213 class H323EndPoint;
00214 class H323Connection;
00215 class H323Listener;
00216 class H323Transport;
00217 class H323Gatekeeper;
00218 
00219 
00220 
00222 
00226 class H323TransportAddress : public PString
00227 {
00228   PCLASSINFO(H323TransportAddress, PString);
00229   public:
00230     H323TransportAddress() { }
00231     H323TransportAddress(const char *);
00232     H323TransportAddress(const PString &);
00233     H323TransportAddress(const H225_TransportAddress &);
00234     H323TransportAddress(const H245_TransportAddress &);
00235     H323TransportAddress(const PIPSocket::Address &, WORD);
00236 
00237     BOOL SetPDU(H225_TransportAddress & pdu) const;
00238     BOOL SetPDU(H245_TransportAddress & pdu) const;
00239 
00242     BOOL IsEquivalent(
00243       const H323TransportAddress & address
00244     );
00245 
00249     BOOL GetIpAddress(
00250       PIPSocket::Address & ip
00251     ) const;
00252 
00256     BOOL GetIpAndPort(
00257       PIPSocket::Address & ip,
00258       WORD & port,
00259       const char * proto = "tcp"
00260     ) const;
00261 
00265     PString GetHostName() const;
00266 
00277     H323Listener * CreateListener(
00278       H323EndPoint & endpoint   
00279     ) const;
00280 
00287     H323Listener * CreateCompatibleListener(
00288       H323EndPoint & endpoint   
00289     ) const;
00290 
00293     H323Transport * CreateTransport(
00294       H323EndPoint & endpoint   
00295     ) const;
00296 
00297   protected:
00298     void Validate();
00299 };
00300 
00301 
00302 PDECLARE_ARRAY(H323TransportAddressArray, H323TransportAddress)
00303 #ifdef DOC_PLUS_PLUS
00304 {
00305 #endif
00306   public:
00307     H323TransportAddressArray(
00308       const H323TransportAddress & address
00309     ) { AppendAddress(address); }
00310     H323TransportAddressArray(
00311       const H225_ArrayOf_TransportAddress & addresses
00312     );
00313     H323TransportAddressArray(
00314       const PStringArray & array
00315     ) { AppendStringCollection(array); }
00316     H323TransportAddressArray(
00317       const PStringList & list
00318     ) { AppendStringCollection(list); }
00319     H323TransportAddressArray(
00320       const PSortedStringList & list
00321     ) { AppendStringCollection(list); }
00322 
00323     void AppendString(
00324       const char * address
00325     );
00326     void AppendString(
00327       const PString & address
00328     );
00329     void AppendAddress(
00330       const H323TransportAddress & address
00331     );
00332 
00333   protected:
00334     void AppendStringCollection(
00335       const PCollection & coll
00336     );
00337 };
00338 
00339 
00352 class H323Listener : public PThread
00353 {
00354   PCLASSINFO(H323Listener, PThread);
00355 
00356   public:
00361     H323Listener(
00362       H323EndPoint & endpoint      
00363     );
00365 
00368     virtual void PrintOn(
00369       ostream & strm
00370     ) const;
00372 
00377     virtual BOOL Open() = 0;
00378 
00381     virtual BOOL Close() = 0;
00382 
00385     virtual H323Transport * Accept(
00386       const PTimeInterval & timeout  
00387     ) = 0;
00388 
00391     virtual H323TransportAddress GetTransportAddress() const = 0;
00392 
00395     virtual BOOL SetUpTransportPDU(
00396       H245_TransportAddress & pdu,         
00397       const H323Transport & associatedTransport 
00398     ) = 0;
00400 
00401   protected:
00402     H323EndPoint & endpoint;  
00403 };
00404 
00405 
00406 PLIST(H323ListenerList, H323Listener);
00407 
00408 
00411 H323TransportAddressArray H323GetInterfaceAddresses(
00412   const H323ListenerList & listeners, 
00413   BOOL excludeLocalHost = TRUE,       
00414   H323Transport * associatedTransport = NULL
00416 );
00417 
00418 H323TransportAddressArray H323GetInterfaceAddresses(
00419   const H323TransportAddress & addr,  
00420   BOOL excludeLocalHost = TRUE,       
00421   H323Transport * associatedTransport = NULL
00423 );
00424 
00427 void H323SetTransportAddresses(
00428   const H323Transport & associatedTransport,   
00429   const H323TransportAddressArray & addresses, 
00430   H225_ArrayOf_TransportAddress & pdu          
00431 );
00432 
00433 
00438 class H323Transport : public PIndirectChannel
00439 {
00440   PCLASSINFO(H323Transport, PIndirectChannel);
00441 
00442   public:
00447     H323Transport(H323EndPoint & endpoint);
00448     ~H323Transport();
00450 
00453     virtual void PrintOn(
00454       ostream & strm
00455     ) const;
00457 
00462     virtual H323TransportAddress GetLocalAddress() const = 0;
00463 
00466     virtual H323TransportAddress GetRemoteAddress() const = 0;
00467 
00473     virtual BOOL SetRemoteAddress(
00474       const H323TransportAddress & address
00475     ) = 0;
00476 
00479     virtual BOOL Connect() = 0;
00480 
00483     BOOL ConnectTo(
00484       const H323TransportAddress & address
00485     ) { return SetRemoteAddress(address) && Connect(); }
00486 
00489     virtual BOOL Close();
00490 
00493     virtual BOOL IsCompatibleTransport(
00494       const H225_TransportAddress & pdu
00495     ) const;
00496 
00499     virtual void SetUpTransportPDU(
00500       H225_TransportAddress & pdu,
00501       BOOL localTsap
00502     ) const;
00503 
00504     enum {
00505       UseLocalTSAP = 0x10001,
00506       UseRemoteTSAP
00507     };
00508 
00513     virtual void SetUpTransportPDU(
00514       H245_TransportAddress & pdu,
00515       unsigned tsap
00516     ) const;
00517 
00519     enum PromisciousModes {
00520       AcceptFromRemoteOnly,
00521       AcceptFromAnyAutoSet,
00522       AcceptFromAny,
00523       NumPromisciousModes
00524     };
00525 
00536     virtual void SetPromiscuous(
00537       PromisciousModes promiscuous
00538     );
00539 
00544     virtual H323TransportAddress GetLastReceivedAddress() const;
00545 
00551     virtual BOOL ReadPDU(
00552       PBYTEArray & pdu   
00553     ) = 0;
00554 
00560     virtual BOOL WritePDU(
00561       const PBYTEArray & pdu  
00562     ) = 0;
00564 
00570     BOOL HandleFirstSignallingChannelPDU();
00572 
00580     virtual H323Transport * CreateControlChannel(
00581       H323Connection & connection
00582     );
00583 
00588     virtual BOOL AcceptControlChannel(
00589       H323Connection & connection
00590     );
00591 
00594     virtual void StartControlChannel(
00595       H323Connection & connection
00596     );
00598 
00605     virtual BOOL DiscoverGatekeeper(
00606       H323Gatekeeper & gk,                  
00607       H323RasPDU & pdu,                     
00608       const H323TransportAddress & address  
00609     );
00611 
00612 
00617     H323EndPoint & GetEndPoint() const { return endpoint; }
00618 
00621     void AttachThread(
00622       PThread * thread
00623     );
00624 
00627     void CleanUpOnTermination();
00629 
00630   protected:
00631     H323EndPoint & endpoint;    
00632     PThread      * thread;      
00633     BOOL canGetInterface;
00634 };
00635 
00636 
00637 
00639 // Transport classes for IP
00640 
00644 class H323TransportIP : public H323Transport
00645 {
00646   PCLASSINFO(H323TransportIP, H323Transport);
00647 
00648   public:
00651     H323TransportIP(
00652       H323EndPoint & endpoint,    
00653       PIPSocket::Address binding, 
00654       WORD remPort                
00655     );
00656 
00659     virtual H323TransportAddress GetLocalAddress() const;
00660 
00663     virtual H323TransportAddress GetRemoteAddress() const;
00664 
00667     virtual BOOL IsCompatibleTransport(
00668       const H225_TransportAddress & pdu
00669     ) const;
00670 
00673     virtual void SetUpTransportPDU(
00674       H225_TransportAddress & pdu,
00675       BOOL localTsap
00676     ) const;
00677 
00680     virtual void SetUpTransportPDU(
00681       H245_TransportAddress & pdu,
00682       unsigned tsap
00683     ) const;
00684 
00685 
00686   protected:
00687     PIPSocket::Address localAddress;  // Address of the local interface
00688     WORD               localPort;
00689     PIPSocket::Address remoteAddress; // Address of the remote host
00690     WORD               remotePort;
00691 };
00692 
00693 
00695 // Transport classes for TCP/IP
00696 
00699 class H323ListenerTCP : public H323Listener
00700 {
00701   PCLASSINFO(H323ListenerTCP, H323Listener);
00702 
00703   public:
00706     H323ListenerTCP(
00707       H323EndPoint & endpoint,    
00708       PIPSocket::Address binding, 
00709       WORD port,                  
00710       BOOL exclusive = FALSE      
00711     );
00712 
00715     ~H323ListenerTCP();
00716     
00717   // Overrides from H323Listener
00720     virtual BOOL Open();
00721 
00724     virtual BOOL Close();
00725 
00728     virtual H323Transport * Accept(
00729       const PTimeInterval & timeout  
00730     );
00731 
00734     virtual H323TransportAddress GetTransportAddress() const;
00735 
00738     virtual BOOL SetUpTransportPDU(
00739       H245_TransportAddress & pdu,        
00740       const H323Transport & associatedTransport 
00741     );
00742 
00743     WORD GetListenerPort() const { return listener.GetPort(); }
00744 
00745 
00746   protected:
00755     virtual void Main();
00756 
00757 
00758     PTCPSocket listener;
00759     PIPSocket::Address localAddress;
00760     BOOL exclusiveListener;
00761 };
00762 
00763 
00766 class H323TransportTCP : public H323TransportIP
00767 {
00768   PCLASSINFO(H323TransportTCP, H323TransportIP);
00769 
00770   public:
00773     H323TransportTCP(
00774       H323EndPoint & endpoint,    
00775       PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(), 
00776       BOOL listen = FALSE         
00777     );
00778 
00781     ~H323TransportTCP();
00782 
00788     virtual BOOL SetRemoteAddress(
00789       const H323TransportAddress & address
00790     );
00791 
00794     virtual BOOL Connect();
00795 
00798     virtual BOOL Close();
00799 
00805     BOOL ReadPDU(
00806       PBYTEArray & pdu   
00807     );
00808 
00814     BOOL WritePDU(
00815       const PBYTEArray & pdu  
00816     );
00817 
00822     virtual H323Transport * CreateControlChannel(
00823       H323Connection & connection
00824     );
00825 
00830     virtual BOOL AcceptControlChannel(
00831       H323Connection & connection
00832     );
00833 
00836     virtual BOOL IsListening() const;
00837 
00838 
00839   protected:
00849     virtual BOOL OnOpen();
00850 
00851 
00852     PTCPSocket * h245listener;
00853 };
00854 
00855 
00857 // Transport classes for UDP/IP
00858 
00861 class H323TransportUDP : public H323TransportIP
00862 {
00863   PCLASSINFO(H323TransportUDP, H323TransportIP);
00864 
00865   public:
00868     H323TransportUDP(
00869       H323EndPoint & endpoint,                  
00870       PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),  
00871       WORD localPort = 0,                       
00872       WORD remotePort = 0                       
00873     );
00874     ~H323TransportUDP();
00875 
00881     virtual BOOL SetRemoteAddress(
00882       const H323TransportAddress & address
00883     );
00884 
00887     virtual BOOL Connect();
00888 
00900     virtual void SetPromiscuous(
00901       PromisciousModes promiscuous
00902     );
00903 
00908     virtual H323TransportAddress GetLastReceivedAddress() const;
00909 
00915     virtual BOOL ReadPDU(
00916       PBYTEArray & pdu   
00917     );
00918 
00924     virtual BOOL WritePDU(
00925       const PBYTEArray & pdu  
00926     );
00927 
00933     virtual BOOL DiscoverGatekeeper(
00934       H323Gatekeeper & gk,                  
00935       H323RasPDU & pdu,                     
00936       const H323TransportAddress & address  
00937     );
00938 
00941     virtual H323TransportAddress GetLocalAddress() const;
00942 
00943   protected:
00944     PromisciousModes     promiscuousReads;
00945     H323TransportAddress lastReceivedAddress;
00946     PIPSocket::Address   lastReceivedInterface;
00947     WORD interfacePort;
00948 };
00949 
00950 
00951 #endif // __TRANSPORTS_H
00952 
00953 

Generated on Fri Nov 17 03:03:34 2006 for OpenH323 by  doxygen 1.5.1