Asterisk - The Open Source Telephony Project  GIT-master-a24979a
Data Structures | Functions
xml.h File Reference

Asterisk XML abstraction layer. More...

#include "asterisk/vector.h"
Include dependency graph for xml.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_xml_namespace_def
 Namespace definition. More...
 
struct  ast_xml_namespace_def_vector
 

Functions

struct ast_xml_node * ast_xml_add_child (struct ast_xml_node *parent, struct ast_xml_node *child)
 Add a child node, to a specified parent node. More...
 
struct ast_xml_node * ast_xml_add_child_list (struct ast_xml_node *parent, struct ast_xml_node *child)
 Add a list of child nodes, to a specified parent node. More...
 
void ast_xml_close (struct ast_xml_doc *doc)
 Close an already open document and free the used structure. More...
 
struct ast_xml_node * ast_xml_copy_node_list (struct ast_xml_node *list)
 Create a copy of a n ode list. More...
 
int ast_xml_doc_dump_file (FILE *output, struct ast_xml_doc *doc)
 Dump the specified document to a file. More...
 
struct ast_xml_node * ast_xml_find_element (struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue)
 Find a node element by name. More...
 
struct ast_xml_ns * ast_xml_find_namespace (struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name)
 
int ast_xml_finish (void)
 Cleanup library allocated global data. More...
 
void ast_xml_free_attr (const char *attribute)
 Free an attribute returned by ast_xml_get_attribute() More...
 
void ast_xml_free_node (struct ast_xml_node *node)
 Free node. More...
 
void ast_xml_free_text (const char *text)
 Free a content element that was returned by ast_xml_get_text() More...
 
const char * ast_xml_get_attribute (struct ast_xml_node *node, const char *attrname)
 Get a node attribute by name. More...
 
struct ast_xml_doc * ast_xml_get_doc (struct ast_xml_node *node)
 Get the document based on a node. More...
 
const char * ast_xml_get_ns_href (struct ast_xml_ns *ns)
 Get the href of a namespace. More...
 
const char * ast_xml_get_ns_prefix (struct ast_xml_ns *ns)
 Get the prefix of a namespace. More...
 
struct ast_xml_node * ast_xml_get_root (struct ast_xml_doc *doc)
 Get the document root node. More...
 
const char * ast_xml_get_text (struct ast_xml_node *node)
 Get an element content string. More...
 
int ast_xml_init (void)
 Initialize the XML library implementation. This function is used to setup everything needed to start working with the xml implementation. More...
 
struct ast_xml_doc * ast_xml_new (void)
 Create a XML document. More...
 
struct ast_xml_node * ast_xml_new_child (struct ast_xml_node *parent, const char *child_name)
 Add a child node inside a passed parent node. More...
 
struct ast_xml_node * ast_xml_new_node (const char *name)
 Create a XML node. More...
 
struct ast_xml_node * ast_xml_node_get_children (struct ast_xml_node *node)
 Get the node's children. More...
 
const char * ast_xml_node_get_name (struct ast_xml_node *node)
 Get the name of a node. More...
 
struct ast_xml_node * ast_xml_node_get_next (struct ast_xml_node *node)
 Get the next node in the same level. More...
 
struct ast_xml_node * ast_xml_node_get_parent (struct ast_xml_node *node)
 Get the parent of a specified node. More...
 
struct ast_xml_node * ast_xml_node_get_prev (struct ast_xml_node *node)
 Get the previous node in the same leve. More...
 
struct ast_xml_doc * ast_xml_open (char *filename)
 Open an XML document. More...
 
struct ast_xml_xpath_results * ast_xml_query (struct ast_xml_doc *doc, const char *xpath_str)
 Execute an XPath query on an XML document. More...
 
struct ast_xml_xpath_results * ast_xml_query_with_namespaces (struct ast_xml_doc *doc, const char *xpath_str, struct ast_xml_namespace_def_vector *namespaces)
 Execute an XPath query on an XML document with namespaces. More...
 
struct ast_xml_doc * ast_xml_read_memory (char *buffer, size_t size)
 Open an XML document that resides in memory. More...
 
int ast_xml_set_attribute (struct ast_xml_node *node, const char *name, const char *value)
 Set an attribute to a node. More...
 
