Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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.45.2.1  2005/02/07 00:41:31  csoutheren
00031  * Backported patches from Atlas-devel
00032  *
00033  * Revision 1.46  2005/01/16 20:39:43  csoutheren
00034  * Fixed problem with IPv6 INADDR_ANY
00035  *
00036  * Revision 1.45  2004/08/24 08:11:25  csoutheren
00037  * Added initial support for receiving broadcasts on Linux
00038  *
00039  * Revision 1.44  2004/05/13 02:26:13  dereksmithies
00040  * Fixes so make docs does not generate warning messages about brackets.
00041  *
00042  * Revision 1.43  2003/12/29 13:28:45  dominance
00043  * fixed docbook syntax trying to generate LaTeX formula with ip$10.x.x.x.
00044  *
00045  * Revision 1.42  2003/04/10 09:44:55  robertj
00046  * Added associated transport to new GetInterfaceAddresses() function so
00047  *   interfaces can be ordered according to active transport links. Improves
00048  *   interoperability.
00049  * Replaced old listener GetTransportPDU() with GetInterfaceAddresses()
00050  *   and H323SetTransportAddresses() functions.
00051  *
00052  * Revision 1.41  2003/04/10 01:03:25  craigs
00053  * Added functions to access to lists of interfaces
00054  *
00055  * Revision 1.40  2003/03/21 05:24:02  robertj
00056  * Added setting of remote port in UDP transport constructor.
00057  *
00058  * Revision 1.39  2003/02/06 04:29:23  robertj
00059  * Added more support for adding things to H323TransportAddressArrays
00060  *
00061  * Revision 1.38  2002/11/21 06:39:56  robertj
00062  * Changed promiscuous mode to be three way. Fixes race condition in gkserver
00063  *   which can cause crashes or more PDUs to be sent to the wrong place.
00064  *
00065  * Revision 1.37  2002/11/10 08:10:43  robertj
00066  * Moved constants for "well known" ports to better place (OPAL change).
00067  *
00068  * Revision 1.36  2002/09/16 01:14:15  robertj
00069  * Added #define so can select if #pragma interface/implementation is used on
00070  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00071  *
00072  * Revision 1.35  2002/07/22 09:40:15  robertj
00073  * Added ability to automatically convert string arrays, lists sorted lists
00074  *   directly to H323TransportAddressArray.
00075  *
00076  * Revision 1.34  2002/07/02 10:02:29  robertj
00077  * Added H323TransportAddress::GetIpAddress() so don't have to provide port
00078  *   when you don't need it as in GetIpAndPort(),.
00079  *
00080  * Revision 1.33  2002/06/28 03:34:25  robertj
00081  * Fixed issues with address translation on gatekeeper RAS channel.
00082  *
00083  * Revision 1.32  2002/06/12 03:51:59  robertj
00084  * Added function to compare two transport addresses in a more intelligent
00085  *   way that strict string comparison. Takes into account wildcarding.
00086  *
00087  * Revision 1.31  2002/02/11 04:20:25  robertj
00088  * Fixed documentation errors, thanks Horacio J. Peņa
00089  *
00090  * Revision 1.30  2002/02/05 23:29:23  robertj
00091  * Changed default for H.323 listener to reuse addresses.
00092  *
00093  * Revision 1.29  2001/12/22 01:48:12  robertj
00094  * Added ability to use local and remote port from transport channel as well
00095  *   as explicit port in H.245 address PDU setting routine.
00096  * Added PrintOn() to listener and transport for tracing purposes.
00097  *
00098  * Revision 1.28  2001/07/17 04:44:29  robertj
00099  * Partial implementation of T.120 and T.38 logical channels.
00100  *
00101  * Revision 1.27  2001/06/25 02:30:46  robertj
00102  * Allowed TCP listener socket to be opened in non-exclusive mode
00103  *   (ie SO_REUSEADDR) to avoid daemon restart problems.
00104  *
00105  * Revision 1.26  2001/06/22 00:14:14  robertj
00106  * Added ConnectTo() function to conencto specific address.
00107  * Added promiscuous mode for UDP channel.
00108  *
00109  * Revision 1.25  2001/05/17 06:37:02  robertj
00110  * Added multicast gatekeeper discovery support.
00111  *
00112  * Revision 1.24  2001/04/09 08:43:39  robertj
00113  * Added ability to get transport address for a listener.
00114  *
00115  * Revision 1.23  2001/03/02 06:59:57  robertj
00116  * Enhanced the globally unique identifier class.
00117  *
00118  * Revision 1.22  2001/02/09 05:16:24  robertj
00119  * Added #pragma interface for GNU C++.
00120  *
00121  * Revision 1.21  2001/01/23 05:08:04  robertj
00122  * Fixed bug when trying to clear call while waiting on H.245 channel connect, thanks Yura Aksyonov.
00123  *
00124  * Revision 1.20  2000/10/20 06:18:58  robertj
00125  * Fixed very small race condition on creating new connectionon incoming call.
00126  * Fixed memory/socket leak if do TCP connect and don't send valid setup PDU.
00127  *
00128  * Revision 1.19  2000/10/04 05:59:09  robertj
00129  * Minor reorganisation of the H.245 secondary channel start up to make it simpler
00130  *    to override its behaviour.
00131  *
00132  * Revision 1.18  2000/09/25 12:59:16  robertj
00133  * Added StartListener() function that takes a H323TransportAddress to start
00134  *     listeners bound to specific interfaces.
00135  *
00136  * Revision 1.17  2000/09/22 01:35:03  robertj
00137  * Added support for handling LID's that only do symmetric codecs.
00138  *
00139  * Revision 1.16  2000/06/07 05:47:55  robertj
00140  * Added call forwarding.
00141  *
00142  * Revision 1.15  2000/05/22 05:21:36  robertj
00143  * Fixed race condition where controlChannel variable could be used before set.
00144  *
00145  * Revision 1.14  2000/05/18 11:53:34  robertj
00146  * Changes to support doc++ documentation generation.
00147  *
00148  * Revision 1.13  2000/05/08 14:07:26  robertj
00149  * Improved the provision and detection of calling and caller numbers, aliases and hostnames.
00150  *
00151  * Revision 1.12  2000/05/02 04:32:25  robertj
00152  * Fixed copyright notice comment.
00153  *
00154  * Revision 1.11  1999/11/06 05:37:44  robertj
00155  * Complete rewrite of termination of connection to avoid numerous race conditions.
00156  *
00157  * Revision 1.10  1999/10/16 03:47:57  robertj
00158  * Fixed termination of gatekeeper RAS thread problem
00159  *
00160  * Revision 1.9  1999/10/10 08:59:47  robertj
00161  * Fixed race condition in connection shutdown
00162  *
00163  * Revision 1.8  1999/09/14 06:52:54  robertj
00164  * Added better support for multi-homed client hosts.
00165  *
00166  * Revision 1.7  1999/09/10 09:43:59  robertj
00167  * Removed attempt at determining local interface for gatekeeper, so still has problem on multi-homed hosts.
00168  *
00169  * Revision 1.6  1999/08/31 12:34:18  robertj
00170  * Added gatekeeper support.
00171  *
00172  * Revision 1.5  1999/08/25 05:14:21  robertj
00173  * Fixed problem with calling modal dialog from a background thread.
00174  *
00175  * Revision 1.4  1999/07/14 06:06:14  robertj
00176  * Fixed termination problems (race conditions) with deleting connection object.
00177  *
00178  * Revision 1.3  1999/07/09 06:09:49  robertj
00179  * Major implementation. An ENORMOUS amount of stuff added everywhere.
00180  *
00181  * Revision 1.2  1999/06/13 12:41:14  robertj
00182  * Implement logical channel transmitter.
00183  * Fixed H245 connect on receiving call.
00184  *
00185  * Revision 1.1  1999/06/09 05:26:20  robertj
00186  * Major restructuring of classes.
00187  *
00188  */
00189 
00190 #ifndef __TRANSPORTS_H
00191 #define __TRANSPORTS_H
00192 
00193 #ifdef P_USE_PRAGMA
00194 #pragma interface
00195 #endif
00196 
00197 
00198 #include <ptlib/sockets.h>
00199 
00200 
00201 class H225_Setup_UUIE;
00202 class H225_TransportAddress;
00203 class H225_ArrayOf_TransportAddress;
00204 class H225_TransportAddress_ipAddress;
00205 
00206 class H245_TransportAddress;
00207 
00208 class H323SignalPDU;
00209 class H323RasPDU;
00210 class H323EndPoint;
00211 class H323Connection;
00212 class H323Listener;
00213 class H323Transport;
00214 class H323Gatekeeper;
00215 
00216 
00217 
00219 
00223 class H323TransportAddress : public PString
00224 {
00225   PCLASSINFO(H323TransportAddress, PString);
00226   public:
00227     H323TransportAddress() { }
00228     H323TransportAddress(const char *);
00229     H323TransportAddress(const PString &);
00230     H323TransportAddress(const H225_TransportAddress &);
00231     H323TransportAddress(const H245_TransportAddress &);
00232     H323TransportAddress(const PIPSocket::Address &, WORD);
00233 
00234     BOOL SetPDU(H225_TransportAddress & pdu) const;
00235     BOOL SetPDU(H245_TransportAddress & pdu) const;
00236 
00239     BOOL IsEquivalent(
00240       const H323TransportAddress & address
00241     );
00242 
00246     BOOL GetIpAddress(
00247       PIPSocket::Address & ip
00248     ) const;
00249 
00253     BOOL GetIpAndPort(
00254       PIPSocket::Address & ip,
00255       WORD & port,
00256       const char * proto = "tcp"
00257     ) const;
00258 
00262     PString GetHostName() const;
00263 
00274     H323Listener * CreateListener(
00275       H323EndPoint & endpoint   
00276     ) const;
00277 
00284     H323Listener * CreateCompatibleListener(
00285       H323EndPoint & endpoint   
00286     ) const;
00287 
00290     H323Transport * CreateTransport(
00291       H323EndPoint & endpoint   
00292     ) const;
00293 
00294   protected:
00295     void Validate();
00296 };
00297 
00298 
00299 PDECLARE_ARRAY(H323TransportAddressArray, H323TransportAddress)
00300 #ifdef DOC_PLUS_PLUS
00301 {
00302 #endif
00303   public:
00304     H323TransportAddressArray(
00305       const H323TransportAddress & address
00306     ) { AppendAddress(address); }
00307     H323TransportAddressArray(
00308       const H225_ArrayOf_TransportAddress & addresses
00309     );
00310     H323TransportAddressArray(
00311       const PStringArray & array
00312     ) { AppendStringCollection(array); }
00313     H323TransportAddressArray(
00314       const PStringList & list
00315     ) { AppendStringCollection(list); }
00316     H323TransportAddressArray(
00317       const PSortedStringList & list
00318     ) { AppendStringCollection(list); }
00319 
00320     void AppendString(
00321       const char * address
00322     );
00323     void AppendString(
00324       const PString & address
00325     );
00326     void AppendAddress(
00327       const H323TransportAddress & address
00328     );
00329 
00330   protected:
00331     void AppendStringCollection(
00332       const PCollection & coll
00333     );
00334 };
00335 
00336 
00349 class H323Listener : public PThread
00350 {
00351   PCLASSINFO(H323Listener, PThread);
00352 
00353   public:
00358     H323Listener(
00359       H323EndPoint & endpoint      
00360     );
00362 
00365     virtual void PrintOn(
00366       ostream & strm
00367     ) const;
00369 
00374     virtual BOOL Open() = 0;
00375 
00378     virtual BOOL Close() = 0;
00379 
00382     virtual H323Transport * Accept(
00383       const PTimeInterval & timeout  
00384     ) = 0;
00385 
00388     virtual H323TransportAddress GetTransportAddress() const = 0;
00389 
00392     virtual BOOL SetUpTransportPDU(
00393       H245_TransportAddress & pdu,         
00394       const H323Transport & associatedTransport 
00395     ) = 0;
00397 
00398   protected:
00399     H323EndPoint & endpoint;  
00400 };
00401 
00402 
00403 PLIST(H323ListenerList, H323Listener);
00404 
00405 
00408 H323TransportAddressArray H323GetInterfaceAddresses(
00409   const H323ListenerList & listeners, 
00410   BOOL excludeLocalHost = TRUE,       
00411   H323Transport * associatedTransport = NULL
00413 );
00414 
00415 H323TransportAddressArray H323GetInterfaceAddresses(
00416   const H323TransportAddress & addr,  
00417   BOOL excludeLocalHost = TRUE,       
00418   H323Transport * associatedTransport = NULL
00420 );
00421 
00424 void H323SetTransportAddresses(
00425   const H323Transport & associatedTransport,   
00426   const H323TransportAddressArray & addresses, 
00427   H225_ArrayOf_TransportAddress & pdu          
00428 );
00429 
00430 
00435 class H323Transport : public PIndirectChannel
00436 {
00437   PCLASSINFO(H323Transport, PIndirectChannel);
00438 
00439   public:
00444     H323Transport(H323EndPoint & endpoint);
00445     ~H323Transport();
00447 
00450     virtual void PrintOn(
00451       ostream & strm
00452     ) const;
00454 
00459     virtual H323TransportAddress GetLocalAddress() const = 0;
00460 
00463     virtual H323TransportAddress GetRemoteAddress() const = 0;
00464 
00470     virtual BOOL SetRemoteAddress(
00471       const H323TransportAddress & address
00472     ) = 0;
00473 
00476     virtual BOOL Connect() = 0;
00477 
00480     BOOL ConnectTo(
00481       const H323TransportAddress & address
00482     ) { return SetRemoteAddress(address) && Connect(); }
00483 
00486     virtual BOOL Close();
00487 
00490     virtual BOOL IsCompatibleTransport(
00491       const H225_TransportAddress & pdu
00492     ) const;
00493 
00496     virtual void SetUpTransportPDU(
00497       H225_TransportAddress & pdu,
00498       BOOL localTsap
00499     ) const;
00500 
00501     enum {
00502       UseLocalTSAP = 0x10001,
00503       UseRemoteTSAP
00504     };
00505 
00510     virtual void SetUpTransportPDU(
00511       H245_TransportAddress & pdu,
00512       unsigned tsap
00513     ) const;
00514 
00516     enum PromisciousModes {
00517       AcceptFromRemoteOnly,
00518       AcceptFromAnyAutoSet,
00519       AcceptFromAny,
00520       NumPromisciousModes
00521     };
00522 
00533     virtual void SetPromiscuous(
00534       PromisciousModes promiscuous
00535     );
00536 
00541     virtual H323TransportAddress GetLastReceivedAddress() const;
00542 
00548     virtual BOOL ReadPDU(
00549       PBYTEArray & pdu   
00550     ) = 0;
00551 
00557     virtual BOOL WritePDU(
00558       const PBYTEArray & pdu  
00559     ) = 0;
00561 
00567     BOOL HandleFirstSignallingChannelPDU();
00569 
00577     virtual H323Transport * CreateControlChannel(
00578       H323Connection & connection
00579     );
00580 
00585     virtual BOOL AcceptControlChannel(
00586       H323Connection & connection
00587     );
00588 
00591     virtual void StartControlChannel(
00592       H323Connection & connection
00593     );
00595 
00602     virtual BOOL DiscoverGatekeeper(
00603       H323Gatekeeper & gk,                  
00604       H323RasPDU & pdu,                     
00605       const H323TransportAddress & address  
00606     );
00608 
00609 
00614     H323EndPoint & GetEndPoint() const { return endpoint; }
00615 
00618     void AttachThread(
00619       PThread * thread
00620     );
00621 
00624     void CleanUpOnTermination();
00626 
00627   protected:
00628     H323EndPoint & endpoint;    
00629     PThread      * thread;      
00630     BOOL canGetInterface;
00631 };
00632 
00633 
00634 
00636 // Transport classes for IP
00637 
00641 class H323TransportIP : public H323Transport
00642 {
00643   PCLASSINFO(H323TransportIP, H323Transport);
00644 
00645   public:
00648     H323TransportIP(
00649       H323EndPoint & endpoint,    
00650       PIPSocket::Address binding, 
00651       WORD remPort                
00652     );
00653 
00656     virtual H323TransportAddress GetLocalAddress() const;
00657 
00660     virtual H323TransportAddress GetRemoteAddress() const;
00661 
00664     virtual BOOL IsCompatibleTransport(
00665       const H225_TransportAddress & pdu
00666     ) const;
00667 
00670     virtual void SetUpTransportPDU(
00671       H225_TransportAddress & pdu,
00672       BOOL localTsap
00673     ) const;
00674 
00677     virtual void SetUpTransportPDU(
00678       H245_TransportAddress & pdu,
00679       unsigned tsap
00680     ) const;
00681 
00682 
00683   protected:
00684     PIPSocket::Address localAddress;  // Address of the local interface
00685     WORD               localPort;
00686     PIPSocket::Address remoteAddress; // Address of the remote host
00687     WORD               remotePort;
00688 };
00689 
00690 
00692 // Transport classes for TCP/IP
00693 
00696 class H323ListenerTCP : public H323Listener
00697 {
00698   PCLASSINFO(H323ListenerTCP, H323Listener);
00699 
00700   public:
00703     H323ListenerTCP(
00704       H323EndPoint & endpoint,    
00705       PIPSocket::Address binding, 
00706       WORD port,                  
00707       BOOL exclusive = FALSE      
00708     );
00709 
00712     ~H323ListenerTCP();
00713     
00714   // Overrides from H323Listener
00717     virtual BOOL Open();
00718 
00721     virtual BOOL Close();
00722 
00725     virtual H323Transport * Accept(
00726       const PTimeInterval & timeout  
00727     );
00728 
00731     virtual H323TransportAddress GetTransportAddress() const;
00732 
00735     virtual BOOL SetUpTransportPDU(
00736       H245_TransportAddress & pdu,        
00737       const H323Transport & associatedTransport 
00738     );
00739 
00740     WORD GetListenerPort() const { return listener.GetPort(); }
00741 
00742 
00743   protected:
00752     virtual void Main();
00753 
00754 
00755     PTCPSocket listener;
00756     PIPSocket::Address localAddress;
00757     BOOL exclusiveListener;
00758 };
00759 
00760 
00763 class H323TransportTCP : public H323TransportIP
00764 {
00765   PCLASSINFO(H323TransportTCP, H323TransportIP);
00766 
00767   public:
00770     H323TransportTCP(
00771       H323EndPoint & endpoint,    
00772       PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(), 
00773       BOOL listen = FALSE         
00774     );
00775 
00778     ~H323TransportTCP();
00779 
00785     virtual BOOL SetRemoteAddress(
00786       const H323TransportAddress & address
00787     );
00788 
00791     virtual BOOL Connect();
00792 
00795     virtual BOOL Close();
00796 
00802     BOOL ReadPDU(
00803       PBYTEArray & pdu   
00804     );
00805 
00811     BOOL WritePDU(
00812       const PBYTEArray & pdu  
00813     );
00814 
00819     virtual H323Transport * CreateControlChannel(
00820       H323Connection & connection
00821     );
00822 
00827     virtual BOOL AcceptControlChannel(
00828       H323Connection & connection
00829     );
00830 
00833     BOOL IsListening() const;
00834 
00835 
00836   protected:
00846     virtual BOOL OnOpen();
00847 
00848 
00849     PTCPSocket * h245listener;
00850 };
00851 
00852 
00854 // Transport classes for UDP/IP
00855 
00858 class H323TransportUDP : public H323TransportIP
00859 {
00860   PCLASSINFO(H323TransportUDP, H323TransportIP);
00861 
00862   public:
00865     H323TransportUDP(
00866       H323EndPoint & endpoint,                  
00867       PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),  
00868       WORD localPort = 0,                       
00869       WORD remotePort = 0                       
00870     );
00871     ~H323TransportUDP();
00872 
00878     virtual BOOL SetRemoteAddress(
00879       const H323TransportAddress & address
00880     );
00881 
00884     virtual BOOL Connect();
00885 
00897     virtual void SetPromiscuous(
00898       PromisciousModes promiscuous
00899     );
00900 
00905     virtual H323TransportAddress GetLastReceivedAddress() const;
00906 
00912     virtual BOOL ReadPDU(
00913       PBYTEArray & pdu   
00914     );
00915 
00921     virtual BOOL WritePDU(
00922       const PBYTEArray & pdu  
00923     );
00924 
00930     virtual BOOL DiscoverGatekeeper(
00931       H323Gatekeeper & gk,                  
00932       H323RasPDU & pdu,                     
00933       const H323TransportAddress & address  
00934     );
00935 
00938     virtual H323TransportAddress GetLocalAddress() const;
00939 
00940   protected:
00941     PromisciousModes     promiscuousReads;
00942     H323TransportAddress lastReceivedAddress;
00943     PIPSocket::Address   lastReceivedInterface;
00944     WORD interfacePort;
00945 };
00946 
00947 
00948 #endif // __TRANSPORTS_H
00949 
00950 

Generated on Tue Mar 15 11:17:08 2005 for OpenH323 by  doxygen 1.4.0