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 #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
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
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
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
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
00606 PSafeSortedList<H323PeerElementServiceRelationship> localServiceRelationships;
00607 PMutex localPeerListMutex;
00608 POrdinalSet localServiceOrdinals;
00609
00610
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