presentity.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Presence Agent, presentity structure and related functions
  3. *
  4. * $Id$
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. * Copyright (C) 2004 Jamey Hicks
  8. *
  9. * This file is part of ser, a free SIP server.
  10. *
  11. * ser is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version
  15. *
  16. * For a license to use the ser software under conditions
  17. * other than those described here, or to purchase support for this
  18. * software, please contact iptel.org by e-mail at the following addresses:
  19. * [email protected]
  20. *
  21. * ser is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  29. */
  30. #ifndef PRESENTITY_H
  31. #define PRESENTITY_H
  32. #include "../../str.h"
  33. #include "../../modules/tm/dlg.h"
  34. #include "watcher.h"
  35. #include "hslot.h"
  36. #include "trace.h"
  37. #include "pdomain.h"
  38. #include <xcap/pres_rules.h>
  39. #include <cds/msg_queue.h>
  40. #include <cds/list.h>
  41. #include <presence/notifier.h>
  42. #include <presence/subscriber.h>
  43. #include <presence/pres_doc.h>
  44. #include <cds/dbid.h>
  45. typedef struct presence_tuple {
  46. presence_tuple_info_t data;
  47. /* Contact is constant for non-published tuples and it is allocated
  48. * together with whole structure. For published tuples is contact
  49. * allocated separately in shared memory and can change. */
  50. int is_published; /* 1 for published tuples - these are stored into DB */
  51. str etag; /* etag for published tuples -> constant for tuple life */
  52. time_t expires; /* tuple expires on ... */
  53. str published_id; /* tuple id used for publish -> constant for tuple life */
  54. } presence_tuple_t;
  55. typedef struct {
  56. presence_note_t data;
  57. str etag; /* published via this etag -> constant for note life */
  58. time_t expires; /* note expires on ... */
  59. str dbid; /* id for database ops - needed for removing expired notes -> constant for note life */
  60. } pa_presence_note_t;
  61. typedef struct _pa_extension_element_t {
  62. extension_element_t data;
  63. str etag; /* published via this etag -> constant for structure life */
  64. time_t expires; /* expires on ... */
  65. str dbid; /* id for database ops - needed for removing expired -> constant for structure life */
  66. } pa_extension_element_t;
  67. typedef struct {
  68. str user;
  69. str contact;
  70. basic_tuple_status_t state;
  71. } tuple_change_info_t;
  72. struct pdomain;
  73. typedef enum pflag {
  74. PFLAG_PRESENCE_CHANGED=1,
  75. PFLAG_WATCHERINFO_CHANGED=2
  76. } pflag_t;
  77. typedef struct _internal_pa_subscription_t {
  78. struct _internal_pa_subscription_t *prev, *next;
  79. watcher_status_t status;
  80. qsa_subscription_t *subscription;
  81. /* msg_queue_t *dst;
  82. * str_t package;
  83. * str_t watcher_uri; */
  84. } internal_pa_subscription_t;
  85. typedef struct presentity {
  86. /* URI of presentity - doesn't change for the presentity's life */
  87. presentity_info_t data;
  88. str uuid; /* use after usrloc uuid-zation - callbacks are
  89. registered to this, - doesn't change for
  90. the presentity's life */
  91. str pres_id; /* id of the record in the presentity table (generated!) */
  92. int id_cntr; /* variable for generating watcher/tuple/... ids */
  93. /* provisional data members */
  94. int ref_cnt; /* reference counter - don't remove if > 1 */
  95. pflag_t flags;
  96. struct pdomain *pdomain;
  97. struct presentity* next; /* Next presentity */
  98. struct presentity* prev; /* Previous presentity in list */
  99. struct hslot* slot; /* Hash table collision slot we belong to */
  100. /* watchers/winfo watchers/internal watchers */
  101. watcher_t *first_watcher, *last_watcher; /* List of watchers */
  102. watcher_t *first_winfo_watcher, *last_winfo_watcher; /* Watchers subscribed to winfo */
  103. internal_pa_subscription_t *first_qsa_subscription, *last_qsa_subscription;
  104. /* authorization data */
  105. presence_rules_t *authorization_info;
  106. xcap_query_params_t xcap_params; /* doesn't change for the presentity's life (FIXME: rewrite) */
  107. time_t auth_rules_refresh_time;
  108. msg_queue_t mq; /* message queue supplying direct usrloc callback processing */
  109. /* data for internal subscriptions to presence
  110. * (reduces memory allocation count) */
  111. qsa_subscription_data_t presence_subscription_data;
  112. qsa_subscription_t *presence_subscription;
  113. } presentity_t;
  114. /* shortcuts for PA structures walking (PA uses derived structures
  115. * instead of that defined in presence library because it needs
  116. * to store more information) */
  117. #define get_first_tuple(p) ((presence_tuple_t*)(p->data.first_tuple))
  118. #define get_next_tuple(t) ((presence_tuple_t*)(t->data.next))
  119. #define get_first_note(p) ((pa_presence_note_t*)(p->data.first_note))
  120. #define get_next_note(n) ((pa_presence_note_t*)(n->data.next))
  121. #define get_first_extension(p) ((pa_extension_element_t*)(p->data.first_unknown_element))
  122. #define get_next_extension(pe) ((pa_extension_element_t*)(pe->data.next))
  123. /** Create a new presentity. */
  124. int new_presentity(struct pdomain *pdomain, str* _uri, str *uid,
  125. xcap_query_params_t *xcap_params, presentity_t** _p);
  126. /** Free all memory associated with a presentity - use only in special
  127. * cases like freeing memory on module cleanup. Otherwise use
  128. * release_presentity instead. */
  129. void free_presentity(presentity_t* _p);
  130. /* Free all memory associated with a presentity and remove it from DB */
  131. void release_presentity(presentity_t* _p);
  132. /** Removes all data for presentity (tuples, watchers, tuple notes, ...)
  133. * from given database table.
  134. * It is possible due to that pres_id is unique identifier
  135. * common for all tables */
  136. int db_remove_presentity_data(presentity_t* presentity, const char *table);
  137. /* set authorization rules for presentity
  138. * ! call from locked region only ! */
  139. int set_auth_rules(presentity_t *p, presence_rules_t *new_auth_rules);
  140. /* Run a timer handler on the presentity - cleanup of expired data, sending
  141. * notifications when presentity modified, ... */
  142. int timer_presentity(presentity_t* _p);
  143. /********** UTILITY functions **********/
  144. /* Gets UID from message (using get_to_uid)
  145. * (it never allocates memory !!!) */
  146. int get_presentity_uid(str *uid_dst, struct sip_msg *m);
  147. /*
  148. * converts uri to uid (uid is allocated in shm)
  149. * used by internal subscriptions and fifo commands
  150. * FIXME: remove (internal subscriptions will be through UID too)
  151. */
  152. int pres_uri2uid(str_t *uid_dst, const str_t *uri);
  153. /* FIXME: change to local function within pdomain.c as soon as
  154. * will be message queue data types solved */
  155. void free_tuple_change_info_content(tuple_change_info_t *i);
  156. /************ Parameters **********/
  157. /* how often refresh authorization rules (xcap change events are
  158. * not implemented yet!) */
  159. extern int auth_rules_refresh_time;
  160. int pdomain_load_presentities(struct pdomain *pdomain);
  161. #endif /* PRESENTITY_H */