comparison 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
comparison
equal deleted inserted replaced
271:42dfb0d61cf0 272:4d80d6122df1
14 struct lw_context { 14 struct lw_context {
15 char *page, *page_front, *page_back; 15 char *page, *page_front, *page_back;
16 char *heap, *heap_front, *heap_back; 16 char *heap, *heap_front, *heap_back;
17 char **inputs; 17 char **inputs;
18 18
19 void *db;
20
19 jmp_buf jmp_buf; 21 jmp_buf jmp_buf;
20 22
21 char error_message[ERROR_BUF_LEN]; 23 char error_message[ERROR_BUF_LEN];
22 }; 24 };
23 25
32 ctx->heap_front = ctx->heap = malloc(heap_len); 34 ctx->heap_front = ctx->heap = malloc(heap_len);
33 ctx->heap_back = ctx->heap_front + heap_len; 35 ctx->heap_back = ctx->heap_front + heap_len;
34 36
35 ctx->inputs = calloc(lw_inputs_len, sizeof(char *)); 37 ctx->inputs = calloc(lw_inputs_len, sizeof(char *));
36 38
39 ctx->db = NULL;
40
37 ctx->error_message[0] = 0; 41 ctx->error_message[0] = 0;
38 42
39 return ctx; 43 return ctx;
44 }
45
46 void lw_set_db(lw_context ctx, void *db) {
47 ctx->db = db;
48 }
49
50 void *lw_get_db(lw_context ctx) {
51 return ctx->db;
40 } 52 }
41 53
42 void lw_free(lw_context ctx) { 54 void lw_free(lw_context ctx) {
43 free(ctx->page); 55 free(ctx->page);
44 free(ctx->heap); 56 free(ctx->heap);
61 void lw_reset(lw_context ctx) { 73 void lw_reset(lw_context ctx) {
62 lw_reset_keep_request(ctx); 74 lw_reset_keep_request(ctx);
63 memset(ctx->inputs, 0, lw_inputs_len * sizeof(char *)); 75 memset(ctx->inputs, 0, lw_inputs_len * sizeof(char *));
64 } 76 }
65 77
78 void lw_db_init(lw_context);
66 void lw_handle(lw_context, char *); 79 void lw_handle(lw_context, char *);
80
81 failure_kind lw_begin_init(lw_context ctx) {
82 int r = setjmp(ctx->jmp_buf);
83
84 if (r == 0)
85 lw_db_init(ctx);
86
87 return r;
88 }
67 89
68 failure_kind lw_begin(lw_context ctx, char *path) { 90 failure_kind lw_begin(lw_context ctx, char *path) {
69 int r = setjmp(ctx->jmp_buf); 91 int r = setjmp(ctx->jmp_buf);
70 92
71 if (r == 0) 93 if (r == 0)