Mon, 22 Nov 2010 10:49:06 +0000
disapproval of revision '11ffbabefd9dafd4cb3dda26da42938a9ed94e38'
| 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 */ | |
|
26393
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
30 | #define _PURPLE_XMLNODE_C_ |
| 7131 | 31 | |
|
28981
4e3922ab4844
Include 'internal.h' before all other headers to make some non-gcc compilers happy.
Paul Aurich <darkrain42@pidgin.im>
parents:
27361
diff
changeset
|
32 | #include "internal.h" |
|
15977
057b184c15d9
Don't advertise that we support the adverts, invite and translate
Mark Doliner <markdoliner@pidgin.im>
parents:
15884
diff
changeset
|
33 | #include "debug.h" |
| 7131 | 34 | |
| 13808 | 35 | #include <libxml/parser.h> |
| 7131 | 36 | #include <string.h> |
| 37 | #include <glib.h> | |
| 38 | ||
| 14386 | 39 | #include "dbus-maybe.h" |
|
14233
4f5fe687b21d
[gaim-migrate @ 16821]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14097
diff
changeset
|
40 | #include "util.h" |
| 7131 | 41 | #include "xmlnode.h" |
| 42 | ||
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
43 | #ifdef _WIN32 |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
44 | # define NEWLINE_S "\r\n" |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
45 | #else |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
46 | # define NEWLINE_S "\n" |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
47 | #endif |
|
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
48 | |
| 7131 | 49 | static xmlnode* |
| 8135 | 50 | new_node(const char *name, XMLNodeType type) |
| 7131 | 51 | { |
| 52 | xmlnode *node = g_new0(xmlnode, 1); | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
53 | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
54 | node->name = g_strdup(name); |
| 7131 | 55 | node->type = type; |
| 56 | ||
| 15884 | 57 | PURPLE_DBUS_REGISTER_POINTER(node, xmlnode); |
| 14386 | 58 | |
| 7131 | 59 | return node; |
| 60 | } | |
| 61 | ||
| 62 | xmlnode* | |
| 63 | xmlnode_new(const char *name) | |
| 64 | { | |
| 65 | g_return_val_if_fail(name != NULL, NULL); | |
| 66 | ||
| 8135 | 67 | return new_node(name, XMLNODE_TYPE_TAG); |
| 7131 | 68 | } |
| 69 | ||
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
70 | xmlnode * |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
71 | xmlnode_new_child(xmlnode *parent, const char *name) |
| 7131 | 72 | { |
| 73 | xmlnode *node; | |
| 74 | ||
| 75 | g_return_val_if_fail(parent != NULL, NULL); | |
| 76 | g_return_val_if_fail(name != NULL, NULL); | |
| 77 | ||
| 8135 | 78 | node = new_node(name, XMLNODE_TYPE_TAG); |
| 7131 | 79 | |
| 80 | xmlnode_insert_child(parent, node); | |
| 81 | ||
| 82 | return node; | |
| 83 | } | |
| 84 | ||
| 85 | void | |
| 86 | xmlnode_insert_child(xmlnode *parent, xmlnode *child) | |
| 87 | { | |
| 88 | g_return_if_fail(parent != NULL); | |
| 89 | g_return_if_fail(child != NULL); | |
| 90 | ||
| 91 | child->parent = parent; | |
| 92 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
93 | if(parent->lastchild) { |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
94 | parent->lastchild->next = child; |
| 7131 | 95 | } else { |
| 96 | parent->child = child; | |
| 97 | } | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
98 | |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
99 | parent->lastchild = child; |
| 7131 | 100 | } |
| 101 | ||
| 102 | void | |
| 10848 | 103 | xmlnode_insert_data(xmlnode *node, const char *data, gssize size) |
| 7131 | 104 | { |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
105 | xmlnode *child; |
| 10848 | 106 | gsize real_size; |
| 7131 | 107 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
108 | g_return_if_fail(node != NULL); |
| 7131 | 109 | g_return_if_fail(data != NULL); |
| 110 | g_return_if_fail(size != 0); | |
| 111 | ||
| 112 | real_size = size == -1 ? strlen(data) : size; | |
| 113 | ||
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
114 | child = new_node(NULL, XMLNODE_TYPE_DATA); |
| 7131 | 115 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
116 | child->data = g_memdup(data, real_size); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
117 | child->data_sz = real_size; |
| 7131 | 118 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
119 | xmlnode_insert_child(node, child); |
| 7131 | 120 | } |
| 121 | ||
| 122 | void | |
| 123 | xmlnode_remove_attrib(xmlnode *node, const char *attr) | |
| 124 | { | |
| 125 | xmlnode *attr_node, *sibling = NULL; | |
| 126 | ||
| 127 | g_return_if_fail(node != NULL); | |
| 128 | g_return_if_fail(attr != NULL); | |
| 129 | ||
|
26393
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
130 | attr_node = node->child; |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
131 | while (attr_node) { |
| 8135 | 132 | 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
|
133 | purple_strequal(attr_node->name, attr)) |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
134 | { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
135 | if (node->lastchild == attr_node) { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
136 | node->lastchild = sibling; |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
137 | } |
|
26393
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
138 | if (sibling == NULL) { |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
139 | node->child = attr_node->next; |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
140 | xmlnode_free(attr_node); |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
141 | attr_node = node->child; |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
142 | } else { |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
143 | sibling->next = attr_node->next; |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
144 | sibling = attr_node->next; |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
145 | xmlnode_free(attr_node); |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
146 | attr_node = sibling; |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
147 | } |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
148 | } |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
149 | else |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
150 | { |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
151 | attr_node = attr_node->next; |
| 7131 | 152 | } |
| 153 | sibling = attr_node; | |
| 154 | } | |
| 155 | } | |
| 156 | ||
| 15265 | 157 | void |
| 158 | xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) | |
| 159 | { | |
| 160 | xmlnode *attr_node, *sibling = NULL; | |
| 161 | ||
| 162 | g_return_if_fail(node != NULL); | |
| 163 | g_return_if_fail(attr != NULL); | |
| 164 | ||
| 165 | for(attr_node = node->child; attr_node; attr_node = attr_node->next) | |
| 166 | { | |
| 167 | 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
|
168 | 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
|
169 | purple_strequal(xmlns, attr_node->xmlns)) |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
170 | { |
|
20228
ce019944d765
applied changes from 9d35dde0c779cca73548172223ba557f27d61882
Luke Schierer <lschiere@pidgin.im>
parents:
20224
diff
changeset
|
171 | if(sibling == NULL) { |
| 15265 | 172 | node->child = attr_node->next; |
| 173 | } else { | |
| 174 | sibling->next = attr_node->next; | |
| 175 | } | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
176 | if (node->lastchild == attr_node) { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
177 | node->lastchild = sibling; |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
178 | } |
| 15265 | 179 | xmlnode_free(attr_node); |
| 180 | return; | |
| 181 | } | |
| 182 | sibling = attr_node; | |
| 183 | } | |
| 184 | } | |
| 185 | ||
| 7131 | 186 | void |
| 187 | xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value) | |
| 188 | { | |
| 189 | xmlnode_remove_attrib(node, attr); | |
|
26393
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
190 | xmlnode_set_attrib_full(node, attr, NULL, NULL, value); |
| 7131 | 191 | } |
| 192 | ||
| 15265 | 193 | void |
| 194 | xmlnode_set_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns, const char *value) | |
| 195 | { | |
|
26393
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
196 | xmlnode_set_attrib_full(node, attr, xmlns, NULL, value); |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
197 | } |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
198 | |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
199 | void |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
200 | xmlnode_set_attrib_with_prefix(xmlnode *node, const char *attr, const char *prefix, const char *value) |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
201 | { |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
202 | xmlnode_set_attrib_full(node, attr, NULL, prefix, value); |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
203 | } |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
204 | |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
205 | void |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
206 | xmlnode_set_attrib_full(xmlnode *node, const char *attr, const char *xmlns, const char *prefix, const char *value) |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
207 | { |
| 15265 | 208 | xmlnode *attrib_node; |
| 209 | ||
| 210 | g_return_if_fail(node != NULL); | |
| 211 | g_return_if_fail(attr != NULL); | |
| 212 | g_return_if_fail(value != NULL); | |
| 213 | ||
| 214 | xmlnode_remove_attrib_with_namespace(node, attr, xmlns); | |
| 215 | attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); | |
| 216 | ||
| 217 | attrib_node->data = g_strdup(value); | |
| 218 | attrib_node->xmlns = g_strdup(xmlns); | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
219 | attrib_node->prefix = g_strdup(prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
220 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
221 | xmlnode_insert_child(node, attrib_node); |
|
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 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
224 | |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
225 | const char * |
|
30510
570fa2a907ea
const-ify the xmlnode* parameter to xmlnode_get_attrib(_with_namespace)
Paul Aurich <darkrain42@pidgin.im>
parents:
29697
diff
changeset
|
226 | xmlnode_get_attrib(const xmlnode *node, const char *attr) |
| 7131 | 227 | { |
| 228 | xmlnode *x; | |
| 229 | ||
| 230 | g_return_val_if_fail(node != NULL, NULL); | |
| 24639 | 231 | g_return_val_if_fail(attr != NULL, NULL); |
| 7131 | 232 | |
| 233 | 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
|
234 | if(x->type == XMLNODE_TYPE_ATTRIB && purple_strequal(attr, x->name)) { |
| 7131 | 235 | return x->data; |
| 236 | } | |
| 237 | } | |
| 238 | ||
| 239 | return NULL; | |
| 240 | } | |
| 241 | ||
| 15265 | 242 | const char * |
|
30510
570fa2a907ea
const-ify the xmlnode* parameter to xmlnode_get_attrib(_with_namespace)
Paul Aurich <darkrain42@pidgin.im>
parents:
29697
diff
changeset
|
243 | xmlnode_get_attrib_with_namespace(const xmlnode *node, const char *attr, const char *xmlns) |
| 15265 | 244 | { |
|
30510
570fa2a907ea
const-ify the xmlnode* parameter to xmlnode_get_attrib(_with_namespace)
Paul Aurich <darkrain42@pidgin.im>
parents:
29697
diff
changeset
|
245 | const xmlnode *x; |
| 15265 | 246 | |
| 247 | g_return_val_if_fail(node != NULL, NULL); | |
| 24639 | 248 | g_return_val_if_fail(attr != NULL, NULL); |
| 15265 | 249 | |
| 250 | for(x = node->child; x; x = x->next) { | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
251 | 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
|
252 | 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
|
253 | purple_strequal(xmlns, x->xmlns)) { |
| 15265 | 254 | return x->data; |
| 255 | } | |
| 256 | } | |
| 257 | ||
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
258 | return NULL; |
| 15265 | 259 | } |
| 260 | ||
| 13808 | 261 | |
| 262 | void xmlnode_set_namespace(xmlnode *node, const char *xmlns) | |
| 263 | { | |
| 264 | g_return_if_fail(node != NULL); | |
| 265 | ||
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
266 | g_free(node->xmlns); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
267 | node->xmlns = g_strdup(xmlns); |
| 13808 | 268 | } |
| 269 | ||
| 270 | const char *xmlnode_get_namespace(xmlnode *node) | |
| 271 | { | |
| 272 | g_return_val_if_fail(node != NULL, NULL); | |
| 273 | ||
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
274 | return node->xmlns; |
| 13808 | 275 | } |
| 276 | ||
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
277 | 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
|
278 | { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
279 | g_return_if_fail(node != NULL); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
280 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
281 | g_free(node->prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
282 | node->prefix = g_strdup(prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
283 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
284 | |
|
25559
b8df546bf422
There's no reason for these to not be const is there? This doesn't
Mark Doliner <markdoliner@pidgin.im>
parents:
25301
diff
changeset
|
285 | const char *xmlnode_get_prefix(const xmlnode *node) |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
286 | { |
|
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
|
287 | 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
|
288 | return node->prefix; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
289 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
290 | |
|
23750
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
291 | xmlnode *xmlnode_get_parent(const xmlnode *child) |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
292 | { |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
293 | g_return_val_if_fail(child != NULL, NULL); |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
294 | return child->parent; |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
295 | } |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
296 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
297 | void |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
298 | xmlnode_free(xmlnode *node) |
| 7131 | 299 | { |
| 300 | xmlnode *x, *y; | |
| 301 | ||
| 302 | g_return_if_fail(node != NULL); | |
| 303 | ||
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
304 | /* 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
|
305 | if(NULL != node->parent) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
306 | if(node->parent->child == node) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
307 | node->parent->child = node->next; |
|
19568
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
308 | if (node->parent->lastchild == node) |
|
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
309 | node->parent->lastchild = node->next; |
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
310 | } else { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
311 | xmlnode *prev = node->parent->child; |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
312 | while(prev && prev->next != node) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
313 | prev = prev->next; |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
314 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
315 | if(prev) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
316 | prev->next = node->next; |
|
19568
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
317 | if (node->parent->lastchild == node) |
|
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
318 | node->parent->lastchild = prev; |
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
319 | } |
|
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 | /* now free our children */ |
| 7131 | 324 | x = node->child; |
| 325 | while(x) { | |
| 326 | y = x->next; | |
| 327 | xmlnode_free(x); | |
| 328 | x = y; | |
| 329 | } | |
| 330 | ||
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
331 | /* now dispose of ourselves */ |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
332 | g_free(node->name); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
333 | g_free(node->data); |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
334 | g_free(node->xmlns); |
| 22061 | 335 | g_free(node->prefix); |
| 14386 | 336 | |
|
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
|
337 | 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
|
338 | 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
|
339 | |
| 15884 | 340 | PURPLE_DBUS_UNREGISTER_POINTER(node); |
| 7131 | 341 | g_free(node); |
| 342 | } | |
| 343 | ||
| 344 | xmlnode* | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
345 | xmlnode_get_child(const xmlnode *parent, const char *name) |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
346 | { |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
347 | return xmlnode_get_child_with_namespace(parent, name, NULL); |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
348 | } |
|
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 | xmlnode * |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
351 | xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *ns) |
| 7131 | 352 | { |
| 353 | xmlnode *x, *ret = NULL; | |
| 354 | char **names; | |
| 355 | char *parent_name, *child_name; | |
| 356 | ||
| 357 | g_return_val_if_fail(parent != NULL, NULL); | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
358 | g_return_val_if_fail(name != NULL, NULL); |
| 7131 | 359 | |
| 360 | names = g_strsplit(name, "/", 2); | |
| 361 | parent_name = names[0]; | |
| 362 | child_name = names[1]; | |
| 363 | ||
| 364 | for(x = parent->child; x; x = x->next) { | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
365 | /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 8262 | 366 | const char *xmlns = NULL; |
| 367 | if(ns) | |
| 13808 | 368 | xmlns = xmlnode_get_namespace(x); |
| 8262 | 369 | |
|
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
|
370 | 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
|
371 | && purple_strequal(ns, xmlns)) { |
| 7131 | 372 | ret = x; |
| 373 | break; | |
| 374 | } | |
| 375 | } | |
| 376 | ||
| 377 | if(child_name && ret) | |
| 8262 | 378 | ret = xmlnode_get_child(ret, child_name); |
| 7131 | 379 | |
| 380 | g_strfreev(names); | |
| 381 | return ret; | |
| 382 | } | |
| 383 | ||
| 384 | char * | |
|
27345
37d67bee50c2
These parameters aren't modified
Mark Doliner <markdoliner@pidgin.im>
parents:
26862
diff
changeset
|
385 | xmlnode_get_data(const xmlnode *node) |
| 7131 | 386 | { |
| 387 | GString *str = NULL; | |
| 388 | xmlnode *c; | |
| 389 | ||
| 390 | g_return_val_if_fail(node != NULL, NULL); | |
| 391 | ||
| 392 | for(c = node->child; c; c = c->next) { | |
| 8135 | 393 | if(c->type == XMLNODE_TYPE_DATA) { |
| 7131 | 394 | 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
|
395 | 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
|
396 | else |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
397 | str = g_string_append_len(str, c->data, c->data_sz); |
| 7131 | 398 | } |
| 399 | } | |
| 400 | ||
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
401 | if (str == NULL) |
|
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
402 | return NULL; |
| 7131 | 403 | |
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
404 | return g_string_free(str, FALSE); |
| 7131 | 405 | } |
| 406 | ||
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
407 | char * |
|
27345
37d67bee50c2
These parameters aren't modified
Mark Doliner <markdoliner@pidgin.im>
parents:
26862
diff
changeset
|
408 | xmlnode_get_data_unescaped(const xmlnode *node) |
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
409 | { |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
410 | 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
|
411 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
412 | 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
|
413 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
414 | 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
|
415 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
416 | return unescaped; |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
417 | } |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
418 | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
419 | static void |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
420 | 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
|
421 | GString *buf) |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
422 | { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
423 | if (*key) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
424 | 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
|
425 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
426 | g_string_append_printf(buf, " xmlns='%s'", value); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
427 | } |
|
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 | |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
430 | static char * |
|
25559
b8df546bf422
There's no reason for these to not be const is there? This doesn't
Mark Doliner <markdoliner@pidgin.im>
parents:
25301
diff
changeset
|
431 | xmlnode_to_str_helper(const xmlnode *node, int *len, gboolean formatting, int depth) |
| 7131 | 432 | { |
| 433 | GString *text = g_string_new(""); | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
434 | const char *prefix; |
|
25559
b8df546bf422
There's no reason for these to not be const is there? This doesn't
Mark Doliner <markdoliner@pidgin.im>
parents:
25301
diff
changeset
|
435 | const xmlnode *c; |
| 9837 | 436 | char *node_name, *esc, *esc2, *tab = NULL; |
| 9838 | 437 | gboolean need_end = FALSE, pretty = formatting; |
| 9837 | 438 | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
439 | g_return_val_if_fail(node != NULL, NULL); |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
440 | |
| 9837 | 441 | if(pretty && depth) { |
| 442 | tab = g_strnfill(depth, '\t'); | |
| 443 | text = g_string_append(text, tab); | |
| 444 | } | |
| 7131 | 445 | |
| 446 | 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
|
447 | prefix = xmlnode_get_prefix(node); |
| 7131 | 448 | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
449 | if (prefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
450 | 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
|
451 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
452 | g_string_append_printf(text, "<%s", node_name); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
453 | } |
|
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 | if (node->namespace_map) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
456 | g_hash_table_foreach(node->namespace_map, |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
457 | (GHFunc)xmlnode_to_str_foreach_append_ns, text); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
458 | } 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
|
459 | if(!node->parent || !purple_strequal(node->xmlns, node->parent->xmlns)) |
| 15184 | 460 | { |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
461 | char *xmlns = g_markup_escape_text(node->xmlns, -1); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
462 | g_string_append_printf(text, " xmlns='%s'", xmlns); |
|
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
463 | g_free(xmlns); |
| 15184 | 464 | } |
| 13808 | 465 | } |
| 7131 | 466 | for(c = node->child; c; c = c->next) |
| 467 | { | |
| 8135 | 468 | if(c->type == XMLNODE_TYPE_ATTRIB) { |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
469 | const char *aprefix = xmlnode_get_prefix(c); |
| 7131 | 470 | esc = g_markup_escape_text(c->name, -1); |
| 471 | 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
|
472 | if (aprefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
473 | 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
|
474 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
475 | 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
|
476 | } |
| 7131 | 477 | g_free(esc); |
| 478 | g_free(esc2); | |
| 8135 | 479 | } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) { |
| 9837 | 480 | if(c->type == XMLNODE_TYPE_DATA) |
| 9838 | 481 | pretty = FALSE; |
| 7131 | 482 | need_end = TRUE; |
| 483 | } | |
| 484 | } | |
| 485 | ||
| 486 | if(need_end) { | |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
487 | g_string_append_printf(text, ">%s", pretty ? NEWLINE_S : ""); |
| 7131 | 488 | |
| 489 | for(c = node->child; c; c = c->next) | |
| 490 | { | |
| 8135 | 491 | if(c->type == XMLNODE_TYPE_TAG) { |
| 7642 | 492 | int esc_len; |
| 9838 | 493 | esc = xmlnode_to_str_helper(c, &esc_len, pretty, depth+1); |
| 7642 | 494 | text = g_string_append_len(text, esc, esc_len); |
| 7131 | 495 | g_free(esc); |
| 12198 | 496 | } else if(c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) { |
| 7131 | 497 | esc = g_markup_escape_text(c->data, c->data_sz); |
| 7642 | 498 | text = g_string_append(text, esc); |
| 7131 | 499 | g_free(esc); |
| 500 | } | |
| 501 | } | |
| 502 | ||
| 9838 | 503 | if(tab && pretty) |
| 9837 | 504 | text = g_string_append(text, tab); |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
505 | if (prefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
506 | 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
|
507 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
508 | 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
|
509 | } |
| 7131 | 510 | } else { |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
511 | g_string_append_printf(text, "/>%s", formatting ? NEWLINE_S : ""); |
| 7131 | 512 | } |
| 513 | ||
| 514 | g_free(node_name); | |
| 515 | ||
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
516 | g_free(tab); |
| 9837 | 517 | |
| 7642 | 518 | if(len) |
| 519 | *len = text->len; | |
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
520 | |
|
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
521 | return g_string_free(text, FALSE); |
| 7131 | 522 | } |
| 523 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
524 | char * |
|
25559
b8df546bf422
There's no reason for these to not be const is there? This doesn't
Mark Doliner <markdoliner@pidgin.im>
parents:
25301
diff
changeset
|
525 | xmlnode_to_str(const xmlnode *node, int *len) |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
526 | { |
| 9837 | 527 | return xmlnode_to_str_helper(node, len, FALSE, 0); |
| 528 | } | |
| 529 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
530 | char * |
|
25559
b8df546bf422
There's no reason for these to not be const is there? This doesn't
Mark Doliner <markdoliner@pidgin.im>
parents:
25301
diff
changeset
|
531 | xmlnode_to_formatted_str(const xmlnode *node, int *len) |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
532 | { |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
533 | char *xml, *xml_with_declaration; |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
534 | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
535 | g_return_val_if_fail(node != NULL, NULL); |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
536 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
537 | xml = xmlnode_to_str_helper(node, len, TRUE, 0); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
538 | xml_with_declaration = |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
539 | 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
|
540 | g_free(xml); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
541 | |
|
22083
d562c88d8327
Patch from QuLogic to correctly set the length. Closes #4515.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22061
diff
changeset
|
542 | if (len) |
|
d562c88d8327
Patch from QuLogic to correctly set the length. Closes #4515.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22061
diff
changeset
|
543 | *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
|
544 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
545 | return xml_with_declaration; |
| 9837 | 546 | } |
| 547 | ||
| 7131 | 548 | struct _xmlnode_parser_data { |
| 549 | xmlnode *current; | |
| 15412 | 550 | gboolean error; |
| 7131 | 551 | }; |
| 552 | ||
| 13808 | 553 | static void |
| 554 | xmlnode_parser_element_start_libxml(void *user_data, | |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
555 | const xmlChar *element_name, const xmlChar *prefix, const xmlChar *xmlns, |
| 13808 | 556 | int nb_namespaces, const xmlChar **namespaces, |
| 557 | int nb_attributes, int nb_defaulted, const xmlChar **attributes) | |
| 558 | { | |
| 559 | struct _xmlnode_parser_data *xpd = user_data; | |
| 560 | xmlnode *node; | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
561 | int i, j; |
| 13808 | 562 | |
| 15412 | 563 | if(!element_name || xpd->error) { |
| 13808 | 564 | return; |
| 565 | } else { | |
| 566 | if(xpd->current) | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
567 | node = xmlnode_new_child(xpd->current, (const char*) element_name); |
| 13808 | 568 | else |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
569 | node = xmlnode_new((const char *) element_name); |
| 13808 | 570 | |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
571 | xmlnode_set_namespace(node, (const char *) xmlns); |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
572 | xmlnode_set_prefix(node, (const char *)prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
573 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
574 | if (nb_namespaces != 0) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
575 | node->namespace_map = g_hash_table_new_full( |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
576 | 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
|
577 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
578 | 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
|
579 | const char *key = (const char *)namespaces[j]; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
580 | const char *val = (const char *)namespaces[j + 1]; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
581 | g_hash_table_insert(node->namespace_map, |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
582 | g_strdup(key ? key : ""), g_strdup(val ? val : "")); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
583 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
584 | } |
| 13808 | 585 | |
| 586 | for(i=0; i < nb_attributes * 5; i+=5) { | |
|
26393
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
587 | const char *name = (const char *)attributes[i]; |
|
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
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]; |
| 29069 | 591 | char *attrib = g_strndup((const char *)attributes[i+3], attrib_len); |
|
14290
f20819ff8d86
[gaim-migrate @ 16910]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
592 | txt = attrib; |
|
29328
cf4435714f5f
Correctly parse "<br>" in an XML attribute. Closes #11318.
Paul Aurich <darkrain42@pidgin.im>
parents:
29069
diff
changeset
|
593 | attrib = purple_unescape_text(txt); |
|
14233
4f5fe687b21d
[gaim-migrate @ 16821]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14097
diff
changeset
|
594 | g_free(txt); |
|
26393
7420fd99903a
Add xmlnode_set_attrib_full that enables you to set an attribute with both
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
25911
diff
changeset
|
595 | xmlnode_set_attrib_full(node, name, NULL, prefix, attrib); |
| 13808 | 596 | g_free(attrib); |
| 597 | } | |
| 598 | ||
| 599 | xpd->current = node; | |
| 600 | } | |
| 601 | } | |
| 602 | ||
| 603 | static void | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
604 | 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
|
605 | const xmlChar *prefix, const xmlChar *xmlns) |
| 13808 | 606 | { |
| 607 | struct _xmlnode_parser_data *xpd = user_data; | |
| 608 | ||
| 15412 | 609 | if(!element_name || !xpd->current || xpd->error) |
| 13808 | 610 | return; |
| 611 | ||
| 612 | if(xpd->current->parent) { | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
613 | if(!xmlStrcmp((xmlChar*) xpd->current->name, element_name)) |
| 13808 | 614 | xpd->current = xpd->current->parent; |
| 615 | } | |
| 616 | } | |
| 617 | ||
| 618 | static void | |
| 619 | xmlnode_parser_element_text_libxml(void *user_data, const xmlChar *text, int text_len) | |
| 620 | { | |
| 621 | struct _xmlnode_parser_data *xpd = user_data; | |
| 622 | ||
| 15412 | 623 | if(!xpd->current || xpd->error) |
| 13808 | 624 | return; |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
25859
diff
changeset
|
625 | |
| 13808 | 626 | if(!text || !text_len) |
| 627 | return; | |
| 628 | ||
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
629 | xmlnode_insert_data(xpd->current, (const char*) text, text_len); |
| 13808 | 630 | } |
| 631 | ||
| 15412 | 632 | static void |
| 633 | xmlnode_parser_error_libxml(void *user_data, const char *msg, ...) | |
| 634 | { | |
| 635 | 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
|
636 | char errmsg[2048]; |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
637 | va_list args; |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
638 | |
| 15412 | 639 | 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
|
640 | |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
641 | 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
|
642 | 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
|
643 | va_end(args); |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
644 | |
|
25301
d81daadd1bee
Error messages from libxml contain their own newlines
Mark Doliner <markdoliner@pidgin.im>
parents:
24639
diff
changeset
|
645 | purple_debug_error("xmlnode", "Error parsing xml file: %s", errmsg); |
| 15412 | 646 | } |
| 647 | ||
|
25726
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
648 | static void |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
649 | xmlnode_parser_structural_error_libxml(void *user_data, xmlErrorPtr error) |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
650 | { |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
651 | struct _xmlnode_parser_data *xpd = user_data; |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
652 | |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
653 | if (error && (error->level == XML_ERR_ERROR || |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
654 | error->level == XML_ERR_FATAL)) { |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
655 | xpd->error = TRUE; |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
656 | purple_debug_error("xmlnode", "XML parser error for xmlnode %p: " |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
657 | "Domain %i, code %i, level %i: %s", |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
658 | user_data, error->domain, error->code, error->level, |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
659 | error->message ? error->message : "(null)\n"); |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
660 | } else if (error) |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
661 | purple_debug_warning("xmlnode", "XML parser error for xmlnode %p: " |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
662 | "Domain %i, code %i, level %i: %s", |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
663 | user_data, error->domain, error->code, error->level, |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
664 | error->message ? error->message : "(null)\n"); |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
665 | else |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
666 | purple_debug_warning("xmlnode", "XML parser error for xmlnode %p\n", |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
667 | user_data); |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
668 | } |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
669 | |
| 13808 | 670 | static xmlSAXHandler xmlnode_parser_libxml = { |
|
17550
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
671 | NULL, /* internalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
672 | NULL, /* isStandalone */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
673 | NULL, /* hasInternalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
674 | NULL, /* hasExternalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
675 | NULL, /* resolveEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
676 | NULL, /* getEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
677 | NULL, /* entityDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
678 | NULL, /* notationDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
679 | NULL, /* attributeDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
680 | NULL, /* elementDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
681 | NULL, /* unparsedEntityDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
682 | NULL, /* setDocumentLocator */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
683 | NULL, /* startDocument */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
684 | NULL, /* endDocument */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
685 | NULL, /* startElement */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
686 | NULL, /* endElement */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
687 | NULL, /* reference */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
688 | xmlnode_parser_element_text_libxml, /* characters */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
689 | NULL, /* ignorableWhitespace */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
690 | NULL, /* processingInstruction */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
691 | NULL, /* comment */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
692 | NULL, /* warning */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
693 | xmlnode_parser_error_libxml, /* error */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
694 | NULL, /* fatalError */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
695 | NULL, /* getParameterEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
696 | NULL, /* cdataBlock */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
697 | NULL, /* externalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
698 | XML_SAX2_MAGIC, /* initialized */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
699 | NULL, /* _private */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
700 | xmlnode_parser_element_start_libxml, /* startElementNs */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
701 | xmlnode_parser_element_end_libxml, /* endElementNs */ |
|
25726
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
702 | xmlnode_parser_structural_error_libxml, /* serror */ |
| 13808 | 703 | }; |
| 7131 | 704 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
705 | xmlnode * |
| 10848 | 706 | xmlnode_from_str(const char *str, gssize size) |
| 7131 | 707 | { |
| 11390 | 708 | struct _xmlnode_parser_data *xpd; |
| 7131 | 709 | xmlnode *ret; |
| 11390 | 710 | gsize real_size; |
| 7131 | 711 | |
| 11390 | 712 | g_return_val_if_fail(str != NULL, NULL); |
| 713 | ||
|
11705
8200a990caf1
[gaim-migrate @ 13996]
Richard Laager <rlaager@pidgin.im>
parents:
11390
diff
changeset
|
714 | real_size = size < 0 ? strlen(str) : size; |
| 11390 | 715 | xpd = g_new0(struct _xmlnode_parser_data, 1); |
| 13808 | 716 | |
| 14384 | 717 | if (xmlSAXUserParseMemory(&xmlnode_parser_libxml, xpd, str, real_size) < 0) { |
| 13808 | 718 | while(xpd->current && xpd->current->parent) |
| 719 | xpd->current = xpd->current->parent; | |
| 720 | if(xpd->current) | |
| 721 | xmlnode_free(xpd->current); | |
| 722 | xpd->current = NULL; | |
| 723 | } | |
| 7131 | 724 | ret = xpd->current; |
| 15412 | 725 | if (xpd->error) { |
| 726 | ret = NULL; | |
| 727 | if (xpd->current) | |
| 728 | xmlnode_free(xpd->current); | |
| 729 | } | |
| 730 | ||
| 7131 | 731 | g_free(xpd); |
| 732 | return ret; | |
| 733 | } | |
| 8135 | 734 | |
|
23964
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
735 | xmlnode * |
|
23972
90e0da03c053
theme loader cleanup, and remove a few warnings
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23964
diff
changeset
|
736 | 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
|
737 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
738 | gchar *filename_full; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
739 | GError *error = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
740 | gchar *contents = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
741 | gsize length; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
742 | xmlnode *node = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
743 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
744 | 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
|
745 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
746 | 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
|
747 | filename, dir); |
|
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 | 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
|
750 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
751 | 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
|
752 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
753 | 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
|
754 | "necessarily an error)\n", filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
755 | g_free(filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
756 | return NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
757 | } |
|
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 | 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
|
760 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
761 | 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
|
762 | filename_full, error->message); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
763 | g_error_free(error); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
764 | } |
|
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 | if ((contents != NULL) && (length > 0)) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
767 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
768 | node = xmlnode_from_str(contents, length); |
|
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 | /* 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
|
771 | if (node == NULL) |
|
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 | gchar *filename_temp, *filename_temp_full; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
774 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
775 | filename_temp = g_strdup_printf("%s~", filename); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
776 | 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
|
777 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
778 | 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
|
779 | "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
|
780 | 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
|
781 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
782 | g_free(filename_temp_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
783 | g_free(filename_temp); |
|
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(contents); |
|
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 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
789 | /* 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
|
790 | if (node == NULL) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
791 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
792 | gchar *title, *msg; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
793 | 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
|
794 | 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
|
795 | "%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
|
796 | "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
|
797 | purple_notify_error(NULL, NULL, title, msg); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
798 | g_free(title); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
799 | g_free(msg); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
800 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
801 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
802 | g_free(filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
803 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
804 | return node; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
805 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
806 | |
|
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
|
807 | 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
|
808 | 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
|
809 | { |
|
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 | 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
|
811 | 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
|
812 | } |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
813 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
814 | xmlnode * |
|
15609
e432251bd57e
sf patch #1647731, from Markus Elfring
Mark Doliner <markdoliner@pidgin.im>
parents:
15435
diff
changeset
|
815 | xmlnode_copy(const xmlnode *src) |
| 8135 | 816 | { |
| 817 | xmlnode *ret; | |
| 818 | xmlnode *child; | |
| 819 | xmlnode *sibling = NULL; | |
| 820 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
821 | g_return_val_if_fail(src != NULL, NULL); |
| 8135 | 822 | |
| 823 | 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
|
824 | 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
|
825 | 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
|
826 | if (src->data_sz) { |
| 8167 | 827 | ret->data = g_memdup(src->data, src->data_sz); |
| 828 | ret->data_sz = src->data_sz; | |
| 829 | } else { | |
| 830 | ret->data = g_strdup(src->data); | |
| 831 | } | |
| 8135 | 832 | } |
|
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
|
833 | 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
|
834 | 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
|
835 | 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
|
836 | 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
|
837 | 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
|
838 | } |
| 8135 | 839 | |
|
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
|
840 | 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
|
841 | if (sibling) { |
| 8135 | 842 | sibling->next = xmlnode_copy(child); |
| 843 | sibling = sibling->next; | |
| 844 | } else { | |
| 845 | ret->child = xmlnode_copy(child); | |
| 846 | sibling = ret->child; | |
| 847 | } | |
| 848 | sibling->parent = ret; | |
| 849 | } | |
| 850 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
851 | ret->lastchild = sibling; |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
852 | |
| 8135 | 853 | return ret; |
| 854 | } | |
| 855 | ||
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
856 | xmlnode * |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
857 | xmlnode_get_next_twin(xmlnode *node) |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
858 | { |
| 8135 | 859 | xmlnode *sibling; |
| 13808 | 860 | const char *ns = xmlnode_get_namespace(node); |
| 8135 | 861 | |
| 862 | g_return_val_if_fail(node != NULL, NULL); | |
| 863 | g_return_val_if_fail(node->type == XMLNODE_TYPE_TAG, NULL); | |
| 864 | ||
| 865 | for(sibling = node->next; sibling; sibling = sibling->next) { | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
866 | /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 8283 | 867 | const char *xmlns = NULL; |
| 8262 | 868 | if(ns) |
| 13808 | 869 | xmlns = xmlnode_get_namespace(sibling); |
| 8262 | 870 | |
|
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
|
871 | 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
|
872 | purple_strequal(ns, xmlns)) |
| 8135 | 873 | return sibling; |
| 874 | } | |
| 875 | ||
| 876 | return NULL; | |
| 877 | } |