Asterisk - The Open Source Telephony Project GIT-master-f36a736
Functions | Variables
res_pjsip_pidf_digium_body_supplement.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_simple.h>
#include <pjlib.h>
#include "asterisk/module.h"
#include "asterisk/presencestate.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_pubsub.h"
#include "asterisk/res_pjsip_presence_xml.h"
#include "asterisk/res_pjsip_body_generator_types.h"
Include dependency graph for res_pjsip_pidf_digium_body_supplement.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int pidf_supplement_body (void *body, void *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP PIDF Sangoma presence supplement" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, .requires = "res_pjsip,res_pjsip_pubsub", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_sip_pubsub_body_supplement pidf_supplement
 

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 118 of file res_pjsip_pidf_digium_body_supplement.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 118 of file res_pjsip_pidf_digium_body_supplement.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 118 of file res_pjsip_pidf_digium_body_supplement.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 98 of file res_pjsip_pidf_digium_body_supplement.c.

99{
102 }
104}
@ 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
static struct ast_sip_pubsub_body_supplement pidf_supplement
int ast_sip_pubsub_register_body_supplement(struct ast_sip_pubsub_body_supplement *supplement)
Register a body generator with the pubsub core.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_sip_pubsub_register_body_supplement(), and pidf_supplement.

◆ pidf_supplement_body()

static int pidf_supplement_body ( void *  body,
void *  data 
)
static

Definition at line 39 of file res_pjsip_pidf_digium_body_supplement.c.

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}
#define ast_log
Definition: astobj2.c:42
#define LOG_WARNING
const char * ast_presence_state2str(enum ast_presence_state state)
Convert presence state to text string for output.
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
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
Definition: test_heap.c:38

References ast_log, ast_presence_state2str(), ast_sip_presence_xml_create_attr(), ast_sip_presence_xml_create_node(), ast_sip_sanitize_xml(), ast_strlen_zero(), LOG_WARNING, ast_sip_exten_state_data::pool, ast_sip_exten_state_data::presence_message, ast_sip_exten_state_data::presence_state, ast_sip_exten_state_data::presence_subtype, and ast_sip_exten_state_data::user_agent.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 106 of file res_pjsip_pidf_digium_body_supplement.c.

107{
109 return 0;
110}
void ast_sip_pubsub_unregister_body_supplement(struct ast_sip_pubsub_body_supplement *supplement)
Unregister a body generator with the pubsub core.

References ast_sip_pubsub_unregister_body_supplement(), and pidf_supplement.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP PIDF Sangoma presence supplement" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, .requires = "res_pjsip,res_pjsip_pubsub", }
static

Definition at line 118 of file res_pjsip_pidf_digium_body_supplement.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 118 of file res_pjsip_pidf_digium_body_supplement.c.

◆ pidf_supplement

struct ast_sip_pubsub_body_supplement pidf_supplement
static
Initial value:
= {
.type = "application",
.subtype = "pidf+xml",
.supplement_body = pidf_supplement_body,
}
static int pidf_supplement_body(void *body, void *data)

Definition at line 92 of file res_pjsip_pidf_digium_body_supplement.c.

Referenced by load_module(), and unload_module().