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 #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
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
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
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
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
00602 PSafeSortedList<H323PeerElementServiceRelationship> localServiceRelationships;
00603 PMutex localPeerListMutex;
00604 POrdinalSet localServiceOrdinals;
00605
00606
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