comparison src/c/driver.c @ 144:f0d3402184d1

Simple forms work
author Adam Chlipala <adamc@hcoop.net>
date Tue, 22 Jul 2008 15:12:20 -0400
parents adfa2c7a75da
children b1b33f7cf555
comparison
equal deleted inserted replaced
143:4b9c2bd6157c 144:f0d3402184d1
84 84
85 back += r; 85 back += r;
86 *back = 0; 86 *back = 0;
87 87
88 if (s = strstr(buf, "\r\n\r\n")) { 88 if (s = strstr(buf, "\r\n\r\n")) {
89 char *cmd, *path; 89 char *cmd, *path, *inputs;
90 90
91 *s = 0; 91 *s = 0;
92
93 printf("Read: %s\n", buf);
92 94
93 if (!(s = strstr(buf, "\r\n"))) { 95 if (!(s = strstr(buf, "\r\n"))) {
94 fprintf(stderr, "No newline in buf\n"); 96 fprintf(stderr, "No newline in buf\n");
95 break; 97 break;
96 } 98 }
112 if (!strsep(&s, " ")) { 114 if (!strsep(&s, " ")) {
113 fprintf(stderr, "No second space in HTTP command\n"); 115 fprintf(stderr, "No second space in HTTP command\n");
114 break; 116 break;
115 } 117 }
116 118
119 if (inputs = strchr(path, '?')) {
120 char *name, *value;
121 *inputs++ = 0;
122
123 while (*inputs) {
124 name = inputs;
125 if (value = strchr(inputs, '=')) {
126 *value++ = 0;
127 if (inputs = strchr(value, '&'))
128 *inputs++ = 0;
129 else
130 inputs = strchr(value, 0);
131 lw_set_input(ctx, name, value);
132 }
133 else if (inputs = strchr(value, '&')) {
134 *inputs++ = 0;
135 lw_set_input(ctx, name, "");
136 }
137 else {
138 inputs = strchr(value, 0);
139 lw_set_input(ctx, name, "");
140 }
141 }
142 }
143
117 printf("Serving URI %s....\n", path); 144 printf("Serving URI %s....\n", path);
118 145
119 ctx = lw_init(1024, 1024);
120 lw_write (ctx, "HTTP/1.1 200 OK\r\n"); 146 lw_write (ctx, "HTTP/1.1 200 OK\r\n");
121 lw_write(ctx, "Content-type: text/html\r\n\r\n"); 147 lw_write(ctx, "Content-type: text/html\r\n\r\n");
122 lw_write(ctx, "<html>"); 148 lw_write(ctx, "<html>");
123 lw_handle(ctx, path); 149 lw_handle(ctx, path);
124 lw_write(ctx, "</html>"); 150 lw_write(ctx, "</html>");