summaryrefslogtreecommitdiff
path: root/include/asterisk/xml.h
blob: 2c30986ccb93612954cd9abaea9b91bf8ed0d596 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Asterisk -- An open source telephony toolkit.
 *
 * Copyright (C) 2008, Eliel C. Sardanons (LU1ALY) <eliels@gmail.com>
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

#ifndef _ASTERISK_XML_H
#define _ASTERISK_XML_H

/*! \file
 *  \brief Asterisk XML abstraction layer
 */

struct ast_xml_node;
struct ast_xml_doc;

/*! \brief Initialize the XML library implementation.
 *         This function is used to setup everything needed
 *         to start working with the xml implementation.
 *  \retval 0 On success.
 *  \retval 1 On error.
 */
int ast_xml_init(void);

/*! \brief Cleanup library allocated global data.
 *  \retval 0 On success.
 *  \retval 1 On error.
 */
int ast_xml_finish(void);

/*! \brief Open an XML document.
 *  \param filename Document path.
 *  \retval NULL on error.
 *  \retval The ast_xml_doc reference to the open document.
 */
struct ast_xml_doc *ast_xml_open(char *filename);

/*! \brief Open an XML document that resides in memory.
 * \param buffer The address where the document is stored
 * \size The number of bytes in the document
 * \retval NULL on error.
 * \retval The ast_xml_doc reference to the open document.
 */
struct ast_xml_doc *ast_xml_read_memory(char *buffer, size_t size);

/*! \brief Close an already open document and free the used
 *        structure.
 *  \retval doc The document reference.
 */
void ast_xml_close(struct ast_xml_doc *doc);

/*! \brief Get the document root node.
 *  \param doc Document reference
 *  \retval NULL on error
 *  \retval The root node on success.
 */
struct ast_xml_node *ast_xml_get_root(struct ast_xml_doc *doc);

/*! \brief Free node
 *  \param node Node to be released.
 */
void ast_xml_free_node(struct ast_xml_node *node);

/*! \brief Free an attribute returned by ast_xml_get_attribute()
 *  \param data pointer to be freed.
 */
void ast_xml_free_attr(const char *attribute);

/*! \brief Free a content element that was returned by ast_xml_get_text()
 *  \param text text to be freed.
 */
void ast_xml_free_text(const char *text);

/*! \brief Get a node attribute by name
 *  \param node Node where to search the attribute.
 *  \param attrname Attribute name.
 *  \retval NULL on error
 *  \retval The attribute value on success.
 */
const char *ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname);

/*! \brief Find a node element by name.
 *  \param node This is the node starting point.
 *  \param name Node name to find.
 *  \param attrname attribute name to match (if NULL it won't be matched).
 *  \param attrvalue attribute value to match (if NULL it won't be matched).
 *  \retval NULL if not found
 *  \retval The node on success.
 */
struct ast_xml_node *ast_xml_find_element(struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue);
struct ast_xml_ns *ast_xml_find_namespace(struct ast_xml_doc *doc, struct ast_xml_node *node, const char *ns_name);
const char *ast_xml_get_ns_href(struct ast_xml_ns *ns);

/*! \brief Get an element content string.
 *  \param node Node from where to get the string.
 *  \retval NULL on error.
 *  \retval The text content of node.
 */
const char *ast_xml_get_text(struct ast_xml_node *node);

/*! \brief Get the name of a node. */
const char *ast_xml_node_get_name(struct ast_xml_node *node);

/*! \brief Get the node's children. */
struct ast_xml_node *ast_xml_node_get_children(struct ast_xml_node *node);

/*! \brief Get the next node in the same level. */
struct ast_xml_node *ast_xml_node_get_next(struct ast_xml_node *node);

/*! \brief Get the previous node in the same leve. */
struct ast_xml_node *ast_xml_node_get_prev(struct ast_xml_node *node);

/*! \brief Get the parent of a specified node. */
struct ast_xml_node *ast_xml_node_get_parent(struct ast_xml_node *node);

/* Features using ast_xml_ */
#ifdef HAVE_LIBXML2
#define AST_XML_DOCS
#endif

#endif /* _ASTERISK_XML_H */