00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
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
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;
00720 WORD localPort;
00721 PIPSocket::Address remoteAddress;
00722 WORD remotePort;
00723 };
00724
00725
00727
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
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
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