[geocode-glib] server: Fix error when QUERY_STRING is not passed
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib] server: Fix error when QUERY_STRING is not passed
- Date: Mon, 14 Jan 2013 07:01:28 +0000 (UTC)
commit f663b538ba2fc2ec9dd5612b0dd29f40cdaa52ca
Author: Bastien Nocera <hadess hadess net>
Date: Sun Jan 13 21:16:29 2013 +0100
server: Fix error when QUERY_STRING is not passed
We would bail out as soon as we saw that the query string was empty,
but we would lookup REMOTE_ADDR if the query string was invalid.
geocode-glib/geocode-ip-server/geoip-lookup.c | 38 ++++++++++++++----------
1 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/geocode-glib/geocode-ip-server/geoip-lookup.c b/geocode-glib/geocode-ip-server/geoip-lookup.c
index 5d35297..9cd7354 100644
--- a/geocode-glib/geocode-ip-server/geoip-lookup.c
+++ b/geocode-glib/geocode-ip-server/geoip-lookup.c
@@ -177,28 +177,36 @@ ip_addr_lookup (const gchar *ipaddress)
GeoIP_delete (gi);
}
-static gchar *
-get_ipaddress (void)
+static char *
+get_ipaddress_from_query (void)
{
- const gchar *data;
- const gchar *value;
- gchar *ipaddress;
GHashTable *table;
- GInetAddress *inet_address;
+ const char *data;
+ char *value;
data = g_getenv ("QUERY_STRING");
- if (data == NULL) {
- print_error_in_json (PARSE_ERR, NULL);
+ if (data == NULL)
return NULL;
- }
table = soup_form_decode (data);
- value = g_hash_table_lookup (table, "ip");
+ value = g_strdup (g_hash_table_lookup (table, "ip"));
+ g_hash_table_destroy (table);
+
+ return value;
+}
+
+static gchar *
+get_ipaddress (void)
+{
+ char *value;
+ GInetAddress *inet_address;
+
+ value = get_ipaddress_from_query ();
if (!value) {
- value = g_getenv ("REMOTE_ADDR");
+ value = g_strdup (g_getenv ("REMOTE_ADDR"));
if (!value) {
print_error_in_json (PARSE_ERR, NULL);
- g_hash_table_destroy (table);
+ g_free (value);
return NULL;
}
}
@@ -206,15 +214,13 @@ get_ipaddress (void)
inet_address = g_inet_address_new_from_string (value);
if (!inet_address) {
print_error_in_json (INVALID_IP_ADDRESS_ERR, NULL);
- g_hash_table_destroy (table);
+ g_free (value);
return NULL;
}
- ipaddress = g_strdup (value);
- g_hash_table_destroy (table);
g_object_unref (inet_address);
- return ipaddress;
+ return value;
}
int
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]