2 * asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2014, Digium, Inc.
6 * Mark Michelson <mmichelson@digium.com>
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.
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.
20 <depend>pjproject</depend>
21 <depend>res_pjsip</depend>
22 <depend>res_pjsip_pubsub</depend>
23 <support_level>core</support_level>
29 #include <pjsip_simple.h>
32 #include "asterisk/module.h"
33 #include "asterisk/res_pjsip.h"
34 #include "asterisk/res_pjsip_pubsub.h"
35 #include "asterisk/res_pjsip_presence_xml.h"
36 #include "asterisk/res_pjsip_body_generator_types.h"
40 * \brief Adds non standard elements to the xml body
42 * This is some code that was part of the original chan_sip implementation
43 * that is not part of the RFC 3863 definition, but we are keeping available
44 * for backward compatability. The original comment stated that Eyebeam
45 * supports this format.
47 static void add_eyebeam(pj_pool_t *pool, pj_xml_node *node, const char *pidfstate)
49 static const char *XMLNS_PP = "xmlns:pp";
50 static const char *XMLNS_PERSON = "urn:ietf:params:xml:ns:pidf:person";
52 static const char *XMLNS_ES = "xmlns:es";
53 static const char *XMLNS_RPID_STATUS = "urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status";
55 static const char *XMLNS_EP = "xmlns:ep";
56 static const char *XMLNS_RPID_PERSON = "urn:ietf:params:xml:ns:pidf:rpid:rpid-person";
58 pj_xml_node *person = ast_sip_presence_xml_create_node(pool, node, "pp:person");
59 pj_xml_node *status = ast_sip_presence_xml_create_node(pool, person, "status");
61 if (pidfstate[0] != '-') {
62 pj_xml_node *activities = ast_sip_presence_xml_create_node(pool, status, "ep:activities");
63 size_t str_size = sizeof("ep:") + strlen(pidfstate);
65 activities->content.ptr = pj_pool_alloc(pool, str_size);
66 activities->content.slen = pj_ansi_snprintf(activities->content.ptr, str_size,
70 ast_sip_presence_xml_create_attr(pool, node, XMLNS_PP, XMLNS_PERSON);
71 ast_sip_presence_xml_create_attr(pool, node, XMLNS_ES, XMLNS_RPID_STATUS);
72 ast_sip_presence_xml_create_attr(pool, node, XMLNS_EP, XMLNS_RPID_PERSON);
75 static int pidf_supplement_body(void *body, void *data)
77 pjpidf_pres *pres = body;
78 struct ast_sip_exten_state_data *state_data = data;
79 char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
80 enum ast_sip_pidf_state local_state;
82 ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,
83 &pidfstate, &pidfnote, &local_state);
85 add_eyebeam(state_data->pool, pres, pidfstate);
89 static struct ast_sip_pubsub_body_supplement pidf_supplement = {
90 .type = "application",
91 .subtype = "pidf+xml",
92 .supplement_body = pidf_supplement_body,
95 static int load_module(void)
97 CHECK_PJSIP_PUBSUB_MODULE_LOADED();
99 if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) {
100 return AST_MODULE_LOAD_DECLINE;
102 return AST_MODULE_LOAD_SUCCESS;
105 static int unload_module(void)
107 ast_sip_pubsub_unregister_body_supplement(&pidf_supplement);
111 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF Eyebeam supplement",
112 .support_level = AST_MODULE_SUPPORT_CORE,
114 .unload = unload_module,
115 .load_pri = AST_MODPRI_CHANNEL_DEPEND,