D:/Storage/CVS_Head/h323plus/include/transports.h

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.1  2007/08/06 20:50:50  shorne
00031  * First commit of h323plus
00032  *
00033  * Revision 1.51.2.1  2007/02/11 00:45:20  shorne
00034  * Added ability to disable NAT method on a call by call basis
00035  *
00036  * Revision 1.51  2006/07/05 04:37:44  csoutheren
00037  * Applied 1488904 - SetPromiscuous(AcceptFromLastReceivedOnly) for T.38
00038  * Thanks to Vyacheslav Frolov
00039  *
00040  * Revision 1.50  2006/06/23 03:21:03  shorne
00041  * Added unsolicited Information support
00042  *
00043  * Revision 1.49  2006/01/20 00:32:24  csoutheren
00044  * First check-in of signalling aggregation code - incomplete and disabled by default
00045  *
00046  * Revision 1.48  2005/11/30 13:05:01  csoutheren
00047  * Changed tags for Doxygen
00048  *
00049  * Revision 1.47  2005/11/21 21:07:41  shorne
00050  * Added GnuGK Nat support
00051  *
00052  * Revision 1.46  2005/01/16 20:39:43  csoutheren
00053  * Fixed problem with IPv6 INADDR_ANY
00054  *
00055  * Revision 1.45  2004/08/24 08:11:25  csoutheren
00056  * Added initial support for receiving broadcasts on Linux
00057  *
00058  * Revision 1.44  2004/05/13 02:26:13  dereksmithies
00059  * Fixes so make docs does not generate warning messages about brackets.
00060  *
00061  * Revision 1.43  2003/12/29 13:28:45  dominance
00062  * fixed docbook syntax trying to generate LaTeX formula with ip$10.x.x.x.
00063  *
00064  * Revision 1.42  2003/04/10 09:44:55  robertj
00065  * Added associated transport to new GetInterfaceAddresses() function so
00066  *   interfaces can be ordered according to active transport links. Improves
00067  *   interoperability.
00068  * Replaced old listener GetTransportPDU() with GetInterfaceAddresses()
00069  *   and H323SetTransportAddresses() functions.
00070  *
00071  * Revision 1.41  2003/04/10 01:03:25  craigs
00072  * Added functions to access to lists of interfaces
00073  *
00074  * Revision 1.40  2003/03/21 05:24:02  robertj
00075  * Added setting of remote port in UDP transport constructor.
00076  *
00077  * Revision 1.39  2003/02/06 04:29:23  robertj
00078  * Added more support for adding things to H323TransportAddressArrays
00079  *
00080  * Revision 1.38  2002/11/21 06:39:56  robertj
00081  * Changed promiscuous mode to be three way. Fixes race condition in gkserver
00082  *   which can cause crashes or more PDUs to be sent to the wrong place.
00083  *
00084  * Revision 1.37  2002/11/10 08:10:43  robertj
00085  * Moved constants for "well known" ports to better place (OPAL change).
00086  *
00087  * Revision 1.36  2002/09/16 01:14:15  robertj
00088  * Added #define so can select if #pragma interface/implementation is used on
00089  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00090  *
00091  * Revision 1.35  2002/07/22 09:40:15  robertj
00092  * Added ability to automatically convert string arrays, lists sorted lists
00093  *   directly to H323TransportAddressArray.
00094  *
00095  * Revision 1.34  2002/07/02 10:02:29  robertj
00096  * Added H323TransportAddress::GetIpAddress() so don't have to provide port
00097  *   when you don't need it as in GetIpAndPort(),.
00098  *
00099  * Revision 1.33  2002/06/28 03:34:25  robertj
00100  * Fixed issues with address translation on gatekeeper RAS channel.
00101  *
00102  * Revision 1.32  2002/06/12 03:51:59  robertj
00103  * Added function to compare two transport addresses in a more intelligent
00104  *   way that strict string comparison. Takes into account wildcarding.
00105  *
00106  * Revision 1.31  2002/02/11 04:20:25  robertj
00107  * Fixed documentation errors, thanks Horacio J. Peņa
00108  *
00109  * Revision 1.30  2002/02/05 23:29:23  robertj
00110  * Changed default for H.323 listener to reuse addresses.
00111  *
00112  * Revision 1.29  2001/12/22 01:48:12  robertj
00113  * Added ability to use local and remote port from transport channel as well
00114  *   as explicit port in H.245 address PDU setting routine.
00115  * Added PrintOn() to listener and transport for tracing purposes.
00116  *
00117  * Revision 1.28  2001/07/17 04:44:29  robertj
00118  * Partial implementation of T.120 and T.38 logical channels.
00119  *
00120  * Revision 1.27  2001/06/25 02:30:46  robertj
00121  * Allowed TCP listener socket to be opened in non-exclusive mode
00122  *   (ie SO_REUSEADDR) to avoid daemon restart problems.
00123  *
00124  * Revision 1.26  2001/06/22 00:14:14  robertj
00125  * Added ConnectTo() function to conencto specific address.
00126  * Added promiscuous mode for UDP channel.
00127  *
00128  * Revision 1.25  2001/05/17 06:37:02  robertj
00129  * Added multicast gatekeeper discovery support.
00130  *
00131  * Revision 1.24  2001/04/09 08:43:39  robertj
00132  * Added ability to get transport address for a listener.
00133  *
00134  * Revision 1.23  2001/03/02 06:59:57  robertj
00135  * Enhanced the globally unique identifier class.
00136  *
00137  * Revision 1.22  2001/02/09 05:16:24  robertj
00138  * Added #pragma interface for GNU C++.
00139  *
00140  * Revision 1.21  2001/01/23 05:08:04  robertj
00141  * Fixed bug when trying to clear call while waiting on H.245 channel connect, thanks Yura Aksyonov.
00142  *
00143  * Revision 1.20  2000/10/20 06:18:58  robertj
00144  * Fixed very small race condition on creating new connectionon incoming call.
00145  * Fixed memory/socket leak if do TCP connect and don't send valid setup PDU.
00146  *
00147  * Revision 1.19  2000/10/04 05:59:09  robertj
00148  * Minor reorganisation of the H.245 secondary channel start up to make it simpler
00149  *    to override its behaviour.
00150  *
00151  * Revision 1.18  2000/09/25 12:59:16  robertj
00152  * Added StartListener() function that takes a H323TransportAddress to start
00153  *     listeners bound to specific interfaces.
00154  *
00155  * Revision 1.17  2000/09/22 01:35:03  robertj
00156  * Added support for handling LID's that only do symmetric codecs.
00157  *
00158  * Revision 1.16  2000/06/07 05:47:55  robertj
00159  * Added call forwarding.
00160  *
00161  * Revision 1.15  2000/05/22 05:21:36  robertj
00162  * Fixed race condition where controlChannel variable could be used before set.
00163  *
00164  * Revision 1.14  2000/05/18 11:53:34  robertj
00165  * Changes to support doc++ documentation generation.
00166  *
00167  * Revision 1.13  2000/05/08 14:07:26  robertj
00168  * Improved the provision and detection of calling and caller numbers, aliases and hostnames.
00169  *
00170  * Revision 1.12  2000/05/02 04:32:25  robertj
00171  * Fixed copyright notice comment.
00172  *
00173  * Revision 1.11  1999/11/06 05:37:44  robertj
00174  * Complete rewrite of termination of connection to avoid numerous race conditions.
00175  *
00176  * Revision 1.10  1999/10/16 03:47:57  robertj
00177  * Fixed termination of gatekeeper RAS thread problem
00178  *
00179  * Revision 1.9  1999/10/10 08:59:47  robertj
00180  * Fixed race condition in connection shutdown
00181  *
00182  * Revision 1.8  1999/09/14 06:52:54  robertj
00183  * Added better support for multi-homed client hosts.
00184  *
00185  * Revision 1.7  1999/09/10 09:43:59  robertj
00186  * Removed attempt at determining local interface for gatekeeper, so still has problem on multi-homed hosts.
00187  *
00188  * Revision 1.6  1999/08/31 12:34:18  robertj
00189  * Added gatekeeper support.
00190  *
00191  * Revision 1.5  1999/08/25 05:14:21  robertj
00192  * Fixed problem with calling modal dialog from a background thread.
00193  *
00194  * Revision 1.4  1999/07/14 06:06:14  robertj
00195  * Fixed termination problems (race conditions) with deleting connection object.
00196  *
00197  * Revision 1.3  1999/07/09 06:09:49  robertj
00198  * Major implementation. An ENORMOUS amount of stuff added everywhere.
00199  *
00200  * Revision 1.2  1999/06/13 12:41:14  robertj
00201  * Implement logical channel transmitter.
00202  * Fixed H245 connect on receiving call.
00203  *
00204  * Revision 1.1  1999/06/09 05:26:20  robertj
00205  * Major restructuring of classes.
00206  *
00207  */
00208 
00209 #ifndef __TRANSPORTS_H
00210 #define __TRANSPORTS_H
00211 
00212 #ifdef P_USE_PRAGMA
00213 #pragma interface
00214 #endif
00215 
00216 
00217 #include <ptlib/sockets.h>
00218 
00219 
00220 class H225_Setup_UUIE;
00221 class H225_TransportAddress;
00222 class H225_ArrayOf_TransportAddress;
00223 class H225_TransportAddress_ipAddress;
00224 
00225 class H245_TransportAddress;
00226 
00227 class H323SignalPDU;
00228 class H323RasPDU;
00229 class H323EndPoint;
00230 class H323Connection;
00231 class H323Listener;
00232 class H323Transport;
00233 class H323Gatekeeper;
00234 
00235 
00236 
00238 
00242 class H323TransportAddress : public PString
00243 {
00244   PCLASSINFO(H323TransportAddress, PString);
00245   public:
00246     H323TransportAddress() { }
00247     H323TransportAddress(const char *);
00248     H323TransportAddress(const PString &);
00249     H323TransportAddress(const H225_TransportAddress &);
00250     H323TransportAddress(const H245_TransportAddress &);
00251     H323TransportAddress(const PIPSocket::Address &, WORD);
00252 
00253     BOOL SetPDU(H225_TransportAddress & pdu) const;
00254     BOOL SetPDU(H245_TransportAddress & pdu) const;
00255 
00258     BOOL IsEquivalent(
00259       const H323TransportAddress & address
00260     );
00261 
00265     BOOL GetIpAddress(
00266       PIPSocket::Address & ip
00267     ) const;
00268 
00272     BOOL GetIpAndPort(
00273       PIPSocket::Address & ip,
00274       WORD & port,
00275       const char * proto = "tcp"
00276     ) const;
00277 
00281     PString GetHostName() const;
00282 
00293     H323Listener * CreateListener(
00294       H323EndPoint & endpoint   
00295     ) const;
00296 
00303     H323Listener * CreateCompatibleListener(
00304       H323EndPoint & endpoint   
00305     ) const;
00306 
00309     H323Transport * CreateTransport(
00310       H323EndPoint & endpoint   
00311     ) const;
00312 
00313   protected:
00314     void Validate();
00315 };
00316 
00317 
00318 PDECLARE_ARRAY(H323TransportAddressArray, H323TransportAddress)
00319 #ifdef DOC_PLUS_PLUS
00320 {
00321 #endif
00322   public:
00323     H323TransportAddressArray(
00324       const H323TransportAddress & address
00325     ) { AppendAddress(address); }
00326     H323TransportAddressArray(
00327       const H225_ArrayOf_TransportAddress & addresses
00328     );
00329     H323TransportAddressArray(
00330       const PStringArray & array
00331     ) { AppendStringCollection(array); }
00332     H323TransportAddressArray(
00333       const PStringList & list
00334     ) { AppendStringCollection(list); }
00335     H323TransportAddressArray(
00336       const PSortedStringList & list
00337     ) { AppendStringCollection(list); }
00338 
00339     void AppendString(
00340       const char * address
00341     );
00342     void AppendString(
00343       const PString & address
00344     );
00345     void AppendAddress(
00346       const H323TransportAddress & address
00347     );
00348 
00349   protected:
00350     void AppendStringCollection(
00351       const PCollection & coll
00352     );
00353 };
00354 
00355 
00368 class H323Listener : public PThread
00369 {
00370   PCLASSINFO(H323Listener, PThread);
00371 
00372   public:
00377     H323Listener(
00378       H323EndPoint & endpoint      
00379     );
00381 
00384     virtual void PrintOn(
00385       ostream & strm
00386     ) const;
00388 
00393     virtual BOOL Open() = 0;
00394 
00397     virtual BOOL Close() = 0;
00398 
00401     virtual H323Transport * Accept(
00402       const PTimeInterval & timeout  
00403     ) = 0;
00404 
00407     virtual H323TransportAddress GetTransportAddress() const = 0;
00408 
00411     virtual BOOL SetUpTransportPDU(
00412       H245_TransportAddress & pdu,         
00413       const H323Transport & associatedTransport 
00414     ) = 0;
00416 
00417   protected:
00418     H323EndPoint & endpoint;  
00419 };
00420 
00421 
00422 PLIST(H323ListenerList, H323Listener);
00423 
00424 
00427 H323TransportAddressArray H323GetInterfaceAddresses(
00428   const H323ListenerList & listeners, 
00429   BOOL excludeLocalHost = TRUE,       
00430   H323Transport * associatedTransport = NULL
00432 );
00433 
00434 H323TransportAddressArray H323GetInterfaceAddresses(
00435   const H323TransportAddress & addr,  
00436   BOOL excludeLocalHost = TRUE,       
00437   H323Transport * associatedTransport = NULL
00439 );
00440 
00443 void H323SetTransportAddresses(
00444   const H323Transport & associatedTransport,   
00445   const H323TransportAddressArray & addresses, 
00446   H225_ArrayOf_TransportAddress & pdu          
00447 );
00448 
00449 
00454 class H323Transport : public PIndirectChannel
00455 {
00456   PCLASSINFO(H323Transport, PIndirectChannel);
00457 
00458   public:
00463     H323Transport(H323EndPoint & endpoint);
00464     ~H323Transport();
00466 
00469     virtual void PrintOn(
00470       ostream & strm
00471     ) const;
00473 
00478     virtual H323TransportAddress GetLocalAddress() const = 0;
00479 
00482     virtual H323TransportAddress GetRemoteAddress() const = 0;
00483 
00489     virtual BOOL SetRemoteAddress(
00490       const H323TransportAddress & address
00491     ) = 0;
00492 
00495     virtual BOOL Connect() = 0;
00496 
00499     BOOL ConnectTo(
00500       const H323TransportAddress & address
00501     ) { return SetRemoteAddress(address) && Connect(); }
00502 
00505     virtual BOOL Close();
00506 
00509     virtual BOOL IsCompatibleTransport(
00510       const H225_TransportAddress & pdu
00511     ) const;
00512 
00515     virtual void SetUpTransportPDU(
00516       H225_TransportAddress & pdu,
00517       BOOL localTsap,
00518           H323Connection * connection = NULL
00519     ) const;
00520 
00521     enum {
00522       UseLocalTSAP = 0x10001,
00523       UseRemoteTSAP
00524     };
00525 
00530     virtual void SetUpTransportPDU(
00531       H245_TransportAddress & pdu,
00532       unsigned tsap
00533     ) const;
00534 
00536     enum PromisciousModes {
00537       AcceptFromRemoteOnly,
00538       AcceptFromAnyAutoSet,
00539       AcceptFromAny,
00540       AcceptFromLastReceivedOnly,
00541       NumPromisciousModes
00542     };
00543 
00554     virtual void SetPromiscuous(
00555       PromisciousModes promiscuous
00556     );
00557 
00562     virtual H323TransportAddress GetLastReceivedAddress() const;
00563 
00569     virtual BOOL ReadPDU(
00570       PBYTEArray & pdu   
00571     ) = 0;
00572 
00577     virtual BOOL ExtractPDU(
00578       const PBYTEArray & pdu, 
00579       PINDEX & len
00580     ) = 0;
00581 
00587     virtual BOOL WritePDU(
00588       const PBYTEArray & pdu  
00589     ) = 0;
00591 
00596     BOOL HandleSignallingSocket(H323SignalPDU & pdu);
00597 
00601     BOOL HandleFirstSignallingChannelPDU();
00603 
00611     virtual H323Transport * CreateControlChannel(
00612       H323Connection & connection
00613     );
00614 
00619     virtual BOOL AcceptControlChannel(
00620       H323Connection & connection
00621     );
00622 
00625     virtual void StartControlChannel(
00626       H323Connection & connection
00627     );
00629 
00636     virtual BOOL DiscoverGatekeeper(
00637       H323Gatekeeper & gk,                  
00638       H323RasPDU & pdu,                     
00639       const H323TransportAddress & address  
00640     );
00642 
00643 
00648     H323EndPoint & GetEndPoint() const { return endpoint; }
00649 
00652     void AttachThread(
00653       PThread * thread
00654     );
00655 
00658     void CleanUpOnTermination();
00660 
00661   protected:
00662     H323EndPoint & endpoint;    
00663     PThread      * thread;      
00664     BOOL canGetInterface;
00665 };
00666 
00667 
00668 
00670 // Transport classes for IP
00671 
00675 class H323TransportIP : public H323Transport
00676 {
00677   PCLASSINFO(H323TransportIP, H323Transport);
00678 
00679   public:
00682     H323TransportIP(
00683       H323EndPoint & endpoint,    
00684       PIPSocket::Address binding, 
00685       WORD remPort                
00686     );
00687 
00690     virtual H323TransportAddress GetLocalAddress() const;
00691 
00694     virtual H323TransportAddress GetRemoteAddress() const;
00695 
00698     virtual BOOL IsCompatibleTransport(
00699       const H225_TransportAddress & pdu
00700     ) const;
00701 
00704     virtual void SetUpTransportPDU(
00705       H225_TransportAddress & pdu,
00706       BOOL localTsap,
00707           H323Connection * connection = NULL
00708     ) const;
00709 
00712     virtual void SetUpTransportPDU(
00713       H245_TransportAddress & pdu,
00714       unsigned tsap
00715     ) const;
00716 
00717 
00718   protected:
00719     PIPSocket::Address localAddress;  // Address of the local interface
00720     WORD               localPort;
00721     PIPSocket::Address remoteAddress; // Address of the remote host
00722     WORD               remotePort;
00723 };
00724 
00725 
00727 // Transport classes for TCP/IP
00728 
00731 class H323ListenerTCP : public H323Listener
00732 {
00733   PCLASSINFO(H323ListenerTCP, H323Listener);
00734 
00735   public:
00738     H323ListenerTCP(
00739       H323EndPoint & endpoint,    
00740       PIPSocket::Address binding, 
00741       WORD port,                  
00742       BOOL exclusive = FALSE      
00743     );
00744 
00747     ~H323ListenerTCP();
00748     
00749   // Overrides from H323Listener
00752     virtual BOOL Open();
00753 
00756     virtual BOOL Close();
00757 
00760     virtual H323Transport * Accept(
00761       const PTimeInterval & timeout  
00762     );
00763 
00766     virtual H323TransportAddress GetTransportAddress() const;
00767 
00770     virtual BOOL SetUpTransportPDU(
00771       H245_TransportAddress & pdu,        
00772       const H323Transport & associatedTransport 
00773     );
00774 
00775     WORD GetListenerPort() const { return listener.GetPort(); }
00776 
00777 
00778   protected:
00787     virtual void Main();
00788 
00789 
00790     PTCPSocket listener;
00791     PIPSocket::Address localAddress;
00792     BOOL exclusiveListener;
00793 };
00794 
00795 
00798 class H323TransportTCP : public H323TransportIP
00799 {
00800   PCLASSINFO(H323TransportTCP, H323TransportIP);
00801 
00802   public:
00805     H323TransportTCP(
00806       H323EndPoint & endpoint,    
00807       PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(), 
00808       BOOL listen = FALSE         
00809     );
00810 
00813     ~H323TransportTCP();
00814 
00820     virtual BOOL SetRemoteAddress(
00821       const H323TransportAddress & address
00822     );
00823 
00826     virtual BOOL Connect();
00827 
00830     virtual BOOL Close();
00831 
00837     BOOL ReadPDU(
00838       PBYTEArray & pdu   
00839     );
00840 
00843     BOOL ExtractPDU(
00844       const PBYTEArray & pdu, 
00845       PINDEX & len
00846     );
00847  
00853     BOOL WritePDU(
00854       const PBYTEArray & pdu  
00855     );
00856 
00861     virtual H323Transport * CreateControlChannel(
00862       H323Connection & connection
00863     );
00864 
00869     virtual BOOL AcceptControlChannel(
00870       H323Connection & connection
00871     );
00872 
00875     virtual BOOL IsListening() const;
00876 
00877 
00878   protected:
00888     virtual BOOL OnOpen();
00889 
00890 
00891     PTCPSocket * h245listener;
00892 };
00893 
00894 
00896 // Transport classes for UDP/IP
00897 
00900 class H323TransportUDP : public H323TransportIP
00901 {
00902   PCLASSINFO(H323TransportUDP, H323TransportIP);
00903 
00904   public:
00907     H323TransportUDP(
00908       H323EndPoint & endpoint,                  
00909       PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),  
00910       WORD localPort = 0,                       
00911       WORD remotePort = 0                       
00912     );
00913     ~H323TransportUDP();
00914 
00920     virtual BOOL SetRemoteAddress(
00921       const H323TransportAddress & address
00922     );
00923 
00926     virtual BOOL Connect();
00927 
00939     virtual void SetPromiscuous(
00940       PromisciousModes promiscuous
00941     );
00942 
00947     virtual H323TransportAddress GetLastReceivedAddress() const;
00948 
00954     virtual BOOL ReadPDU(
00955       PBYTEArray & pdu   
00956     );
00957 
00960     BOOL ExtractPDU(
00961       const PBYTEArray & pdu, 
00962       PINDEX & len
00963     );
00964  
00970     virtual BOOL WritePDU(
00971       const PBYTEArray & pdu  
00972     );
00973 
00979     virtual BOOL DiscoverGatekeeper(
00980       H323Gatekeeper & gk,                  
00981       H323RasPDU & pdu,                     
00982       const H323TransportAddress & address  
00983     );
00984 
00987     virtual H323TransportAddress GetLocalAddress() const;
00988 
00989   protected:
00990     PromisciousModes     promiscuousReads;
00991     H323TransportAddress lastReceivedAddress;
00992     PIPSocket::Address   lastReceivedInterface;
00993     WORD interfacePort;
00994 };
00995 
00996 
00997 #endif // __TRANSPORTS_H
00998 
00999 

Generated on Thu Oct 25 13:42:37 2007 for h323plus by  doxygen 1.5.2