Asterisk - The Open Source Telephony Project  18.5.0
Macros | Enumerations | Functions
res_pjsip_presence_xml.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define AST_PJSIP_XML_PROLOG_LEN   39
 Length of the XML prolog when printing presence or other XML in PJSIP. More...
 

Enumerations

enum  ast_sip_pidf_state { NOTIFY_OPEN, NOTIFY_INUSE, NOTIFY_CLOSED }
 

Functions

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. More...
 
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. More...
 
pj_xml_node * ast_sip_presence_xml_create_node (pj_pool_t *pool, pj_xml_node *parent, const char *name)
 Create XML node. More...
 
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. More...
 
void ast_sip_sanitize_xml (const char *input, char *output, size_t len)
 Replace offensive XML characters with XML entities. More...
 

Macro Definition Documentation

◆ AST_PJSIP_XML_PROLOG_LEN

#define AST_PJSIP_XML_PROLOG_LEN   39

Length of the XML prolog when printing presence or other XML in PJSIP.

When calling any variant of pj_xml_print(), the documentation claims that it will return -1 if the provided buffer is not large enough. However, if the XML prolog is requested to be printed and the buffer is not large enough, then it will return -1 only if the buffer is not large enough to hold the XML prolog or return the length of the XML prolog on failure instead of -1.

This constant is useful to check against when trying to determine if printing XML succeeded or failed.

Definition at line 36 of file res_pjsip_presence_xml.h.

Referenced by dialog_info_to_string(), pidf_to_string(), rlmi_print_body(), and xpidf_to_string().

Enumeration Type Documentation

◆ ast_sip_pidf_state

PIDF state

Enumerator
NOTIFY_OPEN 

Device is not in use

NOTIFY_INUSE 

Device is in use or ringing

NOTIFY_CLOSED 

Device is unavailable, on hold, or busy

Definition at line 41 of file res_pjsip_presence_xml.h.

41  {
42  /*! Device is not in use */
44  /*! Device is in use or ringing */
46  /*! Device is unavailable, on hold, or busy */
48 };

Function Documentation

◆ ast_sip_presence_exten_state_to_str()

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.

Parameters
stateThe extension state
[out]statestring
[out]pidfstate
[out]pidfnote
[out]local_state

Definition at line 84 of file presence_xml.c.

References AST_EXTENSION_BUSY, AST_EXTENSION_INUSE, AST_EXTENSION_NOT_INUSE, AST_EXTENSION_ONHOLD, AST_EXTENSION_RINGING, AST_EXTENSION_UNAVAILABLE, NOTIFY_CLOSED, NOTIFY_INUSE, and NOTIFY_OPEN.

Referenced by dialog_info_generate_body_content(), pidf_generate_body_content(), pidf_supplement_body(), and xpidf_generate_body_content().

87 {
88  switch (state) {
90  *statestring = "early";
91  *local_state = NOTIFY_INUSE;
92  *pidfstate = "on-the-phone";
93  *pidfnote = "Ringing";
94  break;
96  if (notify_early_inuse_ringing) {
97  *statestring = "early";
98  } else {
99  *statestring = "confirmed";
100  }
101  *local_state = NOTIFY_INUSE;
102  *pidfstate = "on-the-phone";
103  *pidfnote = "Ringing";
104  break;
105  case AST_EXTENSION_INUSE:
106  *statestring = "confirmed";
107  *local_state = NOTIFY_INUSE;
108  *pidfstate = "on-the-phone";
109  *pidfnote = "On the phone";
110  break;
111  case AST_EXTENSION_BUSY:
112  *statestring = "confirmed";
113  *local_state = NOTIFY_INUSE;
114  *pidfstate = "on-the-phone";
115  *pidfnote = "On the phone";
116  break;
118  *statestring = "terminated";
119  *local_state = NOTIFY_CLOSED;
120  *pidfstate = "--";
121  *pidfnote = "Unavailable";
122  break;
124  *statestring = "confirmed";
125  *local_state = NOTIFY_INUSE;
126  *pidfstate = "on-the-phone";
127  *pidfnote = "On hold";
128  break;
130  default:
131  /* Default setting */
132  *statestring = "terminated";
133  *local_state = NOTIFY_OPEN;
134  *pidfstate = "--";
135  *pidfnote = "Ready";
136  break;
137  }
138 }

◆ ast_sip_presence_xml_create_attr()

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.

Parameters
poolAllocation pool
nodeNode to add attribute to
nameThe attribute name
valueThe attribute value
Returns
The created attribute

Definition at line 140 of file presence_xml.c.

Referenced by add_eyebeam(), add_rlmi_resource(), ast_sip_presence_xml_find_node_attr(), build_rlmi_body(), dialog_info_generate_body_content(), pidf_supplement_body(), and xpidf_generate_body_content().

