[libgweather] owm: rework uri API key logic to use #define



commit 060a4f2edb848d8891e90157592b6aa147c2125e
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Dec 10 13:04:48 2013 -0500

    owm: rework uri API key logic to use #define
    
    Rework the logic for the URI template to use preprocessor defines
    instead of a local variable.  This means that we get proper checking of
    the format string and avoid the failure to compile under clang when
    -Werror=format-nonliteral is used (as it is by default in our CFLAGS
    from gnome-common).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=720208

 libgweather/weather-owm.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/libgweather/weather-owm.c b/libgweather/weather-owm.c
index 40a8832..06841b9 100644
--- a/libgweather/weather-owm.c
+++ b/libgweather/weather-owm.c
@@ -414,7 +414,6 @@ gboolean
 owm_start_open (GWeatherInfo *info)
 {
     GWeatherInfoPrivate *priv;
-    const char *template;
     gchar *url;
     SoupMessage *message;
     WeatherLocation *loc;
@@ -431,13 +430,16 @@ owm_start_open (GWeatherInfo *info)
     g_ascii_dtostr (latstr, sizeof(latstr), RADIANS_TO_DEGREES (loc->latitude));
     g_ascii_dtostr (lonstr, sizeof(lonstr), RADIANS_TO_DEGREES (loc->longitude));
 
-    template = "http://api.openweathermap.org/data/2.5/forecast?lat=%s&lon=%s&mode=xml&units=metric";
+#define TEMPLATE_START "http://api.openweathermap.org/data/2.5/forecast?lat=%s&lon=%s&mode=xml&units=metric";
 #ifdef OWM_APIKEY
-        "&APPID=" OWM_APIKEY
+ #define TEMPLATE TEMPLATE_START "&APPID=" OWM_APIKEY
+#else
+ #define TEMPLATE TEMPLATE_START
 #endif
-        ;
 
-    url = g_strdup_printf (template, latstr, lonstr);
+    url = g_strdup_printf (TEMPLATE, latstr, lonstr);
+
+#undef TEMPLATE
 
     message = soup_message_new ("GET", url);
     soup_session_queue_message (priv->session, message, owm_finish, info);


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