diff options
author | 2009-06-23 17:59:23 -0400 | |
---|---|---|
committer | 2009-06-23 17:59:23 -0400 | |
commit | 5574caafb5da61e7938eec476975bf82cbf98b97 (patch) | |
tree | 767ed7f7342d56957d23eea82004fb2f2d85e032 /src/c/http.c | |
parent | 32b2d196fc02ca4f9f87574e6da1ffa6c1ea12ab (diff) |
cgi protocol
Diffstat (limited to 'src/c/http.c')
-rw-r--r-- | src/c/http.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/c/http.c b/src/c/http.c index e8345be2..a8f2efd4 100644 --- a/src/c/http.c +++ b/src/c/http.c @@ -8,11 +8,10 @@ #include <netinet/in.h> #include <unistd.h> #include <signal.h> +#include <stdarg.h> #include <pthread.h> -#include <mhash.h> - #include "urweb.h" #include "request.h" @@ -73,9 +72,31 @@ static char *get_header(void *data, const char *h) { return NULL; } +static void on_success(uw_context ctx) { + uw_write_header(ctx, "HTTP/1.1 200 OK\r\n"); +} + +static void on_failure(uw_context ctx) { + uw_write_header(ctx, "HTTP/1.1 500 Internal Server Error\r\n"); +} + +static void log_error(void *data, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + + vfprintf(stderr, fmt, ap); +} + +static void log_debug(void *data, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + + vprintf(fmt, ap); +} + static void *worker(void *data) { int me = *(int *)data; - uw_context ctx = uw_request_new_context(); + uw_context ctx = uw_request_new_context(NULL, log_error, log_debug); size_t buf_size = 2; char *buf = malloc(buf_size); uw_request_context rc = uw_new_request_context(); @@ -205,7 +226,10 @@ static void *worker(void *data) { uw_set_headers(ctx, get_header, headers); - rr = uw_request(rc, ctx, method, path, query_string, body, back - body, sock); + rr = uw_request(rc, ctx, method, path, query_string, body, back - body, + on_success, on_failure, + NULL, log_error, log_debug, + sock); uw_send(ctx, sock); if (rr == SERVED || rr == FAILED) @@ -231,6 +255,8 @@ static void sigint(int signum) { exit(0); } +static loggers ls = {NULL, log_error, log_debug}; + int main(int argc, char *argv[]) { // The skeleton for this function comes from Beej's sockets tutorial. int sockfd; // listen on sock_fd @@ -277,7 +303,7 @@ int main(int argc, char *argv[]) { } } - uw_request_init(); + uw_request_init(NULL, log_error, log_debug); names = calloc(nthreads, sizeof(int)); @@ -316,7 +342,7 @@ int main(int argc, char *argv[]) { pthread_t thread; int name; - if (pthread_create(&thread, NULL, client_pruner, &name)) { + if (pthread_create(&thread, NULL, client_pruner, &ls)) { fprintf(stderr, "Error creating pruner thread\n"); return 1; } |