| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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" |
| 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" |
| 38 |
|
| 39 |
static 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 |
|
| 46 |
if (ast_strlen_zero(state_data->user_agent) || |
| 47 |
(!strstr(state_data->user_agent, "digium") && |
| 48 |
!strstr(state_data->user_agent, "sangoma"))) { |
| 49 |
|
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
if (!(node = ast_sip_presence_xml_create_node( |
| 54 |
state_data->pool, body, "tuple"))) { |
| 55 |
ast_log(LOG_WARNING, "Unable to create PIDF tuple\n"); |
| 56 |
return -1; |
| 57 |
} |
| 58 |
|
| 59 |
ast_sip_presence_xml_create_attr( |
| 60 |
state_data->pool, node, "id", "digium-presence"); |
| 61 |
|
| 62 |
if (!(node = ast_sip_presence_xml_create_node( |
| 63 |
state_data->pool, node, "status"))) { |
| 64 |
ast_log(LOG_WARNING, "Unable to create PIDF tuple status\n"); |
| 65 |
return -1; |
| 66 |
} |
| 67 |
|
| 68 |
if (!(node = ast_sip_presence_xml_create_node( |
| 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 |
|
| 79 |
ast_sip_presence_xml_create_attr( |
| 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)); |
| 85 |
ast_sip_presence_xml_create_attr( |
| 86 |
state_data->pool, node, "subtype", sanitized); |
| 87 |
} |
| 88 |
|
| 89 |
return 0; |
| 90 |
} |
| 91 |
|
| 92 |
static struct ast_sip_pubsub_body_supplement pidf_supplement = { |
| 93 |
.type = "application", |
| 94 |
.subtype = "pidf+xml", |
| 95 |
.supplement_body = pidf_supplement_body, |
| 96 |
}; |
| 97 |
|
| 98 |
static int load_module(void) |
| 99 |
{ |
| 100 |
if (ast_sip_pubsub_register_body_supplement(&pidf_supplement)) { |
| 101 |
return AST_MODULE_LOAD_DECLINE; |
| 102 |
} |
| 103 |
return AST_MODULE_LOAD_SUCCESS; |
| 104 |
} |
| 105 |
|
| 106 |
static int unload_module(void) |
| 107 |
{ |
| 108 |
ast_sip_pubsub_unregister_body_supplement(&pidf_supplement); |
| 109 |
return 0; |
| 110 |
} |
| 111 |
|
| 112 |
AST_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", |
| 118 |
); |