2 * asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, 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 <depend>res_pjsip_exten_state</depend>
24 <support_level>core</support_level>
30 #include <pjsip_simple.h>
33 #include "asterisk/module.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 void ast_sip_sanitize_xml(const char *input, char *output, size_t len)
41 char *copy = ast_strdupa(input);
46 while ((break_point = strpbrk(copy, "<>\"&'\n\r"))) {
47 char to_escape = *break_point;
50 strncat(output, copy, len);
54 strncat(output, "<", len);
57 strncat(output, ">", len);
60 strncat(output, """, len);
63 strncat(output, "&", len);
66 strncat(output, "'", len);
69 strncat(output, " ", len);
72 strncat(output, " ", len);
76 copy = break_point + 1;
79 /* Be sure to copy everything after the final bracket */
81 strncat(output, copy, len);
85 void ast_sip_presence_exten_state_to_str(int state, char **statestring, char **pidfstate,
86 char **pidfnote, enum ast_sip_pidf_state *local_state)
89 case AST_EXTENSION_RINGING:
90 *statestring = "early";
91 *local_state = NOTIFY_INUSE;
93 *pidfnote = "Ringing";
95 case AST_EXTENSION_INUSE:
96 *statestring = "confirmed";
97 *local_state = NOTIFY_INUSE;
99 *pidfnote = "On the phone";
101 case AST_EXTENSION_BUSY:
102 *statestring = "confirmed";
103 *local_state = NOTIFY_CLOSED;
105 *pidfnote = "On the phone";
107 case AST_EXTENSION_UNAVAILABLE:
108 *statestring = "terminated";
109 *local_state = NOTIFY_CLOSED;
111 *pidfnote = "Unavailable";
113 case AST_EXTENSION_ONHOLD:
114 *statestring = "confirmed";
115 *local_state = NOTIFY_CLOSED;
117 *pidfnote = "On hold";
119 case AST_EXTENSION_NOT_INUSE:
121 /* Default setting */
122 *statestring = "terminated";
123 *local_state = NOTIFY_OPEN;
130 pj_xml_attr *ast_sip_presence_xml_create_attr(pj_pool_t *pool,
131 pj_xml_node *node, const char *name, const char *value)
133 pj_xml_attr *attr = PJ_POOL_ALLOC_T(pool, pj_xml_attr);
135 pj_strdup2(pool, &attr->name, name);
136 pj_strdup2(pool, &attr->value, value);
138 pj_xml_add_attr(node, attr);
142 pj_xml_node *ast_sip_presence_xml_create_node(pj_pool_t *pool,
143 pj_xml_node *parent, const char* name)
145 pj_xml_node *node = PJ_POOL_ALLOC_T(pool, pj_xml_node);
147 pj_list_init(&node->attr_head);
148 pj_list_init(&node->node_head);
150 pj_strdup2(pool, &node->name, name);
152 node->content.ptr = NULL;
153 node->content.slen = 0;
155 pj_xml_add_node(parent, node);
159 void ast_sip_presence_xml_find_node_attr(pj_pool_t* pool,
160 pj_xml_node *parent, const char *node_name, const char *attr_name,
161 pj_xml_node **node, pj_xml_attr **attr)
165 if (!(*node = pj_xml_find_node(parent, pj_cstr(&name, node_name)))) {
166 *node = ast_sip_presence_xml_create_node(pool, parent, node_name);
169 if (!(*attr = pj_xml_find_attr(*node, pj_cstr(&name, attr_name), NULL))) {
170 *attr = ast_sip_presence_xml_create_attr(pool, *node, attr_name, "");