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 #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
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;
00688 WORD localPort;
00689 PIPSocket::Address remoteAddress;
00690 WORD remotePort;
00691 };
00692
00693
00695
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
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
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