Asterisk - The Open Source Telephony Project GIT-master-2de1a68
Data Structures | Macros | 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
 

Macros

#define ast_xml_find_child_element(_parent_node, _name, _attrname, _attrvalue)    ast_xml_find_element(ast_xml_node_get_children(_parent_node), _name, _attrname, _attrvalue)
 Find a direct child element by name. More...
 

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...
 
void ast_xml_doc_dump_memory (struct ast_xml_doc *doc, char **buffer, int *length)
 Dump the specified document to a buffer. 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.

Macro Definition Documentation

◆ ast_xml_find_child_element

#define ast_xml_find_child_element (   _parent_node,
  _name,
  _attrname,
  _attrvalue 
)     ast_xml_find_element(ast_xml_node_get_children(_parent_node), _name, _attrname, _attrvalue)

Find a direct child element by name.

Parameters
_parent_nodeThis is the parent node to search.
_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 201 of 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 170 of file xml.c.

171{
172 if (!parent || !child) {
173 return NULL;
174 }
175 return (struct ast_xml_node *) xmlAddChild((xmlNode *) parent, (xmlNode *) child);
176}
#define NULL
Definition: resample.c:96

References NULL.

Referenced by ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), and geoloc_eprofile_to_intermediate().

◆ 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 178 of file xml.c.

179{
180 if (!parent || !child) {
181 return NULL;
182 }
183 return (struct ast_xml_node *) xmlAddChildList((xmlNode *) parent, (xmlNode *) child);
184}

References NULL.

Referenced by ast_geoloc_eprofiles_to_pidf(), and handle_dump_docs().

◆ 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 213 of file xml.c.

214{
215 if (!doc) {
216 return;
217 }
218
219 xmlFreeDoc((xmlDoc *) doc);
220 doc = NULL;
221}

References NULL.

Referenced by ast_geoloc_eprofile_create_from_pidf(), ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), handle_dump_docs(), handle_incoming_request(), xmldoc_load_documentation(), and xmldoc_purge_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 186 of file xml.c.

187{
188 if (!list) {
189 return NULL;
190 }
191 return (struct ast_xml_node *) xmlCopyNodeList((xmlNode *) list);
192}

References NULL.

Referenced by ast_geoloc_eprofiles_to_pidf(), and handle_dump_docs().

◆ 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 382 of file xml.c.

383{
384 return xmlDocDump(output, (xmlDocPtr)doc);
385}

Referenced by handle_dump_docs().

◆ ast_xml_doc_dump_memory()

void ast_xml_doc_dump_memory ( struct ast_xml_doc *  doc,
char **  buffer,
int *  length 
)

Dump the specified document to a buffer.

Parameters
docThe XML doc to dump
bufferA pointer to a char * to receive the address of the results
lengthA pointer to an int to receive the length of the results
Note
The result buffer must be freed with ast_xml_free_text().

Definition at line 387 of file xml.c.

388{
389 xmlDocDumpFormatMemory((xmlDocPtr)doc, (xmlChar **)buffer, length, 1);
390}

Referenced by ast_geoloc_eprofile_create_from_pidf(), ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), and geoloc_eprofile_create_from_xslt_result().

◆ 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 299 of file xml.c.

300{
301 struct ast_xml_node *cur;
302 const char *attr;
303
304 if (!root_node) {
305 return NULL;
306 }
307
308 for (cur = root_node; cur; cur = ast_xml_node_get_next(cur)) {
309 /* Check if the name matchs */
310 if (strcmp(ast_xml_node_get_name(cur), name)) {
311 continue;
312 }
313 /* We need to check for a specific attribute name? */
314 if (!attrname || !attrvalue) {
315 return cur;
316 }
317 /* Get the attribute, we need to compare it. */
318 if ((attr = ast_xml_get_attribute(cur, attrname))) {
319 /* does attribute name/value matches? */
320 if (!strcmp(attr, attrvalue)) {
321 ast_xml_free_attr(attr);
322 return cur;
323 }
324 ast_xml_free_attr(attr);
325 }
326 }
327
328 return NULL;
329}
static const char name[]
Definition: format_mp3.c:68
const char * ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname)
Get a node attribute by name.
Definition: xml.c:269
const char * ast_xml_node_get_name(struct ast_xml_node *node)
Get the name of a node.
Definition: xml.c:392
void ast_xml_free_attr(const char *attribute)
Free an attribute returned by ast_xml_get_attribute()
Definition: xml.c:255
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:402

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(), 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 340 of file xml.c.

340 {
341 xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name);
342 return (struct ast_xml_ns *) ns;
343}
Definition: test_heap.c:38

◆ 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 245 of file xml.c.

246{
247 if (!node) {
248 return;
249 }
250
251 xmlFreeNode((xmlNode *) node);
252 node = NULL;
253}

References NULL.

Referenced by ast_geoloc_eprofiles_to_pidf(), geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), and geoloc_gml_list_to_xml().

