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

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

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