void ast_xml_set_name (struct ast_xml_node *node, const char *name)
 Set or reset an element's name. More...
 
void ast_xml_set_root (struct ast_xml_doc *doc, struct ast_xml_node *node)
 Specify the root node of a XML document. More...
 
void ast_xml_set_text (struct ast_xml_node *node, const char *content)
 Set an element content string. More...
 
struct ast_xml_node * ast_xml_xpath_get_first_result (struct ast_xml_xpath_results *results)
 Return the first result node of an XPath query. More...
 
struct ast_xml_node * ast_xml_xpath_get_result (struct ast_xml_xpath_results *results, int n)
 Return a specific result node of an XPath query. More...
 
int ast_xml_xpath_num_results (struct ast_xml_xpath_results *results)
 Return the number of results from an XPath query. More...
 
void ast_xml_xpath_results_free (struct ast_xml_xpath_results *results)
 Free the XPath results. More...
 

Detailed Description

Asterisk XML abstraction layer.

Definition in file xml.h.

Function Documentation

◆ ast_xml_add_child()

struct ast_xml_node* ast_xml_add_child ( struct ast_xml_node *  parent,
struct ast_xml_node *  child 
)

Add a child node, to a specified parent node.

Parameters
parentWhere to add the child node.
childThe child node to add.
Return values
NULLon error.
non-NULLThe add child node on success.

Definition at line 147 of file xml.c.

148 {
149  if (!parent || !child) {
150  return NULL;
151  }
152  return (struct ast_xml_node *) xmlAddChild((xmlNode *) parent, (xmlNode *) child);
153 }
#define NULL
Definition: resample.c:96

References NULL.

◆ ast_xml_add_child_list()

struct ast_xml_node* ast_xml_add_child_list ( struct ast_xml_node *  parent,
struct ast_xml_node *  child 
)

Add a list of child nodes, to a specified parent node.

Parameters
parentWhere to add the child node.
childThe child list to add.
Return values
NULLon error.
non-NULLThe added child list on success.

Definition at line 155 of file xml.c.

156 {
157  if (!parent || !child) {
158  return NULL;
159  }
160  return (struct ast_xml_node *) xmlAddChildList((xmlNode *) parent, (xmlNode *) child);
161 }

References NULL.

◆ ast_xml_close()

void ast_xml_close ( struct ast_xml_doc *  doc)

Close an already open document and free the used structure.

Parameters
docXML Document to close

Definition at line 190 of file xml.c.

191 {
192  if (!doc) {
193  return;
194  }
195 
196  xmlFreeDoc((xmlDoc *) doc);
197  doc = NULL;
198 }

References NULL.

Referenced by ast_xmldoc_load_documentation(), cc_esc_publish_handler(), sip_pidf_validate(), and xmldoc_unload_documentation().

◆ ast_xml_copy_node_list()

struct ast_xml_node* ast_xml_copy_node_list ( struct ast_xml_node *  list)

Create a copy of a n ode list.

Parameters
listThe list to copy.
Return values
NULLon error.
non-NULLThe copied list.

Definition at line 163 of file xml.c.

164 {
165  if (!list) {
166  return NULL;
167  }
168  return (struct ast_xml_node *) xmlCopyNodeList((xmlNode *) list);
169 }

References NULL.

◆ ast_xml_doc_dump_file()

int ast_xml_doc_dump_file ( FILE *  output,
struct ast_xml_doc *  doc 
)

Dump the specified document to a file.

Definition at line 359 of file xml.c.

360 {
361  return xmlDocDump(output, (xmlDocPtr)doc);
362 }

◆ ast_xml_find_element()

struct ast_xml_node* ast_xml_find_element ( struct ast_xml_node *  root_node,
const char *  name,
const char *  attrname,
const char *  attrvalue 
)

Find a node element by name.

