Author: jmb
Date: Sat Oct 17 16:47:29 2009
New Revision: 9650
URL:
http://source.netsurf-browser.org?rev=9650&view=rev
Log:
Stub out a handler for a test: scheme
Modified:
branches/jmb/new-cache/test/llcache.c
Modified: branches/jmb/new-cache/test/llcache.c
URL:
http://source.netsurf-browser.org/branches/jmb/new-cache/test/llcache.c?r...
==============================================================================
--- branches/jmb/new-cache/test/llcache.c (original)
+++ branches/jmb/new-cache/test/llcache.c Sat Oct 17 16:47:29 2009
@@ -3,6 +3,7 @@
#include "content/fetch.h"
#include "content/llcache.h"
+#include "utils/ring.h"
#include "utils/url.h"
/******************************************************************************
@@ -91,6 +92,100 @@
}
/******************************************************************************
+ * test: protocol handler *
+ ******************************************************************************/
+
+typedef struct test_context {
+ struct fetch *parent;
+
+ bool aborted;
+ bool locked;
+
+ struct test_context *r_prev;
+ struct test_context *r_next;
+} test_context;
+
+static test_context *ring;
+
+bool test_initialise(const char *scheme)
+{
+ /* Nothing to do */
+ return true;
+}
+
+void test_finalise(const char *scheme)
+{
+ /* Nothing to do */
+}
+
+void *test_setup_fetch(struct fetch *parent, const char *url, bool only_2xx,
+ const char *post_urlenc,
+ struct fetch_multipart_data *post_multipart,
+ const char **headers)
+{
+ test_context *ctx = calloc(1, sizeof(test_context));
+
+ if (ctx == NULL)
+ return NULL;
+
+ ctx->parent = parent;
+
+ RING_INSERT(ring, ctx);
+
+ return ctx;
+}
+
+bool test_start_fetch(void *handle)
+{
+ /* Nothing to do */
+ return true;
+}
+
+void test_abort_fetch(void *handle)
+{
+ test_context *ctx = handle;
+
+ ctx->aborted = true;
+}
+
+void test_free_fetch(void *handle)
+{
+ test_context *ctx = handle;
+
+ RING_REMOVE(ring, ctx);
+
+ free(ctx);
+}
+
+void test_process(test_context *ctx)
+{
+ /** \todo Implement */
+}
+
+void test_poll(const char *scheme)
+{
+ test_context *ctx, *next;
+
+ if (ring == NULL)
+ return;
+
+ ctx = ring;
+ do {
+ next = ctx->r_next;
+
+ if (ctx->locked)
+ continue;
+
+ if (ctx->aborted == false) {
+ test_process(ctx);
+ }
+
+ fetch_remove_from_queues(ctx->parent);
+ fetch_free(ctx->parent);
+ } while ((ctx = next) != ring && ring != NULL);
+}
+
+/******************************************************************************
* The actual test code *
******************************************************************************/
@@ -131,6 +226,9 @@
/* Initialise subsystems */
url_init();
fetch_init();
+ fetch_add_fetcher("test", test_initialise, test_setup_fetch,
+ test_start_fetch, test_abort_fetch, test_free_fetch,
+ test_poll, test_finalise);
/* Initialise low-level cache */
error = llcache_initialise(query_handler, NULL);