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;
44 if (ast_strlen_zero(state_data->user_agent) ||
45 !strstr(state_data->user_agent, "digium")) {
46 /* not a digium phone */
50 if (!(node = ast_sip_presence_xml_create_node(
51 state_data->pool, body, "tuple"))) {
52 ast_log(LOG_WARNING, "Unable to create PIDF tuple\n");
56 ast_sip_presence_xml_create_attr(
57 state_data->pool, node, "id", "digium-presence");
59 if (!(node = ast_sip_presence_xml_create_node(
60 state_data->pool, node, "status"))) {
61 ast_log(LOG_WARNING, "Unable to create PIDF tuple status\n");
65 if (!(node = ast_sip_presence_xml_create_node(
66 state_data->pool, node, "digium_presence"))) {
67 ast_log(LOG_WARNING, "Unable to create digium presence\n");
71 if (!ast_strlen_zero(state_data->presence_message)) {
72 pj_strdup2(state_data->pool, &node->content,
73 state_data->presence_message);
76 ast_sip_presence_xml_create_attr(
77 state_data->pool, node, "type", ast_presence_state2str(
78 state_data->presence_state));
80 if (!ast_strlen_zero(state_data->presence_subtype)) {
81 ast_sip_presence_xml_create_attr(
82 state_data->pool, node, "subtype",
83 state_data->presence_subtype);
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 if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) {
98 return AST_MODULE_LOAD_DECLINE;
100 return AST_MODULE_LOAD_SUCCESS;
103 static int unload_module(void)
105 ast_sip_pubsub_unregister_body_supplement(&pidf_supplement);
109 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF Digium presence supplement",
111 .unload = unload_module,
112 .load_pri = AST_MODPRI_CHANNEL_DEPEND,