Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
XML abstraction layer. More...
#include "asterisk.h"
#include "asterisk/xml.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/autoconfig.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xinclude.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
Go to the source code of this file.
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 i) |
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... | |
static int | process_xincludes (xmlDoc *doc) |
XML abstraction layer.
Definition in file xml.c.
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.
parent | Where to add the child node. |
child | The child node to add. |
NULL | on error. |
non-NULL | The add child node on success. |
Definition at line 168 of file xml.c.
References NULL.
Referenced by ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), and geoloc_eprofile_to_intermediate().
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.
parent | Where to add the child node. |
child | The child list to add. |
NULL | on error. |
non-NULL | The added child list on success. |
Definition at line 176 of file xml.c.
References NULL.
Referenced by ast_geoloc_eprofiles_to_pidf(), and handle_dump_docs().
void ast_xml_close | ( | struct ast_xml_doc * | doc | ) |
Close an already open document and free the used structure.
doc | XML Document to close |
Definition at line 211 of file xml.c.
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().
struct ast_xml_node * ast_xml_copy_node_list | ( | struct ast_xml_node * | list | ) |
Create a copy of a n ode list.
list | The list to copy. |
NULL | on error. |
non-NULL | The copied list. |
Definition at line 184 of file xml.c.
References NULL.
Referenced by ast_geoloc_eprofiles_to_pidf(), and handle_dump_docs().
int ast_xml_doc_dump_file | ( | FILE * | output, |
struct ast_xml_doc * | doc | ||
) |
Dump the specified document to a file.
Definition at line 380 of file xml.c.
Referenced by handle_dump_docs().
void ast_xml_doc_dump_memory | ( | struct ast_xml_doc * | doc, |
char ** | buffer, | ||
int * | length | ||
) |
Dump the specified document to a buffer.
doc | The XML doc to dump |
buffer | A pointer to a char * to receive the address of the results |
length | A pointer to an int to receive the length of the results |
Definition at line 385 of file xml.c.
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().
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.
root_node | This is the node starting point. |
name | Node name to find. |
attrname | attribute name to match (if NULL it won't be matched). |
attrvalue | attribute value to match (if NULL it won't be matched). |
NULL | if not found. |
Definition at line 297 of file xml.c.
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().
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 338 of file xml.c.
int ast_xml_finish | ( | void | ) |
Cleanup library allocated global data.
0 | On success. |
1 | On error. |
Definition at line 57 of file xml.c.
Referenced by xmldoc_unload_documentation().
void ast_xml_free_attr | ( | const char * | attribute | ) |
Free an attribute returned by ast_xml_get_attribute()
attribute | pointer to be freed. |
Definition at line 253 of file xml.c.
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().
void ast_xml_free_node | ( | struct ast_xml_node * | node | ) |
Free node.
node | Node to be released. |
Definition at line 243 of file xml.c.
References NULL.
Referenced by ast_geoloc_eprofiles_to_pidf(), geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), and geoloc_gml_list_to_xml().
void ast_xml_free_text | ( | const char * | text | ) |
Free a content element that was returned by ast_xml_get_text()
text | text to be freed. |
Definition at line 260 of file xml.c.
References text.
Referenced by _ast_xmldoc_build_seealso(), ast_geoloc_eprofile_create_from_pidf(), ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), geoloc_eprofile_create_from_xslt_result(), 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().
const char * ast_xml_get_attribute | ( | struct ast_xml_node * | node, |
const char * | attrname | ||
) |
Get a node attribute by name.
node | Node where to search the attribute. |
attrname | Attribute name. |
NULL | on error |
Definition at line 267 of file xml.c.
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().
struct ast_xml_doc * ast_xml_get_doc | ( | struct ast_xml_node * | node | ) |
const char * ast_xml_get_ns_href | ( | struct ast_xml_ns * | ns | ) |
const char * ast_xml_get_ns_prefix | ( | struct ast_xml_ns * | ns | ) |
struct ast_xml_node * ast_xml_get_root | ( | struct ast_xml_doc * | doc | ) |
Get the document root node.
doc | XML Document reference |
NULL | on error |
Definition at line 230 of file xml.c.
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().
const char * ast_xml_get_text | ( | struct ast_xml_node * | node | ) |
Get an element content string.
node | Node from where to get the string. |
NULL | on error. |
Definition at line 353 of file xml.c.
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().
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.
0 | On success. |
1 | On error. |
Definition at line 48 of file xml.c.
Referenced by xmldoc_load_documentation().
struct ast_xml_doc * ast_xml_new | ( | void | ) |
Create a XML document.
NULL | on error. |
non-NULL | The allocated document structure. |
Definition at line 136 of file xml.c.
Referenced by ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), and handle_dump_docs().
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.
parent | The pointer of the parent node. |
child_name | The name of the child node to add. |
NULL | on error. |
non-NULL | The created child node pointer. |
Definition at line 156 of file xml.c.
References NULL.
Referenced by geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), geoloc_gml_list_to_xml(), and xmldoc_update_config_type().
struct ast_xml_node * ast_xml_new_node | ( | const char * | name | ) |
Create a XML node.
name | The name of the node to be created. |
NULL | on error. |
non-NULL | The allocated node structe. |
Definition at line 144 of file xml.c.
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().
struct ast_xml_node * ast_xml_node_get_children | ( | struct ast_xml_node * | node | ) |
Get the node's children.
Definition at line 395 of file xml.c.
Referenced by _ast_xmldoc_build_arguments(), _ast_xmldoc_build_seealso(), _ast_xmldoc_build_syntax(), _xmldoc_build_field(), ast_geoloc_eprofiles_to_pidf(), ast_xmldoc_build_arguments(), ast_xmldoc_build_documentation(), ast_xmldoc_build_final_response(), ast_xmldoc_build_list_responses(), ast_xmldoc_build_seealso(), build_config_docs(), geoloc_eprofile_create_from_xslt_result(), handle_dump_docs(), is_pidf_lo(), load_modules(), var_list_from_loc_info(), var_list_from_node(), xmldoc_build_final_response(), xmldoc_build_list_responses(), xmldoc_get_formatted(), xmldoc_get_node(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_config_object(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), xmldoc_has_inside(), xmldoc_has_nodes(), xmldoc_has_specialtags(), xmldoc_parse_argument(), xmldoc_parse_cmd_enumlist(), xmldoc_parse_enum(), xmldoc_parse_enumlist(), xmldoc_parse_example(), xmldoc_parse_info(), xmldoc_parse_option(), xmldoc_parse_optionlist(), xmldoc_parse_para(), xmldoc_parse_parameter(), xmldoc_parse_specialtags(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().
const char * ast_xml_node_get_name | ( | struct ast_xml_node * | node | ) |
Get the name of a node.
Definition at line 390 of file xml.c.
Referenced by _ast_xmldoc_build_arguments(), _ast_xmldoc_build_seealso(), _ast_xmldoc_build_syntax(), ast_xml_find_element(), ast_xmldoc_build_documentation(), build_config_docs(), geoloc_eprofile_create_from_xslt_result(), is_pidf_lo(), var_list_from_loc_info(), var_list_from_node(), xmldoc_build_list_responses(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), xmldoc_has_inside(), xmldoc_has_nodes(), xmldoc_has_specialtags(), xmldoc_load_documentation(), xmldoc_parse_cmd_enumlist(), xmldoc_parse_enumlist(), xmldoc_parse_example(), xmldoc_parse_info(), xmldoc_parse_option(), xmldoc_parse_optionlist(), xmldoc_parse_para(), xmldoc_parse_parameter(), xmldoc_parse_specialtags(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().
struct ast_xml_node * ast_xml_node_get_next | ( | struct ast_xml_node * | node | ) |
Get the next node in the same level.
Definition at line 400 of file xml.c.
Referenced by _ast_xmldoc_build_arguments(), _ast_xmldoc_build_seealso(), _ast_xmldoc_build_syntax(), ast_xml_find_element(), ast_xmldoc_build_documentation(), build_config_docs(), var_list_from_node(), xmldoc_build_list_responses(), xmldoc_get_formatted(), xmldoc_get_node(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), xmldoc_has_inside(), xmldoc_has_nodes(), xmldoc_has_specialtags(), xmldoc_parse_argument(), xmldoc_parse_cmd_enumlist(), xmldoc_parse_enum(), xmldoc_parse_enumlist(), xmldoc_parse_example(), xmldoc_parse_info(), xmldoc_parse_option(), xmldoc_parse_optionlist(), xmldoc_parse_para(), xmldoc_parse_parameter(), xmldoc_parse_specialtags(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().
struct ast_xml_node * ast_xml_node_get_parent | ( | struct ast_xml_node * | node | ) |
struct ast_xml_node * ast_xml_node_get_prev | ( | struct ast_xml_node * | node | ) |
struct ast_xml_doc * ast_xml_open | ( | char * | filename | ) |
Open an XML document.
filename | Document path. |
NULL | on error. |
Definition at line 94 of file xml.c.
References ast_log, LOG_NOTICE, NULL, and process_xincludes().
Referenced by xmldoc_load_documentation().
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.
doc | XML document to query |
xpath_str | The XPath query string to execute on the document |
NULL | on failure |
Definition at line 441 of file xml.c.
References ast_debug, ast_log, voicemailpwcheck::context, LOG_ERROR, LOG_WARNING, NULL, and result.
Referenced by ast_xmldoc_query().
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.
doc | XML document to query |
xpath_str | The XPath query string to execute on the document |
namespaces | A vector of ast_xml_namespace structures (not pointers) |
NULL | on failure |
Definition at line 463 of file xml.c.
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.
struct ast_xml_doc * ast_xml_read_memory | ( | char * | buffer, |
size_t | size | ||
) |
Open an XML document that resides in memory.
buffer | The address where the document is stored |
size | The number of bytes in the document |
NULL | on error. |
Definition at line 192 of file xml.c.
References NULL, and process_xincludes().
Referenced by handle_incoming_request().
int ast_xml_set_attribute | ( | struct ast_xml_node * | node, |
const char * | name, | ||
const char * | value | ||
) |
Set an attribute to a node.
node | In which node we want to insert the attribute. |
name | The attribute name. |
value | The attribute value. |
0 | on success. |
-1 | on error. |
Definition at line 284 of file xml.c.
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().
void ast_xml_set_name | ( | struct ast_xml_node * | node, |
const char * | name | ||
) |
void ast_xml_set_root | ( | struct ast_xml_doc * | doc, |
struct ast_xml_node * | node | ||
) |
Specify the root node of a XML document.
doc | XML Document reference |
node | A pointer to the node we want to set as root node. |
Definition at line 221 of file xml.c.
Referenced by ast_geoloc_eprofile_to_pidf(), ast_geoloc_eprofiles_to_pidf(), and handle_dump_docs().
void ast_xml_set_text | ( | struct ast_xml_node * | node, |
const char * | content | ||
) |
Set an element content string.
node | Node from where to set the content string. |
content | The text to insert in the node. |
Definition at line 362 of file xml.c.
Referenced by geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), geoloc_gml_list_to_xml(), and xmldoc_update_config_type().
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.
results | The XPath results object to get the first result from |
NULL | on error |
Definition at line 415 of file xml.c.
Referenced by load_modules(), xmldoc_update_config_option(), and xmldoc_update_config_type().
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.
results | The XPath results object to get the result from |
n | The index of the result to get |
NULL | on error |
Definition at line 420 of file xml.c.
int ast_xml_xpath_num_results | ( | struct ast_xml_xpath_results * | results | ) |
Return the number of results from an XPath query.
results | The XPath results object to count |
Definition at line 433 of file xml.c.
void ast_xml_xpath_results_free | ( | struct ast_xml_xpath_results * | results | ) |
Free the XPath results.
results | The XPath results object to dispose of |
Definition at line 425 of file xml.c.
Referenced by load_modules(), xmldoc_update_config_option(), and xmldoc_update_config_type().
|
static |
Definition at line 83 of file xml.c.
Referenced by ast_xml_open(), and ast_xml_read_memory().