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  * $Log: peclient.h,v $
00027  * Revision 2.3  2005/11/30 13:35:26  csoutheren
00028  * Changed tags for Doxygen
00029  *
00030  * Revision 2.2  2004/06/04 06:54:17  csoutheren
00031  * Migrated updates from OpenH323 1.14.1
00032  *
00033  * Revision 2.1  2004/02/19 10:46:44  rjongbloed
00034  * Merged OpenH323 version 1.13.1 changes.
00035  *
00036  * Revision 1.28  2003/05/14 03:04:58  rjongbloed
00037  * Added another method for removing service relationships.
00038  * Added virtual for handling SR requests.
00039  *
00040  * Revision 1.27  2003/05/05 08:28:45  craigs
00041  * Fixed lastUpdate time in descriptors
00042  *
00043  * Revision 1.26  2003/04/30 04:56:57  craigs
00044  * Improved handling for nonexistent routes
00045  *
00046  * Revision 1.25  2003/04/10 12:37:54  craigs
00047  * Improved handling of wildcard entries
00048  *
00049  * Revision 1.24  2003/04/10 07:05:15  craigs
00050  * Allowed access to endpoint type in descriptors
00051  *
00052  * Revision 1.23  2003/04/10 03:42:16  craigs
00053  * Allow AccessRequest to return multiple transport addresses
00054  *
00055  * Revision 1.22  2003/04/09 10:47:25  craigs
00056  * Fixed problems
00057  *
00058  * Revision 1.21  2003/04/08 12:23:54  craigs
00059  * Fixed problem with descriptors not being removed when service relationships go away
00060  *
00061  * Revision 1.20  2003/04/07 05:11:13  craigs
00062  * Added changes to get access to descriptor creates/updates/deletes
00063  *
00064  * Revision 1.19  2003/04/02 06:05:10  robertj
00065  * Added versions of AddDescriptor that contain the GUID.
00066  *
00067  * Revision 1.18  2003/04/01 05:59:30  robertj
00068  * Fixed H.501 transaction code setting members for m_common PDU part.
00069  *
00070  * Revision 1.17  2003/04/01 04:47:48  robertj
00071  * Abstracted H.225 RAS transaction processing (RIP and secondary thread) in
00072  *   server environment for use by H.501 peer elements.
00073  *
00074  * Revision 1.16  2003/04/01 01:17:44  robertj
00075  * Minor changes to AccessEquest and AddDescriptor API to allow for
00076  *   string arrays of aliases.
00077  *
00078  * Revision 1.15  2003/03/28 00:30:23  craigs
00079  * Fixed problems with service relationship ordinals and better descriptor update access
00080  *
00081  * Revision 1.14  2003/03/27 09:24:06  craigs
00082  * Rewritten support for descriptors and multiple templates
00083  *
00084  * Revision 1.13  2003/03/26 07:08:46  robertj
00085  * Added default parameters to AddDescriptor() functions
00086  *
00087  * Revision 1.12  2003/03/25 07:50:11  craigs
00088  * Added support for mutiple transports per descriptor
00089  *
00090  * Revision 1.11  2003/03/25 05:13:13  craigs
00091  * More speed enhancements
00092  *
00093  * Revision 1.10  2003/03/25 01:58:46  robertj
00094  * Fixed GNU warnings
00095  *
00096  * Revision 1.9  2003/03/25 01:47:58  craigs
00097  * Changes for new OpenH323 H.501
00098  *
00099  * Revision 1.8  2003/03/20 01:51:07  robertj
00100  * More abstraction of H.225 RAS and H.501 protocols transaction handling.
00101  *
00102  * Revision 1.7  2003/03/18 13:58:16  craigs
00103  * More H.501 implementation
00104  *
00105  * Revision 1.6  2003/03/18 02:18:45  craigs
00106  * Changed incorrect include
00107  *
00108  * Revision 1.5  2003/03/17 13:19:49  craigs
00109  * More H501 implementation
00110  *
00111  * Revision 1.4  2003/03/14 06:00:42  craigs
00112  * More updates
00113  *
00114  * Revision 1.3  2003/03/01 00:23:51  craigs
00115  * New PeerElement implementation
00116  *
00117  * Revision 1.2  2003/02/21 07:23:18  robertj
00118  * Fixed up some comments
00119  *
00120  * Revision 1.1  2003/02/21 05:28:39  craigs
00121  * Factored out code for user with peer elements
00122  *
00123  */
00124 
00125 #ifndef __OPAL_PECLIENT_H
00126 #define __OPAL_PECLIENT_H
00127 
00128 #ifdef P_USE_PRAGMA
00129 #pragma interface
00130 #endif
00131 
00132 
00133 #include <h323/h323annexg.h>
00134 #include <h323/h323ep.h>
00135 
00136 #include <ptlib/safecoll.h>
00137 
00138 
00139 class H323PeerElement;
00140 
00141 
00143 
00144 class H501Transaction : public H323Transaction
00145 {
00146     PCLASSINFO(H501Transaction, H323Transaction);
00147   public:
00148     H501Transaction(
00149       H323PeerElement & pe,
00150       const H501PDU & pdu,
00151       BOOL hasReject
00152     );
00153 
00154     virtual H323TransactionPDU * CreateRIP(
00155       unsigned sequenceNumber,
00156       unsigned delay
00157     ) const;
00158 
00159     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00160 
00161     H501_MessageCommonInfo & requestCommon;
00162     H501_MessageCommonInfo & confirmCommon;
00163 
00164   protected:
00165     H323PeerElement & peerElement;
00166 };
00167 
00168 
00170 
00171 class H501ServiceRequest : public H501Transaction
00172 {
00173     PCLASSINFO(H501ServiceRequest, H501Transaction);
00174   public:
00175     H501ServiceRequest(
00176       H323PeerElement & pe,
00177       const H501PDU & pdu
00178     );
00179 
00180 #if PTRACING
00181     virtual const char * GetName() const;
00182 #endif
00183     virtual void SetRejectReason(
00184       unsigned reasonCode
00185     );
00186 
00187     H501_ServiceRequest & srq;
00188     H501_ServiceConfirmation & scf;
00189     H501_ServiceRejection  & srj;
00190 
00191   protected:
00192     virtual Response OnHandlePDU();
00193 };
00194 
00195 
00197 
00198 class H501DescriptorUpdate : public H501Transaction
00199 {
00200     PCLASSINFO(H501DescriptorUpdate, H501Transaction);
00201   public:
00202     H501DescriptorUpdate(
00203       H323PeerElement & pe,
00204       const H501PDU & pdu
00205     );
00206 
00207 #if PTRACING
00208     virtual const char * GetName() const;
00209 #endif
00210     virtual void SetRejectReason(
00211       unsigned reasonCode
00212     );
00213 
00214     H501_DescriptorUpdate & du;
00215     H501_DescriptorUpdateAck & ack;
00216 
00217   protected:
00218     virtual Response OnHandlePDU();
00219 };
00220 
00221 
00223 
00224 class H501AccessRequest : public H501Transaction
00225 {
00226     PCLASSINFO(H501AccessRequest, H501Transaction);
00227   public:
00228     H501AccessRequest(
00229       H323PeerElement & pe,
00230       const H501PDU & pdu
00231     );
00232 
00233 #if PTRACING
00234     virtual const char * GetName() const;
00235 #endif
00236     virtual void SetRejectReason(
00237       unsigned reasonCode
00238     );
00239 
00240     H501_AccessRequest & arq;
00241     H501_AccessConfirmation & acf;
00242     H501_AccessRejection  & arj;
00243 
00244   protected:
00245     virtual Response OnHandlePDU();
00246 };
00247 
00248 
00250 
00251 class H323PeerElementDescriptor : public PSafeObject
00252 {
00253   PCLASSINFO(H323PeerElementDescriptor, PSafeObject);
00254   public:
00255     H323PeerElementDescriptor(const OpalGloballyUniqueID & _descriptorID)
00256       : descriptorID(_descriptorID), state(Dirty), creator(0)
00257     { }
00258 
00259     Comparison Compare(const PObject & obj) const;
00260 
00261     enum Options {
00262       Protocol_H323            = 0x0001,
00263       Protocol_Voice           = 0x0002,
00264       Protocol_Max             = 0x0002,
00265       Option_WildCard          = 0x0004,
00266       Option_SendAccessRequest = 0x0008,
00267       Option_NotAvailable      = 0x0010,
00268       Option_PrioritySet       = 0x0020,
00269       Option_PriorityMask      = 0x1fc0,
00270     };
00271 
00272     enum {
00273       HighestPriority          = 0,
00274       DefaultPriority          = 80,
00275       LowestPriority           = 127
00276     };
00277 
00278     static inline unsigned SetPriorityOption(unsigned pri)     { return Option_PrioritySet | ((pri & 0x7f) << 6); }
00279     static inline unsigned GetPriorityOption(unsigned options) { return (options & Option_PrioritySet) ? ((options >> 6) & 0x7f) : DefaultPriority; }
00280 
00281     void CopyTo(H501_Descriptor & descriptor);
00282     static BOOL CopyToAddressTemplate(H501_AddressTemplate & addressTemplates, 
00283                                    const H225_EndpointType & ep, 
00284                            const H225_ArrayOf_AliasAddress & aliases, 
00285                            const H225_ArrayOf_AliasAddress & transportAddress, 
00286                                                     unsigned options = H323PeerElementDescriptor::Protocol_H323);
00287 
00288     static void SetProtocolList(H501_ArrayOf_SupportedProtocols & h501Protocols, unsigned protocols);
00289     static unsigned GetProtocolList(const H501_ArrayOf_SupportedProtocols & h501Protocols);
00290 
00291     OpalGloballyUniqueID descriptorID;
00292 
00293     BOOL ContainsNonexistent();
00294 
00295     enum States {
00296       Clean,
00297       Dirty,
00298       Deleted
00299     } state;
00300 
00301     H501_ArrayOf_AddressTemplate addressTemplates;
00302     PString gatekeeperID;
00303     PTime lastChanged;
00304     POrdinalKey creator;
00305 };
00306 
00307 
00309 
00310 class H323PeerElementServiceRelationship : public PSafeObject
00311 {
00312     PCLASSINFO(H323PeerElementServiceRelationship, PSafeObject);
00313   public:
00314     H323PeerElementServiceRelationship()
00315       : ordinal(0)
00316       { }
00317 
00318     H323PeerElementServiceRelationship(const OpalGloballyUniqueID & _serviceID)
00319       : serviceID(_serviceID), ordinal(0)
00320       { }
00321 
00322     Comparison Compare(const PObject & obj) const
00323       { return serviceID.Compare(((H323PeerElementServiceRelationship&)obj).serviceID); }
00324 
00325     OpalGloballyUniqueID serviceID;
00326     POrdinalKey ordinal;
00327     H323TransportAddress peer;
00328     PString name;
00329     PTime createdTime;
00330     PTime lastUpdateTime;
00331     PTime expireTime;
00332 };
00333 
00334 
00336 
00339 class H323PeerElement : public H323_AnnexG
00340 {
00341     PCLASSINFO(H323PeerElement, H323_AnnexG);
00342   public:
00347     H323PeerElement(
00348       H323EndPoint & endpoint,  
00349       H323Transport * transport = NULL
00350     );
00351     H323PeerElement(
00352       H323EndPoint & endpoint,  
00353       const H323TransportAddress & addr
00354     );
00355 
00358     ~H323PeerElement();
00360 
00361     enum Error {
00362       Confirmed,
00363       Rejected,
00364       NoResponse,
00365       NoServiceRelationship,
00366       ServiceRelationshipReestablished
00367     };
00368 
00369     enum {
00370       LocalServiceRelationshipOrdinal  = 0,
00371       NoServiceRelationshipOrdinal     = 1,
00372       RemoteServiceRelationshipOrdinal = 2
00373     };
00374 
00379     void PrintOn(
00380       ostream & strm    
00381     ) const;
00383 
00384     PSafePtr<H323PeerElementDescriptor> GetFirstDescriptor(
00385       PSafetyMode mode = PSafeReference
00386     ) { return PSafePtr<H323PeerElementDescriptor>(descriptors, mode); }
00387 
00388     PSafePtr<H323PeerElementServiceRelationship> GetFirstLocalServiceRelationship(
00389       PSafetyMode mode = PSafeReference
00390     ) { return PSafePtr<H323PeerElementServiceRelationship>(localServiceRelationships, mode); }
00391 
00392     PSafePtr<H323PeerElementServiceRelationship> GetFirstRemoteServiceRelationship(
00393       PSafetyMode mode = PSafeReference
00394     ) { return PSafePtr<H323PeerElementServiceRelationship>(remoteServiceRelationships, mode); }
00395 
00396     void SetLocalName(const PString & name);
00397     PString GetLocalName() const;
00398 
00399     void SetDomainName(const PString & name);
00400     PString GetDomainName() const;
00401 
00402     /*********************************************************
00403       functions to establish and break service relationships
00404       */
00405 
00408     BOOL SetOnlyServiceRelationship(const PString & peer, BOOL keepTrying = TRUE);
00409     BOOL AddServiceRelationship(const H323TransportAddress & peer, BOOL keepTrying = TRUE);
00410     BOOL AddServiceRelationship(const H323TransportAddress & peer, OpalGloballyUniqueID & serviceID, BOOL keepTrying = TRUE);
00411     BOOL RemoveServiceRelationship(const OpalGloballyUniqueID & serviceID, int reason = H501_ServiceReleaseReason::e_terminated);
00412     BOOL RemoveServiceRelationship(const H323TransportAddress & peer, int reason = H501_ServiceReleaseReason::e_terminated);
00413     BOOL RemoveAllServiceRelationships();
00414 
00415     Error ServiceRequestByAddr(const H323TransportAddress & peer);
00416     Error ServiceRequestByAddr(const H323TransportAddress & peer, OpalGloballyUniqueID & serviceID);
00417     Error ServiceRequestByID(OpalGloballyUniqueID & serviceID);
00418 
00421     BOOL ServiceRelease(const OpalGloballyUniqueID & serviceID, unsigned reason);
00422 
00423     /*********************************************************
00424       functions to manipulate the local descriptor table
00425      */
00426 
00427     BOOL AddDescriptor(
00428       const OpalGloballyUniqueID & descriptorID,
00429       const PStringArray & aliases, 
00430       const H323TransportAddressArray & transportAddrs, 
00431       unsigned options = H323PeerElementDescriptor::Protocol_H323, 
00432       BOOL now = FALSE
00433     );
00434 
00435     BOOL AddDescriptor(
00436       const OpalGloballyUniqueID & descriptorID,
00437       const H225_ArrayOf_AliasAddress & aliases, 
00438       const H323TransportAddressArray & transportAddrs, 
00439       unsigned options = H323PeerElementDescriptor::Protocol_H323, 
00440       BOOL now = FALSE
00441     );
00442 
00443     BOOL AddDescriptor(
00444       const OpalGloballyUniqueID & descriptorID,
00445       const H225_ArrayOf_AliasAddress & aliases, 
00446       const H225_ArrayOf_AliasAddress & transportAddr, 
00447       unsigned options = H323PeerElementDescriptor::Protocol_H323, 
00448       BOOL now = FALSE
00449     );
00450 
00451     BOOL AddDescriptor(
00452       const OpalGloballyUniqueID & descriptorID,
00453       const POrdinalKey & creator,
00454       const H225_ArrayOf_AliasAddress & alias, 
00455       const H225_ArrayOf_AliasAddress & transportAddresses,
00456       unsigned options = H323PeerElementDescriptor::Protocol_H323,
00457       BOOL now = FALSE
00458     );
00459 
00460     BOOL AddDescriptor(
00461       const OpalGloballyUniqueID & descriptorID,
00462       const POrdinalKey & creator,
00463       const H501_ArrayOf_AddressTemplate & addressTemplates,
00464       const PTime & updateTime,
00465       BOOL now = FALSE
00466     );
00467 
00470     BOOL DeleteDescriptor(const PString & alias, BOOL now = FALSE);
00471     BOOL DeleteDescriptor(const H225_AliasAddress & alias, BOOL now = FALSE);
00472     BOOL DeleteDescriptor(const OpalGloballyUniqueID & descriptorID, BOOL now = FALSE);
00473 
00476     BOOL AccessRequest(
00477       const PString & searchAlias,
00478       PStringArray & destAliases, 
00479       H323TransportAddress & transportAddress,
00480       unsigned options = H323PeerElementDescriptor::Protocol_H323
00481     );
00482 
00483     BOOL AccessRequest(
00484       const PString & searchAlias,
00485       H225_ArrayOf_AliasAddress & destAliases,
00486       H323TransportAddress & transportAddress,
00487       unsigned options = H323PeerElementDescriptor::Protocol_H323
00488     );
00489 
00490     BOOL AccessRequest(
00491       const H225_AliasAddress & searchAlias,
00492       H225_ArrayOf_AliasAddress & destAliases,
00493       H323TransportAddress & transportAddress,
00494       unsigned options = H323PeerElementDescriptor::Protocol_H323
00495     );
00496 
00497     BOOL AccessRequest(
00498       const H225_AliasAddress & alias,
00499       H225_ArrayOf_AliasAddress & destAliases,
00500       H225_AliasAddress & transportAddress,
00501       unsigned options = H323PeerElementDescriptor::Protocol_H323
00502     );
00503 
00504     /*********************************************************
00505       functions to send send descriptors to another peer element
00506       */
00507     BOOL UpdateDescriptor(H323PeerElementDescriptor * descriptor);
00508     BOOL UpdateDescriptor(H323PeerElementDescriptor * descriptor, H501_UpdateInformation_updateType::Choices updateType);
00509 
00510 
00511     Error SendUpdateDescriptorByID(const OpalGloballyUniqueID & serviceID, 
00512                                     H323PeerElementDescriptor * descriptor, 
00513                      H501_UpdateInformation_updateType::Choices updateType);
00514 
00515     Error SendUpdateDescriptorByAddr(const H323TransportAddress & peer, 
00516                                       H323PeerElementDescriptor * descriptor, 
00517                        H501_UpdateInformation_updateType::Choices updateType);
00518 
00519     Error SendAccessRequestByID(const OpalGloballyUniqueID & peerID, 
00520                                                    H501PDU & request, 
00521                                                    H501PDU & confirmPDU);
00522 
00523     Error SendAccessRequestByAddr(const H323TransportAddress & peerAddr, 
00524                                                      H501PDU & request, 
00525                                                      H501PDU & confirmPDU);
00526 
00527 
00528     /*********************************************************
00529       low level request functions
00530       */
00531 
00532     BOOL MakeRequest(H323_AnnexG::Request & request);
00533 
00534     virtual void OnAddServiceRelationship(const H323TransportAddress &) { }
00535     virtual void OnRemoveServiceRelationship(const H323TransportAddress &) { }
00536 
00537     virtual void OnNewDescriptor(const H323PeerElementDescriptor &) { }
00538     virtual void OnUpdateDescriptor(const H323PeerElementDescriptor &) { }
00539     virtual void OnRemoveDescriptor(const H323PeerElementDescriptor &) { }
00540 
00541     virtual H323Transaction::Response OnServiceRequest(H501ServiceRequest & info);
00542     virtual H323Transaction::Response OnDescriptorUpdate(H501DescriptorUpdate & info);
00543     virtual H323Transaction::Response OnAccessRequest(H501AccessRequest & info);
00544 
00545     BOOL OnReceiveServiceRequest(const H501PDU & pdu, const H501_ServiceRequest & pduBody);
00546     BOOL OnReceiveServiceConfirmation(const H501PDU & pdu, const H501_ServiceConfirmation & pduBody);
00547 
00548     BOOL OnReceiveDescriptorUpdate(const H501PDU & pdu, const H501_DescriptorUpdate & pduBody);
00549     BOOL OnReceiveDescriptorUpdateACK(const H501PDU & pdu, const H501_DescriptorUpdateAck & pduBody);
00550 
00551     BOOL OnReceiveAccessRequest(const H501PDU & pdu, const H501_AccessRequest & pduBody);
00552     BOOL OnReceiveAccessConfirmation (const H501PDU & pdu, const H501_AccessConfirmation & pduBody);
00553     BOOL OnReceiveAccessRejection(const H501PDU & pdu,     const H501_AccessRejection & pduBody);
00554 
00555     class AliasKey : public H225_AliasAddress
00556     {
00557       public:
00558         AliasKey(const H225_AliasAddress & _alias, const OpalGloballyUniqueID & _id, PINDEX _pos, BOOL _wild = FALSE)
00559           : H225_AliasAddress(_alias), id(_id), pos(_pos), wild(_wild)
00560         { }
00561 
00562         OpalGloballyUniqueID id;
00563         PINDEX pos;
00564         BOOL wild;
00565     };
00566 
00567   protected:
00568     void Construct();
00569 
00570     Error SendUpdateDescriptor(              H501PDU & pdu,  
00571                           const H323TransportAddress & peer, 
00572                            H323PeerElementDescriptor * descriptor,
00573             H501_UpdateInformation_updateType::Choices updateType);
00574 
00575     BOOL OnRemoteServiceRelationshipDisappeared(OpalGloballyUniqueID & serviceID, const H323TransportAddress & peer);
00576     void InternalRemoveServiceRelationship(const H323TransportAddress & peer);
00577     H323Transaction::Response HandleServiceRequest(H501ServiceRequest & info);
00578 
00579     virtual H323PeerElementDescriptor          * CreateDescriptor(const OpalGloballyUniqueID & descriptorID);
00580     virtual H323PeerElementServiceRelationship * CreateServiceRelationship();
00581     virtual AliasKey                           * CreateAliasKey(const H225_AliasAddress & alias, const OpalGloballyUniqueID & id, PINDEX pos, BOOL wild = FALSE);
00582 
00583     void RemoveDescriptorInformation(const H501_ArrayOf_AddressTemplate & addressTemplates);
00584 
00585     PDECLARE_NOTIFIER(PThread, H323PeerElement, MonitorMain);
00586     PDECLARE_NOTIFIER(PThread, H323PeerElement, UpdateAllDescriptors);
00587     PDECLARE_NOTIFIER(PTimer, H323PeerElement, TickleMonitor);
00588 
00589     PMutex localNameMutex;
00590     PString localIdentifier;
00591     PString domainName;
00592 
00593     PSemaphore requestMutex;
00594     PThread  * monitor;
00595     BOOL       monitorStop;
00596     PSyncPoint monitorTickle;
00597 
00598     PMutex basePeerOrdinalMutex;
00599     PINDEX basePeerOrdinal;
00600 
00601     // structures needed to maintain local service relationships (for which we receive a ServiceRequest)
00602     PSafeSortedList<H323PeerElementServiceRelationship> localServiceRelationships;
00603     PMutex localPeerListMutex;
00604     POrdinalSet localServiceOrdinals;
00605 
00606     // structures needed to maintain remote service relationships (for which we send a ServiceRequest)
00607     PMutex remotePeerListMutex;
00608     PSafeSortedList<H323PeerElementServiceRelationship> remoteServiceRelationships;
00609     PStringToString remotePeerAddrToServiceID;
00610     PDICTIONARY(StringToOrdinalKey, PString, POrdinalKey);
00611     StringToOrdinalKey remotePeerAddrToOrdinalKey;
00612 
00613     PSafeSortedList<H323PeerElementDescriptor> descriptors;
00614 
00615     PSORTED_LIST(AliasKeyList, H225_AliasAddress);
00616 
00617     PMutex aliasMutex;
00618     AliasKeyList transportAddressToDescriptorID;
00619     AliasKeyList specificAliasToDescriptorID;
00620     AliasKeyList wildcardAliasToDescriptorID;
00621 };
00622 
00623 
00624 #endif // __OPAL_PECLIENT_H
00625 
00626 

Generated on Fri Mar 7 06:33:40 2008 for OPAL by  doxygen 1.5.1