diff src/c/urweb.c @ 687:a3ddf05fb3e3

On start-up, delete/nullify rows mentioning clients or channels
author Adam Chlipala <adamc@hcoop.net>
date Thu, 02 Apr 2009 11:42:26 -0400
parents c73c5fe72388
children b6a8425e1b1f
line wrap: on
line diff
--- a/src/c/urweb.c	Thu Apr 02 10:57:14 2009 -0400
+++ b/src/c/urweb.c	Thu Apr 02 11:42:26 2009 -0400
@@ -308,15 +308,15 @@
 
 extern int uw_inputs_len, uw_timeout;
 
-uw_context uw_init(size_t outHeaders_len, size_t script_len, size_t page_len, size_t heap_len) {
+uw_context uw_init() {
   uw_context ctx = malloc(sizeof(struct uw_context));
 
   ctx->headers = ctx->headers_end = NULL;
 
-  buf_init(&ctx->outHeaders, outHeaders_len);
-  buf_init(&ctx->page, page_len);
-  buf_init(&ctx->heap, heap_len);
-  buf_init(&ctx->script, script_len);
+  buf_init(&ctx->outHeaders, 0);
+  buf_init(&ctx->page, 0);
+  buf_init(&ctx->heap, 0);
+  buf_init(&ctx->script, 0);
   ctx->script.start[0] = 0;
 
   ctx->inputs = calloc(uw_inputs_len, sizeof(char *));
@@ -1931,3 +1931,19 @@
 
   pthread_mutex_unlock(&clients_mutex);
 }
+
+void uw_initializer(uw_context ctx);
+
+failure_kind uw_initialize(uw_context ctx) {
+  int r = setjmp(ctx->jmp_buf);
+
+  if (r == 0) {
+    if (uw_db_begin(ctx))
+      uw_error(ctx, FATAL, "Error running SQL BEGIN");
+    uw_initializer(ctx);
+    if (uw_db_commit(ctx))
+      uw_error(ctx, FATAL, "Error running SQL COMMIT");
+  }
+
+  return r;
+}