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 #ifndef __TRANSPORTS_H
00204 #define __TRANSPORTS_H
00205
00206 #ifdef P_USE_PRAGMA
00207 #pragma interface
00208 #endif
00209
00210
00211 #include <ptlib/sockets.h>
00212
00213
00214 class H225_Setup_UUIE;
00215 class H225_TransportAddress;
00216 class H225_ArrayOf_TransportAddress;
00217 class H225_TransportAddress_ipAddress;
00218
00219 class H245_TransportAddress;
00220
00221 class H323SignalPDU;
00222 class H323RasPDU;
00223 class H323EndPoint;
00224 class H323Connection;
00225 class H323Listener;
00226 class H323Transport;
00227 class H323Gatekeeper;
00228
00229
00230
00232
00236 class H323TransportAddress : public PString
00237 {
00238 PCLASSINFO(H323TransportAddress, PString);
00239 public:
00240 H323TransportAddress() { }
00241 H323TransportAddress(const char *);
00242 H323TransportAddress(const PString &);
00243 H323TransportAddress(const H225_TransportAddress &);
00244 H323TransportAddress(const H245_TransportAddress &);
00245 H323TransportAddress(const PIPSocket::Address &, WORD);
00246
00247 BOOL SetPDU(H225_TransportAddress & pdu) const;
00248 BOOL SetPDU(H245_TransportAddress & pdu) const;
00249
00252 BOOL IsEquivalent(
00253 const H323TransportAddress & address
00254 );
00255
00259 BOOL GetIpAddress(
00260 PIPSocket::Address & ip
00261 ) const;
00262
00266 BOOL GetIpAndPort(
00267 PIPSocket::Address & ip,
00268 WORD & port,
00269 const char * proto = "tcp"
00270 ) const;
00271
00275 PString GetHostName() const;
00276
00287 H323Listener * CreateListener(
00288 H323EndPoint & endpoint
00289 ) const;
00290
00297 H323Listener * CreateCompatibleListener(
00298 H323EndPoint & endpoint
00299 ) const;
00300
00303 H323Transport * CreateTransport(
00304 H323EndPoint & endpoint
00305 ) const;
00306
00307 protected:
00308 void Validate();
00309 };
00310
00311
00312 PDECLARE_ARRAY(H323TransportAddressArray, H323TransportAddress)
00313 #ifdef DOC_PLUS_PLUS
00314 {
00315 #endif
00316 public:
00317 H323TransportAddressArray(
00318 const H323TransportAddress & address
00319 ) { AppendAddress(address); }
00320 H323TransportAddressArray(
00321 const H225_ArrayOf_TransportAddress & addresses
00322 );
00323 H323TransportAddressArray(
00324 const PStringArray & array
00325 ) { AppendStringCollection(array); }
00326 H323TransportAddressArray(
00327 const PStringList & list
00328 ) { AppendStringCollection(list); }
00329 H323TransportAddressArray(
00330 const PSortedStringList & list
00331 ) { AppendStringCollection(list); }
00332
00333 void AppendString(
00334 const char * address
00335 );
00336 void AppendString(
00337 const PString & address
00338 );
00339 void AppendAddress(
00340 const H323TransportAddress & address
00341 );
00342
00343 protected:
00344 void AppendStringCollection(
00345 const PCollection & coll
00346 );
00347 };
00348
00349
00362 class H323Listener : public PThread
00363 {
00364 PCLASSINFO(H323Listener, PThread);
00365
00366 public:
00371 H323Listener(
00372 H323EndPoint & endpoint
00373 );
00375
00378 virtual void PrintOn(
00379 ostream & strm
00380 ) const;
00382
00387 virtual BOOL Open() = 0;
00388
00391 virtual BOOL Close() = 0;
00392
00395 virtual H323Transport * Accept(
00396 const PTimeInterval & timeout
00397 ) = 0;
00398
00401 virtual H323TransportAddress GetTransportAddress() const = 0;
00402
00405 virtual BOOL SetUpTransportPDU(
00406 H245_TransportAddress & pdu,
00407 const H323Transport & associatedTransport
00408 ) = 0;
00410
00411 protected:
00412 H323EndPoint & endpoint;
00413 };
00414
00415
00416 PLIST(H323ListenerList, H323Listener);
00417
00418
00421 H323TransportAddressArray H323GetInterfaceAddresses(
00422 const H323ListenerList & listeners,
00423 BOOL excludeLocalHost = TRUE,
00424 H323Transport * associatedTransport = NULL
00426 );
00427
00428 H323TransportAddressArray H323GetInterfaceAddresses(
00429 const H323TransportAddress & addr,
00430 BOOL excludeLocalHost = TRUE,
00431 H323Transport * associatedTransport = NULL
00433 );
00434
00437 void H323SetTransportAddresses(
00438 const H323Transport & associatedTransport,
00439 const H323TransportAddressArray & addresses,
00440 H225_ArrayOf_TransportAddress & pdu
00441 );
00442
00443
00448 class H323Transport : public PIndirectChannel
00449 {
00450 PCLASSINFO(H323Transport, PIndirectChannel);
00451
00452 public:
00457 H323Transport(H323EndPoint & endpoint);
00458 ~H323Transport();
00460
00463 virtual void PrintOn(
00464 ostream & strm
00465 ) const;
00467
00472 virtual H323TransportAddress GetLocalAddress() const = 0;
00473
00476 virtual H323TransportAddress GetRemoteAddress() const = 0;
00477
00483 virtual BOOL SetRemoteAddress(
00484 const H323TransportAddress & address
00485 ) = 0;
00486
00489 virtual BOOL Connect() = 0;
00490
00493 BOOL ConnectTo(
00494 const H323TransportAddress & address
00495 ) { return SetRemoteAddress(address) && Connect(); }
00496
00499 virtual BOOL Close();
00500
00503 virtual BOOL IsCompatibleTransport(
00504 const H225_TransportAddress & pdu
00505 ) const;
00506
00509 virtual void SetUpTransportPDU(
00510 H225_TransportAddress & pdu,
00511 BOOL localTsap
00512 ) const;
00513
00514 enum {
00515 UseLocalTSAP = 0x10001,
00516 UseRemoteTSAP
00517 };
00518
00523 virtual void SetUpTransportPDU(
00524 H245_TransportAddress & pdu,
00525 unsigned tsap
00526 ) const;
00527
00529 enum PromisciousModes {
00530 AcceptFromRemoteOnly,
00531 AcceptFromAnyAutoSet,
00532 AcceptFromAny,
00533 AcceptFromLastReceivedOnly,
00534 NumPromisciousModes
00535 };
00536
00547 virtual void SetPromiscuous(
00548 PromisciousModes promiscuous
00549 );
00550
00555 virtual H323TransportAddress GetLastReceivedAddress() const;
00556
00562 virtual BOOL ReadPDU(
00563 PBYTEArray & pdu
00564 ) = 0;
00565
00570 virtual BOOL ExtractPDU(
00571 const PBYTEArray & pdu,
00572 PINDEX & len
00573 ) = 0;
00574
00580 virtual BOOL WritePDU(
00581 const PBYTEArray & pdu
00582 ) = 0;
00584
00589 BOOL HandleSignallingSocket(H323SignalPDU & pdu);
00590
00594 BOOL HandleFirstSignallingChannelPDU();
00596
00604 virtual H323Transport * CreateControlChannel(
00605 H323Connection & connection
00606 );
00607
00612 virtual BOOL AcceptControlChannel(
00613 H323Connection & connection
00614 );
00615
00618 virtual void StartControlChannel(
00619 H323Connection & connection
00620 );
00622
00629 virtual BOOL DiscoverGatekeeper(
00630 H323Gatekeeper & gk,
00631 H323RasPDU & pdu,
00632 const H323TransportAddress & address
00633 );
00635
00636
00641 H323EndPoint & GetEndPoint() const { return endpoint; }
00642
00645 void AttachThread(
00646 PThread * thread
00647 );
00648
00651 void CleanUpOnTermination();
00653
00654 protected:
00655 H323EndPoint & endpoint;
00656 PThread * thread;
00657 BOOL canGetInterface;
00658 };
00659
00660
00661
00663
00664
00668 class H323TransportIP : public H323Transport
00669 {
00670 PCLASSINFO(H323TransportIP, H323Transport);
00671
00672 public:
00675 H323TransportIP(
00676 H323EndPoint & endpoint,
00677 PIPSocket::Address binding,
00678 WORD remPort
00679 );
00680
00683 virtual H323TransportAddress GetLocalAddress() const;
00684
00687 virtual H323TransportAddress GetRemoteAddress() const;
00688
00691 virtual BOOL IsCompatibleTransport(
00692 const H225_TransportAddress & pdu
00693 ) const;
00694
00697 virtual void SetUpTransportPDU(
00698 H225_TransportAddress & pdu,
00699 BOOL localTsap
00700 ) const;
00701
00704 virtual void SetUpTransportPDU(
00705 H245_TransportAddress & pdu,
00706 unsigned tsap
00707 ) const;
00708
00709
00710 protected:
00711 PIPSocket::Address localAddress;
00712 WORD localPort;
00713 PIPSocket::Address remoteAddress;
00714 WORD remotePort;
00715 };
00716
00717
00719
00720
00723 class H323ListenerTCP : public H323Listener
00724 {
00725 PCLASSINFO(H323ListenerTCP, H323Listener);
00726
00727 public:
00730 H323ListenerTCP(
00731 H323EndPoint & endpoint,
00732 PIPSocket::Address binding,
00733 WORD port,
00734 BOOL exclusive = FALSE
00735 );
00736
00739 ~H323ListenerTCP();
00740
00741
00744 virtual BOOL Open();
00745
00748 virtual BOOL Close();
00749
00752 virtual H323Transport * Accept(
00753 const PTimeInterval & timeout
00754 );
00755
00758 virtual H323TransportAddress GetTransportAddress() const;
00759
00762 virtual BOOL SetUpTransportPDU(
00763 H245_TransportAddress & pdu,
00764 const H323Transport & associatedTransport
00765 );
00766
00767 WORD GetListenerPort() const { return listener.GetPort(); }
00768
00769
00770 protected:
00779 virtual void Main();
00780
00781
00782 PTCPSocket listener;
00783 PIPSocket::Address localAddress;
00784 BOOL exclusiveListener;
00785 };
00786
00787
00790 class H323TransportTCP : public H323TransportIP
00791 {
00792 PCLASSINFO(H323TransportTCP, H323TransportIP);
00793
00794 public:
00797 H323TransportTCP(
00798 H323EndPoint & endpoint,
00799 PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),
00800 BOOL listen = FALSE
00801 );
00802
00805 ~H323TransportTCP();
00806
00812 virtual BOOL SetRemoteAddress(
00813 const H323TransportAddress & address
00814 );
00815
00818 virtual BOOL Connect();
00819
00822 virtual BOOL Close();
00823
00829 BOOL ReadPDU(
00830 PBYTEArray & pdu
00831 );
00832
00835 BOOL ExtractPDU(
00836 const PBYTEArray & pdu,
00837 PINDEX & len
00838 );
00839
00845 BOOL WritePDU(
00846 const PBYTEArray & pdu
00847 );
00848
00853 virtual H323Transport * CreateControlChannel(
00854 H323Connection & connection
00855 );
00856
00861 virtual BOOL AcceptControlChannel(
00862 H323Connection & connection
00863 );
00864
00867 virtual BOOL IsListening() const;
00868
00869
00870 protected:
00880 virtual BOOL OnOpen();
00881
00882
00883 PTCPSocket * h245listener;
00884 };
00885
00886
00888
00889
00892 class H323TransportUDP : public H323TransportIP
00893 {
00894 PCLASSINFO(H323TransportUDP, H323TransportIP);
00895
00896 public:
00899 H323TransportUDP(
00900 H323EndPoint & endpoint,
00901 PIPSocket::Address binding = PIPSocket::GetDefaultIpAny(),
00902 WORD localPort = 0,
00903 WORD remotePort = 0
00904 );
00905 ~H323TransportUDP();
00906
00912 virtual BOOL SetRemoteAddress(
00913 const H323TransportAddress & address
00914 );
00915
00918 virtual BOOL Connect();
00919
00931 virtual void SetPromiscuous(
00932 PromisciousModes promiscuous
00933 );
00934
00939 virtual H323TransportAddress GetLastReceivedAddress() const;
00940
00946 virtual BOOL ReadPDU(
00947 PBYTEArray & pdu
00948 );
00949
00952 BOOL ExtractPDU(
00953 const PBYTEArray & pdu,
00954 PINDEX & len
00955 );
00956
00962 virtual BOOL WritePDU(
00963 const PBYTEArray & pdu
00964 );
00965
00971 virtual BOOL DiscoverGatekeeper(
00972 H323Gatekeeper & gk,
00973 H323RasPDU & pdu,
00974 const H323TransportAddress & address
00975 );
00976
00979 virtual H323TransportAddress GetLocalAddress() const;
00980
00981 protected:
00982 PromisciousModes promiscuousReads;
00983 H323TransportAddress lastReceivedAddress;
00984 PIPSocket::Address lastReceivedInterface;
00985 WORD interfacePort;
00986 };
00987
00988
00989 #endif // __TRANSPORTS_H
00990
00991