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.51  2006/07/05 04:37:44  csoutheren
00031  * Applied 1488904 - SetPromiscuous(AcceptFromLastReceivedOnly) for T.38
00032  * Thanks to Vyacheslav Frolov
00033  *
00034  * Revision 1.50  2006/06/23 03:21:03  shorne
00035  * Added unsolicited Information support
00036  *
00037  * Revision 1.49  2006/01/20 00:32:24  csoutheren
00038  * First check-in of signalling aggregation code - incomplete and disabled by default
00039  *
00040  * Revision 1.48  2005/11/30 13:05:01  csoutheren
00041  * Changed tags for Doxygen
00042  *
00043  * Revision 1.47  2005/11/21 21:07:41  shorne
00044  * Added GnuGK Nat support
00045  *
00046  * Revision 1.46  2005/01/16 20:39:43  csoutheren
00047  * Fixed problem with IPv6 INADDR_ANY
00048  *
00049  * Revision 1.45  2004/08/24 08:11:25  csoutheren
00050  * Added initial support for receiving broadcasts on Linux
00051  *
00052  * Revision 1.44  2004/05/13 02:26:13  dereksmithies
00053  * Fixes so make docs does not generate warning messages about brackets.
00054  *
00055  * Revision 1.43  2003/12/29 13:28:45  dominance
00056  * fixed docbook syntax trying to generate LaTeX formula with ip$10.x.x.x.
00057  *
00058  * Revision 1.42  2003/04/10 09:44:55  robertj
00059  * Added associated transport to new GetInterfaceAddresses() function so
00060  *   interfaces can be ordered according to active transport links. Improves
00061  *   interoperability.
00062  * Replaced old listener GetTransportPDU() with GetInterfaceAddresses()
00063  *   and H323SetTransportAddresses() functions.
00064  *
00065  * Revision 1.41  2003/04/10 01:03:25  craigs
00066  * Added functions to access to lists of interfaces
00067  *
00068  * Revision 1.40  2003/03/21 05:24:02  robertj
00069  * Added setting of remote port in UDP transport constructor.
00070  *
00071  * Revision 1.39  2003/02/06 04:29:23  robertj
00072  * Added more support for adding things to H323TransportAddressArrays
00073  *
00074  * Revision 1.38  2002/11/21 06:39:56  robertj
00075  * Changed promiscuous mode to be three way. Fixes race condition in gkserver
00076  *   which can cause crashes or more PDUs to be sent to the wrong place.
00077  *
00078  * Revision 1.37  2002/11/10 08:10:43  robertj
00079  * Moved constants for "well known" ports to better place (OPAL change).
00080  *
00081  * Revision 1.36  2002/09/16 01:14:15  robertj
00082  * Added #define so can select if #pragma interface/implementation is used on
00083  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00084  *
00085  * Revision 1.35  2002/07/22 09:40:15  robertj
00086  * Added ability to automatically convert string arrays, lists sorted lists
00087  *   directly to H323TransportAddressArray.
00088  *
00089  * Revision 1.34  2002/07/02 10:02:29  robertj
00090  * Added H323TransportAddress::GetIpAddress() so don't have to provide port
00091  *   when you don't need it as in GetIpAndPort(),.
00092  *
00093  * Revision 1.33  2002/06/28 03:34:25  robertj
00094  * Fixed issues with address translation on gatekeeper RAS channel.
00095  *
00096  * Revision 1.32  2002/06/12 03:51:59  robertj
00097  * Added function to compare two transport addresses in a more intelligent
00098  *   way that strict string comparison. Takes into account wildcarding.
00099  *
00100  * Revision 1.31  2002/02/11 04:20:25  robertj
00101  * Fixed documentation errors, thanks Horacio J. Peņa
00102  *
00103  * Revision 1.30  2002/02/05 23:29:23  robertj
00104  * Changed default for H.323 listener to reuse addresses.
00105  *
00106  * Revision 1.29  2001/12/22 01:48:12  robertj
00107  * Added ability to use local and remote port from transport channel as well
00108  *   as explicit port in H.245 address PDU setting routine.
00109  * Added PrintOn() to listener and transport for tracing purposes.
00110  *
00111  * Revision 1.28  2001/07/17 04:44:29  robertj
00112  * Partial implementation of T.120 and T.38 logical channels.
00113  *
00114  * Revision 1.27  2001/06/25 02:30:46  robertj
00115  * Allowed TCP listener socket to be opened in non-exclusive mode
00116  *   (ie SO_REUSEADDR) to avoid daemon restart problems.
00117  *
00118  * Revision 1.26  2001/06/22 00:14:14  robertj
00119  * Added ConnectTo() function to conencto specific address.
00120  * Added promiscuous mode for UDP channel.
00121  *
00122  * Revision 1.25  2001/05/17 06:37:02  robertj
00123  * Added multicast gatekeeper discovery support.
00124  *
00125  * Revision 1.24  2001/04/09 08:43:39  robertj
00126  * Added ability to get transport address for a listener.
00127  *
00128  * Revision 1.23  2001/03/02 06:59:57  robertj
00129  * Enhanced the globally unique identifier class.
00130  *
00131  * Revision 1.22  2001/02/09 05:16:24  robertj
00132  * Added #pragma interface for GNU C++.
00133  *
00134  * Revision 1.21  2001/01/23 05:08:04  robertj
00135  * Fixed bug when trying to clear call while waiting on H.245 channel connect, thanks Yura Aksyonov.
00136  *
00137  * Revision 1.20  2000/10/20 06:18:58  robertj
00138  * Fixed very small race condition on creating new connectionon incoming call.
00139  * Fixed memory/socket leak if do TCP connect and don't send valid setup PDU.
00140  *
00141  * Revision 1.19  2000/10/04 05:59:09  robertj
00142  * Minor reorganisation of the H.245 secondary channel start up to make it simpler
00143  *    to override its behaviour.
00144  *
00145  * Revision 1.18  2000/09/25 12:59:16  robertj
00146  * Added StartListener() function that takes a H323TransportAddress to start
00147  *     listeners bound to specific interfaces.
00148  *
00149  * Revision 1.17  2000/09/22 01:35:03  robertj
00150  * Added support for handling LID's that only do symmetric codecs.
00151  *
00152  * Revision 1.16  2000/06/07 05:47:55  robertj
00153  * Added call forwarding.
00154  *
00155  * Revision 1.15  2000/05/22 05:21:36  robertj
00156  * Fixed race condition where controlChannel variable could be used before set.
00157  *
00158  * Revision 1.14  2000/05/18 11:53:34  robertj
00159  * Changes to support doc++ documentation generation.
00160  *
00161  * Revision 1.13  2000/05/08 14:07:26  robertj
00162  * Improved the provision and detection of calling and caller numbers, aliases and hostnames.
00163  *
00164  * Revision 1.12  2000/05/02 04:32:25  robertj
00165  * Fixed copyright notice comment.
00166  *
00167  * Revision 1.11  1999/11/06 05:37:44  robertj
00168  * Complete rewrite of termination of connection to avoid numerous race conditions.
00169  *
00170  * Revision 1.10  1999/10/16 03:47:57  robertj
00171  * Fixed termination of gatekeeper RAS thread problem
00172  *
00173  * Revision 1.9  1999/10/10 08:59:47  robertj
00174  * Fixed race condition in connection shutdown
00175  *
00176  * Revision 1.8  1999/09/14 06:52:54  robertj
00177  * Added better support for multi-homed client hosts.
00178  *
00179  * Revision 1.7  1999/09/10 09:43:59  robertj
00180  * Removed attempt at determining local interface for gatekeeper, so still has problem on multi-homed hosts.
00181  *
00182  * Revision 1.6  1999/08/31 12:34:18  robertj
00183  * Added gatekeeper support.
00184  *
00185  * Revision 1.5  1999/08/25 05:14:21  robertj
00186  * Fixed problem with calling modal dialog from a background thread.
00187  *
00188  * Revision 1.4  1999/07/14 06:06:14  robertj
00189  * Fixed termination problems (race conditions) with deleting connection object.
00190  *
00191  * Revision 1.3  1999/07/09 06:09:49  robertj
00192  * Major implementation. An ENORMOUS amount of stuff added everywhere.
00193  *
00194  * Revision 1.2  1999/06/13 12:41:14  robertj
00195  * Implement logical channel transmitter.
00196  * Fixed H245 connect on receiving call.
00197  *
00198  * Revision 1.1  1999/06/09 05:26:20  robertj
00199  * Major restructuring of classes.
00200  *
00201  */
00202 
00203 #ifndef __TRANSPORTS_H
00204 #define __TRANSPORTS_H
00205 
00206 #ifdef P_USE_PRAGMA
00207 #pragma interface
00208 #endif
00209 
00210 
00211 #include <ptlib/sockets.h>
00212 
00213 
00214 class H225_Setup_UUIE;
00215 class H225_TransportAddress;
00216 class H225_ArrayOf_TransportAddress;
00217 class H225_TransportAddress_ipAddress;
00218 
00219 class H245_TransportAddress;
00220 
00221 class H323SignalPDU;
00222 class H323RasPDU;
00223 class H323EndPoint;
00224 class H323Connection;
00225 class H323Listener;
00226 class H323Transport;
00227 class H323Gatekeeper;
00228 
00229 
00230 
00232 
00236 class H323TransportAddress : public PString
00237 {
00238   PCLASSINFO(H323TransportAddress, PString);
00239   public:
00240     H323TransportAddress() { }
00241     H323TransportAddress(const char *);
00242     H323TransportAddress(const PString &);
00243     H323TransportAddress(const H225_TransportAddress &);
00244     H323TransportAddress(const H245_TransportAddress &);
00245     H323TransportAddress(const PIPSocket::Address &, WORD);
00246 
00247     BOOL SetPDU(H225_TransportAddress & pdu) const;
00248     BOOL SetPDU(H245_TransportAddress & pdu) const;
00249 
00252     BOOL IsEquivalent(
00253       const H323TransportAddress & address
00254     );
00255 
00259     BOOL GetIpAddress(
00260       PIPSocket::Address & ip
00261     ) const;
00262 
00266     BOOL GetIpAndPort(
00267       PIPSocket::Address & ip,
00268       WORD & port,
00269       const char * proto = "tcp"
00270     ) const;
00271 
00275     PString GetHostName() const;
00276 
00287     H323Listener * CreateListener(
00288       H323EndPoint & endpoint   
00289     ) const;
00290 
00297     H323Listener * CreateCompatibleListener(
00298       H323EndPoint & endpoint   
00299     ) const;
00300 
00303     H323Transport * CreateTransport(
00304       H323EndPoint & endpoint   
00305     ) const;
00306 
00307   protected:
00308     void Validate();
00309 };
00310 
00311 
00312 PDECLARE_ARRAY(H323TransportAddressArray, H323TransportAddress)
00313 #ifdef DOC_PLUS_PLUS
00314 {
00315 #endif
00316   public:
00317     H323TransportAddressArray(
00318       const H323TransportAddress & address
00319     ) { AppendAddress(address); }
00320     H323TransportAddressArray(
00321       const H225_ArrayOf_TransportAddress & addresses
00322     );
00323     H323TransportAddressArray(
00324       const PStringArray & array
00325     ) { AppendStringCollection(array); }
00326     H323TransportAddressArray(
00327       const PStringList & list
00328     ) { AppendStringCollection(list); }
00329     H323TransportAddressArray(
00330       const PSortedStringList & list
00331     ) { AppendStringCollection(list); }
00332 
00333     void AppendString(
00334       const char * address
00335     );
00336     void AppendString(
00337       const PString & address
00338     );
00339     void AppendAddress(
00340       const H323TransportAddress & address
00341     );
00342 
00343   protected:
00344     void AppendStringCollection(
00345       const PCollection & coll
00346     );
00347 };
00348 
00349 
00362 class H323Listener : public PThread
00363 {
00364   PCLASSINFO(H323Listener, PThread);
00365 
00366   public:
00371     H323Listener(
00372       H323EndPoint & endpoint      
00373     );
00375 
00378     virtual void PrintOn(
00379       ostream & strm
00380     ) const;
00382 
00387     virtual BOOL Open() = 0;
00388 
00391     virtual BOOL Close() = 0;
00392 
00395     virtual H323Transport * Accept(
00396       const PTimeInterval & timeout  
00397     ) = 0;
00398 
00401     virtual H323TransportAddress GetTransportAddress() const = 0;
00402 
00405     virtual BOOL SetUpTransportPDU(
00406       H245_TransportAddress & pdu,         
00407       const H323Transport & associatedTransport 
00408     ) = 0;
00410 
00411   protected:
00412     H323EndPoint & endpoint;  
00413 };
00414 
00415 
00416 PLIST(H323ListenerList, H323Listener);
00417 
00418 
00421 H323TransportAddressArray H323GetInterfaceAddresses(
00422   const H323ListenerList & listeners, 
00423   BOOL excludeLocalHost = TRUE,       
00424   H323Transport * associatedTransport = NULL
00426 );
00427 
00428 H323TransportAddressArray H323GetInterfaceAddresses(
00429   const H323TransportAddress & addr,  
00430   BOOL excludeLocalHost = TRUE,       
00431   H323Transport * associatedTransport = NULL
00433 );
00434 
00437 void H323SetTransportAddresses(
00438   const H323Transport & associatedTransport,   
00439   const H323TransportAddressArray & addresses, 
00440   H225_ArrayOf_TransportAddress & pdu          
00441 );
00442 
00443 
00448 class H323Transport : public PIndirectChannel
00449 {
00450   PCLASSINFO(H323Transport, PIndirectChannel);
00451 
00452   public:
00457     H323Transport(H323EndPoint & endpoint);
00458     ~H323Transport();
00460 
00463     virtual void PrintOn(
00464       ostream & strm
00465     ) const;
00467 
00472     virtual H323TransportAddress GetLocalAddress() const = 0;
00473 
00476     virtual H323TransportAddress GetRemoteAddress() const = 0;
00477 
00483     virtual BOOL SetRemoteAddress(
00484       const H323TransportAddress & address
00485     ) = 0;
00486 
00489     virtual BOOL Connect() = 0;
00490 
00493     BOOL ConnectTo(
00494       const H323TransportAddress & address
00495     ) { return SetRemoteAddress(address) && Connect(); }
00496 
00499     virtual BOOL Close();
00500 
00503     virtual BOOL IsCompatibleTransport(
00504       const H225_TransportAddress & pdu
00505     ) const;
00506 
00509     virtual void SetUpTransportPDU(
00510       H225_TransportAddress & pdu,
00511       BOOL localTsap
00512     ) const;
00513 
00514     enum {
00515       UseLocalTSAP = 0x10001,
00516       UseRemoteTSAP
00517     };
00518 
00523     virtual void SetUpTransportPDU(
00524       H245_TransportAddress & pdu,
00525       unsigned tsap
00526     ) const;
00527 
00529     enum PromisciousModes {
00530       AcceptFromRemoteOnly,
00531       AcceptFromAnyAutoSet,
00532       AcceptFromAny,
00533       AcceptFromLastReceivedOnly,
00534       NumPromisciousModes
00535     };
00536 
00547     virtual void SetPromiscuous(
00548       PromisciousModes promiscuous
00549     );
00550 
00555     virtual H323TransportAddress GetLastReceivedAddress() const;
00556 
00562     virtual BOOL ReadPDU(
00563       PBYTEArray & pdu   
00564     ) = 0;
00565 
00570     virtual BOOL ExtractPDU(
00571       const PBYTEArray & pdu, 
00572       PINDEX & len
00573     ) = 0;
00574 
00580     virtual BOOL WritePDU(
00581       const PBYTEArray & pdu  
00582     ) = 0;
00584 
00589     BOOL HandleSignallingSocket(H323SignalPDU & pdu);
00590 
00594     BOOL HandleFirstSignallingChannelPDU();
00596 
00604     virtual H323Transport * CreateControlChannel(
00605       H323Connection & connection
00606     );
00607 
00612     virtual BOOL AcceptControlChannel(
00613       H323Connection & connection
00614     );
00615 
00618     virtual void StartControlChannel(
00619       H323Connection & connection
00620     );
00622 
00629     virtual BOOL DiscoverGatekeeper(
00630       H323Gatekeeper & gk,                  
00631       H323RasPDU & pdu,                     
00632       const H323TransportAddress & address  
00633     );
00635 
00636 
00641     H323EndPoint & GetEndPoint() const { return endpoint; }
00642 
00645     void AttachThread(
00646       PThread * thread
00647     );
00648 
00651     void CleanUpOnTermination();
00653 
00654   protected:
00655     H323EndPoint & endpoint;    
00656     PThread      * thread;      
00657     BOOL canGetInterface;
00658 };
00659 
00660 
00661 
00663 // Transport classes for IP
00664 
00668 class H323TransportIP : public H323Transport
00669 {
00670   PCLASSINFO(H323TransportIP, H323Transport);
00671 
00672   public:
00675     H323TransportIP(
00676       H323EndPoint & endpoint,    
00677       PIPSocket::Address binding, 
00678       WORD remPort                
00679     );
00680 
00683     virtual H323TransportAddress GetLocalAddress() const;
00684 
00687     virtual H323TransportAddress GetRemoteAddress() const;
00688 
00691     virtual BOOL IsCompatibleTransport(
00692       const H225_TransportAddress & pdu
00693     ) const;
00694 
00697     virtual void SetUpTransportPDU(
00698       H225_TransportAddress & pdu,
00699       BOOL localTsap
00700     ) const;
00701 
00704     virtual void SetUpTransportPDU(
00705       H245_TransportAddress & pdu,
00706       unsigned tsap
00707     ) const;
00708 
00709 
00710   protected:
00711     PIPSocket::Address localAddress;  // Address of the local interface
00712     WORD               localPort;
00713     PIPSocket::Address remoteAddress; // Address of the remote host
00714     WORD               remotePort;
00715 };
00716 
00717 
00719 // Transport classes for TCP/IP
00720 
00723 class H323ListenerTCP : public H323Listener
00724 {
00725   PCLASSINFO(H323ListenerTCP, H323Listener);
00726 
00727   public:
00730     H323ListenerTCP(
00731       H323EndPoint & endpoint,    
00732       PIPSocket::Address binding, 
00733       WORD port,                  
00734       BOOL exclusive = FALSE      
00735     );
00736 
00739     ~H323ListenerTCP();
00740     
00741   // Overrides from H323Listener
00744     virtual BOOL Open();
00745 
00748     virtual BOOL Close();
00749 
00752     virtual H323Transport * Accept(
00753       const PTimeInterval & timeout  
00754     );
00755 
00758     virtual H323TransportAddress GetTransportAddress() const;
00759 
00762     virtual BOOL SetUpTransportPDU(
00763       H245_TransportAddress & pdu,        
00764       const H323Transport & associatedTransport 
00765     );
00766 
00767     WORD GetListenerPort() const { return listener.GetPort(); }
00768 
00769 
00770   protected:
00779     virtual void Main();
00780 
00781 
00782     PTCPSocket listener;
00783     PIPSocket::Address localAddress;
00784     BOOL exclusiveListener;
00785 };
00786 
00787 
00790 class H323TransportTCP : public H323TransportIP
00791 {
00792   PCLASSINFO(H323TransportTCP, H323TransportIP);
00793 
00794   public:
00797     H323TransportTCP(
00798       H323EndPoint & endpoint,    
00799       PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(), 
00800       BOOL listen = FALSE         
00801     );
00802 
00805     ~H323TransportTCP();
00806 
00812     virtual BOOL SetRemoteAddress(
00813       const H323TransportAddress & address
00814     );
00815 
00818     virtual BOOL Connect();
00819 
00822     virtual BOOL Close();
00823 
00829     BOOL ReadPDU(
00830       PBYTEArray & pdu   
00831     );
00832 
00835     BOOL ExtractPDU(
00836       const PBYTEArray & pdu, 
00837       PINDEX & len
00838     );
00839  
00845     BOOL WritePDU(
00846       const PBYTEArray & pdu  
00847     );
00848 
00853     virtual H323Transport * CreateControlChannel(
00854       H323Connection & connection
00855     );
00856 
00861     virtual BOOL AcceptControlChannel(
00862       H323Connection & connection
00863     );
00864 
00867     virtual BOOL IsListening() const;
00868 
00869 
00870   protected:
00880     virtual BOOL OnOpen();
00881 
00882 
00883     PTCPSocket * h245listener;
00884 };
00885 
00886 
00888 // Transport classes for UDP/IP
00889 
00892 class H323TransportUDP : public H323TransportIP
00893 {
00894   PCLASSINFO(H323TransportUDP, H323TransportIP);
00895 
00896   public:
00899     H323TransportUDP(
00900       H323EndPoint & endpoint,                  
00901       PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),  
00902       WORD localPort = 0,                       
00903       WORD remotePort = 0                       
00904     );
00905     ~H323TransportUDP();
00906 
00912     virtual BOOL SetRemoteAddress(
00913       const H323TransportAddress & address
00914     );
00915 
00918     virtual BOOL Connect();
00919 
00931     virtual void SetPromiscuous(
00932       PromisciousModes promiscuous
00933     );
00934 
00939     virtual H323TransportAddress GetLastReceivedAddress() const;
00940 
00946     virtual BOOL ReadPDU(
00947       PBYTEArray & pdu   
00948     );
00949 
00952     BOOL ExtractPDU(
00953       const PBYTEArray & pdu, 
00954       PINDEX & len
00955     );
00956  
00962     virtual BOOL WritePDU(
00963       const PBYTEArray & pdu  
00964     );
00965 
00971     virtual BOOL DiscoverGatekeeper(
00972       H323Gatekeeper & gk,                  
00973       H323RasPDU & pdu,                     
00974       const H323TransportAddress & address  
00975     );
00976 
00979     virtual H323TransportAddress GetLocalAddress() const;
00980 
00981   protected:
00982     PromisciousModes     promiscuousReads;
00983     H323TransportAddress lastReceivedAddress;
00984     PIPSocket::Address   lastReceivedInterface;
00985     WORD interfacePort;
00986 };
00987 
00988 
00989 #endif // __TRANSPORTS_H
00990 
00991 

Generated on Wed Feb 6 09:02:45 2008 for OpenH323 by  doxygen 1.5.4