142 {
143  pj_xml_attr *attr = PJ_POOL_ALLOC_T(pool, pj_xml_attr);
144 
145  pj_strdup2(pool, &attr->name, name);
146  pj_strdup2(pool, &attr->value, value);
147 
148  pj_xml_add_attr(node, attr);
149  return attr;
150 }
Definition: test_heap.c:38
static pj_pool_t * pool
Global memory pool for configuration and timers.
int value
Definition: syslog.c:37
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_sip_presence_xml_create_node()

pj_xml_node* ast_sip_presence_xml_create_node ( pj_pool_t *  pool,
pj_xml_node *  parent,
const char *  name 
)

Create XML node.

Parameters
poolAllocation pool
parentOptional node that will be parent to the created node
nameThe name for the new node
Returns
The created node

Definition at line 152 of file presence_xml.c.

References NULL.

Referenced by add_eyebeam(), add_rlmi_resource(), ast_sip_presence_xml_find_node_attr(), build_rlmi_body(), dialog_info_allocate_body(), dialog_info_generate_body_content(), and pidf_supplement_body().

154 {
155  pj_xml_node *node = PJ_POOL_ALLOC_T(pool, pj_xml_node);
156 
157  pj_list_init(&node->attr_head);
158  pj_list_init(&node->node_head);
159 
160  pj_strdup2(pool, &node->name, name);
161 
162  node->content.ptr = NULL;
163  node->content.slen = 0;
164 
165  if (parent) {
166  pj_xml_add_node(parent, node);
167  }
168 
169  return node;
170 }
Definition: test_heap.c:38
static pj_pool_t * pool
Global memory pool for configuration and timers.
#define NULL
Definition: resample.c:96
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_sip_presence_xml_find_node_attr()

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.

Given a starting node, this will find an attribute that belongs to a specific node. If the node does not exist, it will be created under the passed-in parent. If the attribute does not exist, then it will be created on the node with an empty string as its value.

Parameters
poolAllocation pool
parentStarting node for search
node_nameName of node where to find attribute
attr_nameName of attribute to find
[out]nodeNode that was found or created
[out]attrAttribute that was found or created
Returns
The found attribute

Definition at line 172 of file presence_xml.c.

References ast_sip_presence_xml_create_attr(), ast_sip_presence_xml_create_node(), name, and NULL.

Referenced by xpidf_generate_body_content().

175 {
176  pj_str_t name;
177 
178  if (!(*node = pj_xml_find_node(parent, pj_cstr(&name, node_name)))) {
179  *node = ast_sip_presence_xml_create_node(pool, parent, node_name);
180  }
181 
182  if (!(*attr = pj_xml_find_attr(*node, pj_cstr(&name, attr_name), NULL))) {
183  *attr = ast_sip_presence_xml_create_attr(pool, *node, attr_name, "");
184  }
185 }
Definition: test_heap.c:38
static pj_pool_t * pool
Global memory pool for configuration and timers.
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
#define NULL
Definition: resample.c:96
static const char name[]
Definition: cdr_mysql.c:74
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

◆ ast_sip_sanitize_xml()

void ast_sip_sanitize_xml ( const char *  input,
char *  output,
size_t  len 
)

Replace offensive XML characters with XML entities.

" = " < = <

= >

' = ' & = &

Parameters
inputString to sanitize
[out]outputSanitized string
lenSize of output buffer

Definition at line 29 of file presence_xml.c.

References ast_strdupa, and copy().

Referenced by AST_TEST_DEFINE(), dialog_info_generate_body_content(), pidf_generate_body_content(), pidf_supplement_body(), and xpidf_generate_body_content().

30 {
31  char *copy = ast_strdupa(input);
32  char *break_point;
33  size_t remaining = len - 1;
34 
35  output[0] = '\0';
36 
37  while ((break_point = strpbrk(copy, "<>\"&'\n\r")) && remaining) {
38  char to_escape = *break_point;
39 
40  *break_point = '\0';
41  strncat(output, copy, remaining);
42 
43  /* The strncat function will write remaining+1 if the string length is
44  * equal to or greater than the size provided to it. We take this into
45  * account by subtracting 1, which ensures that the NULL byte is written
46  * inside of the provided buffer.
47  */
48  remaining = len - strlen(output) - 1;
49 
50  switch (to_escape) {
51  case '<':
52  strncat(output, "&lt;", remaining);
53  break;
54  case '>':
55  strncat(output, "&gt;", remaining);
56  break;
57  case '"':
58  strncat(output, "&quot;", remaining);
59  break;
60  case '&':
61  strncat(output, "&amp;", remaining);
62  break;
63  case '\'':
64  strncat(output, "&apos;", remaining);
65  break;
66  case '\r':
67  strncat(output, "&#13;", remaining);
68  break;
69  case '\n':
70  strncat(output, "&#10;", remaining);
71  break;
72  };
73 
74  copy = break_point + 1;
75  remaining = len - strlen(output) - 1;
76  }
77 
78  /* Be sure to copy everything after the final bracket */
79  if (*copy && remaining) {
80  strncat(output, copy, remaining);
81  }
82 }
static int copy(char *infile, char *outfile)
Utility function to copy a file.
static int input(yyscan_t yyscanner)
Definition: ast_expr2f.c:1584
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)