annotate src/xmlnode.c @ 14054:51f71ad82141

[gaim-migrate @ 16667] Use GLIB_CHECK_VERSION to determine if g_str_has_prefix() is needed. As of glib 2.1.0 it was available. committer: Tailor Script <tailor@pidgin.im>
author Evan Schoenberg <evan.s@dreskin.net>
date Mon, 07 Aug 2006 23:10:37 +0000
parents 8bda65b88e49
children d38d8716426c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /**
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * @file xmlnode.c XML DOM functions
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * gaim
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7642
diff changeset
6 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7642
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7642
diff changeset
8 * source distribution.
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 *
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * (at your option) any later version.
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 *
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * GNU General Public License for more details.
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 */
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 /* A lot of this code at least resembles the code in libxode, but since
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 * libxode uses memory pools that we simply have no need for, I decided to
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 * write my own stuff. Also, re-writing this lets me be as lightweight
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 * as I want to be. Thank you libxode for giving me a good starting point */
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 #include "internal.h"
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
32 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
33 #include <libxml/parser.h>
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
34 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 #include <string.h>
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 #include <glib.h>
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 #include "xmlnode.h"
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
40 #ifdef _WIN32
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
41 # define NEWLINE_S "\r\n"
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
42 #else
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
43 # define NEWLINE_S "\n"
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
44 #endif
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
45
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 static xmlnode*
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
47 new_node(const char *name, XMLNodeType type)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 xmlnode *node = g_new0(xmlnode, 1);
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
50
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
51 node->name = g_strdup(name);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 node->type = type;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 return node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 xmlnode*
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 xmlnode_new(const char *name)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 g_return_val_if_fail(name != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
62 return new_node(name, XMLNODE_TYPE_TAG);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
65 xmlnode *
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
66 xmlnode_new_child(xmlnode *parent, const char *name)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 xmlnode *node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 g_return_val_if_fail(parent != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 g_return_val_if_fail(name != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
73 node = new_node(name, XMLNODE_TYPE_TAG);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 xmlnode_insert_child(parent, node);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 return node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 xmlnode_insert_child(xmlnode *parent, xmlnode *child)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 g_return_if_fail(parent != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 g_return_if_fail(child != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 child->parent = parent;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
88 if(parent->lastchild) {
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
89 parent->lastchild->next = child;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 } else {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 parent->child = child;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 }
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
93
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
94 parent->lastchild = child;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 void
10848
98de05966d6d [gaim-migrate @ 12520]
Nathan Walp <nwalp@pidgin.im>
parents: 10736
diff changeset
98 xmlnode_insert_data(xmlnode *node, const char *data, gssize size)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 {
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
100 xmlnode *child;
10848
98de05966d6d [gaim-migrate @ 12520]
Nathan Walp <nwalp@pidgin.im>
parents: 10736
diff changeset
101 gsize real_size;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
103 g_return_if_fail(node != NULL);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 g_return_if_fail(data != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 g_return_if_fail(size != 0);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 real_size = size == -1 ? strlen(data) : size;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
109 child = new_node(NULL, XMLNODE_TYPE_DATA);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
111 child->data = g_memdup(data, real_size);
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
112 child->data_sz = real_size;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
114 xmlnode_insert_child(node, child);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 xmlnode_remove_attrib(xmlnode *node, const char *attr)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 xmlnode *attr_node, *sibling = NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 g_return_if_fail(node != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 g_return_if_fail(attr != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125 for(attr_node = node->child; attr_node; attr_node = attr_node->next)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
127 if(attr_node->type == XMLNODE_TYPE_ATTRIB &&
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128 !strcmp(attr_node->name, attr)) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 if(node->child == attr_node) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130 node->child = attr_node->next;
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
131 } else if (node->lastchild == attr_node) {
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
132 node->lastchild = sibling;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
133 } else {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134 sibling->next = attr_node->next;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 xmlnode_free(attr_node);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139 sibling = attr_node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143 void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 xmlnode *attrib_node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 g_return_if_fail(node != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 g_return_if_fail(attr != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 g_return_if_fail(value != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152 xmlnode_remove_attrib(node, attr);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
154 attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 attrib_node->data = g_strdup(value);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 xmlnode_insert_child(node, attrib_node);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
161 const char *
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162 xmlnode_get_attrib(xmlnode *node, const char *attr)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 xmlnode *x;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 g_return_val_if_fail(node != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168 for(x = node->child; x; x = x->next) {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
169 if(x->type == XMLNODE_TYPE_ATTRIB && !strcmp(attr, x->name)) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170 return x->data;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
172 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
173
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
174 return NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
177
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
178 void xmlnode_set_namespace(xmlnode *node, const char *xmlns)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
179 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
180 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
181 g_return_if_fail(node != NULL);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
182
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
183 g_free(node->namespace);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
184 node->namespace = g_strdup(xmlns);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
185 #else
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
186 xmlnode_set_attrib(node, "xmlns", xmlns);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
187 #endif
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
188 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
189
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
190 const char *xmlnode_get_namespace(xmlnode *node)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
191 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
192 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
193 g_return_val_if_fail(node != NULL, NULL);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
194
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
195 return node->namespace;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
196 #else
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
197 return xmlnode_get_attrib(node, "xmlns");
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
198 #endif
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
199 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
200
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
201 void
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
202 xmlnode_free(xmlnode *node)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
203 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204 xmlnode *x, *y;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206 g_return_if_fail(node != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208 x = node->child;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 while(x) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210 y = x->next;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 xmlnode_free(x);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 x = y;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
215 g_free(node->name);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
216 g_free(node->data);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
217 #ifdef HAVE_LIBXML
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
218 g_free(node->namespace);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
219 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 g_free(node);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
222
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
223 xmlnode*
10736
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
224 xmlnode_get_child(const xmlnode *parent, const char *name)
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
225 {
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
226 return xmlnode_get_child_with_namespace(parent, name, NULL);
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
227 }
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
228
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
229 xmlnode *
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
230 xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *ns)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
231 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
232 xmlnode *x, *ret = NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
233 char **names;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
234 char *parent_name, *child_name;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236 g_return_val_if_fail(parent != NULL, NULL);
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
237 g_return_val_if_fail(name != NULL, NULL);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 names = g_strsplit(name, "/", 2);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 parent_name = names[0];
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241 child_name = names[1];
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243 for(x = parent->child; x; x = x->next) {
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
244 const char *xmlns = NULL;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
245 if(ns)
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
246 xmlns = xmlnode_get_namespace(x);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
247
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
248 if(x->type == XMLNODE_TYPE_TAG && name && !strcmp(parent_name, x->name)
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
249 && (!ns || (xmlns && !strcmp(ns, xmlns)))) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 ret = x;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251 break;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 if(child_name && ret)
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
256 ret = xmlnode_get_child(ret, child_name);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 g_strfreev(names);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 return ret;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
262 char *
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263 xmlnode_get_data(xmlnode *node)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265 GString *str = NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 xmlnode *c;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
267
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
268 g_return_val_if_fail(node != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 for(c = node->child; c; c = c->next) {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
271 if(c->type == XMLNODE_TYPE_DATA) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 if(!str)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273 str = g_string_new("");
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 str = g_string_append_len(str, c->data, c->data_sz);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
275 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
276 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
277
10331
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
278 if (str == NULL)
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
279 return NULL;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280
10331
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
281 return g_string_free(str, FALSE);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
282 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
283
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
284 static char *
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
285 xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
287 GString *text = g_string_new("");
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 xmlnode *c;
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
289 char *node_name, *esc, *esc2, *tab = NULL;
9838
ad7fab671e6f [gaim-migrate @ 10715]
Nathan Walp <nwalp@pidgin.im>
parents: 9837
diff changeset
290 gboolean need_end = FALSE, pretty = formatting;
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
291
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
292 g_return_val_if_fail(node != NULL, NULL);
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
293
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
294 if(pretty && depth) {
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
295 tab = g_strnfill(depth, '\t');
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
296 text = g_string_append(text, tab);
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
297 }
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 node_name = g_markup_escape_text(node->name, -1);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300 g_string_append_printf(text, "<%s", node_name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
302 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
303 if (node->namespace) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
304 char *namespace = g_markup_escape_text(node->namespace, -1);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
305 g_string_append_printf(text, " xmlns='%s'", namespace);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
306 g_free(namespace);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
307 }
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
308 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309 for(c = node->child; c; c = c->next)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
311 if(c->type == XMLNODE_TYPE_ATTRIB) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
312 esc = g_markup_escape_text(c->name, -1);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
313 esc2 = g_markup_escape_text(c->data, -1);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
314 g_string_append_printf(text, " %s='%s'", esc, esc2);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 g_free(esc);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316 g_free(esc2);
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
317 } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) {
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
318 if(c->type == XMLNODE_TYPE_DATA)
9838
ad7fab671e6f [gaim-migrate @ 10715]
Nathan Walp <nwalp@pidgin.im>
parents: 9837
diff changeset
319 pretty = FALSE;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320 need_end = TRUE;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
323
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
324 if(need_end) {
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
325 g_string_append_printf(text, ">%s", pretty ? NEWLINE_S : "");
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 for(c = node->child; c; c = c->next)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
329 if(c->type == XMLNODE_TYPE_TAG) {
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
330 int esc_len;
9838
ad7fab671e6f [gaim-migrate @ 10715]
Nathan Walp <nwalp@pidgin.im>
parents: 9837
diff changeset
331 esc = xmlnode_to_str_helper(c, &esc_len, pretty, depth+1);
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
332 text = g_string_append_len(text, esc, esc_len);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 g_free(esc);
12198
9679b615edb8 [gaim-migrate @ 14500]
Nathan Walp <nwalp@pidgin.im>
parents: 12041
diff changeset
334 } else if(c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335 esc = g_markup_escape_text(c->data, c->data_sz);
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
336 text = g_string_append(text, esc);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 g_free(esc);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
338 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340
9838
ad7fab671e6f [gaim-migrate @ 10715]
Nathan Walp <nwalp@pidgin.im>
parents: 9837
diff changeset
341 if(tab && pretty)
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
342 text = g_string_append(text, tab);
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
343 g_string_append_printf(text, "</%s>%s", node_name, formatting ? NEWLINE_S : "");
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344 } else {
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
345 g_string_append_printf(text, "/>%s", formatting ? NEWLINE_S : "");
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348 g_free(node_name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
349
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
350 g_free(tab);
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
351
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
352 if(len)
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
353 *len = text->len;
10331
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
354
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
355 return g_string_free(text, FALSE);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
356 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
357
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
358 char *
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
359 xmlnode_to_str(xmlnode *node, int *len)
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
360 {
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
361 return xmlnode_to_str_helper(node, len, FALSE, 0);
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
362 }
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
363
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
364 char *
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
365 xmlnode_to_formatted_str(xmlnode *node, int *len)
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
366 {
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
367 char *xml, *xml_with_declaration;
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
368
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
369 g_return_val_if_fail(node != NULL, NULL);
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
370
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
371 xml = xmlnode_to_str_helper(node, len, TRUE, 0);
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
372 xml_with_declaration =
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
373 g_strdup_printf("<?xml version='1.0' encoding='UTF-8' ?>" NEWLINE_S NEWLINE_S "%s", xml);
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
374 g_free(xml);
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
375
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
376 return xml_with_declaration;
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
377 }
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
378
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
379 struct _xmlnode_parser_data {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
380 xmlnode *current;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
381 };
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
382
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
383 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
384 static void
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
385 xmlnode_parser_element_start_libxml(void *user_data,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
386 const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
387 int nb_namespaces, const xmlChar **namespaces,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
388 int nb_attributes, int nb_defaulted, const xmlChar **attributes)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
389 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
390 struct _xmlnode_parser_data *xpd = user_data;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
391 xmlnode *node;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
392 int i;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
393
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
394 if(!element_name) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
395 return;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
396 } else {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
397 if(xpd->current)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
398 node = xmlnode_new_child(xpd->current, element_name);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
399 else
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
400 node = xmlnode_new(element_name);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
401
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
402 xmlnode_set_namespace(node, namespace);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
403
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
404 for(i=0; i < nb_attributes * 5; i+=5) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
405 int attrib_len = attributes[i+4] - attributes[i+3];
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
406 char *attrib = g_malloc(attrib_len + 1);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
407 memcpy(attrib, attributes[i+3], attrib_len);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
408 attrib[attrib_len] = '\0';
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
409 xmlnode_set_attrib(node, attributes[i], attrib);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
410 g_free(attrib);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
411 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
412
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
413 xpd->current = node;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
414 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
415 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
416
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
417 static void
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13831
diff changeset
418 xmlnode_parser_element_end_libxml(void *user_data, const xmlChar *element_name,
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
419 const xmlChar *prefix, const xmlChar *namespace)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
420 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
421 struct _xmlnode_parser_data *xpd = user_data;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
422
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
423 if(!element_name || !xpd->current)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
424 return;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
425
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
426 if(xpd->current->parent) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
427 if(!strcmp(xpd->current->name, element_name))
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
428 xpd->current = xpd->current->parent;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
429 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
430 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
431
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
432 static void
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
433 xmlnode_parser_element_text_libxml(void *user_data, const xmlChar *text, int text_len)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
434 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
435 struct _xmlnode_parser_data *xpd = user_data;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
436
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
437 if(!xpd->current)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
438 return;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
439
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
440 if(!text || !text_len)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
441 return;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
442
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
443 xmlnode_insert_data(xpd->current, text, text_len);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
444 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
445
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
446 #else
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
447
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
448 static void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
449 xmlnode_parser_element_start(GMarkupParseContext *context,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
450 const char *element_name, const char **attrib_names,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
451 const char **attrib_values, gpointer user_data, GError **error)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
452 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
453 struct _xmlnode_parser_data *xpd = user_data;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
454 xmlnode *node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
455 int i;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
456
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
457 if(!element_name) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
458 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
459 } else {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
460 if(xpd->current)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
461 node = xmlnode_new_child(xpd->current, element_name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
462 else
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
463 node = xmlnode_new(element_name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
464
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
465 for(i=0; attrib_names[i]; i++)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
466 xmlnode_set_attrib(node, attrib_names[i], attrib_values[i]);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
467
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
468 xpd->current = node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
469 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
470 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
471
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
472 static void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
473 xmlnode_parser_element_end(GMarkupParseContext *context,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
474 const char *element_name, gpointer user_data, GError **error)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
475 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
476 struct _xmlnode_parser_data *xpd = user_data;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
477
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
478 if(!element_name || !xpd->current)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
479 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
480
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
481 if(xpd->current->parent) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
482 if(!strcmp(xpd->current->name, element_name))
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
483 xpd->current = xpd->current->parent;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
484 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
485 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
486
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
487 static void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
488 xmlnode_parser_element_text(GMarkupParseContext *context, const char *text,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
489 gsize text_len, gpointer user_data, GError **error)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
490 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
491 struct _xmlnode_parser_data *xpd = user_data;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
492
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
493 if(!xpd->current)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
494 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
495
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
496 if(!text || !text_len)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
497 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
498
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
499 xmlnode_insert_data(xpd->current, text, text_len);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
500 }
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
501 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
502
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
503 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
504 static xmlSAXHandler xmlnode_parser_libxml = {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
505 .internalSubset = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
506 .isStandalone = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
507 .hasInternalSubset = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
508 .hasExternalSubset = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
509 .resolveEntity = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
510 .getEntity = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
511 .entityDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
512 .notationDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
513 .attributeDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
514 .elementDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
515 .unparsedEntityDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
516 .setDocumentLocator = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
517 .startDocument = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
518 .endDocument = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
519 .startElement = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
520 .endElement = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
521 .reference = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
522 .characters = xmlnode_parser_element_text_libxml,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
523 .ignorableWhitespace = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
524 .processingInstruction = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
525 .comment = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
526 .warning = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
527 .error = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
528 .fatalError = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
529 .getParameterEntity = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
530 .cdataBlock = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
531 .externalSubset = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
532 .initialized = XML_SAX2_MAGIC,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
533 ._private = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
534 .startElementNs = xmlnode_parser_element_start_libxml,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
535 .endElementNs = xmlnode_parser_element_end_libxml,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
536 .serror = NULL
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
537 };
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
538 #else
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
539 static GMarkupParser xmlnode_parser = {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
540 xmlnode_parser_element_start,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
541 xmlnode_parser_element_end,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
542 xmlnode_parser_element_text,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
543 NULL,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
544 NULL
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
545 };
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
546 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
547
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
548 xmlnode *
10848
98de05966d6d [gaim-migrate @ 12520]
Nathan Walp <nwalp@pidgin.im>
parents: 10736
diff changeset
549 xmlnode_from_str(const char *str, gssize size)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
550 {
11390
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
551 struct _xmlnode_parser_data *xpd;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
552 xmlnode *ret;
13831
3c6d0c24179a [gaim-migrate @ 16280]
Richard Laager <rlaager@wiktel.com>
parents: 13806
diff changeset
553 #ifndef HAVE_LIBXML
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
554 GMarkupParseContext *context;
13831
3c6d0c24179a [gaim-migrate @ 16280]
Richard Laager <rlaager@wiktel.com>
parents: 13806
diff changeset
555 #endif
11390
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
556 gsize real_size;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
557
11390
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
558 g_return_val_if_fail(str != NULL, NULL);
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
559
11705
0906a3e9626c [gaim-migrate @ 13996]
Richard Laager <rlaager@wiktel.com>
parents: 11390
diff changeset
560 real_size = size < 0 ? strlen(str) : size;
11390
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
561 xpd = g_new0(struct _xmlnode_parser_data, 1);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
562
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
563 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
564 if (xmlSAXUserParseMemory(&xmlnode_parser_libxml, xpd, str, size) < 0) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
565 while(xpd->current && xpd->current->parent)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
566 xpd->current = xpd->current->parent;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
567 if(xpd->current)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
568 xmlnode_free(xpd->current);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
569 xpd->current = NULL;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
570 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
571 #else
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
572 context = g_markup_parse_context_new(&xmlnode_parser, 0, xpd, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
573
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
574 if(!g_markup_parse_context_parse(context, str, real_size, NULL)) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
575 while(xpd->current && xpd->current->parent)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
576 xpd->current = xpd->current->parent;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
577 if(xpd->current)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
578 xmlnode_free(xpd->current);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
579 xpd->current = NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
580 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
581 g_markup_parse_context_free(context);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
582 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
583 ret = xpd->current;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
584 g_free(xpd);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
585 return ret;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
586 }
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
587
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
588 xmlnode *
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
589 xmlnode_copy(xmlnode *src)
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
590 {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
591 xmlnode *ret;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
592 xmlnode *child;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
593 xmlnode *sibling = NULL;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
594
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
595 g_return_val_if_fail(src != NULL, NULL);
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
596
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
597 ret = new_node(src->name, src->type);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
598 if(src->data) {
8167
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
599 if(src->data_sz) {
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
600 ret->data = g_memdup(src->data, src->data_sz);
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
601 ret->data_sz = src->data_sz;
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
602 } else {
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
603 ret->data = g_strdup(src->data);
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
604 }
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
605 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
606
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
607 for(child = src->child; child; child = child->next) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
608 if(sibling) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
609 sibling->next = xmlnode_copy(child);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
610 sibling = sibling->next;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
611 } else {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
612 ret->child = xmlnode_copy(child);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
613 sibling = ret->child;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
614 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
615 sibling->parent = ret;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
616 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
617
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
618 ret->lastchild = sibling;
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
619
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
620 return ret;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
621 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
622
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
623 xmlnode *
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
624 xmlnode_get_next_twin(xmlnode *node)
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
625 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
626 xmlnode *sibling;
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
627 const char *ns = xmlnode_get_namespace(node);
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
628
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
629 g_return_val_if_fail(node != NULL, NULL);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
630 g_return_val_if_fail(node->type == XMLNODE_TYPE_TAG, NULL);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
631
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
632 for(sibling = node->next; sibling; sibling = sibling->next) {
8283
35f69749b226 [gaim-migrate @ 9007]
Luke Schierer <lschiere@pidgin.im>
parents: 8262
diff changeset
633 const char *xmlns = NULL;
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
634 if(ns)
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
635 xmlns = xmlnode_get_namespace(sibling);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
636
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
637 if(sibling->type == XMLNODE_TYPE_TAG && !strcmp(node->name, sibling->name) &&
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
638 (!ns || (xmlns && !strcmp(ns, xmlns))))
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
639 return sibling;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
640 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
641
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
642 return NULL;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
643 }