[Xfce4-commits] <xfce4-weather-plugin:master> Further refactor parse_xml_document.
Harald Judt
noreply at xfce.org
Tue Nov 20 20:18:07 CET 2012
Updating branch refs/heads/master
to 6f6ce2969f328890e8a2b24ecaacdd7d5f95b92e (commit)
from 6d1554fa46eab3744105eb2478e60734d9584fce (commit)
commit 6f6ce2969f328890e8a2b24ecaacdd7d5f95b92e
Author: Harald Judt <h.judt at gmx.at>
Date: Tue Nov 20 20:03:24 2012 +0100
Further refactor parse_xml_document.
In some cases, more than one none needs to be parsed, so add a function
to get the XML documents which can be processed elsewhere.
panel-plugin/weather-parsers.c | 37 ++++++++++++++++++++++---------------
panel-plugin/weather-parsers.h | 2 ++
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index 610d935..5a27a32 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -439,6 +439,22 @@ parse_place(xmlNode *cur_node)
}
+xmlDoc *
+get_xml_document(SoupMessage *msg)
+{
+ if (G_LIKELY(msg && msg->response_body && msg->response_body->data))
+ if (g_utf8_validate(msg->response_body->data, -1, NULL)) {
+ /* force parsing as UTF-8, the XML encoding header may lie */
+ return xmlReadMemory(msg->response_body->data,
+ strlen(msg->response_body->data),
+ NULL, "UTF-8", 0);
+ } else
+ return xmlParseMemory(msg->response_body->data,
+ strlen(msg->response_body->data));
+ return NULL;
+}
+
+
gpointer
parse_xml_document(SoupMessage *msg,
XmlParseFunc parse_func)
@@ -447,21 +463,12 @@ parse_xml_document(SoupMessage *msg,
xmlNode *root_node;
gpointer user_data = NULL;
- if (G_LIKELY(msg && msg->response_body && msg->response_body->data)) {
- if (g_utf8_validate(msg->response_body->data, -1, NULL)) {
- /* force parsing as UTF-8, the XML encoding header may lie */
- doc = xmlReadMemory(msg->response_body->data,
- strlen(msg->response_body->data),
- NULL, "UTF-8", 0);
- } else
- doc = xmlParseMemory(msg->response_body->data,
- strlen(msg->response_body->data));
- if (G_LIKELY(doc)) {
- root_node = xmlDocGetRootElement(doc);
- if (G_LIKELY(root_node))
- user_data = parse_func(root_node);
- xmlFreeDoc(doc);
- }
+ doc = get_xml_document(msg);
+ if (G_LIKELY(doc)) {
+ root_node = xmlDocGetRootElement(doc);
+ if (G_LIKELY(root_node))
+ user_data = parse_func(root_node);
+ xmlFreeDoc(doc);
}
return user_data;
}
diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
index bc4bfad..b853eca 100644
--- a/panel-plugin/weather-parsers.h
+++ b/panel-plugin/weather-parsers.h
@@ -122,6 +122,8 @@ xml_time *get_timeslice(xml_weather *data,
const time_t start_t,
const time_t end_t);
+xmlDoc *get_xml_document(SoupMessage *msg);
+
gpointer parse_xml_document(SoupMessage *msg,
XmlParseFunc parse_func);
More information about the Xfce4-commits
mailing list