After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 696526 - lib: geocode_ipclient_search* should return location
lib: geocode_ipclient_search* should return location
Status: RESOLVED FIXED
Product: geocode-glib
Classification: Other
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: geocode-glib maintainer(s)
geocode-glib maintainer(s)
Depends on:
Blocks: 696527
 
 
Reported: 2013-03-25 00:20 UTC by Zeeshan Ali
Modified: 2013-04-03 15:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
lib: Add error code for internal server errors (1.24 KB, patch)
2013-03-25 00:20 UTC, Zeeshan Ali
committed Details | Review
lib: geocode_ipclient_search* should return location (9.78 KB, patch)
2013-03-25 00:20 UTC, Zeeshan Ali
needs-work Details | Review
server: Put server errors into a separate header (1.78 KB, patch)
2013-03-27 01:30 UTC, Zeeshan Ali
committed Details | Review
lib: geocode_ipclient_search* should return location (12.14 KB, patch)
2013-03-27 01:30 UTC, Zeeshan Ali
committed Details | Review
Add testcases for _geocode_ip_json_to_location() (4.60 KB, patch)
2013-04-02 22:07 UTC, Zeeshan Ali
accepted-commit_now Details | Review
Add testcases for _geocode_ip_json_to_location() (4.38 KB, patch)
2013-04-03 14:57 UTC, Zeeshan Ali
committed Details | Review

Description Zeeshan Ali 2013-03-25 00:20:04 UTC
See patches
Comment 1 Zeeshan Ali 2013-03-25 00:20:06 UTC
Created attachment 239711 [details] [review]
lib: Add error code for internal server errors
Comment 2 Zeeshan Ali 2013-03-25 00:20:10 UTC
Created attachment 239712 [details] [review]
lib: geocode_ipclient_search* should return location

This API will be a lot more useful if we provide a parsed GeocodeLocation
object to the caller rather than just the raw JSON string we get as
response from server.
Comment 3 Bastien Nocera 2013-03-25 14:16:02 UTC
Review of attachment 239711 [details] [review]:

Sure.
Comment 4 Bastien Nocera 2013-03-25 14:32:03 UTC
Review of attachment 239712 [details] [review]:

::: geocode-glib/geocode-ipclient.c
@@ +46,3 @@
+        SERVER_INVALID_ENTRY,
+        SERVER_DATABASE
+} ServerError;

That needs to be moved to a common header so it can be shared with the server.

@@ +344,3 @@
+        location->longitude = json_object_get_double_member (object, "longitude");
+
+        string = g_string_new ("");

Concatenating strings like that won't work.

We should ensure that if you have the city name, you have the region and the country_name, and then you could do:
if (has_member ("city"))
  desc = g_strdup_printf ("%s, %s (%s)", city, region, country);
Comment 5 Zeeshan Ali 2013-03-27 01:30:18 UTC
Created attachment 239909 [details] [review]
server: Put server errors into a separate header
Comment 6 Zeeshan Ali 2013-03-27 01:30:53 UTC
Created attachment 239910 [details] [review]
lib: geocode_ipclient_search* should return location

This API will be a lot more useful if we provide a parsed GeocodeLocation
object to the caller rather than just the raw JSON string we get as
response from server.
Comment 7 Bastien Nocera 2013-04-02 17:18:19 UTC
Review of attachment 239909 [details] [review]:

::: geocode-glib/geocode-ip-server/geoip-server.h
@@ +4,3 @@
+#define GEOIP_SERVER_H
+
+#include <glib.h>

No need to include glib here.
Comment 8 Bastien Nocera 2013-04-02 17:34:14 UTC
Review of attachment 239910 [details] [review]:

Short version: fixed the bugs, needs tests added.

::: geocode-glib/geocode-ipclient.c
@@ +285,3 @@
 
+static gboolean
+parse_server_error (JsonObject *object, GError **error) {

brace on the following line. Fixed in the committed patch.

@@ +317,3 @@
+
+static GeocodeLocation *
+json_to_location (const char *json, GError **error) {

Ditto wrt the brace.

I've also made this private to the module so it can be reused in tests (feed it a json output, and check that it's parsed properly without blowing up).

You'll need to provide a few tests for this too.

@@ +339,3 @@
+        location->longitude = json_object_get_double_member (object, "longitude");
+
+        if (json_object_has_member (object, "city"))

I've reorganised this so that we don't cause problems if city is set but not region_name for example.
(we should avoid creating this in the server, but we should be resilient in the client).

@@ +353,3 @@
+
+        if (desc != NULL) {
+            geocode_location_set_description (location, desc);

8-characters indentation :)
Fixed too.
Comment 9 Bastien Nocera 2013-04-02 17:44:29 UTC
Attachment 239711 [details] pushed as e25df53 - lib: Add error code for internal server errors
Attachment 239909 [details] pushed as 4f1b35a - server: Put server errors into a separate header
Comment 10 Zeeshan Ali 2013-04-02 20:29:38 UTC
Review of attachment 239910 [details] [review]:

Thanks for fixing all this. :)
Comment 11 Zeeshan Ali 2013-04-02 22:07:20 UTC
Created attachment 240439 [details] [review]
Add testcases for _geocode_ip_json_to_location()

Test this function against responses from both our server and freegeoip.
Comment 12 Bastien Nocera 2013-04-03 14:14:13 UTC
Review of attachment 240439 [details] [review]:

Looks good apart from that.

::: geocode-glib/test-geoip-parse.c
@@ +30,3 @@
+                g_error_free (error);
+        }
+        g_free(contents);

space missing.

@@ +42,3 @@
+        g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=");
+
+        g_test_add_data_func ("/geoip/parse-freegeoip-response",

Merge into the existing test suite please.
Comment 13 Zeeshan Ali 2013-04-03 14:57:46 UTC
Created attachment 240485 [details] [review]
Add testcases for _geocode_ip_json_to_location()

Test this function against responses from both our server and freegeoip.
Comment 14 Bastien Nocera 2013-04-03 15:01:33 UTC
Review of attachment 240485 [details] [review]:

Looks good to commit.

::: geocode-glib/test-geoip.c
@@ +28,3 @@
+        GError *error = NULL;
+
+        path = g_build_filename(TEST_SRCDIR, (const char *) data, NULL);

space.

@@ +30,3 @@
+        path = g_build_filename(TEST_SRCDIR, (const char *) data, NULL);
+        g_assert (path != NULL);
+        file = g_file_new_for_path(path);

space.

@@ +43,3 @@
+        }
+        g_free (contents);
+        g_free(path);

space.
Comment 15 Zeeshan Ali 2013-04-03 15:44:17 UTC
Attachment 240485 [details] pushed as 4f1f6aa - Add testcases for _geocode_ip_json_to_location()