Commit e8c8fc35 authored by Zeeshan Ali's avatar Zeeshan Ali

Import all geocode-glib sources

Instead of just importing geocode-location, we now import all its
sources into a subdir. Not only latest geocode-location needs a few
other files but also is the fact that we'll likely need to use more of
geocode-glib API in geoclue.

This commit also updates geocode-location.
parent 2d5958b2
......@@ -191,6 +191,7 @@ AC_CONFIG_FILES([
src/Makefile
src/geoclue-2.0.pc
src/agent/Makefile
src/geocode-glib/Makefile
src/geoip-server/Makefile
po/Makefile.in
data/org.freedesktop.GeoClue2.conf
......
......@@ -7,7 +7,7 @@ install-exec-hook:
echo "Unable to setcap cap_sys_ptrace+ep $(libexecdir)/geoclue. " \
"Package systems may do this after installation."
SUBDIRS = agent
SUBDIRS = agent geocode-glib
if BUILD_GEOIP_SERVER
SUBDIRS += geoip-server
......@@ -66,17 +66,16 @@ libgeoclue_la_SOURCES = \
gclue-web-source.c \
gclue-web-source.h \
gclue-enums.h \
geocode-location.c \
geocode-location.h \
$(NULL)
libgeoclue_la_LIBADD = $(GEOCLUE_LIBS) $(LIBS)
geoclue_SOURCES = \
gclue-main.c \
$(NULL)
geoclue_LDADD = $(GEOCLUE_LIBS) \
$(LIBS) \
$(builddir)/libgeoclue.la
geoclue_LDADD = $(GEOCLUE_LIBS) \
$(LIBS) \
$(builddir)/libgeoclue.la \
$(builddir)/geocode-glib/libgeocode-glib.la
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = $(interface_DATA) \
......@@ -86,12 +85,6 @@ EXTRA_DIST = $(interface_DATA) \
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = geoclue-2.0.pc
GEOCODEGLIBDIR=$(top_srcdir)/../geocode-glib/geocode-glib/
GEOCODEGLIBFILES=geocode-location.c geocode-location.h
update-from-geocode-glib:
FILES="$(GEOCODEGLIBFILES)" DIR="$(GEOCODEGLIBDIR)" $(srcdir)/update-from-geocode-glib.sh && changed=true ; \
git commit -m "location: Update from geocode-glib" $(GEOCODEGLIBFILES)
# Enum types
GEOCLUE_ENUMS = \
$(srcdir)/gclue-enums.h
......
......@@ -24,7 +24,7 @@
#define GCLUE_CONFIG_H
#include <gio/gio.h>
#include "geocode-location.h"
#include "geocode-glib/geocode-location.h"
#include "gclue-client-info.h"
#include "gclue-config.h"
......
......@@ -24,7 +24,7 @@
#include <glib.h>
#include <gio/gio.h>
#include "geocode-location.h"
#include "geocode-glib/geocode-location.h"
G_BEGIN_DECLS
......
......@@ -24,7 +24,7 @@
#define GCLUE_LOCATOR_H
#include <gio/gio.h>
#include "geocode-location.h"
#include "geocode-glib/geocode-location.h"
#include "gclue-enum-types.h"
#include "gclue-location-source.h"
......
......@@ -24,7 +24,7 @@
#define GCLUE_SERVICE_LOCATION_H
#include <glib-object.h>
#include "geocode-location.h"
#include "geocode-glib/geocode-location.h"
#include "gclue-client-info.h"
#include "geoclue-interface.h"
......
......@@ -26,7 +26,7 @@
#include <string.h>
#include "gclue-web-source.h"
#include "gclue-error.h"
#include "geocode-location.h"
#include "geocode-glib/geocode-location.h"
/**
* SECTION:gclue-web-source
......
......@@ -29,7 +29,7 @@
#include "gclue-wifi.h"
#include "gclue-config.h"
#include "gclue-error.h"
#include "geocode-location.h"
#include "geocode-glib/geocode-location.h"
/* Since we use the Geolocate API (rather than Search), we could easily switch
* to Google geolocation service in future, if such a need arises.
......
This diff is collapsed.
/*
Copyright (C) 2013 Jonas Danielsson
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Authors: Jonas Danielsson <jonas@threetimestwo.org>
*/
#ifndef GEOCODE_BOUNDING_BOX_H
#define GEOCODE_BOUNDING_BOX_H
#include <glib-object.h>
G_BEGIN_DECLS
GType geocode_bounding_box_get_type (void) G_GNUC_CONST;
#define GEOCODE_TYPE_BOUNDING_BOX (geocode_bounding_box_get_type ())
#define GEOCODE_BOUNDING_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOCODE_TYPE_BOUNDING_BOX, GeocodeBoundingBox))
#define GEOCODE_IS_BOUNDING_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEOCODE_TYPE_BOUNDING_BOX))
#define GEOCODE_BOUNDING_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEOCODE_TYPE_BOUNDING_BOX, GeocodeBoundingBoxClass))
#define GEOCODE_IS_BOUNDING_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEOCODE_TYPE_BOUNDING_BOX))
#define GEOCODE_BOUNDING_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEOCODE_TYPE_BOUNDING_BOX, GeocodeBoundingBoxClass))
typedef struct _GeocodeBoundingBox GeocodeBoundingBox;
typedef struct _GeocodeBoundingBoxClass GeocodeBoundingBoxClass;
typedef struct _GeocodeBoundingBoxPrivate GeocodeBoundingBoxPrivate;
/**
* GeocodeBoundingBox:
*
* All the fields in the #GeocodeLocation structure are private and should
* never be accessed directly.
**/
struct _GeocodeBoundingBox {
/* <private> */
GObject parent_instance;
GeocodeBoundingBoxPrivate *priv;
};
/**
* GeocodeBoundingBoxClass:
*
* All the fields in the #GeocodeBoundingBoxClass structure are private and
* should never be accessed directly.
**/
struct _GeocodeBoundingBoxClass {
/* <private> */
GObjectClass parent_class;
};
GeocodeBoundingBox *geocode_bounding_box_new (gdouble top,
gdouble bottom,
gdouble left,
gdouble right);
gdouble geocode_bounding_box_get_top (GeocodeBoundingBox *bbox);
gdouble geocode_bounding_box_get_bottom (GeocodeBoundingBox *bbox);
gdouble geocode_bounding_box_get_left (GeocodeBoundingBox *bbox);
gdouble geocode_bounding_box_get_right (GeocodeBoundingBox *bbox);
G_END_DECLS
#endif /* GEOCODE_BOUNDING_BOX_H */
#include <geocode-glib/geocode-glib.h>
#include <geocode-glib/geocode-enum-types.h>
/* enumerations from "geocode-location.h" */
GType
geocode_location_uri_scheme_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
{ GEOCODE_LOCATION_URI_SCHEME_GEO, "GEOCODE_LOCATION_URI_SCHEME_GEO", "geo" },
{ 0, NULL, NULL }
};
etype = g_enum_register_static ("GeocodeLocationURIScheme", values);
}
return etype;
}
GType
geocode_location_crs_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
{ GEOCODE_LOCATION_CRS_WGS84, "GEOCODE_LOCATION_CRS_WGS84", "wgs84" },
{ 0, NULL, NULL }
};
etype = g_enum_register_static ("GeocodeLocationCRS", values);
}
return etype;
}
/* enumerations from "geocode-error.h" */
GType
geocode_error_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
{ GEOCODE_ERROR_PARSE, "GEOCODE_ERROR_PARSE", "parse" },
{ GEOCODE_ERROR_NOT_SUPPORTED, "GEOCODE_ERROR_NOT_SUPPORTED", "not-supported" },
{ GEOCODE_ERROR_NO_MATCHES, "GEOCODE_ERROR_NO_MATCHES", "no-matches" },
{ GEOCODE_ERROR_INVALID_ARGUMENTS, "GEOCODE_ERROR_INVALID_ARGUMENTS", "invalid-arguments" },
{ GEOCODE_ERROR_INTERNAL_SERVER, "GEOCODE_ERROR_INTERNAL_SERVER", "internal-server" },
{ 0, NULL, NULL }
};
etype = g_enum_register_static ("GeocodeError", values);
}
return etype;
}
/* enumerations from "geocode-place.h" */
GType
geocode_place_type_get_type (void)
{
static GType etype = 0;
if (etype == 0) {
static const GEnumValue values[] = {
{ GEOCODE_PLACE_TYPE_UNKNOWN, "GEOCODE_PLACE_TYPE_UNKNOWN", "unknown" },
{ GEOCODE_PLACE_TYPE_BUILDING, "GEOCODE_PLACE_TYPE_BUILDING", "building" },
{ GEOCODE_PLACE_TYPE_STREET, "GEOCODE_PLACE_TYPE_STREET", "street" },
{ GEOCODE_PLACE_TYPE_TOWN, "GEOCODE_PLACE_TYPE_TOWN", "town" },
{ GEOCODE_PLACE_TYPE_STATE, "GEOCODE_PLACE_TYPE_STATE", "state" },
{ GEOCODE_PLACE_TYPE_COUNTY, "GEOCODE_PLACE_TYPE_COUNTY", "county" },
{ GEOCODE_PLACE_TYPE_LOCAL_ADMINISTRATIVE_AREA, "GEOCODE_PLACE_TYPE_LOCAL_ADMINISTRATIVE_AREA", "local-administrative-area" },
{ GEOCODE_PLACE_TYPE_POSTAL_CODE, "GEOCODE_PLACE_TYPE_POSTAL_CODE", "postal-code" },
{ GEOCODE_PLACE_TYPE_COUNTRY, "GEOCODE_PLACE_TYPE_COUNTRY", "country" },
{ GEOCODE_PLACE_TYPE_ISLAND, "GEOCODE_PLACE_TYPE_ISLAND", "island" },
{ GEOCODE_PLACE_TYPE_AIRPORT, "GEOCODE_PLACE_TYPE_AIRPORT", "airport" },
{ GEOCODE_PLACE_TYPE_RAILWAY_STATION, "GEOCODE_PLACE_TYPE_RAILWAY_STATION", "railway-station" },
{ GEOCODE_PLACE_TYPE_BUS_STOP, "GEOCODE_PLACE_TYPE_BUS_STOP", "bus-stop" },
{ GEOCODE_PLACE_TYPE_MOTORWAY, "GEOCODE_PLACE_TYPE_MOTORWAY", "motorway" },
{ GEOCODE_PLACE_TYPE_DRAINAGE, "GEOCODE_PLACE_TYPE_DRAINAGE", "drainage" },
{ GEOCODE_PLACE_TYPE_LAND_FEATURE, "GEOCODE_PLACE_TYPE_LAND_FEATURE", "land-feature" },
{ GEOCODE_PLACE_TYPE_MISCELLANEOUS, "GEOCODE_PLACE_TYPE_MISCELLANEOUS", "miscellaneous" },
{ GEOCODE_PLACE_TYPE_SUPERNAME, "GEOCODE_PLACE_TYPE_SUPERNAME", "supername" },
{ GEOCODE_PLACE_TYPE_POINT_OF_INTEREST, "GEOCODE_PLACE_TYPE_POINT_OF_INTEREST", "point-of-interest" },
{ GEOCODE_PLACE_TYPE_SUBURB, "GEOCODE_PLACE_TYPE_SUBURB", "suburb" },
{ GEOCODE_PLACE_TYPE_COLLOQUIAL, "GEOCODE_PLACE_TYPE_COLLOQUIAL", "colloquial" },
{ GEOCODE_PLACE_TYPE_ZONE, "GEOCODE_PLACE_TYPE_ZONE", "zone" },
{ GEOCODE_PLACE_TYPE_HISTORICAL_STATE, "GEOCODE_PLACE_TYPE_HISTORICAL_STATE", "historical-state" },
{ GEOCODE_PLACE_TYPE_HISTORICAL_COUNTY, "GEOCODE_PLACE_TYPE_HISTORICAL_COUNTY", "historical-county" },
{ GEOCODE_PLACE_TYPE_CONTINENT, "GEOCODE_PLACE_TYPE_CONTINENT", "continent" },
{ GEOCODE_PLACE_TYPE_TIME_ZONE, "GEOCODE_PLACE_TYPE_TIME_ZONE", "time-zone" },
{ GEOCODE_PLACE_TYPE_ESTATE, "GEOCODE_PLACE_TYPE_ESTATE", "estate" },
{ GEOCODE_PLACE_TYPE_HISTORICAL_TOWN, "GEOCODE_PLACE_TYPE_HISTORICAL_TOWN", "historical-town" },
{ GEOCODE_PLACE_TYPE_OCEAN, "GEOCODE_PLACE_TYPE_OCEAN", "ocean" },
{ GEOCODE_PLACE_TYPE_SEA, "GEOCODE_PLACE_TYPE_SEA", "sea" },
{ 0, NULL, NULL }
};
etype = g_enum_register_static ("GeocodePlaceType", values);
}
return etype;
}
#ifndef __GEOCODE_ENUM_TYPES_H__
#define __GEOCODE_ENUM_TYPES_H__
#include <glib-object.h>
G_BEGIN_DECLS
/* enumerations from "geocode-location.h" */
GType geocode_location_uri_scheme_get_type (void) G_GNUC_CONST;
#define GEOCODE_TYPE_LOCATION_URI_SCHEME (geocode_location_uri_scheme_get_type())
/**
* SECTION:geocode-enum-types
* @short_description: Geocode enumerated types
* @include: geocode-glib/geocode-glib.h
*
* The enumerated types defined and used by geocode-glib.
**/
GType geocode_location_crs_get_type (void) G_GNUC_CONST;
#define GEOCODE_TYPE_LOCATION_CRS (geocode_location_crs_get_type())
/**
* SECTION:geocode-enum-types
* @short_description: Geocode enumerated types
* @include: geocode-glib/geocode-glib.h
*
* The enumerated types defined and used by geocode-glib.
**/
/* enumerations from "geocode-error.h" */
GType geocode_error_get_type (void) G_GNUC_CONST;
#define GEOCODE_TYPE_ERROR (geocode_error_get_type())
/**
* SECTION:geocode-enum-types
* @short_description: Geocode enumerated types
* @include: geocode-glib/geocode-glib.h
*
* The enumerated types defined and used by geocode-glib.
**/
/* enumerations from "geocode-place.h" */
GType geocode_place_type_get_type (void) G_GNUC_CONST;
#define GEOCODE_TYPE_PLACE_TYPE (geocode_place_type_get_type())
/**
* SECTION:geocode-enum-types
* @short_description: Geocode enumerated types
* @include: geocode-glib/geocode-glib.h
*
* The enumerated types defined and used by geocode-glib.
**/
G_END_DECLS
#endif /* __GEOCODE_ENUM_TYPES_H__ */
/*
Copyright (C) 2011 Bastien Nocera
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Authors: Bastien Nocera <hadess@hadess.net>
*/
#include <geocode-glib/geocode-error.h>
/**
* SECTION:geocode-error
* @short_description: Error helper functions
* @include: geocode-glib/geocode-glib.h
*
* Contains helper functions for reporting errors to the user.
**/
/**
* geocode_error_quark:
*
* Gets the geocode-glib error quark.
*
* Return value: a #GQuark.
**/
GQuark
geocode_error_quark (void)
{
static GQuark quark;
if (!quark)
quark = g_quark_from_static_string ("geocode_error");
return quark;
}
/*
Copyright (C) 2011 Bastien Nocera
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Authors: Bastien Nocera <hadess@hadess.net>
*/
#ifndef GEOCODE_ERROR_H
#define GEOCODE_ERROR_H
#include <glib.h>
G_BEGIN_DECLS
/**
* GEOCODE_ERROR:
*
* Error domain for geocode-glib. Errors from this domain will be from
* the #GeocodeError enumeration.
* See #GError for more information on error domains.
**/
#define GEOCODE_ERROR (geocode_error_quark ())
/**
* GeocodeError:
* @GEOCODE_ERROR_PARSE: An error occured parsing the response from the web service.
* @GEOCODE_ERROR_NOT_SUPPORTED: The request made was not supported.
* @GEOCODE_ERROR_NO_MATCHES: The requests made didn't have any matches.
* @GEOCODE_ERROR_INVALID_ARGUMENTS: The request made contained invalid arguments.
* @GEOCODE_ERROR_INTERNAL_SERVER: The server encountered an (possibly unrecoverable) internal error.
*
* Error codes returned by geocode-glib functions.
**/
typedef enum {
GEOCODE_ERROR_PARSE,
GEOCODE_ERROR_NOT_SUPPORTED,
GEOCODE_ERROR_NO_MATCHES,
GEOCODE_ERROR_INVALID_ARGUMENTS,
GEOCODE_ERROR_INTERNAL_SERVER
} GeocodeError;
GQuark geocode_error_quark (void);
G_END_DECLS
#endif /* GEOCODE_ERROR_H */
This diff is collapsed.
/*
Copyright (C) 2012 Bastien Nocera
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Authors: Bastien Nocera <hadess@hadess.net>
*/
#ifndef GEOCODE_FORWARD_H
#define GEOCODE_FORWARD_H
#include <glib.h>
#include <gio/gio.h>
#include <geocode-glib/geocode-glib.h>
#include <geocode-glib/geocode-bounding-box.h>
G_BEGIN_DECLS
GType geocode_forward_get_type (void) G_GNUC_CONST;
#define GEOCODE_TYPE_FORWARD (geocode_forward_get_type ())
#define GEOCODE_FORWARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOCODE_TYPE_FORWARD, GeocodeForward))
#define GEOCODE_IS_FORWARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEOCODE_TYPE_FORWARD))
#define GEOCODE_FORWARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEOCODE_TYPE_FORWARD, GeocodeForwardClass))
#define GEOCODE_IS_FORWARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEOCODE_TYPE_FORWARD))
#define GEOCODE_FORWARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEOCODE_TYPE_FORWARD, GeocodeForwardClass))
/**
* GeocodeForward:
*
* All the fields in the #GeocodeForward structure are private and should never be accessed directly.
**/
typedef struct _GeocodeForward GeocodeForward;
typedef struct _GeocodeForwardClass GeocodeForwardClass;
typedef struct _GeocodeForwardPrivate GeocodeForwardPrivate;
struct _GeocodeForward {
/* <private> */
GObject parent_instance;
GeocodeForwardPrivate *priv;
};
/**
* GeocodeForwardClass:
*
* All the fields in the #GeocodeForwardClass structure are private and should never be accessed directly.
**/
struct _GeocodeForwardClass {
/* <private> */
GObjectClass parent_class;
};
GeocodeForward *geocode_forward_new_for_string (const char *str);
GeocodeForward *geocode_forward_new_for_params (GHashTable *params);
guint geocode_forward_get_answer_count (GeocodeForward *forward);
void geocode_forward_set_answer_count (GeocodeForward *forward,
guint count);
GeocodeBoundingBox * geocode_forward_get_search_area (GeocodeForward *forward);
void geocode_forward_set_search_area (GeocodeForward *forward,
GeocodeBoundingBox *box);
gboolean geocode_forward_get_bounded (GeocodeForward *forward);
void geocode_forward_set_bounded (GeocodeForward *forward,
gboolean bounded);
void geocode_forward_search_async (GeocodeForward *forward,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GList *geocode_forward_search_finish (GeocodeForward *forward,
GAsyncResult *res,
GError **error);
GList *geocode_forward_search (GeocodeForward *forward,
GError **error);
G_END_DECLS
#endif /* GEOCODE_FORWARD_H */
/*
Copyright (C) 2010 Bastien Nocera
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Authors: Bastien Nocera <hadess@hadess.net>
*/
#ifndef GEOCODE_GLIB_PRIVATE_H
#define GEOCODE_GLIB_PRIVATE_H
#include <glib.h>
#include <libsoup/soup.h>
#include <json-glib/json-glib.h>
#include <geocode-glib/geocode-location.h>
#include <geocode-glib/geocode-place.h>
G_BEGIN_DECLS
#define YAHOO_APPID "zznSbDjV34HRU5CXQc4D3qE1DzCsJTaKvWTLhNJxbvI_JTp1hIncJ4xTSJFRgjE-"
#define DEFAULT_ANSWER_COUNT 10
typedef enum {
GEOCODE_GLIB_RESOLVE_FORWARD,
GEOCODE_GLIB_RESOLVE_REVERSE
} GeocodeLookupType;
GList *_geocode_parse_search_json (const char *contents,
GError **error);
GeocodeLocation *_geocode_ip_json_to_location (const char *json,
GError **error);
void
_geocode_read_nominatim_attributes (JsonReader *reader,
GHashTable *ht);
GeocodePlace *
_geocode_create_place_from_attributes (GHashTable *ht);
char *_geocode_object_get_lang (void);
char *_geocode_glib_cache_path_for_query (SoupMessage *query);
gboolean _geocode_glib_cache_save (SoupMessage *query,
const char *contents);
gboolean _geocode_glib_cache_load (SoupMessage *query,
char **contents);
GHashTable *_geocode_glib_dup_hash_table (GHashTable *ht);
G_END_DECLS
#endif /* GEOCODE_GLIB_PRIVATE_H */
/*
Copyright (C) 2011 Bastien Nocera
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA.
Authors: Bastien Nocera <hadess@hadess.net>
*/
#include <string.h>
#include <errno.h>
#include <locale.h>
#include <gio/gio.h>
#include <json-glib/json-glib.h>
#include <libsoup/soup.h>
#include <geocode-glib/geocode-glib.h>
#include <geocode-glib/geocode-error.h>
#include <geocode-glib/geocode-glib-private.h>
/**
* SECTION:geocode-glib
* @short_description: Geocode glib main functions
* @include: geocode-glib/geocode-glib.h
*
* Contains functions for geocoding and reverse geocoding using the
* <ulink url="http://wiki.openstreetmap.org/wiki/Nominatim">OSM Nominatim APIs</ulink>
**/
char *
_geocode_glib_cache_path_for_query (SoupMessage *query)
{
const char *filename;
char *path;
SoupURI *soup_uri;
char *uri;
GChecksum *sum;
/* Create cache directory */
path = g_build_filename (g_get_user_cache_dir (),
"geocode-glib",
NULL);
if (g_mkdir_with_parents (path, 0700) < 0) {
g_warning ("Failed to mkdir path '%s': %s", path, g_strerror (errno));
g_free (path);
return NULL;
}
g_free (path);
/* Create path for query */
soup_uri = soup_message_get_uri (query);
uri = soup_uri_to_string (soup_uri, FALSE);
sum = g_checksum_new (G_CHECKSUM_SHA256);
g_checksum_update (sum, (const guchar *) uri, strlen (uri));
filename = g_checksum_get_string (sum);
path = g_build_filename (g_get_user_cache_dir (),
"geocode-glib",
filename,
NULL);
g_checksum_free (sum);
g_free (uri);
return path;
}
gboolean
_geocode_glib_cache_save (SoupMessage *query,
const char *contents)
{
char *path;
gboolean ret;
path = _geocode_glib_cache_path_for_query (query);
g_debug ("Saving cache file '%s'", path);
ret = g_file_set_contents (path, contents, -1, NULL);
g_free (path);
return ret;
}
gboolean
_geocode_glib_cache_load (SoupMessage *query,
char **contents)
{
char *path;
gboolean ret;
path = _geocode_glib_cache_path_for_query (query);
g_debug ("Loading cache file '%s'", path);
ret = g_file_get_contents (path, contents, NULL, NULL);
g_free (path);
return ret;
}
static gboolean
parse_lang (const char *locale,
char **language_codep,
char **territory_codep)
{
GRegex *re;
GMatchInfo *match_info;
gboolean res;