Sat Apr 26 2014 22:03:20

Asterisk developer's documentation


xml.h File Reference

Asterisk XML abstraction layer. More...

This graph shows which files directly or indirectly include this file:

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.
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.
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.
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.
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.
struct 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)
struct 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.
struct ast_xml_doc * ast_xml_new (void)
 Create a XML document.
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.
struct ast_xml_node * ast_xml_new_node (const char *name)
 Create a XML node.
struct 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.
struct ast_xml_node * ast_xml_node_get_next (struct ast_xml_node *node)
 Get the next node in the same level.
struct ast_xml_node * ast_xml_node_get_parent (struct ast_xml_node *node)
 Get the parent of a specified node.
struct ast_xml_node * ast_xml_node_get_prev (struct ast_xml_node *node)
 Get the previous node in the same leve.
struct ast_xml_doc * ast_xml_open (char *filename)
 Open an XML document.
struct 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.

Detailed Description

Asterisk XML abstraction layer.

Definition in file xml.h.


Function Documentation

struct ast_xml_node* ast_xml_add_child ( struct ast_xml_node *  parent,
struct ast_xml_node *  child 
) [read]

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

Referenced by data_get_xml_add_child().

{
   if (!parent || !child) {
      return NULL;
   }
   return (struct ast_xml_node *) xmlAddChild((xmlNode *) parent, (xmlNode *) child);
}
void ast_xml_close ( struct ast_xml_doc *  doc)

Close an already open document and free the used structure.

Return values:
docThe document reference.

Definition at line 134 of file xml.c.

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

{
   if (!doc) {
      return;
   }

   xmlFreeDoc((xmlDoc *) doc);
   doc = NULL;
}
int ast_xml_doc_dump_file ( FILE *  output,
struct ast_xml_doc *  doc 
)

Dump the specified document to a file.

Definition at line 289 of file xml.c.

{
   return xmlDocDump(output, (xmlDocPtr)doc);
}
struct ast_xml_node* ast_xml_find_element ( struct ast_xml_node *  root_node,
const char *  name,
const char *  attrname,
const char *  attrvalue 
) [read]

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.
Thenode on success.

Definition at line 220 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 _xmldoc_build_field(), cc_esc_publish_handler(), and xmldoc_get_node().

{
   struct ast_xml_node *cur;
   const char *attr;

   if (!root_node) {
      return NULL;
   }

   for (cur = root_node; cur; cur = ast_xml_node_get_next(cur)) {
      /* Check if the name matchs */
      if (strcmp(ast_xml_node_get_name(cur), name)) {
         continue;
      }
      /* We need to check for a specific attribute name? */
      if (!attrname || !attrvalue) {
         return cur;
      }
      /* Get the attribute, we need to compare it. */
      if ((attr = ast_xml_get_attribute(cur, attrname))) {
         /* does attribute name/value matches? */
         if (!strcmp(attr, attrvalue)) {
            ast_xml_free_attr(attr);
            return cur;
         }
         ast_xml_free_attr(attr);
      }
   }

   return NULL;
}
struct ast_xml_ns* ast_xml_find_namespace ( struct ast_xml_doc *  doc,
struct ast_xml_node *  node,
const char *  ns_name 
) [read]

Definition at line 261 of file xml.c.

Referenced by pidf_validate_presence().

                                                                                                                   {
   xmlNsPtr ns = xmlSearchNs((xmlDocPtr) doc, (xmlNodePtr) node, (xmlChar *) ns_name);
   return (struct ast_xml_ns *) ns;
}
int ast_xml_finish ( void  )

Cleanup library allocated global data.

Return values:
0On success.
1On error.

Definition at line 48 of file xml.c.

Referenced by xmldoc_unload_documentation().

{
   xmlCleanupParser();

   return 0;
}
void ast_xml_free_node ( struct ast_xml_node *  node)

Free node.

Parameters:
nodeNode to be released.

Definition at line 166 of file xml.c.

{
   if (!node) {
      return;
   }

   xmlFreeNode((xmlNode *) node);
   node = NULL;
}
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 183 of file xml.c.

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

{
   if (text) {
      xmlFree((char *) text);
   }
}
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
Theattribute value on success.

Definition at line 190 of file xml.c.