Parameters
root_nodeThis is the node starting point.
nameNode name to find.
attrnameattribute name to match (if NULL it won't be matched).
attrvalueattribute value to match (if NULL it won't be matched).
Return values
NULLif not found.
Returns
The node on success.

Definition at line 276 of file xml.c.

277 {
278  struct ast_xml_node *cur;
279  const char *attr;
280 
281  if (!root_node) {
282  return NULL;
283  }
284 
285  for (cur = root_node; cur; cur = ast_xml_node_get_next(cur)) {
286  /* Check if the name matchs */
287  if (strcmp(ast_xml_node_get_name(cur), name)) {
288  continue;
289  }
290  /* We need to check for a specific attribute name? */
291  if (!attrname || !attrvalue) {
292  return cur;
293  }
294  /* Get the attribute, we need to compare it. */
295  if ((attr = ast_xml_get_attribute(cur, attrname))) {
296  /* does attribute name/value matches? */
297  if (!strcmp(attr, attrvalue)) {
298  ast_xml_free_attr(attr);
299  return cur;
300  }
301  ast_xml_free_attr(attr);
302  }
303  }
304 
305  return NULL;
306 }
static const char name[]
Definition: format_mp3.c:68
const char * ast_xml_node_get_name(struct ast_xml_node *node)
Get the name of a node.
Definition: xml.c:364
void ast_xml_free_attr(const char *attribute)
Free an attribute returned by ast_xml_get_attribute()
Definition: xml.c:232
const char * ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname)
Get a node attribute by name.
Definition: xml.c:246
struct ast_xml_node * ast_xml_node_get_next(struct ast_xml_node *node)
Get the next node in the same level.
Definition: xml.c:374

References ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_name(), ast_xml_node_get_next(), name, and NULL.

Referenced by _xmldoc_build_field(), cc_esc_publish_handler(), load_modules(), xmldoc_build_final_response(), xmldoc_build_list_responses(), xmldoc_get_node(), and xmldoc_get_syntax_config_object().

◆ ast_xml_find_namespace()

struct ast_xml_ns* ast_xml_find_namespace ( struct ast_xml_doc *  doc,
struct ast_xml_node *  node,
const char *  ns_name 
)

Definition at line 317 of file xml.c.

317  {
318  xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name);
319  return (struct ast_xml_ns *) ns;
320 }
Definition: test_heap.c:38

Referenced by pidf_validate_presence().

◆ ast_xml_finish()

int ast_xml_finish ( void  )

Cleanup library allocated global data.

Return values
0On success.
1On error.

Definition at line 57 of file xml.c.

58 {
59  xmlCleanupParser();
60 #ifdef HAVE_LIBXSLT
61 #ifdef HAVE_LIBXSLT_CLEANUP
62  xsltCleanupGlobals();
63 #else
64  xsltUninit();
65 #endif
66 #endif
67 
68  return 0;
69 }

Referenced by xmldoc_unload_documentation().

◆ ast_xml_free_attr()

void ast_xml_free_attr ( const char *  attribute)

◆ ast_xml_free_node()

void ast_xml_free_node ( struct ast_xml_node *  node)

Free node.

Parameters
nodeNode to be released.

Definition at line 222 of file xml.c.

223 {
224  if (!node) {
225  return;
226  }
227 
228  xmlFreeNode((xmlNode *) node);
229  node = NULL;
230 }

References NULL.

◆ ast_xml_free_text()

void ast_xml_free_text ( const char *  text)

Free a content element that was returned by ast_xml_get_text()

Parameters
texttext to be freed.

Definition at line 239 of file xml.c.

240 {
241  if (text) {
242  xmlFree((char *) text);
243  }
244 }
char * text
Definition: app_queue.c:1641

References text.

Referenced by _ast_xmldoc_build_seealso(), cc_esc_publish_handler(), xmldoc_get_formatted(), xmldoc_get_syntax_config_object(), xmldoc_parse_example(), xmldoc_parse_para(), and xmldoc_parse_variable().

◆ ast_xml_get_attribute()

const char* ast_xml_get_attribute ( struct ast_xml_node *  node,
const char *  attrname 
)

Get a node attribute by name.

Parameters
nodeNode where to search the attribute.
attrnameAttribute name.
Return values
NULLon error
Returns
The attribute value on success.

Definition at line 246 of file xml.c.

247 {
248  xmlChar *attrvalue;
249 
250  if (!node) {
251  return NULL;
252  }
253 
254  if (!attrname) {
255  return NULL;
256  }
257 
258  attrvalue = xmlGetProp((xmlNode *) node, (xmlChar *) attrname);
259 
260  return (const char *) attrvalue;
261 }

References NULL.

