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
00132
00133
00134 #ifndef __OPAL_PECLIENT_H
00135 #define __OPAL_PECLIENT_H
00136
00137 #ifdef P_USE_PRAGMA
00138 #pragma interface
00139 #endif
00140
00141
00142 #include "h323annexg.h"
00143 #include "h323ep.h"
00144 #include "h501.h"
00145
00146 #include <ptlib/safecoll.h>
00147
00148
00149 class H323PeerElement;
00150
00151
00153
00154 class H501Transaction : public H323Transaction
00155 {
00156 PCLASSINFO(H501Transaction, H323Transaction);
00157 public:
00158 H501Transaction(
00159 H323PeerElement & pe,
00160 const H501PDU & pdu,
00161 BOOL hasReject
00162 );
00163
00164 virtual H323TransactionPDU * CreateRIP(
00165 unsigned sequenceNumber,
00166 unsigned delay
00167 ) const;
00168
00169 virtual H235Authenticator::ValidationResult ValidatePDU() const;
00170
00171 H501_MessageCommonInfo & requestCommon;
00172 H501_MessageCommonInfo & confirmCommon;
00173
00174 protected:
00175 H323PeerElement & peerElement;
00176 };
00177
00178
00180
00181 class H501ServiceRequest : public H501Transaction
00182 {
00183 PCLASSINFO(H501ServiceRequest, H501Transaction);
00184 public:
00185 H501ServiceRequest(
00186 H323PeerElement & pe,
00187 const H501PDU & pdu
00188 );
00189
00190 #if PTRACING
00191 virtual const char * GetName() const;
00192 #endif
00193 virtual void SetRejectReason(
00194 unsigned reasonCode
00195 );
00196
00197 H501_ServiceRequest & srq;
00198 H501_ServiceConfirmation & scf;
00199 H501_ServiceRejection & srj;
00200
00201 protected:
00202 virtual Response OnHandlePDU();
00203 };
00204
00205
00207
00208 class H501DescriptorUpdate : public H501Transaction
00209 {
00210 PCLASSINFO(H501DescriptorUpdate, H501Transaction);
00211 public:
00212 H501DescriptorUpdate(
00213 H323PeerElement & pe,
00214 const H501PDU & pdu
00215 );
00216
00217 #if PTRACING
00218 virtual const char * GetName() const;
00219 #endif
00220 virtual void SetRejectReason(
00221 unsigned reasonCode
00222 );
00223
00224 H501_DescriptorUpdate & du;
00225 H501_DescriptorUpdateAck & ack;
00226
00227 protected:
00228 virtual Response OnHandlePDU();
00229 };
00230
00231
00233
00234 class H501AccessRequest : public H501Transaction
00235 {
00236 PCLASSINFO(H501AccessRequest, H501Transaction);
00237 public:
00238 H501AccessRequest(
00239 H323PeerElement & pe,
00240 const H501PDU & pdu
00241 );
00242
00243 #if PTRACING
00244 virtual const char * GetName() const;
00245 #endif
00246 virtual void SetRejectReason(
00247 unsigned reasonCode
00248 );
00249
00250 H501_AccessRequest & arq;
00251 H501_AccessConfirmation & acf;
00252 H501_AccessRejection & arj;
00253
00254 protected:
00255 virtual Response OnHandlePDU();
00256 };
00257
00258
00260
00261 class H323PeerElementDescriptor : public PSafeObject
00262 {
00263 PCLASSINFO(H323PeerElementDescriptor, PSafeObject);
00264 public:
00265 H323PeerElementDescriptor(const OpalGloballyUniqueID & _descriptorID)
00266 : descriptorID(_descriptorID), state(Dirty), creator(0)
00267 { }
00268
00269 Comparison Compare(const PObject & obj) const;
00270
00271 enum Options {
00272 Protocol_H323 = 0x0001,
00273 Protocol_Voice = 0x0002,
00274 Protocol_Max = 0x0002,
00275 Option_WildCard = 0x0004,
00276 Option_SendAccessRequest = 0x0008,
00277 Option_NotAvailable = 0x0010,
00278 Option_PrioritySet = 0x0020,
00279 Option_PriorityMask = 0x1fc0,
00280 };
00281
00282 enum {
00283 HighestPriority = 0,
00284 DefaultPriority = 80,
00285 LowestPriority = 127
00286 };
00287
00288 static inline unsigned SetPriorityOption(unsigned pri) { return Option_PrioritySet | ((pri & 0x7f) << 6); }
00289 static inline unsigned GetPriorityOption(unsigned options) { return (options & Option_PrioritySet) ? ((options >> 6) & 0x7f) : DefaultPriority; }
00290
00291 void CopyTo(H501_Descriptor & descriptor);
00292 static BOOL CopyToAddressTemplate(H501_AddressTemplate & addressTemplates,
00293 const H225_EndpointType & ep,
00294 const H225_ArrayOf_AliasAddress & aliases,
00295 const H225_ArrayOf_AliasAddress & transportAddress,
00296 unsigned options = H323PeerElementDescriptor::Protocol_H323);
00297
00298 static void SetProtocolList(H501_ArrayOf_SupportedProtocols & h501Protocols, unsigned protocols);
00299 static unsigned GetProtocolList(const H501_ArrayOf_SupportedProtocols & h501Protocols);
00300
00301 OpalGloballyUniqueID descriptorID;
00302
00303 BOOL ContainsNonexistent();
00304
00305 enum States {
00306 Clean,
00307 Dirty,
00308 Deleted
00309 } state;
00310
00311 H501_ArrayOf_AddressTemplate addressTemplates;
00312 PString gatekeeperID;
00313 PTime lastChanged;
00314 POrdinalKey creator;
00315 };
00316
00317
00319
00320 class H323PeerElementServiceRelationship : public PSafeObject
00321 {
00322 PCLASSINFO(H323PeerElementServiceRelationship, PSafeObject);
00323 public:
00324 H323PeerElementServiceRelationship()
00325 : ordinal(0)
00326 { }
00327
00328 H323PeerElementServiceRelationship(const OpalGloballyUniqueID & _serviceID)
00329 : serviceID(_serviceID), ordinal(0)
00330 { }
00331
00332 Comparison Compare(const PObject & obj) const
00333 { return serviceID.Compare(((H323PeerElementServiceRelationship&)obj).serviceID); }
00334
00335 OpalGloballyUniqueID serviceID;
00336 POrdinalKey ordinal;
00337 H323TransportAddress peer;
00338 PString name;
00339 PTime createdTime;
00340 PTime lastUpdateTime;
00341 PTime expireTime;
00342 };
00343
00344
00346
00349 class H323PeerElement : public H323_AnnexG
00350 {
00351 PCLASSINFO(H323PeerElement, H323_AnnexG);
00352 public:
00357 H323PeerElement(
00358 H323EndPoint & endpoint,
00359 H323Transport * transport = NULL
00360 );
00361 H323PeerElement(
00362 H323EndPoint & endpoint,
00363 const H323TransportAddress & addr
00364 );
00365
00368 ~H323PeerElement();
00370
00371 enum Error {
00372 Confirmed,
00373 Rejected,
00374 NoResponse,
00375 NoServiceRelationship,
00376 ServiceRelationshipReestablished
00377 };
00378
00379 enum {
00380 LocalServiceRelationshipOrdinal = 0,
00381 NoServiceRelationshipOrdinal = 1,
00382 RemoteServiceRelationshipOrdinal = 2
00383 };
00384
00389 void PrintOn(
00390 ostream & strm
00391 ) const;
00393
00394 PSafePtr<H323PeerElementDescriptor> GetFirstDescriptor(
00395 PSafetyMode mode = PSafeReference
00396 ) { return PSafePtr<H323PeerElementDescriptor>(descriptors, mode); }
00397
00398 PSafePtr<H323PeerElementServiceRelationship> GetFirstLocalServiceRelationship(
00399 PSafetyMode mode = PSafeReference
00400 ) { return PSafePtr<H323PeerElementServiceRelationship>(localServiceRelationships, mode); }
00401
00402 PSafePtr<H323PeerElementServiceRelationship> GetFirstRemoteServiceRelationship(
00403 PSafetyMode mode = PSafeReference
00404 ) { return PSafePtr<H323PeerElementServiceRelationship>(remoteServiceRelationships, mode); }
00405
00406 void SetLocalName(const PString & name);
00407 PString GetLocalName() const;
00408
00409 void SetDomainName(const PString & name);
00410 PString GetDomainName() const;
00411
00412
00413
00414
00415
00418 BOOL SetOnlyServiceRelationship(const PString & peer, BOOL keepTrying = TRUE);
00419 BOOL AddServiceRelationship(const H323TransportAddress & peer, BOOL keepTrying = TRUE);
00420 BOOL AddServiceRelationship(const H323TransportAddress & peer, OpalGloballyUniqueID & serviceID, BOOL keepTrying = TRUE);
00421 BOOL RemoveServiceRelationship(const OpalGloballyUniqueID & serviceID, int reason = H501_ServiceReleaseReason::e_terminated);
00422 BOOL RemoveServiceRelationship(const H323TransportAddress & peer, int reason = H501_ServiceReleaseReason::e_terminated);
00423 BOOL RemoveAllServiceRelationships();
00424
00425 Error ServiceRequestByAddr(const H323TransportAddress & peer);
00426 Error ServiceRequestByAddr(const H323TransportAddress & peer, OpalGloballyUniqueID & serviceID);
00427 Error ServiceRequestByID(OpalGloballyUniqueID & serviceID);
00428
00431 BOOL ServiceRelease(const OpalGloballyUniqueID & serviceID, unsigned reason);
00432
00433
00434
00435
00436
00437 BOOL AddDescriptor(
00438 const OpalGloballyUniqueID & descriptorID,
00439 const PStringArray & aliases,
00440 const H323TransportAddressArray & transportAddrs,
00441 unsigned options = H323PeerElementDescriptor::Protocol_H323,
00442 BOOL now = FALSE
00443 );
00444
00445 BOOL AddDescriptor(
00446 const OpalGloballyUniqueID & descriptorID,
00447 const H225_ArrayOf_AliasAddress & aliases,
00448 const H323TransportAddressArray & transportAddrs,
00449 unsigned options = H323PeerElementDescriptor::Protocol_H323,
00450 BOOL now = FALSE
00451 );
00452
00453 BOOL AddDescriptor(
00454 const OpalGloballyUniqueID & descriptorID,
00455 const H225_ArrayOf_AliasAddress & aliases,
00456 const H225_ArrayOf_AliasAddress & transportAddr,
00457 unsigned options = H323PeerElementDescriptor::Protocol_H323,
00458 BOOL now = FALSE
00459 );
00460
00461 BOOL AddDescriptor(
00462 const OpalGloballyUniqueID & descriptorID,
00463 const POrdinalKey & creator,
00464 const H225_ArrayOf_AliasAddress & alias,
00465 const H225_ArrayOf_AliasAddress & transportAddresses,
00466 unsigned options = H323PeerElementDescriptor::Protocol_H323,
00467 BOOL now = FALSE
00468 );
00469
00470 BOOL AddDescriptor(
00471 const OpalGloballyUniqueID & descriptorID,
00472 const POrdinalKey & creator,
00473 const H501_ArrayOf_AddressTemplate & addressTemplates,
00474 const PTime & updateTime,
00475 BOOL now = FALSE
00476 );
00477
00480 BOOL DeleteDescriptor(const PString & alias, BOOL now = FALSE);
00481 BOOL DeleteDescriptor(const H225_AliasAddress & alias, BOOL now = FALSE);
00482 BOOL DeleteDescriptor(const OpalGloballyUniqueID & descriptorID, BOOL now = FALSE);
00483
00486 BOOL AccessRequest(
00487 const PString & searchAlias,
00488 PStringArray & destAliases,
00489 H323TransportAddress & transportAddress,
00490 unsigned options = H323PeerElementDescriptor::Protocol_H323
00491 );
00492
00493 BOOL AccessRequest(
00494 const PString & searchAlias,
00495 H225_ArrayOf_AliasAddress & destAliases,
00496 H323TransportAddress & transportAddress,
00497 unsigned options = H323PeerElementDescriptor::Protocol_H323
00498 );
00499
00500 BOOL AccessRequest(
00501 const H225_AliasAddress & searchAlias,
00502 H225_ArrayOf_AliasAddress & destAliases,
00503 H323TransportAddress & transportAddress,
00504 unsigned options = H323PeerElementDescriptor::Protocol_H323
00505 );
00506
00507 BOOL AccessRequest(
00508 const H225_AliasAddress & alias,
00509 H225_ArrayOf_AliasAddress & destAliases,
00510 H225_AliasAddress & transportAddress,
00511 unsigned options = H323PeerElementDescriptor::Protocol_H323
00512 );
00513
00514
00515
00516
00517 BOOL UpdateDescriptor(H323PeerElementDescriptor * descriptor);
00518 BOOL UpdateDescriptor(H323PeerElementDescriptor * descriptor, H501_UpdateInformation_updateType::Choices updateType);
00519
00520
00521 Error SendUpdateDescriptorByID(const OpalGloballyUniqueID & serviceID,
00522 H323PeerElementDescriptor * descriptor,
00523 H501_UpdateInformation_updateType::Choices updateType);
00524
00525 Error SendUpdateDescriptorByAddr(const H323TransportAddress & peer,
00526 H323PeerElementDescriptor * descriptor,
00527 H501_UpdateInformation_updateType::Choices updateType);
00528
00529 Error SendAccessRequestByID(const OpalGloballyUniqueID & peerID,
00530 H501PDU & request,
00531 H501PDU & confirmPDU);
00532
00533 Error SendAccessRequestByAddr(const H323TransportAddress & peerAddr,
00534 H501PDU & request,
00535 H501PDU & confirmPDU);
00536
00537
00538
00539
00540
00541
00542 BOOL MakeRequest(H323_AnnexG::Request & request);
00543
00544 virtual void OnAddServiceRelationship(const H323TransportAddress &) { }
00545 virtual void OnRemoveServiceRelationship(const H323TransportAddress &) { }
00546
00547 virtual void OnNewDescriptor(const H323PeerElementDescriptor &) { }
00548 virtual void OnUpdateDescriptor(const H323PeerElementDescriptor &) { }
00549 virtual void OnRemoveDescriptor(const H323PeerElementDescriptor &) { }
00550
00551 virtual H323Transaction::Response OnServiceRequest(H501ServiceRequest & info);
00552 virtual H323Transaction::Response OnDescriptorUpdate(H501DescriptorUpdate & info);
00553 virtual H323Transaction::Response OnAccessRequest(H501AccessRequest & info);
00554
00555 BOOL OnReceiveServiceRequest(const H501PDU & pdu, const H501_ServiceRequest & pduBody);
00556 BOOL OnReceiveServiceConfirmation(const H501PDU & pdu, const H501_ServiceConfirmation & pduBody);
00557
00558 BOOL OnReceiveDescriptorUpdate(const H501PDU & pdu, const H501_DescriptorUpdate & pduBody);
00559 BOOL OnReceiveDescriptorUpdateACK(const H501PDU & pdu, const H501_DescriptorUpdateAck & pduBody);
00560
00561 BOOL OnReceiveAccessRequest(const H501PDU & pdu, const H501_AccessRequest & pduBody);
00562 BOOL OnReceiveAccessConfirmation (const H501PDU & pdu, const H501_AccessConfirmation & pduBody);
00563 BOOL OnReceiveAccessRejection(const H501PDU & pdu, const H501_AccessRejection & pduBody);
00564
00565 class AliasKey : public H225_AliasAddress
00566 {
00567 public:
00568 AliasKey(const H225_AliasAddress & _alias, const OpalGloballyUniqueID & _id, PINDEX _pos, BOOL _wild = FALSE)
00569 : H225_AliasAddress(_alias), id(_id), pos(_pos), wild(_wild)
00570 { }
00571
00572 OpalGloballyUniqueID id;
00573 PINDEX pos;
00574 BOOL wild;
00575 };
00576
00577 protected:
00578 void Construct();
00579
00580 Error SendUpdateDescriptor( H501PDU & pdu,
00581 const H323TransportAddress & peer,
00582 H323PeerElementDescriptor * descriptor,
00583 H501_UpdateInformation_updateType::Choices updateType);
00584
00585 BOOL OnRemoteServiceRelationshipDisappeared(OpalGloballyUniqueID & serviceID, const H323TransportAddress & peer);
00586 void InternalRemoveServiceRelationship(const H323TransportAddress & peer);
00587 H323Transaction::Response HandleServiceRequest(H501ServiceRequest & info);
00588
00589 virtual H323PeerElementDescriptor * CreateDescriptor(const OpalGloballyUniqueID & descriptorID);
00590 virtual H323PeerElementServiceRelationship * CreateServiceRelationship();
00591 virtual AliasKey * CreateAliasKey(const H225_AliasAddress & alias, const OpalGloballyUniqueID & id, PINDEX pos, BOOL wild = FALSE);
00592
00593 void RemoveDescriptorInformation(const H501_ArrayOf_AddressTemplate & addressTemplates);
00594
00595 PDECLARE_NOTIFIER(PThread, H323PeerElement, MonitorMain);
00596 PDECLARE_NOTIFIER(PThread, H323PeerElement, UpdateAllDescriptors);
00597 PDECLARE_NOTIFIER(PTimer, H323PeerElement, TickleMonitor);
00598
00599 PMutex localNameMutex;
00600 PString localIdentifier;
00601 PString domainName;
00602
00603 PSemaphore requestMutex;
00604 PThread * monitor;
00605 BOOL monitorStop;
00606 PSyncPoint monitorTickle;
00607
00608 PMutex basePeerOrdinalMutex;
00609 PINDEX basePeerOrdinal;
00610
00611
00612 PSafeSortedList<H323PeerElementServiceRelationship> localServiceRelationships;
00613 PMutex localPeerListMutex;
00614 POrdinalSet localServiceOrdinals;
00615
00616
00617 PMutex remotePeerListMutex;
00618 PSafeSortedList<H323PeerElementServiceRelationship> remoteServiceRelationships;
00619 PStringToString remotePeerAddrToServiceID;
00620 PDICTIONARY(StringToOrdinalKey, PString, POrdinalKey);
00621 StringToOrdinalKey remotePeerAddrToOrdinalKey;
00622
00623 PSafeSortedList<H323PeerElementDescriptor> descriptors;
00624
00625 PSORTED_LIST(AliasKeyList, H225_AliasAddress);
00626
00627 PMutex aliasMutex;
00628 AliasKeyList transportAddressToDescriptorID;
00629 AliasKeyList specificAliasToDescriptorID;
00630 AliasKeyList wildcardAliasToDescriptorID;
00631 };
00632
00633
00634 #endif // __OPAL_PECLIENT_H
00635
00636