[geocode-glib/gnome-3-16] Add a default user-agent based on GApplication id
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib/gnome-3-16] Add a default user-agent based on GApplication id
- Date: Sun, 31 Jan 2016 09:07:52 +0000 (UTC)
commit 1b0681da3aaecbb8d9d0c645c1acc8ad84c326fc
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Fri Jan 8 09:06:13 2016 +0100
Add a default user-agent based on GApplication id
Nominatim’s usage policy requires a User-Agent. They want to be
able to block batch offenders that misuse the terms of service.
We can set a user-agent based on GApplication (if we are one) to
make sure at least trusted GNOME applications can be identified.
https://bugzilla.gnome.org/show_bug.cgi?id=756313
configure.ac | 2 +-
geocode-glib/Makefile.am | 1 +
geocode-glib/geocode-forward.c | 2 +-
geocode-glib/geocode-glib-private.h | 1 +
geocode-glib/geocode-glib.c | 23 +++++++++++++++++++++++
geocode-glib/geocode-reverse.c | 2 +-
6 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 73b6de6..a199096 100644
--- a/configure.ac
+++ b/configure.ac
@@ -62,7 +62,7 @@ dnl Requires for the library
PKG_CHECK_MODULES(GEOCODE,
gio-2.0 >= 2.34
json-glib-1.0 >= 0.99.2
- libsoup-2.4)
+ libsoup-2.4 >= 2.42)
GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`
AC_SUBST(GLIB_GENMARSHAL)
diff --git a/geocode-glib/Makefile.am b/geocode-glib/Makefile.am
index ef94fc3..f62056e 100644
--- a/geocode-glib/Makefile.am
+++ b/geocode-glib/Makefile.am
@@ -45,6 +45,7 @@ gcglib_HEADERS = \
AM_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_builddir) \
+ -DPACKAGE_VERSION=\"@PACKAGE_VERSION \" \
-DTEST_SRCDIR=\""$(srcdir)/data/"\" \
-DGEOCODE_LOCALEDIR=\"$(localedir)\"
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index 446d6b5..a01a7a2 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -202,7 +202,7 @@ geocode_forward_init (GeocodeForward *forward)
forward->priv = G_TYPE_INSTANCE_GET_PRIVATE ((forward), GEOCODE_TYPE_FORWARD, GeocodeForwardPrivate);
forward->priv->ht = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
- forward->priv->soup_session = soup_session_new ();
+ forward->priv->soup_session = _geocode_glib_build_soup_session ();
forward->priv->answer_count = DEFAULT_ANSWER_COUNT;
forward->priv->search_area = NULL;
forward->priv->bounded = FALSE;
diff --git a/geocode-glib/geocode-glib-private.h b/geocode-glib/geocode-glib-private.h
index c32c49f..730577f 100644
--- a/geocode-glib/geocode-glib-private.h
+++ b/geocode-glib/geocode-glib-private.h
@@ -56,6 +56,7 @@ gboolean _geocode_glib_cache_load (SoupMessage *query,
char **contents);
GHashTable *_geocode_glib_dup_hash_table (GHashTable *ht);
gboolean _geocode_object_is_number_after_street (void);
+SoupSession *_geocode_glib_build_soup_session (void);
G_END_DECLS
diff --git a/geocode-glib/geocode-glib.c b/geocode-glib/geocode-glib.c
index 0ac4eb5..4e3b3fd 100644
--- a/geocode-glib/geocode-glib.c
+++ b/geocode-glib/geocode-glib.c
@@ -37,6 +37,29 @@
* <ulink url="http://wiki.openstreetmap.org/wiki/Nominatim">OSM Nominatim APIs</ulink>
**/
+SoupSession *
+_geocode_glib_build_soup_session (void)
+{
+ GApplication *application;
+ SoupSession *session;
+ char *user_agent;
+
+ application = g_application_get_default ();
+ if (application) {
+ const char *id = g_application_get_application_id (application);
+ user_agent = g_strdup_printf ("geocode-glib/%s (%s)",
+ PACKAGE_VERSION, id);
+ } else {
+ user_agent = g_strdup_printf ("geocode-glib/%s",
+ PACKAGE_VERSION);
+ }
+
+ session = soup_session_new_with_options (SOUP_SESSION_USER_AGENT,
+ user_agent, NULL);
+ g_free (user_agent);
+ return session;
+}
+
char *
_geocode_glib_cache_path_for_query (SoupMessage *query)
{
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index 746c96c..199f2c5 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -79,7 +79,7 @@ geocode_reverse_init (GeocodeReverse *object)
object->priv = G_TYPE_INSTANCE_GET_PRIVATE ((object), GEOCODE_TYPE_REVERSE, GeocodeReversePrivate);
object->priv->ht = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
- object->priv->soup_session = soup_session_new ();
+ object->priv->soup_session = _geocode_glib_build_soup_session ();
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]