diff src/c/urweb.c @ 272:4d80d6122df1

Initializing database connection
author Adam Chlipala <adamc@hcoop.net>
date Tue, 02 Sep 2008 11:57:25 -0400
parents 1e24a3e6d614
children ed4af33681d8
line wrap: on
line diff
--- a/src/c/urweb.c	Tue Sep 02 10:51:41 2008 -0400
+++ b/src/c/urweb.c	Tue Sep 02 11:57:25 2008 -0400
@@ -16,6 +16,8 @@
   char *heap, *heap_front, *heap_back;
   char **inputs;
 
+  void *db;
+
   jmp_buf jmp_buf;
 
   char error_message[ERROR_BUF_LEN];
@@ -34,11 +36,21 @@
 
   ctx->inputs = calloc(lw_inputs_len, sizeof(char *));
 
+  ctx->db = NULL;
+
   ctx->error_message[0] = 0;
 
   return ctx;
 }
 
+void lw_set_db(lw_context ctx, void *db) {
+  ctx->db = db;
+}
+
+void *lw_get_db(lw_context ctx) {
+  return ctx->db;
+}
+
 void lw_free(lw_context ctx) {
   free(ctx->page);
   free(ctx->heap);
@@ -63,8 +75,18 @@
   memset(ctx->inputs, 0, lw_inputs_len * sizeof(char *));
 }
 
+void lw_db_init(lw_context);
 void lw_handle(lw_context, char *);
 
+failure_kind lw_begin_init(lw_context ctx) {
+  int r = setjmp(ctx->jmp_buf);
+
+  if (r == 0)
+    lw_db_init(ctx);
+
+  return r;
+}
+
 failure_kind lw_begin(lw_context ctx, char *path) {
   int r = setjmp(ctx->jmp_buf);