diff --git a/client/src/cart_item.c b/client/src/cart_item.c index 0a5da38..9fc09b1 100644 --- a/client/src/cart_item.c +++ b/client/src/cart_item.c @@ -179,9 +179,47 @@ void yacos_cart_item_fetch_meta(YacosCartItem *self) // TODO: The soup 's probably memory-leaking all over the place. Check this some time.. } +static void yacos_cart_item_fetch_image_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) +{ + YacosCartItem *self = YACOS_CART_ITEM(user_data); + GdkPixbuf *pixbuf_raw, *pixbuf_scaled; + GMemoryInputStream *s; + + if (msg->status_code != 200) { + g_warning("image: Received error code %d from server.", msg->status_code); + } else { + s = G_MEMORY_INPUT_STREAM(g_memory_input_stream_new()); + g_memory_input_stream_add_data(s, msg->response_body->data, msg->response_body->length, NULL); + pixbuf_raw = gdk_pixbuf_new_from_stream(G_INPUT_STREAM(s), NULL, NULL); + g_object_unref(s); + pixbuf_scaled = gdk_pixbuf_scale_simple(pixbuf_raw, 100, 100, GDK_INTERP_BILINEAR); + g_object_unref(pixbuf_raw); + gtk_image_set_from_pixbuf(GTK_IMAGE(self->priv.image), pixbuf_scaled); + g_object_unref(pixbuf_scaled); + } + + gtk_stack_set_visible_child(self->priv.stack_image_loader, self->priv.image); +} + void yacos_cart_item_fetch_image(YacosCartItem *self) { - return; + SoupMessage *msg; + gchar *url; + gchar *id_str; + + id_str = yacos_tag_id_to_str(self->priv.tag_id); + url = g_strdup_printf("%s?image&id=%s", self->priv.api.url_base, id_str); + g_free(id_str); + msg = soup_message_new("GET", url); + soup_message_headers_append (msg->request_headers, "x-token", self->priv.api.token); + g_free(url); + + soup_session_queue_message(self->priv.api.soup_session_meta, + msg, + yacos_cart_item_fetch_image_cb, + self); + + /* TODO: More memory leaks? */ } yacos_tag_id yacos_cart_item_get_id(YacosCartItem *self) diff --git a/server/api.php b/server/api.php index b87c659..6f62c0a 100644 --- a/server/api.php +++ b/server/api.php @@ -2,10 +2,22 @@ // This is just a dummy implementation during the development of the GTK+3 GUI -if ($_SERVER['HTTP_X_TOKEN'] != "123456") die("Invalid token.\n"); +if ($_SERVER['HTTP_X_TOKEN'] != "123456") { + http_response_code(403); + die("Invalid token.\n"); +} + +$id = $_GET['id']; +preg_match("/^[A-Za-z0-9]{6,10}$/", $id, $matches); +if (!$matches) { + http_response_code(400); + die ("Invalid tag ID."); +} + +// $id is now safe to use if (isset($_GET['meta'])) { - if ($_GET['id'] == "BF09CE") { + if ($id == "BF09CE") { ?> { "title" : "Cute Wifi Cat", @@ -13,7 +25,7 @@ if (isset($_GET['meta'])) { "comment" : "It's mewine!" } { "title" : "Crazy Stuff", @@ -22,6 +34,7 @@ if (isset($_GET['meta'])) { } { "title" : "INVALID", @@ -30,5 +43,17 @@ if (isset($_GET['meta'])) { } diff --git a/server/img/BE6200.png b/server/img/BE6200.png new file mode 100644 index 0000000..630503e Binary files /dev/null and b/server/img/BE6200.png differ diff --git a/server/img/BF09CE.png b/server/img/BF09CE.png new file mode 100644 index 0000000..6da225f Binary files /dev/null and b/server/img/BF09CE.png differ