Mercurial > pidgin
annotate src/xmlnode.h @ 14122:dabbcb9b013d
[gaim-migrate @ 16759]
This initializes threads for glib and dbus, because under some
circumstances multithreaded libraries are causing dbus badness
(namely, gnome-vfs). This fix doesn't really belong in Gaim, but in
the interest of expedience (we don't want to wait for upstream
libraries to get their initializations all worked around to make
things safe) the fix goes here. Note that all Gaim frontends will
have to initialize glib threads if other threaded libraries which
interact with glib or dbus or what-have-you come into play.
committer: Tailor Script <tailor@pidgin.im>
| author | Ethan Blanton <elb@pidgin.im> |
|---|---|
| date | Mon, 14 Aug 2006 21:46:17 +0000 |
| parents | 85144ba7d726 |
| children |
| rev | line source |
|---|---|
| 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 */ |
|
14100
85144ba7d726
[gaim-migrate @ 16730]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13806
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 */ | |
| 7131 | 41 typedef struct _xmlnode |
| 42 { | |
|
14100
85144ba7d726
[gaim-migrate @ 16730]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13806
diff
changeset
|
43 char *name; /**< The name of the node. */ |
| 13806 | 44 #ifdef HAVE_LIBXML |
|
14100
85144ba7d726
[gaim-migrate @ 16730]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13806
diff
changeset
|
45 char *namespace; /**< The namespace of the node */ |
| 13806 | 46 #endif |
|
14100
85144ba7d726
[gaim-migrate @ 16730]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13806
diff
changeset
|
47 XMLNodeType type; /**< The type of the node. */ |
|
85144ba7d726
[gaim-migrate @ 16730]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13806
diff
changeset
|
48 char *data; /**< The data for the node. */ |
|
85144ba7d726
[gaim-migrate @ 16730]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13806
diff
changeset
|
49 size_t data_sz; /**< The size of the data. */ |
| 10327 | 50 struct _xmlnode *parent; /**< The parent node or @c NULL.*/ |
| 51 struct _xmlnode *child; /**< The child node or @c NULL.*/ | |
|
12233
02833a0ae716
[gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents:
11707
diff
changeset
|
52 struct _xmlnode *lastchild; /**< The last child node or @c NULL.*/ |
| 10327 | 53 struct _xmlnode *next; /**< The next node or @c NULL. */ |
| 7131 | 54 } xmlnode; |
| 55 | |
| 10327 | 56 /** |
| 57 * Creates a new xmlnode. | |
| 58 * | |
| 59 * @param name The name of the node. | |
| 60 * | |
| 61 * @return The new node. | |
| 62 */ | |
| 7131 | 63 xmlnode *xmlnode_new(const char *name); |
| 10327 | 64 |
| 65 /** | |
| 66 * Creates a new xmlnode child. | |
| 67 * | |
| 68 * @param parent The parent node. | |
| 69 * @param name The name of the child node. | |
| 70 * | |
| 71 * @return The new child node. | |
| 72 */ | |
| 7131 | 73 xmlnode *xmlnode_new_child(xmlnode *parent, const char *name); |
| 10327 | 74 |
| 75 /** | |
| 76 * Inserts a node into a node as a child. | |
| 77 * | |
| 78 * @param parent The parent node to insert child into. | |
| 79 * @param child The child node to insert into parent. | |
| 80 */ | |
| 7131 | 81 void xmlnode_insert_child(xmlnode *parent, xmlnode *child); |
| 10327 | 82 |
| 83 /** | |
| 84 * Gets a child node named name. | |
| 85 * | |
| 86 * @param parent The parent node. | |
| 87 * @param name The child's name. | |
| 88 * | |
| 89 * @return The child or NULL. | |
| 90 */ | |
| 10736 | 91 xmlnode *xmlnode_get_child(const xmlnode *parent, const char *name); |
| 10327 | 92 |
| 93 /** | |
| 94 * Gets a child node named name in a namespace. | |
| 95 * | |
| 96 * @param parent The parent node. | |
| 97 * @param name The child's name. | |
| 98 * @param xmlns The namespace. | |
| 99 * | |
| 100 * @return The child or NULL. | |
| 101 */ | |
| 10736 | 102 xmlnode *xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *xmlns); |
| 10327 | 103 |
| 104 /** | |
| 105 * Gets the next node with the same name as node. | |
| 106 * | |
| 107 * @param node The node of a twin to find. | |
| 108 * | |
| 109 * @return The twin of node or NULL. | |
| 110 */ | |
| 8135 | 111 xmlnode *xmlnode_get_next_twin(xmlnode *node); |
| 10327 | 112 |
| 113 /** | |
| 114 * Inserts data into a node. | |
| 115 * | |
| 10415 | 116 * @param node The node to insert data into. |
| 10327 | 117 * @param data The data to insert. |
| 10415 | 118 * @param size The size of the data to insert. If data is |
| 119 * null-terminated you can pass in -1. | |
| 10327 | 120 */ |
| 10848 | 121 void xmlnode_insert_data(xmlnode *node, const char *data, gssize size); |
| 10327 | 122 |
| 123 /** | |
| 124 * Gets data from a node. | |
| 125 * | |
| 126 * @param node The node to get data from. | |
| 127 * | |
|
14100
85144ba7d726
[gaim-migrate @ 16730]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13806
diff
changeset
|
128 * @return The data from the node. You must g_free |
|
85144ba7d726
[gaim-migrate @ 16730]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13806
diff
changeset
|
129 * this string when finished using it. |
| 10327 | 130 */ |
| 7131 | 131 char *xmlnode_get_data(xmlnode *node); |
| 10327 | 132 |
| 133 /** | |
| 134 * Sets an attribute for a node. | |
| 135 * | |
| 136 * @param node The node to set an attribute for. | |
| 137 * @param attr The name of the attribute. | |
| 138 * @param value The value of the attribute. | |
| 139 */ | |
| 7131 | 140 void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); |
| 10327 | 141 |
| 142 /** | |
| 143 * Gets an attribute from a node. | |
| 144 * | |
| 145 * @param node The node to get an attribute from. | |
| 146 * @param attr The attribute to get. | |
| 147 * | |
| 148 * @return The value of the attribute. | |
| 149 */ | |
| 7131 | 150 const char *xmlnode_get_attrib(xmlnode *node, const char *attr); |
| 10327 | 151 |
| 152 /** | |
| 153 * Removes an attribute from a node. | |
| 154 * | |
| 155 * @param node The node to remove an attribute from. | |
| 156 * @param attr The attribute to remove. | |
| 157 */ | |
| 7131 | 158 void xmlnode_remove_attrib(xmlnode *node, const char *attr); |
| 10327 | 159 |
| 160 /** | |
| 13806 | 161 * Sets the namespace of a node |
| 162 * | |
| 163 * @param node The node to qualify | |
| 164 * @param xmlns The namespace of the node | |
| 165 */ | |
| 166 void xmlnode_set_namespace(xmlnode *node, const char *xmlns); | |
| 167 | |
| 168 /** | |
| 169 * Returns the namespace of a node | |
| 170 * | |
| 171 * @param node The node to get the namepsace from | |
| 172 * @return The namespace of this node | |
| 173 */ | |
| 174 const char *xmlnode_get_namespace(xmlnode *node); | |
| 175 | |
| 176 /** | |
| 10327 | 177 * Returns the node in a string of xml. |
| 178 * | |
| 179 * @param node The starting node to output. | |
| 180 * @param len Address for the size of the string. | |
| 181 * | |
|
12887
4229503f1cd9
[gaim-migrate @ 15240]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
12233
diff
changeset
|
182 * @return The node represented as a string. You must |
| 10415 | 183 * g_free this string when finished using it. |
| 10327 | 184 */ |
| 10425 | 185 char *xmlnode_to_str(xmlnode *node, int *len); |
| 10327 | 186 |
| 187 /** | |
| 188 * Returns the node in a string of human readable xml. | |
| 189 * | |
| 190 * @param node The starting node to output. | |
| 191 * @param len Address for the size of the string. | |
| 192 * | |
| 193 * @return The node as human readable string including | |
| 10415 | 194 * tab and new line characters. You must |
| 195 * g_free this string when finished using it. | |
| 10327 | 196 */ |
| 10425 | 197 char *xmlnode_to_formatted_str(xmlnode *node, int *len); |
| 10327 | 198 |
| 199 /** | |
| 10337 | 200 * Creates a node from a string of XML. Calling this on the |
| 201 * root node of an XML document will parse the entire document | |
| 202 * into a tree of nodes, and return the xmlnode of the root. | |
| 10327 | 203 * |
| 204 * @param str The string of xml. | |
|
11707
b7af9100af6c
[gaim-migrate @ 13998]
Richard Laager <rlaager@wiktel.com>
parents:
10848
diff
changeset
|
205 * @param size The size of the string, or -1 if @a str is |
|
b7af9100af6c
[gaim-migrate @ 13998]
Richard Laager <rlaager@wiktel.com>
parents:
10848
diff
changeset
|
206 * NUL-terminated. |
| 10327 | 207 * |
| 208 * @return The new node. | |
| 209 */ | |
| 10848 | 210 xmlnode *xmlnode_from_str(const char *str, gssize size); |
| 10327 | 211 |
| 212 /** | |
| 213 * Creates a new node from the source node. | |
| 214 * | |
| 215 * @param src The node to copy. | |
| 216 * | |
| 217 * @return A new copy of the src node. | |
| 218 */ | |
| 8167 | 219 xmlnode *xmlnode_copy(xmlnode *src); |
| 7131 | 220 |
| 10327 | 221 /** |
| 222 * Frees a node and all of it's children. | |
| 223 * | |
| 224 * @param node The node to free. | |
| 225 */ | |
| 7131 | 226 void xmlnode_free(xmlnode *node); |
| 227 | |
| 228 #endif /* _GAIM_XMLNODE_H_ */ |
