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 #ifndef __OPAL_H323TRANS_H
00085 #define __OPAL_H323TRANS_H
00086
00087 #ifdef P_USE_PRAGMA
00088 #pragma interface
00089 #endif
00090
00091 #include "transports.h"
00092 #include "h235auth.h"
00093
00094 #include <ptclib/asner.h>
00095
00096
00097 class H323TransactionPDU {
00098 public:
00099 H323TransactionPDU();
00100 H323TransactionPDU(const H235Authenticators & auth);
00101
00102 virtual ~H323TransactionPDU() { }
00103
00104 virtual BOOL Read(H323Transport & transport);
00105 virtual BOOL Write(H323Transport & transport);
00106
00107 virtual PASN_Object & GetPDU() = 0;
00108 virtual PASN_Choice & GetChoice() = 0;
00109 virtual const PASN_Object & GetPDU() const = 0;
00110 virtual const PASN_Choice & GetChoice() const = 0;
00111 virtual unsigned GetSequenceNumber() const = 0;
00112 virtual unsigned GetRequestInProgressDelay() const = 0;
00113 #if PTRACING
00114 virtual const char * GetProtocolName() const = 0;
00115 #endif
00116 virtual H323TransactionPDU * ClonePDU() const = 0;
00117 virtual void DeletePDU() = 0;
00118
00119 const H235Authenticators & GetAuthenticators() const { return authenticators; }
00120 void SetAuthenticators(
00121 const H235Authenticators & auth
00122 ) { authenticators = auth; }
00123
00124 H235Authenticator::ValidationResult Validate(
00125 const PASN_Array & clearTokens,
00126 unsigned clearOptionalField,
00127 const PASN_Array & cryptoTokens,
00128 unsigned cryptoOptionalField
00129 ) const { return authenticators.ValidatePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField, rawPDU); }
00130
00131 void Prepare(
00132 PASN_Array & clearTokens,
00133 unsigned clearOptionalField,
00134 PASN_Array & cryptoTokens,
00135 unsigned cryptoOptionalField
00136 ) { authenticators.PreparePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField); }
00137
00138 protected:
00139 H235Authenticators authenticators;
00140 PPER_Stream rawPDU;
00141 };
00142
00143
00145
00146 class H323Transactor : public PObject
00147 {
00148 PCLASSINFO(H323Transactor, PObject);
00149 public:
00152
00155 H323Transactor(
00156 H323EndPoint & endpoint,
00157 H323Transport * transport,
00158 WORD localPort,
00159 WORD remotePort
00160 );
00161 H323Transactor(
00162 H323EndPoint & endpoint,
00163 const H323TransportAddress & iface,
00164 WORD localPort,
00165 WORD remotePort
00166 );
00167
00170 ~H323Transactor();
00172
00177 void PrintOn(
00178 ostream & strm
00179 ) const;
00181
00186 BOOL SetTransport(
00187 const H323TransportAddress & iface
00188 );
00189
00192 H323TransportAddressArray GetInterfaceAddresses(
00193 BOOL excludeLocalHost = TRUE,
00194 H323Transport * associatedTransport = NULL
00196 );
00197
00200 virtual BOOL StartChannel();
00201
00205 virtual void StopChannel();
00206
00209 virtual H323TransactionPDU * CreateTransactionPDU() const = 0;
00210
00213 virtual BOOL HandleTransaction(
00214 const PASN_Object & rawPDU
00215 ) = 0;
00216
00219 virtual void OnSendingPDU(
00220 PASN_Object & rawPDU
00221 ) = 0;
00222
00225 virtual BOOL WritePDU(
00226 H323TransactionPDU & pdu
00227 );
00228
00231 virtual BOOL WriteTo(
00232 H323TransactionPDU & pdu,
00233 const H323TransportAddressArray & addresses,
00234 BOOL callback = TRUE
00235 );
00237
00242 H323EndPoint & GetEndPoint() const { return endpoint; }
00243
00246 H323Transport & GetTransport() const { return *transport; }
00247
00250 void SetCheckResponseCryptoTokens(
00251 BOOL value
00252 ) { checkResponseCryptoTokens = value; }
00253
00256 BOOL GetCheckResponseCryptoTokens() { return checkResponseCryptoTokens; }
00258
00259 protected:
00260 void Construct();
00261
00262 unsigned GetNextSequenceNumber();
00263 BOOL SetUpCallSignalAddresses(
00264 H225_ArrayOf_TransportAddress & addresses
00265 );
00266
00267
00268 PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions);
00269
00270 class Request : public PObject
00271 {
00272 PCLASSINFO(Request, PObject);
00273 public:
00274 Request(
00275 unsigned seqNum,
00276 H323TransactionPDU & pdu
00277 );
00278 Request(
00279 unsigned seqNum,
00280 H323TransactionPDU & pdu,
00281 const H323TransportAddressArray & addresses
00282 );
00283
00284 BOOL Poll(H323Transactor &);
00285 void CheckResponse(unsigned, const PASN_Choice *);
00286 void OnReceiveRIP(unsigned milliseconds);
00287
00288
00289 unsigned rejectReason;
00290 void * responseInfo;
00291
00292 H323TransportAddressArray requestAddresses;
00293
00294 unsigned sequenceNumber;
00295 H323TransactionPDU & requestPDU;
00296 PTimeInterval whenResponseExpected;
00297 PSyncPoint responseHandled;
00298 PMutex responseMutex;
00299
00300 enum {
00301 AwaitingResponse,
00302 ConfirmReceived,
00303 RejectReceived,
00304 TryAlternate,
00305 BadCryptoTokens,
00306 RequestInProgress,
00307 NoResponseReceived
00308 } responseResult;
00309 };
00310
00311 virtual BOOL MakeRequest(
00312 Request & request
00313 );
00314 BOOL CheckForResponse(
00315 unsigned,
00316 unsigned,
00317 const PASN_Choice * = NULL
00318 );
00319 BOOL HandleRequestInProgress(
00320 const H323TransactionPDU & pdu,
00321 unsigned delay
00322 );
00323 BOOL CheckCryptoTokens(
00324 const H323TransactionPDU & pdu,
00325 const PASN_Array & clearTokens,
00326 unsigned clearOptionalField,
00327 const PASN_Array & cryptoTokens,
00328 unsigned cryptoOptionalField
00329 );
00330
00331 void AgeResponses();
00332 BOOL SendCachedResponse(
00333 const H323TransactionPDU & pdu
00334 );
00335
00336 class Response : public PString
00337 {
00338 PCLASSINFO(Response, PString);
00339 public:
00340 Response(const H323TransportAddress & addr, unsigned seqNum);
00341 ~Response();
00342
00343 void SetPDU(const H323TransactionPDU & pdu);
00344 BOOL SendCachedResponse(H323Transport & transport);
00345
00346 PTime lastUsedTime;
00347 PTimeInterval retirementAge;
00348 H323TransactionPDU * replyPDU;
00349 };
00350
00351
00352 H323EndPoint & endpoint;
00353 WORD defaultLocalPort;
00354 WORD defaultRemotePort;
00355 H323Transport * transport;
00356 BOOL checkResponseCryptoTokens;
00357
00358 unsigned nextSequenceNumber;
00359 PMutex nextSequenceNumberMutex;
00360
00361 PDictionary<POrdinalKey, Request> requests;
00362 PMutex requestsMutex;
00363 Request * lastRequest;
00364
00365 PMutex pduWriteMutex;
00366 PSortedList<Response> responses;
00367 };
00368
00369
00371
00372 class H323Transaction : public PObject
00373 {
00374 PCLASSINFO(H323Transaction, PObject);
00375 public:
00380 H323Transaction(
00381 H323Transactor & transactor,
00382 const H323TransactionPDU & requestToCopy,
00383 H323TransactionPDU * confirm,
00384 H323TransactionPDU * reject
00385 );
00386 ~H323Transaction();
00388
00389 enum Response {
00390 Ignore = -2,
00391 Reject = -1,
00392 Confirm = 0
00393 };
00394 inline static Response InProgress(unsigned time) { return (Response)(time&0xffff); }
00395
00396 virtual H323TransactionPDU * CreateRIP(
00397 unsigned sequenceNumber,
00398 unsigned delay
00399 ) const = 0;
00400
00401 BOOL HandlePDU();
00402
00403 virtual BOOL WritePDU(
00404 H323TransactionPDU & pdu
00405 );
00406
00407 BOOL CheckCryptoTokens(
00408 const H235Authenticators & authenticators
00409 );
00410
00411 #if PTRACING
00412 virtual const char * GetName() const = 0;
00413 #endif
00414 virtual H235Authenticator::ValidationResult ValidatePDU() const = 0;
00415 virtual void SetRejectReason(
00416 unsigned reasonCode
00417 ) = 0;
00418
00419 BOOL IsFastResponseRequired() const { return fastResponseRequired && canSendRIP; }
00420 BOOL CanSendRIP() const { return canSendRIP; }
00421 H323TransportAddress GetReplyAddress() const { return replyAddresses[0]; }
00422 const H323TransportAddressArray & GetReplyAddresses() const { return replyAddresses; }
00423 BOOL IsBehindNAT() const { return isBehindNAT; }
00424 H323Transactor & GetTransactor() const { return transactor; }
00425 H235Authenticator::ValidationResult GetAuthenticatorResult() const { return authenticatorResult; }
00426
00427 protected:
00428 virtual Response OnHandlePDU() = 0;
00429 PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler);
00430
00431 H323Transactor & transactor;
00432 unsigned requestSequenceNumber;
00433 H323TransportAddressArray replyAddresses;
00434 BOOL fastResponseRequired;
00435 H323TransactionPDU * request;
00436 H323TransactionPDU * confirm;
00437 H323TransactionPDU * reject;
00438
00439 H235Authenticators authenticators;
00440 H235Authenticator::ValidationResult authenticatorResult;
00441 BOOL isBehindNAT;
00442 BOOL canSendRIP;
00443 };
00444
00445
00447
00448 class H323TransactionServer : public PObject
00449 {
00450 PCLASSINFO(H323TransactionServer, PObject);
00451 public:
00456 H323TransactionServer(
00457 H323EndPoint & endpoint
00458 );
00459
00462 ~H323TransactionServer();
00464
00465 virtual WORD GetDefaultUdpPort() = 0;
00466
00471 H323EndPoint & GetOwnerEndPoint() const { return ownerEndPoint; }
00472
00486 BOOL AddListeners(
00487 const H323TransportAddressArray & ifaces
00488 );
00489
00493 BOOL AddListener(
00494 const H323TransportAddress & interfaceName
00495 );
00496
00503 BOOL AddListener(
00504 H323Transport * transport
00505 );
00506
00513 BOOL AddListener(
00514 H323Transactor * listener
00515 );
00516
00525 virtual H323Transactor * CreateListener(
00526 H323Transport * transport
00527 ) = 0;
00528
00532 BOOL RemoveListener(
00533 H323Transactor * listener
00534 );
00535
00536 BOOL SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress & addresses);
00538
00539 protected:
00540 H323EndPoint & ownerEndPoint;
00541
00542 PThread * monitorThread;
00543 PSyncPoint monitorExit;
00544
00545 PMutex mutex;
00546 PLIST(ListenerList, H323Transactor);
00547 ListenerList listeners;
00548 BOOL usingAllInterfaces;
00549 };
00550
00551
00552 #endif // __OPAL_H323TRANS_H
00553
00554