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