Commit 06083f1c authored by Jussi Kukkonen's avatar Jussi Kukkonen

change hostip provider to use GeocluWebService

Also add xml namespace handling to GeoclueWebService
parent b1ee090c
......@@ -167,12 +167,43 @@ geoclue_web_service_init (GTypeInstance *instance,
self->response = NULL;
self->xpath_ctx = NULL;
self->namespaces = NULL;
self->base_url = NULL;
self->using_connection_events = FALSE;
geoclue_web_service_connection_events_init (self);
}
/* A GFunc, use with g_list_foreach */
static void
geoclue_web_service_free_ns (gpointer data, gpointer user_data)
{
XmlNamespace *ns = (XmlNamespace *)data;
g_free (ns->name);
g_free (ns->uri);
g_free (ns);
}
/* A GFunc, use with g_list_foreach */
static void
geoclue_web_service_register_ns (gpointer data, gpointer user_data)
{
g_assert (GEOCLUE_IS_WEB_SERVICE (user_data));
GeoclueWebService *self = (GeoclueWebService *)user_data;
XmlNamespace *ns = (XmlNamespace *)data;
xmlXPathRegisterNs (self->xpath_ctx,
(xmlChar*)ns->name, (xmlChar*)ns->uri);
}
static void
geoclue_web_service_register_namespaces (GeoclueWebService *self)
{
g_assert (GEOCLUE_IS_WEB_SERVICE (self));
g_assert (self->xpath_ctx);
g_list_foreach (self->namespaces, (GFunc)geoclue_web_service_register_ns, self);
}
static void
geoclue_web_service_finalize (GObject *obj)
{
......@@ -183,6 +214,10 @@ geoclue_web_service_finalize (GObject *obj)
geoclue_web_service_connection_events_deinit (self);
g_free (self->base_url);
g_free (self->response);
g_list_foreach (self->namespaces, (GFunc)geoclue_web_service_free_ns, NULL);
g_list_free (self->namespaces);
xmlXPathFreeContext (self->xpath_ctx);
/*chain up*/
......@@ -210,6 +245,8 @@ geoclue_web_service_set_property (GObject *object,
case GEOCLUE_WEB_SERVICE_URL:
g_free (self->base_url);
g_free (self->response);
g_list_foreach (self->namespaces, (GFunc)geoclue_web_service_free_ns, NULL);
g_list_free (self->namespaces);
xmlXPathFreeContext (self->xpath_ctx);
self->base_url = g_value_dup_string (value);
g_debug ("set base_url: %s\n",self->base_url);
......@@ -381,9 +418,26 @@ geoclue_web_service_query (GeoclueWebService *self, ...)
}
g_assert (self->response);
g_free (url);
return (geoclue_seb_service_build_xpath_context (self));
if (!geoclue_seb_service_build_xpath_context (self)) {
return FALSE;
}
g_assert (self->xpath_ctx);
geoclue_web_service_register_namespaces (self);
return TRUE;
}
gboolean
geoclue_web_service_add_namespace (GeoclueWebService *self, gchar *namespace, gchar *uri)
{
g_return_val_if_fail (GEOCLUE_IS_WEB_SERVICE (self), FALSE);
g_return_val_if_fail (self->base_url, FALSE);
XmlNamespace *ns = g_new0(XmlNamespace,1);
ns->name = g_strdup (namespace);
ns->uri = g_strdup (uri);
self->namespaces = g_list_prepend (self->namespaces, ns);
}
gboolean
geoclue_web_service_get_double (GeoclueWebService *self, gdouble *OUT_value, gchar *xpath)
{
......
......@@ -16,7 +16,7 @@
* <http://www.gnu.org/licenses/>.
*/
/* A GeoclueWebService is meant to be used in webservice based geoclue
/* GeoclueWebService is meant to be used in webservice-based geoclue
* provider implementations. It has two tasks:
* a) simplify interaction with webservices
* a) notify about connectivity changes
......@@ -32,7 +32,7 @@
* "base_url", "http://plazes.com/suggestions.xml",
* NULL);
*
*** CONNECTION-EVENT
*** CONNECTION EVENT
*
* There's a "connection-event" signal for getting notified about
* connection events:
......@@ -70,6 +70,10 @@
* but if the data is xml it's easier to use
* "geoclue_web_service_get_*" -methods to get specific data using
* simple xpath expressions.
*
* If the xml data uses namespaces, they should be added with
* geoclue_web_service_add_namespace before calling
* geoclue_web_service_query.
*/
#ifndef GEOCLUE_WEB_SERVICE_H
......@@ -91,6 +95,12 @@
G_BEGIN_DECLS
typedef struct _XmlNamespace XmlNamespace;
struct _XmlNamespace {
gchar *name;
gchar *uri;
};
#define GEOCLUE_TYPE_WEB_SERVICE (geoclue_web_service_get_type ())
#define GEOCLUE_WEB_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOCLUE_TYPE_WEB_SERVICE, GeoclueWebService))
#define GEOCLUE_WEB_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEOCLUE_TYPE_WEB_SERVICE, GeoclueWebServiceClass))
......@@ -107,6 +117,7 @@ struct _GeoclueWebService {
/* private */
gchar* base_url;
gchar *response;
GList *namespaces;
gboolean using_connection_events;
xmlXPathContext *xpath_ctx;
......@@ -130,6 +141,8 @@ GType geoclue_web_service_get_type (void);
/* Public methods */
gboolean geoclue_web_service_query (GeoclueWebService *self, ...);
gboolean geoclue_web_service_add_namespace (GeoclueWebService *self, gchar *namespace, gchar *uri);
gboolean geoclue_web_service_get_string (GeoclueWebService *self, gchar **OUT_value, gchar *xpath);
gboolean geoclue_web_service_get_double (GeoclueWebService *self, gdouble *OUT_value, gchar *xpath);
......
......@@ -19,7 +19,7 @@ $(service_DATA): $(service_in_files) Makefile
AM_CPPFLAGS = $(YAHOO_CFLAGS) $(CONIC_CFLAGS) -I$(top_srcdir)
AM_LDFLAGS = $(YAHOO_LIBS) $(CONIC_LIBS) ../../geoclue/libgeoclue.la
AM_LDFLAGS = $(YAHOO_LIBS) $(CONIC_LIBS) ../../geoclue/libgeoclue.la ../common/geoclue_web_service.o
EXTRA_DIST = \
geoclue_position_server_hostip.h \
......
......@@ -20,19 +20,14 @@
#ifndef __GEOCLUE_POSITION_SERVER_H__
#define __GEOCLUE_POSITION_SERVER_H__
#define DBUS_API_SUBJECT_TO_CHANGE
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <glib.h>
#ifdef HAVE_LIBCONIC
#include <conicconnection.h>
#endif
#include "../common/geoclue_web_service.h"
#define GEOCLUE_POSITION_DBUS_SERVICE "org.freedesktop.geoclue.position.hostip"
#define GEOCLUE_POSITION_DBUS_PATH "/org/freedesktop/geoclue/position/hostip"
......@@ -40,7 +35,6 @@
G_BEGIN_DECLS
//Let's create a geoclue_position object that has one method of geoclue_position
typedef struct GeocluePosition GeocluePosition;
typedef struct GeocluePositionClass GeocluePositionClass;
......@@ -50,6 +44,8 @@ struct GeocluePosition
GObject parent;
GMainLoop* loop;
GeoclueWebService *web_service;
gdouble current_lat;
gdouble current_lon;
gboolean is_current_valid;
......@@ -66,11 +62,6 @@ struct GeocluePosition
gchar* civic_description;
gchar* civic_text;
gboolean is_civic_valid;
#ifdef HAVE_LIBCONIC
ConIcConnection* net_connection;
DBusConnection* dbus_connection;
#endif
};
struct GeocluePositionClass
......@@ -182,11 +173,7 @@ gboolean geoclue_position_shutdown( GeocluePosition *obj,
GError** error);
G_END_DECLS
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment