diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-07-13 15:44:00 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-07-13 15:44:00 -0400 |
commit | c54e3eca0a8d7e72f12801bc5ec993dddfa7958b (patch) | |
tree | a37326be0f01025df57b4f3bf1f209528042df1c /src/c/driver.c | |
parent | 0eb51a6e21e5f435d37afd885ae316a0575c7208 (diff) |
Serving pages
Diffstat (limited to 'src/c/driver.c')
-rw-r--r-- | src/c/driver.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/c/driver.c b/src/c/driver.c index 16b2dad5..8f3ef70f 100644 --- a/src/c/driver.c +++ b/src/c/driver.c @@ -5,11 +5,13 @@ #include <sys/socket.h> #include <netinet/in.h> +#include "lacweb.h" + int lw_port = 8080; int lw_backlog = 10; int lw_bufsize = 1024; -void lw_handle(char*); +void lw_handle(lw_context, char*); static void worker(int sock) { char buf[lw_bufsize+1], *back = buf, *s; @@ -36,10 +38,11 @@ static void worker(int sock) { if (s = strstr(buf, "\r\n\r\n")) { char *cmd, *path; + lw_context ctx; *s = 0; - if (!(s = strstr(buf, "\n"))) { + if (!(s = strstr(buf, "\r\n"))) { fprintf(stderr, "No newline in buf\n"); close(sock); return; @@ -68,10 +71,15 @@ static void worker(int sock) { } printf("Serving URI %s....\n", path); - puts("Content-type: text/html\n\n"); - puts("<html>"); - lw_handle(path); - puts("</html>"); + + ctx = lw_init(1024); + lw_write (ctx, "HTTP/1.1 200 OK\r\n"); + lw_write(ctx, "Content-type: text/html\r\n\r\n"); + lw_write(ctx, "<html>"); + lw_handle(ctx, path); + lw_write(ctx, "</html>"); + + lw_send(ctx, sock); printf("Done with client.\n\n"); close(sock); |