◆ ast_xml_free_text()

void ast_xml_free_text ( const char *  text)

◆ 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.
Note
The result must be freed with ast_xml_free_attr().

Definition at line 269 of file xml.c.

270{
271 xmlChar *attrvalue;
272
273 if (!node) {
274 return NULL;
275 }
276
277 if (!attrname) {
278 return NULL;
279 }
280
281 attrvalue = xmlGetProp((xmlNode *) node, (xmlChar *) attrname);
282
283 return (const char *) attrvalue;
284}

References NULL.

Referenced by _ast_xmldoc_build_seealso(), ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), ast_xml_find_element(), ast_xmldoc_build_documentation(), ast_xmldoc_regenerate_doc_item(), build_config_docs(), geoloc_eprofile_create_from_xslt_result(), var_list_from_confidence(), var_list_from_loc_info(), var_list_from_node(), 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 331 of file xml.c.

332{
333 if (!node) {
334 return NULL;
335 }
336
337 return (struct ast_xml_doc *) ((xmlNode *)node)->doc;
338}

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 350 of file xml.c.

351{
352 return (const char *) ((xmlNsPtr) ns)->href;
353}

◆ 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 345 of file xml.c.

346{
347 return (const char *) ((xmlNsPtr) ns)->prefix;
348}

◆ 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 232 of file xml.c.

233{
234 xmlNode *root_node;
235
236 if (!doc) {
237 return NULL;
238 }
239
240 root_node = xmlDocGetRootElement((xmlDoc *) doc);
241
242 return (struct ast_xml_node *) root_node;
243}

References NULL.

Referenced by ast_xmldoc_build_documentation(), geoloc_eprofile_create_from_xslt_result(), handle_dump_docs(), is_pidf_lo(), xmldoc_get_node(), and xmldoc_load_documentation().

◆ 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 355 of file xml.c.

356{
357 if (!node) {
358 return NULL;
359 }
360
361 return (const char *) xmlNodeGetContent((xmlNode *) node);
362}

References NULL.

Referenced by _ast_xmldoc_build_seealso(), geoloc_eprofile_create_from_xslt_result(), load_modules(), var_list_from_confidence(), var_list_from_node(), 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 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 138 of file xml.c.

139{
140 xmlDoc *doc;
141
142 doc = xmlNewDoc((const xmlChar *) "1.0");
143 return (struct ast_xml_doc *) doc;
144}

Referenced by ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), and handle_dump_docs().

◆ 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 158 of file xml.c.

159{
160 xmlNode *child;
161
162 if (!parent || !child_name) {
163 return NULL;
164 }
165
166 child = xmlNewChild((xmlNode *) parent, NULL, (const xmlChar *) child_name, NULL);
167 return (struct ast_xml_node *) child;
168}

References NULL.

Referenced by geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), geoloc_gml_list_to_xml(), and 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 146 of file xml.c.

147{
148 xmlNode *node;
149 if (!name) {
150 return NULL;
151 }
152
153 node = xmlNewNode(NULL, (const xmlChar *) name);
154
155 return (struct ast_xml_node *) node;
156}

References name, and NULL.

Referenced by ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), geoloc_gml_list_to_xml(), and handle_dump_docs().

◆ 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 412 of file xml.c.

413{
414 return (struct ast_xml_node *) ((xmlNode *) node)->parent;
415}

◆ 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 407 of file xml.c.

408{
409 return (struct ast_xml_node *) ((xmlNode *) node)->prev;
410}

◆ 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 94 of file xml.c.

95{
96 xmlDoc *doc;
97
98 if (!filename) {
99 return NULL;
100 }
101
102 xmlSubstituteEntitiesDefault(1);
103
104 doc = xmlReadFile(filename, NULL, XML_PARSE_RECOVER);
105 if (!doc) {
106 return NULL;
107 }
108
109 /* process xinclude elements. */
110 if (process_xincludes(doc) < 0) {
111 xmlFreeDoc(doc);
112 return NULL;
113 }
114
115#ifdef HAVE_LIBXSLT
116 {
117 xsltStylesheetPtr xslt = xsltLoadStylesheetPI(doc);
118 if (xslt) {
119 xmlDocPtr tmpdoc = xsltApplyStylesheet(xslt, doc, NULL);
120 xsltFreeStylesheet(xslt);
121 xmlFreeDoc(doc);
122 if (!tmpdoc) {
123 return NULL;
124 }
125 doc = tmpdoc;
126 }
127 }
128#else /* no HAVE_LIBXSLT */
129 ast_log(LOG_NOTICE, "XSLT support not found. XML documentation may be incomplete.\n");
130#endif /* HAVE_LIBXSLT */
131
132 /* Optimize for XPath */
133 xmlXPathOrderDocElems(doc);
134
135 return (struct ast_xml_doc *) doc;
136}
#define ast_log
Definition: astobj2.c:42
#define LOG_NOTICE
static int process_xincludes(xmlDoc *doc)
Definition: xml.c:83

