00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
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
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
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
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
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
00609 PSafeSortedList<H323PeerElementServiceRelationship> localServiceRelationships;
00610 PMutex localPeerListMutex;
00611 POrdinalSet localServiceOrdinals;
00612
00613
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