Fri, 18 Jan 2013 03:51:05 -0500
Move blist loading into purple_core_init.
The comments say we want to move this into purple_blist_init, but that
seems like it would be problematic. We need the UI ops to be set, which
moves blist init after UI init. But stuff needs blist signals to be
registered before UI init, etc., etc. It seemed like a pain to work that
all out. I made purple_blist_boot for purple_core_init to call after the
UI init happened. It could have been called _load, but I didn't want
people to accidentally continue calling it.
| 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 | { | |
|
31935
77896a9a09c2
jabber: Check for empty string when setting mood.
Paul Aurich <darkrain42@pidgin.im>
parents:
31549
diff
changeset
|
65 | g_return_val_if_fail(name != NULL && *name != '\0', NULL); |
| 7131 | 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); | |
|
31935
77896a9a09c2
jabber: Check for empty string when setting mood.
Paul Aurich <darkrain42@pidgin.im>
parents:
31549
diff
changeset
|
76 | g_return_val_if_fail(name != NULL && *name != '\0', NULL); |
| 7131 | 77 | |
| 8135 | 78 | node = new_node(name, XMLNODE_TYPE_TAG); |
| 7131 | 79 | |
| 80 | xmlnode_insert_child(parent, node); | |
|
32321
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
81 | #if 0 |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
82 | /* This would give xmlnodes more appropriate namespacing |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
83 | * when creating them. Otherwise, unless an explicit namespace |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
84 | * is set, xmlnode_get_namespace() will return NULL, when |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
85 | * there may be a default namespace. |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
86 | * |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
87 | * I'm unconvinced that it's useful, and concerned it may break things. |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
88 | * |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
89 | * _insert_child would need the same thing, probably (assuming |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
90 | * xmlns->node == NULL) |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
91 | */ |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
92 | xmlnode_set_namespace(node, xmlnode_get_default_namespace(node)) |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
93 | #endif |
| 7131 | 94 | |
| 95 | return node; | |
| 96 | } | |
| 97 | ||
| 98 | void | |
| 99 | xmlnode_insert_child(xmlnode *parent, xmlnode *child) | |
| 100 | { | |
| 101 | g_return_if_fail(parent != NULL); | |
| 102 | g_return_if_fail(child != NULL); | |
| 103 | ||
| 104 | child->parent = parent; | |
| 105 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
106 | if(parent->lastchild) { |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
107 | parent->lastchild->next = child; |
| 7131 | 108 | } else { |
| 109 | parent->child = child; | |
| 110 | } | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
111 | |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
112 | parent->lastchild = child; |
| 7131 | 113 | } |
| 114 | ||
| 115 | void | |
| 10848 | 116 | xmlnode_insert_data(xmlnode *node, const char *data, gssize size) |
| 7131 | 117 | { |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
118 | xmlnode *child; |
| 10848 | 119 | gsize real_size; |
| 7131 | 120 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
121 | g_return_if_fail(node != NULL); |
| 7131 | 122 | g_return_if_fail(data != NULL); |
| 123 | g_return_if_fail(size != 0); | |
| 124 | ||
| 125 | real_size = size == -1 ? strlen(data) : size; | |
| 126 | ||
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
127 | child = new_node(NULL, XMLNODE_TYPE_DATA); |
| 7131 | 128 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
129 | child->data = g_memdup(data, real_size); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
130 | child->data_sz = real_size; |
| 7131 | 131 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
132 | xmlnode_insert_child(node, child); |
| 7131 | 133 | } |
| 134 | ||
| 135 | void | |
| 136 | xmlnode_remove_attrib(xmlnode *node, const char *attr) | |
| 137 | { | |
| 138 | xmlnode *attr_node, *sibling = NULL; | |
| 139 | ||
| 140 | g_return_if_fail(node != NULL); | |
| 141 | g_return_if_fail(attr != NULL); | |
| 142 | ||
|
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
|
143 | 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
|
144 | while (attr_node) { |
| 8135 | 145 | 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
|
146 | purple_strequal(attr_node->name, attr)) |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
147 | { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
148 | if (node->lastchild == attr_node) { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
149 | node->lastchild = sibling; |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
150 | } |
|
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
|
151 | 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
|
152 | 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
|
153 | 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
|
154 | 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
|
155 | } 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
|
156 | 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
|
157 | 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
|
158 | 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
|
159 | 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
|
160 | } |
|
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
|
161 | } |
|
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
|
162 | 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
|
163 | { |
|
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
|
164 | attr_node = attr_node->next; |
| 7131 | 165 | } |
| 166 | sibling = attr_node; | |
| 167 | } | |
| 168 | } | |
| 169 | ||
| 15265 | 170 | void |
| 171 | xmlnode_remove_attrib_with_namespace(xmlnode *node, const char *attr, const char *xmlns) | |
| 172 | { | |
| 173 | xmlnode *attr_node, *sibling = NULL; | |
| 174 | ||
| 175 | g_return_if_fail(node != NULL); | |
| 176 | g_return_if_fail(attr != NULL); | |
| 177 | ||
| 178 | for(attr_node = node->child; attr_node; attr_node = attr_node->next) | |
| 179 | { | |
| 180 | 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
|
181 | 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
|
182 | purple_strequal(xmlns, attr_node->xmlns)) |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
183 | { |
|
20228
ce019944d765
applied changes from 9d35dde0c779cca73548172223ba557f27d61882
Luke Schierer <lschiere@pidgin.im>
parents:
20224
diff
changeset
|
184 | if(sibling == NULL) { |
| 15265 | 185 | node->child = attr_node->next; |
| 186 | } else { | |
| 187 | sibling->next = attr_node->next; | |
| 188 | } | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
189 | if (node->lastchild == attr_node) { |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
190 | node->lastchild = sibling; |
|
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
191 | } |
| 15265 | 192 | xmlnode_free(attr_node); |
| 193 | return; | |
| 194 | } | |
| 195 | sibling = attr_node; | |
| 196 | } | |
| 197 | } | |
| 198 | ||
| 7131 | 199 | void |
| 200 | xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value) | |
| 201 | { | |
| 202 | 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
|
203 | xmlnode_set_attrib_full(node, attr, NULL, NULL, value); |
| 7131 | 204 | } |
| 205 | ||
| 15265 | 206 | void |
|
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
|
207 | 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
|
208 | { |
| 15265 | 209 | xmlnode *attrib_node; |
| 210 | ||
| 211 | g_return_if_fail(node != NULL); | |
| 212 | g_return_if_fail(attr != NULL); | |
| 213 | g_return_if_fail(value != NULL); | |
| 214 | ||
| 215 | xmlnode_remove_attrib_with_namespace(node, attr, xmlns); | |
| 216 | attrib_node = new_node(attr, XMLNODE_TYPE_ATTRIB); | |
| 217 | ||
| 218 | attrib_node->data = g_strdup(value); | |
| 219 | attrib_node->xmlns = g_strdup(xmlns); | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
220 | attrib_node->prefix = g_strdup(prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
221 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
222 | xmlnode_insert_child(node, attrib_node); |
|
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 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
225 | |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
226 | const char * |
|
30510
570fa2a907ea
const-ify the xmlnode* parameter to xmlnode_get_attrib(_with_namespace)
Paul Aurich <darkrain42@pidgin.im>
parents:
29697
diff
changeset
|
227 | xmlnode_get_attrib(const xmlnode *node, const char *attr) |
| 7131 | 228 | { |
| 229 | xmlnode *x; | |
| 230 | ||
| 231 | g_return_val_if_fail(node != NULL, NULL); | |
| 24639 | 232 | g_return_val_if_fail(attr != NULL, NULL); |
| 7131 | 233 | |
| 234 | 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
|
235 | if(x->type == XMLNODE_TYPE_ATTRIB && purple_strequal(attr, x->name)) { |
| 7131 | 236 | return x->data; |
| 237 | } | |
| 238 | } | |
| 239 | ||
| 240 | return NULL; | |
| 241 | } | |
| 242 | ||
| 15265 | 243 | const char * |
|
30510
570fa2a907ea
const-ify the xmlnode* parameter to xmlnode_get_attrib(_with_namespace)
Paul Aurich <darkrain42@pidgin.im>
parents:
29697
diff
changeset
|
244 | xmlnode_get_attrib_with_namespace(const xmlnode *node, const char *attr, const char *xmlns) |
| 15265 | 245 | { |
|
30510
570fa2a907ea
const-ify the xmlnode* parameter to xmlnode_get_attrib(_with_namespace)
Paul Aurich <darkrain42@pidgin.im>
parents:
29697
diff
changeset
|
246 | const xmlnode *x; |
| 15265 | 247 | |
| 248 | g_return_val_if_fail(node != NULL, NULL); | |
| 24639 | 249 | g_return_val_if_fail(attr != NULL, NULL); |
| 15265 | 250 | |
| 251 | for(x = node->child; x; x = x->next) { | |
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
252 | 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
|
253 | 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
|
254 | purple_strequal(xmlns, x->xmlns)) { |
| 15265 | 255 | return x->data; |
| 256 | } | |
| 257 | } | |
| 258 | ||
|
15277
7f9e97dffc4f
[gaim-migrate @ 18005]
Mark Doliner <markdoliner@pidgin.im>
parents:
15265
diff
changeset
|
259 | return NULL; |
| 15265 | 260 | } |
| 261 | ||
| 13808 | 262 | |
| 263 | void xmlnode_set_namespace(xmlnode *node, const char *xmlns) | |
| 264 | { | |
|
32322
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
265 | char *tmp; |
| 13808 | 266 | g_return_if_fail(node != NULL); |
| 267 | ||
|
32322
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
268 | tmp = node->xmlns; |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
269 | node->xmlns = g_strdup(xmlns); |
|
32322
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
270 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
271 | if (node->namespace_map) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
272 | g_hash_table_insert(node->namespace_map, |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
273 | g_strdup(""), g_strdup(xmlns)); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
274 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
275 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
276 | g_free(tmp); |
| 13808 | 277 | } |
| 278 | ||
|
32321
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
279 | const char *xmlnode_get_namespace(const xmlnode *node) |
| 13808 | 280 | { |
| 281 | g_return_val_if_fail(node != NULL, NULL); | |
| 282 | ||
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
283 | return node->xmlns; |
| 13808 | 284 | } |
| 285 | ||
|
32321
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
286 | const char *xmlnode_get_default_namespace(const xmlnode *node) |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
287 | { |
|
32322
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
288 | const xmlnode *current_node; |
|
32321
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
289 | const char *ns = NULL; |
|
32322
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
290 | |
|
32321
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
291 | g_return_val_if_fail(node != NULL, NULL); |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
292 | |
|
32322
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
293 | current_node = node; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
294 | while (current_node) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
295 | /* If this node does *not* have a prefix, node->xmlns is the default |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
296 | * namespace. Otherwise, it's the prefix namespace. |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
297 | */ |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
298 | if (!current_node->prefix && current_node->xmlns) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
299 | return current_node->xmlns; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
300 | } else if (current_node->namespace_map) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
301 | ns = g_hash_table_lookup(current_node->namespace_map, ""); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
302 | if (ns && *ns) |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
303 | return ns; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
304 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
305 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
306 | current_node = current_node->parent; |
|
32321
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
307 | } |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
308 | |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
309 | return ns; |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
310 | } |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
311 | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
312 | 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
|
313 | { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
314 | g_return_if_fail(node != NULL); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
315 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
316 | g_free(node->prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
317 | node->prefix = g_strdup(prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
318 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
319 | |
|
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
|
320 | 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
|
321 | { |
|
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
|
322 | 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
|
323 | return node->prefix; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
324 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
325 | |
|
32322
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
326 | const char *xmlnode_get_prefix_namespace(const xmlnode *node, const char *prefix) |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
327 | { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
328 | const xmlnode *current_node; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
329 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
330 | g_return_val_if_fail(node != NULL, NULL); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
331 | g_return_val_if_fail(prefix != NULL, xmlnode_get_default_namespace(node)); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
332 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
333 | current_node = node; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
334 | while (current_node) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
335 | if (current_node->prefix && g_str_equal(prefix, current_node->prefix) && |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
336 | current_node->xmlns) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
337 | return current_node->xmlns; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
338 | } else if (current_node->namespace_map) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
339 | const char *ns = g_hash_table_lookup(current_node->namespace_map, prefix); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
340 | if (ns && *ns) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
341 | return ns; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
342 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
343 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
344 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
345 | current_node = current_node->parent; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
346 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
347 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
348 | return NULL; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
349 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
350 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
351 | void xmlnode_strip_prefixes(xmlnode *node) |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
352 | { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
353 | xmlnode *child; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
354 | const char *prefix; |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
355 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
356 | g_return_if_fail(node != NULL); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
357 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
358 | for (child = node->child; child; child = child->next) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
359 | if (child->type == XMLNODE_TYPE_TAG) |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
360 | xmlnode_strip_prefixes(child); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
361 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
362 | |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
363 | prefix = xmlnode_get_prefix(node); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
364 | if (prefix) { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
365 | const char *ns = xmlnode_get_prefix_namespace(node, prefix); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
366 | xmlnode_set_namespace(node, ns); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
367 | xmlnode_set_prefix(node, NULL); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
368 | } else { |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
369 | xmlnode_set_namespace(node, xmlnode_get_default_namespace(node)); |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
370 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
371 | } |
|
5c1dd6d9d57f
xmlnode: Add xmlnode_strip_prefixes
Paul Aurich <darkrain42@pidgin.im>
parents:
32321
diff
changeset
|
372 | |
|
23750
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
373 | xmlnode *xmlnode_get_parent(const xmlnode *child) |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
374 | { |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
375 | g_return_val_if_fail(child != NULL, NULL); |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
376 | return child->parent; |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
377 | } |
|
57baab09bf45
Added xmlnode_get_parent.
Michael Ruprecht <maiku@pidgin.im>
parents:
22083
diff
changeset
|
378 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
379 | void |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
380 | xmlnode_free(xmlnode *node) |
| 7131 | 381 | { |
| 382 | xmlnode *x, *y; | |
| 383 | ||
| 384 | g_return_if_fail(node != NULL); | |
| 385 | ||
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
386 | /* 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
|
387 | if(NULL != node->parent) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
388 | if(node->parent->child == node) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
389 | node->parent->child = node->next; |
|
19568
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
390 | if (node->parent->lastchild == node) |
|
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
391 | node->parent->lastchild = node->next; |
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
392 | } else { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
393 | xmlnode *prev = node->parent->child; |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
394 | while(prev && prev->next != node) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
395 | prev = prev->next; |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
396 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
397 | if(prev) { |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
398 | prev->next = node->next; |
|
19568
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
399 | if (node->parent->lastchild == node) |
|
1daa0179da7b
xmlnode bugfix patch from Mauro Brasil
Sean Egan <seanegan@pidgin.im>
parents:
18315
diff
changeset
|
400 | node->parent->lastchild = prev; |
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
401 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
402 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
403 | } |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
404 | |
|
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
405 | /* now free our children */ |
| 7131 | 406 | x = node->child; |
| 407 | while(x) { | |
| 408 | y = x->next; | |
| 409 | xmlnode_free(x); | |
| 410 | x = y; | |
| 411 | } | |
| 412 | ||
|
18315
10dbbd7540b8
fix a buddy icon bug in jabber
Nathan Walp <nwalp@pidgin.im>
parents:
18131
diff
changeset
|
413 | /* now dispose of ourselves */ |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
414 | g_free(node->name); |
|
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
415 | g_free(node->data); |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
416 | g_free(node->xmlns); |
| 22061 | 417 | g_free(node->prefix); |
| 14386 | 418 | |
|
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
|
419 | 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
|
420 | 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
|
421 | |
| 15884 | 422 | PURPLE_DBUS_UNREGISTER_POINTER(node); |
| 7131 | 423 | g_free(node); |
| 424 | } | |
| 425 | ||
| 426 | xmlnode* | |
|
10736
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
427 | xmlnode_get_child(const xmlnode *parent, const char *name) |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
428 | { |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
429 | return xmlnode_get_child_with_namespace(parent, name, NULL); |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
430 | } |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
431 | |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
432 | xmlnode * |
|
fb529f29c25c
[gaim-migrate @ 12338]
Mark Doliner <markdoliner@pidgin.im>
parents:
10425
diff
changeset
|
433 | xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *ns) |
| 7131 | 434 | { |
| 435 | xmlnode *x, *ret = NULL; | |
| 436 | char **names; | |
| 437 | char *parent_name, *child_name; | |
| 438 | ||
| 439 | g_return_val_if_fail(parent != NULL, NULL); | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
440 | g_return_val_if_fail(name != NULL, NULL); |
| 7131 | 441 | |
| 442 | names = g_strsplit(name, "/", 2); | |
| 443 | parent_name = names[0]; | |
| 444 | child_name = names[1]; | |
| 445 | ||
| 446 | for(x = parent->child; x; x = x->next) { | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
447 | /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 8262 | 448 | const char *xmlns = NULL; |
| 449 | if(ns) | |
| 13808 | 450 | xmlns = xmlnode_get_namespace(x); |
| 8262 | 451 | |
|
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
|
452 | 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
|
453 | && purple_strequal(ns, xmlns)) { |
| 7131 | 454 | ret = x; |
| 455 | break; | |
| 456 | } | |
| 457 | } | |
| 458 | ||
| 459 | if(child_name && ret) | |
| 8262 | 460 | ret = xmlnode_get_child(ret, child_name); |
| 7131 | 461 | |
| 462 | g_strfreev(names); | |
| 463 | return ret; | |
| 464 | } | |
| 465 | ||
| 466 | char * | |
|
27345
37d67bee50c2
These parameters aren't modified
Mark Doliner <markdoliner@pidgin.im>
parents:
26862
diff
changeset
|
467 | xmlnode_get_data(const xmlnode *node) |
| 7131 | 468 | { |
| 469 | GString *str = NULL; | |
| 470 | xmlnode *c; | |
| 471 | ||
| 472 | g_return_val_if_fail(node != NULL, NULL); | |
| 473 | ||
| 474 | for(c = node->child; c; c = c->next) { | |
| 8135 | 475 | if(c->type == XMLNODE_TYPE_DATA) { |
| 7131 | 476 | 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
|
477 | 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
|
478 | else |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
479 | str = g_string_append_len(str, c->data, c->data_sz); |
| 7131 | 480 | } |
| 481 | } | |
| 482 | ||
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
483 | if (str == NULL) |
|
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
484 | return NULL; |
| 7131 | 485 | |
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
486 | return g_string_free(str, FALSE); |
| 7131 | 487 | } |
| 488 | ||
|
18131
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
489 | char * |
|
27345
37d67bee50c2
These parameters aren't modified
Mark Doliner <markdoliner@pidgin.im>
parents:
26862
diff
changeset
|
490 | 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
|
491 | { |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
492 | 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
|
493 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
494 | 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
|
495 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
496 | 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
|
497 | |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
498 | return unescaped; |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
499 | } |
|
7127441da3ba
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
Nathan Walp <nwalp@pidgin.im>
parents:
17550
diff
changeset
|
500 | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
501 | static void |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
502 | 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
|
503 | GString *buf) |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
504 | { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
505 | if (*key) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
506 | 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
|
507 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
508 | g_string_append_printf(buf, " xmlns='%s'", value); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
509 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
510 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
511 | |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
512 | 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
|
513 | xmlnode_to_str_helper(const xmlnode *node, int *len, gboolean formatting, int depth) |
| 7131 | 514 | { |
| 515 | GString *text = g_string_new(""); | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
516 | 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
|
517 | const xmlnode *c; |
| 9837 | 518 | char *node_name, *esc, *esc2, *tab = NULL; |
| 9838 | 519 | gboolean need_end = FALSE, pretty = formatting; |
| 9837 | 520 | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
521 | g_return_val_if_fail(node != NULL, NULL); |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
522 | |
| 9837 | 523 | if(pretty && depth) { |
| 524 | tab = g_strnfill(depth, '\t'); | |
| 525 | text = g_string_append(text, tab); | |
| 526 | } | |
| 7131 | 527 | |
| 528 | 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
|
529 | prefix = xmlnode_get_prefix(node); |
| 7131 | 530 | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
531 | if (prefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
532 | 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
|
533 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
534 | g_string_append_printf(text, "<%s", node_name); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
535 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
536 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
537 | if (node->namespace_map) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
538 | g_hash_table_foreach(node->namespace_map, |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
539 | (GHFunc)xmlnode_to_str_foreach_append_ns, text); |
|
32321
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
540 | } else { |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
541 | /* Figure out if this node has a different default namespace from parent */ |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
542 | const char *xmlns = NULL; |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
543 | const char *parent_xmlns = NULL; |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
544 | if (!prefix) |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
545 | xmlns = node->xmlns; |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
546 | |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
547 | if (!xmlns) |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
548 | xmlns = xmlnode_get_default_namespace(node); |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
549 | if (node->parent) |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
550 | parent_xmlns = xmlnode_get_default_namespace(node->parent); |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
551 | if (!purple_strequal(xmlns, parent_xmlns)) |
| 15184 | 552 | { |
|
32321
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
553 | char *escaped_xmlns = g_markup_escape_text(xmlns, -1); |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
554 | g_string_append_printf(text, " xmlns='%s'", escaped_xmlns); |
|
ae17a89ef666
xmlnode: Fix some brokeness in xmlnode serialization with prefixed elements.
Paul Aurich <darkrain42@pidgin.im>
parents:
32313
diff
changeset
|
555 | g_free(escaped_xmlns); |
| 15184 | 556 | } |
| 13808 | 557 | } |
| 7131 | 558 | for(c = node->child; c; c = c->next) |
| 559 | { | |
| 8135 | 560 | if(c->type == XMLNODE_TYPE_ATTRIB) { |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
561 | const char *aprefix = xmlnode_get_prefix(c); |
| 7131 | 562 | esc = g_markup_escape_text(c->name, -1); |
| 563 | 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
|
564 | if (aprefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
565 | 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
|
566 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
567 | 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
|
568 | } |
| 7131 | 569 | g_free(esc); |
| 570 | g_free(esc2); | |
| 8135 | 571 | } else if(c->type == XMLNODE_TYPE_TAG || c->type == XMLNODE_TYPE_DATA) { |
| 9837 | 572 | if(c->type == XMLNODE_TYPE_DATA) |
| 9838 | 573 | pretty = FALSE; |
| 7131 | 574 | need_end = TRUE; |
| 575 | } | |
| 576 | } | |
| 577 | ||
| 578 | if(need_end) { | |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
579 | g_string_append_printf(text, ">%s", pretty ? NEWLINE_S : ""); |
| 7131 | 580 | |
| 581 | for(c = node->child; c; c = c->next) | |
| 582 | { | |
| 8135 | 583 | if(c->type == XMLNODE_TYPE_TAG) { |
| 7642 | 584 | int esc_len; |
| 9838 | 585 | esc = xmlnode_to_str_helper(c, &esc_len, pretty, depth+1); |
| 7642 | 586 | text = g_string_append_len(text, esc, esc_len); |
| 7131 | 587 | g_free(esc); |
| 12198 | 588 | } else if(c->type == XMLNODE_TYPE_DATA && c->data_sz > 0) { |
| 7131 | 589 | esc = g_markup_escape_text(c->data, c->data_sz); |
| 7642 | 590 | text = g_string_append(text, esc); |
| 7131 | 591 | g_free(esc); |
| 592 | } | |
| 593 | } | |
| 594 | ||
| 9838 | 595 | if(tab && pretty) |
| 9837 | 596 | text = g_string_append(text, tab); |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
597 | if (prefix) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
598 | 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
|
599 | } else { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
600 | 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
|
601 | } |
| 7131 | 602 | } else { |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
603 | g_string_append_printf(text, "/>%s", formatting ? NEWLINE_S : ""); |
| 7131 | 604 | } |
| 605 | ||
| 606 | g_free(node_name); | |
| 607 | ||
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
608 | g_free(tab); |
| 9837 | 609 | |
| 7642 | 610 | if(len) |
| 611 | *len = text->len; | |
|
10331
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
612 | |
|
9955b6f7c998
[gaim-migrate @ 11538]
Mark Doliner <markdoliner@pidgin.im>
parents:
9838
diff
changeset
|
613 | return g_string_free(text, FALSE); |
| 7131 | 614 | } |
| 615 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
616 | 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
|
617 | xmlnode_to_str(const xmlnode *node, int *len) |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
618 | { |
| 9837 | 619 | return xmlnode_to_str_helper(node, len, FALSE, 0); |
| 620 | } | |
| 621 | ||
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
622 | 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
|
623 | xmlnode_to_formatted_str(const xmlnode *node, int *len) |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
624 | { |
|
10425
d82cef15da95
[gaim-migrate @ 11677]
Mark Doliner <markdoliner@pidgin.im>
parents:
10424
diff
changeset
|
625 | char *xml, *xml_with_declaration; |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
626 | |
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
627 | g_return_val_if_fail(node != NULL, NULL); |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
628 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
629 | xml = xmlnode_to_str_helper(node, len, TRUE, 0); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
630 | xml_with_declaration = |
|
12041
a297893ebdbd
[gaim-migrate @ 14334]
Daniel Atallah <datallah@pidgin.im>
parents:
11705
diff
changeset
|
631 | 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
|
632 | g_free(xml); |
|
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
633 | |
|
22083
d562c88d8327
Patch from QuLogic to correctly set the length. Closes #4515.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22061
diff
changeset
|
634 | if (len) |
|
d562c88d8327
Patch from QuLogic to correctly set the length. Closes #4515.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
22061
diff
changeset
|
635 | *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
|
636 | |
|
10415
faceb835eb87
[gaim-migrate @ 11665]
Mark Doliner <markdoliner@pidgin.im>
parents:
10331
diff
changeset
|
637 | return xml_with_declaration; |
| 9837 | 638 | } |
| 639 | ||
| 7131 | 640 | struct _xmlnode_parser_data { |
| 641 | xmlnode *current; | |
| 15412 | 642 | gboolean error; |
| 7131 | 643 | }; |
| 644 | ||
| 13808 | 645 | static void |
| 646 | xmlnode_parser_element_start_libxml(void *user_data, | |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
647 | const xmlChar *element_name, const xmlChar *prefix, const xmlChar *xmlns, |
| 13808 | 648 | int nb_namespaces, const xmlChar **namespaces, |
| 649 | int nb_attributes, int nb_defaulted, const xmlChar **attributes) | |
| 650 | { | |
| 651 | struct _xmlnode_parser_data *xpd = user_data; | |
| 652 | xmlnode *node; | |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
653 | int i, j; |
| 13808 | 654 | |
| 15412 | 655 | if(!element_name || xpd->error) { |
| 13808 | 656 | return; |
| 657 | } else { | |
| 658 | if(xpd->current) | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
659 | node = xmlnode_new_child(xpd->current, (const char*) element_name); |
| 13808 | 660 | else |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
661 | node = xmlnode_new((const char *) element_name); |
| 13808 | 662 | |
|
15238
e52522b871ee
[gaim-migrate @ 17963]
Mark Doliner <markdoliner@pidgin.im>
parents:
15184
diff
changeset
|
663 | xmlnode_set_namespace(node, (const char *) xmlns); |
|
21454
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
664 | xmlnode_set_prefix(node, (const char *)prefix); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
665 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
666 | if (nb_namespaces != 0) { |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
667 | node->namespace_map = g_hash_table_new_full( |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
668 | 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
|
669 | |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
670 | 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
|
671 | const char *key = (const char *)namespaces[j]; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
672 | const char *val = (const char *)namespaces[j + 1]; |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
673 | g_hash_table_insert(node->namespace_map, |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
674 | g_strdup(key ? key : ""), g_strdup(val ? val : "")); |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
675 | } |
|
2ca06ee152ac
make our xmlnode preserve prefixes
Ka-Hing Cheung <khc@pidgin.im>
parents:
20228
diff
changeset
|
676 | } |
| 13808 | 677 | |
| 678 | 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
|
679 | 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
|
680 | const char *prefix = (const char *)attributes[i+1]; |
|
14290
f20819ff8d86
[gaim-migrate @ 16910]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14254
diff
changeset
|
681 | char *txt; |
| 13808 | 682 | int attrib_len = attributes[i+4] - attributes[i+3]; |
| 29069 | 683 | 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
|
684 | txt = attrib; |
|
29328
cf4435714f5f
Correctly parse "<br>" in an XML attribute. Closes #11318.
Paul Aurich <darkrain42@pidgin.im>
parents:
29069
diff
changeset
|
685 | attrib = purple_unescape_text(txt); |
|
14233
4f5fe687b21d
[gaim-migrate @ 16821]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
14097
diff
changeset
|
686 | 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
|
687 | xmlnode_set_attrib_full(node, name, NULL, prefix, attrib); |
| 13808 | 688 | g_free(attrib); |
| 689 | } | |
| 690 | ||
| 691 | xpd->current = node; | |
| 692 | } | |
| 693 | } | |
| 694 | ||
| 695 | static void | |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
13833
diff
changeset
|
696 | 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
|
697 | const xmlChar *prefix, const xmlChar *xmlns) |
| 13808 | 698 | { |
| 699 | struct _xmlnode_parser_data *xpd = user_data; | |
| 700 | ||
|
31549
96622b0be540
Change space indentation to tab indentation on a line
Mark Doliner <markdoliner@pidgin.im>
parents:
30510
diff
changeset
|
701 | if(!element_name || !xpd->current || xpd->error) |
| 13808 | 702 | return; |
| 703 | ||
| 704 | if(xpd->current->parent) { | |
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
705 | if(!xmlStrcmp((xmlChar*) xpd->current->name, element_name)) |
| 13808 | 706 | xpd->current = xpd->current->parent; |
| 707 | } | |
| 708 | } | |
| 709 | ||
| 710 | static void | |
| 711 | xmlnode_parser_element_text_libxml(void *user_data, const xmlChar *text, int text_len) | |
| 712 | { | |
| 713 | struct _xmlnode_parser_data *xpd = user_data; | |
| 714 | ||
| 15412 | 715 | if(!xpd->current || xpd->error) |
| 13808 | 716 | return; |
|
25888
d0fdd378a635
Remove trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents:
25859
diff
changeset
|
717 | |
| 13808 | 718 | if(!text || !text_len) |
| 719 | return; | |
| 720 | ||
|
14690
9287ecc4adb1
[gaim-migrate @ 17369]
Daniel Atallah <datallah@pidgin.im>
parents:
14498
diff
changeset
|
721 | xmlnode_insert_data(xpd->current, (const char*) text, text_len); |
| 13808 | 722 | } |
| 723 | ||
| 15412 | 724 | static void |
| 725 | xmlnode_parser_error_libxml(void *user_data, const char *msg, ...) | |
| 726 | { | |
| 727 | 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
|
728 | char errmsg[2048]; |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
729 | va_list args; |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
730 | |
| 15412 | 731 | 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
|
732 | |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
733 | 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
|
734 | 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
|
735 | va_end(args); |
|
c044ef20e299
Print an error when there was a problem parsing some XML
Mark Doliner <markdoliner@pidgin.im>
parents:
19568
diff
changeset
|
736 | |
|
25301
d81daadd1bee
Error messages from libxml contain their own newlines
Mark Doliner <markdoliner@pidgin.im>
parents:
24639
diff
changeset
|
737 | purple_debug_error("xmlnode", "Error parsing xml file: %s", errmsg); |
| 15412 | 738 | } |
| 739 | ||
|
25726
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
740 | static void |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
741 | 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
|
742 | { |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
743 | struct _xmlnode_parser_data *xpd = user_data; |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
744 | |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
745 | if (error && (error->level == XML_ERR_ERROR || |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
746 | error->level == XML_ERR_FATAL)) { |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
747 | xpd->error = TRUE; |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
748 | 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
|
749 | "Domain %i, code %i, level %i: %s", |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
750 | user_data, error->domain, error->code, error->level, |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
751 | error->message ? error->message : "(null)\n"); |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
752 | } else if (error) |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
753 | 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
|
754 | "Domain %i, code %i, level %i: %s", |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
755 | user_data, error->domain, error->code, error->level, |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
756 | error->message ? error->message : "(null)\n"); |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
757 | else |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
758 | 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
|
759 | user_data); |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
760 | } |
|
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
761 | |
| 13808 | 762 | static xmlSAXHandler xmlnode_parser_libxml = { |
|
17550
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
763 | NULL, /* internalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
764 | NULL, /* isStandalone */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
765 | NULL, /* hasInternalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
766 | NULL, /* hasExternalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
767 | NULL, /* resolveEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
768 | NULL, /* getEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
769 | NULL, /* entityDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
770 | NULL, /* notationDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
771 | NULL, /* attributeDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
772 | NULL, /* elementDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
773 | NULL, /* unparsedEntityDecl */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
774 | NULL, /* setDocumentLocator */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
775 | NULL, /* startDocument */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
776 | NULL, /* endDocument */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
777 | NULL, /* startElement */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
778 | NULL, /* endElement */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
779 | NULL, /* reference */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
780 | xmlnode_parser_element_text_libxml, /* characters */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
781 | NULL, /* ignorableWhitespace */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
782 | NULL, /* processingInstruction */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
783 | NULL, /* comment */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
784 | NULL, /* warning */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
785 | xmlnode_parser_error_libxml, /* error */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
786 | NULL, /* fatalError */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
787 | NULL, /* getParameterEntity */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
788 | NULL, /* cdataBlock */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
789 | NULL, /* externalSubset */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
790 | XML_SAX2_MAGIC, /* initialized */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
791 | NULL, /* _private */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
792 | xmlnode_parser_element_start_libxml, /* startElementNs */ |
|
d67724d3a606
Kill a C99 struct initialization.
Richard Laager <rlaager@pidgin.im>
parents:
15979
diff
changeset
|
793 | xmlnode_parser_element_end_libxml, /* endElementNs */ |
|
25726
19e0c9302a43
*** Plucked rev d34a1589 (darkrain42@pidgin.im):
Paul Aurich <darkrain42@pidgin.im>
parents:
25559
diff
changeset
|
794 | xmlnode_parser_structural_error_libxml, /* serror */ |
| 13808 | 795 | }; |
| 7131 | 796 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
797 | xmlnode * |
| 10848 | 798 | xmlnode_from_str(const char *str, gssize size) |
| 7131 | 799 | { |
| 11390 | 800 | struct _xmlnode_parser_data *xpd; |
| 7131 | 801 | xmlnode *ret; |
| 11390 | 802 | gsize real_size; |
| 7131 | 803 | |
| 11390 | 804 | g_return_val_if_fail(str != NULL, NULL); |
| 805 | ||
|
11705
8200a990caf1
[gaim-migrate @ 13996]
Richard Laager <rlaager@pidgin.im>
parents:
11390
diff
changeset
|
806 | real_size = size < 0 ? strlen(str) : size; |
| 11390 | 807 | xpd = g_new0(struct _xmlnode_parser_data, 1); |
| 13808 | 808 | |
| 14384 | 809 | if (xmlSAXUserParseMemory(&xmlnode_parser_libxml, xpd, str, real_size) < 0) { |
| 13808 | 810 | while(xpd->current && xpd->current->parent) |
| 811 | xpd->current = xpd->current->parent; | |
| 812 | if(xpd->current) | |
| 813 | xmlnode_free(xpd->current); | |
| 814 | xpd->current = NULL; | |
| 815 | } | |
| 7131 | 816 | ret = xpd->current; |
| 15412 | 817 | if (xpd->error) { |
| 818 | ret = NULL; | |
| 819 | if (xpd->current) | |
| 820 | xmlnode_free(xpd->current); | |
| 821 | } | |
| 822 | ||
| 7131 | 823 | g_free(xpd); |
| 824 | return ret; | |
| 825 | } | |
| 8135 | 826 | |
|
23964
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
827 | xmlnode * |
|
23972
90e0da03c053
theme loader cleanup, and remove a few warnings
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23964
diff
changeset
|
828 | 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
|
829 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
830 | gchar *filename_full; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
831 | GError *error = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
832 | gchar *contents = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
833 | gsize length; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
834 | xmlnode *node = NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
835 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
836 | 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
|
837 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
838 | 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
|
839 | filename, dir); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
840 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
841 | 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
|
842 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
843 | 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
|
844 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
845 | 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
|
846 | "necessarily an error)\n", filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
847 | g_free(filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
848 | return NULL; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
849 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
850 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
851 | 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
|
852 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
853 | 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
|
854 | filename_full, error->message); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
855 | g_error_free(error); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
856 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
857 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
858 | if ((contents != NULL) && (length > 0)) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
859 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
860 | node = xmlnode_from_str(contents, length); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
861 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
862 | /* 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
|
863 | if (node == NULL) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
864 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
865 | gchar *filename_temp, *filename_temp_full; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
866 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
867 | filename_temp = g_strdup_printf("%s~", filename); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
868 | 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
|
869 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
870 | 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
|
871 | "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
|
872 | 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
|
873 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
874 | g_free(filename_temp_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
875 | g_free(filename_temp); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
876 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
877 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
878 | g_free(contents); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
879 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
880 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
881 | /* 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
|
882 | if (node == NULL) |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
883 | { |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
884 | gchar *title, *msg; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
885 | 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
|
886 | 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
|
887 | "%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
|
888 | "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
|
889 | purple_notify_error(NULL, NULL, title, msg); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
890 | g_free(title); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
891 | g_free(msg); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
892 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
893 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
894 | g_free(filename_full); |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
895 | |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
896 | return node; |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
897 | } |
|
342e3f5bedd9
partially working status icon theme stuff
Justin Rodriguez <ffdragon@soc.pidgin.im>
parents:
23962
diff
changeset
|
898 | |
|
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
|
899 | 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
|
900 | 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
|
901 | { |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
902 | 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
|
903 | 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
|
904 | } |
|
283d616f7f29
Make sure xmlnode_copy also copies the prefix and namespace_map from
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
22083
diff
changeset
|
905 | |
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
906 | xmlnode * |
|
15609
e432251bd57e
sf patch #1647731, from Markus Elfring
Mark Doliner <markdoliner@pidgin.im>
parents:
15435
diff
changeset
|
907 | xmlnode_copy(const xmlnode *src) |
| 8135 | 908 | { |
| 909 | xmlnode *ret; | |
| 910 | xmlnode *child; | |
| 911 | xmlnode *sibling = NULL; | |
| 912 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
913 | g_return_val_if_fail(src != NULL, NULL); |
| 8135 | 914 | |
| 915 | 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
|
916 | 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
|
917 | 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
|
918 | if (src->data_sz) { |
| 8167 | 919 | ret->data = g_memdup(src->data, src->data_sz); |
| 920 | ret->data_sz = src->data_sz; | |
| 921 | } else { | |
| 922 | ret->data = g_strdup(src->data); | |
| 923 | } | |
| 8135 | 924 | } |
|
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
|
925 | 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
|
926 | 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
|
927 | 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
|
928 | 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
|
929 | 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
|
930 | } |
| 8135 | 931 | |
|
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
|
932 | 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
|
933 | if (sibling) { |
| 8135 | 934 | sibling->next = xmlnode_copy(child); |
| 935 | sibling = sibling->next; | |
| 936 | } else { | |
| 937 | ret->child = xmlnode_copy(child); | |
| 938 | sibling = ret->child; | |
| 939 | } | |
| 940 | sibling->parent = ret; | |
| 941 | } | |
| 942 | ||
|
12233
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
943 | ret->lastchild = sibling; |
|
0570720fee6c
[gaim-migrate @ 14535]
Michael Carlson <corfe83@users.sourceforge.net>
parents:
12198
diff
changeset
|
944 | |
| 8135 | 945 | return ret; |
| 946 | } | |
| 947 | ||
|
10423
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
948 | xmlnode * |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
949 | xmlnode_get_next_twin(xmlnode *node) |
|
4663a8238def
[gaim-migrate @ 11675]
Mark Doliner <markdoliner@pidgin.im>
parents:
10415
diff
changeset
|
950 | { |
| 8135 | 951 | xmlnode *sibling; |
| 13808 | 952 | const char *ns = xmlnode_get_namespace(node); |
| 8135 | 953 | |
| 954 | g_return_val_if_fail(node != NULL, NULL); | |
| 955 | g_return_val_if_fail(node->type == XMLNODE_TYPE_TAG, NULL); | |
| 956 | ||
| 957 | for(sibling = node->next; sibling; sibling = sibling->next) { | |
|
20224
d4b827c606db
applied changes from 4d50bf3b08569aa2108a9f5da47fb1548d0c7dd9
Luke Schierer <lschiere@pidgin.im>
parents:
20147
diff
changeset
|
958 | /* XXX: Is it correct to ignore the namespace for the match if none was specified? */ |
| 8283 | 959 | const char *xmlns = NULL; |
| 8262 | 960 | if(ns) |
| 13808 | 961 | xmlns = xmlnode_get_namespace(sibling); |
| 8262 | 962 | |
|
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
|
963 | 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
|
964 | purple_strequal(ns, xmlns)) |
| 8135 | 965 | return sibling; |
| 966 | } | |
| 967 | ||
| 968 | return NULL; | |
| 969 | } |