Wed, 27 Jun 2007 03:39:19 +0000
- Add purple_certificate_get_subject_name and associated libpurple
machinery
| 7131 | 1 | /** |
| 2 | * @file xmlnode.h XML DOM functions | |
| 10327 | 3 | * @ingroup core |
| 7131 | 4 | * |
| 15884 | 5 | * purple |
| 7131 | 6 | * |
| 15884 | 7 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 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 | */ | |
| 15884 | 25 | #ifndef _PURPLE_XMLNODE_H_ |
| 26 | #define _PURPLE_XMLNODE_H_ | |
| 7131 | 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 | /** | |
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
127 | * Gets (escaped) data from a node. |
| 10327 | 128 | * |
| 129 | * @param node The node to get data from. | |
| 130 | * | |
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
131 | * @return The data from the node. This data is in raw escaped format. |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
132 | * 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
|
133 | */ |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
134 | 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
|
135 | |
|
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 | * 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
|
138 | * |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
139 | * @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
|
140 | * |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
141 | * @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
|
142 | * this string when finished using it. |
| 10327 | 143 | */ |
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
15884
diff
changeset
|
144 | char *xmlnode_get_data_unescaped(xmlnode *node); |
| 10327 | 145 | |
| 146 | /** | |
| 147 | * Sets an attribute for a node. | |
| 148 | * | |
| 149 | * @param node The node to set an attribute for. | |
| 150 | * @param attr The name of the attribute. | |
| 151 | * @param value The value of the attribute. | |
| 152 | */ | |
| 7131 | 153 | void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); |
| 10327 | 154 | |
| 155 | /** | |
| 15265 | 156 | * Sets a namespaced attribute for a node |
| 157 | * | |
| 158 | * @param node The node to set an attribute for. | |
| 159 | * @param attr The name of the attribute to set | |
| 160 | * @param xmlns The namespace of the attribute to ste | |
| 161 | * @param value The value of the attribute | |
| 162 | */ | |
| 163 | void xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value); | |
| 164 | ||
| 165 | /** | |
| 10327 | 166 | * Gets an attribute from a node. |
| 167 | * | |
| 168 | * @param node The node to get an attribute from. | |
| 169 | * @param attr The attribute to get. | |
| 170 | * | |
| 171 | * @return The value of the attribute. | |
| 172 | */ | |
| 7131 | 173 | const char *xmlnode_get_attrib(xmlnode *node, const char *attr); |
| 10327 | 174 | |
| 175 | /** | |
| 15265 | 176 | * Gets a namespaced attribute from a node |
| 177 | * | |
| 178 | * @param node The node to get an attribute from. | |
| 179 | * @param attr The attribute to get | |
| 180 | * @param xmlns The namespace of the attribute to get | |
| 181 | * | |
| 182 | * @return The value of the attribute/ | |
| 183 | */ | |
| 184 | const char *xmlnode_get_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns); | |
| 185 | ||
| 186 | /** | |
| 10327 | 187 | * Removes an attribute from a node. |
| 188 | * | |
| 189 | * @param node The node to remove an attribute from. | |
| 190 | * @param attr The attribute to remove. | |
| 191 | */ | |
| 7131 | 192 | void xmlnode_remove_attrib(xmlnode *node, const char *attr); |
| 10327 | 193 | |
| 194 | /** | |
| 15265 | 195 | * Removes a namespaced attribute from a node |
| 196 | * | |
| 197 | * @param node The node to remove an attribute from | |
| 198 | * @param attr The attribute to remove | |
| 199 | * @param xmlns The namespace of the attribute to remove | |
| 200 | */ | |
| 201 | void xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns); | |
| 202 | ||
| 203 | /** | |
| 13808 | 204 | * Sets the namespace of a node |
| 205 | * | |
| 206 | * @param node The node to qualify | |
| 207 | * @param xmlns The namespace of the node | |
| 208 | */ | |
| 209 | void xmlnode_set_namespace(xmlnode *node, const char *xmlns); | |
| 210 | ||
| 211 | /** | |
| 212 | * Returns the namespace of a node | |
| 213 | * | |
| 214 | * @param node The node to get the namepsace from | |
| 215 | * @return The namespace of this node | |
| 216 | */ | |
| 217 | const char *xmlnode_get_namespace(xmlnode *node); | |
| 218 | ||
| 219 | /** | |
| 10327 | 220 | * Returns the node in a string of xml. |
| 221 | * | |
| 222 | * @param node The starting node to output. | |
| 223 | * @param len Address for the size of the string. | |
| 224 | * | |
|
12887
4235bbee17b1
[gaim-migrate @ 15240]
Daniel Atallah <datallah@pidgin.im>
parents:
12233
diff
changeset
|
225 | * @return The node represented as a string. You must |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
226 | * g_free this string when finished using it. |
| 10327 | 227 | */ |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
228 | char *xmlnode_to_str(xmlnode *node, int *len); |
| 10327 | 229 | |
| 230 | /** | |
| 231 | * Returns the node in a string of human readable xml. | |
| 232 | * | |
| 233 | * @param node The starting node to output. | |
| 234 | * @param len Address for the size of the string. | |
| 235 | * | |
| 236 | * @return The node as human readable string including | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
237 | * tab and new line characters. You must |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10337
diff
changeset
|
238 | * g_free this string when finished using it. |
| 10327 | 239 | */ |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
240 | char *xmlnode_to_formatted_str(xmlnode *node, int *len); |
| 10327 | 241 | |
| 242 | /** | |
|
10337
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
243 | * 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
|
244 | * root node of an XML document will parse the entire document |
|
778231f38df6
[gaim-migrate @ 11545]
Mark Doliner <markdoliner@pidgin.im>
parents:
10327
diff
changeset
|
245 | * into a tree of nodes, and return the xmlnode of the root. |
| 10327 | 246 | * |
| 247 | * @param str The string of xml. | |
|
11707
a2c8dd795e3b
[gaim-migrate @ 13998]
Richard Laager <rlaager@pidgin.im>
parents:
10848
diff
changeset
|
248 | * @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
|
249 | * NUL-terminated. |
| 10327 | 250 | * |
| 251 | * @return The new node. | |
| 252 | */ | |
| 10848 | 253 | xmlnode *xmlnode_from_str(const char *str, gssize size); |
| 10327 | 254 | |
| 255 | /** | |
| 256 | * Creates a new node from the source node. | |
| 257 | * | |
| 258 | * @param src The node to copy. | |
| 259 | * | |
| 260 | * @return A new copy of the src node. | |
| 261 | */ | |
|
15609
e432251bd57e
sf patch #1647731, from Markus Elfring
Mark Doliner <markdoliner@pidgin.im>
parents:
15435
diff
changeset
|
262 | xmlnode *xmlnode_copy(const xmlnode *src); |
| 7131 | 263 | |
| 10327 | 264 | /** |
| 265 | * Frees a node and all of it's children. | |
| 266 | * | |
| 267 | * @param node The node to free. | |
| 268 | */ | |
| 7131 | 269 | void xmlnode_free(xmlnode *node); |
| 270 | ||
|
14988
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
271 | #ifdef __cplusplus |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
272 | } |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
273 | #endif |
|
66b34458d49e
[gaim-migrate @ 17698]
Richard Laager <rlaager@pidgin.im>
parents:
14498
diff
changeset
|
274 | |
| 15884 | 275 | #endif /* _PURPLE_XMLNODE_H_ */ |