watcher.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Presence Agent, watcher structure and related functions
  3. *
  4. * $Id$
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #ifndef WATCHER_H
  30. #define WATCHER_H
  31. #include "../../str.h"
  32. #include "../../modules/tm/dlg.h"
  33. #include "../../lib/srdb2/db.h"
  34. #include "../../parser/parse_content.h"
  35. #include "../../parser/parse_event.h" /* EVENT_PRESENCE, EVENT_PRESENCE_WINFO, ... */
  36. #include <stdio.h>
  37. #include <time.h>
  38. #define DOC_XPIDF MIMETYPE(APPLICATION,XPIDFXML)
  39. #define DOC_LPIDF MIMETYPE(APPLICATION,LPIDFXML)
  40. #define DOC_PIDF MIMETYPE(APPLICATION,PIDFXML)
  41. #define DOC_CPIM_PIDF MIMETYPE(APPLICATION,CPIM_PIDFXML)
  42. #define DOC_MSRTC_PIDF MIMETYPE(APPLICATION,XML_MSRTC_PIDF)
  43. #define DOC_WINFO MIMETYPE(APPLICATION,WATCHERINFOXML)
  44. /* DOC_XCAP_CHANGE = (1 << 4),
  45. DOC_LOCATION = (1 << 5),*/
  46. #define DOC_MULTIPART_RELATED MIMETYPE(MULTIPART,RELATED),
  47. #define DOC_RLMI_XML MIMETYPE(APPLICATION,RLMIXML)
  48. typedef enum watcher_status {
  49. WS_PENDING = 0,
  50. WS_ACTIVE = 1,
  51. WS_REJECTED = 2,
  52. WS_TERMINATED = 3,
  53. WS_PENDING_TERMINATED = 4
  54. } watcher_status_t;
  55. extern str watcher_status_names[];
  56. extern str watcher_event_names[];
  57. typedef enum watcher_event {
  58. WE_SUBSCRIBE = 0,
  59. WE_APPROVED = 1,
  60. WE_DEACTIVATED = 2,
  61. WE_PROBATION = 3,
  62. WE_REJECTED = 4,
  63. WE_TIMEOUT = 5,
  64. WE_GIVEUP = 6,
  65. WE_NORESOURCE = 7
  66. } watcher_event_t;
  67. typedef enum wflags {
  68. WFLAG_SUBSCRIPTION_CHANGED=1
  69. } wflags_t;
  70. /*
  71. * Structure representing a watcher
  72. */
  73. typedef struct watcher {
  74. str display_name; /* Display Name of watcher */
  75. str uri; /* Uri of the watcher */
  76. time_t expires; /* Absolute of the expiration */
  77. int event_package; /* event package being watched */
  78. int preferred_mimetype; /* Type of document accepted by the watcher */
  79. int document_index; /* many documents (winfo, ...) requires sequential numbering */
  80. dlg_t* dialog; /* Dialog handle */
  81. str id; /* id of this watcher (used for DB and winfo docs) */
  82. str server_contact; /* used for contact header in NOTIFY messages */
  83. wflags_t flags;
  84. watcher_event_t event;
  85. watcher_status_t status; /* status of subscription */
  86. struct watcher *prev, *next; /* linking members */
  87. } watcher_t;
  88. struct presentity;
  89. /* Convert watcher status name to enum */
  90. watcher_status_t watcher_status_from_string(str *wsname);
  91. /* Create a new watcher structure */
  92. int new_watcher_no_wb(str* _uri, time_t _e, int event_package,
  93. int doc_type, dlg_t* _dlg, str *display_name,
  94. str *server_contact,
  95. str *id, /* database ID or NULL if not loading from DB */
  96. watcher_t** _w);
  97. /* Release a watcher structure */
  98. void free_watcher(watcher_t* _w);
  99. /** Appends watcher/winfo watcher to presentity. It updates presentity's
  100. * flags and adds the watcher into DB if requested and use_db set. */
  101. int append_watcher(struct presentity *_p, watcher_t *_w, int add_to_db);
  102. /* Remove a watcher/winfo watcher from the watcher list and from database. */
  103. void remove_watcher(struct presentity* _p, watcher_t* _w);
  104. /* Find a watcher/winfo watcher in the list/winfo list (according to
  105. * _et parameter) via dialog identifier */
  106. int find_watcher_dlg(struct presentity* _p, dlg_id_t *dlg_id, int _et, watcher_t** _w);
  107. /* update watcher in db */
  108. int db_update_watcher(struct presentity *p, watcher_t* _w);
  109. /* Update expires value of a watcher */
  110. int update_watcher(struct presentity *p, watcher_t* _w, time_t _e, struct sip_msg *m);
  111. /* Read watcherinfo table from database for presentity _p */
  112. int db_read_watcherinfo(struct presentity *_p, db_con_t* db);
  113. /** Returns 1 if given watcher is in one of terminated statuses
  114. * and should be deleted */
  115. int is_watcher_terminated(watcher_t *w);
  116. /** Returns 1 if given watcher can receive status documents */
  117. int is_watcher_authorized(watcher_t *w);
  118. /** Sets status to correct terminated status for this watcher. */
  119. void set_watcher_terminated_status(watcher_t *w);
  120. const char *event_package2str(int et);
  121. #endif /* WATCHER_H */