]> spindle.queued.net Git - midori/commitdiff
Add sokoke_get_res_server
authorChristian Dywan <christian@twotoasts.de>
Sat, 2 May 2009 19:36:09 +0000 (21:36 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sat, 2 May 2009 19:36:09 +0000 (21:36 +0200)
midori/sokoke.c
midori/sokoke.h

index bb421d80e6231581d7330b0ec8e2ebad5c0fe3c4..69f2d675af289d27b7d792f5a0ae1ab8e04b76fa 100644 (file)
@@ -971,3 +971,50 @@ sokoke_remove_path (const gchar* path,
     g_rmdir (path);
     return TRUE;
 }
+
+static void
+res_server_handler_cb (SoupServer*        res_server,
+                       SoupMessage*       msg,
+                       const gchar*       path,
+                       GHashTable*        query,
+                       SoupClientContext* client,
+                       gpointer           data)
+{
+    if (g_str_has_prefix (path, "/res"))
+    {
+        gchar* filename = g_strconcat (DATADIR "/midori", path, NULL);
+        gchar* contents;
+        guint length;
+
+        if (g_file_get_contents (filename, &contents, &length, NULL))
+        {
+            /* FIXME: Support any MIME type */
+            soup_message_set_response (msg, "image/png", SOUP_MEMORY_TAKE,
+                                       contents, length);
+            soup_message_set_status (msg, 401);
+        }
+        else
+            soup_message_set_status (msg, 404);
+        g_free (filename);
+    }
+    else
+    {
+        soup_message_set_status (msg, 404);
+    }
+}
+
+SoupServer*
+sokoke_get_res_server (void)
+{
+    static SoupServer* res_server = NULL;
+
+    if (G_UNLIKELY (!res_server))
+    {
+        res_server = soup_server_new ("port", SOUP_ADDRESS_ANY_PORT, NULL);
+        soup_server_add_handler (res_server, "/",
+            res_server_handler_cb, NULL, NULL);
+        soup_server_run_async (res_server);
+    }
+
+    return res_server;
+}
index d750f2f3fc7fa32d53be9e7ae434f5037924d08a..e960e08723a301385db277a68cc5b02195a2eb09 100644 (file)
@@ -16,7 +16,7 @@
 #include <katze/katze.h>
 
 #include <gtk/gtk.h>
-
+#include <libsoup/soup.h>
 #include <JavaScriptCore/JavaScript.h>
 
 gchar*
@@ -154,4 +154,7 @@ gboolean
 sokoke_remove_path                      (const gchar*    path,
                                          gboolean        ignore_errors);
 
+SoupServer*
+sokoke_get_res_server                   (void);
+
 #endif /* !__SOKOKE_H__ */