Referenced by _ast_xmldoc_build_seealso(), ast_xml_find_element(), ast_xmldoc_build_documentation(), ast_xmldoc_regenerate_doc_item(), build_config_docs(), pidf_validate_presence(), pidf_validate_tuple(), xmldoc_attribute_match(), xmldoc_build_final_response(), xmldoc_build_list_responses(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_config_object(), xmldoc_get_syntax_config_option(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), xmldoc_parse_argument(), xmldoc_parse_enumlist(), xmldoc_parse_example(), xmldoc_parse_info(), xmldoc_parse_optionlist(), xmldoc_parse_parameter(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().

◆ ast_xml_get_doc()

struct ast_xml_doc* ast_xml_get_doc ( struct ast_xml_node *  node)

Get the document based on a node.

Parameters
nodeA node that is part of the dom.
Returns
The dom pointer where this node resides.

Definition at line 308 of file xml.c.

309 {
310  if (!node) {
311  return NULL;
312  }
313 
314  return (struct ast_xml_doc *) ((xmlNode *)node)->doc;
315 }

References NULL.

◆ ast_xml_get_ns_href()

const char* ast_xml_get_ns_href ( struct ast_xml_ns *  ns)

Get the href of a namespace.

Parameters
nsThe namespace
Returns
The href of the namespace.

Definition at line 327 of file xml.c.

328 {
329  return (const char *) ((xmlNsPtr) ns)->href;
330 }

Referenced by pidf_validate_presence().

◆ ast_xml_get_ns_prefix()

const char* ast_xml_get_ns_prefix ( struct ast_xml_ns *  ns)

Get the prefix of a namespace.

Parameters
nsThe namespace
Returns
The prefix of the namespace.

Definition at line 322 of file xml.c.

323 {
324  return (const char *) ((xmlNsPtr) ns)->prefix;
325 }

◆ ast_xml_get_root()

struct ast_xml_node* ast_xml_get_root ( struct ast_xml_doc *  doc)

Get the document root node.

Parameters
docXML Document reference
Return values
NULLon error
Returns
The root node on success.

Definition at line 209 of file xml.c.

210 {
211  xmlNode *root_node;
212 
213  if (!doc) {
214  return NULL;
215  }
216 
217  root_node = xmlDocGetRootElement((xmlDoc *) doc);
218 
219  return (struct ast_xml_node *) root_node;
220 }

References NULL.

Referenced by ast_xmldoc_build_documentation(), ast_xmldoc_load_documentation(), cc_esc_publish_handler(), pidf_validate_presence(), and xmldoc_get_node().

◆ ast_xml_get_text()

const char* ast_xml_get_text ( struct ast_xml_node *  node)

Get an element content string.

Parameters
nodeNode from where to get the string.
Return values
NULLon error.
Returns
The text content of node.

Definition at line 332 of file xml.c.

333 {
334  if (!node) {
335  return NULL;
336  }
337 
338  return (const char *) xmlNodeGetContent((xmlNode *) node);
339 }

References NULL.

Referenced by _ast_xmldoc_build_seealso(), cc_esc_publish_handler(), load_modules(), xmldoc_get_formatted(), xmldoc_get_syntax_config_object(), xmldoc_parse_example(), xmldoc_parse_para(), and xmldoc_parse_variable().

◆ ast_xml_init()

int ast_xml_init ( void  )

Initialize the XML library implementation. This function is used to setup everything needed to start working with the xml implementation.

Return values
0On success.
1On error.

Definition at line 48 of file xml.c.

49 {
50  LIBXML_TEST_VERSION
51 #ifdef HAVE_LIBXSLT
52  xsltInit();
53 #endif
54  return 0;
55 }

Referenced by ast_xmldoc_load_documentation().

◆ ast_xml_new()

struct ast_xml_doc* ast_xml_new ( void  )

Create a XML document.

Return values
NULLon error.
non-NULLThe allocated document structure.

Definition at line 115 of file xml.c.

116 {
117  xmlDoc *doc;
118 
119  doc = xmlNewDoc((const xmlChar *) "1.0");
120  return (struct ast_xml_doc *) doc;
121 }

◆ ast_xml_new_child()

struct ast_xml_node* ast_xml_new_child ( struct ast_xml_node *  parent,
const char *  child_name 
)

Add a child node inside a passed parent node.

Parameters
parentThe pointer of the parent node.
child_nameThe name of the child node to add.
Return values
NULLon error.
non-NULLThe created child node pointer.

Definition at line 135 of file xml.c.

136 {
137  xmlNode *child;
138 
139  if (!parent || !child_name) {
140  return NULL;
141  }
142 
143  child = xmlNewChild((xmlNode *) parent, NULL, (const xmlChar *) child_name, NULL);
144  return (struct ast_xml_node *) child;
145 }

References NULL.

Referenced by xmldoc_update_config_type().

◆ ast_xml_new_node()

struct ast_xml_node* ast_xml_new_node ( const char *  name)

Create a XML node.

Parameters
nameThe name of the node to be created.
Return values
NULLon error.
non-NULLThe allocated node structe.

Definition at line 123 of file xml.c.

124 {
125  xmlNode *node;
126  if (!name) {
127  return NULL;
128  }
129 
130  node = xmlNewNode(NULL, (const xmlChar *) name);
131 
132  return (struct ast_xml_node *) node;
133 }

References name, and NULL.

◆ ast_xml_node_get_children()

struct ast_xml_node* ast_xml_node_get_children ( struct ast_xml_node *  node)

◆ ast_xml_node_get_name()

const char* ast_xml_node_get_name ( struct ast_xml_node *  node)

◆ ast_xml_node_get_next()

struct ast_xml_node* ast_xml_node_get_next ( struct ast_xml_node *  node)

◆ ast_xml_node_get_parent()

struct ast_xml_node* ast_xml_node_get_parent ( struct ast_xml_node *  node)

Get the parent of a specified node.

Definition at line 384 of file xml.c.

385 {
386  return (struct ast_xml_node *) ((xmlNode *) node)->parent;
387 }

◆ ast_xml_node_get_prev()

struct ast_xml_node* ast_xml_node_get_prev ( struct ast_xml_node *  node)

Get the previous node in the same leve.

Definition at line 379 of file xml.c.

380 {
381  return (struct ast_xml_node *) ((xmlNode *) node)->prev;
382 }

◆ ast_xml_open()

struct ast_xml_doc* ast_xml_open ( char *  filename)

Open an XML document.

Parameters
filenameDocument path.
Return values
NULLon error.
Returns
The ast_xml_doc reference to the open document.

Definition at line 71 of file xml.c.

72 {
73  xmlDoc *doc;
74 
75  if (!filename) {
76  return NULL;
77  }
78 
79  xmlSubstituteEntitiesDefault(1);
80 
81  doc = xmlReadFile(filename, NULL, XML_PARSE_RECOVER);
82  if (!doc) {
83  return NULL;
84  }
85 
86  /* process xinclude elements. */
87  if (xmlXIncludeProcess(doc) < 0) {
88  xmlFreeDoc(doc);
89  return NULL;
90  }
91 
92 #ifdef HAVE_LIBXSLT
93  {
94  xsltStylesheetPtr xslt = xsltLoadStylesheetPI(doc);
95  if (xslt) {
96  xmlDocPtr tmpdoc = xsltApplyStylesheet(xslt, doc, NULL);
97  xsltFreeStylesheet(xslt);
98  xmlFreeDoc(doc);
99  if (!tmpdoc) {
100  return NULL;
101  }
102  doc = tmpdoc;
103  }
104  }
105 #else /* no HAVE_LIBXSLT */
106  ast_log(LOG_NOTICE, "XSLT support not found. XML documentation may be incomplete.\n");
107 #endif /* HAVE_LIBXSLT */
108 
109  /* Optimize for XPath */
110  xmlXPathOrderDocElems(doc);
111 
112  return (struct ast_xml_doc *) doc;
113 }
#define ast_log
Definition: astobj2.c:42
#define LOG_NOTICE

References ast_log, LOG_NOTICE, and NULL.

Referenced by ast_xmldoc_load_documentation().

◆ ast_xml_query()

struct ast_xml_xpath_results* ast_xml_query ( struct ast_xml_doc *  doc,
const char *  xpath_str 
)

Execute an XPath query on an XML document.

Parameters
docXML document to query
xpath_strThe XPath query string to execute on the document
Returns
An object containing the results of the XPath query on success
Return values
NULLon failure
Since
12

Definition at line 415 of file xml.c.

416 {
417  xmlXPathContextPtr context;
418  xmlXPathObjectPtr result;
419  if (!(context = xmlXPathNewContext((xmlDoc *) doc))) {
420  ast_log(LOG_ERROR, "Could not create XPath context!\n");
421  return NULL;
422  }
423  result = xmlXPathEvalExpression((xmlChar *) xpath_str, context);
424  xmlXPathFreeContext(context);
425  if (!result) {
426  ast_log(LOG_WARNING, "Error for query: %s\n", xpath_str);
427  return NULL;
428  }
429  if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
430  xmlXPathFreeObject(result);
431  ast_debug(5, "No results for query: %s\n", xpath_str);
432  return NULL;
433  }
434  return (struct ast_xml_xpath_results *) result;
435 }
static PGresult * result
Definition: cel_pgsql.c:84
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_WARNING

References ast_debug, ast_log, context, LOG_ERROR, LOG_WARNING, NULL, and result.

Referenced by ast_xmldoc_query().

◆ ast_xml_query_with_namespaces()

struct ast_xml_xpath_results* ast_xml_query_with_namespaces ( struct ast_xml_doc *  doc,
const char *  xpath_str,
struct ast_xml_namespace_def_vector namespaces 
)

Execute an XPath query on an XML document with namespaces.

Parameters
docXML document to query
xpath_strThe XPath query string to execute on the document
namespacesA vector of ast_xml_namespace structures (not pointers)
Returns
An object containing the results of the XPath query on success
Return values
NULLon failure

Definition at line 437 of file xml.c.

439 {
440  xmlXPathContextPtr context;
441  xmlXPathObjectPtr result;
442  int i;
443 
444  if (!(context = xmlXPathNewContext((xmlDoc *) doc))) {
445  ast_log(LOG_ERROR, "Could not create XPath context!\n");
446  return NULL;
447  }
448 
449  for (i = 0; i < AST_VECTOR_SIZE(namespaces); i++) {
450  struct ast_xml_namespace_def ns = AST_VECTOR_GET(namespaces, i);
451  if (xmlXPathRegisterNs(context, (xmlChar *)ns.prefix,
452  (xmlChar *)ns.href) != 0) {
453  xmlXPathFreeContext(context);
454  ast_log(LOG_ERROR, "Could not register namespace %s:%s\n",
455  ns.prefix, ns.href);
456  return NULL;
457  }
458  }
459 
460  result = xmlXPathEvalExpression((xmlChar *) xpath_str, context);
461  xmlXPathFreeContext(context);
462  if (!result) {
463  ast_log(LOG_WARNING, "Error for query: %s\n", xpath_str);
464  return NULL;
465  }
466  if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
467  xmlXPathFreeObject(result);
468  ast_debug(5, "No results for query: %s\n", xpath_str);
469  return NULL;
470  }
471  return (struct ast_xml_xpath_results *) result;
472 }
Namespace definition.
Definition: xml.h:301
const char * prefix
Definition: xml.h:302
const char * href
Definition: xml.h:303
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

