#include "asterisk.h"
#include "asterisk/xml.h"
#include "asterisk/logger.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xinclude.h>
Go to the source code of this file.
Functions | |
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. | |
void | ast_xml_close (struct ast_xml_doc *doc) |
Close an already open document and free the used structure. | |
int | ast_xml_doc_dump_file (FILE *output, struct ast_xml_doc *doc) |
Dump the specified document to a file. | |
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. | |
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. | |
void | ast_xml_free_attr (const char *attribute) |
Free an attribute returned by ast_xml_get_attribute(). | |
void | ast_xml_free_node (struct ast_xml_node *node) |
Free node. | |
void | ast_xml_free_text (const char *text) |
Free a content element that was returned by ast_xml_get_text(). | |
const char * | ast_xml_get_attribute (struct ast_xml_node *node, const char *attrname) |
Get a node attribute by name. | |
ast_xml_doc * | ast_xml_get_doc (struct ast_xml_node *node) |
Get the document based on a node. | |
const char * | ast_xml_get_ns_href (struct ast_xml_ns *ns) |
ast_xml_node * | ast_xml_get_root (struct ast_xml_doc *doc) |
Get the document root node. | |
const char * | ast_xml_get_text (struct ast_xml_node *node) |
Get an element content string. | |
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. | |
ast_xml_doc * | ast_xml_new (void) |
Create a XML document. | |
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. | |
ast_xml_node * | ast_xml_new_node (const char *name) |
Create a XML node. | |
ast_xml_node * | ast_xml_node_get_children (struct ast_xml_node *node) |
Get the node's children. | |
const char * | ast_xml_node_get_name (struct ast_xml_node *node) |
Get the name of a node. | |
ast_xml_node * | ast_xml_node_get_next (struct ast_xml_node *node) |
Get the next node in the same level. | |
ast_xml_node * | ast_xml_node_get_parent (struct ast_xml_node *node) |
Get the parent of a specified node. | |
ast_xml_node * | ast_xml_node_get_prev (struct ast_xml_node *node) |
Get the previous node in the same leve. | |
ast_xml_doc * | ast_xml_open (char *filename) |
Open an XML document. | |
ast_xml_doc * | ast_xml_read_memory (char *buffer, size_t size) |
Open an XML document that resides in memory. | |
int | ast_xml_set_attribute (struct ast_xml_node *node, const char *name, const char *value) |
Set an attribute to a node. | |
void | ast_xml_set_root (struct ast_xml_doc *doc, struct ast_xml_node *node) |
Specify the root node of a XML document. | |
void | ast_xml_set_text (struct ast_xml_node *node, const char *content) |
Set an element content string. |
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 103 of file xml.c.
Referenced by data_get_xml_add_child().
00104 { 00105 if (!parent || !child) { 00106 return NULL; 00107 } 00108 return (struct ast_xml_node *) xmlAddChild((xmlNode *) parent, (xmlNode *) child); 00109 }
void ast_xml_close | ( | struct ast_xml_doc * | doc | ) |
Close an already open document and free the used structure.
doc | The document reference. |
Definition at line 130 of file xml.c.
Referenced by ast_data_get_xml(), cc_esc_publish_handler(), and sip_pidf_validate().
00131 { 00132 if (!doc) { 00133 return; 00134 } 00135 00136 xmlFreeDoc((xmlDoc *) doc); 00137 doc = NULL; 00138 }
int ast_xml_doc_dump_file | ( | FILE * | output, | |
struct ast_xml_doc * | doc | |||
) |
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. | |
The | node on success. |
Definition at line 216 of file xml.c.
References ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_name(), and ast_xml_node_get_next().
Referenced by cc_esc_publish_handler(), xmldoc_build_field(), and xmldoc_get_node().
00217 { 00218 struct ast_xml_node *cur; 00219 const char *attr; 00220 00221 if (!root_node) { 00222 return NULL; 00223 } 00224 00225 for (cur = root_node; cur; cur = ast_xml_node_get_next(cur)) { 00226 /* Check if the name matchs */ 00227 if (strcmp(ast_xml_node_get_name(cur), name)) { 00228 continue; 00229 } 00230 /* We need to check for a specific attribute name? */ 00231 if (!attrname || !attrvalue) { 00232 return cur; 00233 } 00234 /* Get the attribute, we need to compare it. */ 00235 if ((attr = ast_xml_get_attribute(cur, attrname))) { 00236 /* does attribute name/value matches? */ 00237 if (!strcmp(attr, attrvalue)) { 00238 ast_xml_free_attr(attr); 00239 return cur; 00240 } 00241 ast_xml_free_attr(attr); 00242 } 00243 } 00244 00245 return NULL; 00246 }
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 257 of file xml.c.
Referenced by pidf_validate_presence().
00257 { 00258 xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name); 00259 return (struct ast_xml_ns *) ns; 00260 }
int ast_xml_finish | ( | void | ) |
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 172 of file xml.c.
Referenced by ast_xml_find_element(), ast_xmldoc_build_seealso(), pidf_validate_presence(), pidf_validate_tuple(), xmldoc_get_node(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), xmldoc_parse_argument(), xmldoc_parse_enumlist(), xmldoc_parse_optionlist(), xmldoc_parse_parameter(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().
void ast_xml_free_node | ( | struct ast_xml_node * | node | ) |
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 179 of file xml.c.
Referenced by ast_xmldoc_build_seealso(), cc_esc_publish_handler(), xmldoc_get_formatted(), xmldoc_parse_para(), and xmldoc_parse_variable().
00180 { 00181 if (text) { 00182 xmlFree((char *) text); 00183 } 00184 }
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 | |
The | attribute value on success. |
Definition at line 186 of file xml.c.
Referenced by ast_xml_find_element(), ast_xmldoc_build_seealso(), pidf_validate_presence(), pidf_validate_tuple(), xmldoc_get_node(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), xmldoc_parse_argument(), xmldoc_parse_enumlist(), xmldoc_parse_optionlist(), xmldoc_parse_parameter(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().
00187 { 00188 xmlChar *attrvalue; 00189 00190 if (!node) { 00191 return NULL; 00192 } 00193 00194 if (!attrname) { 00195 return NULL; 00196 } 00197 00198 attrvalue = xmlGetProp((xmlNode *) node, (xmlChar *) attrname); 00199 00200 return (const char *) attrvalue; 00201 }
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 | ) |
struct ast_xml_node* ast_xml_get_root | ( | struct ast_xml_doc * | doc | ) |
Get the document root node.
doc | Document reference |
NULL | on error | |
The | root node on success. |
Definition at line 149 of file xml.c.
Referenced by cc_esc_publish_handler(), pidf_validate_presence(), and xmldoc_get_node().
00150 { 00151 xmlNode *root_node; 00152 00153 if (!doc) { 00154 return NULL; 00155 } 00156 00157 root_node = xmlDocGetRootElement((xmlDoc *) doc); 00158 00159 return (struct ast_xml_node *) root_node; 00160 }
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. | |
The | text content of node. |
Definition at line 267 of file xml.c.
Referenced by ast_xmldoc_build_seealso(), cc_esc_publish_handler(), xmldoc_get_formatted(), xmldoc_parse_para(), and xmldoc_parse_variable().
00268 { 00269 if (!node) { 00270 return NULL; 00271 } 00272 00273 return (const char *) xmlNodeGetContent((xmlNode *) node); 00274 }
int ast_xml_init | ( | void | ) |
struct ast_xml_doc* ast_xml_new | ( | void | ) |
Create a XML document.
NULL | on error. | |
non-NULL | The allocated document structure. |
Definition at line 71 of file xml.c.
Referenced by ast_data_get_xml().
00072 { 00073 xmlDoc *doc; 00074 00075 doc = xmlNewDoc((const xmlChar *) "1.0"); 00076 return (struct ast_xml_doc *) doc; 00077 }
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 91 of file xml.c.
00092 { 00093 xmlNode *child; 00094 00095 if (!parent || !child_name) { 00096 return NULL; 00097 } 00098 00099 child = xmlNewChild((xmlNode *) parent, NULL, (const xmlChar *) child_name, NULL); 00100 return (struct ast_xml_node *) child; 00101 }
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 79 of file xml.c.
Referenced by ast_data_get_xml(), and data_get_xml_add_child().
00080 { 00081 xmlNode *node; 00082 if (!name) { 00083 return NULL; 00084 } 00085 00086 node = xmlNewNode(NULL, (const xmlChar *) name); 00087 00088 return (struct ast_xml_node *) node; 00089 }
struct ast_xml_node* ast_xml_node_get_children | ( | struct ast_xml_node * | node | ) |
Get the node's children.
Definition at line 295 of file xml.c.
Referenced by ast_xmldoc_build_arguments(), ast_xmldoc_build_seealso(), ast_xmldoc_build_syntax(), cc_esc_publish_handler(), pidf_validate_presence(), pidf_validate_tuple(), xmldoc_build_field(), 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_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 290 of file xml.c.
Referenced by ast_xml_find_element(), ast_xmldoc_build_arguments(), ast_xmldoc_build_seealso(), ast_xmldoc_build_syntax(), pidf_validate_presence(), pidf_validate_tuple(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), xmldoc_has_inside(), xmldoc_has_nodes(), xmldoc_has_specialtags(), xmldoc_parse_cmd_enumlist(), xmldoc_parse_enumlist(), 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 300 of file xml.c.
Referenced by ast_xml_find_element(), ast_xmldoc_build_arguments(), ast_xmldoc_build_seealso(), ast_xmldoc_build_syntax(), pidf_validate_presence(), pidf_validate_tuple(), xmldoc_get_formatted(), 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_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. | |
The | ast_xml_doc reference to the open document. |
Definition at line 51 of file xml.c.
00052 { 00053 xmlDoc *doc; 00054 00055 if (!filename) { 00056 return NULL; 00057 } 00058 00059 doc = xmlReadFile(filename, NULL, XML_PARSE_RECOVER); 00060 if (doc) { 00061 /* process xinclude elements. */ 00062 if (xmlXIncludeProcess(doc) < 0) { 00063 xmlFreeDoc(doc); 00064 return NULL; 00065 } 00066 } 00067 00068 return (struct ast_xml_doc *) doc; 00069 }
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. | |
The | ast_xml_doc reference to the open document. |
Definition at line 111 of file xml.c.
Referenced by sip_pidf_validate().
00112 { 00113 xmlDoc *doc; 00114 00115 if (!buffer) { 00116 return NULL; 00117 } 00118 00119 if (!(doc = xmlParseMemory(buffer, (int) size))) { 00120 /* process xinclude elements. */ 00121 if (xmlXIncludeProcess(doc) < 0) { 00122 xmlFreeDoc(doc); 00123 return NULL; 00124 } 00125 } 00126 00127 return (struct ast_xml_doc *) doc; 00128 }
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 203 of file xml.c.
00204 { 00205 if (!name || !value) { 00206 return -1; 00207 } 00208 00209 if (!xmlSetProp((xmlNode *) node, (xmlChar *) name, (xmlChar *) value)) { 00210 return -1; 00211 } 00212 00213 return 0; 00214 }
void ast_xml_set_root | ( | struct ast_xml_doc * | doc, | |
struct ast_xml_node * | node | |||
) |
Specify the root node of a XML document.
doc | The document pointer. | |
node | A pointer to the node we want to set as root node. |
Definition at line 140 of file xml.c.
Referenced by ast_data_get_xml().
00141 { 00142 if (!doc || !node) { 00143 return; 00144 } 00145 00146 xmlDocSetRootElement((xmlDoc *) doc, (xmlNode *) node); 00147 }
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 276 of file xml.c.
Referenced by data_get_xml_add_child().
00277 { 00278 if (!node || !content) { 00279 return; 00280 } 00281 00282 xmlNodeSetContent((xmlNode *) node, (const xmlChar *) content); 00283 }