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