annotate libpurple/xmlnode.c @ 29397:fff648ea95ae

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