[libgweather/wip/hadess/3.28.3: 1/10] weather-metar: properly extract metar data



commit ee60288a41d60609d5b9feee2df34ebb72ab0132
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Mon Apr 30 14:14:09 2018 +0300

    weather-metar: properly extract metar data
    
    Commit 283afc2d23355def1c1bab70a641f40cea52ba7f switched to new
    METAR data provider, but did not fully update code to properly
    extract METAR data.
    
    The code still assumes that data are separated by newlines. That
    means that now extracted data includes part of opening raw_text
    tag, location code and closing raw_text tag.
    
    Fix this by moving pointer to correct position to make sure that
    xml tag and location code is not included. Also search for
    closing tag to exclude it from data.
    
    Before:
    ext>EVRA 241450Z 22011KT 9999 -SHRA SCT034CB OVC039 11/05 Q1005 NOSIG</raw_text>\u000d
    
    After:
    241450Z 22011KT 9999 -SHRA SCT034CB OVC039 11/05 Q1005 NOSIG

 libgweather/weather-metar.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/libgweather/weather-metar.c b/libgweather/weather-metar.c
index 31ef815..aeb65ad 100644
--- a/libgweather/weather-metar.c
+++ b/libgweather/weather-metar.c
@@ -588,12 +588,12 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
 
     loc = &priv->location;
 
-    searchkey = g_strdup_printf ("<raw_text>%s", loc->code);
+    searchkey = g_strdup_printf ("<raw_text>%s ", loc->code);
     p = strstr (msg->response_body->data, searchkey);
-    g_free (searchkey);
+
     if (p) {
-       p += WEATHER_LOCATION_CODE_LEN + 2;
-       eoln = strchr(p, '\n');
+       p += strlen (searchkey);
+       eoln = strstr (p, "</raw_text>");
        if (eoln)
            metar = g_strndup (p, eoln - p);
        else
@@ -608,6 +608,8 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
        priv->network_error = TRUE;
     }
 
+    g_free (searchkey);
+
     priv->valid = success;
     _gweather_info_request_done (info, msg);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]