Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
res_pjsip_pidf_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_pidf_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 void * pidf_allocate_body (void *data)
 
static int pidf_generate_body_content (void *body, void *data)
 
static void pidf_to_string (void *body, struct ast_str **str)
 
static int unload_module (void)
 

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 pidf_body_generator
 

Macro Definition Documentation

◆ MAX_STRING_GROWTHS

#define MAX_STRING_GROWTHS   5

Definition at line 83 of file res_pjsip_pidf_body_generator.c.

Referenced by pidf_to_string().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 137 of file res_pjsip_pidf_body_generator.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 137 of file res_pjsip_pidf_body_generator.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 137 of file res_pjsip_pidf_body_generator.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 117 of file res_pjsip_pidf_body_generator.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and ast_sip_pubsub_register_body_generator().

Referenced by unload_module().

118 {
121  }
123 }
int ast_sip_pubsub_register_body_generator(struct ast_sip_pubsub_body_generator *generator)
Register a body generator with the pubsub core.
static struct ast_sip_pubsub_body_generator pidf_body_generator
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78

◆ pidf_allocate_body()

static void* pidf_allocate_body ( void *  data)
static

Definition at line 38 of file res_pjsip_pidf_body_generator.c.

References ast_strdupa, ast_strip_quoted(), entity, ast_sip_exten_state_data::local, 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  pjpidf_pres *pres;
43  pj_str_t entity;
44 
45  pres = pjpidf_create(state_data->pool, pj_cstr(&entity, ast_strip_quoted(local, "<", ">")));
46 
47  return pres;
48 }
static int entity
Definition: isdn_lib.c:259
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
structure used for presence XML bodies

◆ pidf_generate_body_content()

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

Definition at line 50 of file res_pjsip_pidf_body_generator.c.

References ast_log, ast_sip_presence_exten_state_to_str(), ast_sip_sanitize_xml(), ast_sip_exten_state_data::exten, ast_sip_exten_state_data::exten_state, id, LOG_WARNING, NOTIFY_INUSE, NOTIFY_OPEN, NULL, ast_sip_exten_state_data::pool, priority, and ast_sip_exten_state_data::remote.

51 {
52  pjpidf_tuple *tuple;
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;
58  struct ast_sip_exten_state_data *state_data = data;
59 
60  ast_sip_presence_exten_state_to_str(state_data->exten_state, &statestring,
61  &pidfstate, &pidfnote, &local_state, 0);
62 
63  if (!pjpidf_pres_add_note(state_data->pool, pres, pj_cstr(&note, pidfnote))) {
64  ast_log(LOG_WARNING, "Unable to add note to PIDF presence\n");
65  return -1;
66  }
67 
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");
71  return -1;
72  }
73 
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);
79 
80  return 0;
81 }
#define LOG_WARNING
Definition: logger.h:274
enum ast_extension_states exten_state
#define NULL
Definition: resample.c:96
static int priority
#define ast_log
Definition: astobj2.c:42
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
enum queue_result id
Definition: app_queue.c:1507
ast_sip_pidf_state

◆ pidf_to_string()

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

Definition at line 85 of file res_pjsip_pidf_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.

86 {
87  pjpidf_pres *pres = body;
88  int growths = 0;
89  int size;
90 
91  do {
92  size = pjpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str) - 1);
93  if (size <= AST_PJSIP_XML_PROLOG_LEN) {
94  ast_str_make_space(str, ast_str_size(*str) * 2);
95  ++growths;
96  }
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");
100  return;
101  }
102 
103  *(ast_str_buffer(*str) + size) = '\0';
104  ast_str_update(*str);
105 }
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 MAX_STRING_GROWTHS
#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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 125 of file res_pjsip_pidf_body_generator.c.

References AST_MODFLAG_LOAD_ORDER, AST_MODPRI_CHANNEL_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ast_sip_pubsub_unregister_body_generator(), ASTERISK_GPL_KEY, and load_module().

126 {
128  return 0;
129 }
static struct ast_sip_pubsub_body_generator 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.

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 137 of file res_pjsip_pidf_body_generator.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 137 of file res_pjsip_pidf_body_generator.c.

◆ pidf_body_generator

struct ast_sip_pubsub_body_generator pidf_body_generator
static

Definition at line 107 of file res_pjsip_pidf_body_generator.c.