Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | 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.16  2004/08/24 08:11:24  csoutheren
00028  * Added initial support for receiving broadcasts on Linux
00029  *
00030  * Revision 1.15  2003/12/11 05:39:04  csoutheren
00031  * Added storage of H.225 version in endpoint structure
00032  * Disabled sending RIPs to endpoints that cannot handle them
00033  *
00034  * Revision 1.14  2003/04/30 07:50:58  robertj
00035  * Redesigned the alternate credentials in ARQ system as old implementation
00036  *   was fraught with concurrency issues, most importantly it can cause false
00037  *   detection of replay attacks taking out an endpoint completely.
00038  *
00039  * Revision 1.13  2003/04/10 09:40:05  robertj
00040  * Added associated transport to new GetInterfaceAddresses() function so
00041  *   interfaces can be ordered according to active transport links. Improves
00042  *   interoperability.
00043  *
00044  * Revision 1.12  2003/04/10 01:03:58  craigs
00045  * Added functions to access to lists of interfaces
00046  *
00047  * Revision 1.11  2003/04/09 03:08:06  robertj
00048  * Fixed race condition in shutting down transactor (pure virtual call)
00049  *
00050  * Revision 1.10  2003/04/01 05:59:30  robertj
00051  * Fixed H.501 transaction code setting members for m_common PDU part.
00052  *
00053  * Revision 1.9  2003/04/01 04:47:48  robertj
00054  * Abstracted H.225 RAS transaction processing (RIP and secondary thread) in
00055  *   server environment for use by H.501 peer elements.
00056  *
00057  * Revision 1.8  2003/03/26 00:46:25  robertj
00058  * Had another go at making H323Transactor being able to be created
00059  *   without having a listener running.
00060  *
00061  * Revision 1.7  2003/03/25 04:56:17  robertj
00062  * Fixed issues to do with multiple inheritence in transaction reply cache.
00063  *
00064  * Revision 1.6  2003/03/21 05:26:45  robertj
00065  * Added setting of remote port in UDP transport constructor.
00066  *
00067  * Revision 1.5  2003/03/20 01:51:07  robertj
00068  * More abstraction of H.225 RAS and H.501 protocols transaction handling.
00069  *
00070  * Revision 1.4  2003/03/01 00:23:42  craigs
00071  * New PeerElement implementation
00072  *
00073  * Revision 1.3  2003/02/25 06:48:15  robertj
00074  * More work on PDU transaction abstraction.
00075  *
00076  * Revision 1.2  2003/02/25 03:14:58  robertj
00077  * Added missing virtual destructor.
00078  *
00079  * Revision 1.1  2003/02/21 05:28:39  craigs
00080  * Factored out code for user with peer elements
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 // Local interface for transport
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     //Background thread handler.
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         // Inter-thread transfer variables
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     // Configuration variables
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  // Transport for listener
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 

Generated on Sat Mar 5 14:59:06 2005 for OpenH323 by  doxygen 1.4.1