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 *pidf_allocate_body(
void *data)
50 static int pidf_generate_body_content(
void *body,
void *data)
53 pj_str_t note, id, contact, priority;
54 char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
55 enum ast_sip_pidf_state local_state;
56 char sanitized[PJSIP_MAX_URL_SIZE];
57 pjpidf_pres *pres = body;
60 ast_sip_presence_exten_state_to_str(state_data->
exten_state, &statestring,
61 &pidfstate, &pidfnote, &local_state, 0);
63 if (!pjpidf_pres_add_note(state_data->
pool, pres, pj_cstr(¬e, pidfnote))) {
64 ast_log(LOG_WARNING,
"Unable to add note to PIDF presence\n");
68 if (!(tuple = pjpidf_pres_add_tuple(state_data->
pool, pres,
69 pj_cstr(&
id, state_data->
exten)))) {
70 ast_log(LOG_WARNING,
"Unable to create PIDF tuple\n");
74 ast_sip_sanitize_xml(state_data->
remote, sanitized,
sizeof(sanitized));
75 pjpidf_tuple_set_contact(state_data->
pool, tuple, pj_cstr(&contact, sanitized));
76 pjpidf_tuple_set_contact_prio(state_data->
pool, tuple, pj_cstr(&priority,
"1"));
77 pjpidf_status_set_basic_open(pjpidf_tuple_get_status(tuple),
78 local_state == NOTIFY_OPEN || local_state == NOTIFY_INUSE);
83 #define MAX_STRING_GROWTHS 5
85 static void pidf_to_string(
void *body,
struct ast_str **str)
87 pjpidf_pres *pres = body;
93 if (size <= AST_PJSIP_XML_PROLOG_LEN) {
97 }
while (size <= AST_PJSIP_XML_PROLOG_LEN && growths < MAX_STRING_GROWTHS);
98 if (size <= AST_PJSIP_XML_PROLOG_LEN) {
99 ast_log(LOG_WARNING,
"PIDF body text too large\n");
108 .
type =
"application",
109 .subtype =
"pidf+xml",
110 .body_type = AST_SIP_EXTEN_STATE_DATA,
111 .allocate_body = pidf_allocate_body,
112 .generate_body_content = pidf_generate_body_content,
113 .to_string = pidf_to_string,
117 static int load_module(
void)
119 if (ast_sip_pubsub_register_body_generator(&pidf_body_generator)) {
125 static int unload_module(
void)
127 ast_sip_pubsub_unregister_body_generator(&pidf_body_generator);
131 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
"PJSIP Extension State PIDF Provider",
132 .support_level = AST_MODULE_SUPPORT_CORE,
134 .unload = unload_module,
136 .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.
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.