2 * asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2014, Digium, Inc.
6 * Kevin Harwell <kharwell@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/presencestate.h"
34 #include "asterisk/res_pjsip.h"
35 #include "asterisk/res_pjsip_pubsub.h"
36 #include "asterisk/res_pjsip_presence_xml.h"
37 #include "asterisk/res_pjsip_body_generator_types.h"
39 static int pidf_supplement_body(void *body, void *data)
41 struct ast_sip_exten_state_data *state_data = data;
45 if (ast_strlen_zero(state_data->user_agent) ||
46 !strstr(state_data->user_agent, "digium")) {
47 /* not a digium phone */
51 if (!(node = ast_sip_presence_xml_create_node(
52 state_data->pool, body, "tuple"))) {
53 ast_log(LOG_WARNING, "Unable to create PIDF tuple\n");
57 ast_sip_presence_xml_create_attr(
58 state_data->pool, node, "id", "digium-presence");
60 if (!(node = ast_sip_presence_xml_create_node(
61 state_data->pool, node, "status"))) {
62 ast_log(LOG_WARNING, "Unable to create PIDF tuple status\n");
66 if (!(node = ast_sip_presence_xml_create_node(
67 state_data->pool, node, "digium_presence"))) {
68 ast_log(LOG_WARNING, "Unable to create digium presence\n");
72 if (!ast_strlen_zero(state_data->presence_message)) {
73 ast_sip_sanitize_xml(state_data->presence_message, sanitized, sizeof(sanitized));
74 pj_strdup2(state_data->pool, &node->content, sanitized);
77 ast_sip_presence_xml_create_attr(
78 state_data->pool, node, "type", ast_presence_state2str(
79 state_data->presence_state));
81 if (!ast_strlen_zero(state_data->presence_subtype)) {
82 ast_sip_sanitize_xml(state_data->presence_subtype, sanitized, sizeof(sanitized));
83 ast_sip_presence_xml_create_attr(
84 state_data->pool, node, "subtype", sanitized);
90 static struct ast_sip_pubsub_body_supplement pidf_supplement = {
91 .type = "application",
92 .subtype = "pidf+xml",
93 .supplement_body = pidf_supplement_body,
96 static int load_module(void)
98 if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) {
99 return AST_MODULE_LOAD_DECLINE;
101 return AST_MODULE_LOAD_SUCCESS;
104 static int unload_module(void)
106 ast_sip_pubsub_unregister_body_supplement(&pidf_supplement);
110 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF Digium presence supplement",
112 .unload = unload_module,
113 .load_pri = AST_MODPRI_CHANNEL_DEPEND,