From 2a2aface6fddf173e48f4e86a8e2d6941a7498cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberts=20Muktup=C4=81vels?= Date: Mon, 30 Apr 2018 14:14:09 +0300 Subject: 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\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 ("%s", loc->code); + searchkey = g_strdup_printf ("%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, ""); 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); } -- cgit v1.2.1