Sun, 15 Apr 2007 02:10:37 +0000
propagate from branch 'im.pidgin.gaim' (head b2836a24d81e7a1bd1d21b3aea8794b094391344)
to branch 'im.pidgin.rlaager.merging.soc-msnp13-to-svn18164' (head 463b4fa9f067b279f843520d95a822adc86a0a1b)
| 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 | ||
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
28 | #ifdef __cplusplus |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
29 | extern "C" { |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
30 | #endif |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
31 | |
| 10327 | 32 | /** |
| 33 | * The valid types for an xmlnode | |
| 34 | */ | |
| 8135 | 35 | typedef enum _XMLNodeType |
| 7131 | 36 | { |
| 10327 | 37 | XMLNODE_TYPE_TAG, /**< Just a tag */ |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
38 | XMLNODE_TYPE_ATTRIB, /**< Has attributes */ |
| 10327 | 39 | XMLNODE_TYPE_DATA /**< Has data */ |
| 8135 | 40 | } XMLNodeType; |
| 7131 | 41 | |
| 10327 | 42 | /** |
| 43 | * An xmlnode. | |
| 44 | */ | |
| 14386 | 45 | typedef struct _xmlnode xmlnode; |
| 46 | struct _xmlnode | |
| 7131 | 47 | { |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
48 | char *name; /**< The name of the node. */ |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
14988
diff
changeset
|
49 | char *xmlns; /**< The namespace of the node */ |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
50 | XMLNodeType type; /**< The type of the node. */ |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
51 | char *data; /**< The data for the node. */ |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
52 | size_t data_sz; /**< The size of the data. */ |
| 10327 | 53 | struct _xmlnode *parent; /**< The parent node or @c NULL.*/ |
| 54 | struct _xmlnode *child; /**< The child node or @c NULL.*/ | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
11707
diff
changeset
|
55 | struct _xmlnode *lastchild; /**< The last child node or @c NULL.*/ |
| 10327 | 56 | struct _xmlnode *next; /**< The next node or @c NULL. */ |
| 14386 | 57 | }; |
| 7131 | 58 | |
| 10327 | 59 | /** |
| 60 | * Creates a new xmlnode. | |
| 61 | * | |
| 62 | * @param name The name of the node. | |
| 63 | * | |
| 64 | * @return The new node. | |
| 65 | */ | |
| 7131 | 66 | xmlnode *xmlnode_new(const char *name); |
| 10327 | 67 | |
| 68 | /** | |
| 69 | * Creates a new xmlnode child. | |
| 70 | * | |
| 71 | * @param parent The parent node. | |
| 72 | * @param name The name of the child node. | |
| 73 | * | |
| 74 | * @return The new child node. | |
| 75 | */ | |
| 7131 | 76 | xmlnode *xmlnode_new_child(xmlnode *parent, const char *name); |
| 10327 | 77 | |
| 78 | /** | |
| 79 | * Inserts a node into a node as a child. | |
| 80 | * | |
| 81 | * @param parent The parent node to insert child into. | |
| 82 | * @param child The child node to insert into parent. | |
| 83 | */ | |
| 7131 | 84 | void xmlnode_insert_child(xmlnode *parent, xmlnode *child); |
| 10327 | 85 | |
| 86 | /** | |
| 87 | * Gets a child node named name. | |
| 88 | * | |
| 89 | * @param parent The parent node. | |
| 90 | * @param name The child's name. | |
| 91 | * | |
| 92 | * @return The child or NULL. | |
| 93 | */ | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
94 | xmlnode *xmlnode_get_child(const xmlnode *parent, const char *name); |
| 10327 | 95 | |
| 96 | /** | |
| 97 | * Gets a child node named name in a namespace. | |
| 98 | * | |
| 99 | * @param parent The parent node. | |
| 100 | * @param name The child's name. | |
| 101 | * @param xmlns The namespace. | |
| 102 | * | |
| 103 | * @return The child or NULL. | |
| 104 | */ | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
105 | xmlnode *xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *xmlns); |
| 10327 | 106 | |
| 107 | /** | |
| 108 | * Gets the next node with the same name as node. | |
| 109 | * | |
| 110 | * @param node The node of a twin to find. | |
| 111 | * | |
| 112 | * @return The twin of node or NULL. | |
| 113 | */ | |
| 8135 | 114 | xmlnode *xmlnode_get_next_twin(xmlnode *node); |
| 10327 | 115 | |
| 116 | /** | |
| 117 | * Inserts data into a node. | |
| 118 | * | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
119 | * @param node The node to insert data into. |
| 10327 | 120 | * @param data The data to insert. |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
121 | * @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
|
122 | * null-terminated you can pass in -1. |
| 10327 | 123 | */ |
| 10848 | 124 | void xmlnode_insert_data(xmlnode *node, const char *data, gssize size); |
| 10327 | 125 | |
| 126 | /** | |
| 127 | * Gets data from a node. | |
| 128 | * | |
| 129 | * @param node The node to get data from. | |
| 130 | * | |
|
14162
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
131 | * @return The data from the node. You must g_free |
|
3546040af8e2
[gaim-migrate @ 16730]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
132 | * this string when finished using it. |
| 10327 | 133 | */ |
| 7131 | 134 | char *xmlnode_get_data(xmlnode *node); |
| 10327 | 135 | |
| 136 | /** | |
| 137 | * Sets an attribute for a node. | |
| 138 | * | |
| 139 | * @param node The node to set an attribute for. | |
| 140 | * @param attr The name of the attribute. | |
| 141 | * @param value The value of the attribute. | |
| 142 | */ | |
| 7131 | 143 | void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); |
| 10327 | 144 | |
| 145 | /** | |
| 15265 | 146 | * Sets a namespaced attribute for a node |
| 147 | * | |
| 148 | * @param node The node to set an attribute for. | |
| 149 | * @param attr The name of the attribute to set | |
| 150 | * @param xmlns The namespace of the attribute to ste | |
| 151 | * @param value The value of the attribute | |
| 152 | */ | |
| 153 | void xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value); | |
| 154 | ||
| 155 | /** | |
| 10327 | 156 | * Gets an attribute from a node. |
| 157 | * | |
| 158 | * @param node The node to get an attribute from. | |
| 159 | * @param attr The attribute to get. | |
| 160 | * | |
| 161 | * @return The value of the attribute. | |
| 162 | */ | |
| 7131 | 163 | const char *xmlnode_get_attrib(xmlnode *node, const char *attr); |
| 10327 | 164 | |
| 165 | /** | |
| 15265 | 166 | * Gets a namespaced attribute from a node |
| 167 | * | |
| 168 | * @param node The node to get an attribute from. | |
| 169 | * @param attr The attribute to get | |
| 170 | * @param xmlns The namespace of the attribute to get | |
| 171 | * | |
| 172 | * @return The value of the attribute/ | |
| 173 | */ | |
| 174 | const char *xmlnode_get_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns); | |
| 175 | ||
| 176 | /** | |
| 10327 | 177 | * Removes an attribute from a node. |
| 178 | * | |
| 179 | * @param node The node to remove an attribute from. | |
| 180 | * @param attr The attribute to remove. | |
| 181 | */ | |
| 7131 | 182 | void xmlnode_remove_attrib(xmlnode *node, const char *attr); |
| 10327 | 183 | |
| 184 | /** | |
| 15265 | 185 | * Removes a namespaced attribute from a node |
| 186 | * | |
| 187 | * @param node The node to remove an attribute from | |
| 188 | * @param attr The attribute to remove | |
| 189 | * @param xmlns The namespace of the attribute to remove | |
| 190 | */ | |
| 191 | void xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns); | |
| 192 | ||
| 193 | /** | |
| 13808 | 194 | * Sets the namespace of a node |
| 195 | * | |
| 196 | * @param node The node to qualify | |
| 197 | * @param xmlns The namespace of the node | |
| 198 | */ | |
| 199 | void xmlnode_set_namespace(xmlnode *node, const char *xmlns); | |
| 200 | ||
| 201 | /** | |
| 202 | * Returns the namespace of a node | |
| 203 | * | |
| 204 | * @param node The node to get the namepsace from | |
| 205 | * @return The namespace of this node | |
| 206 | */ | |
| 207 | const char *xmlnode_get_namespace(xmlnode *node); | |
| 208 | ||
| 209 | /** | |
| 10327 | 210 | * Returns the node in a string of xml. |
| 211 | * | |
| 212 | * @param node The starting node to output. | |
| 213 | * @param len Address for the size of the string. | |
| 214 | * | |
|
12887
4235bbee17b1
[gaim-migrate @ 15240]
Daniel Atallah <datallah@pidgin.im>
parents:
12233
diff
changeset
|
215 | * @return The node represented as a string. You must |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
216 | * g_free this string when finished using it. |
| 10327 | 217 | */ |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
218 | char *xmlnode_to_str(xmlnode *node, int *len); |
| 10327 | 219 | |
| 220 | /** | |
| 221 | * Returns the node in a string of human readable xml. | |
| 222 | * | |
| 223 | * @param node The starting node to output. | |
| 224 | * @param len Address for the size of the string. | |
| 225 | * | |
| 226 | * @return The node as human readable string including | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
227 | * tab and new line characters. You must |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
228 | * g_free this string when finished using it. |
| 10327 | 229 | */ |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
230 | char *xmlnode_to_formatted_str(xmlnode *node, int *len); |
| 10327 | 231 | |
| 232 | /** | |
|
10337
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
233 | * 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
|
234 | * root node of an XML document will parse the entire document |
|
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
235 | * into a tree of nodes, and return the xmlnode of the root. |
| 10327 | 236 | * |
| 237 | * @param str The string of xml. | |
|
11707
a2c8dd795e3b
[gaim-migrate @ 13998]
Richard Laager <rlaager@pidgin.im>
parents:
10848
diff
changeset
|
238 | * @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
|
239 | * NUL-terminated. |
| 10327 | 240 | * |
| 241 | * @return The new node. | |
| 242 | */ | |
| 10848 | 243 | xmlnode *xmlnode_from_str(const char *str, gssize size); |
| 10327 | 244 | |
| 245 | /** | |
| 246 | * Creates a new node from the source node. | |
| 247 | * | |
| 248 | * @param src The node to copy. | |
| 249 | * | |
| 250 | * @return A new copy of the src node. | |
| 251 | */ | |
| 8167 | 252 | xmlnode *xmlnode_copy(xmlnode *src); |
| 7131 | 253 | |
| 10327 | 254 | /** |
| 255 | * Frees a node and all of it's children. | |
| 256 | * | |
| 257 | * @param node The node to free. | |
| 258 | */ | |
| 7131 | 259 | void xmlnode_free(xmlnode *node); |
| 260 | ||
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
261 | #ifdef __cplusplus |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
262 | } |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
263 | #endif |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
264 | |
| 7131 | 265 | #endif /* _GAIM_XMLNODE_H_ */ |