[geocode-glib] forward: Add description extension to geo uri



commit 931bd04172e87dacd7dbcd0001a271f328c429cf
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Tue Apr 8 22:09:38 2014 +0200

    forward: Add description extension to geo uri
    
    Android and Google Maps support an extention to geo uri that allows
    specifying a label to a location.
    
    The form is
        geo:0,0?q=lat,lng(label)
    
    This patch adds parsing of that format to GeocodeLocation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727861

 geocode-glib/geocode-location.c |   55 +++++++++++++++++++++++++++++++++++++++
 geocode-glib/test-geouri.c      |    8 +++++-
 2 files changed, 62 insertions(+), 1 deletions(-)
---
diff --git a/geocode-glib/geocode-location.c b/geocode-glib/geocode-location.c
index 133c992..2f9193d 100644
--- a/geocode-glib/geocode-location.c
+++ b/geocode-glib/geocode-location.c
@@ -202,6 +202,57 @@ geocode_location_set_property(GObject      *object,
         }
 }
 
+static void
+parse_geo_uri_special_parameters (GeocodeLocation *loc,
+                                  const char      *params,
+                                  GError         **error)
+{
+        char *end_ptr;
+        char *next_token;
+        char *description;
+        char *token_end;
+        int description_len;
+
+        if (loc->priv->latitude != 0 || loc->priv->longitude != 0)
+            goto err;
+
+        if (strncmp (params, "q=", 2) != 0)
+                goto err;
+
+        next_token = ((char *)params) + 2;
+
+        loc->priv->latitude = g_ascii_strtod (next_token, &end_ptr);
+        if (*end_ptr != ',' || *end_ptr == *params)
+                goto err;
+        next_token = end_ptr + 1;
+
+        loc->priv->longitude = g_ascii_strtod (next_token, &end_ptr);
+        if (*end_ptr == *next_token)
+                goto err;
+
+        if (*end_ptr != '(' || *end_ptr == *next_token)
+                goto err;
+        next_token = end_ptr + 1;
+
+        if ((token_end = strchr (next_token, ')')) == NULL)
+                goto err;
+
+        description_len = token_end - next_token;
+        if (description_len <= 0)
+            goto err;
+
+        description = g_strndup (next_token, description_len);
+        geocode_location_set_description (loc, description);
+        g_free (description);
+        return;
+
+ err:
+       g_set_error_literal (error,
+                            GEOCODE_ERROR,
+                            GEOCODE_ERROR_PARSE,
+                            "Failed to parse geo URI parameters");
+}
+
 /*
   From RFC 5870:
       Both 'crs' and 'u' parameters MUST NOT appear more than once each.
@@ -353,6 +404,10 @@ parse_geo_uri (GeocodeLocation *loc,
                 next_token = end_ptr + 1;
                 parse_geo_uri_parameters (loc, next_token, error);
                 return;
+        } else if (*end_ptr == '?') {
+                next_token = end_ptr + 1;
+                parse_geo_uri_special_parameters (loc, next_token, error);
+                return;
         } else if (*end_ptr == '\0') {
                 return;
         }
diff --git a/geocode-glib/test-geouri.c b/geocode-glib/test-geouri.c
index 97f1b89..1163564 100644
--- a/geocode-glib/test-geouri.c
+++ b/geocode-glib/test-geouri.c
@@ -34,7 +34,13 @@ static struct uri uris[] = {
     { "geo:13.37alpha,42.42", FALSE },
     { "geo:13.37,alpha42.42", FALSE },
     { "geo:13.37,42.42,12.alpha", FALSE },
-    { "geo:,13.37,42.42", FALSE }
+    { "geo:,13.37,42.42", FALSE },
+    { "geo:0,0?q=13.36,4242(description)", TRUE },
+    { "geo:0,0?q=-13.36,4242(description)", TRUE },
+    { "geo:0,0?q=13.36,-4242(description)", TRUE },
+    { "geo:1,2?q=13.36,4242(description)", FALSE },
+    { "geo:0,0?q=13.36,4242(description", FALSE },
+    { "geo:0,0?q=13.36,4242()", FALSE }
 };
 
 static void


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