peclient.h

Go to the documentation of this file.
00001 /*
00002  * peclient.h
00003  *
00004  * H.323 Annex G Peer Element client protocol 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  * $Revision: 20836 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-09-03 05:24:34 +0000 (Wed, 03 Sep 2008) $
00029  */
00030 
00031 #ifndef __OPAL_PECLIENT_H
00032 #define __OPAL_PECLIENT_H
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 
00039 #include <h323/h323annexg.h>
00040 #include <h323/h323ep.h>
00041 
00042 #include <ptlib/safecoll.h>
00043 
00044 
00045 class H323PeerElement;
00046 
00047 
00049 
00050 class H501Transaction : public H323Transaction
00051 {
00052     PCLASSINFO(H501Transaction, H323Transaction);
00053   public:
00054     H501Transaction(
00055       H323PeerElement & pe,
00056       const H501PDU & pdu,
00057       PBoolean hasReject
00058     );
00059 
00060     virtual H323TransactionPDU * CreateRIP(
00061       unsigned sequenceNumber,
00062       unsigned delay
00063     ) const;
00064 
00065     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00066 
00067     H501_MessageCommonInfo & requestCommon;
00068     H501_MessageCommonInfo & confirmCommon;
00069 
00070   protected:
00071     H323PeerElement & peerElement;
00072 };
00073 
00074 
00076 
00077 class H501ServiceRequest : public H501Transaction
00078 {
00079     PCLASSINFO(H501ServiceRequest, H501Transaction);
00080   public:
00081     H501ServiceRequest(
00082       H323PeerElement & pe,
00083       const H501PDU & pdu
00084     );
00085 
00086 #if PTRACING
00087     virtual const char * GetName() const;
00088 #endif
00089     virtual void SetRejectReason(
00090       unsigned reasonCode
00091     );
00092 
00093     H501_ServiceRequest & srq;
00094     H501_ServiceConfirmation & scf;
00095     H501_ServiceRejection  & srj;
00096 
00097   protected:
00098     virtual Response OnHandlePDU();
00099 };
00100 
00101 
00103 
00104 class H501DescriptorUpdate : public H501Transaction
00105 {
00106     PCLASSINFO(H501DescriptorUpdate, H501Transaction);
00107   public:
00108     H501DescriptorUpdate(
00109       H323PeerElement & pe,
00110       const H501PDU & pdu
00111     );
00112 
00113 #if PTRACING
00114     virtual const char * GetName() const;
00115 #endif
00116     virtual void SetRejectReason(
00117       unsigned reasonCode
00118     );
00119 
00120     H501_DescriptorUpdate & du;
00121     H501_DescriptorUpdateAck & ack;
00122 
00123   protected:
00124     virtual Response OnHandlePDU();
00125 };
00126 
00127 
00129 
00130 class H501AccessRequest : public H501Transaction
00131 {
00132     PCLASSINFO(H501AccessRequest, H501Transaction);
00133   public:
00134     H501AccessRequest(
00135       H323PeerElement & pe,
00136       const H501PDU & pdu
00137     );
00138 
00139 #if PTRACING
00140     virtual const char * GetName() const;
00141 #endif
00142     virtual void SetRejectReason(
00143       unsigned reasonCode
00144     );
00145 
00146     H501_AccessRequest & arq;
00147     H501_AccessConfirmation & acf;
00148     H501_AccessRejection  & arj;
00149 
00150   protected:
00151     virtual Response OnHandlePDU();
00152 };
00153 
00154 
00156 
00157 class H323PeerElementDescriptor : public PSafeObject
00158 {
00159   PCLASSINFO(H323PeerElementDescriptor, PSafeObject);
00160   public:
00161     H323PeerElementDescriptor(const OpalGloballyUniqueID & _descriptorID)
00162       : descriptorID(_descriptorID), state(Dirty), creator(0)
00163     { }
00164 
00165     Comparison Compare(const PObject & obj) const;
00166 
00167     enum Options {
00168       Protocol_H323            = 0x0001,
00169       Protocol_Voice           = 0x0002,
00170       Protocol_Max             = 0x0002,
00171       Option_WildCard          = 0x0004,
00172       Option_SendAccessRequest = 0x0008,
00173       Option_NotAvailable      = 0x0010,
00174       Option_PrioritySet       = 0x0020,
00175       Option_PriorityMask      = 0x1fc0,
00176     };
00177 
00178     enum {
00179       HighestPriority          = 0,
00180       DefaultPriority          = 80,
00181       LowestPriority           = 127
00182     };
00183 
00184     static inline unsigned SetPriorityOption(unsigned pri)     { return Option_PrioritySet | ((pri & 0x7f) << 6); }
00185     static inline unsigned GetPriorityOption(unsigned options) { return (options & Option_PrioritySet) != 0 ? ((options >> 6) & 0x7f) : DefaultPriority; }
00186 
00187     void CopyTo(H501_Descriptor & descriptor);
00188     static PBoolean CopyToAddressTemplate(H501_AddressTemplate & addressTemplates, 
00189                                    const H225_EndpointType & ep, 
00190                            const H225_ArrayOf_AliasAddress & aliases, 
00191                            const H225_ArrayOf_AliasAddress & transportAddress, 
00192                                                     unsigned options = H323PeerElementDescriptor::Protocol_H323);
00193 
00194     static void SetProtocolList(H501_ArrayOf_SupportedProtocols & h501Protocols, unsigned protocols);
00195     static unsigned GetProtocolList(const H501_ArrayOf_SupportedProtocols & h501Protocols);
00196 
00197     OpalGloballyUniqueID descriptorID;
00198 
00199     PBoolean ContainsNonexistent();
00200 
00201     enum States {
00202       Clean,
00203       Dirty,
00204       Deleted
00205     } state;
00206 
00207     H501_ArrayOf_AddressTemplate addressTemplates;
00208     PString gatekeeperID;
00209     PTime lastChanged;
00210     POrdinalKey creator;
00211 };
00212 
00213 
00215 
00216 class H323PeerElementServiceRelationship : public PSafeObject
00217 {
00218     PCLASSINFO(H323PeerElementServiceRelationship, PSafeObject);
00219   public:
00220     H323PeerElementServiceRelationship()
00221       : ordinal(0)
00222       { }
00223 
00224     H323PeerElementServiceRelationship(const OpalGloballyUniqueID & _serviceID)
00225       : serviceID(_serviceID), ordinal(0)
00226       { }
00227 
00228     Comparison Compare(const PObject & obj) const
00229       { return serviceID.Compare(((H323PeerElementServiceRelationship&)obj).serviceID); }
00230 
00231     OpalGloballyUniqueID serviceID;
00232     POrdinalKey ordinal;
00233     H323TransportAddress peer;
00234     PString name;
00235     PTime createdTime;
00236     PTime lastUpdateTime;
00237     PTime expireTime;
00238 };
00239 
00240 
00242 
00245 class H323PeerElement : public H323_AnnexG
00246 {
00247     PCLASSINFO(H323PeerElement, H323_AnnexG);
00248   public:
00253     H323PeerElement(
00254       H323EndPoint & endpoint,  
00255       H323Transport * transport = NULL
00256     );
00257     H323PeerElement(
00258       H323EndPoint & endpoint,  
00259       const H323TransportAddress & addr
00260     );
00261 
00264     ~H323PeerElement();
00266 
00267     enum Error {
00268       Confirmed,
00269       Rejected,
00270       NoResponse,
00271       NoServiceRelationship,
00272       ServiceRelationshipReestablished
00273     };
00274 
00275     enum {
00276       LocalServiceRelationshipOrdinal  = 0,
00277       NoServiceRelationshipOrdinal     = 1,
00278       RemoteServiceRelationshipOrdinal = 2
00279     };
00280 
00285     void PrintOn(
00286       ostream & strm    
00287     ) const;
00289 
00290     PSafePtr<H323PeerElementDescriptor> GetFirstDescriptor(
00291       PSafetyMode mode = PSafeReference
00292     ) { return PSafePtr<H323PeerElementDescriptor>(descriptors, mode); }
00293 
00294     PSafePtr<H323PeerElementServiceRelationship> GetFirstLocalServiceRelationship(
00295       PSafetyMode mode = PSafeReference
00296     ) { return PSafePtr<H323PeerElementServiceRelationship>(localServiceRelationships, mode); }
00297 
00298     PSafePtr<H323PeerElementServiceRelationship> GetFirstRemoteServiceRelationship(
00299       PSafetyMode mode = PSafeReference
00300     ) { return PSafePtr<H323PeerElementServiceRelationship>(remoteServiceRelationships, mode); }
00301 
00302     void SetLocalName(const PString & name);
00303     PString GetLocalName() const;
00304 
00305     void SetDomainName(const PString & name);
00306     PString GetDomainName() const;
00307 
00308     /*********************************************************
00309       functions to establish and break service relationships
00310       */
00311 
00314     PBoolean SetOnlyServiceRelationship(const PString & peer, PBoolean keepTrying = PTrue);
00315     PBoolean AddServiceRelationship(const H323TransportAddress & peer, PBoolean keepTrying = PTrue);
00316     PBoolean AddServiceRelationship(const H323TransportAddress & peer, OpalGloballyUniqueID & serviceID, PBoolean keepTrying = PTrue);
00317     PBoolean RemoveServiceRelationship(const OpalGloballyUniqueID & serviceID, int reason = H501_ServiceReleaseReason::e_terminated);
00318     PBoolean RemoveServiceRelationship(const H323TransportAddress & peer, int reason = H501_ServiceReleaseReason::e_terminated);
00319     PBoolean RemoveAllServiceRelationships();
00320 
00321     Error ServiceRequestByAddr(const H323TransportAddress & peer);
00322     Error ServiceRequestByAddr(const H323TransportAddress & peer, OpalGloballyUniqueID & serviceID);
00323     Error ServiceRequestByID(OpalGloballyUniqueID & serviceID);
00324 
00327     PBoolean ServiceRelease(const OpalGloballyUniqueID & serviceID, unsigned reason);
00328 
00329     /*********************************************************
00330       functions to manipulate the local descriptor table
00331      */
00332 
00333     PBoolean AddDescriptor(
00334       const OpalGloballyUniqueID & descriptorID,
00335       const PStringArray & aliases, 
00336       const H323TransportAddressArray & transportAddrs, 
00337       unsigned options = H323PeerElementDescriptor::Protocol_H323, 
00338       PBoolean now = PFalse
00339     );
00340 
00341     PBoolean AddDescriptor(
00342       const OpalGloballyUniqueID & descriptorID,
00343       const H225_ArrayOf_AliasAddress & aliases, 
00344       const H323TransportAddressArray & transportAddrs, 
00345       unsigned options = H323PeerElementDescriptor::Protocol_H323, 
00346       PBoolean now = PFalse
00347     );
00348 
00349     PBoolean AddDescriptor(
00350       const OpalGloballyUniqueID & descriptorID,
00351       const H225_ArrayOf_AliasAddress & aliases, 
00352       const H225_ArrayOf_AliasAddress & transportAddr, 
00353       unsigned options = H323PeerElementDescriptor::Protocol_H323, 
00354       PBoolean now = PFalse
00355     );
00356 
00357     PBoolean AddDescriptor(
00358       const OpalGloballyUniqueID & descriptorID,
00359       const POrdinalKey & creator,
00360       const H225_ArrayOf_AliasAddress & alias, 
00361       const H225_ArrayOf_AliasAddress & transportAddresses,
00362       unsigned options = H323PeerElementDescriptor::Protocol_H323,
00363       PBoolean now = PFalse
00364     );
00365 
00366     PBoolean AddDescriptor(
00367       const OpalGloballyUniqueID & descriptorID,
00368       const POrdinalKey & creator,
00369       const H501_ArrayOf_AddressTemplate & addressTemplates,
00370       const PTime & updateTime,
00371       PBoolean now = PFalse
00372     );
00373 
00376     PBoolean DeleteDescriptor(const PString & alias, PBoolean now = PFalse);
00377     PBoolean DeleteDescriptor(const H225_AliasAddress & alias, PBoolean now = PFalse);
00378     PBoolean DeleteDescriptor(const OpalGloballyUniqueID & descriptorID, PBoolean now = PFalse);
00379 
00382     PBoolean AccessRequest(
00383       const PString & searchAlias,
00384       PStringArray & destAliases, 
00385       H323TransportAddress & transportAddress,
00386       unsigned options = H323PeerElementDescriptor::Protocol_H323
00387     );
00388 
00389     PBoolean AccessRequest(
00390       const PString & searchAlias,
00391       H225_ArrayOf_AliasAddress & destAliases,
00392       H323TransportAddress & transportAddress,
00393       unsigned options = H323PeerElementDescriptor::Protocol_H323
00394     );
00395 
00396     PBoolean AccessRequest(
00397       const H225_AliasAddress & searchAlias,
00398       H225_ArrayOf_AliasAddress & destAliases,
00399       H323TransportAddress & transportAddress,
00400       unsigned options = H323PeerElementDescriptor::Protocol_H323
00401     );
00402 
00403     PBoolean AccessRequest(
00404       const H225_AliasAddress & alias,
00405       H225_ArrayOf_AliasAddress & destAliases,
00406       H225_AliasAddress & transportAddress,
00407       unsigned options = H323PeerElementDescriptor::Protocol_H323
00408     );
00409 
00410     /*********************************************************
00411       functions to send send descriptors to another peer element
00412       */
00413     PBoolean UpdateDescriptor(H323PeerElementDescriptor * descriptor);
00414     PBoolean UpdateDescriptor(H323PeerElementDescriptor * descriptor, H501_UpdateInformation_updateType::Choices updateType);
00415 
00416 
00417     Error SendUpdateDescriptorByID(const OpalGloballyUniqueID & serviceID, 
00418                                     H323PeerElementDescriptor * descriptor, 
00419                      H501_UpdateInformation_updateType::Choices updateType);
00420 
00421     Error SendUpdateDescriptorByAddr(const H323TransportAddress & peer, 
00422                                       H323PeerElementDescriptor * descriptor, 
00423                        H501_UpdateInformation_updateType::Choices updateType);
00424 
00425     Error SendAccessRequestByID(const OpalGloballyUniqueID & peerID, 
00426                                                    H501PDU & request, 
00427                                                    H501PDU & confirmPDU);
00428 
00429     Error SendAccessRequestByAddr(const H323TransportAddress & peerAddr, 
00430                                                      H501PDU & request, 
00431                                                      H501PDU & confirmPDU);
00432 
00433 
00434     /*********************************************************
00435       low level request functions
00436       */
00437 
00438     PBoolean MakeRequest(H323_AnnexG::Request & request);
00439 
00440     virtual void OnAddServiceRelationship(const H323TransportAddress &) { }
00441     virtual void OnRemoveServiceRelationship(const H323TransportAddress &) { }
00442 
00443     virtual void OnNewDescriptor(const H323PeerElementDescriptor &) { }
00444     virtual void OnUpdateDescriptor(const H323PeerElementDescriptor &) { }
00445     virtual void OnRemoveDescriptor(const H323PeerElementDescriptor &) { }
00446 
00447     virtual H323Transaction::Response OnServiceRequest(H501ServiceRequest & info);
00448     virtual H323Transaction::Response OnDescriptorUpdate(H501DescriptorUpdate & info);
00449     virtual H323Transaction::Response OnAccessRequest(H501AccessRequest & info);
00450 
00451     PBoolean OnReceiveServiceRequest(const H501PDU & pdu, const H501_ServiceRequest & pduBody);
00452     PBoolean OnReceiveServiceConfirmation(const H501PDU & pdu, const H501_ServiceConfirmation & pduBody);
00453 
00454     PBoolean OnReceiveDescriptorUpdate(const H501PDU & pdu, const H501_DescriptorUpdate & pduBody);
00455     PBoolean OnReceiveDescriptorUpdateACK(const H501PDU & pdu, const H501_DescriptorUpdateAck & pduBody);
00456 
00457     PBoolean OnReceiveAccessRequest(const H501PDU & pdu, const H501_AccessRequest & pduBody);
00458     PBoolean OnReceiveAccessConfirmation (const H501PDU & pdu, const H501_AccessConfirmation & pduBody);
00459     PBoolean OnReceiveAccessRejection(const H501PDU & pdu,     const H501_AccessRejection & pduBody);
00460 
00461     class AliasKey : public H225_AliasAddress
00462     {
00463       public:
00464         AliasKey(const H225_AliasAddress & _alias, const OpalGloballyUniqueID & _id, PINDEX _pos, PBoolean _wild = PFalse)
00465           : H225_AliasAddress(_alias), id(_id), pos(_pos), wild(_wild)
00466         { }
00467 
00468         OpalGloballyUniqueID id;
00469         PINDEX pos;
00470         PBoolean wild;
00471     };
00472 
00473   protected:
00474     void Construct();
00475 
00476     Error SendUpdateDescriptor(              H501PDU & pdu,  
00477                           const H323TransportAddress & peer, 
00478                            H323PeerElementDescriptor * descriptor,
00479             H501_UpdateInformation_updateType::Choices updateType);
00480 
00481     PBoolean OnRemoteServiceRelationshipDisappeared(OpalGloballyUniqueID & serviceID, const H323TransportAddress & peer);
00482     void InternalRemoveServiceRelationship(const H323TransportAddress & peer);
00483     H323Transaction::Response HandleServiceRequest(H501ServiceRequest & info);
00484 
00485     virtual H323PeerElementDescriptor          * CreateDescriptor(const OpalGloballyUniqueID & descriptorID);
00486     virtual H323PeerElementServiceRelationship * CreateServiceRelationship();
00487     virtual AliasKey                           * CreateAliasKey(const H225_AliasAddress & alias, const OpalGloballyUniqueID & id, PINDEX pos, PBoolean wild = PFalse);
00488 
00489     void RemoveDescriptorInformation(const H501_ArrayOf_AddressTemplate & addressTemplates);
00490 
00491     PDECLARE_NOTIFIER(PThread, H323PeerElement, MonitorMain);
00492     PDECLARE_NOTIFIER(PThread, H323PeerElement, UpdateAllDescriptors);
00493     PDECLARE_NOTIFIER(PTimer, H323PeerElement, TickleMonitor);
00494 
00495     PMutex localNameMutex;
00496     PString localIdentifier;
00497     PString domainName;
00498 
00499     PSemaphore requestMutex;
00500     PThread  * monitor;
00501     PBoolean       monitorStop;
00502     PSyncPoint monitorTickle;
00503 
00504     PMutex basePeerOrdinalMutex;
00505     PINDEX basePeerOrdinal;
00506 
00507     // structures needed to maintain local service relationships (for which we receive a ServiceRequest)
00508     PSafeSortedList<H323PeerElementServiceRelationship> localServiceRelationships;
00509     PMutex localPeerListMutex;
00510     POrdinalSet localServiceOrdinals;
00511 
00512     // structures needed to maintain remote service relationships (for which we send a ServiceRequest)
00513     PMutex remotePeerListMutex;
00514     PSafeSortedList<H323PeerElementServiceRelationship> remoteServiceRelationships;
00515     PStringToString remotePeerAddrToServiceID;
00516     PDICTIONARY(StringToOrdinalKey, PString, POrdinalKey);
00517     StringToOrdinalKey remotePeerAddrToOrdinalKey;
00518 
00519     PSafeSortedList<H323PeerElementDescriptor> descriptors;
00520 
00521     PSORTED_LIST(AliasKeyList, H225_AliasAddress);
00522 
00523     PMutex aliasMutex;
00524     AliasKeyList transportAddressToDescriptorID;
00525     AliasKeyList specificAliasToDescriptorID;
00526     AliasKeyList wildcardAliasToDescriptorID;
00527 };
00528 
00529 
00530 #endif // __OPAL_PECLIENT_H
00531 
00532 

Generated on Mon Sep 15 11:49:14 2008 for OPAL by  doxygen 1.5.1