References ast_debug, ast_log, AST_VECTOR_GET, AST_VECTOR_SIZE, context, ast_xml_namespace_def::href, LOG_ERROR, LOG_WARNING, NULL, ast_xml_namespace_def::prefix, and result.

◆ ast_xml_read_memory()

struct ast_xml_doc* ast_xml_read_memory ( char *  buffer,
size_t  size 
)

Open an XML document that resides in memory.

Parameters
bufferThe address where the document is stored
sizeThe number of bytes in the document
Return values
NULLon error.
Returns
The ast_xml_doc reference to the open document.

Definition at line 171 of file xml.c.

172 {
173  xmlDoc *doc;
174 
175  if (!buffer) {
176  return NULL;
177  }
178 
179  if (!(doc = xmlParseMemory(buffer, (int) size))) {
180  /* process xinclude elements. */
181  if (xmlXIncludeProcess(doc) < 0) {
182  xmlFreeDoc(doc);
183  return NULL;
184  }
185  }
186 
187  return (struct ast_xml_doc *) doc;
188 }

References NULL.

Referenced by sip_pidf_validate().

◆ ast_xml_set_attribute()

int ast_xml_set_attribute ( struct ast_xml_node *  node,
const char *  name,
const char *  value 
)

Set an attribute to a node.

