status_query.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include <stdio.h>
  2. #include "../../str.h"
  3. #include "../../dprint.h"
  4. #include "../../mem/mem.h"
  5. #include "dlist.h"
  6. #include "presentity.h"
  7. #include "watcher.h"
  8. #include "pdomain.h"
  9. #include "pa_mod.h"
  10. #include <libxml/parser.h>
  11. #include <libxml/xpath.h>
  12. #include <presence/pidf.h>
  13. #include <cds/logger.h>
  14. /* Helper functions */
  15. presence_tuple_t *find_online_tuple(presentity_t *p,
  16. presence_tuple_t *search_from)
  17. {
  18. presence_tuple_t *t = NULL;
  19. if (!p) return t;
  20. if (search_from) t = search_from;
  21. else t = get_first_tuple(p);
  22. while (t) {
  23. switch (t->data.status.basic) {
  24. case presence_tuple_open: return t;
  25. /* TODO: what about other state values? */
  26. default: break;
  27. }
  28. t = get_next_tuple(t);
  29. }
  30. return NULL;
  31. }
  32. /* Handler functions */
  33. int target_online(struct sip_msg* _m, char* _domain, char* _s2)
  34. {
  35. struct pdomain* d;
  36. struct presentity *p;
  37. str uid = STR_NULL;
  38. int res = -1;
  39. presence_tuple_t *t;
  40. d = (struct pdomain*)_domain;
  41. if (get_presentity_uid(&uid, _m) < 0) {
  42. ERR("Error while extracting presentity UID\n");
  43. return 0; /* ??? impossible to return -1 or 1 */
  44. }
  45. /* TRACE_LOG("is \'%.*s\' online ?\n", FMT_STR(uid)); */
  46. lock_pdomain(d);
  47. if (find_presentity_uid(d, &uid, &p) == 0) {
  48. /* presentity found */
  49. t = find_online_tuple(p, NULL);
  50. if (t) res = 1; /* online tuple found */
  51. }
  52. unlock_pdomain(d);
  53. return res;
  54. }
  55. /* check watcher status for given value */
  56. int test_watcher_status(struct sip_msg* _m, char* _domain, char* _status)
  57. {
  58. /* returns watcher's authorization status (only existing watchers - should
  59. * be called after processing SUBSCRIBE request) */
  60. /* find presentity, not found => -1*/
  61. /* find watcher, not found => -1 */
  62. /* test if auth == watcher status => -1/1 */
  63. return -1;
  64. }