annotate src/xmlnode.c @ 13806:25e63008d3bb

[gaim-migrate @ 16229] Use libxml2 for XML parsing, if available. The biggest benefit from this is actual support for XML namespaces. This fixes a handful of Google Talk integration problems, including typing notifications and buddy icons. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 08 Jun 2006 01:03:51 +0000
parents 02833a0ae716
children 3c6d0c24179a
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
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51 if(name)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 node->name = g_strdup(name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 node->type = type;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 return node;
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
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 xmlnode*
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 xmlnode_new(const char *name)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 g_return_val_if_fail(name != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
63 return new_node(name, XMLNODE_TYPE_TAG);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
66 xmlnode *
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
67 xmlnode_new_child(xmlnode *parent, const char *name)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 xmlnode *node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 g_return_val_if_fail(parent != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 g_return_val_if_fail(name != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
74 node = new_node(name, XMLNODE_TYPE_TAG);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76 xmlnode_insert_child(parent, node);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 return node;
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
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 xmlnode_insert_child(xmlnode *parent, xmlnode *child)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84 g_return_if_fail(parent != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 g_return_if_fail(child != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 child->parent = parent;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
89 if(parent->lastchild) {
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
90 parent->lastchild->next = child;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 } else {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 parent->child = child;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 }
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
94
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
95 parent->lastchild = child;
7131
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
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 void
10848
98de05966d6d [gaim-migrate @ 12520]
Nathan Walp <nwalp@pidgin.im>
parents: 10736
diff changeset
99 xmlnode_insert_data(xmlnode *node, const char *data, gssize size)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 {
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
101 xmlnode *child;
10848
98de05966d6d [gaim-migrate @ 12520]
Nathan Walp <nwalp@pidgin.im>
parents: 10736
diff changeset
102 gsize real_size;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
104 g_return_if_fail(node != NULL);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 g_return_if_fail(data != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 g_return_if_fail(size != 0);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 real_size = size == -1 ? strlen(data) : size;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
110 child = new_node(NULL, XMLNODE_TYPE_DATA);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
112 child->data = g_memdup(data, real_size);
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
113 child->data_sz = real_size;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
115 xmlnode_insert_child(node, child);
7131
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
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 xmlnode_remove_attrib(xmlnode *node, const char *attr)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 xmlnode *attr_node, *sibling = NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 g_return_if_fail(node != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124 g_return_if_fail(attr != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 for(attr_node = node->child; attr_node; attr_node = attr_node->next)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
128 if(attr_node->type == XMLNODE_TYPE_ATTRIB &&
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 !strcmp(attr_node->name, attr)) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130 if(node->child == attr_node) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 node->child = attr_node->next;
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
132 } else if (node->lastchild == attr_node) {
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
133 node->lastchild = sibling;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134 } else {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 sibling->next = attr_node->next;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 xmlnode_free(attr_node);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140 sibling = attr_node;
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
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 xmlnode *attrib_node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 g_return_if_fail(node != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150 g_return_if_fail(attr != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 g_return_if_fail(value != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 xmlnode_remove_attrib(node, attr);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
155 attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157 attrib_node->data = g_strdup(value);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 xmlnode_insert_child(node, attrib_node);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
162 const char *
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 xmlnode_get_attrib(xmlnode *node, const char *attr)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165 xmlnode *x;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167 g_return_val_if_fail(node != NULL, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 for(x = node->child; x; x = x->next) {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
170 if(x->type == XMLNODE_TYPE_ATTRIB && !strcmp(attr, x->name)) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171 return x->data;
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
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 return NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
177
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
178
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
179 void xmlnode_set_namespace(xmlnode *node, const char *xmlns)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
180 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
181 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
182 g_return_if_fail(node != NULL);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
183
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
184 if (node->namespace)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
185 g_free(node->namespace);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
186
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
187 node->namespace = g_strdup(xmlns);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
188 #else
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
189 return xmlnode_set_attrib(node, "xmlns", xmlns);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
190 #endif
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
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
193 const char *xmlnode_get_namespace(xmlnode *node)
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 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
196 g_return_val_if_fail(node != NULL, NULL);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
197
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
198 return node->namespace;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
199 #else
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
200 return xmlnode_get_attrib(node, "xmlns");
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
201 #endif
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
202 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
203
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
204 void
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
205 xmlnode_free(xmlnode *node)
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 xmlnode *x, *y;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209 g_return_if_fail(node != NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 x = node->child;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 while(x) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 y = x->next;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 xmlnode_free(x);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 x = y;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218 if(node->name)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219 g_free(node->name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
220 if(node->data)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 g_free(node->data);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
222 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
223 if(node->namespace)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
224 g_free(node->namespace);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
225 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226 g_free(node);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
229 xmlnode*
10736
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
230 xmlnode_get_child(const xmlnode *parent, const char *name)
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
231 {
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
232 return xmlnode_get_child_with_namespace(parent, name, NULL);
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
233 }
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
234
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
235 xmlnode *
703f722d076f [gaim-migrate @ 12338]
Mark Doliner <mark@kingant.net>
parents: 10425
diff changeset
236 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
237 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 xmlnode *x, *ret = NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 char **names;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 char *parent_name, *child_name;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 g_return_val_if_fail(parent != NULL, NULL);
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
243 g_return_val_if_fail(name != NULL, NULL);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 names = g_strsplit(name, "/", 2);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 parent_name = names[0];
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 child_name = names[1];
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 for(x = parent->child; x; x = x->next) {
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
250 const char *xmlns = NULL;
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
251 if(ns)
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
252 xmlns = xmlnode_get_namespace(x);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
253
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
254 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
255 && (!ns || (xmlns && !strcmp(ns, xmlns)))) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256 ret = x;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 break;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 }
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 if(child_name && ret)
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
262 ret = xmlnode_get_child(ret, child_name);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
263
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
264 g_strfreev(names);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
265 return ret;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
266 }
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 char *
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 xmlnode_get_data(xmlnode *node)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 GString *str = NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 xmlnode *c;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
274 g_return_val_if_fail(node != NULL, NULL);
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 for(c = node->child; c; c = c->next) {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
277 if(c->type == XMLNODE_TYPE_DATA) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
278 if(!str)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279 str = g_string_new("");
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
280 str = g_string_append_len(str, c->data, c->data_sz);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
281 }
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
10331
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
284 if (str == NULL)
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
285 return NULL;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286
10331
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
287 return g_string_free(str, FALSE);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
290 static char *
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
291 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
292 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 GString *text = g_string_new("");
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294 xmlnode *c;
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
295 char *node_name, *esc, *esc2, *tab = NULL;
9838
ad7fab671e6f [gaim-migrate @ 10715]
Nathan Walp <nwalp@pidgin.im>
parents: 9837
diff changeset
296 gboolean need_end = FALSE, pretty = formatting;
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
297
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
298 g_return_val_if_fail(node != NULL, NULL);
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
299
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
300 if(pretty && depth) {
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
301 tab = g_strnfill(depth, '\t');
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
302 text = g_string_append(text, tab);
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
303 }
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
304
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305 node_name = g_markup_escape_text(node->name, -1);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306 g_string_append_printf(text, "<%s", node_name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
308 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
309 if (node->namespace) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
310 char *namespace = g_markup_escape_text(node->namespace, -1);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
311 g_string_append_printf(text, " xmlns='%s'", namespace);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
312 g_free(namespace);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
313 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
314 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
315 for(c = node->child; c; c = c->next)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
316 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
317 if(c->type == XMLNODE_TYPE_ATTRIB) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
318 esc = g_markup_escape_text(c->name, -1);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
319 esc2 = g_markup_escape_text(c->data, -1);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
320 g_string_append_printf(text, " %s='%s'", esc, esc2);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
321 g_free(esc);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
322 g_free(esc2);
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
323 } 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
324 if(c->type == XMLNODE_TYPE_DATA)
9838
ad7fab671e6f [gaim-migrate @ 10715]
Nathan Walp <nwalp@pidgin.im>
parents: 9837
diff changeset
325 pretty = FALSE;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
326 need_end = TRUE;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
327 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
328 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
329
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
330 if(need_end) {
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
331 g_string_append_printf(text, ">%s", pretty ? NEWLINE_S : "");
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
332
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
333 for(c = node->child; c; c = c->next)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
334 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
335 if(c->type == XMLNODE_TYPE_TAG) {
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
336 int esc_len;
9838
ad7fab671e6f [gaim-migrate @ 10715]
Nathan Walp <nwalp@pidgin.im>
parents: 9837
diff changeset
337 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
338 text = g_string_append_len(text, esc, esc_len);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339 g_free(esc);
12198
9679b615edb8 [gaim-migrate @ 14500]
Nathan Walp <nwalp@pidgin.im>
parents: 12041
diff changeset
340 } else if(c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) {
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 esc = g_markup_escape_text(c->data, c->data_sz);
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
342 text = g_string_append(text, esc);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343 g_free(esc);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
344 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346
9838
ad7fab671e6f [gaim-migrate @ 10715]
Nathan Walp <nwalp@pidgin.im>
parents: 9837
diff changeset
347 if(tab && pretty)
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
348 text = g_string_append(text, tab);
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
349 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
350 } else {
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
351 g_string_append_printf(text, "/>%s", formatting ? NEWLINE_S : "");
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
352 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
353
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
354 g_free(node_name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
355
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
356 if(tab)
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
357 g_free(tab);
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
358
7642
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
359 if(len)
9008b5be4275 [gaim-migrate @ 8285]
Nathan Walp <nwalp@pidgin.im>
parents: 7131
diff changeset
360 *len = text->len;
10331
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
361
20df7dd1c57c [gaim-migrate @ 11538]
Mark Doliner <mark@kingant.net>
parents: 9838
diff changeset
362 return g_string_free(text, FALSE);
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
363 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
364
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
365 char *
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
366 xmlnode_to_str(xmlnode *node, int *len)
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
367 {
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
368 return xmlnode_to_str_helper(node, len, FALSE, 0);
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
369 }
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
370
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
371 char *
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
372 xmlnode_to_formatted_str(xmlnode *node, int *len)
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
373 {
10425
9903182f2aac [gaim-migrate @ 11677]
Mark Doliner <mark@kingant.net>
parents: 10424
diff changeset
374 char *xml, *xml_with_declaration;
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
375
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
376 g_return_val_if_fail(node != NULL, NULL);
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
377
10415
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
378 xml = xmlnode_to_str_helper(node, len, TRUE, 0);
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
379 xml_with_declaration =
12041
da44f68fb4d2 [gaim-migrate @ 14334]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11705
diff changeset
380 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
381 g_free(xml);
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
382
5b7a74d397cc [gaim-migrate @ 11665]
Mark Doliner <mark@kingant.net>
parents: 10331
diff changeset
383 return xml_with_declaration;
9837
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
384 }
dafebadcf8d2 [gaim-migrate @ 10714]
Nathan Walp <nwalp@pidgin.im>
parents: 8283
diff changeset
385
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
386 struct _xmlnode_parser_data {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
387 xmlnode *current;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
388 };
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
389
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
390 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
391 static void
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
392 xmlnode_parser_element_start_libxml(void *user_data,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
393 const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
394 int nb_namespaces, const xmlChar **namespaces,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
395 int nb_attributes, int nb_defaulted, const xmlChar **attributes)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
396 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
397 struct _xmlnode_parser_data *xpd = user_data;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
398 xmlnode *node;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
399 int i;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
400
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
401 if(!element_name) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
402 return;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
403 } else {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
404 if(xpd->current)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
405 node = xmlnode_new_child(xpd->current, element_name);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
406 else
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
407 node = xmlnode_new(element_name);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
408
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
409 xmlnode_set_namespace(node, namespace);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
410
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
411 for(i=0; i < nb_attributes * 5; i+=5) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
412 int attrib_len = attributes[i+4] - attributes[i+3];
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
413 char *attrib = g_malloc(attrib_len + 1);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
414 memcpy(attrib, attributes[i+3], attrib_len);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
415 attrib[attrib_len] = '\0';
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
416 xmlnode_set_attrib(node, attributes[i], attrib);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
417 g_free(attrib);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
418 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
419
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
420 xpd->current = node;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
421 }
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
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
424 static void
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
425 xmlnode_parser_element_end_libxml(void *user_data, const xmlChar *element_name,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
426 const xmlChar *prefix, const xmlChar *namespace)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
427 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
428 struct _xmlnode_parser_data *xpd = user_data;
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 if(!element_name || !xpd->current)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
431 return;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
432
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
433 if(xpd->current->parent) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
434 if(!strcmp(xpd->current->name, element_name))
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
435 xpd->current = xpd->current->parent;
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 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
438
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
439 static void
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
440 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
441 {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
442 struct _xmlnode_parser_data *xpd = user_data;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
443
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
444 if(!xpd->current)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
445 return;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
446
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
447 if(!text || !text_len)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
448 return;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
449
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
450 xmlnode_insert_data(xpd->current, text, text_len);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
451 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
452
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
453 #else
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
454
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
455 static void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
456 xmlnode_parser_element_start(GMarkupParseContext *context,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
457 const char *element_name, const char **attrib_names,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
458 const char **attrib_values, gpointer user_data, GError **error)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
459 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
460 struct _xmlnode_parser_data *xpd = user_data;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
461 xmlnode *node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
462 int i;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
463
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
464 if(!element_name) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
465 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
466 } else {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
467 if(xpd->current)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
468 node = xmlnode_new_child(xpd->current, element_name);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
469 else
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
470 node = xmlnode_new(element_name);
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 for(i=0; attrib_names[i]; i++)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
473 xmlnode_set_attrib(node, attrib_names[i], attrib_values[i]);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
474
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
475 xpd->current = node;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
476 }
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
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
479 static void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
480 xmlnode_parser_element_end(GMarkupParseContext *context,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
481 const char *element_name, gpointer user_data, GError **error)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
482 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
483 struct _xmlnode_parser_data *xpd = user_data;
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 if(!element_name || !xpd->current)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
486 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
487
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
488 if(xpd->current->parent) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
489 if(!strcmp(xpd->current->name, element_name))
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
490 xpd->current = xpd->current->parent;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
491 }
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
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
494 static void
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
495 xmlnode_parser_element_text(GMarkupParseContext *context, const char *text,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
496 gsize text_len, gpointer user_data, GError **error)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
497 {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
498 struct _xmlnode_parser_data *xpd = user_data;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
499
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
500 if(!xpd->current)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
501 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
502
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
503 if(!text || !text_len)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
504 return;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
505
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
506 xmlnode_insert_data(xpd->current, text, text_len);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
507 }
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
508 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
509
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
510 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
511 static xmlSAXHandler xmlnode_parser_libxml = {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
512 .internalSubset = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
513 .isStandalone = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
514 .hasInternalSubset = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
515 .hasExternalSubset = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
516 .resolveEntity = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
517 .getEntity = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
518 .entityDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
519 .notationDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
520 .attributeDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
521 .elementDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
522 .unparsedEntityDecl = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
523 .setDocumentLocator = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
524 .startDocument = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
525 .endDocument = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
526 .startElement = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
527 .endElement = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
528 .reference = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
529 .characters = xmlnode_parser_element_text_libxml,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
530 .ignorableWhitespace = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
531 .processingInstruction = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
532 .comment = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
533 .warning = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
534 .error = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
535 .fatalError = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
536 .getParameterEntity = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
537 .cdataBlock = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
538 .externalSubset = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
539 .initialized = XML_SAX2_MAGIC,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
540 ._private = NULL,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
541 .startElementNs = xmlnode_parser_element_start_libxml,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
542 .endElementNs = xmlnode_parser_element_end_libxml,
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
543 .serror = NULL
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
544 };
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
545 #else
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
546 static GMarkupParser xmlnode_parser = {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
547 xmlnode_parser_element_start,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
548 xmlnode_parser_element_end,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
549 xmlnode_parser_element_text,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
550 NULL,
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
551 NULL
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
552 };
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
553 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
554
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
555 xmlnode *
10848
98de05966d6d [gaim-migrate @ 12520]
Nathan Walp <nwalp@pidgin.im>
parents: 10736
diff changeset
556 xmlnode_from_str(const char *str, gssize 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 struct _xmlnode_parser_data *xpd;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
559 xmlnode *ret;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
560 GMarkupParseContext *context;
11390
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
561 gsize real_size;
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
562
11390
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
563 g_return_val_if_fail(str != NULL, NULL);
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
564
11705
0906a3e9626c [gaim-migrate @ 13996]
Richard Laager <rlaager@wiktel.com>
parents: 11390
diff changeset
565 real_size = size < 0 ? strlen(str) : size;
11390
869cef00a947 [gaim-migrate @ 13618]
Nathan Walp <nwalp@pidgin.im>
parents: 10848
diff changeset
566 xpd = g_new0(struct _xmlnode_parser_data, 1);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
567
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
568 #ifdef HAVE_LIBXML
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
569 if (xmlSAXUserParseMemory(&xmlnode_parser_libxml, xpd, str, size) < 0) {
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
570 while(xpd->current && xpd->current->parent)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
571 xpd->current = xpd->current->parent;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
572 if(xpd->current)
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
573 xmlnode_free(xpd->current);
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
574 xpd->current = NULL;
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
575 }
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
576 #else
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
577 context = g_markup_parse_context_new(&xmlnode_parser, 0, xpd, NULL);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
578
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
579 if(!g_markup_parse_context_parse(context, str, real_size, NULL)) {
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
580 while(xpd->current && xpd->current->parent)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
581 xpd->current = xpd->current->parent;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
582 if(xpd->current)
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
583 xmlnode_free(xpd->current);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
584 xpd->current = NULL;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
585 }
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
586 g_markup_parse_context_free(context);
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
587 #endif
7131
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
588 ret = xpd->current;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
589 g_free(xpd);
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
590 return ret;
af889fd531d0 [gaim-migrate @ 7698]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
591 }
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
592
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
593 xmlnode *
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
594 xmlnode_copy(xmlnode *src)
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
595 {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
596 xmlnode *ret;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
597 xmlnode *child;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
598 xmlnode *sibling = NULL;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
599
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
600 g_return_val_if_fail(src != NULL, NULL);
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
601
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
602 ret = new_node(src->name, src->type);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
603 if(src->data) {
8167
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
604 if(src->data_sz) {
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
605 ret->data = g_memdup(src->data, src->data_sz);
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
606 ret->data_sz = src->data_sz;
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
607 } else {
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
608 ret->data = g_strdup(src->data);
b55b70aef314 [gaim-migrate @ 8880]
Nathan Walp <nwalp@pidgin.im>
parents: 8135
diff changeset
609 }
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
610 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
611
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
612 for(child = src->child; child; child = child->next) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
613 if(sibling) {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
614 sibling->next = xmlnode_copy(child);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
615 sibling = sibling->next;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
616 } else {
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
617 ret->child = xmlnode_copy(child);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
618 sibling = ret->child;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
619 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
620 sibling->parent = 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
12233
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
623 ret->lastchild = sibling;
02833a0ae716 [gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents: 12198
diff changeset
624
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
625 return ret;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
626 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
627
10423
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
628 xmlnode *
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
629 xmlnode_get_next_twin(xmlnode *node)
3232e1a33899 [gaim-migrate @ 11675]
Mark Doliner <mark@kingant.net>
parents: 10415
diff changeset
630 {
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
631 xmlnode *sibling;
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
632 const char *ns = xmlnode_get_namespace(node);
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
633
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
634 g_return_val_if_fail(node != NULL, NULL);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
635 g_return_val_if_fail(node->type == XMLNODE_TYPE_TAG, NULL);
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
636
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
637 for(sibling = node->next; sibling; sibling = sibling->next) {
8283
35f69749b226 [gaim-migrate @ 9007]
Luke Schierer <lschiere@pidgin.im>
parents: 8262
diff changeset
638 const char *xmlns = NULL;
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
639 if(ns)
13806
25e63008d3bb [gaim-migrate @ 16229]
Sean Egan <seanegan@gmail.com>
parents: 12233
diff changeset
640 xmlns = xmlnode_get_namespace(sibling);
8262
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
641
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
642 if(sibling->type == XMLNODE_TYPE_TAG && !strcmp(node->name, sibling->name) &&
b5dbd1839716 [gaim-migrate @ 8985]
Nathan Walp <nwalp@pidgin.im>
parents: 8167
diff changeset
643 (!ns || (xmlns && !strcmp(ns, xmlns))))
8135
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
644 return sibling;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
645 }
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
646
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
647 return NULL;
8f4ce853e685 [gaim-migrate @ 8840]
Nathan Walp <nwalp@pidgin.im>
parents: 8046
diff changeset
648 }