References ast_log, LOG_NOTICE, NULL, and process_xincludes().

Referenced by 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 443 of file xml.c.

444{
445 xmlXPathContextPtr context;
446 xmlXPathObjectPtr result;
447 if (!(context = xmlXPathNewContext((xmlDoc *) doc))) {
448 ast_log(LOG_ERROR, "Could not create XPath context!\n");
449 return NULL;
450 }
451 result = xmlXPathEvalExpression((xmlChar *) xpath_str, context);
452 xmlXPathFreeContext(context);
453 if (!result) {
454 ast_log(LOG_WARNING, "Error for query: %s\n", xpath_str);
455 return NULL;
456 }
457 if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
458 xmlXPathFreeObject(result);
459 ast_debug(5, "No results for query: %s\n", xpath_str);
460 return NULL;
461 }
462 return (struct ast_xml_xpath_results *) result;
463}
static PGresult * result
Definition: cel_pgsql.c:84
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_WARNING

References ast_debug, ast_log, voicemailpwcheck::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 465 of file xml.c.

467{
468 xmlXPathContextPtr context;
469 xmlXPathObjectPtr result;
470 int i;
471
472 if (!(context = xmlXPathNewContext((xmlDoc *) doc))) {
473 ast_log(LOG_ERROR, "Could not create XPath context!\n");
474 return NULL;
475 }
476
477 for (i = 0; i < AST_VECTOR_SIZE(namespaces); i++) {
478 struct ast_xml_namespace_def ns = AST_VECTOR_GET(namespaces, i);
479 if (xmlXPathRegisterNs(context, (xmlChar *)ns.prefix,
480 (xmlChar *)ns.href) != 0) {
481 xmlXPathFreeContext(context);
482 ast_log(LOG_ERROR, "Could not register namespace %s:%s\n",
483 ns.prefix, ns.href);
484 return NULL;
485 }
486 }
487
488 result = xmlXPathEvalExpression((xmlChar *) xpath_str, context);
489 xmlXPathFreeContext(context);
490 if (!result) {
491 ast_log(LOG_WARNING, "Error for query: %s\n", xpath_str);
492 return NULL;
493 }
494 if (xmlXPathNodeSetIsEmpty(result->nodesetval)) {
495 xmlXPathFreeObject(result);
496 ast_debug(5, "No results for query: %s\n", xpath_str);
497 return NULL;
498 }
499 return (struct ast_xml_xpath_results *) result;
500}
Namespace definition.
Definition: xml.h:325
const char * prefix
Definition: xml.h:326
const char * href
Definition: xml.h:327
#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, voicemailpwcheck::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 194 of file xml.c.

195{
196 xmlDoc *doc;
197
198 if (!buffer) {
199 return NULL;
200 }
201
202 if (!(doc = xmlParseMemory(buffer, (int) size))) {
203 /* process xinclude elements. */
204 if (process_xincludes(doc) < 0) {
205 xmlFreeDoc(doc);
206 return NULL;
207 }
208 }
209
210 return (struct ast_xml_doc *) doc;
211}

References NULL, and process_xincludes().

Referenced by handle_incoming_request().

◆ 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 286 of file xml.c.

287{
288 if (!name || !value) {
289 return -1;
290 }
291
292 if (!xmlSetProp((xmlNode *) node, (xmlChar *) name, (xmlChar *) value)) {
293 return -1;
294 }
295
296 return 0;
297}
int value
Definition: syslog.c:37

References name, and value.

Referenced by ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), geoloc_gml_list_to_xml(), 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 373 of file xml.c.

374{
375 if (!node || !name) {
376 return;
377 }
378
379 xmlNodeSetName((xmlNode *) node, (const xmlChar *) name);
380}

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 223 of file xml.c.

224{
225 if (!doc || !node) {
226 return;
227 }
228
229 xmlDocSetRootElement((xmlDoc *) doc, (xmlNode *) node);
230}

Referenced by ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), and handle_dump_docs().

◆ 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 364 of file xml.c.

365{
366 if (!node || !content) {
367 return;
368 }
369
370 xmlNodeSetContent((xmlNode *) node, (const xmlChar *) content);
371}

Referenced by geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), geoloc_gml_list_to_xml(), and 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 417 of file xml.c.

418{
419 return (struct ast_xml_node *) ((xmlXPathObjectPtr) results)->nodesetval->nodeTab[0];
420}

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 422 of file xml.c.

423{
424 return (struct ast_xml_node *) ((xmlXPathObjectPtr) results)->nodesetval->nodeTab[i];
425}

◆ 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 435 of file xml.c.

436{
437 if (!results) {
438 return 0;
439 }
440 return ((xmlXPathObjectPtr) results)->nodesetval->nodeNr;
441}

◆ 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 427 of file xml.c.

428{
429 if (!results) {
430 return;
431 }
432 xmlXPathFreeObject((xmlXPathObjectPtr) results);
433}

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