Commit c9718de1 authored by Jussi Kukkonen's avatar Jussi Kukkonen

convert map_yahoo-backend to new GeoclueWebService

Includes small changes to GeoclueWebService to make it more
suitable for fetching binary data.
parent 15fd5eef
This diff is collapsed.
...@@ -62,12 +62,12 @@ ...@@ -62,12 +62,12 @@
* } * }
* *
* So, geoclue_web_service_query takes a NULL-terminated list of * So, geoclue_web_service_query takes a NULL-terminated list of
* key-value pairs that will be appended to base_url. The value part * key-value pairs that will be used as GET params. The value part
* will be escaped. The example case query url will be: * of the pair will be escaped. The example case query url will be:
* "http://plazes.com/suggestions.xml?mac_address=00%3A11%3A95%3A20%3Adf%3A11" * "http://plazes.com/suggestions.xml?mac_address=00%3A11%3A95%3A20%3Adf%3A11"
* *
* The actual response data is available (see "response"-property), * The actual response data is available (see "response"-property),
* but if the data is xml it's easier to use * but if the data is xml it's a lot easier to use
* "geoclue_web_service_get_*" -methods to get specific data using * "geoclue_web_service_get_*" -methods to get specific data using
* simple xpath expressions. * simple xpath expressions.
* *
...@@ -116,7 +116,8 @@ struct _GeoclueWebService { ...@@ -116,7 +116,8 @@ struct _GeoclueWebService {
/* private */ /* private */
gchar* base_url; gchar* base_url;
gchar *response; guchar *response;
gint response_length;
GList *namespaces; GList *namespaces;
gboolean using_connection_events; gboolean using_connection_events;
xmlXPathContext *xpath_ctx; xmlXPathContext *xpath_ctx;
......
...@@ -19,7 +19,7 @@ $(service_DATA): $(service_in_files) Makefile ...@@ -19,7 +19,7 @@ $(service_DATA): $(service_in_files) Makefile
AM_CPPFLAGS = $(YAHOO_CFLAGS) -I$(top_srcdir) AM_CPPFLAGS = $(YAHOO_CFLAGS) -I$(top_srcdir)
AM_LDFLAGS = $(YAHOO_LIBS) AM_LDFLAGS = $(YAHOO_LIBS) ../common/geoclue_web_service.o
EXTRA_DIST = \ EXTRA_DIST = \
geoclue_map_server_yahoo.h \ geoclue_map_server_yahoo.h \
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <geoclue_map_signal_marshal.h> #include <geoclue_map_signal_marshal.h>
#include <dbus/dbus-glib-bindings.h> #include <dbus/dbus-glib-bindings.h>
#include <math.h>
typedef enum _geoclue_map_returncode typedef enum _geoclue_map_returncode
{ {
...@@ -41,14 +41,7 @@ typedef enum _geoclue_map_returncode ...@@ -41,14 +41,7 @@ typedef enum _geoclue_map_returncode
} GEOCLUE_MAP_RETURNCODE; } GEOCLUE_MAP_RETURNCODE;
#define YAHOO_MAP_URL "http://api.local.yahoo.com/MapsService/V1/mapImage"
#include <libxml/xmlreader.h>
#include <libsoup/soup.h>
#include <fcntl.h>
#include <stdlib.h>
#include <math.h>
#define GEOCLUE_MAP_MIN_HEIGHT 100 #define GEOCLUE_MAP_MIN_HEIGHT 100
#define GEOCLUE_MAP_MAX_HEIGHT 2000 #define GEOCLUE_MAP_MAX_HEIGHT 2000
...@@ -127,17 +120,19 @@ geoclue_map_init (GeoclueMap *obj) ...@@ -127,17 +120,19 @@ geoclue_map_init (GeoclueMap *obj)
{ {
g_printerr("Unable to register Geoclue map service: %s", error->message); g_printerr("Unable to register Geoclue map service: %s", error->message);
g_error_free (error); g_error_free (error);
exit(1); exit(1);
} }
if (request_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) if (request_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{ {
g_printerr("Yahoo maps service already running!\n"); g_printerr("Yahoo maps service already running!\n");
} }
obj->web_service = g_object_new (GEOCLUE_TYPE_WEB_SERVICE,
g_print("registered mapping interface \n"); "base_url", YAHOO_MAP_URL,
NULL);
g_print("registered mapping interface \n");
} }
...@@ -239,114 +234,68 @@ gboolean geoclue_map_min_width(GeoclueMap *obj, int* min_width, GError **error) ...@@ -239,114 +234,68 @@ gboolean geoclue_map_min_width(GeoclueMap *obj, int* min_width, GError **error)
void geoclue_map_map_thread(params *obj) void geoclue_map_map_thread(params *obj)
{ {
gchar *lat = g_strdup_printf ("%f", obj->IN_latitude);
gdouble IN_latitude = obj->IN_latitude; gchar *lon = g_strdup_printf ("%f", obj->IN_longitude);
gdouble IN_longitude = obj->IN_longitude; gchar *width = g_strdup_printf ("%d", obj->IN_width);
gint IN_width = obj->IN_width; gchar *height = g_strdup_printf ("%d", obj->IN_height);
gint IN_height = obj->IN_height; gchar *zoom = g_strdup_printf ("%d", obj->IN_zoom);
gint IN_zoom = obj->IN_zoom;
gchar *png_url;
GeoclueWebService *png_service;
SoupSession *session;
SoupMessage *msg; if (!geoclue_web_service_query (obj->server->web_service,
SoupMessage *msg2; "appid", "YahooDemo",
const char *cafile = NULL; "latitude", lat,
SoupUri *proxy = NULL; "longitude", lon,
SoupUri *base_uri = NULL; "imagetype", "png",
"image_height", height,
base_uri = soup_uri_new ("http://api.local.yahoo.com/MapsService/V1/mapImage?appid=libgeomap&latitude=38.0&longitude=-122.0&imagetype=png&image_height=800&image_width=800&zoom=7"); "image_width", width,
"zoom", zoom,
NULL)) {
char* proxy_env; /* TODO: error handling */
return;
proxy_env = getenv ("http_proxy");
printf("found proxy %s:end\n", proxy_env);
if (proxy_env != NULL) {
printf("added proxy %s\n", proxy_env);
proxy = soup_uri_new (proxy_env);
session = soup_session_sync_new_with_options (
SOUP_SESSION_SSL_CA_FILE, cafile,
SOUP_SESSION_PROXY_URI, proxy,
NULL);
} }
else g_free (lat);
{ g_free (lon);
session = soup_session_sync_new (); g_free (width);
g_free (height);
g_free (zoom);
geoclue_web_service_get_string (obj->server->web_service,
&png_url, "//Result");
if (!g_str_has_prefix (png_url, "http://")) {
/* TODO: error handling */
return;
} }
g_debug("Trying to grab image %s\n", png_url);
png_service = g_object_new (GEOCLUE_TYPE_WEB_SERVICE,
"base_url",png_url,
NULL);
g_free (png_url);
char url[5000]; if (!geoclue_web_service_query (png_service, NULL)) {
/* TODO: error handling */
snprintf(url, 5000,"http://api.local.yahoo.com/MapsService/V1/mapImage?appid=YahooDemo&latitude=%f&longitude=%f&imagetype=png&image_height=%d&image_width=%d&zoom=%d", IN_latitude, IN_longitude, IN_height, IN_width, IN_zoom); return;
g_print(url);
msg = soup_message_new ("GET", url);
soup_session_send_message(session, msg);
char *name, *value;
xmlTextReaderPtr reader;
int ret;
char* pngurl;
//reader = xmlReaderForFile(argv[1], NULL, 0);
reader = xmlReaderForMemory (msg->response.body,
msg->response.length,
NULL,
NULL,
0);
ret = xmlTextReaderRead(reader);
//FIXME: super hack because I don't know how to use the XML libraries. This just works for now
while (ret == 1) {
name = (char*)xmlTextReaderConstName(reader);
if (!strcmp(name,"#text"))
{
value = (char*)xmlTextReaderConstValue(reader);
printf("%s %s\n", name, value);
int size = strlen(value);
pngurl = malloc(size);
strcpy(pngurl, value);
}
ret = xmlTextReaderRead(reader);
} }
xmlFreeTextReader(reader);
GArray *mydata;
mydata = g_array_new (FALSE, FALSE, sizeof (guint8));
g_object_get (png_service,
"response", &mydata->data,
"response-length", &mydata->len,
NULL);
g_debug ("map size: %d", mydata->len);
// A very bad rough sanity check g_object_unref (png_service);
if(pngurl != NULL)
{
if(pngurl[0] == 'h')
{
printf("Trying to grab image %s\n", pngurl);
msg2 = soup_message_new ("GET", pngurl);
soup_session_send_message(session, msg2);
printf("got message\n, parsing\n");
GArray *mydata;
mydata = g_array_new(FALSE,FALSE, sizeof(guint8));
mydata->data = msg2->response.body;
mydata->len = msg2->response.length;
g_signal_emit_by_name (obj->server, g_signal_emit_by_name (obj->server,
"get_map_finished", "get_map_finished",
0, mydata, "image/png"); 0, mydata, "image/png");
}
}
}; };
gboolean geoclue_map_get_map (GeoclueMap *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_width, const gint IN_height, const gint IN_zoom, int* return_code, GError **error) gboolean geoclue_map_get_map (GeoclueMap *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_width, const gint IN_height, const gint IN_zoom, int* return_code, GError **error)
{ {
...@@ -500,6 +449,7 @@ gboolean geoclue_map_service_available(GeoclueMap *obj, gboolean* OUT_available, ...@@ -500,6 +449,7 @@ gboolean geoclue_map_service_available(GeoclueMap *obj, gboolean* OUT_available,
gboolean geoclue_map_shutdown(GeoclueMap *obj, GError** error) gboolean geoclue_map_shutdown(GeoclueMap *obj, GError** error)
{ {
g_object_unref (obj->web_service);
g_main_loop_quit (obj->loop); g_main_loop_quit (obj->loop);
return TRUE; return TRUE;
} }
......
...@@ -19,14 +19,10 @@ ...@@ -19,14 +19,10 @@
#ifndef __GEOCLUE_MAP_SERVER_H__ #ifndef __GEOCLUE_MAP_SERVER_H__
#define __GEOCLUE_MAP_SERVER_H__ #define __GEOCLUE_MAP_SERVER_H__
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus-glib.h>
#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <config.h> #include <config.h>
#include <glib.h>
#include <dbus/dbus-glib.h>
#include "../common/geoclue_web_service.h"
#define GEOCLUE_MAP_DBUS_SERVICE "org.freedesktop.geoclue.map.yahoo" #define GEOCLUE_MAP_DBUS_SERVICE "org.freedesktop.geoclue.map.yahoo"
#define GEOCLUE_MAP_DBUS_PATH "/org/freedesktop/geoclue/map/yahoo" #define GEOCLUE_MAP_DBUS_PATH "/org/freedesktop/geoclue/map/yahoo"
...@@ -34,11 +30,8 @@ ...@@ -34,11 +30,8 @@
G_BEGIN_DECLS G_BEGIN_DECLS
//Let's create a geoclue_map object that has one method of geoclue_map
typedef struct GeoclueMap GeoclueMap; typedef struct GeoclueMap GeoclueMap;
typedef struct GeoclueMapClass GeoclueMapClass; typedef struct GeoclueMapClass GeoclueMapClass;
...@@ -46,17 +39,16 @@ GType geoclue_map_get_type (void); ...@@ -46,17 +39,16 @@ GType geoclue_map_get_type (void);
struct GeoclueMap struct GeoclueMap
{ {
GObject parent; GObject parent;
GMainLoop* loop;
GeoclueWebService *web_service;
char* buffer; char* buffer;
GArray* OUT_map_buffer; GArray* OUT_map_buffer;
gint width; gint width;
gint height; gint height;
gboolean pending_request; gboolean pending_request;
GMainLoop* loop;
}; };
struct GeoclueMapClass struct GeoclueMapClass
...@@ -94,11 +86,8 @@ gboolean geoclue_map_service_available(GeoclueMap *obj, gboolean* OUT_available, ...@@ -94,11 +86,8 @@ gboolean geoclue_map_service_available(GeoclueMap *obj, gboolean* OUT_available,
gboolean geoclue_map_shutdown(GeoclueMap *obj, GError** error); gboolean geoclue_map_shutdown(GeoclueMap *obj, GError** error);
G_END_DECLS G_END_DECLS
#endif #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