1 /* 2 * h460p.h 3 * 4 * H460 Presence class. 5 * 6 * h323plus library 7 * 8 * Copyright (c) 2008 ISVO (Asia) Pte. Ltd. 9 * 10 * The contents of this file are subject to the Mozilla Public License 11 * Version 1.1 (the "License"); you may not use this file except in 12 * compliance with the License. You may obtain a copy of the License at 13 * http://www.mozilla.org/MPL/ 14 * 15 * Alternatively, the contents of this file may be used under the terms 16 * of the General Public License (the "GNU License"), in which case the 17 * provisions of GNU License are applicable instead of those 18 * above. If you wish to allow use of your version of this file only 19 * under the terms of the GNU License and not to allow others to use 20 * your version of this file under the MPL, indicate your decision by 21 * deleting the provisions above and replace them with the notice and 22 * other provisions required by the GNU License. If you do not delete 23 * the provisions above, a recipient may use your version of this file 24 * under either the MPL or the GNU License." 25 * 26 * Software distributed under the License is distributed on an "AS IS" 27 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 28 * the License for the specific language governing rights and limitations 29 * under the License. 30 * 31 * 32 * The Initial Developer of the Original Code is ISVO (Asia) Pte. Ltd. 33 * 34 * Contributor(s): ______________________________________. 35 * 36 * $Id$ 37 * 38 * 39 */ 40 41 42 #pragma once 43 44 #include "openh323buildopts.h" 45 46 #ifdef H323_H460P 47 48 #include <ptlib.h> 49 #include <h460/h460pres.h> 50 #include <guid.h> 51 #include <transports.h> 52 #include <list> 53 #include <map> 54 55 class H323PresenceInstruction : public H460P_PresenceInstruction 56 { 57 58 public: 59 60 enum Instruction { 61 e_subscribe, 62 e_unsubscribe, 63 e_block, 64 e_unblock, 65 e_pending 66 }; 67 68 static PString GetInstructionString(unsigned instruct); 69 70 enum Category { 71 e_Audio, 72 e_Video, 73 e_Data, 74 e_ExtVideo, 75 e_Teleprence, 76 e_Meeting, 77 e_UnknownCategory = 100 78 }; 79 80 static PString GetCategoryString(unsigned cat); 81 static H323PresenceInstruction::Category GetCategory(const H460P_PresenceAlias & alias); 82 static bool SetCategory(H323PresenceInstruction::Category cat ,H460P_PresenceAlias & alias); 83 84 H323PresenceInstruction(Instruction instruct, const PString & alias, 85 const PString & display = PString(), const PString & avatar = PString(), Category category=e_UnknownCategory); 86 87 Instruction GetInstruction(); 88 PString GetAlias() const; 89 PString GetAlias(PString & display, PString & avatar, H323PresenceInstruction::Category & category) const; 90 91 }; 92 93 class H323PresenceInstructions : public H460P_PresenceInstruct 94 { 95 public: 96 void Add(const H323PresenceInstruction & instruct); 97 H323PresenceInstruction & operator[](PINDEX i) const; 98 99 void SetAlias(const PString & alias); 100 void GetAlias(PString & alias); 101 102 void SetSize(PINDEX newSize); 103 PINDEX GetSize() const; 104 }; 105 106 /////////////////////////////////////////////////////////////////////////////// 107 108 class H323PresenceNotification : public H460P_PresenceNotification 109 { 110 111 public: 112 113 enum States { 114 e_hidden, 115 e_available, 116 e_online, 117 e_offline, 118 e_onCall, 119 e_voiceMail, 120 e_notAvailable, 121 e_away, 122 e_generic 123 }; 124 125 static PString GetStateString(unsigned state); 126 127 void SetPresenceState(States state, const PString & display = PString()); 128 void SetGenericState(const PString & state); 129 void GetPresenceState(States & state, PString & display) const; 130 131 void AddSupportedFeature(int id); 132 void AddSupportedFeature(const H460P_PresenceFeature & id); 133 void AddEndpointLocale(const H460P_PresenceGeoLocation & loc); 134 void AddGenericData(const H225_ArrayOf_GenericData & data); 135 136 void AddSubscriber(const OpalGloballyUniqueID & guid); 137 OpalGloballyUniqueID GetSubscriber(PINDEX i); 138 void RemoveSubscribers(); 139 void AddAlias(const PString & alias); 140 PString GetAlias() const; 141 142 }; 143 144 class H323PresenceNotifications : public H460P_PresenceNotify 145 { 146 147 public: 148 void Add(const H323PresenceNotification & notify); 149 H323PresenceNotification & operator[](PINDEX i) const; 150 151 void SetAlias(const PString & alias); 152 void GetAlias(PString & alias); 153 154 void SetAliasList(const PStringList & alias); 155 void GetAliasList(PStringList & alias) const; 156 157 void SetSize(PINDEX newSize); 158 PINDEX GetSize() const; 159 160 private: 161 PStringList m_aliasList; 162 }; 163 164 struct PresSubDetails 165 { 166 PString m_display; 167 PString m_avatar; 168 unsigned m_category; 169 }; 170 171 ////////////////////////////////////////////////////////////////////////////////////////// 172 173 typedef std::map<PString,PresSubDetails> PresenceSubscriberList; 174 175 class H323PresenceSubscription : public H460P_PresenceSubscription 176 { 177 178 public: 179 H323PresenceSubscription(); 180 H323PresenceSubscription(const OpalGloballyUniqueID & guid); 181 182 // Sending Gatekeeper 183 void SetSubscriptionDetails(const PString & subscribe, const PStringList & aliases); 184 void SetSubscriptionDetails(const H225_AliasAddress & subscribe, const H225_AliasAddress & subscriber, 185 const PString & display=PString(), const PString & avatar=PString(), 186 H323PresenceInstruction::Category category=H323PresenceInstruction::e_UnknownCategory); 187 void GetSubscriberDetails(PresenceSubscriberList & aliases) const; 188 void GetSubscriberDetails(PStringList & aliases) const; 189 PString GetSubscribed(); 190 191 void SetGatekeeperRAS(const H323TransportAddress & address); 192 H323TransportAddress GetGatekeeperRAS(); 193 194 // Receiving Gatekeeper/Endpoint 195 void MakeDecision(bool approve); 196 bool IsDecisionMade(); 197 int IsApproved(); // -1 not decided; 0 - not approved; 1 - approved; 198 void SetTimeToLive(int t); 199 int GetTimeToLive(); 200 201 void SetSubscription(const OpalGloballyUniqueID & guid); 202 OpalGloballyUniqueID GetSubscription() const; 203 204 void SetApproved(bool success); 205 void AddGenericData(const H225_ArrayOf_GenericData & data); 206 207 }; 208 209 class H323PresenceSubscriptions : public H460P_PresenceAuthorize 210 { 211 public: 212 void Add(const H323PresenceSubscription & sub); 213 H323PresenceSubscription & operator[](PINDEX i) const; 214 215 void SetAlias(const PString & alias); 216 void GetAlias(PString & alias); 217 218 void SetSize(PINDEX newSize); 219 PINDEX GetSize() const; 220 }; 221 222 ////////////////////////////////////////////////////////////////////////////////////////// 223 224 class H323PresenceIdentifiers : public H460P_ArrayOf_PresenceIdentifier 225 { 226 227 public: 228 void Add(const OpalGloballyUniqueID & guid, PBoolean todelete = false); 229 OpalGloballyUniqueID GetIdentifier(PINDEX i); 230 }; 231 232 struct H323PresenceRecord 233 { 234 H225_EndpointIdentifier m_identifer; 235 H225_AliasAddress m_locAlias; 236 H225_AliasAddress m_subAlias; 237 time_t m_timeStamp; 238 unsigned m_ttl; 239 }; 240 241 struct H323PresenceID 242 { 243 PBoolean m_isSubscriber; 244 H225_AliasAddress m_subscriber; 245 H225_AliasAddress m_Alias; 246 PString m_Display; 247 PString m_Avatar; 248 H323PresenceInstruction::Instruction m_Status; 249 H323PresenceInstruction::Category m_Category; 250 PBoolean m_Active; 251 PTime m_Updated; 252 }; 253 254 struct H323PresenceEndpoint 255 { 256 H323PresenceSubscriptions m_Authorize; 257 H323PresenceInstructions m_Instruction; 258 H323PresenceNotifications m_Notify; 259 H323PresenceIdentifiers m_Identifiers; 260 }; 261 262 #define H323PresenceStore std::map<H225_AliasAddress,H323PresenceEndpoint> 263 #define H323PresenceGkStore std::map<H225_TransportAddress,H323PresenceEndpoint> 264 265 template<class Msg> 266 struct Order { operatorOrder267 bool operator()(const Msg & s1, const Msg & s2) const 268 { 269 return s1.Compare(s2) < 0; 270 } 271 }; 272 273 // Indicia 274 #define H323PresenceInd std::map<H225_AliasAddress,list<H460P_PresencePDU>,Order<H225_AliasAddress> > 275 276 277 // Gatekeeper functions 278 #define H323PresenceAlias std::map<H225_AliasAddress,H225_EndpointIdentifier,Order<H225_AliasAddress> > 279 #define H323PresenceLocal std::map<H225_EndpointIdentifier, H323PresenceInd,Order<H225_EndpointIdentifier> > 280 281 #define H323PresenceExternal std::map<H225_AliasAddress,H225_TransportAddress,Order<H225_AliasAddress> > 282 #define H323PresenceRemote std::map<H225_TransportAddress, H323PresenceInd> 283 #define H323PresenceLRQRelay std::map<H460P_PresenceIdentifier,H225_TransportAddress,Order<H460P_PresenceIdentifier> > 284 285 #define H323PresenceIds std::map<H460P_PresenceIdentifier,H323PresenceID,Order<H460P_PresenceIdentifier> > 286 #define H323PresencePending std::map<H225_AliasAddress,H460P_PresenceIdentifier, Order<H225_AliasAddress> > 287 #define H323PresenceIdMap std::map<H225_AliasAddress,H323PresencePending, Order<H225_AliasAddress> > 288 289 290 // Derive you implementation from H323PresenceHandler. 291 292 class H323PresenceHandler : public PObject 293 { 294 PCLASSINFO(H323PresenceHandler, PObject); 295 296 public: 297 bool ReceivedPDU(const PASN_OctetString & pdu, H225_TransportAddress * ip = NULL); 298 299 enum MsgType { 300 e_Status, 301 e_Instruct, 302 e_Authorize, 303 e_Notify, 304 e_Request, 305 e_Response, 306 e_Alive, 307 e_Remove, 308 e_Alert 309 }; 310 311 enum InstType { 312 e_subscribe, 313 e_unsubscribe, 314 e_block, 315 e_unblock, 316 e_pending 317 }; 318 319 class localeInfo { 320 public: 321 localeInfo(); 322 bool BuildLocalePDU(H460P_PresenceGeoLocation & pdu); 323 324 PString m_locale; 325 PString m_region; 326 PString m_country; 327 PString m_countryCode; 328 PString m_latitude; 329 PString m_longitude; 330 PString m_elevation; 331 }; 332 333 virtual PBoolean BuildPresenceElement(unsigned msgtag, ///< RAS Message ID 334 list<PASN_OctetString> & pdu ///< Encoded PresenceElement 335 ); 336 337 virtual PBoolean BuildPresenceElement(unsigned msgtag, ///< Presence Message ID 338 const H225_EndpointIdentifier & ep, ///< Endpoint Identifier 339 list<PASN_OctetString> & pdu ///< Presence Message elements 340 ); 341 342 virtual PBoolean BuildPresenceElement(unsigned msgtag, ///< Presence Message ID 343 const H225_TransportAddress & ip, ///< Transport Address 344 list<PASN_OctetString> & pdu ///< Presence Message elements 345 ); 346 347 // OLD function calls 348 virtual PBoolean BuildPresenceElement(unsigned msgtag, ///< RAS Message ID 349 PASN_OctetString & pdu ///< Encoded PresenceElement 350 ); 351 virtual PBoolean BuildPresenceElement(unsigned msgtag, ///< Presence Message ID 352 const H225_EndpointIdentifier & ep, ///< Endpoint Identifier 353 PASN_OctetString & pdu ///< Presence Message elements 354 ); 355 virtual PBoolean BuildPresenceElement(unsigned msgtag, ///< Presence Message ID 356 const H225_TransportAddress & ip, ///< Transport Address 357 PASN_OctetString & pdu ///< Presence Message elements 358 ); 359 360 361 PBoolean BuildPresenceMessage(unsigned id, ///< Presence Message ID 362 H323PresenceStore & store, ///< Presence Store Information 363 H460P_ArrayOf_PresenceMessage & element ///< Presence Message elements 364 ); 365 366 PBoolean BuildPresenceMessage(unsigned id, ///< Presence Message ID 367 const H225_EndpointIdentifier & ep, ///< Endpoint Identifier 368 H460P_ArrayOf_PresenceMessage & msgs ///< Presence Message elements 369 ); 370 371 PBoolean BuildPresenceMessage(unsigned id, ///< Presence Message ID 372 const H225_TransportAddress & ip, ///< Transport Address 373 H460P_ArrayOf_PresenceMessage & msgs ///< Presence Message elements 374 ); 375 376 virtual H323PresenceStore & GetPresenceStoreLocked(unsigned msgtag =0); 377 virtual void PresenceStoreUnLock(unsigned msgtag = 0); 378 379 // Events Endpoints OnNotification(MsgType,const H460P_PresenceNotification &,const H225_AliasAddress &)380 virtual void OnNotification(MsgType /*tag*/, 381 const H460P_PresenceNotification & /*notify*/, 382 const H225_AliasAddress & /*addr*/ 383 ) {} 384 OnSubscription(MsgType,const H460P_PresenceSubscription &,const H225_AliasAddress &)385 virtual void OnSubscription(MsgType /*tag*/, 386 const H460P_PresenceSubscription & /*subscription*/, 387 const H225_AliasAddress & /*addr*/ 388 ) {} 389 OnInstructions(MsgType,const H460P_ArrayOf_PresenceInstruction &,const H225_AliasAddress &)390 virtual void OnInstructions(MsgType /*tag*/, 391 const H460P_ArrayOf_PresenceInstruction & /*instruction*/, 392 const H225_AliasAddress & /*addr*/ 393 ) {} 394 395 // Events Gatekeepers OnNotification(MsgType,const H460P_PresenceNotification &,const H225_TransportAddress &)396 virtual void OnNotification(MsgType /*tag*/, 397 const H460P_PresenceNotification & /*notify*/, 398 const H225_TransportAddress & /*ip*/ 399 ) {} 400 OnSubscription(MsgType,const H460P_PresenceSubscription &,const H225_TransportAddress &)401 virtual void OnSubscription(MsgType /*tag*/, 402 const H460P_PresenceSubscription & /*subscription*/, 403 const H225_TransportAddress & /*ip*/ 404 ) {} 405 OnIdentifiers(MsgType,const H460P_PresenceIdentifier &,const H225_TransportAddress &)406 virtual void OnIdentifiers(MsgType /*tag*/, 407 const H460P_PresenceIdentifier & /*identifier*/, 408 const H225_TransportAddress & /*ip*/ 409 ) {} 410 411 412 // Build Endpoint Callbacks BuildSubscription(const H225_EndpointIdentifier &,H323PresenceStore &)413 virtual PBoolean BuildSubscription(const H225_EndpointIdentifier & /*ep*/, 414 H323PresenceStore & /*subscription*/ 415 ) { return false; } 416 BuildNotification(const H225_EndpointIdentifier &,H323PresenceStore &)417 virtual PBoolean BuildNotification(const H225_EndpointIdentifier & /*ep*/, 418 H323PresenceStore & /*notify*/ 419 ) { return false; } 420 BuildInstructions(const H225_EndpointIdentifier &,H323PresenceStore &)421 virtual PBoolean BuildInstructions(const H225_EndpointIdentifier & /*ep*/, 422 H323PresenceStore & /*instruction*/ 423 ) { return false; } 424 425 // Build Gatekeeper Callbacks BuildSubscription(bool,const H225_TransportAddress &,H323PresenceGkStore &)426 virtual PBoolean BuildSubscription(bool /*request*/, 427 const H225_TransportAddress & /*ip*/, 428 H323PresenceGkStore & /*subscription*/ 429 ) { return false; } 430 BuildNotification(const H225_TransportAddress &,H323PresenceGkStore &)431 virtual PBoolean BuildNotification( 432 const H225_TransportAddress & /*ip*/, 433 H323PresenceGkStore & /*notify*/ 434 ) { return false; } 435 BuildIdentifiers(bool,const H225_TransportAddress &,H323PresenceGkStore &)436 virtual PBoolean BuildIdentifiers(bool /*alive*/, 437 const H225_TransportAddress & /*ip*/, 438 H323PresenceGkStore & /*identifiers*/ 439 ) { return false; } 440 441 protected: 442 // Build Messages 443 H460P_PresenceStatus & BuildStatus(H460P_ArrayOf_PresenceMessage & msg, 444 const H323PresenceNotifications & notify, 445 const H323PresenceInstructions & inst, 446 const H225_AliasAddress & alias); 447 H460P_PresenceInstruct & BuildInstruct(H460P_ArrayOf_PresenceMessage & msg, 448 const H323PresenceInstructions & inst, 449 const H225_AliasAddress & alias); 450 H460P_PresenceAuthorize & BuildAuthorize(H460P_PresenceMessage & msg, 451 const H323PresenceSubscriptions & subs); 452 H460P_PresenceNotify & BuildNotify(H460P_PresenceMessage & msg, 453 const H323PresenceNotifications & notify); 454 H460P_PresenceRequest & BuildRequest(H460P_PresenceMessage & msg, 455 const H323PresenceSubscriptions & subs); 456 H460P_PresenceResponse & BuildResponse(H460P_PresenceMessage & msg, 457 const H323PresenceSubscriptions & subs); 458 H460P_PresenceAlive & BuildAlive(H460P_PresenceMessage & msg, 459 const H323PresenceIdentifiers & id); 460 H460P_PresenceRemove & BuildRemove(H460P_PresenceMessage & msg, 461 const H323PresenceIdentifiers & id); 462 H460P_PresenceAlert & BuildAlert(H460P_PresenceMessage & msg, 463 const H323PresenceNotifications & notify); 464 465 private: 466 H323PresenceStore m_presenceStore; 467 PMutex storeMutex; 468 }; 469 470 471 #endif 472 473 474