Fri, 19 Oct 2007 18:27:12 +0000
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
through 525a410c03e7e16535f3fe683f9651283109265d
applied changes from 525a410c03e7e16535f3fe683f9651283109265d
through d4b316d73ebaf93803ca2642e78b8821c3b5d5c7
| 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 && |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
132 | !strcmp(attr_node->name, attr)) |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
133 | { |
| 7131 | 134 | if(node->child == attr_node) { |
| 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 | ||
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
149 | /* Compare two nullable xmlns strings. |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
150 | * They are considered equal if they're both NULL or the strings are equal |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
151 | */ |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
152 | static gboolean _xmlnode_compare_xmlns(const char *xmlns1, const char *xmlns2) { |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
153 | gboolean equal = FALSE; |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
154 | |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
155 | if (xmlns1 == NULL && xmlns2 == NULL) |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
156 | equal = TRUE; |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
157 | else if (xmlns1 != NULL && xmlns2 != NULL && !strcmp(xmlns1, xmlns2)) |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
158 | equal = TRUE; |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
159 | |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
160 | return equal; |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
161 | } |
| 15265 | 162 | |
| 163 | void | |
| 164 | xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) | |
| 165 | { | |
| 166 | xmlnode *attr_node, *sibling = NULL; | |
| 167 | ||
| 168 | g_return_if_fail(node != NULL); | |
| 169 | g_return_if_fail(attr != NULL); | |
| 170 | ||
| 171 | for(attr_node = node->child; attr_node; attr_node = attr_node->next) | |
| 172 | { | |
| 173 | if(attr_node->type == XMLNODE_TYPE_ATTRIB && | |
| 174 | !strcmp(attr_node->name, attr) && | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
175 | _xmlnode_compare_xmlns(xmlns, attr_node->xmlns)) |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
176 | { |
| 15265 | 177 | if(node->child == attr_node) { |
| 178 | node->child = attr_node->next; | |
| 179 | } else { | |
| 180 | sibling->next = attr_node->next; | |
| 181 | } | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
182 | if (node->lastchild == attr_node) { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
183 | node->lastchild = sibling; |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
184 | } |
| 15265 | 185 | xmlnode_free(attr_node); |
| 186 | return; | |
| 187 | } | |
| 188 | sibling = attr_node; | |
| 189 | } | |
| 190 | } | |
| 191 | ||
| 7131 | 192 | void |
| 193 | xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value) | |
| 194 | { | |
| 195 | xmlnode *attrib_node; | |
| 196 | ||
| 197 | g_return_if_fail(node != NULL); | |
| 198 | g_return_if_fail(attr != NULL); | |
| 199 | g_return_if_fail(value != NULL); | |
| 200 | ||
| 201 | xmlnode_remove_attrib(node, attr); | |
| 202 | ||
| 8135 | 203 | attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); |
| 7131 | 204 | |
| 205 | attrib_node->data = g_strdup(value); | |
| 206 | ||
| 207 | xmlnode_insert_child(node, attrib_node); | |
| 208 | } | |
| 209 | ||
| 15265 | 210 | void |
| 211 | xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value) | |
| 212 | { | |
| 213 | xmlnode *attrib_node; | |
| 214 | ||
| 215 | g_return_if_fail(node != NULL); | |
| 216 | g_return_if_fail(attr != NULL); | |
| 217 | g_return_if_fail(value != NULL); | |
| 218 | ||
| 219 | xmlnode_remove_attrib_with_namespace(node, attr, xmlns); | |
| 220 | ||
| 221 | attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); | |
| 222 | ||
| 223 | attrib_node->data = g_strdup(value); | |
| 224 | attrib_node->xmlns = g_strdup(xmlns); | |
| 225 | ||
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
226 | xmlnode_insert_child(node, attrib_node); |
| 15265 | 227 | } |
| 228 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
229 | const char * |
| 7131 | 230 | xmlnode_get_attrib(xmlnode *node, const char *attr) |
| 231 | { | |
| 232 | xmlnode *x; | |
| 233 | ||
| 234 | g_return_val_if_fail(node != NULL, NULL); | |
| 235 | ||
| 236 | for(x = node->child; x; x = x->next) { | |
| 8135 | 237 | if(x->type == XMLNODE_TYPE_ATTRIB && !strcmp(attr, x->name)) { |
| 7131 | 238 | return x->data; |
| 239 | } | |
| 240 | } | |
| 241 | ||
| 242 | return NULL; | |
| 243 | } | |
| 244 | ||
| 15265 | 245 | const char * |
| 246 | xmlnode_get_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) | |
| 247 | { | |
| 248 | xmlnode *x; | |
| 249 | ||
| 250 | g_return_val_if_fail(node != NULL, NULL); | |
| 251 | ||
| 252 | for(x = node->child; x; x = x->next) { | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
253 | if(x->type == XMLNODE_TYPE_ATTRIB && |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
254 | !strcmp(attr, x->name) && |
|
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
255 | _xmlnode_compare_xmlns(xmlns, x->xmlns)) { |
| 15265 | 256 | return x->data; |
| 257 | } | |
| 258 | } | |
| 259 | ||
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
260 | return NULL; |
| 15265 | 261 | } |
| 262 | ||
| 13808 | 263 | |
| 264 | void xmlnode_set_namespace(xmlnode *node, const char *xmlns) | |
| 265 | { | |
| 266 | g_return_if_fail(node != NULL); | |
| 267 | ||
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
268 | g_free(node->xmlns); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
269 | node->xmlns = g_strdup(xmlns); |
| 13808 | 270 | } |
| 271 | ||
| 272 | const char *xmlnode_get_namespace(xmlnode *node) | |
| 273 | { | |
| 274 | g_return_val_if_fail(node != NULL, NULL); | |
| 275 | ||
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
276 | return node->xmlns; |
| 13808 | 277 | } |
| 278 | ||
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
279 | void |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
280 | xmlnode_free(xmlnode *node) |
| 7131 | 281 | { |
| 282 | xmlnode *x, *y; | |
| 283 | ||
| 284 | g_return_if_fail(node != NULL); | |
| 285 | ||
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
286 | /* 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
|
287 | if(NULL != node->parent) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
288 | if(node->parent->child == node) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
289 | node->parent->child = node->next; |
|
19568
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
290 | if (node->parent->lastchild == node) |
|
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
291 | node->parent->lastchild = node->next; |
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
292 | } else { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
293 | xmlnode *prev = node->parent->child; |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
294 | while(prev && prev->next != node) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
295 | prev = prev->next; |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
296 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
297 | if(prev) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
298 | prev->next = node->next; |
|
19568
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
299 | if (node->parent->lastchild == node) |
|
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
300 | node->parent->lastchild = prev; |
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
301 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
302 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
303 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
304 | |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
305 | /* now free our children */ |
| 7131 | 306 | x = node->child; |
| 307 | while(x) { | |
| 308 | y = x->next; | |
| 309 | xmlnode_free(x); | |
| 310 | x = y; | |
| 311 | } | |
| 312 | ||
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
313 | /* now dispose of ourselves */ |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
314 | g_free(node->name); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
315 | g_free(node->data); |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
316 | g_free(node->xmlns); |
| 14386 | 317 | |
| 15884 | 318 | PURPLE_DBUS_UNREGISTER_POINTER(node); |
| 7131 | 319 | g_free(node); |
| 320 | } | |
| 321 | ||
| 322 | xmlnode* | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
323 | xmlnode_get_child(const xmlnode *parent, const char *name) |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
324 | { |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
325 | return xmlnode_get_child_with_namespace(parent, name, NULL); |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
326 | } |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
327 | |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
328 | xmlnode * |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
329 | xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *ns) |
| 7131 | 330 | { |
| 331 | xmlnode *x, *ret = NULL; | |
| 332 | char **names; | |
| 333 | char *parent_name, *child_name; | |
| 334 | ||
| 335 | g_return_val_if_fail(parent != NULL, NULL); | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
336 | g_return_val_if_fail(name != NULL, NULL); |
| 7131 | 337 | |
| 338 | names = g_strsplit(name, "/", 2); | |
| 339 | parent_name = names[0]; | |
| 340 | child_name = names[1]; | |
| 341 | ||
| 342 | for(x = parent->child; x; x = x->next) { | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
343 | /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 8262 | 344 | const char *xmlns = NULL; |
| 345 | if(ns) | |
| 13808 | 346 | xmlns = xmlnode_get_namespace(x); |
| 8262 | 347 | |
| 348 | if(x->type == XMLNODE_TYPE_TAG && name && !strcmp(parent_name, x->name) | |
| 349 | && (!ns || (xmlns && !strcmp(ns, xmlns)))) { | |
| 7131 | 350 | ret = x; |
| 351 | break; | |
| 352 | } | |
| 353 | } | |
| 354 | ||
| 355 | if(child_name && ret) | |
| 8262 | 356 | ret = xmlnode_get_child(ret, child_name); |
| 7131 | 357 | |
| 358 | g_strfreev(names); | |
| 359 | return ret; | |
| 360 | } | |
| 361 | ||
| 362 | char * | |
| 363 | xmlnode_get_data(xmlnode *node) | |
| 364 | { | |
| 365 | GString *str = NULL; | |
| 366 | xmlnode *c; | |
| 367 | ||
| 368 | g_return_val_if_fail(node != NULL, NULL); | |
| 369 | ||
| 370 | for(c = node->child; c; c = c->next) { | |
| 8135 | 371 | if(c->type == XMLNODE_TYPE_DATA) { |
| 7131 | 372 | 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
|
373 | 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
|
374 | else |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
375 | str = g_string_append_len(str, c->data, c->data_sz); |
| 7131 | 376 | } |
| 377 | } | |
| 378 | ||
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
379 | if (str == NULL) |
|
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
380 | return NULL; |
| 7131 | 381 | |
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
382 | return g_string_free(str, FALSE); |
| 7131 | 383 | } |
| 384 | ||
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
385 | char * |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
386 | 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
|
387 | { |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
388 | 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
|
389 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
390 | 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
|
391 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
392 | 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
|
393 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
394 | return unescaped; |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
395 | } |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
396 | |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
397 | static char * |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
398 | xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth) |
| 7131 | 399 | { |
| 400 | GString *text = g_string_new(""); | |
| 401 | xmlnode *c; | |
| 9837 | 402 | char *node_name, *esc, *esc2, *tab = NULL; |
| 9838 | 403 | gboolean need_end = FALSE, pretty = formatting; |
| 9837 | 404 | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
405 | g_return_val_if_fail(node != NULL, NULL); |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
406 | |
| 9837 | 407 | if(pretty && depth) { |
| 408 | tab = g_strnfill(depth, '\t'); | |
| 409 | text = g_string_append(text, tab); | |
| 410 | } | |
| 7131 | 411 | |
| 412 | node_name = g_markup_escape_text(node->name, -1); | |
| 413 | g_string_append_printf(text, "<%s", node_name); | |
| 414 | ||
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
415 | if (node->xmlns) { |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
416 | if(!node->parent || !node->parent->xmlns || strcmp(node->xmlns, node->parent->xmlns)) |
| 15184 | 417 | { |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
418 | char *xmlns = g_markup_escape_text(node->xmlns, -1); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
419 | g_string_append_printf(text, " xmlns='%s'", xmlns); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
420 | g_free(xmlns); |
| 15184 | 421 | } |
| 13808 | 422 | } |
| 7131 | 423 | for(c = node->child; c; c = c->next) |
| 424 | { | |
| 8135 | 425 | if(c->type == XMLNODE_TYPE_ATTRIB) { |
| 7131 | 426 | esc = g_markup_escape_text(c->name, -1); |
| 427 | esc2 = g_markup_escape_text(c->data, -1); | |
| 428 | g_string_append_printf(text, " %s='%s'", esc, esc2); | |
| 429 | g_free(esc); | |
| 430 | g_free(esc2); | |
| 8135 | 431 | } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) { |
| 9837 | 432 | if(c->type == XMLNODE_TYPE_DATA) |
| 9838 | 433 | pretty = FALSE; |
| 7131 | 434 | need_end = TRUE; |
| 435 | } | |
| 436 | } | |
| 437 | ||
| 438 | if(need_end) { | |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
439 | g_string_append_printf(text, ">%s", pretty ? NEWLINE_S : ""); |
| 7131 | 440 | |
| 441 | for(c = node->child; c; c = c->next) | |
| 442 | { | |
| 8135 | 443 | if(c->type == XMLNODE_TYPE_TAG) { |
| 7642 | 444 | int esc_len; |
| 9838 | 445 | esc = xmlnode_to_str_helper(c, &esc_len, pretty, depth+1); |
| 7642 | 446 | text = g_string_append_len(text, esc, esc_len); |
| 7131 | 447 | g_free(esc); |
| 12198 | 448 | } else if(c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) { |
| 7131 | 449 | esc = g_markup_escape_text(c->data, c->data_sz); |
| 7642 | 450 | text = g_string_append(text, esc); |
| 7131 | 451 | g_free(esc); |
| 452 | } | |
| 453 | } | |
| 454 | ||
| 9838 | 455 | if(tab && pretty) |
| 9837 | 456 | text = g_string_append(text, tab); |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
457 | g_string_append_printf(text, "</%s>%s", node_name, formatting ? NEWLINE_S : ""); |
| 7131 | 458 | } else { |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
459 | g_string_append_printf(text, "/>%s", formatting ? NEWLINE_S : ""); |
| 7131 | 460 | } |
| 461 | ||
| 462 | g_free(node_name); | |
| 463 | ||
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
464 | g_free(tab); |
| 9837 | 465 | |
| 7642 | 466 | if(len) |
| 467 | *len = text->len; | |
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
468 | |
|
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
469 | return g_string_free(text, FALSE); |
| 7131 | 470 | } |
| 471 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
472 | char * |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
473 | xmlnode_to_str(xmlnode *node, int *len) |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
474 | { |
| 9837 | 475 | return xmlnode_to_str_helper(node, len, FALSE, 0); |
| 476 | } | |
| 477 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
478 | char * |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
479 | xmlnode_to_formatted_str(xmlnode *node, int *len) |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
480 | { |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
481 | char *xml, *xml_with_declaration; |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
482 | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
483 | g_return_val_if_fail(node != NULL, NULL); |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
484 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
485 | xml = xmlnode_to_str_helper(node, len, TRUE, 0); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
486 | xml_with_declaration = |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
487 | 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
|
488 | g_free(xml); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
489 | |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
490 | return xml_with_declaration; |
| 9837 | 491 | } |
| 492 | ||
| 7131 | 493 | struct _xmlnode_parser_data { |
| 494 | xmlnode *current; | |
| 15412 | 495 | gboolean error; |
| 7131 | 496 | }; |
| 497 | ||
| 13808 | 498 | static void |
| 499 | xmlnode_parser_element_start_libxml(void *user_data, | |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
500 | const xmlChar *element_name, const xmlChar *prefix, const xmlChar *xmlns, |
| 13808 | 501 | int nb_namespaces, const xmlChar **namespaces, |
| 502 | int nb_attributes, int nb_defaulted, const xmlChar **attributes) | |
| 503 | { | |
| 504 | struct _xmlnode_parser_data *xpd = user_data; | |
| 505 | xmlnode *node; | |
| 506 | int i; | |
| 507 | ||
| 15412 | 508 | if(!element_name || xpd->error) { |
| 13808 | 509 | return; |
| 510 | } else { | |
| 511 | if(xpd->current) | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
512 | node = xmlnode_new_child(xpd->current, (const char*) element_name); |
| 13808 | 513 | else |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
514 | node = xmlnode_new((const char *) element_name); |
| 13808 | 515 | |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
516 | xmlnode_set_namespace(node, (const char *) xmlns); |
| 13808 | 517 | |
| 518 | for(i=0; i < nb_attributes * 5; i+=5) { | |
|
14290
f20819ff8d86
[gaim-migrate @ 16910]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
519 | char *txt; |
| 13808 | 520 | int attrib_len = attributes[i+4] - attributes[i+3]; |
| 521 | char *attrib = g_malloc(attrib_len + 1); | |
| 522 | memcpy(attrib, attributes[i+3], attrib_len); | |
| 523 | attrib[attrib_len] = '\0'; | |
|
14290
f20819ff8d86
[gaim-migrate @ 16910]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
524 | txt = attrib; |
| 15884 | 525 | attrib = purple_unescape_html(txt); |
|
14233
4f5fe687b21d
[gaim-migrate @ 16821]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14097
diff
changeset
|
526 | g_free(txt); |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
527 | xmlnode_set_attrib(node, (const char*) attributes[i], attrib); |
| 13808 | 528 | g_free(attrib); |
| 529 | } | |
| 530 | ||
| 531 | xpd->current = node; | |
| 532 | } | |
| 533 | } | |
| 534 | ||
| 535 | static void | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
536 | 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
|
537 | const xmlChar *prefix, const xmlChar *xmlns) |
| 13808 | 538 | { |
| 539 | struct _xmlnode_parser_data *xpd = user_data; | |
| 540 | ||
| 15412 | 541 | if(!element_name || !xpd->current || xpd->error) |
| 13808 | 542 | return; |
| 543 | ||
| 544 | if(xpd->current->parent) { | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
545 | if(!xmlStrcmp((xmlChar*) xpd->current->name, element_name)) |
| 13808 | 546 | xpd->current = xpd->current->parent; |
| 547 | } | |
| 548 | } | |
| 549 | ||
| 550 | static void | |
| 551 | xmlnode_parser_element_text_libxml(void *user_data, const xmlChar *text, int text_len) | |
| 552 | { | |
| 553 | struct _xmlnode_parser_data *xpd = user_data; | |
| 554 | ||
| 15412 | 555 | if(!xpd->current || xpd->error) |
| 13808 | 556 | return; |
| 15412 | 557 | |
| 13808 | 558 | if(!text || !text_len) |
| 559 | return; | |
| 560 | ||
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
561 | xmlnode_insert_data(xpd->current, (const char*) text, text_len); |
| 13808 | 562 | } |
| 563 | ||
| 15412 | 564 | static void |
| 565 | xmlnode_parser_error_libxml(void *user_data, const char *msg, ...) | |
| 566 | { | |
| 567 | 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
|
568 | char errmsg[2048]; |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
569 | va_list args; |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
570 | |
| 15412 | 571 | 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
|
572 | |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
573 | 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
|
574 | 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
|
575 | va_end(args); |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
576 | |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
577 | purple_debug_error("xmlnode", "Error parsing xml file: %s\n", errmsg); |
| 15412 | 578 | } |
| 579 | ||
| 13808 | 580 | static xmlSAXHandler xmlnode_parser_libxml = { |
|
17550
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
581 | NULL, /* internalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
582 | NULL, /* isStandalone */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
583 | NULL, /* hasInternalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
584 | NULL, /* hasExternalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
585 | NULL, /* resolveEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
586 | NULL, /* getEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
587 | NULL, /* entityDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
588 | NULL, /* notationDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
589 | NULL, /* attributeDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
590 | NULL, /* elementDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
591 | NULL, /* unparsedEntityDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
592 | NULL, /* setDocumentLocator */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
593 | NULL, /* startDocument */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
594 | NULL, /* endDocument */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
595 | NULL, /* startElement */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
596 | NULL, /* endElement */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
597 | NULL, /* reference */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
598 | xmlnode_parser_element_text_libxml, /* characters */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
599 | NULL, /* ignorableWhitespace */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
600 | NULL, /* processingInstruction */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
601 | NULL, /* comment */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
602 | NULL, /* warning */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
603 | xmlnode_parser_error_libxml, /* error */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
604 | NULL, /* fatalError */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
605 | NULL, /* getParameterEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
606 | NULL, /* cdataBlock */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
607 | NULL, /* externalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
608 | XML_SAX2_MAGIC, /* initialized */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
609 | NULL, /* _private */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
610 | xmlnode_parser_element_start_libxml, /* startElementNs */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
611 | xmlnode_parser_element_end_libxml, /* endElementNs */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
612 | NULL, /* serror */ |
| 13808 | 613 | }; |
| 7131 | 614 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
615 | xmlnode * |
| 10848 | 616 | xmlnode_from_str(const char *str, gssize size) |
| 7131 | 617 | { |
| 11390 | 618 | struct _xmlnode_parser_data *xpd; |
| 7131 | 619 | xmlnode *ret; |
| 11390 | 620 | gsize real_size; |
| 7131 | 621 | |
| 11390 | 622 | g_return_val_if_fail(str != NULL, NULL); |
| 623 | ||
|
11705
8200a990caf1
[gaim-migrate @ 13996]
Richard Laager <rlaager@pidgin.im>
parents:
11390
diff
changeset
|
624 | real_size = size < 0 ? strlen(str) : size; |
| 11390 | 625 | xpd = g_new0(struct _xmlnode_parser_data, 1); |
| 13808 | 626 | |
| 14384 | 627 | if (xmlSAXUserParseMemory(&xmlnode_parser_libxml, xpd, str, real_size) < 0) { |
| 13808 | 628 | while(xpd->current && xpd->current->parent) |
| 629 | xpd->current = xpd->current->parent; | |
| 630 | if(xpd->current) | |
| 631 | xmlnode_free(xpd->current); | |
| 632 | xpd->current = NULL; | |
| 633 | } | |
| 7131 | 634 | ret = xpd->current; |
| 15412 | 635 | if (xpd->error) { |
| 636 | ret = NULL; | |
| 637 | if (xpd->current) | |
| 638 | xmlnode_free(xpd->current); | |
| 639 | } | |
| 640 | ||
| 7131 | 641 | g_free(xpd); |
| 642 | return ret; | |
| 643 | } | |
| 8135 | 644 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
645 | xmlnode * |
|
15609
e432251bd57e
sf patch #1647731, from Markus Elfring
Mark Doliner <markdoliner@pidgin.im>
parents:
15435
diff
changeset
|
646 | xmlnode_copy(const xmlnode *src) |
| 8135 | 647 | { |
| 648 | xmlnode *ret; | |
| 649 | xmlnode *child; | |
| 650 | xmlnode *sibling = NULL; | |
| 651 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
652 | g_return_val_if_fail(src != NULL, NULL); |
| 8135 | 653 | |
| 654 | 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
|
655 | ret->xmlns = g_strdup(src->xmlns); |
| 8135 | 656 | if(src->data) { |
| 8167 | 657 | if(src->data_sz) { |
| 658 | ret->data = g_memdup(src->data, src->data_sz); | |
| 659 | ret->data_sz = src->data_sz; | |
| 660 | } else { | |
| 661 | ret->data = g_strdup(src->data); | |
| 662 | } | |
| 8135 | 663 | } |
| 664 | ||
| 665 | for(child = src->child; child; child = child->next) { | |
| 666 | if(sibling) { | |
| 667 | sibling->next = xmlnode_copy(child); | |
| 668 | sibling = sibling->next; | |
| 669 | } else { | |
| 670 | ret->child = xmlnode_copy(child); | |
| 671 | sibling = ret->child; | |
| 672 | } | |
| 673 | sibling->parent = ret; | |
| 674 | } | |
| 675 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
676 | ret->lastchild = sibling; |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
677 | |
| 8135 | 678 | return ret; |
| 679 | } | |
| 680 | ||
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
681 | xmlnode * |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
682 | xmlnode_get_next_twin(xmlnode *node) |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
683 | { |
| 8135 | 684 | xmlnode *sibling; |
| 13808 | 685 | const char *ns = xmlnode_get_namespace(node); |
| 8135 | 686 | |
| 687 | g_return_val_if_fail(node != NULL, NULL); | |
| 688 | g_return_val_if_fail(node->type == XMLNODE_TYPE_TAG, NULL); | |
| 689 | ||
| 690 | for(sibling = node->next; sibling; sibling = sibling->next) { | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
691 | /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 8283 | 692 | const char *xmlns = NULL; |
| 8262 | 693 | if(ns) |
| 13808 | 694 | xmlns = xmlnode_get_namespace(sibling); |
| 8262 | 695 | |
| 696 | if(sibling->type == XMLNODE_TYPE_TAG && !strcmp(node->name, sibling->name) && | |
| 697 | (!ns || (xmlns && !strcmp(ns, xmlns)))) | |
| 8135 | 698 | return sibling; |
| 699 | } | |
| 700 | ||
| 701 | return NULL; | |
| 702 | } |