Mon, 04 Sep 2006 03:55:12 +0000
[gaim-migrate @ 17150]
libxml2 is now required for XML parsing
| 7131 | 1 | /** |
| 2 | * @file xmlnode.h XML DOM functions | |
| 10327 | 3 | * @ingroup core |
| 7131 | 4 | * |
| 5 | * gaim | |
| 6 | * | |
| 8046 | 7 | * Gaim is the legal property of its developers, whose names are too numerous |
| 8 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 9 | * source distribution. | |
| 7131 | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 24 | */ | |
| 25 | #ifndef _GAIM_XMLNODE_H_ | |
| 26 | #define _GAIM_XMLNODE_H_ | |
| 27 | ||
| 10327 | 28 | /** |
| 29 | * The valid types for an xmlnode | |
| 30 | */ | |
| 8135 | 31 | typedef enum _XMLNodeType |
| 7131 | 32 | { |
| 10327 | 33 | XMLNODE_TYPE_TAG, /**< Just a tag */ |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
34 | XMLNODE_TYPE_ATTRIB, /**< Has attributes */ |
| 10327 | 35 | XMLNODE_TYPE_DATA /**< Has data */ |
| 8135 | 36 | } XMLNodeType; |
| 7131 | 37 | |
| 10327 | 38 | /** |
| 39 | * An xmlnode. | |
| 40 | */ | |
| 14386 | 41 | typedef struct _xmlnode xmlnode; |
| 42 | struct _xmlnode | |
| 7131 | 43 | { |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
44 | char *name; /**< The name of the node. */ |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
45 | char *namespace; /**< The namespace of the node */ |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
46 | XMLNodeType type; /**< The type of the node. */ |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
47 | char *data; /**< The data for the node. */ |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
48 | size_t data_sz; /**< The size of the data. */ |
| 10327 | 49 | struct _xmlnode *parent; /**< The parent node or @c NULL.*/ |
| 50 | struct _xmlnode *child; /**< The child node or @c NULL.*/ | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
11707
diff
changeset
|
51 | struct _xmlnode *lastchild; /**< The last child node or @c NULL.*/ |
| 10327 | 52 | struct _xmlnode *next; /**< The next node or @c NULL. */ |
| 14386 | 53 | }; |
| 7131 | 54 | |
| 10327 | 55 | /** |
| 56 | * Creates a new xmlnode. | |
| 57 | * | |
| 58 | * @param name The name of the node. | |
| 59 | * | |
| 60 | * @return The new node. | |
| 61 | */ | |
| 7131 | 62 | xmlnode *xmlnode_new(const char *name); |
| 10327 | 63 | |
| 64 | /** | |
| 65 | * Creates a new xmlnode child. | |
| 66 | * | |
| 67 | * @param parent The parent node. | |
| 68 | * @param name The name of the child node. | |
| 69 | * | |
| 70 | * @return The new child node. | |
| 71 | */ | |
| 7131 | 72 | xmlnode *xmlnode_new_child(xmlnode *parent, const char *name); |
| 10327 | 73 | |
| 74 | /** | |
| 75 | * Inserts a node into a node as a child. | |
| 76 | * | |
| 77 | * @param parent The parent node to insert child into. | |
| 78 | * @param child The child node to insert into parent. | |
| 79 | */ | |
| 7131 | 80 | void xmlnode_insert_child(xmlnode *parent, xmlnode *child); |
| 10327 | 81 | |
| 82 | /** | |
| 83 | * Gets a child node named name. | |
| 84 | * | |
| 85 | * @param parent The parent node. | |
| 86 | * @param name The child's name. | |
| 87 | * | |
| 88 | * @return The child or NULL. | |
| 89 | */ | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
90 | xmlnode *xmlnode_get_child(const xmlnode *parent, const char *name); |
| 10327 | 91 | |
| 92 | /** | |
| 93 | * Gets a child node named name in a namespace. | |
| 94 | * | |
| 95 | * @param parent The parent node. | |
| 96 | * @param name The child's name. | |
| 97 | * @param xmlns The namespace. | |
| 98 | * | |
| 99 | * @return The child or NULL. | |
| 100 | */ | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
101 | xmlnode *xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *xmlns); |
| 10327 | 102 | |
| 103 | /** | |
| 104 | * Gets the next node with the same name as node. | |
| 105 | * | |
| 106 | * @param node The node of a twin to find. | |
| 107 | * | |
| 108 | * @return The twin of node or NULL. | |
| 109 | */ | |
| 8135 | 110 | xmlnode *xmlnode_get_next_twin(xmlnode *node); |
| 10327 | 111 | |
| 112 | /** | |
| 113 | * Inserts data into a node. | |
| 114 | * | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
115 | * @param node The node to insert data into. |
| 10327 | 116 | * @param data The data to insert. |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
117 | * @param size The size of the data to insert. If data is |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
118 | * null-terminated you can pass in -1. |
| 10327 | 119 | */ |
| 10848 | 120 | void xmlnode_insert_data(xmlnode *node, const char *data, gssize size); |
| 10327 | 121 | |
| 122 | /** | |
| 123 | * Gets data from a node. | |
| 124 | * | |
| 125 | * @param node The node to get data from. | |
| 126 | * | |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
127 | * @return The data from the node. You must g_free |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
128 | * this string when finished using it. |
| 10327 | 129 | */ |
| 7131 | 130 | char *xmlnode_get_data(xmlnode *node); |
| 10327 | 131 | |
| 132 | /** | |
| 133 | * Sets an attribute for a node. | |
| 134 | * | |
| 135 | * @param node The node to set an attribute for. | |
| 136 | * @param attr The name of the attribute. | |
| 137 | * @param value The value of the attribute. | |
| 138 | */ | |
| 7131 | 139 | void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); |
| 10327 | 140 | |
| 141 | /** | |
| 142 | * Gets an attribute from a node. | |
| 143 | * | |
| 144 | * @param node The node to get an attribute from. | |
| 145 | * @param attr The attribute to get. | |
| 146 | * | |
| 147 | * @return The value of the attribute. | |
| 148 | */ | |
| 7131 | 149 | const char *xmlnode_get_attrib(xmlnode *node, const char *attr); |
| 10327 | 150 | |
| 151 | /** | |
| 152 | * Removes an attribute from a node. | |
| 153 | * | |
| 154 | * @param node The node to remove an attribute from. | |
| 155 | * @param attr The attribute to remove. | |
| 156 | */ | |
| 7131 | 157 | void xmlnode_remove_attrib(xmlnode *node, const char *attr); |
| 10327 | 158 | |
| 159 | /** | |
| 13808 | 160 | * Sets the namespace of a node |
| 161 | * | |
| 162 | * @param node The node to qualify | |
| 163 | * @param xmlns The namespace of the node | |
| 164 | */ | |
| 165 | void xmlnode_set_namespace(xmlnode *node, const char *xmlns); | |
| 166 | ||
| 167 | /** | |
| 168 | * Returns the namespace of a node | |
| 169 | * | |
| 170 | * @param node The node to get the namepsace from | |
| 171 | * @return The namespace of this node | |
| 172 | */ | |
| 173 | const char *xmlnode_get_namespace(xmlnode *node); | |
| 174 | ||
| 175 | /** | |
| 10327 | 176 | * Returns the node in a string of xml. |
| 177 | * | |
| 178 | * @param node The starting node to output. | |
| 179 | * @param len Address for the size of the string. | |
| 180 | * | |
|
12887
4235bbee17b1
[gaim-migrate @ 15240]
Daniel Atallah <datallah@pidgin.im>
parents:
12233
diff
changeset
|
181 | * @return The node represented as a string. You must |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
182 | * g_free this string when finished using it. |
| 10327 | 183 | */ |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
184 | char *xmlnode_to_str(xmlnode *node, int *len); |
| 10327 | 185 | |
| 186 | /** | |
| 187 | * Returns the node in a string of human readable xml. | |
| 188 | * | |
| 189 | * @param node The starting node to output. | |
| 190 | * @param len Address for the size of the string. | |
| 191 | * | |
| 192 | * @return The node as human readable string including | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
193 | * tab and new line characters. You must |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
194 | * g_free this string when finished using it. |
| 10327 | 195 | */ |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
196 | char *xmlnode_to_formatted_str(xmlnode *node, int *len); |
| 10327 | 197 | |
| 198 | /** | |
|
10337
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
199 | * Creates a node from a string of XML. Calling this on the |
|
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
200 | * root node of an XML document will parse the entire document |
|
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
201 | * into a tree of nodes, and return the xmlnode of the root. |
| 10327 | 202 | * |
| 203 | * @param str The string of xml. | |
|
11707
a2c8dd795e3b
[gaim-migrate @ 13998]
Richard Laager <rlaager@pidgin.im>
parents:
10848
diff
changeset
|
204 | * @param size The size of the string, or -1 if @a str is |
|
a2c8dd795e3b
[gaim-migrate @ 13998]
Richard Laager <rlaager@pidgin.im>
parents:
10848
diff
changeset
|
205 | * NUL-terminated. |
| 10327 | 206 | * |
| 207 | * @return The new node. | |
| 208 | */ | |
| 10848 | 209 | xmlnode *xmlnode_from_str(const char *str, gssize size); |
| 10327 | 210 | |
| 211 | /** | |
| 212 | * Creates a new node from the source node. | |
| 213 | * | |
| 214 | * @param src The node to copy. | |
| 215 | * | |
| 216 | * @return A new copy of the src node. | |
| 217 | */ | |
| 8167 | 218 | xmlnode *xmlnode_copy(xmlnode *src); |
| 7131 | 219 | |
| 10327 | 220 | /** |
| 221 | * Frees a node and all of it's children. | |
| 222 | * | |
| 223 | * @param node The node to free. | |
| 224 | */ | |
| 7131 | 225 | void xmlnode_free(xmlnode *node); |
| 226 | ||
| 227 | #endif /* _GAIM_XMLNODE_H_ */ |