Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
res_pjsip_xpidf_body_generator.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_simple.h>
#include <pjlib.h>
#include "asterisk/module.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_xpidf_body_generator.c:

Go to the source code of this file.

Macros

#define MAX_STRING_GROWTHS   5
 

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 unload_module (void)
 
static void unregister_all (void)
 
static void * xpidf_allocate_body (void *data)
 
static int xpidf_generate_body_content (void *body, void *data)
 
static void xpidf_to_string (void *body, struct ast_str **str)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Extension State PIDF Provider" , .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_generator cpim_pidf_body_generator
 
static struct ast_sip_pubsub_body_generator xpidf_body_generator
 

Macro Definition Documentation

◆ MAX_STRING_GROWTHS

#define MAX_STRING_GROWTHS   5

Definition at line 99 of file res_pjsip_xpidf_body_generator.c.

Referenced by xpidf_to_string().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 178 of file res_pjsip_xpidf_body_generator.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 178 of file res_pjsip_xpidf_body_generator.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 178 of file res_pjsip_xpidf_body_generator.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 149 of file res_pjsip_xpidf_body_generator.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_sip_pubsub_register_body_generator(), and unregister_all().

Referenced by unload_module().

150 {
152  goto fail;
153  }
154 
156  goto fail;
157  }
158 
160 
161 fail:
162  unregister_all();
164 }
static struct ast_sip_pubsub_body_generator xpidf_body_generator
int ast_sip_pubsub_register_body_generator(struct ast_sip_pubsub_body_generator *generator)
Register a body generator with the pubsub core.
static void unregister_all(void)
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_sip_pubsub_body_generator cpim_pidf_body_generator

◆ unload_module()

static int unload_module ( void  )
static

◆ unregister_all()

static void unregister_all ( void  )
static

Definition at line 143 of file res_pjsip_xpidf_body_generator.c.

References ast_sip_pubsub_unregister_body_generator().

Referenced by load_module(), and unload_module().

144 {
147 }
static struct ast_sip_pubsub_body_generator xpidf_body_generator
static struct ast_sip_pubsub_body_generator cpim_pidf_body_generator
void ast_sip_pubsub_unregister_body_generator(struct ast_sip_pubsub_body_generator *generator)
Unregister a body generator with the pubsub core.

◆ xpidf_allocate_body()

static void* xpidf_allocate_body ( void *  data)
static

Definition at line 38 of file res_pjsip_xpidf_body_generator.c.

References ast_strdupa, ast_strip_quoted(), ast_sip_exten_state_data::local, name, and ast_sip_exten_state_data::pool.

39 {
40  struct ast_sip_exten_state_data *state_data = data;
41  char *local = ast_strdupa(state_data->local);
42  pjxpidf_pres *pres;
43  pj_str_t name;
44 
45  pres = pjxpidf_create(state_data->pool, pj_cstr(&name, ast_strip_quoted(local, "<", ">")));
46  return pres;
47 }
char * ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
Strip leading/trailing whitespace and quotes from a string.
Definition: main/utils.c:1639
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static const char name[]
Definition: cdr_mysql.c:74
structure used for presence XML bodies

◆ xpidf_generate_body_content()

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

Definition at line 49 of file res_pjsip_xpidf_body_generator.c.

References ast_sip_presence_exten_state_to_str(), ast_sip_presence_xml_create_attr(), ast_sip_presence_xml_find_node_attr(), ast_sip_sanitize_xml(), ast_sip_exten_state_data::exten, ast_sip_exten_state_data::exten_state, NOTIFY_INUSE, NOTIFY_OPEN, NULL, ast_sip_exten_state_data::pool, ast_sip_exten_state_data::remote, and status.

50 {
51  pjxpidf_pres *pres = body;
52  struct ast_sip_exten_state_data *state_data = data;
53  static pj_str_t STR_ADDR_PARAM = { ";user=ip", 8 };
54  char *statestring = NULL, *pidfstate = NULL, *pidfnote = NULL;
55  pj_xml_attr *attr;
56  enum ast_sip_pidf_state local_state;
57  pj_str_t uri;
58  char sanitized[PJSIP_MAX_URL_SIZE];
59  pj_xml_node *atom;
60  pj_xml_node *address;
61  pj_xml_node *status;
62  pj_xml_node *msnsubstatus;
63 
64  ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,
65  &pidfstate, &pidfnote, &local_state, 0);
66 
67  ast_sip_presence_xml_find_node_attr(state_data->pool, pres, "atom", "id",
68  &atom, &attr);
69  pj_strdup2(state_data->pool, &attr->value, state_data->exten);
70 
71  ast_sip_presence_xml_find_node_attr(state_data->pool, atom, "address",
72  "uri", &address, &attr);
73 
74  ast_sip_sanitize_xml(state_data->remote, sanitized, sizeof(sanitized));
75 
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);
81 
82  ast_sip_presence_xml_create_attr(state_data->pool, address, "priority", "0.80000");
83 
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");
89 
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");
95 
96  return 0;
97 }
char * address
Definition: f2c.h:59
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
enum ast_extension_states exten_state
#define NULL
Definition: resample.c:96
void ast_sip_presence_exten_state_to_str(int state, char **statestring, char **pidfstate, char **pidfnote, enum ast_sip_pidf_state *local_state, unsigned int notify_early_inuse_ringing)
Convert extension state to relevant PIDF strings.
Definition: presence_xml.c:84
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
structure used for presence XML bodies
ast_sip_pidf_state
void ast_sip_presence_xml_find_node_attr(pj_pool_t *pool, pj_xml_node *parent, const char *node_name, const char *attr_name, pj_xml_node **node, pj_xml_attr **attr)
Find an attribute within a given node.
Definition: presence_xml.c:172
jack_status_t status
Definition: app_jack.c:146

◆ xpidf_to_string()

static void xpidf_to_string ( void *  body,
struct ast_str **  str 
)
static

Definition at line 101 of file res_pjsip_xpidf_body_generator.c.

References ast_log, AST_PJSIP_XML_PROLOG_LEN, ast_str_buffer(), ast_str_make_space, ast_str_size(), ast_str_update(), LOG_WARNING, and MAX_STRING_GROWTHS.

102 {
103  pjxpidf_pres *pres = body;
104  int growths = 0;
105  int size;
106 
107  do {
108  size = pjxpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str) - 1);
109  if (size <= AST_PJSIP_XML_PROLOG_LEN) {
110  ast_str_make_space(str, ast_str_size(*str) * 2);
111  ++growths;
112  }
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");
116  return;
117  }
118 
119  *(ast_str_buffer(*str) + size) = '\0';
120  ast_str_update(*str);
121 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:699
#define LOG_WARNING
Definition: logger.h:274
#define ast_str_make_space(buf, new_len)
Definition: strings.h:780
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_log
Definition: astobj2.c:42
#define AST_PJSIP_XML_PROLOG_LEN
Length of the XML prolog when printing presence or other XML in PJSIP.
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition: strings.h:663
#define MAX_STRING_GROWTHS

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "PJSIP Extension State PIDF Provider" , .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 178 of file res_pjsip_xpidf_body_generator.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 178 of file res_pjsip_xpidf_body_generator.c.

◆ cpim_pidf_body_generator

struct ast_sip_pubsub_body_generator cpim_pidf_body_generator
static

Definition at line 133 of file res_pjsip_xpidf_body_generator.c.

◆ xpidf_body_generator

struct ast_sip_pubsub_body_generator xpidf_body_generator
static

Definition at line 123 of file res_pjsip_xpidf_body_generator.c.