29 #include <pjsip_simple.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"
38 static void *xpidf_allocate_body(
void *data)
49 static int xpidf_generate_body_content(
void *body,
void *data)
51 pjxpidf_pres *pres = body;
53 static pj_str_t STR_ADDR_PARAM = {
";user=ip", 8 };
54 char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
56 enum ast_sip_pidf_state local_state;
58 char sanitized[PJSIP_MAX_URL_SIZE];
62 pj_xml_node *msnsubstatus;
64 ast_sip_presence_exten_state_to_str(state_data->
exten_state, &statestring,
65 &pidfstate, &pidfnote, &local_state, 0);
67 ast_sip_presence_xml_find_node_attr(state_data->
pool, pres,
"atom",
"id",
69 pj_strdup2(state_data->
pool, &attr->value, state_data->
exten);
71 ast_sip_presence_xml_find_node_attr(state_data->
pool, atom,
"address",
72 "uri", &address, &attr);
74 ast_sip_sanitize_xml(state_data->
remote, sanitized,
sizeof(sanitized));
76 uri.ptr = (
char*) pj_pool_alloc(state_data->
pool,
77 strlen(sanitized) + STR_ADDR_PARAM.slen);
78 pj_strcpy2( &uri, sanitized);
79 pj_strcat( &uri, &STR_ADDR_PARAM);
80 pj_strdup(state_data->
pool, &attr->value, &uri);
82 ast_sip_presence_xml_create_attr(state_data->
pool, address,
"priority",
"0.80000");
84 ast_sip_presence_xml_find_node_attr(state_data->
pool, address,
85 "status",
"status", &status, &attr);
86 pj_strdup2(state_data->
pool, &attr->value,
87 (local_state == NOTIFY_OPEN) ?
"open" :
88 (local_state == NOTIFY_INUSE) ?
"inuse" :
"closed");
90 ast_sip_presence_xml_find_node_attr(state_data->
pool, address,
91 "msnsubstatus",
"substatus", &msnsubstatus, &attr);
92 pj_strdup2(state_data->
pool, &attr->value,
93 (local_state == NOTIFY_OPEN) ?
"online" :
94 (local_state == NOTIFY_INUSE) ?
"onthephone" :
"offline");
99 #define MAX_STRING_GROWTHS 5
101 static void xpidf_to_string(
void *body,
struct ast_str **str)
103 pjxpidf_pres *pres = body;
109 if (size <= AST_PJSIP_XML_PROLOG_LEN) {
113 }
while (size <= AST_PJSIP_XML_PROLOG_LEN && growths < MAX_STRING_GROWTHS);
114 if (size <= AST_PJSIP_XML_PROLOG_LEN) {
115 ast_log(LOG_WARNING,
"XPIDF body text too large\n");
124 .
type =
"application",
125 .subtype =
"xpidf+xml",
126 .body_type = AST_SIP_EXTEN_STATE_DATA,
127 .allocate_body = xpidf_allocate_body,
128 .generate_body_content = xpidf_generate_body_content,
129 .to_string = xpidf_to_string,
134 .
type =
"application",
135 .subtype =
"cpim-pidf+xml",
136 .body_type = AST_SIP_EXTEN_STATE_DATA,
137 .allocate_body = xpidf_allocate_body,
138 .generate_body_content = xpidf_generate_body_content,
139 .to_string = xpidf_to_string,
143 static void unregister_all(
void)
145 ast_sip_pubsub_unregister_body_generator(&cpim_pidf_body_generator);
146 ast_sip_pubsub_unregister_body_generator(&xpidf_body_generator);
149 static int load_module(
void)
151 if (ast_sip_pubsub_register_body_generator(&xpidf_body_generator)) {
155 if (ast_sip_pubsub_register_body_generator(&cpim_pidf_body_generator)) {
166 static int unload_module(
void)
172 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
"PJSIP Extension State PIDF Provider",
173 .support_level = AST_MODULE_SUPPORT_CORE,
175 .unload = unload_module,
177 .requires =
"res_pjsip,res_pjsip_pubsub",
Asterisk main include file. File version handling, generic pbx functions.
const char * type
Content type In "plain/text", "plain" is the type.
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static struct ast_sockaddr address
Address for UDPTL.
char remote[PJSIP_MAX_URL_SIZE]
enum ast_extension_states exten_state
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
#define ast_strdupa(s)
duplicate a string in memory from the stack
char local[PJSIP_MAX_URL_SIZE]
Support for dynamic strings.
Module has failed to load, may be in an inconsistent state.
structure used for presence XML bodies
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.