1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Frameworks/libpurple.framework/Versions/0.6.2/Headers/xmlnode.h Fri Aug 21 13:25:11 2009 -0700
1.3 @@ -0,0 +1,356 @@
1.4 +/**
1.5 + * @file xmlnode.h XML DOM functions
1.6 + * @ingroup core
1.7 + */
1.8 +
1.9 +/* purple
1.10 + *
1.11 + * Purple is the legal property of its developers, whose names are too numerous
1.12 + * to list here. Please refer to the COPYRIGHT file distributed with this
1.13 + * source distribution.
1.14 + *
1.15 + * This program is free software; you can redistribute it and/or modify
1.16 + * it under the terms of the GNU General Public License as published by
1.17 + * the Free Software Foundation; either version 2 of the License, or
1.18 + * (at your option) any later version.
1.19 + *
1.20 + * This program is distributed in the hope that it will be useful,
1.21 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.22 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.23 + * GNU General Public License for more details.
1.24 + *
1.25 + * You should have received a copy of the GNU General Public License
1.26 + * along with this program; if not, write to the Free Software
1.27 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
1.28 + */
1.29 +#ifndef _PURPLE_XMLNODE_H_
1.30 +#define _PURPLE_XMLNODE_H_
1.31 +
1.32 +#include <glib.h>
1.33 +
1.34 +#ifdef __cplusplus
1.35 +extern "C" {
1.36 +#endif
1.37 +
1.38 +/**
1.39 + * The valid types for an xmlnode
1.40 + */
1.41 +typedef enum _XMLNodeType
1.42 +{
1.43 + XMLNODE_TYPE_TAG, /**< Just a tag */
1.44 + XMLNODE_TYPE_ATTRIB, /**< Has attributes */
1.45 + XMLNODE_TYPE_DATA /**< Has data */
1.46 +} XMLNodeType;
1.47 +
1.48 +/**
1.49 + * An xmlnode.
1.50 + */
1.51 +typedef struct _xmlnode xmlnode;
1.52 +struct _xmlnode
1.53 +{
1.54 + char *name; /**< The name of the node. */
1.55 + char *xmlns; /**< The namespace of the node */
1.56 + XMLNodeType type; /**< The type of the node. */
1.57 + char *data; /**< The data for the node. */
1.58 + size_t data_sz; /**< The size of the data. */
1.59 + xmlnode *parent; /**< The parent node or @c NULL.*/
1.60 + xmlnode *child; /**< The child node or @c NULL.*/
1.61 + xmlnode *lastchild; /**< The last child node or @c NULL.*/
1.62 + xmlnode *next; /**< The next node or @c NULL. */
1.63 + char *prefix; /**< The namespace prefix if any. */
1.64 + GHashTable *namespace_map; /**< The namespace map. */
1.65 +};
1.66 +
1.67 +/**
1.68 + * Creates a new xmlnode.
1.69 + *
1.70 + * @param name The name of the node.
1.71 + *
1.72 + * @return The new node.
1.73 + */
1.74 +xmlnode *xmlnode_new(const char *name);
1.75 +
1.76 +/**
1.77 + * Creates a new xmlnode child.
1.78 + *
1.79 + * @param parent The parent node.
1.80 + * @param name The name of the child node.
1.81 + *
1.82 + * @return The new child node.
1.83 + */
1.84 +xmlnode *xmlnode_new_child(xmlnode *parent, const char *name);
1.85 +
1.86 +/**
1.87 + * Inserts a node into a node as a child.
1.88 + *
1.89 + * @param parent The parent node to insert child into.
1.90 + * @param child The child node to insert into parent.
1.91 + */
1.92 +void xmlnode_insert_child(xmlnode *parent, xmlnode *child);
1.93 +
1.94 +/**
1.95 + * Gets a child node named name.
1.96 + *
1.97 + * @param parent The parent node.
1.98 + * @param name The child's name.
1.99 + *
1.100 + * @return The child or NULL.
1.101 + */
1.102 +xmlnode *xmlnode_get_child(const xmlnode *parent, const char *name);
1.103 +
1.104 +/**
1.105 + * Gets a child node named name in a namespace.
1.106 + *
1.107 + * @param parent The parent node.
1.108 + * @param name The child's name.
1.109 + * @param xmlns The namespace.
1.110 + *
1.111 + * @return The child or NULL.
1.112 + */
1.113 +xmlnode *xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *xmlns);
1.114 +
1.115 +/**
1.116 + * Gets the next node with the same name as node.
1.117 + *
1.118 + * @param node The node of a twin to find.
1.119 + *
1.120 + * @return The twin of node or NULL.
1.121 + */
1.122 +xmlnode *xmlnode_get_next_twin(xmlnode *node);
1.123 +
1.124 +/**
1.125 + * Inserts data into a node.
1.126 + *
1.127 + * @param node The node to insert data into.
1.128 + * @param data The data to insert.
1.129 + * @param size The size of the data to insert. If data is
1.130 + * null-terminated you can pass in -1.
1.131 + */
1.132 +void xmlnode_insert_data(xmlnode *node, const char *data, gssize size);
1.133 +
1.134 +/**
1.135 + * Gets (escaped) data from a node.
1.136 + *
1.137 + * @param node The node to get data from.
1.138 + *
1.139 + * @return The data from the node or NULL. This data is in raw escaped format.
1.140 + * You must g_free this string when finished using it.
1.141 + */
1.142 +char *xmlnode_get_data(const xmlnode *node);
1.143 +
1.144 +/**
1.145 + * Gets unescaped data from a node.
1.146 + *
1.147 + * @param node The node to get data from.
1.148 + *
1.149 + * @return The data from the node, in unescaped form. You must g_free
1.150 + * this string when finished using it.
1.151 + */
1.152 +char *xmlnode_get_data_unescaped(const xmlnode *node);
1.153 +
1.154 +/**
1.155 + * Sets an attribute for a node.
1.156 + *
1.157 + * @param node The node to set an attribute for.
1.158 + * @param attr The name of the attribute.
1.159 + * @param value The value of the attribute.
1.160 + */
1.161 +void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value);
1.162 +
1.163 +#if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_XMLNODE_C_)
1.164 +/**
1.165 + * Sets a prefixed attribute for a node
1.166 + *
1.167 + * @param node The node to set an attribute for.
1.168 + * @param attr The name of the attribute to set
1.169 + * @param prefix The prefix of the attribute to ste
1.170 + * @param value The value of the attribute
1.171 + *
1.172 + * @deprecated Use xmlnode_set_attrib_full instead.
1.173 + */
1.174 +void xmlnode_set_attrib_with_prefix(xmlnode *node, const char *attr, const char *prefix, const char *value);
1.175 +
1.176 +/**
1.177 + * Sets a namespaced attribute for a node
1.178 + *
1.179 + * @param node The node to set an attribute for.
1.180 + * @param attr The name of the attribute to set
1.181 + * @param xmlns The namespace of the attribute to ste
1.182 + * @param value The value of the attribute
1.183 + *
1.184 + * @deprecated Use xmlnode_set_attrib_full instead.
1.185 + */
1.186 +void xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value);
1.187 +#endif /* PURPLE_DISABLE_DEPRECATED */
1.188 +
1.189 +/**
1.190 + * Sets a namespaced attribute for a node
1.191 + *
1.192 + * @param node The node to set an attribute for.
1.193 + * @param attr The name of the attribute to set
1.194 + * @param xmlns The namespace of the attribute to ste
1.195 + * @param prefix The prefix of the attribute to ste
1.196 + * @param value The value of the attribute
1.197 + *
1.198 + * @since 2.6.0
1.199 + */
1.200 +void xmlnode_set_attrib_full(xmlnode *node, const char *attr, const char *xmlns,
1.201 + const char *prefix, const char *value);
1.202 +
1.203 +/**
1.204 + * Gets an attribute from a node.
1.205 + *
1.206 + * @param node The node to get an attribute from.
1.207 + * @param attr The attribute to get.
1.208 + *
1.209 + * @return The value of the attribute.
1.210 + */
1.211 +const char *xmlnode_get_attrib(xmlnode *node, const char *attr);
1.212 +
1.213 +/**
1.214 + * Gets a namespaced attribute from a node
1.215 + *
1.216 + * @param node The node to get an attribute from.
1.217 + * @param attr The attribute to get
1.218 + * @param xmlns The namespace of the attribute to get
1.219 + *
1.220 + * @return The value of the attribute/
1.221 + */
1.222 +const char *xmlnode_get_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns);
1.223 +
1.224 +/**
1.225 + * Removes an attribute from a node.
1.226 + *
1.227 + * @param node The node to remove an attribute from.
1.228 + * @param attr The attribute to remove.
1.229 + */
1.230 +void xmlnode_remove_attrib(xmlnode *node, const char *attr);
1.231 +
1.232 +/**
1.233 + * Removes a namespaced attribute from a node
1.234 + *
1.235 + * @param node The node to remove an attribute from
1.236 + * @param attr The attribute to remove
1.237 + * @param xmlns The namespace of the attribute to remove
1.238 + */
1.239 +void xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns);
1.240 +
1.241 +/**
1.242 + * Sets the namespace of a node
1.243 + *
1.244 + * @param node The node to qualify
1.245 + * @param xmlns The namespace of the node
1.246 + */
1.247 +void xmlnode_set_namespace(xmlnode *node, const char *xmlns);
1.248 +
1.249 +/**
1.250 + * Returns the namespace of a node
1.251 + *
1.252 + * @param node The node to get the namepsace from
1.253 + * @return The namespace of this node
1.254 + */
1.255 +const char *xmlnode_get_namespace(xmlnode *node);
1.256 +
1.257 +/**
1.258 + * Sets the prefix of a node
1.259 + *
1.260 + * @param node The node to qualify
1.261 + * @param prefix The prefix of the node
1.262 + */
1.263 +void xmlnode_set_prefix(xmlnode *node, const char *prefix);
1.264 +
1.265 +/**
1.266 + * Returns the prefix of a node
1.267 + *
1.268 + * @param node The node to get the prefix from
1.269 + * @return The prefix of this node
1.270 + */
1.271 +const char *xmlnode_get_prefix(const xmlnode *node);
1.272 +
1.273 +/**
1.274 + * Gets the parent node.
1.275 + *
1.276 + * @param child The child node.
1.277 + *
1.278 + * @return The parent or NULL.
1.279 + *
1.280 + * @since 2.6.0
1.281 + */
1.282 +xmlnode *xmlnode_get_parent(const xmlnode *child);
1.283 +
1.284 +/**
1.285 + * Returns the node in a string of xml.
1.286 + *
1.287 + * @param node The starting node to output.
1.288 + * @param len Address for the size of the string.
1.289 + *
1.290 + * @return The node represented as a string. You must
1.291 + * g_free this string when finished using it.
1.292 + */
1.293 +char *xmlnode_to_str(const xmlnode *node, int *len);
1.294 +
1.295 +/**
1.296 + * Returns the node in a string of human readable xml.
1.297 + *
1.298 + * @param node The starting node to output.
1.299 + * @param len Address for the size of the string.
1.300 + *
1.301 + * @return The node as human readable string including
1.302 + * tab and new line characters. You must
1.303 + * g_free this string when finished using it.
1.304 + */
1.305 +char *xmlnode_to_formatted_str(const xmlnode *node, int *len);
1.306 +
1.307 +/**
1.308 + * Creates a node from a string of XML. Calling this on the
1.309 + * root node of an XML document will parse the entire document
1.310 + * into a tree of nodes, and return the xmlnode of the root.
1.311 + *
1.312 + * @param str The string of xml.
1.313 + * @param size The size of the string, or -1 if @a str is
1.314 + * NUL-terminated.
1.315 + *
1.316 + * @return The new node.
1.317 + */
1.318 +xmlnode *xmlnode_from_str(const char *str, gssize size);
1.319 +
1.320 +/**
1.321 + * Creates a new node from the source node.
1.322 + *
1.323 + * @param src The node to copy.
1.324 + *
1.325 + * @return A new copy of the src node.
1.326 + */
1.327 +xmlnode *xmlnode_copy(const xmlnode *src);
1.328 +
1.329 +/**
1.330 + * Frees a node and all of its children.
1.331 + *
1.332 + * @param node The node to free.
1.333 + */
1.334 +void xmlnode_free(xmlnode *node);
1.335 +
1.336 +/**
1.337 + * Creates a node from a XML File. Calling this on the
1.338 + * root node of an XML document will parse the entire document
1.339 + * into a tree of nodes, and return the xmlnode of the root.
1.340 + *
1.341 + * @param dir The directory where the file is located
1.342 + * @param filename The filename
1.343 + * @param description A description of the file being parsed. Displayed to
1.344 + * the user if the file cannot be read.
1.345 + * @param process The subsystem that is calling xmlnode_from_file. Used as
1.346 + * the category for debugging.
1.347 + *
1.348 + * @return The new node or NULL if an error occurred.
1.349 + *
1.350 + * @since 2.6.0
1.351 + */
1.352 +xmlnode *xmlnode_from_file(const char *dir, const char *filename,
1.353 + const char *description, const char *process);
1.354 +
1.355 +#ifdef __cplusplus
1.356 +}
1.357 +#endif
1.358 +
1.359 +#endif /* _PURPLE_XMLNODE_H_ */