Parameters
nodeIn which node we want to insert the attribute.
nameThe attribute name.
valueThe attribute value.
Return values
0on success.
-1on error.

Definition at line 263 of file xml.c.

264 {
265  if (!name || !value) {
266  return -1;
267  }
268 
269  if (!xmlSetProp((xmlNode *) node, (xmlChar *) name, (xmlChar *) value)) {
270  return -1;
271  }
272 
273  return 0;
274 }
int value
Definition: syslog.c:37

References name, and value.

Referenced by xmldoc_update_config_option(), and xmldoc_update_config_type().

◆ ast_xml_set_name()

void ast_xml_set_name ( struct ast_xml_node *  node,
const char *  name 
)

Set or reset an element's name.

Parameters
nodeNode whose name is to be set.
nameNew name.

Definition at line 350 of file xml.c.

351 {
352  if (!node || !name) {
353  return;
354  }
355 
356  xmlNodeSetName((xmlNode *) node, (const xmlChar *) name);
357 }

References name.

◆ ast_xml_set_root()

void ast_xml_set_root ( struct ast_xml_doc *  doc,
struct ast_xml_node *  node 
)

Specify the root node of a XML document.

Parameters
docXML Document reference
nodeA pointer to the node we want to set as root node.

Definition at line 200 of file xml.c.

