Fix parsing of XOAP xml.
authorBrenden Matthews <brenden@rty.ca>
Wed, 5 Aug 2009 03:15:08 +0000 (21:15 -0600)
committerBrenden Matthews <brenden@rty.ca>
Wed, 5 Aug 2009 03:15:08 +0000 (21:15 -0600)
Also made the XOAP cloud condition match that of the NOAA stuff
(lowercase).

doc/variables.xml
src/weather.c

index 8b969a7..b695418 100644 (file)
             <simplelist>
                 <member>
                     <command>last_update</command>
-                    <option>The date and time stamp of the data.
+                    <para>The date and time stamp of the data.
                     The result depends on the URI used. For the
                     NOAA site it is date (yyyy/mm/dd) and UTC time.
                     For the weather.com one it is date
                     ([m]m/[d]d/yy) and Local Time of the
-                    station.</option>
+                    station.</para>
                 </member>
                 <member>
                     <command>temperature</command>
-                    <option>Air temperature (you can use the
+                                       <para>Air temperature (you can use the
                     'temperature_unit' config setting to change
-                    units)</option>
+                                       units)</para>
                 </member>
                 <member>
                     <command>cloud_cover</command>
-                    <option>The highest cloud cover status</option>
+                    <para>The highest cloud cover status</para>
                 </member>
                 <member>
                     <command>pressure</command>
-                    <option>Air pressure in millibar</option>
+                    <para>Air pressure in millibar</para>
                 </member>
                 <member>
                     <command>wind_speed</command>
-                    <option>Wind speed in km/h</option>
+                    <para>Wind speed in km/h</para>
                 </member>
                 <member>
                     <command>wind_dir</command>
-                    <option>Wind direction</option>
+                    <para>Wind direction</para>
                 </member>
                 <member>
                     <command>wind_dir_DEG</command>
-                    <option>Compass wind direction</option>
+                    <para>Compass wind direction</para>
                 </member>
                 <member>
                     <command>humidity</command>
-                    <option>Relative humidity in %</option>
+                    <para>Relative humidity in %</para>
                 </member>
                 <member>
                     <command>weather</command>
-                    <option>Any relevant weather event (rain, snow,
+                    <para>Any relevant weather event (rain, snow,
                     etc.). This is not used if you are querying the
                     weather.com site since this data is aggregated
-                    into the cloud_cover one</option>
+                    into the cloud_cover one</para>
                 </member>
                 <member>
                     <command>icon</command>
-                    <option>Weather icon (only for
+                    <para>Weather icon (only for
                     www.weather.com). Can be used together with the
                     icon kit provided upon registering to their
-                    service.</option>
+                    service.</para>
                 </member>
             </simplelist>
             <para>'delay_in_minutes' (optional, default 30) cannot
-            be lower than 30 min.</para>
+            be less than 30 minutes.</para>
             <para>This object is threaded, and once a thread is
             created it can't be explicitely destroyed. One thread
-            will run for each URI specified. You can use any
-            protocol that Curl supports.</para>
+            will run for each URI specified.</para>
             <para>Note that these variables are still EXPERIMENTAL
             and can be subject to many future changes.</para>
         </listitem>
index de496e1..ca9f542 100644 (file)
@@ -109,7 +109,7 @@ static void parse_df(PWEATHER_FORECAST *res, xmlXPathContextPtr xpathCtx)
        xmlXPathObjectPtr xpathObj;
 
        for (i = 0; i < NUM_XPATH_EXPRESSIONS_DF; i++) {
-               xpathObj = xmlXPathEvalExpression((xmlChar *)xpath_expression_df[i], xpathCtx);
+               xpathObj = xmlXPathEvalExpression((const xmlChar *)xpath_expression_df[i], xpathCtx);
                if (xpathObj != NULL) {
                        xmlNodeSetPtr nodes = xpathObj->nodesetval;
                        k = 0;
@@ -179,34 +179,46 @@ static void parse_cc(PWEATHER *res, xmlXPathContextPtr xpathCtx)
        char *content;
        xmlXPathObjectPtr xpathObj;
 
+       xpathObj = xmlXPathEvalExpression((const xmlChar *)"/error/err", xpathCtx);
+       if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr > 0 &&
+                       xpathObj->nodesetval->nodeTab[0]->type == XML_ELEMENT_NODE) {
+               content = (char *)xmlNodeGetContent(xpathObj->nodesetval->nodeTab[0]);
+               NORM_ERR("XOAP error: %s", content);
+               xmlFree(content);
+               xmlXPathFreeObject(xpathObj);
+               return;
+       }
+
        for (i = 0; i < NUM_XPATH_EXPRESSIONS_CC; i++) {
-               xpathObj = xmlXPathEvalExpression((xmlChar *)xpath_expression_cc[i], xpathCtx);
-               if ((xpathObj != NULL) && (xpathObj->nodesetval->nodeTab[0]->type == XML_ELEMENT_NODE)) {
+               xpathObj = xmlXPathEvalExpression((const xmlChar *)xpath_expression_cc[i], xpathCtx);
+               if (xpathObj && xpathObj->nodesetval && xpathObj->nodesetval->nodeNr >0 &&
+                               xpathObj->nodesetval->nodeTab[0]->type ==
+                               XML_ELEMENT_NODE) {
                        content = (char *)xmlNodeGetContent(xpathObj->nodesetval->nodeTab[0]);
                        switch(i) {
-                       case 0:
-                               strncpy(res->lastupd, content, 31);
-                               break;
-                       case 1:
-                               res->temp = atoi(content);
-                               break;
-                       case 2:
-                               strncpy(res->xoap_t, content, 31);
-                               break;
-                       case 3:
-                               res->bar = atoi(content);
-                               break;
-                       case 4:
-                               res->wind_s = atoi(content);
-                               break;
-                       case 5:
-                               res->wind_d = atoi(content);
-                           break;
-                       case 6:
-                               res->hmid = atoi(content);
-                               break;
-                       case 7:
-                               strncpy(res->icon, content, 2);
+                               case 0:
+                                       strncpy(res->lastupd, content, 31);
+                                       break;
+                               case 1:
+                                       res->temp = atoi(content);
+                                       break;
+                               case 2:
+                                       strncpy(res->xoap_t, content, 31);
+                                       break;
+                               case 3:
+                                       res->bar = atoi(content);
+                                       break;
+                               case 4:
+                                       res->wind_s = atoi(content);
+                                       break;
+                               case 5:
+                                       res->wind_d = atoi(content);
+                                       break;
+                               case 6:
+                                       res->hmid = atoi(content);
+                                       break;
+                               case 7:
+                                       strncpy(res->icon, content, 2);
                        }
                        xmlFree(content);
                }
@@ -695,7 +707,12 @@ void weather_process_info(char *p, int p_max_size, char *uri, char *data_type, i
        } else if (strcmp(data_type, "cloud_cover") == EQUAL) {
 #ifdef XOAP
                if (data->xoap_t[0] != '\0') {
+                       char *s = p;
                        strncpy(p, data->xoap_t, p_max_size);
+                       while (*s) {
+                               *s = tolower(*s);
+                               s++;
+                       }
                } else
 #endif /* XOAP */
                        if (data->cc == 0) {