Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

h323trans.h

Go to the documentation of this file.
00001 /* 00002 * h323trans.h 00003 * 00004 * H.323 Transactor handler 00005 * 00006 * Open H323 Library 00007 * 00008 * Copyright (c) 2003 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Open H323 Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Log: h323trans.h,v $ 00027 * Revision 1.15 2003/12/11 05:39:04 csoutheren 00028 * Added storage of H.225 version in endpoint structure 00029 * Disabled sending RIPs to endpoints that cannot handle them 00030 * 00031 * Revision 1.14 2003/04/30 07:50:58 robertj 00032 * Redesigned the alternate credentials in ARQ system as old implementation 00033 * was fraught with concurrency issues, most importantly it can cause false 00034 * detection of replay attacks taking out an endpoint completely. 00035 * 00036 * Revision 1.13 2003/04/10 09:40:05 robertj 00037 * Added associated transport to new GetInterfaceAddresses() function so 00038 * interfaces can be ordered according to active transport links. Improves 00039 * interoperability. 00040 * 00041 * Revision 1.12 2003/04/10 01:03:58 craigs 00042 * Added functions to access to lists of interfaces 00043 * 00044 * Revision 1.11 2003/04/09 03:08:06 robertj 00045 * Fixed race condition in shutting down transactor (pure virtual call) 00046 * 00047 * Revision 1.10 2003/04/01 05:59:30 robertj 00048 * Fixed H.501 transaction code setting members for m_common PDU part. 00049 * 00050 * Revision 1.9 2003/04/01 04:47:48 robertj 00051 * Abstracted H.225 RAS transaction processing (RIP and secondary thread) in 00052 * server environment for use by H.501 peer elements. 00053 * 00054 * Revision 1.8 2003/03/26 00:46:25 robertj 00055 * Had another go at making H323Transactor being able to be created 00056 * without having a listener running. 00057 * 00058 * Revision 1.7 2003/03/25 04:56:17 robertj 00059 * Fixed issues to do with multiple inheritence in transaction reply cache. 00060 * 00061 * Revision 1.6 2003/03/21 05:26:45 robertj 00062 * Added setting of remote port in UDP transport constructor. 00063 * 00064 * Revision 1.5 2003/03/20 01:51:07 robertj 00065 * More abstraction of H.225 RAS and H.501 protocols transaction handling. 00066 * 00067 * Revision 1.4 2003/03/01 00:23:42 craigs 00068 * New PeerElement implementation 00069 * 00070 * Revision 1.3 2003/02/25 06:48:15 robertj 00071 * More work on PDU transaction abstraction. 00072 * 00073 * Revision 1.2 2003/02/25 03:14:58 robertj 00074 * Added missing virtual destructor. 00075 * 00076 * Revision 1.1 2003/02/21 05:28:39 craigs 00077 * Factored out code for user with peer elements 00078 * 00079 */ 00080 00081 #ifndef __OPAL_H323TRANS_H 00082 #define __OPAL_H323TRANS_H 00083 00084 #ifdef P_USE_PRAGMA 00085 #pragma interface 00086 #endif 00087 00088 #include "transports.h" 00089 #include "h235auth.h" 00090 00091 #include <ptclib/asner.h> 00092 00093 00094 class H323TransactionPDU { 00095 public: 00096 H323TransactionPDU(); 00097 H323TransactionPDU(const H235Authenticators & auth); 00098 00099 virtual ~H323TransactionPDU() { } 00100 00101 virtual BOOL Read(H323Transport & transport); 00102 virtual BOOL Write(H323Transport & transport); 00103 00104 virtual PASN_Object & GetPDU() = 0; 00105 virtual PASN_Choice & GetChoice() = 0; 00106 virtual const PASN_Object & GetPDU() const = 0; 00107 virtual const PASN_Choice & GetChoice() const = 0; 00108 virtual unsigned GetSequenceNumber() const = 0; 00109 virtual unsigned GetRequestInProgressDelay() const = 0; 00110 #if PTRACING 00111 virtual const char * GetProtocolName() const = 0; 00112 #endif 00113 virtual H323TransactionPDU * ClonePDU() const = 0; 00114 virtual void DeletePDU() = 0; 00115 00116 const H235Authenticators & GetAuthenticators() const { return authenticators; } 00117 void SetAuthenticators( 00118 const H235Authenticators & auth 00119 ) { authenticators = auth; } 00120 00121 H235Authenticator::ValidationResult Validate( 00122 const PASN_Array & clearTokens, 00123 unsigned clearOptionalField, 00124 const PASN_Array & cryptoTokens, 00125 unsigned cryptoOptionalField 00126 ) const { return authenticators.ValidatePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField, rawPDU); } 00127 00128 void Prepare( 00129 PASN_Array & clearTokens, 00130 unsigned clearOptionalField, 00131 PASN_Array & cryptoTokens, 00132 unsigned cryptoOptionalField 00133 ) { authenticators.PreparePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField); } 00134 00135 protected: 00136 H235Authenticators authenticators; 00137 PPER_Stream rawPDU; 00138 }; 00139 00140 00142 00143 class H323Transactor : public PObject 00144 { 00145 PCLASSINFO(H323Transactor, PObject); 00146 public: 00149 00152 H323Transactor( 00153 H323EndPoint & endpoint, 00154 H323Transport * transport, 00155 WORD localPort, 00156 WORD remotePort 00157 ); 00158 H323Transactor( 00159 H323EndPoint & endpoint, 00160 const H323TransportAddress & iface, 00161 WORD localPort, 00162 WORD remotePort 00163 ); 00164 00167 ~H323Transactor(); 00169 00174 void PrintOn( 00175 ostream & strm 00176 ) const; 00178 00183 BOOL SetTransport( 00184 const H323TransportAddress & iface // Local interface for transport 00185 ); 00186 00189 H323TransportAddressArray GetInterfaceAddresses( 00190 BOOL excludeLocalHost = TRUE, 00191 H323Transport * associatedTransport = NULL 00193 ); 00194 00197 virtual BOOL StartChannel(); 00198 00202 virtual void StopChannel(); 00203 00206 virtual H323TransactionPDU * CreateTransactionPDU() const = 0; 00207 00210 virtual BOOL HandleTransaction( 00211 const PASN_Object & rawPDU 00212 ) = 0; 00213 00216 virtual void OnSendingPDU( 00217 PASN_Object & rawPDU 00218 ) = 0; 00219 00222 virtual BOOL WritePDU( 00223 H323TransactionPDU & pdu 00224 ); 00225 00228 virtual BOOL WriteTo( 00229 H323TransactionPDU & pdu, 00230 const H323TransportAddressArray & addresses, 00231 BOOL callback = TRUE 00232 ); 00234 00239 H323EndPoint & GetEndPoint() const { return endpoint; } 00240 00243 H323Transport & GetTransport() const { return *transport; } 00244 00247 void SetCheckResponseCryptoTokens( 00248 BOOL value 00249 ) { checkResponseCryptoTokens = value; } 00250 00253 BOOL GetCheckResponseCryptoTokens() { return checkResponseCryptoTokens; } 00255 00256 protected: 00257 void Construct(); 00258 00259 unsigned GetNextSequenceNumber(); 00260 BOOL SetUpCallSignalAddresses( 00261 H225_ArrayOf_TransportAddress & addresses 00262 ); 00263 00264 //Background thread handler. 00265 PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions); 00266 00267 class Request : public PObject 00268 { 00269 PCLASSINFO(Request, PObject); 00270 public: 00271 Request( 00272 unsigned seqNum, 00273 H323TransactionPDU & pdu 00274 ); 00275 Request( 00276 unsigned seqNum, 00277 H323TransactionPDU & pdu, 00278 const H323TransportAddressArray & addresses 00279 ); 00280 00281 BOOL Poll(H323Transactor &); 00282 void CheckResponse(unsigned, const PASN_Choice *); 00283 void OnReceiveRIP(unsigned milliseconds); 00284 00285 // Inter-thread transfer variables 00286 unsigned rejectReason; 00287 void * responseInfo; 00288 00289 H323TransportAddressArray requestAddresses; 00290 00291 unsigned sequenceNumber; 00292 H323TransactionPDU & requestPDU; 00293 PTimeInterval whenResponseExpected; 00294 PSyncPoint responseHandled; 00295 PMutex responseMutex; 00296 00297 enum { 00298 AwaitingResponse, 00299 ConfirmReceived, 00300 RejectReceived, 00301 TryAlternate, 00302 BadCryptoTokens, 00303 RequestInProgress, 00304 NoResponseReceived 00305 } responseResult; 00306 }; 00307 00308 virtual BOOL MakeRequest( 00309 Request & request 00310 ); 00311 BOOL CheckForResponse( 00312 unsigned, 00313 unsigned, 00314 const PASN_Choice * = NULL 00315 ); 00316 BOOL HandleRequestInProgress( 00317 const H323TransactionPDU & pdu, 00318 unsigned delay 00319 ); 00320 BOOL CheckCryptoTokens( 00321 const H323TransactionPDU & pdu, 00322 const PASN_Array & clearTokens, 00323 unsigned clearOptionalField, 00324 const PASN_Array & cryptoTokens, 00325 unsigned cryptoOptionalField 00326 ); 00327 00328 void AgeResponses(); 00329 BOOL SendCachedResponse( 00330 const H323TransactionPDU & pdu 00331 ); 00332 00333 class Response : public PString 00334 { 00335 PCLASSINFO(Response, PString); 00336 public: 00337 Response(const H323TransportAddress & addr, unsigned seqNum); 00338 ~Response(); 00339 00340 void SetPDU(const H323TransactionPDU & pdu); 00341 BOOL SendCachedResponse(H323Transport & transport); 00342 00343 PTime lastUsedTime; 00344 PTimeInterval retirementAge; 00345 H323TransactionPDU * replyPDU; 00346 }; 00347 00348 // Configuration variables 00349 H323EndPoint & endpoint; 00350 WORD defaultLocalPort; 00351 WORD defaultRemotePort; 00352 H323Transport * transport; 00353 BOOL checkResponseCryptoTokens; 00354 00355 unsigned nextSequenceNumber; 00356 PMutex nextSequenceNumberMutex; 00357 00358 PDictionary<POrdinalKey, Request> requests; 00359 PMutex requestsMutex; 00360 Request * lastRequest; 00361 00362 PMutex pduWriteMutex; 00363 PSortedList<Response> responses; 00364 }; 00365 00366 00368 00369 class H323Transaction : public PObject 00370 { 00371 PCLASSINFO(H323Transaction, PObject); 00372 public: 00377 H323Transaction( 00378 H323Transactor & transactor, 00379 const H323TransactionPDU & requestToCopy, 00380 H323TransactionPDU * confirm, 00381 H323TransactionPDU * reject 00382 ); 00383 ~H323Transaction(); 00385 00386 enum Response { 00387 Ignore = -2, 00388 Reject = -1, 00389 Confirm = 0 00390 }; 00391 inline static Response InProgress(unsigned time) { return (Response)(time&0xffff); } 00392 00393 virtual H323TransactionPDU * CreateRIP( 00394 unsigned sequenceNumber, 00395 unsigned delay 00396 ) const = 0; 00397 00398 BOOL HandlePDU(); 00399 00400 virtual BOOL WritePDU( 00401 H323TransactionPDU & pdu 00402 ); 00403 00404 BOOL CheckCryptoTokens( 00405 const H235Authenticators & authenticators 00406 ); 00407 00408 #if PTRACING 00409 virtual const char * GetName() const = 0; 00410 #endif 00411 virtual H235Authenticator::ValidationResult ValidatePDU() const = 0; 00412 virtual void SetRejectReason( 00413 unsigned reasonCode 00414 ) = 0; 00415 00416 BOOL IsFastResponseRequired() const { return fastResponseRequired && canSendRIP; } 00417 BOOL CanSendRIP() const { return canSendRIP; } 00418 H323TransportAddress GetReplyAddress() const { return replyAddresses[0]; } 00419 const H323TransportAddressArray & GetReplyAddresses() const { return replyAddresses; } 00420 BOOL IsBehindNAT() const { return isBehindNAT; } 00421 H323Transactor & GetTransactor() const { return transactor; } 00422 H235Authenticator::ValidationResult GetAuthenticatorResult() const { return authenticatorResult; } 00423 00424 protected: 00425 virtual Response OnHandlePDU() = 0; 00426 PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler); 00427 00428 H323Transactor & transactor; 00429 unsigned requestSequenceNumber; 00430 H323TransportAddressArray replyAddresses; 00431 BOOL fastResponseRequired; 00432 H323TransactionPDU * request; 00433 H323TransactionPDU * confirm; 00434 H323TransactionPDU * reject; 00435 00436 H235Authenticators authenticators; 00437 H235Authenticator::ValidationResult authenticatorResult; 00438 BOOL isBehindNAT; 00439 BOOL canSendRIP; 00440 }; 00441 00442 00444 00445 class H323TransactionServer : public PObject 00446 { 00447 PCLASSINFO(H323TransactionServer, PObject); 00448 public: 00453 H323TransactionServer( 00454 H323EndPoint & endpoint 00455 ); 00456 00459 ~H323TransactionServer(); 00461 00462 virtual WORD GetDefaultUdpPort() = 0; 00463 00468 H323EndPoint & GetOwnerEndPoint() const { return ownerEndPoint; } 00469 00483 BOOL AddListeners( 00484 const H323TransportAddressArray & ifaces 00485 ); 00486 00490 BOOL AddListener( 00491 const H323TransportAddress & interfaceName 00492 ); 00493 00500 BOOL AddListener( 00501 H323Transport * transport 00502 ); 00503 00510 BOOL AddListener( 00511 H323Transactor * listener 00512 ); 00513 00522 virtual H323Transactor * CreateListener( 00523 H323Transport * transport // Transport for listener 00524 ) = 0; 00525 00529 BOOL RemoveListener( 00530 H323Transactor * listener 00531 ); 00532 00533 BOOL SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress & addresses); 00535 00536 protected: 00537 H323EndPoint & ownerEndPoint; 00538 00539 PThread * monitorThread; 00540 PSyncPoint monitorExit; 00541 00542 PMutex mutex; 00543 PLIST(ListenerList, H323Transactor); 00544 ListenerList listeners; 00545 }; 00546 00547 00548 #endif // __OPAL_H323TRANS_H 00549 00550

Generated on Sat Jul 24 17:03:32 2004 for OpenH323 by doxygen 1.3.7