201 {
202  if (!doc || !node) {
203  return;
204  }
205 
206  xmlDocSetRootElement((xmlDoc *) doc, (xmlNode *) node);
207 }

◆ ast_xml_set_text()

void ast_xml_set_text ( struct ast_xml_node *  node,
const char *  content 
)

Set an element content string.

Parameters
nodeNode from where to set the content string.
contentThe text to insert in the node.

Definition at line 341 of file xml.c.

342 {
343  if (!node || !content) {
344  return;
345  }
346 
347  xmlNodeSetContent((xmlNode *) node, (const xmlChar *) content);
348 }

Referenced by xmldoc_update_config_type().

◆ ast_xml_xpath_get_first_result()

struct ast_xml_node* ast_xml_xpath_get_first_result ( struct ast_xml_xpath_results *  results)

Return the first result node of an XPath query.

Parameters
resultsThe XPath results object to get the first result from
Returns
The first result in the XPath object on success
Return values
NULLon error
Since
12

Definition at line 389 of file xml.c.

390 {
391  return (struct ast_xml_node *) ((xmlXPathObjectPtr) results)->nodesetval->nodeTab[0];
392 }

Referenced by load_modules(), xmldoc_update_config_option(), and xmldoc_update_config_type().

◆ ast_xml_xpath_get_result()

struct ast_xml_node* ast_xml_xpath_get_result ( struct ast_xml_xpath_results *  results,
int  n 
)

Return a specific result node of an XPath query.

Parameters
resultsThe XPath results object to get the result from
nThe index of the result to get
Returns
The nth result in the XPath object on success
Return values
NULLon error

Definition at line 394 of file xml.c.

395 {
396  return (struct ast_xml_node *) ((xmlXPathObjectPtr) results)->nodesetval->nodeTab[i];
397 }

◆ ast_xml_xpath_num_results()

int ast_xml_xpath_num_results ( struct ast_xml_xpath_results *  results)

Return the number of results from an XPath query.

Parameters
resultsThe XPath results object to count
Returns
The number of results in the XPath object
Since
12

Definition at line 407 of file xml.c.

408 {
409  if (!results) {
410  return 0;
411  }
412  return ((xmlXPathObjectPtr) results)->nodesetval->nodeNr;
413 }

◆ ast_xml_xpath_results_free()

void ast_xml_xpath_results_free ( struct ast_xml_xpath_results *  results)

Free the XPath results.

Parameters
resultsThe XPath results object to dispose of
Since
12

Definition at line 399 of file xml.c.

400 {
401  if (!results) {
402  return;
403  }
404  xmlXPathFreeObject((xmlXPathObjectPtr) results);
405 }

Referenced by load_modules(), xmldoc_update_config_option(), and xmldoc_update_config_type().