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 "transports.h"
00095 #include "h235auth.h"
00096
00097 #include <ptclib/asner.h>
00098
00099
00100 class H323TransactionPDU {
00101 public:
00102 H323TransactionPDU();
00103 H323TransactionPDU(const H235Authenticators & auth);
00104
00105 virtual ~H323TransactionPDU() { }
00106
00107 virtual BOOL Read(H323Transport & transport);
00108 virtual BOOL Write(H323Transport & transport);
00109
00110 virtual PASN_Object & GetPDU() = 0;
00111 virtual PASN_Choice & GetChoice() = 0;
00112 virtual const PASN_Object & GetPDU() const = 0;
00113 virtual const PASN_Choice & GetChoice() const = 0;
00114 virtual unsigned GetSequenceNumber() const = 0;
00115 virtual unsigned GetRequestInProgressDelay() const = 0;
00116 #if PTRACING
00117 virtual const char * GetProtocolName() const = 0;
00118 #endif
00119 virtual H323TransactionPDU * ClonePDU() const = 0;
00120 virtual void DeletePDU() = 0;
00121
00122 const H235Authenticators & GetAuthenticators() const { return authenticators; }
00123 void SetAuthenticators(
00124 const H235Authenticators & auth
00125 ) { authenticators = auth; }
00126
00127 H235Authenticator::ValidationResult Validate(
00128 const PASN_Array & clearTokens,
00129 unsigned clearOptionalField,
00130 const PASN_Array & cryptoTokens,
00131 unsigned cryptoOptionalField
00132 ) const { return authenticators.ValidatePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField, rawPDU); }
00133
00134 void Prepare(
00135 PASN_Array & clearTokens,
00136 unsigned clearOptionalField,
00137 PASN_Array & cryptoTokens,
00138 unsigned cryptoOptionalField
00139 ) { authenticators.PreparePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField); }
00140
00141 protected:
00142 H235Authenticators authenticators;
00143 PPER_Stream rawPDU;
00144 };
00145
00146
00148
00149 class H323Transactor : public PObject
00150 {
00151 PCLASSINFO(H323Transactor, PObject);
00152 public:
00155
00158 H323Transactor(
00159 H323EndPoint & endpoint,
00160 H323Transport * transport,
00161 WORD localPort,
00162 WORD remotePort
00163 );
00164 H323Transactor(
00165 H323EndPoint & endpoint,
00166 const H323TransportAddress & iface,
00167 WORD localPort,
00168 WORD remotePort
00169 );
00170
00173 ~H323Transactor();
00175
00180 void PrintOn(
00181 ostream & strm
00182 ) const;
00184
00189 BOOL SetTransport(
00190 const H323TransportAddress & iface
00191 );
00192
00195 H323TransportAddressArray GetInterfaceAddresses(
00196 BOOL excludeLocalHost = TRUE,
00197 H323Transport * associatedTransport = NULL
00199 );
00200
00203 virtual BOOL StartChannel();
00204
00208 virtual void StopChannel();
00209
00212 virtual H323TransactionPDU * CreateTransactionPDU() const = 0;
00213
00216 virtual BOOL HandleTransaction(
00217 const PASN_Object & rawPDU
00218 ) = 0;
00219
00222 virtual void OnSendingPDU(
00223 PASN_Object & rawPDU
00224 ) = 0;
00225
00228 virtual BOOL WritePDU(
00229 H323TransactionPDU & pdu
00230 );
00231
00234 virtual BOOL WriteTo(
00235 H323TransactionPDU & pdu,
00236 const H323TransportAddressArray & addresses,
00237 BOOL callback = TRUE
00238 );
00240
00245 H323EndPoint & GetEndPoint() const { return endpoint; }
00246
00249 H323Transport & GetTransport() const { return *transport; }
00250
00253 void SetCheckResponseCryptoTokens(
00254 BOOL value
00255 ) { checkResponseCryptoTokens = value; }
00256
00259 BOOL GetCheckResponseCryptoTokens() { return checkResponseCryptoTokens; }
00261
00262 protected:
00263 void Construct();
00264
00265 unsigned GetNextSequenceNumber();
00266 BOOL SetUpCallSignalAddresses(
00267 H225_ArrayOf_TransportAddress & addresses
00268 );
00269
00270
00271 PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions);
00272
00273 class Request : public PObject
00274 {
00275 PCLASSINFO(Request, PObject);
00276 public:
00277 Request(
00278 unsigned seqNum,
00279 H323TransactionPDU & pdu
00280 );
00281 Request(
00282 unsigned seqNum,
00283 H323TransactionPDU & pdu,
00284 const H323TransportAddressArray & addresses
00285 );
00286
00287 BOOL Poll(H323Transactor &);
00288 void CheckResponse(unsigned, const PASN_Choice *);
00289 void OnReceiveRIP(unsigned milliseconds);
00290
00291
00292 unsigned rejectReason;
00293 void * responseInfo;
00294
00295 H323TransportAddressArray requestAddresses;
00296
00297 unsigned sequenceNumber;
00298 H323TransactionPDU & requestPDU;
00299 PTimeInterval whenResponseExpected;
00300 PSyncPoint responseHandled;
00301 PMutex responseMutex;
00302
00303 enum {
00304 AwaitingResponse,
00305 ConfirmReceived,
00306 RejectReceived,
00307 TryAlternate,
00308 BadCryptoTokens,
00309 RequestInProgress,
00310 NoResponseReceived
00311 } responseResult;
00312 };
00313
00314 virtual BOOL MakeRequest(
00315 Request & request
00316 );
00317 BOOL CheckForResponse(
00318 unsigned,
00319 unsigned,
00320 const PASN_Choice * = NULL
00321 );
00322 BOOL HandleRequestInProgress(
00323 const H323TransactionPDU & pdu,
00324 unsigned delay
00325 );
00326 BOOL CheckCryptoTokens(
00327 const H323TransactionPDU & pdu,
00328 const PASN_Array & clearTokens,
00329 unsigned clearOptionalField,
00330 const PASN_Array & cryptoTokens,
00331 unsigned cryptoOptionalField
00332 );
00333
00334 void AgeResponses();
00335 BOOL SendCachedResponse(
00336 const H323TransactionPDU & pdu
00337 );
00338
00339 class Response : public PString
00340 {
00341 PCLASSINFO(Response, PString);
00342 public:
00343 Response(const H323TransportAddress & addr, unsigned seqNum);
00344 ~Response();
00345
00346 void SetPDU(const H323TransactionPDU & pdu);
00347 BOOL SendCachedResponse(H323Transport & transport);
00348
00349 PTime lastUsedTime;
00350 PTimeInterval retirementAge;
00351 H323TransactionPDU * replyPDU;
00352 };
00353
00354
00355 H323EndPoint & endpoint;
00356 WORD defaultLocalPort;
00357 WORD defaultRemotePort;
00358 H323Transport * transport;
00359 BOOL checkResponseCryptoTokens;
00360
00361 unsigned nextSequenceNumber;
00362 PMutex nextSequenceNumberMutex;
00363
00364 PDictionary<POrdinalKey, Request> requests;
00365 PMutex requestsMutex;
00366 Request * lastRequest;
00367
00368 PMutex pduWriteMutex;
00369 PSortedList<Response> responses;
00370 };
00371
00372
00374
00375 class H323Transaction : public PObject
00376 {
00377 PCLASSINFO(H323Transaction, PObject);
00378 public:
00383 H323Transaction(
00384 H323Transactor & transactor,
00385 const H323TransactionPDU & requestToCopy,
00386 H323TransactionPDU * confirm,
00387 H323TransactionPDU * reject
00388 );
00389 ~H323Transaction();
00391
00392 enum Response {
00393 Ignore = -2,
00394 Reject = -1,
00395 Confirm = 0
00396 };
00397 inline static Response InProgress(unsigned time) { return (Response)(time&0xffff); }
00398
00399 virtual H323TransactionPDU * CreateRIP(
00400 unsigned sequenceNumber,
00401 unsigned delay
00402 ) const = 0;
00403
00404 BOOL HandlePDU();
00405
00406 virtual BOOL WritePDU(
00407 H323TransactionPDU & pdu
00408 );
00409
00410 BOOL CheckCryptoTokens(
00411 const H235Authenticators & authenticators
00412 );
00413
00414 #if PTRACING
00415 virtual const char * GetName() const = 0;
00416 #endif
00417 virtual H235Authenticator::ValidationResult ValidatePDU() const = 0;
00418 virtual void SetRejectReason(
00419 unsigned reasonCode
00420 ) = 0;
00421
00422 BOOL IsFastResponseRequired() const { return fastResponseRequired && canSendRIP; }
00423 BOOL CanSendRIP() const { return canSendRIP; }
00424 H323TransportAddress GetReplyAddress() const { return replyAddresses[0]; }
00425 const H323TransportAddressArray & GetReplyAddresses() const { return replyAddresses; }
00426 BOOL IsBehindNAT() const { return isBehindNAT; }
00427 H323Transactor & GetTransactor() const { return transactor; }
00428 H235Authenticator::ValidationResult GetAuthenticatorResult() const { return authenticatorResult; }
00429
00430 protected:
00431 virtual Response OnHandlePDU() = 0;
00432 PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler);
00433
00434 H323Transactor & transactor;
00435 unsigned requestSequenceNumber;
00436 H323TransportAddressArray replyAddresses;
00437 BOOL fastResponseRequired;
00438 H323TransactionPDU * request;
00439 H323TransactionPDU * confirm;
00440 H323TransactionPDU * reject;
00441
00442 H235Authenticators authenticators;
00443 H235Authenticator::ValidationResult authenticatorResult;
00444 BOOL isBehindNAT;
00445 BOOL canSendRIP;
00446 };
00447
00448
00450
00451 class H323TransactionServer : public PObject
00452 {
00453 PCLASSINFO(H323TransactionServer, PObject);
00454 public:
00459 H323TransactionServer(
00460 H323EndPoint & endpoint
00461 );
00462
00465 ~H323TransactionServer();
00467
00468 virtual WORD GetDefaultUdpPort() = 0;
00469
00474 H323EndPoint & GetOwnerEndPoint() const { return ownerEndPoint; }
00475
00489 BOOL AddListeners(
00490 const H323TransportAddressArray & ifaces
00491 );
00492
00496 BOOL AddListener(
00497 const H323TransportAddress & interfaceName
00498 );
00499
00506 BOOL AddListener(
00507 H323Transport * transport
00508 );
00509
00516 BOOL AddListener(
00517 H323Transactor * listener
00518 );
00519
00528 virtual H323Transactor * CreateListener(
00529 H323Transport * transport
00530 ) = 0;
00531
00535 BOOL RemoveListener(
00536 H323Transactor * listener
00537 );
00538
00539 BOOL SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress & addresses);
00541
00542 protected:
00543 H323EndPoint & ownerEndPoint;
00544
00545 PThread * monitorThread;
00546 PSyncPoint monitorExit;
00547
00548 PMutex mutex;
00549 PLIST(ListenerList, H323Transactor);
00550 ListenerList listeners;
00551 BOOL usingAllInterfaces;
00552 };
00553
00554
00555 #endif // __OPAL_H323TRANS_H
00556
00557