Blame SOURCES/0007-weather-add-app-ID-to-HTTP-user-agent.patch

3584c8
From 9e04624edff61f381365485565477f5302a2b93e Mon Sep 17 00:00:00 2001
3584c8
From: Michael Catanzaro <mcatanzaro@gnome.org>
3584c8
Date: Fri, 19 Mar 2021 15:45:52 -0500
3584c8
Subject: [PATCH 7/7] weather: add app ID to HTTP user agent
3584c8
3584c8
met.no has requested we add the app ID even if we cannot provide
3584c8
application contact info. See #82.
3584c8
---
3584c8
 libgweather/gweather-weather.c | 34 ++++++++++++++++++++++++++++++++--
3584c8
 1 file changed, 32 insertions(+), 2 deletions(-)
3584c8
3584c8
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
3584c8
index 62543169..f81aa7e2 100644
3584c8
--- a/libgweather/gweather-weather.c
3584c8
+++ b/libgweather/gweather-weather.c
3584c8
@@ -583,6 +583,37 @@ dump_and_unref_cache (SoupCache *cache)
3584c8
 
3584c8
 static SoupSession *static_session;
3584c8
 
3584c8
+static const char *
3584c8
+app_id (void)
3584c8
+{
3584c8
+    GApplication *app = g_application_get_default ();
3584c8
+    const char *id;
3584c8
+
3584c8
+    if (app) {
3584c8
+        id = g_application_get_application_id (app);
3584c8
+        if (id)
3584c8
+            return id;
3584c8
+    }
3584c8
+
3584c8
+    return g_get_prgname ();
3584c8
+}
3584c8
+
3584c8
+static char *
3584c8
+compute_user_agent (void)
3584c8
+{
3584c8
+    return g_strdup_printf ("libgweather/%s (+https://gitlab.gnome.org/GNOME/libgweather/) (%s) ", LIBGWEATHER_VERSION, app_id ());
3584c8
+}
3584c8
+
3584c8
+static const char *
3584c8
+user_agent (void)
3584c8
+{
3584c8
+  static GOnce once = G_ONCE_INIT;
3584c8
+
3584c8
+  g_once (&once, compute_user_agent, NULL);
3584c8
+
3584c8
+  return once.retval;
3584c8
+}
3584c8
+
3584c8
 static SoupSession *
3584c8
 ref_session (void)
3584c8
 {
3584c8
@@ -595,8 +626,7 @@ ref_session (void)
3584c8
 	return g_object_ref (session);
3584c8
 
3584c8
     session = soup_session_new ();
3584c8
-    g_object_set (G_OBJECT (session), SOUP_SESSION_USER_AGENT,
3584c8
-                  "libgweather/" LIBGWEATHER_VERSION " (+https://gitlab.gnome.org/GNOME/libgweather/) ", NULL);
3584c8
+    g_object_set (G_OBJECT (session), SOUP_SESSION_USER_AGENT, user_agent (), NULL);
3584c8
 
3584c8
     cache = get_cache ();
3584c8
     if (cache != NULL) {
3584c8
-- 
3584c8
2.30.2
3584c8