1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 04:32:55 +00:00

Merge branch 'master' of ssh://git.omp.am/home/omp/git/conky

This commit is contained in:
Nikolas Garofil 2009-07-24 11:12:35 +02:00
commit 3322b2a9a9
2 changed files with 57 additions and 47 deletions

View File

@ -1,3 +1,7 @@
2009-07-23
* Changed xoap parsing method to xpath, in preparation to include
forecast data
2009-07-19 2009-07-19
* Fixed out-of-tree builds * Fixed out-of-tree builds
* Update MPD elapsed/progress when stopped (sf.net #2792113) * Update MPD elapsed/progress when stopped (sf.net #2792113)

View File

@ -38,6 +38,15 @@
#endif /* MATH */ #endif /* MATH */
#ifdef XOAP #ifdef XOAP
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/xpath.h>
/* Xpath expressions for XOAP xml parsing */
#define NUM_XPATH_EXPRESSIONS 7
const xmlChar *xpath_expression[NUM_XPATH_EXPRESSIONS] = {
"/weather/cc/lsup", "/weather/cc/tmp", "/weather/cc/t",
"/weather/cc/bar/r", "/weather/cc/wind/s", "/weather/cc/wind/d",
"/weather/cc/hmid"
};
#endif /* XOAP */ #endif /* XOAP */
/* Possible sky conditions */ /* Possible sky conditions */
@ -81,35 +90,45 @@ int rel_humidity(int dew_point, int air) {
} }
#ifdef XOAP #ifdef XOAP
//TODO: Lets get rid of the recursion static void parse_cc(PWEATHER *res, xmlXPathContextPtr xpathCtx)
static void parse_cc(PWEATHER *res, xmlNodePtr cc)
{ {
int i;
char *content;
xmlXPathObjectPtr xpathObj;
xmlNodePtr cur = NULL; for (i = 0; i < NUM_XPATH_EXPRESSIONS; i++) {
xpathObj = xmlXPathEvalExpression(xpath_expression[i], xpathCtx);
for (cur = cc; cur; cur = cur->next) { if ((xpathObj != NULL) && (xpathObj->nodesetval->nodeTab[0]->type == XML_ELEMENT_NODE)) {
if (cur->type == XML_ELEMENT_NODE) { content = (char *)xmlNodeGetContent(xpathObj->nodesetval->nodeTab[0]);
if (!xmlStrcmp(cur->name, (const xmlChar *) "lsup")) { switch(i) {
strncpy(res->lastupd, (char *)cur->children->content, 31); case 0:
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "tmp")) { strncpy(res->lastupd, content, 31);
res->temp = atoi((char *)cur->children->content); break;
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "t")) { case 1:
if(res->xoap_t[0] == '\0') { res->temp = atoi(content);
strncpy(res->xoap_t, (char *)cur->children->content, 31); break;
case 2:
if(res->xoap_t[0] == '\0') {
strncpy(res->xoap_t, content, 31);
} }
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "r")) { break;
res->bar = atoi((char *)cur->children->content); case 3:
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "s")) { res->bar = atoi(content);
res->wind_s = atoi((char *)cur->children->content); break;
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "d")) { case 4:
if (isdigit((char)cur->children->content[0])) { res->wind_s = atoi(content);
res->wind_d = atoi((char *)cur->children->content); break;
} case 5:
} else if (!xmlStrcmp(cur->name, (const xmlChar *) "hmid")) { if (isdigit((char)content[0])) {
res->hmid = atoi((char *)cur->children->content); res->wind_d = atoi(content);
} }
break;
case 6:
res->hmid = atoi(content);
}
xmlFree(content);
} }
parse_cc(res, cur->children); xmlXPathFreeObject(xpathObj);
} }
return; return;
} }
@ -117,37 +136,24 @@ static void parse_cc(PWEATHER *res, xmlNodePtr cc)
static void parse_weather_xml(PWEATHER *res, const char *data) static void parse_weather_xml(PWEATHER *res, const char *data)
{ {
xmlDocPtr doc; xmlDocPtr doc;
xmlNodePtr cur; xmlXPathContextPtr xpathCtx;
if (!(doc = xmlReadMemory(data, strlen(data), "", NULL, 0))) { if (!(doc = xmlReadMemory(data, strlen(data), "", NULL, 0))) {
ERR("weather: can't read xml data"); ERR("weather: can't read xml data");
return; return;
} }
cur = xmlDocGetRootElement(doc); xpathCtx = xmlXPathNewContext(doc);
if(xpathCtx == NULL) {
while(cur) { ERR("weather: unable to create new XPath context");
if (cur->type == XML_ELEMENT_NODE) { xmlFreeDoc(doc);
if (!xmlStrcmp(cur->name, (const xmlChar *) "weather")) { return;
cur = cur->children;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
if (!xmlStrcmp(cur->name, (const xmlChar *) "cc")) {
parse_cc(res, cur->children);
xmlFreeDoc(doc);
return;
}
}
cur = cur->next;
}
}
}
cur = cur->next;
} }
ERR("weather: incorrect xml data"); parse_cc(res, xpathCtx);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc); xmlFreeDoc(doc);
return ; return;
} }
#endif /* XOAP */ #endif /* XOAP */