res_pjsip_pidf_eyebeam_body_supplement.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2014, Digium, Inc.
  5. *
  6. * Mark Michelson <mmichelson@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*** MODULEINFO
  19. <depend>pjproject</depend>
  20. <depend>res_pjsip</depend>
  21. <depend>res_pjsip_pubsub</depend>
  22. <support_level>core</support_level>
  23. ***/
  24. #include "asterisk.h"
  25. #include <pjsip.h>
  26. #include <pjsip_simple.h>
  27. #include <pjlib.h>
  28. #include "asterisk/module.h"
  29. #include "asterisk/res_pjsip.h"
  30. #include "asterisk/res_pjsip_pubsub.h"
  31. #include "asterisk/res_pjsip_presence_xml.h"
  32. #include "asterisk/res_pjsip_body_generator_types.h"
  33. /*!
  34. * \internal
  35. * \brief Adds non standard elements to the xml body
  36. *
  37. * This is some code that was part of the original chan_sip implementation
  38. * that is not part of the RFC 3863 definition, but we are keeping available
  39. * for backward compatability. The original comment stated that Eyebeam
  40. * supports this format.
  41. */
  42. static void add_eyebeam(pj_pool_t *pool, pj_xml_node *node, const char *pidfstate)
  43. {
  44. static const char *XMLNS_PP = "xmlns:pp";
  45. static const char *XMLNS_PERSON = "urn:ietf:params:xml:ns:pidf:person";
  46. static const char *XMLNS_ES = "xmlns:es";
  47. static const char *XMLNS_RPID_STATUS = "urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status";
  48. static const char *XMLNS_EP = "xmlns:ep";
  49. static const char *XMLNS_RPID_PERSON = "urn:ietf:params:xml:ns:pidf:rpid:rpid-person";
  50. pj_xml_node *person = ast_sip_presence_xml_create_node(pool, node, "pp:person");
  51. pj_xml_node *status = ast_sip_presence_xml_create_node(pool, person, "status");
  52. if (pidfstate[0] != '-') {
  53. pj_xml_node *activities = ast_sip_presence_xml_create_node(pool, status, "ep:activities");
  54. size_t str_size = sizeof("ep:") + strlen(pidfstate);
  55. activities->content.ptr = pj_pool_alloc(pool, str_size);
  56. activities->content.slen = pj_ansi_snprintf(activities->content.ptr, str_size,
  57. "ep:%s", pidfstate);
  58. }
  59. ast_sip_presence_xml_create_attr(pool, node, XMLNS_PP, XMLNS_PERSON);
  60. ast_sip_presence_xml_create_attr(pool, node, XMLNS_ES, XMLNS_RPID_STATUS);
  61. ast_sip_presence_xml_create_attr(pool, node, XMLNS_EP, XMLNS_RPID_PERSON);
  62. }
  63. static int pidf_supplement_body(void *body, void *data)
  64. {
  65. pjpidf_pres *pres = body;
  66. struct ast_sip_exten_state_data *state_data = data;
  67. char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
  68. enum ast_sip_pidf_state local_state;
  69. ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,
  70. &pidfstate, &pidfnote, &local_state);
  71. add_eyebeam(state_data->pool, pres, pidfstate);
  72. return 0;
  73. }
  74. static struct ast_sip_pubsub_body_supplement pidf_supplement = {
  75. .type = "application",
  76. .subtype = "pidf+xml",
  77. .supplement_body = pidf_supplement_body,
  78. };
  79. static int load_module(void)
  80. {
  81. CHECK_PJSIP_PUBSUB_MODULE_LOADED();
  82. if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) {
  83. return AST_MODULE_LOAD_DECLINE;
  84. }
  85. return AST_MODULE_LOAD_SUCCESS;
  86. }
  87. static int unload_module(void)
  88. {
  89. ast_sip_pubsub_unregister_body_supplement(&pidf_supplement);
  90. return 0;
  91. }
  92. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF Eyebeam supplement",
  93. .support_level = AST_MODULE_SUPPORT_CORE,
  94. .load = load_module,
  95. .unload = unload_module,
  96. .load_pri = AST_MODPRI_CHANNEL_DEPEND,
  97. );