Mon, 26 Jan 2009 06:44:00 +0000
Remove trailing whitespace
| 7131 | 1 | /** |
| 2 | * @file xmlnode.c XML DOM functions | |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
3 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
4 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19897
diff
changeset
|
5 | /* purple |
| 7131 | 6 | * |
| 15884 | 7 | * Purple is the legal property of its developers, whose names are too numerous |
| 8046 | 8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 9 | * source distribution. | |
| 7131 | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify | |
| 12 | * it under the terms of the GNU General Public License as published by | |
| 13 | * the Free Software Foundation; either version 2 of the License, or | |
| 14 | * (at your option) any later version. | |
| 15 | * | |
| 16 | * This program is distributed in the hope that it will be useful, | |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 | * GNU General Public License for more details. | |
| 20 | * | |
| 21 | * You should have received a copy of the GNU General Public License | |
| 22 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19821
diff
changeset
|
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 7131 | 24 | */ |
| 25 | ||
| 26 | /* A lot of this code at least resembles the code in libxode, but since | |
| 27 | * libxode uses memory pools that we simply have no need for, I decided to | |
| 28 | * write my own stuff. Also, re-writing this lets me be as lightweight | |
| 29 | * as I want to be. Thank you libxode for giving me a good starting point */ | |
| 30 | ||
|
15977
057b184c15d9
Don't advertise that we support the adverts, invite and translate
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
31 | #include "debug.h" |
| 7131 | 32 | #include "internal.h" |
| 33 | ||
| 13808 | 34 | #include <libxml/parser.h> |
| 7131 | 35 | #include <string.h> |
| 36 | #include <glib.h> | |
| 37 | ||
| 14386 | 38 | #include "dbus-maybe.h" |
|
14233
4f5fe687b21d
[gaim-migrate @ 16821]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14097
diff
changeset
|
39 | #include "util.h" |
| 7131 | 40 | #include "xmlnode.h" |
| 41 | ||
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
42 | #ifdef _WIN32 |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
43 | # define NEWLINE_S "\r\n" |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
44 | #else |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
45 | # define NEWLINE_S "\n" |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
46 | #endif |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
47 | |
| 7131 | 48 | static xmlnode* |
| 8135 | 49 | new_node(const char *name, XMLNodeType type) |
| 7131 | 50 | { |
| 51 | xmlnode *node = g_new0(xmlnode, 1); | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
52 | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
53 | node->name = g_strdup(name); |
| 7131 | 54 | node->type = type; |
| 55 | ||
| 15884 | 56 | PURPLE_DBUS_REGISTER_POINTER(node, xmlnode); |
| 14386 | 57 | |
| 7131 | 58 | return node; |
| 59 | } | |
| 60 | ||
| 61 | xmlnode* | |
| 62 | xmlnode_new(const char *name) | |
| 63 | { | |
| 64 | g_return_val_if_fail(name != NULL, NULL); | |
| 65 | ||
| 8135 | 66 | return new_node(name, XMLNODE_TYPE_TAG); |
| 7131 | 67 | } |
| 68 | ||
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
69 | xmlnode * |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
70 | xmlnode_new_child(xmlnode *parent, const char *name) |
| 7131 | 71 | { |
| 72 | xmlnode *node; | |
| 73 | ||
| 74 | g_return_val_if_fail(parent != NULL, NULL); | |
| 75 | g_return_val_if_fail(name != NULL, NULL); | |
| 76 | ||
| 8135 | 77 | node = new_node(name, XMLNODE_TYPE_TAG); |
| 7131 | 78 | |
| 79 | xmlnode_insert_child(parent, node); | |
| 80 | ||
| 81 | return node; | |
| 82 | } | |
| 83 | ||
| 84 | void | |
| 85 | xmlnode_insert_child(xmlnode *parent, xmlnode *child) | |
| 86 | { | |
| 87 | g_return_if_fail(parent != NULL); | |
| 88 | g_return_if_fail(child != NULL); | |
| 89 | ||
| 90 | child->parent = parent; | |
| 91 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
92 | if(parent->lastchild) { |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
93 | parent->lastchild->next = child; |
| 7131 | 94 | } else { |
| 95 | parent->child = child; | |
| 96 | } | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
97 | |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
98 | parent->lastchild = child; |
| 7131 | 99 | } |
| 100 | ||
| 101 | void | |
| 10848 | 102 | xmlnode_insert_data(xmlnode *node, const char *data, gssize size) |
| 7131 | 103 | { |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
104 | xmlnode *child; |
| 10848 | 105 | gsize real_size; |
| 7131 | 106 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
107 | g_return_if_fail(node != NULL); |
| 7131 | 108 | g_return_if_fail(data != NULL); |
| 109 | g_return_if_fail(size != 0); | |
| 110 | ||
| 111 | real_size = size == -1 ? strlen(data) : size; | |
| 112 | ||
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
113 | child = new_node(NULL, XMLNODE_TYPE_DATA); |
| 7131 | 114 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
115 | child->data = g_memdup(data, real_size); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
116 | child->data_sz = real_size; |
| 7131 | 117 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
118 | xmlnode_insert_child(node, child); |
| 7131 | 119 | } |
| 120 | ||
| 121 | void | |
| 122 | xmlnode_remove_attrib(xmlnode *node, const char *attr) | |
| 123 | { | |
| 124 | xmlnode *attr_node, *sibling = NULL; | |
| 125 | ||
| 126 | g_return_if_fail(node != NULL); | |
| 127 | g_return_if_fail(attr != NULL); | |
| 128 | ||
| 129 | for(attr_node = node->child; attr_node; attr_node = attr_node->next) | |
| 130 | { | |
| 8135 | 131 | if(attr_node->type == XMLNODE_TYPE_ATTRIB && |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
132 | purple_strequal(attr_node->name, attr)) |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
133 | { |
|
20228
ce019944d765
applied changes from 9d35dde0c779cca73548172223ba557f27d61882
Luke Schierer <lschiere@pidgin.im>
parents:
20224
diff
changeset
|
134 | if(sibling == NULL) { |
| 7131 | 135 | node->child = attr_node->next; |
| 136 | } else { | |
| 137 | sibling->next = attr_node->next; | |
| 138 | } | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
139 | if (node->lastchild == attr_node) { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
140 | node->lastchild = sibling; |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
141 | } |
| 7131 | 142 | xmlnode_free(attr_node); |
| 143 | return; | |
| 144 | } | |
| 145 | sibling = attr_node; | |
| 146 | } | |
| 147 | } | |
| 148 | ||
| 15265 | 149 | void |
| 150 | xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) | |
| 151 | { | |
| 152 | xmlnode *attr_node, *sibling = NULL; | |
| 153 | ||
| 154 | g_return_if_fail(node != NULL); | |
| 155 | g_return_if_fail(attr != NULL); | |
| 156 | ||
| 157 | for(attr_node = node->child; attr_node; attr_node = attr_node->next) | |
| 158 | { | |
| 159 | if(attr_node->type == XMLNODE_TYPE_ATTRIB && | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
160 | purple_strequal(attr, attr_node->name) && |
|
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
161 | purple_strequal(xmlns, attr_node->xmlns)) |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
162 | { |
|
20228
ce019944d765
applied changes from 9d35dde0c779cca73548172223ba557f27d61882
Luke Schierer <lschiere@pidgin.im>
parents:
20224
diff
changeset
|
163 | if(sibling == NULL) { |
| 15265 | 164 | node->child = attr_node->next; |
| 165 | } else { | |
| 166 | sibling->next = attr_node->next; | |
| 167 | } | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
168 | if (node->lastchild == attr_node) { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
169 | node->lastchild = sibling; |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
170 | } |
| 15265 | 171 | xmlnode_free(attr_node); |
| 172 | return; | |
| 173 | } | |
| 174 | sibling = attr_node; | |
| 175 | } | |
| 176 | } | |
| 177 | ||
| 7131 | 178 | void |
| 179 | xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value) | |
| 180 | { | |
| 181 | xmlnode *attrib_node; | |
| 182 | ||
| 183 | g_return_if_fail(node != NULL); | |
| 184 | g_return_if_fail(attr != NULL); | |
| 185 | g_return_if_fail(value != NULL); | |
| 186 | ||
| 187 | xmlnode_remove_attrib(node, attr); | |
| 188 | ||
| 8135 | 189 | attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); |
| 7131 | 190 | |
| 191 | attrib_node->data = g_strdup(value); | |
| 192 | ||
| 193 | xmlnode_insert_child(node, attrib_node); | |
| 194 | } | |
| 195 | ||
| 15265 | 196 | void |
| 197 | xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value) | |
| 198 | { | |
| 199 | xmlnode *attrib_node; | |
| 200 | ||
| 201 | g_return_if_fail(node != NULL); | |
| 202 | g_return_if_fail(attr != NULL); | |
| 203 | g_return_if_fail(value != NULL); | |
| 204 | ||
| 205 | xmlnode_remove_attrib_with_namespace(node, attr, xmlns); | |
| 206 | attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); | |
| 207 | ||
| 208 | attrib_node->data = g_strdup(value); | |
| 209 | attrib_node->xmlns = g_strdup(xmlns); | |
| 210 | ||
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
211 | xmlnode_insert_child(node, attrib_node); |
| 15265 | 212 | } |
| 213 | ||
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
214 | void |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
215 | xmlnode_set_attrib_with_prefix(xmlnode *node, const char *attr, const char *prefix, const char *value) |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
216 | { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
217 | xmlnode *attrib_node; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
218 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
219 | g_return_if_fail(node != NULL); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
220 | g_return_if_fail(attr != NULL); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
221 | g_return_if_fail(value != NULL); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
222 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
223 | attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
224 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
225 | attrib_node->data = g_strdup(value); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
226 | attrib_node->prefix = g_strdup(prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
227 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
228 | xmlnode_insert_child(node, attrib_node); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
229 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
230 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
231 | |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
232 | const char * |
| 7131 | 233 | xmlnode_get_attrib(xmlnode *node, const char *attr) |
| 234 | { | |
| 235 | xmlnode *x; | |
| 236 | ||
| 237 | g_return_val_if_fail(node != NULL, NULL); | |
| 24639 | 238 | g_return_val_if_fail(attr != NULL, NULL); |
| 7131 | 239 | |
| 240 | for(x = node->child; x; x = x->next) { | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
241 | if(x->type == XMLNODE_TYPE_ATTRIB && purple_strequal(attr, x->name)) { |
| 7131 | 242 | return x->data; |
| 243 | } | |
| 244 | } | |
| 245 | ||
| 246 | return NULL; | |
| 247 | } | |
| 248 | ||
| 15265 | 249 | const char * |
| 250 | xmlnode_get_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) | |
| 251 | { | |
| 252 | xmlnode *x; | |
| 253 | ||
| 254 | g_return_val_if_fail(node != NULL, NULL); | |
| 24639 | 255 | g_return_val_if_fail(attr != NULL, NULL); |
| 15265 | 256 | |
| 257 | for(x = node->child; x; x = x->next) { | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
258 | if(x->type == XMLNODE_TYPE_ATTRIB && |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
259 | purple_strequal(attr, x->name) && |
|
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
260 | purple_strequal(xmlns, x->xmlns)) { |
| 15265 | 261 | return x->data; |
| 262 | } | |
| 263 | } | |
| 264 | ||
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
265 | return NULL; |
| 15265 | 266 | } |
| 267 | ||
| 13808 | 268 | |
| 269 | void xmlnode_set_namespace(xmlnode *node, const char *xmlns) | |
| 270 | { | |
| 271 | g_return_if_fail(node != NULL); | |
| 272 | ||
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
273 | g_free(node->xmlns); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
274 | node->xmlns = g_strdup(xmlns); |
| 13808 | 275 | } |
| 276 | ||
| 277 | const char *xmlnode_get_namespace(xmlnode *node) | |
| 278 | { | |
| 279 | g_return_val_if_fail(node != NULL, NULL); | |
| 280 | ||
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
281 | return node->xmlns; |
| 13808 | 282 | } |
| 283 | ||
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
284 | void xmlnode_set_prefix(xmlnode *node, const char *prefix) |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
285 | { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
286 | g_return_if_fail(node != NULL); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
287 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
288 | g_free(node->prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
289 | node->prefix = g_strdup(prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
290 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
291 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
292 | const char *xmlnode_get_prefix(xmlnode *node) |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
293 | { |
|
21720
235394d5c7f4
Pull a bunch of bugfix only changes to im.pidgin.pidgin.2.3.1,
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21487
diff
changeset
|
294 | g_return_val_if_fail(node != NULL, NULL); |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
295 | return node->prefix; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
296 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
297 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
298 | void |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
299 | xmlnode_free(xmlnode *node) |
| 7131 | 300 | { |
| 301 | xmlnode *x, *y; | |
| 302 | ||
| 303 | g_return_if_fail(node != NULL); | |
| 304 | ||
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
305 | /* if we're part of a tree, remove ourselves from the tree first */ |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
306 | if(NULL != node->parent) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
307 | if(node->parent->child == node) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
308 | node->parent->child = node->next; |
|
19568
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
309 | if (node->parent->lastchild == node) |
|
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
310 | node->parent->lastchild = node->next; |
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
311 | } else { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
312 | xmlnode *prev = node->parent->child; |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
313 | while(prev && prev->next != node) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
314 | prev = prev->next; |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
315 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
316 | if(prev) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
317 | prev->next = node->next; |
|
19568
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
318 | if (node->parent->lastchild == node) |
|
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
319 | node->parent->lastchild = prev; |
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
320 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
321 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
322 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
323 | |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
324 | /* now free our children */ |
| 7131 | 325 | x = node->child; |
| 326 | while(x) { | |
| 327 | y = x->next; | |
| 328 | xmlnode_free(x); | |
| 329 | x = y; | |
| 330 | } | |
| 331 | ||
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
332 | /* now dispose of ourselves */ |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
333 | g_free(node->name); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
334 | g_free(node->data); |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
335 | g_free(node->xmlns); |
| 22061 | 336 | g_free(node->prefix); |
| 14386 | 337 | |
|
21720
235394d5c7f4
Pull a bunch of bugfix only changes to im.pidgin.pidgin.2.3.1,
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21487
diff
changeset
|
338 | if(node->namespace_map) |
|
235394d5c7f4
Pull a bunch of bugfix only changes to im.pidgin.pidgin.2.3.1,
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21487
diff
changeset
|
339 | g_hash_table_destroy(node->namespace_map); |
|
235394d5c7f4
Pull a bunch of bugfix only changes to im.pidgin.pidgin.2.3.1,
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
21487
diff
changeset
|
340 | |
| 15884 | 341 | PURPLE_DBUS_UNREGISTER_POINTER(node); |
| 7131 | 342 | g_free(node); |
| 343 | } | |
| 344 | ||
| 345 | xmlnode* | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
346 | xmlnode_get_child(const xmlnode *parent, const char *name) |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
347 | { |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
348 | return xmlnode_get_child_with_namespace(parent, name, NULL); |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
349 | } |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
350 | |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
351 | xmlnode * |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
352 | xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *ns) |
| 7131 | 353 | { |
| 354 | xmlnode *x, *ret = NULL; | |
| 355 | char **names; | |
| 356 | char *parent_name, *child_name; | |
| 357 | ||
| 358 | g_return_val_if_fail(parent != NULL, NULL); | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
359 | g_return_val_if_fail(name != NULL, NULL); |
| 7131 | 360 | |
| 361 | names = g_strsplit(name, "/", 2); | |
| 362 | parent_name = names[0]; | |
| 363 | child_name = names[1]; | |
| 364 | ||
| 365 | for(x = parent->child; x; x = x->next) { | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
366 | /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 8262 | 367 | const char *xmlns = NULL; |
| 368 | if(ns) | |
| 13808 | 369 | xmlns = xmlnode_get_namespace(x); |
| 8262 | 370 | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
371 | if(x->type == XMLNODE_TYPE_TAG && purple_strequal(parent_name, x->name) |
|
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
372 | && purple_strequal(ns, xmlns)) { |
| 7131 | 373 | ret = x; |
| 374 | break; | |
| 375 | } | |
| 376 | } | |
| 377 | ||
| 378 | if(child_name && ret) | |
| 8262 | 379 | ret = xmlnode_get_child(ret, child_name); |
| 7131 | 380 | |
| 381 | g_strfreev(names); | |
| 382 | return ret; | |
| 383 | } | |
| 384 | ||
| 385 | char * | |
| 386 | xmlnode_get_data(xmlnode *node) | |
| 387 | { | |
| 388 | GString *str = NULL; | |
| 389 | xmlnode *c; | |
| 390 | ||
| 391 | g_return_val_if_fail(node != NULL, NULL); | |
| 392 | ||
| 393 | for(c = node->child; c; c = c->next) { | |
| 8135 | 394 | if(c->type == XMLNODE_TYPE_DATA) { |
| 7131 | 395 | if(!str) |
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
396 | str = g_string_new_len(c->data, c->data_sz); |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
397 | else |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
398 | str = g_string_append_len(str, c->data, c->data_sz); |
| 7131 | 399 | } |
| 400 | } | |
| 401 | ||
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
402 | if (str == NULL) |
|
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
403 | return NULL; |
| 7131 | 404 | |
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
405 | return g_string_free(str, FALSE); |
| 7131 | 406 | } |
| 407 | ||
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
408 | char * |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
409 | xmlnode_get_data_unescaped(xmlnode *node) |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
410 | { |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
411 | char *escaped = xmlnode_get_data(node); |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
412 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
413 | char *unescaped = escaped ? purple_unescape_html(escaped) : NULL; |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
414 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
415 | g_free(escaped); |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
416 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
417 | return unescaped; |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
418 | } |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
419 | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
420 | static void |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
421 | xmlnode_to_str_foreach_append_ns(const char *key, const char *value, |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
422 | GString *buf) |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
423 | { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
424 | if (*key) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
425 | g_string_append_printf(buf, " xmlns:%s='%s'", key, value); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
426 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
427 | g_string_append_printf(buf, " xmlns='%s'", value); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
428 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
429 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
430 | |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
431 | static char * |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
432 | xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth) |
| 7131 | 433 | { |
| 434 | GString *text = g_string_new(""); | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
435 | const char *prefix; |
| 7131 | 436 | xmlnode *c; |
| 9837 | 437 | char *node_name, *esc, *esc2, *tab = NULL; |
| 9838 | 438 | gboolean need_end = FALSE, pretty = formatting; |
| 9837 | 439 | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
440 | g_return_val_if_fail(node != NULL, NULL); |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
441 | |
| 9837 | 442 | if(pretty && depth) { |
| 443 | tab = g_strnfill(depth, '\t'); | |
| 444 | text = g_string_append(text, tab); | |
| 445 | } | |
| 7131 | 446 | |
| 447 | node_name = g_markup_escape_text(node->name, -1); | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
448 | prefix = xmlnode_get_prefix(node); |
| 7131 | 449 | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
450 | if (prefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
451 | g_string_append_printf(text, "<%s:%s", prefix, node_name); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
452 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
453 | g_string_append_printf(text, "<%s", node_name); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
454 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
455 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
456 | if (node->namespace_map) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
457 | g_hash_table_foreach(node->namespace_map, |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
458 | (GHFunc)xmlnode_to_str_foreach_append_ns, text); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
459 | } else if (node->xmlns) { |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
460 | if(!node->parent || !purple_strequal(node->xmlns, node->parent->xmlns)) |
| 15184 | 461 | { |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
462 | char *xmlns = g_markup_escape_text(node->xmlns, -1); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
463 | g_string_append_printf(text, " xmlns='%s'", xmlns); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
464 | g_free(xmlns); |
| 15184 | 465 | } |
| 13808 | 466 | } |
| 7131 | 467 | for(c = node->child; c; c = c->next) |
| 468 | { | |
| 8135 | 469 | if(c->type == XMLNODE_TYPE_ATTRIB) { |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
470 | const char *aprefix = xmlnode_get_prefix(c); |
| 7131 | 471 | esc = g_markup_escape_text(c->name, -1); |
| 472 | esc2 = g_markup_escape_text(c->data, -1); | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
473 | if (aprefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
474 | g_string_append_printf(text, " %s:%s='%s'", aprefix, esc, esc2); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
475 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
476 | g_string_append_printf(text, " %s='%s'", esc, esc2); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
477 | } |
| 7131 | 478 | g_free(esc); |
| 479 | g_free(esc2); | |
| 8135 | 480 | } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) { |
| 9837 | 481 | if(c->type == XMLNODE_TYPE_DATA) |
| 9838 | 482 | pretty = FALSE; |
| 7131 | 483 | need_end = TRUE; |
| 484 | } | |
| 485 | } | |
| 486 | ||
| 487 | if(need_end) { | |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
488 | g_string_append_printf(text, ">%s", pretty ? NEWLINE_S : ""); |
| 7131 | 489 | |
| 490 | for(c = node->child; c; c = c->next) | |
| 491 | { | |
| 8135 | 492 | if(c->type == XMLNODE_TYPE_TAG) { |
| 7642 | 493 | int esc_len; |
| 9838 | 494 | esc = xmlnode_to_str_helper(c, &esc_len, pretty, depth+1); |
| 7642 | 495 | text = g_string_append_len(text, esc, esc_len); |
| 7131 | 496 | g_free(esc); |
| 12198 | 497 | } else if(c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) { |
| 7131 | 498 | esc = g_markup_escape_text(c->data, c->data_sz); |
| 7642 | 499 | text = g_string_append(text, esc); |
| 7131 | 500 | g_free(esc); |
| 501 | } | |
| 502 | } | |
| 503 | ||
| 9838 | 504 | if(tab && pretty) |
| 9837 | 505 | text = g_string_append(text, tab); |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
506 | if (prefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
507 | g_string_append_printf(text, "</%s:%s>%s", prefix, node_name, formatting ? NEWLINE_S : ""); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
508 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
509 | g_string_append_printf(text, "</%s>%s", node_name, formatting ? NEWLINE_S : ""); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
510 | } |
| 7131 | 511 | } else { |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
512 | g_string_append_printf(text, "/>%s", formatting ? NEWLINE_S : ""); |
| 7131 | 513 | } |
| 514 | ||
| 515 | g_free(node_name); | |
| 516 | ||
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
517 | g_free(tab); |
| 9837 | 518 | |
| 7642 | 519 | if(len) |
| 520 | *len = text->len; | |
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
521 | |
|
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
522 | return g_string_free(text, FALSE); |
| 7131 | 523 | } |
| 524 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
525 | char * |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
526 | xmlnode_to_str(xmlnode *node, int *len) |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
527 | { |
| 9837 | 528 | return xmlnode_to_str_helper(node, len, FALSE, 0); |
| 529 | } | |
| 530 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
531 | char * |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
532 | xmlnode_to_formatted_str(xmlnode *node, int *len) |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
533 | { |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
534 | char *xml, *xml_with_declaration; |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
535 | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
536 | g_return_val_if_fail(node != NULL, NULL); |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
537 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
538 | xml = xmlnode_to_str_helper(node, len, TRUE, 0); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
539 | xml_with_declaration = |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
540 | g_strdup_printf("<?xml version='1.0' encoding='UTF-8' ?>" NEWLINE_S NEWLINE_S "%s", xml); |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
541 | g_free(xml); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
542 | |
|
22083
d562c88d8327
Patch from QuLogic to correctly set the length. Closes #4515.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22061
diff
changeset
|
543 | if (len) |
|
d562c88d8327
Patch from QuLogic to correctly set the length. Closes #4515.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22061
diff
changeset
|
544 | *len += sizeof("<?xml version='1.0' encoding='UTF-8' ?>" NEWLINE_S NEWLINE_S) - 1; |
|
d562c88d8327
Patch from QuLogic to correctly set the length. Closes #4515.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22061
diff
changeset
|
545 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
546 | return xml_with_declaration; |
| 9837 | 547 | } |
| 548 | ||
| 7131 | 549 | struct _xmlnode_parser_data { |
| 550 | xmlnode *current; | |
| 15412 | 551 | gboolean error; |
| 7131 | 552 | }; |
| 553 | ||
| 13808 | 554 | static void |
| 555 | xmlnode_parser_element_start_libxml(void *user_data, | |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
556 | const xmlChar *element_name, const xmlChar *prefix, const xmlChar *xmlns, |
| 13808 | 557 | int nb_namespaces, const xmlChar **namespaces, |
| 558 | int nb_attributes, int nb_defaulted, const xmlChar **attributes) | |
| 559 | { | |
| 560 | struct _xmlnode_parser_data *xpd = user_data; | |
| 561 | xmlnode *node; | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
562 | int i, j; |
| 13808 | 563 | |
| 15412 | 564 | if(!element_name || xpd->error) { |
| 13808 | 565 | return; |
| 566 | } else { | |
| 567 | if(xpd->current) | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
568 | node = xmlnode_new_child(xpd->current, (const char*) element_name); |
| 13808 | 569 | else |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
570 | node = xmlnode_new((const char *) element_name); |
| 13808 | 571 | |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
572 | xmlnode_set_namespace(node, (const char *) xmlns); |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
573 | xmlnode_set_prefix(node, (const char *)prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
574 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
575 | if (nb_namespaces != 0) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
576 | node->namespace_map = g_hash_table_new_full( |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
577 | g_str_hash, g_str_equal, g_free, g_free); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
578 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
579 | for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
580 | const char *key = (const char *)namespaces[j]; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
581 | const char *val = (const char *)namespaces[j + 1]; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
582 | g_hash_table_insert(node->namespace_map, |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
583 | g_strdup(key ? key : ""), g_strdup(val ? val : "")); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
584 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
585 | } |
| 13808 | 586 | |
| 587 | for(i=0; i < nb_attributes * 5; i+=5) { | |
|
21487
f355ec220186
Explicitly cast from xmlChar (== unsigned char) to char, squishing a warning.
Will Thompson <resiak@pidgin.im>
parents:
21454
diff
changeset
|
588 | const char *prefix = (const char *)attributes[i + 1]; |
|
14290
f20819ff8d86
[gaim-migrate @ 16910]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
589 | char *txt; |
| 13808 | 590 | int attrib_len = attributes[i+4] - attributes[i+3]; |
| 591 | char *attrib = g_malloc(attrib_len + 1); | |
| 592 | memcpy(attrib, attributes[i+3], attrib_len); | |
| 593 | attrib[attrib_len] = '\0'; | |
|
14290
f20819ff8d86
[gaim-migrate @ 16910]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
594 | txt = attrib; |
| 15884 | 595 | attrib = purple_unescape_html(txt); |
|
14233
4f5fe687b21d
[gaim-migrate @ 16821]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14097
diff
changeset
|
596 | g_free(txt); |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
597 | if (prefix && *prefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
598 | xmlnode_set_attrib_with_prefix(node, (const char*) attributes[i], prefix, attrib); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
599 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
600 | xmlnode_set_attrib(node, (const char*) attributes[i], attrib); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
601 | } |
| 13808 | 602 | g_free(attrib); |
| 603 | } | |
| 604 | ||
| 605 | xpd->current = node; | |
| 606 | } | |
| 607 | } | |
| 608 | ||
| 609 | static void | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
610 | xmlnode_parser_element_end_libxml(void *user_data, const xmlChar *element_name, |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
611 | const xmlChar *prefix, const xmlChar *xmlns) |
| 13808 | 612 | { |
| 613 | struct _xmlnode_parser_data *xpd = user_data; | |
| 614 | ||
| 15412 | 615 | if(!element_name || !xpd->current || xpd->error) |
| 13808 | 616 | return; |
| 617 | ||
| 618 | if(xpd->current->parent) { | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
619 | if(!xmlStrcmp((xmlChar*) xpd->current->name, element_name)) |
| 13808 | 620 | xpd->current = xpd->current->parent; |
| 621 | } | |
| 622 | } | |
| 623 | ||
| 624 | static void | |
| 625 | xmlnode_parser_element_text_libxml(void *user_data, const xmlChar *text, int text_len) | |
| 626 | { | |
| 627 | struct _xmlnode_parser_data *xpd = user_data; | |
| 628 | ||
| 15412 | 629 | if(!xpd->current || xpd->error) |
| 13808 | 630 | return; |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
25859
diff
changeset
|
631 | |
| 13808 | 632 | if(!text || !text_len) |
| 633 | return; | |
| 634 | ||
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
635 | xmlnode_insert_data(xpd->current, (const char*) text, text_len); |
| 13808 | 636 | } |
| 637 | ||
| 15412 | 638 | static void |
| 639 | xmlnode_parser_error_libxml(void *user_data, const char *msg, ...) | |
| 640 | { | |
| 641 | struct _xmlnode_parser_data *xpd = user_data; | |
|
19821
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
642 | char errmsg[2048]; |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
643 | va_list args; |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
644 | |
| 15412 | 645 | xpd->error = TRUE; |
|
19821
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
646 | |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
647 | va_start(args, msg); |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
648 | vsnprintf(errmsg, sizeof(errmsg), msg, args); |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
649 | va_end(args); |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
650 | |
|
25301
d81daadd1bee
Error messages from libxml contain their own newlines
Mark Doliner <markdoliner@pidgin.im>
parents:
24639
diff
changeset
|
651 | purple_debug_error("xmlnode", "Error parsing xml file: %s", errmsg); |
| 15412 | 652 | } |
| 653 | ||
| 13808 | 654 | static xmlSAXHandler xmlnode_parser_libxml = { |
|
17550
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
655 | NULL, /* internalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
656 | NULL, /* isStandalone */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
657 | NULL, /* hasInternalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
658 | NULL, /* hasExternalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
659 | NULL, /* resolveEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
660 | NULL, /* getEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
661 | NULL, /* entityDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
662 | NULL, /* notationDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
663 | NULL, /* attributeDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
664 | NULL, /* elementDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
665 | NULL, /* unparsedEntityDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
666 | NULL, /* setDocumentLocator */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
667 | NULL, /* startDocument */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
668 | NULL, /* endDocument */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
669 | NULL, /* startElement */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
670 | NULL, /* endElement */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
671 | NULL, /* reference */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
672 | xmlnode_parser_element_text_libxml, /* characters */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
673 | NULL, /* ignorableWhitespace */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
674 | NULL, /* processingInstruction */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
675 | NULL, /* comment */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
676 | NULL, /* warning */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
677 | xmlnode_parser_error_libxml, /* error */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
678 | NULL, /* fatalError */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
679 | NULL, /* getParameterEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
680 | NULL, /* cdataBlock */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
681 | NULL, /* externalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
682 | XML_SAX2_MAGIC, /* initialized */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
683 | NULL, /* _private */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
684 | xmlnode_parser_element_start_libxml, /* startElementNs */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
685 | xmlnode_parser_element_end_libxml, /* endElementNs */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
686 | NULL, /* serror */ |
| 13808 | 687 | }; |
| 7131 | 688 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
689 | xmlnode * |
| 10848 | 690 | xmlnode_from_str(const char *str, gssize size) |
| 7131 | 691 | { |
| 11390 | 692 | struct _xmlnode_parser_data *xpd; |
| 7131 | 693 | xmlnode *ret; |
| 11390 | 694 | gsize real_size; |
| 7131 | 695 | |
| 11390 | 696 | g_return_val_if_fail(str != NULL, NULL); |
| 697 | ||
|
11705
8200a990caf1
[gaim-migrate @ 13996]
Richard Laager <rlaager@pidgin.im>
parents:
11390
diff
changeset
|
698 | real_size = size < 0 ? strlen(str) : size; |
| 11390 | 699 | xpd = g_new0(struct _xmlnode_parser_data, 1); |
| 13808 | 700 | |
| 14384 | 701 | if (xmlSAXUserParseMemory(&xmlnode_parser_libxml, xpd, str, real_size) < 0) { |
| 13808 | 702 | while(xpd->current && xpd->current->parent) |
| 703 | xpd->current = xpd->current->parent; | |
| 704 | if(xpd->current) | |
| 705 | xmlnode_free(xpd->current); | |
| 706 | xpd->current = NULL; | |
| 707 | } | |
| 7131 | 708 | ret = xpd->current; |
| 15412 | 709 | if (xpd->error) { |
| 710 | ret = NULL; | |
| 711 | if (xpd->current) | |
| 712 | xmlnode_free(xpd->current); | |
| 713 | } | |
| 714 | ||
| 7131 | 715 | g_free(xpd); |
| 716 | return ret; | |
| 717 | } | |
| 8135 | 718 | |
|
23964
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
719 | xmlnode * |
|
23972
90e0da03c053
theme loader cleanup, and remove a few warnings
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23964
diff
changeset
|
720 | xmlnode_from_file(const char *dir,const char *filename, const char *description, const char *process) |
|
23964
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
721 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
722 | gchar *filename_full; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
723 | GError *error = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
724 | gchar *contents = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
725 | gsize length; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
726 | xmlnode *node = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
727 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
728 | g_return_val_if_fail(dir != NULL, NULL); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
729 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
730 | purple_debug_info(process, "Reading file %s from directory %s\n", |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
731 | filename, dir); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
732 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
733 | filename_full = g_build_filename(dir, filename, NULL); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
734 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
735 | if (!g_file_test(filename_full, G_FILE_TEST_EXISTS)) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
736 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
737 | purple_debug_info(process, "File %s does not exist (this is not " |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
738 | "necessarily an error)\n", filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
739 | g_free(filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
740 | return NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
741 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
742 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
743 | if (!g_file_get_contents(filename_full, &contents, &length, &error)) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
744 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
745 | purple_debug_error(process, "Error reading file %s: %s\n", |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
746 | filename_full, error->message); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
747 | g_error_free(error); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
748 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
749 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
750 | if ((contents != NULL) && (length > 0)) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
751 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
752 | node = xmlnode_from_str(contents, length); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
753 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
754 | /* If we were unable to parse the file then save its contents to a backup file */ |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
755 | if (node == NULL) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
756 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
757 | gchar *filename_temp, *filename_temp_full; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
758 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
759 | filename_temp = g_strdup_printf("%s~", filename); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
760 | filename_temp_full = g_build_filename(dir, filename_temp, NULL); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
761 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
762 | purple_debug_error("util", "Error parsing file %s. Renaming old " |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
763 | "file to %s\n", filename_full, filename_temp); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
764 | purple_util_write_data_to_file_absolute(filename_temp_full, contents, length); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
765 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
766 | g_free(filename_temp_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
767 | g_free(filename_temp); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
768 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
769 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
770 | g_free(contents); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
771 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
772 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
773 | /* If we could not parse the file then show the user an error message */ |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
774 | if (node == NULL) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
775 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
776 | gchar *title, *msg; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
777 | title = g_strdup_printf(_("Error Reading %s"), filename); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
778 | msg = g_strdup_printf(_("An error was encountered reading your " |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
779 | "%s. The file has not been loaded, and the old file " |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
780 | "has been renamed to %s~."), description, filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
781 | purple_notify_error(NULL, NULL, title, msg); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
782 | g_free(title); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
783 | g_free(msg); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
784 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
785 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
786 | g_free(filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
787 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
788 | return node; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
789 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
790 | |
|
23821
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
791 | static void |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
792 | xmlnode_copy_foreach_ns(gpointer key, gpointer value, gpointer user_data) |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
793 | { |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
794 | GHashTable *ret = (GHashTable *)user_data; |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
795 | g_hash_table_insert(ret, g_strdup(key), g_strdup(value)); |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
796 | } |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
797 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
798 | xmlnode * |
|
15609
e432251bd57e
sf patch #1647731, from Markus Elfring
Mark Doliner <markdoliner@pidgin.im>
parents:
15435
diff
changeset
|
799 | xmlnode_copy(const xmlnode *src) |
| 8135 | 800 | { |
| 801 | xmlnode *ret; | |
| 802 | xmlnode *child; | |
| 803 | xmlnode *sibling = NULL; | |
| 804 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
805 | g_return_val_if_fail(src != NULL, NULL); |
| 8135 | 806 | |
| 807 | ret = new_node(src->name, src->type); | |
|
17825
ced38a45f560
Fixed a bug in xmlnode_copy, it didn't preserve the namespace in the copy.
Andreas Monitzer <am@adiumx.com>
parents:
15979
diff
changeset
|
808 | ret->xmlns = g_strdup(src->xmlns); |
|
23821
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
809 | if (src->data) { |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
810 | if (src->data_sz) { |
| 8167 | 811 | ret->data = g_memdup(src->data, src->data_sz); |
| 812 | ret->data_sz = src->data_sz; | |
| 813 | } else { | |
| 814 | ret->data = g_strdup(src->data); | |
| 815 | } | |
| 8135 | 816 | } |
|
23821
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
817 | ret->prefix = g_strdup(src->prefix); |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
818 | if (src->namespace_map) { |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
819 | ret->namespace_map = g_hash_table_new_full(g_str_hash, g_str_equal, |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
820 | g_free, g_free); |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
821 | g_hash_table_foreach(src->namespace_map, xmlnode_copy_foreach_ns, ret->namespace_map); |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
822 | } |
| 8135 | 823 | |
|
23821
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
824 | for (child = src->child; child; child = child->next) { |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
825 | if (sibling) { |
| 8135 | 826 | sibling->next = xmlnode_copy(child); |
| 827 | sibling = sibling->next; | |
| 828 | } else { | |
| 829 | ret->child = xmlnode_copy(child); | |
| 830 | sibling = ret->child; | |
| 831 | } | |
| 832 | sibling->parent = ret; | |
| 833 | } | |
| 834 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
835 | ret->lastchild = sibling; |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
836 | |
| 8135 | 837 | return ret; |
| 838 | } | |
| 839 | ||
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
840 | xmlnode * |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
841 | xmlnode_get_next_twin(xmlnode *node) |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
842 | { |
| 8135 | 843 | xmlnode *sibling; |
| 13808 | 844 | const char *ns = xmlnode_get_namespace(node); |
| 8135 | 845 | |
| 846 | g_return_val_if_fail(node != NULL, NULL); | |
| 847 | g_return_val_if_fail(node->type == XMLNODE_TYPE_TAG, NULL); | |
| 848 | ||
| 849 | for(sibling = node->next; sibling; sibling = sibling->next) { | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
850 | /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 8283 | 851 | const char *xmlns = NULL; |
| 8262 | 852 | if(ns) |
| 13808 | 853 | xmlns = xmlnode_get_namespace(sibling); |
| 8262 | 854 | |
|
25859
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
855 | if(sibling->type == XMLNODE_TYPE_TAG && purple_strequal(node->name, sibling->name) && |
|
b42be7bb9dac
Patch from Paul Aurich to add purple_strequal to help readability and simplicity of code. Ie, don't need to negate the value of strcmp, since this does a strcmp and does the negation for us
Paul Aurich <darkrain42@pidgin.im>
parents:
25854
diff
changeset
|
856 | purple_strequal(ns, xmlns)) |
| 8135 | 857 | return sibling; |
| 858 | } | |
| 859 | ||
| 860 | return NULL; | |
| 861 | } |