Mon, 01 Oct 2007 16:38:36 +0000
fixes #3090
committer: Luke Schierer <lschiere@pidgin.im>
| 7131 | 1 | /** |
| 2 | * @file xmlnode.h XML DOM functions | |
| 10327 | 3 | * @ingroup core |
|
20330
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19897
diff
changeset
|
4 | */ |
|
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19897
diff
changeset
|
5 | |
|
650a7af9c238
remove gpl boilerplate from doxygen docs
Sean Egan <seanegan@pidgin.im>
parents:
19897
diff
changeset
|
6 | /* purple |
| 7131 | 7 | * |
| 15884 | 8 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 9 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 10 | * source distribution. | |
| 7131 | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify | |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation; either version 2 of the License, or | |
| 15 | * (at your option) any later version. | |
| 16 | * | |
| 17 | * This program is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18131
diff
changeset
|
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7131 | 25 | */ |
| 15884 | 26 | #ifndef _PURPLE_XMLNODE_H_ |
| 27 | #define _PURPLE_XMLNODE_H_ | |
| 7131 | 28 | |
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
29 | #ifdef __cplusplus |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
30 | extern "C" { |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
31 | #endif |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
32 | |
| 10327 | 33 | /** |
| 34 | * The valid types for an xmlnode | |
| 35 | */ | |
| 8135 | 36 | typedef enum _XMLNodeType |
| 7131 | 37 | { |
| 10327 | 38 | XMLNODE_TYPE_TAG, /**< Just a tag */ |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
39 | XMLNODE_TYPE_ATTRIB, /**< Has attributes */ |
| 10327 | 40 | XMLNODE_TYPE_DATA /**< Has data */ |
| 8135 | 41 | } XMLNodeType; |
| 7131 | 42 | |
| 10327 | 43 | /** |
| 44 | * An xmlnode. | |
| 45 | */ | |
| 14386 | 46 | typedef struct _xmlnode xmlnode; |
| 47 | struct _xmlnode | |
| 7131 | 48 | { |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
49 | char *name; /**< The name of the node. */ |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
14988
diff
changeset
|
50 | char *xmlns; /**< The namespace of the node */ |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
51 | XMLNodeType type; /**< The type of the node. */ |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
52 | char *data; /**< The data for the node. */ |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
53 | size_t data_sz; /**< The size of the data. */ |
| 10327 | 54 | struct _xmlnode *parent; /**< The parent node or @c NULL.*/ |
| 55 | struct _xmlnode *child; /**< The child node or @c NULL.*/ | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
11707
diff
changeset
|
56 | struct _xmlnode *lastchild; /**< The last child node or @c NULL.*/ |
| 10327 | 57 | struct _xmlnode *next; /**< The next node or @c NULL. */ |
| 14386 | 58 | }; |
| 7131 | 59 | |
| 10327 | 60 | /** |
| 61 | * Creates a new xmlnode. | |
| 62 | * | |
| 63 | * @param name The name of the node. | |
| 64 | * | |
| 65 | * @return The new node. | |
| 66 | */ | |
| 7131 | 67 | xmlnode *xmlnode_new(const char *name); |
| 10327 | 68 | |
| 69 | /** | |
| 70 | * Creates a new xmlnode child. | |
| 71 | * | |
| 72 | * @param parent The parent node. | |
| 73 | * @param name The name of the child node. | |
| 74 | * | |
| 75 | * @return The new child node. | |
| 76 | */ | |
| 7131 | 77 | xmlnode *xmlnode_new_child(xmlnode *parent, const char *name); |
| 10327 | 78 | |
| 79 | /** | |
| 80 | * Inserts a node into a node as a child. | |
| 81 | * | |
| 82 | * @param parent The parent node to insert child into. | |
| 83 | * @param child The child node to insert into parent. | |
| 84 | */ | |
| 7131 | 85 | void xmlnode_insert_child(xmlnode *parent, xmlnode *child); |
| 10327 | 86 | |
| 87 | /** | |
| 88 | * Gets a child node named name. | |
| 89 | * | |
| 90 | * @param parent The parent node. | |
| 91 | * @param name The child's name. | |
| 92 | * | |
| 93 | * @return The child or NULL. | |
| 94 | */ | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
95 | xmlnode *xmlnode_get_child(const xmlnode *parent, const char *name); |
| 10327 | 96 | |
| 97 | /** | |
| 98 | * Gets a child node named name in a namespace. | |
| 99 | * | |
| 100 | * @param parent The parent node. | |
| 101 | * @param name The child's name. | |
| 102 | * @param xmlns The namespace. | |
| 103 | * | |
| 104 | * @return The child or NULL. | |
| 105 | */ | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
106 | xmlnode *xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *xmlns); |
| 10327 | 107 | |
| 108 | /** | |
| 109 | * Gets the next node with the same name as node. | |
| 110 | * | |
| 111 | * @param node The node of a twin to find. | |
| 112 | * | |
| 113 | * @return The twin of node or NULL. | |
| 114 | */ | |
| 8135 | 115 | xmlnode *xmlnode_get_next_twin(xmlnode *node); |
| 10327 | 116 | |
| 117 | /** | |
| 118 | * Inserts data into a node. | |
| 119 | * | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
120 | * @param node The node to insert data into. |
| 10327 | 121 | * @param data The data to insert. |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
122 | * @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
|
123 | * null-terminated you can pass in -1. |
| 10327 | 124 | */ |
| 10848 | 125 | void xmlnode_insert_data(xmlnode *node, const char *data, gssize size); |
| 10327 | 126 | |
| 127 | /** | |
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
128 | * Gets (escaped) data from a node. |
| 10327 | 129 | * |
| 130 | * @param node The node to get data from. | |
| 131 | * | |
|
20546
35d778ab0450
Correctly process an additional <Service> with type Profile and name 'Messenger Roaming Identity' sent with the contact list using a recently registered WLM account, that was causing the initial ADL command to be sent malformed, and our presence status not being forwarded to our buddies
Carlos Silva <typ0@pidgin.im>
parents:
18131
diff
changeset
|
132 | * @return The data from the node or NULL. This data is in raw escaped format. |
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
133 | * You must g_free this string when finished using it. |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
134 | */ |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
135 | char *xmlnode_get_data(xmlnode *node); |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
136 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
137 | /** |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
138 | * Gets unescaped data from a node. |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
139 | * |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
140 | * @param node The node to get data from. |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
141 | * |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
142 | * @return The data from the node, in unescaped form. You must g_free |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
143 | * this string when finished using it. |
| 10327 | 144 | */ |
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
145 | char *xmlnode_get_data_unescaped(xmlnode *node); |
| 10327 | 146 | |
| 147 | /** | |
| 148 | * Sets an attribute for a node. | |
| 149 | * | |
| 150 | * @param node The node to set an attribute for. | |
| 151 | * @param attr The name of the attribute. | |
| 152 | * @param value The value of the attribute. | |
| 153 | */ | |
| 7131 | 154 | void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); |
| 10327 | 155 | |
| 156 | /** | |
| 15265 | 157 | * Sets a namespaced attribute for a node |
| 158 | * | |
| 159 | * @param node The node to set an attribute for. | |
| 160 | * @param attr The name of the attribute to set | |
| 161 | * @param xmlns The namespace of the attribute to ste | |
| 162 | * @param value The value of the attribute | |
| 163 | */ | |
| 164 | void xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value); | |
| 165 | ||
| 166 | /** | |
| 10327 | 167 | * Gets an attribute from a node. |
| 168 | * | |
| 169 | * @param node The node to get an attribute from. | |
| 170 | * @param attr The attribute to get. | |
| 171 | * | |
| 172 | * @return The value of the attribute. | |
| 173 | */ | |
| 7131 | 174 | const char *xmlnode_get_attrib(xmlnode *node, const char *attr); |
| 10327 | 175 | |
| 176 | /** | |
| 15265 | 177 | * Gets a namespaced attribute from a node |
| 178 | * | |
| 179 | * @param node The node to get an attribute from. | |
| 180 | * @param attr The attribute to get | |
| 181 | * @param xmlns The namespace of the attribute to get | |
| 182 | * | |
| 183 | * @return The value of the attribute/ | |
| 184 | */ | |
| 185 | const char *xmlnode_get_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns); | |
| 186 | ||
| 187 | /** | |
| 10327 | 188 | * Removes an attribute from a node. |
| 189 | * | |
| 190 | * @param node The node to remove an attribute from. | |
| 191 | * @param attr The attribute to remove. | |
| 192 | */ | |
| 7131 | 193 | void xmlnode_remove_attrib(xmlnode *node, const char *attr); |
| 10327 | 194 | |
| 195 | /** | |
| 15265 | 196 | * Removes a namespaced attribute from a node |
| 197 | * | |
| 198 | * @param node The node to remove an attribute from | |
| 199 | * @param attr The attribute to remove | |
| 200 | * @param xmlns The namespace of the attribute to remove | |
| 201 | */ | |
| 202 | void xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns); | |
| 203 | ||
| 204 | /** | |
| 13808 | 205 | * Sets the namespace of a node |
| 206 | * | |
| 207 | * @param node The node to qualify | |
| 208 | * @param xmlns The namespace of the node | |
| 209 | */ | |
| 210 | void xmlnode_set_namespace(xmlnode *node, const char *xmlns); | |
| 211 | ||
| 212 | /** | |
| 213 | * Returns the namespace of a node | |
| 214 | * | |
| 215 | * @param node The node to get the namepsace from | |
| 216 | * @return The namespace of this node | |
| 217 | */ | |
| 218 | const char *xmlnode_get_namespace(xmlnode *node); | |
| 219 | ||
| 220 | /** | |
| 10327 | 221 | * Returns the node in a string of xml. |
| 222 | * | |
| 223 | * @param node The starting node to output. | |
| 224 | * @param len Address for the size of the string. | |
| 225 | * | |
|
12887
4235bbee17b1
[gaim-migrate @ 15240]
Daniel Atallah <datallah@pidgin.im>
parents:
12233
diff
changeset
|
226 | * @return The node represented as a string. You must |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
227 | * g_free this string when finished using it. |
| 10327 | 228 | */ |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
229 | char *xmlnode_to_str(xmlnode *node, int *len); |
| 10327 | 230 | |
| 231 | /** | |
| 232 | * Returns the node in a string of human readable xml. | |
| 233 | * | |
| 234 | * @param node The starting node to output. | |
| 235 | * @param len Address for the size of the string. | |
| 236 | * | |
| 237 | * @return The node as human readable string including | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
238 | * tab and new line characters. You must |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
239 | * g_free this string when finished using it. |
| 10327 | 240 | */ |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
241 | char *xmlnode_to_formatted_str(xmlnode *node, int *len); |
| 10327 | 242 | |
| 243 | /** | |
|
10337
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
244 | * 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
|
245 | * root node of an XML document will parse the entire document |
|
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
246 | * into a tree of nodes, and return the xmlnode of the root. |
| 10327 | 247 | * |
| 248 | * @param str The string of xml. | |
|
11707
a2c8dd795e3b
[gaim-migrate @ 13998]
Richard Laager <rlaager@pidgin.im>
parents:
10848
diff
changeset
|
249 | * @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
|
250 | * NUL-terminated. |
| 10327 | 251 | * |
| 252 | * @return The new node. | |
| 253 | */ | |
| 10848 | 254 | xmlnode *xmlnode_from_str(const char *str, gssize size); |
| 10327 | 255 | |
| 256 | /** | |
| 257 | * Creates a new node from the source node. | |
| 258 | * | |
| 259 | * @param src The node to copy. | |
| 260 | * | |
| 261 | * @return A new copy of the src node. | |
| 262 | */ | |
|
15609
e432251bd57e
sf patch #1647731, from Markus Elfring
Mark Doliner <markdoliner@pidgin.im>
parents:
15435
diff
changeset
|
263 | xmlnode *xmlnode_copy(const xmlnode *src); |
| 7131 | 264 | |
| 10327 | 265 | /** |
|
17775
1df27cab581c
implemented user mood, still missing the front end interface
Andreas Monitzer <am@adiumx.com>
parents:
15884
diff
changeset
|
266 | * Frees a node and all of its children. |
| 10327 | 267 | * |
| 268 | * @param node The node to free. | |
| 269 | */ | |
| 7131 | 270 | void xmlnode_free(xmlnode *node); |
| 271 | ||
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
272 | #ifdef __cplusplus |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
273 | } |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
274 | #endif |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
275 | |
| 15884 | 276 | #endif /* _PURPLE_XMLNODE_H_ */ |