Asterisk - The Open Source Telephony Project GIT-master-7e7a603
res_pjsip_pidf_digium_body_supplement.c
Go to the documentation of this file.
1/*
2 * asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2014, Digium, Inc.
5 *
6 * Kevin Harwell <kharwell@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
19/*** MODULEINFO
20 <depend>pjproject</depend>
21 <depend>res_pjsip</depend>
22 <depend>res_pjsip_pubsub</depend>
23 <support_level>core</support_level>
24 ***/
25
26#include "asterisk.h"
27
28#include <pjsip.h>
29#include <pjsip_simple.h>
30#include <pjlib.h>
31
32#include "asterisk/module.h"
34#include "asterisk/res_pjsip.h"
38
39static int pidf_supplement_body(void *body, void *data)
40{
41 struct ast_sip_exten_state_data *state_data = data;
42 pj_xml_node *node;
43 char sanitized[1024];
44
45 /* The res_pjsip_exten_state module converts the user agent to lower case */
46 if (ast_strlen_zero(state_data->user_agent) ||
47 (!strstr(state_data->user_agent, "digium") &&
48 !strstr(state_data->user_agent, "sangoma"))) {
49 /* not a Sangoma phone */
50 return 0;
51 }
52
54 state_data->pool, body, "tuple"))) {
55 ast_log(LOG_WARNING, "Unable to create PIDF tuple\n");
56 return -1;
57 }
58
60 state_data->pool, node, "id", "digium-presence");
61
63 state_data->pool, node, "status"))) {
64 ast_log(LOG_WARNING, "Unable to create PIDF tuple status\n");
65 return -1;
66 }
67
69 state_data->pool, node, "digium_presence"))) {
70 ast_log(LOG_WARNING, "Unable to create digium presence\n");
71 return -1;
72 }
73
74 if (!ast_strlen_zero(state_data->presence_message)) {
75 ast_sip_sanitize_xml(state_data->presence_message, sanitized, sizeof(sanitized));
76 pj_strdup2(state_data->pool, &node->content, sanitized);
77 }
78
80 state_data->pool, node, "type", ast_presence_state2str(
81 state_data->presence_state));
82
83 if (!ast_strlen_zero(state_data->presence_subtype)) {
84 ast_sip_sanitize_xml(state_data->presence_subtype, sanitized, sizeof(sanitized));
86 state_data->pool, node, "subtype", sanitized);
87 }
88
89 return 0;
90}
91
93 .type = "application",
94 .subtype = "pidf+xml",
95 .supplement_body = pidf_supplement_body,
96};
97
98static int load_module(void)
99{
102 }
104}
105
106static int unload_module(void)
107{
109 return 0;
110}
111
112AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP PIDF Sangoma presence supplement",
113 .support_level = AST_MODULE_SUPPORT_CORE,
114 .load = load_module,
115 .unload = unload_module,
116 .load_pri = AST_MODPRI_CHANNEL_DEPEND,
117 .requires = "res_pjsip,res_pjsip_pubsub",
Asterisk main include file. File version handling, generic pbx functions.
#define ast_log
Definition: astobj2.c:42
#define LOG_WARNING
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition: module.h:317
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:543
@ AST_MODPRI_CHANNEL_DEPEND
Definition: module.h:326
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
Presence state management.
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.
static int load_module(void)
static struct ast_sip_pubsub_body_supplement pidf_supplement
static int unload_module(void)
static int pidf_supplement_body(void *body, void *data)
void ast_sip_sanitize_xml(const char *input, char *output, size_t len)
Replace offensive XML characters with XML entities.
Definition: presence_xml.c:29
pj_xml_node * ast_sip_presence_xml_create_node(pj_pool_t *pool, pj_xml_node *parent, const char *name)
Create XML node.
Definition: presence_xml.c:152
pj_xml_attr * ast_sip_presence_xml_create_attr(pj_pool_t *pool, pj_xml_node *node, const char *name, const char *value)
Create XML attribute.
Definition: presence_xml.c:140
void ast_sip_pubsub_unregister_body_supplement(struct ast_sip_pubsub_body_supplement *supplement)
Unregister a body generator with the pubsub core.
int ast_sip_pubsub_register_body_supplement(struct ast_sip_pubsub_body_supplement *supplement)
Register a body generator with the pubsub core.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
structure used for presence XML bodies
enum ast_presence_state presence_state
const char * type
Content type In "plain/text", "plain" is the type.
Definition: test_heap.c:38