3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * Rewritten from scratch during Google Summer of Code 2012
8 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
10 * Previously implemented by:
11 * - Arkadiusz Miskiewicz <misiek@pld.org.pl> - first implementation (2001);
12 * - Bartosz Oler <bartosz@bzimage.us> - reimplemented during GSoC 2005;
13 * - Krzysztof Klinikowski <grommasher@gmail.com> - some parts (2009-2011).
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
34 gboolean
ggp_xml_get_string(const PurpleXmlNode
*xml
, gchar
*childName
, gchar
**var
)
38 g_return_val_if_fail(xml
!= NULL
, FALSE
);
39 g_return_val_if_fail(var
!= NULL
, FALSE
);
41 if (childName
!= NULL
) {
42 xml
= purple_xmlnode_get_child(xml
, childName
);
47 str
= purple_xmlnode_get_data(xml
);
55 gboolean
ggp_xml_get_bool(const PurpleXmlNode
*xml
, gchar
*childName
, gboolean
*var
)
60 succ
= ggp_xml_get_string(xml
, childName
, &str
);
64 *var
= (strcmp(str
, "true") == 0 ||
65 strcmp(str
, "True") == 0 ||
66 strcmp(str
, "TRUE") == 0 ||
67 strcmp(str
, "1") == 0);
73 gboolean
ggp_xml_get_uint(const PurpleXmlNode
*xml
, gchar
*childName
, unsigned int *var
)
79 succ
= ggp_xml_get_string(xml
, childName
, &str
);
84 val
= strtoul(str
, &endptr
, 10);
86 succ
= (errno
!= ERANGE
&& endptr
[0] == '\0');
94 gboolean
ggp_xml_set_string(PurpleXmlNode
*xml
, gchar
*childName
, const gchar
*val
)
96 g_return_val_if_fail(xml
!= NULL
, FALSE
);
97 g_return_val_if_fail(val
!= NULL
, FALSE
);
99 if (childName
!= NULL
) {
100 PurpleXmlNode
*child
= purple_xmlnode_get_child(xml
, childName
);
102 child
= purple_xmlnode_new_child(xml
, childName
);
106 ggp_xmlnode_remove_children(xml
);
107 purple_xmlnode_insert_data(xml
, val
, -1);
112 gboolean
ggp_xml_set_bool(PurpleXmlNode
*xml
, gchar
*childName
, gboolean val
)
114 return ggp_xml_set_string(xml
, childName
, val
? "true" : "false");
117 gboolean
ggp_xml_set_uint(PurpleXmlNode
*xml
, gchar
*childName
, unsigned int val
)
120 g_snprintf(buff
, sizeof(buff
), "%u", val
);
121 return ggp_xml_set_string(xml
, childName
, buff
);
124 void ggp_xmlnode_remove_children(PurpleXmlNode
*xml
)
126 PurpleXmlNode
*child
= xml
->child
;
128 PurpleXmlNode
*next
= child
->next
;
129 if (child
->type
!= PURPLE_XMLNODE_TYPE_ATTRIB
)
130 purple_xmlnode_free(child
);
135 unsigned int ggp_xml_child_count(PurpleXmlNode
*xml
, const gchar
*childName
)
137 PurpleXmlNode
*child
;
138 unsigned int count
= 0;
140 g_return_val_if_fail(xml
!= NULL
, 0);
143 child
= purple_xmlnode_get_child(xml
, childName
);
145 child
= purple_xmlnode_get_next_twin(child
);