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 #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
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;
00685 WORD localPort;
00686 PIPSocket::Address remoteAddress;
00687 WORD remotePort;
00688 };
00689
00690
00692
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
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
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