Referenced by _ast_xmldoc_build_seealso(), ast_xml_find_element(), ast_xmldoc_build_documentation(), pidf_validate_presence(), pidf_validate_tuple(), xmldoc_attribute_match(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), xmldoc_parse_argument(), xmldoc_parse_enumlist(), xmldoc_parse_info(), xmldoc_parse_optionlist(), xmldoc_parse_parameter(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().

{
   xmlChar *attrvalue;

   if (!node) {
      return NULL;
   }

   if (!attrname) {
      return NULL;
   }

   attrvalue = xmlGetProp((xmlNode *) node, (xmlChar *) attrname);

   return (const char *) attrvalue;
}
struct ast_xml_doc* ast_xml_get_doc ( struct ast_xml_node *  node) [read]

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

{
   if (!node) {
      return NULL;
   }

   return (struct ast_xml_doc *) ((xmlNode *)node)->doc;
}
const char* ast_xml_get_ns_href ( struct ast_xml_ns *  ns)

Definition at line 266 of file xml.c.

Referenced by pidf_validate_presence().

{
   return (const char *) ((xmlNsPtr) ns)->href;
}
struct ast_xml_node* ast_xml_get_root ( struct ast_xml_doc *  doc) [read]

Get the document root node.

Parameters:
docDocument reference
Return values:
NULLon error
Theroot node on success.

Definition at line 153 of file xml.c.

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

{
   xmlNode *root_node;

   if (!doc) {
      return NULL;
   }

   root_node = xmlDocGetRootElement((xmlDoc *) doc);

   return (struct ast_xml_node *) root_node;
}
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.
Thetext content of node.

Definition at line 271 of file xml.c.

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

{
   if (!node) {
      return NULL;
   }

   return (const char *) xmlNodeGetContent((xmlNode *) node);
}
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 41 of file xml.c.

Referenced by ast_xmldoc_load_documentation().

{
   LIBXML_TEST_VERSION

   return 0;
}
struct ast_xml_doc* ast_xml_new ( void  ) [read]

Create a XML document.

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

Definition at line 75 of file xml.c.

Referenced by ast_data_get_xml().

{
   xmlDoc *doc;

   doc = xmlNewDoc((const xmlChar *) "1.0");
   return (struct ast_xml_doc *) doc;
}
struct ast_xml_node* ast_xml_new_child ( struct ast_xml_node *  parent,
const char *  child_name 
) [read]

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

{
   xmlNode *child;

   if (!parent || !child_name) {
      return NULL;
   }

   child = xmlNewChild((xmlNode *) parent, NULL, (const xmlChar *) child_name, NULL);
   return (struct ast_xml_node *) child;
}
struct ast_xml_node* ast_xml_new_node ( const char *  name) [read]

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

Referenced by ast_data_get_xml(), and data_get_xml_add_child().

{
   xmlNode *node;
   if (!name) {
      return NULL;
   }

   node = xmlNewNode(NULL, (const xmlChar *) name);

   return (struct ast_xml_node *) node;
}
struct ast_xml_node* ast_xml_node_get_parent ( struct ast_xml_node *  node) [read]

Get the parent of a specified node.

Definition at line 314 of file xml.c.

{
   return (struct ast_xml_node *) ((xmlNode *) node)->parent;
}
struct ast_xml_node* ast_xml_node_get_prev ( struct ast_xml_node *  node) [read]

Get the previous node in the same leve.

Definition at line 309 of file xml.c.

{
   return (struct ast_xml_node *) ((xmlNode *) node)->prev;
}
struct ast_xml_doc* ast_xml_open ( char *  filename) [read]

Open an XML document.

Parameters:
filenameDocument path.
Return values:
NULLon error.
Theast_xml_doc reference to the open document.

Definition at line 55 of file xml.c.

Referenced by ast_xmldoc_load_documentation().

{
   xmlDoc *doc;

   if (!filename) {
      return NULL;
   }

   doc = xmlReadFile(filename, NULL, XML_PARSE_RECOVER);
   if (doc) {
      /* process xinclude elements. */
      if (xmlXIncludeProcess(doc) < 0) {
         xmlFreeDoc(doc);
         return NULL;
      }
   }

   return (struct ast_xml_doc *) doc;
}
struct ast_xml_doc* ast_xml_read_memory ( char *  buffer,
size_t  size 
) [read]

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.
Theast_xml_doc reference to the open document.

Definition at line 115 of file xml.c.

Referenced by sip_pidf_validate().

{
   xmlDoc *doc;

   if (!buffer) {
      return NULL;
   }

   if (!(doc = xmlParseMemory(buffer, (int) size))) {
      /* process xinclude elements. */
      if (xmlXIncludeProcess(doc) < 0) {
         xmlFreeDoc(doc);
         return NULL;
      }
   }

   return (struct ast_xml_doc *) doc;
}
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 207 of file xml.c.

{
   if (!name || !value) {
      return -1;
   }

   if (!xmlSetProp((xmlNode *) node, (xmlChar *) name, (xmlChar *) value)) {
      return -1;
   }

   return 0;
}
void ast_xml_set_root ( struct ast_xml_doc *  doc,
struct ast_xml_node *  node 
)

Specify the root node of a XML document.

Parameters:
docThe document pointer.
nodeA pointer to the node we want to set as root node.

Definition at line 144 of file xml.c.

Referenced by ast_data_get_xml().

{
   if (!doc || !node) {
      return;
   }

   xmlDocSetRootElement((xmlDoc *) doc, (xmlNode *) node);
}
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 280 of file xml.c.

Referenced by data_get_xml_add_child().

{
   if (!node || !content) {
      return;
   }

   xmlNodeSetContent((xmlNode *) node, (const xmlChar *) content);
}