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
#ifndef __TRANSPORTS_H
00182
#define __TRANSPORTS_H
00183
00184
#ifdef P_USE_PRAGMA
00185
#pragma interface
00186
#endif
00187
00188
00189
#include <ptlib/sockets.h>
00190
00191
00192
class H225_Setup_UUIE;
00193
class H225_TransportAddress;
00194
class H225_ArrayOf_TransportAddress;
00195
class H225_TransportAddress_ipAddress;
00196
00197
class H245_TransportAddress;
00198
00199
class H323SignalPDU;
00200
class H323RasPDU;
00201
class H323EndPoint;
00202
class H323Connection;
00203
class H323Listener;
00204
class H323Transport;
00205
class H323Gatekeeper;
00206
00207
00208
00210
00214 class H323TransportAddress :
public PString
00215 {
00216 PCLASSINFO(
H323TransportAddress, PString);
00217
public:
00218 H323TransportAddress() { }
00219
H323TransportAddress(
const char *);
00220
H323TransportAddress(
const PString &);
00221
H323TransportAddress(
const H225_TransportAddress &);
00222
H323TransportAddress(
const H245_TransportAddress &);
00223
H323TransportAddress(
const PIPSocket::Address &, WORD);
00224
00225 BOOL SetPDU(
H225_TransportAddress & pdu)
const;
00226 BOOL SetPDU(
H245_TransportAddress & pdu)
const;
00227
00230 BOOL IsEquivalent(
00231
const H323TransportAddress & address
00232 );
00233
00237 BOOL GetIpAddress(
00238 PIPSocket::Address & ip
00239 )
const;
00240
00244 BOOL GetIpAndPort(
00245 PIPSocket::Address & ip,
00246 WORD & port,
00247
const char * proto =
"tcp"
00248 )
const;
00249
00253 PString
GetHostName() const;
00254
00265
H323Listener * CreateListener(
00266
H323EndPoint & endpoint
00267 ) const;
00268
00275
H323Listener * CreateCompatibleListener(
00276
H323EndPoint & endpoint
00277 ) const;
00278
00281
H323Transport * CreateTransport(
00282
H323EndPoint & endpoint
00283 ) const;
00284
00285 protected:
00286
void Validate();
00287 };
00288
00289
00290 PDECLARE_ARRAY(H323TransportAddressArray,
H323TransportAddress)
00291 #ifdef DOC_PLUS_PLUS
00292 {
00293
#endif
00294
public:
00295 H323TransportAddressArray(
00296
const H323TransportAddress & address
00297 ) { AppendAddress(address); }
00298 H323TransportAddressArray(
00299
const H225_ArrayOf_TransportAddress & addresses
00300 );
00301 H323TransportAddressArray(
00302
const PStringArray & array
00303 ) { AppendStringCollection(array); }
00304 H323TransportAddressArray(
00305
const PStringList & list
00306 ) { AppendStringCollection(list); }
00307 H323TransportAddressArray(
00308
const PSortedStringList & list
00309 ) { AppendStringCollection(list); }
00310
00311
void AppendString(
00312
const char * address
00313 );
00314
void AppendString(
00315
const PString & address
00316 );
00317
void AppendAddress(
00318
const H323TransportAddress & address
00319 );
00320
00321
protected:
00322
void AppendStringCollection(
00323
const PCollection & coll
00324 );
00325 };
00326
00327
00340 class H323Listener :
public PThread
00341 {
00342 PCLASSINFO(
H323Listener, PThread);
00343
00344
public:
00349
H323Listener(
00350
H323EndPoint & endpoint
00351 );
00353
00356
virtual void PrintOn(
00357 ostream & strm
00358 )
const;
00360
00365
virtual BOOL Open() = 0;
00366
00369
virtual BOOL Close() = 0;
00370
00373
virtual H323Transport * Accept(
00374
const PTimeInterval & timeout
00375 ) = 0;
00376
00379
virtual H323TransportAddress GetTransportAddress()
const = 0;
00380
00383
virtual BOOL SetUpTransportPDU(
00384
H245_TransportAddress & pdu,
00385
const H323Transport & associatedTransport
00386 ) = 0;
00388
00389
protected:
00390 H323EndPoint & endpoint;
00391 };
00392
00393
00394
PLIST(H323ListenerList,
H323Listener);
00395
00396
00399 H323TransportAddressArray
H323GetInterfaceAddresses(
00400
const H323ListenerList & listeners,
00401 BOOL excludeLocalHost = TRUE,
00402
H323Transport * associatedTransport = NULL
00404 );
00405
00406 H323TransportAddressArray
H323GetInterfaceAddresses(
00407
const H323TransportAddress & addr,
00408 BOOL excludeLocalHost = TRUE,
00409
H323Transport * associatedTransport = NULL
00411 );
00412
00415
void H323SetTransportAddresses(
00416
const H323Transport & associatedTransport,
00417
const H323TransportAddressArray & addresses,
00418
H225_ArrayOf_TransportAddress & pdu
00419 );
00420
00421
00426 class H323Transport :
public PIndirectChannel
00427 {
00428 PCLASSINFO(
H323Transport, PIndirectChannel);
00429
00430
public:
00435
H323Transport(
H323EndPoint & endpoint);
00436 ~
H323Transport();
00438
00441
virtual void PrintOn(
00442 ostream & strm
00443 )
const;
00445
00450
virtual H323TransportAddress GetLocalAddress()
const = 0;
00451
00454
virtual H323TransportAddress GetRemoteAddress()
const = 0;
00455
00461
virtual BOOL SetRemoteAddress(
00462
const H323TransportAddress & address
00463 ) = 0;
00464
00467
virtual BOOL Connect() = 0;
00468
00471 BOOL ConnectTo(
00472
const H323TransportAddress & address
00473 ) {
return SetRemoteAddress(address) && Connect(); }
00474
00477
virtual BOOL Close();
00478
00481
virtual BOOL IsCompatibleTransport(
00482
const H225_TransportAddress & pdu
00483 )
const;
00484
00487
virtual void SetUpTransportPDU(
00488
H225_TransportAddress & pdu,
00489 BOOL localTsap
00490 )
const;
00491
00492
enum {
00493 UseLocalTSAP = 0x10001,
00494 UseRemoteTSAP
00495 };
00496
00501
virtual void SetUpTransportPDU(
00502
H245_TransportAddress & pdu,
00503
unsigned tsap
00504 )
const;
00505
00507 enum PromisciousModes {
00508 AcceptFromRemoteOnly,
00509 AcceptFromAnyAutoSet,
00510 AcceptFromAny,
00511 NumPromisciousModes
00512 };
00513
00524
virtual void SetPromiscuous(
00525 PromisciousModes promiscuous
00526 );
00527
00532
virtual H323TransportAddress GetLastReceivedAddress() const;
00533
00539 virtual BOOL ReadPDU(
00540 PBYTEArray & pdu
00541 ) = 0;
00542
00548 virtual BOOL WritePDU(
00549 const PBYTEArray & pdu
00550 ) = 0;
00552
00558 BOOL HandleFirstSignallingChannelPDU();
00560
00568 virtual
H323Transport * CreateControlChannel(
00569
H323Connection & connection
00570 );
00571
00576 virtual BOOL AcceptControlChannel(
00577
H323Connection & connection
00578 );
00579
00582 virtual
void StartControlChannel(
00583
H323Connection & connection
00584 );
00586
00593 virtual BOOL DiscoverGatekeeper(
00594
H323Gatekeeper & gk,
00595
H323RasPDU & pdu,
00596 const
H323TransportAddress & address
00597 );
00599
00600
00605 H323EndPoint & GetEndPoint()
const {
return endpoint; }
00606
00609
void AttachThread(
00610 PThread * thread
00611 );
00612
00615
void CleanUpOnTermination();
00617
00618
protected:
00619 H323EndPoint & endpoint;
00620 PThread * thread;
00621 };
00622
00623
00624
00626
00627
00631 class H323TransportIP :
public H323Transport
00632 {
00633 PCLASSINFO(
H323TransportIP,
H323Transport);
00634
00635
public:
00638
H323TransportIP(
00639
H323EndPoint & endpoint,
00640 PIPSocket::Address binding,
00641 WORD remPort
00642 );
00643
00646
virtual H323TransportAddress GetLocalAddress()
const;
00647
00650
virtual H323TransportAddress GetRemoteAddress()
const;
00651
00654
virtual BOOL IsCompatibleTransport(
00655
const H225_TransportAddress & pdu
00656 )
const;
00657
00660
virtual void SetUpTransportPDU(
00661
H225_TransportAddress & pdu,
00662 BOOL localTsap
00663 )
const;
00664
00667
virtual void SetUpTransportPDU(
00668
H245_TransportAddress & pdu,
00669
unsigned tsap
00670 )
const;
00671
00672
00673
protected:
00674 PIPSocket::Address localAddress;
00675 WORD localPort;
00676 PIPSocket::Address remoteAddress;
00677 WORD remotePort;
00678 };
00679
00680
00682
00683
00686 class H323ListenerTCP :
public H323Listener
00687 {
00688 PCLASSINFO(
H323ListenerTCP,
H323Listener);
00689
00690
public:
00693
H323ListenerTCP(
00694
H323EndPoint & endpoint,
00695 PIPSocket::Address binding,
00696 WORD port,
00697 BOOL exclusive = FALSE
00698 );
00699
00702 ~
H323ListenerTCP();
00703
00704
00707
virtual BOOL Open();
00708
00711
virtual BOOL Close();
00712
00715
virtual H323Transport * Accept(
00716
const PTimeInterval & timeout
00717 );
00718
00721
virtual H323TransportAddress GetTransportAddress()
const;
00722
00725
virtual BOOL SetUpTransportPDU(
00726
H245_TransportAddress & pdu,
00727
const H323Transport & associatedTransport
00728 );
00729
00730 WORD GetListenerPort()
const {
return listener.GetPort(); }
00731
00732
00733
protected:
00742
virtual void Main();
00743
00744
00745 PTCPSocket listener;
00746 PIPSocket::Address localAddress;
00747 BOOL exclusiveListener;
00748 };
00749
00750
00753 class H323TransportTCP :
public H323TransportIP
00754 {
00755 PCLASSINFO(
H323TransportTCP,
H323TransportIP);
00756
00757
public:
00760
H323TransportTCP(
00761
H323EndPoint & endpoint,
00762 PIPSocket::Address binding = INADDR_ANY,
00763 BOOL listen = FALSE
00764 );
00765
00768 ~
H323TransportTCP();
00769
00775
virtual BOOL SetRemoteAddress(
00776
const H323TransportAddress & address
00777 );
00778
00781
virtual BOOL Connect();
00782
00785
virtual BOOL Close();
00786
00792 BOOL ReadPDU(
00793 PBYTEArray & pdu
00794 );
00795
00801 BOOL WritePDU(
00802
const PBYTEArray & pdu
00803 );
00804
00809
virtual H323Transport * CreateControlChannel(
00810
H323Connection & connection
00811 );
00812
00817
virtual BOOL AcceptControlChannel(
00818
H323Connection & connection
00819 );
00820
00823 BOOL IsListening()
const;
00824
00825
00826
protected:
00836
virtual BOOL OnOpen();
00837
00838
00839 PTCPSocket * h245listener;
00840 };
00841
00842
00844
00845
00848 class H323TransportUDP :
public H323TransportIP
00849 {
00850 PCLASSINFO(
H323TransportUDP,
H323TransportIP);
00851
00852
public:
00855
H323TransportUDP(
00856
H323EndPoint & endpoint,
00857 PIPSocket::Address binding = INADDR_ANY,
00858 WORD localPort = 0,
00859 WORD remotePort = 0
00860 );
00861 ~
H323TransportUDP();
00862
00868
virtual BOOL SetRemoteAddress(
00869
const H323TransportAddress & address
00870 );
00871
00874
virtual BOOL Connect();
00875
00887
virtual void SetPromiscuous(
00888 PromisciousModes promiscuous
00889 );
00890
00895
virtual H323TransportAddress GetLastReceivedAddress()
const;
00896
00902
virtual BOOL ReadPDU(
00903 PBYTEArray & pdu
00904 );
00905
00911
virtual BOOL WritePDU(
00912
const PBYTEArray & pdu
00913 );
00914
00920
virtual BOOL DiscoverGatekeeper(
00921
H323Gatekeeper & gk,
00922
H323RasPDU & pdu,
00923
const H323TransportAddress & address
00924 );
00925
00926
protected:
00927 PromisciousModes promiscuousReads;
00928 H323TransportAddress lastReceivedAddress;
00929 };
00930
00931
00932
#endif // __TRANSPORTS_H
00933
00934