Lines Matching full:s
82 struct httpd_state *s = (struct httpd_state *)state; in generate_part_of_file() local
84 if(s->file.len > uip_mss()) { in generate_part_of_file()
85 s->len = uip_mss(); in generate_part_of_file()
87 s->len = s->file.len; in generate_part_of_file()
89 memcpy(uip_appdata, s->file.data, s->len); in generate_part_of_file()
91 return s->len; in generate_part_of_file()
95 PT_THREAD(send_file(struct httpd_state *s)) in PT_THREAD() argument
97 PSOCK_BEGIN(&s->sout); in PT_THREAD()
100 PSOCK_GENERATOR_SEND(&s->sout, generate_part_of_file, s); in PT_THREAD()
101 s->file.len -= s->len; in PT_THREAD()
102 s->file.data += s->len; in PT_THREAD()
103 } while(s->file.len > 0); in PT_THREAD()
105 PSOCK_END(&s->sout); in PT_THREAD()
109 PT_THREAD(send_part_of_file(struct httpd_state *s)) in PT_THREAD() argument
111 PSOCK_BEGIN(&s->sout); in PT_THREAD()
113 PSOCK_SEND(&s->sout, s->file.data, s->len); in PT_THREAD()
115 PSOCK_END(&s->sout); in PT_THREAD()
119 next_scriptstate(struct httpd_state *s) in next_scriptstate() argument
122 p = strchr(s->scriptptr, ISO_nl) + 1; in next_scriptstate()
123 s->scriptlen -= (unsigned short)(p - s->scriptptr); in next_scriptstate()
124 s->scriptptr = p; in next_scriptstate()
128 PT_THREAD(handle_script(struct httpd_state *s)) in PT_THREAD() argument
132 PT_BEGIN(&s->scriptpt); in PT_THREAD()
135 while(s->file.len > 0) { in PT_THREAD()
138 if(*s->file.data == ISO_percent && in PT_THREAD()
139 *(s->file.data + 1) == ISO_bang) { in PT_THREAD()
140 s->scriptptr = s->file.data + 3; in PT_THREAD()
141 s->scriptlen = s->file.len - 3; in PT_THREAD()
142 if(*(s->scriptptr - 1) == ISO_colon) { in PT_THREAD()
143 httpd_fs_open(s->scriptptr + 1, &s->file); in PT_THREAD()
144 PT_WAIT_THREAD(&s->scriptpt, send_file(s)); in PT_THREAD()
146 PT_WAIT_THREAD(&s->scriptpt, in PT_THREAD()
147 httpd_cgi(s->scriptptr)(s, s->scriptptr)); in PT_THREAD()
149 next_scriptstate(s); in PT_THREAD()
153 s->file.data = s->scriptptr; in PT_THREAD()
154 s->file.len = s->scriptlen; in PT_THREAD()
159 if(s->file.len > uip_mss()) { in PT_THREAD()
160 s->len = uip_mss(); in PT_THREAD()
162 s->len = s->file.len; in PT_THREAD()
165 if(*s->file.data == ISO_percent) { in PT_THREAD()
166 ptr = strchr(s->file.data + 1, ISO_percent); in PT_THREAD()
168 ptr = strchr(s->file.data, ISO_percent); in PT_THREAD()
171 ptr != s->file.data) { in PT_THREAD()
172 s->len = (int)(ptr - s->file.data); in PT_THREAD()
173 if(s->len >= uip_mss()) { in PT_THREAD()
174 s->len = uip_mss(); in PT_THREAD()
177 PT_WAIT_THREAD(&s->scriptpt, send_part_of_file(s)); in PT_THREAD()
178 s->file.data += s->len; in PT_THREAD()
179 s->file.len -= s->len; in PT_THREAD()
184 PT_END(&s->scriptpt); in PT_THREAD()
188 PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr)) in PT_THREAD() argument
192 PSOCK_BEGIN(&s->sout); in PT_THREAD()
194 PSOCK_SEND_STR(&s->sout, statushdr); in PT_THREAD()
196 ptr = strrchr(s->filename, ISO_period); in PT_THREAD()
198 PSOCK_SEND_STR(&s->sout, http_content_type_binary); in PT_THREAD()
201 PSOCK_SEND_STR(&s->sout, http_content_type_html); in PT_THREAD()
203 PSOCK_SEND_STR(&s->sout, http_content_type_css); in PT_THREAD()
205 PSOCK_SEND_STR(&s->sout, http_content_type_png); in PT_THREAD()
207 PSOCK_SEND_STR(&s->sout, http_content_type_gif); in PT_THREAD()
209 PSOCK_SEND_STR(&s->sout, http_content_type_jpg); in PT_THREAD()
211 PSOCK_SEND_STR(&s->sout, http_content_type_plain); in PT_THREAD()
213 PSOCK_END(&s->sout); in PT_THREAD()
217 PT_THREAD(handle_output(struct httpd_state *s)) in PT_THREAD() argument
221 PT_BEGIN(&s->outputpt); in PT_THREAD()
223 if(!httpd_fs_open(s->filename, &s->file)) { in PT_THREAD()
224 httpd_fs_open(http_404_html, &s->file); in PT_THREAD()
225 strcpy(s->filename, http_404_html); in PT_THREAD()
226 PT_WAIT_THREAD(&s->outputpt, in PT_THREAD()
227 send_headers(s, in PT_THREAD()
229 PT_WAIT_THREAD(&s->outputpt, in PT_THREAD()
230 send_file(s)); in PT_THREAD()
232 PT_WAIT_THREAD(&s->outputpt, in PT_THREAD()
233 send_headers(s, in PT_THREAD()
235 ptr = strchr(s->filename, ISO_period); in PT_THREAD()
237 PT_INIT(&s->scriptpt); in PT_THREAD()
238 PT_WAIT_THREAD(&s->outputpt, handle_script(s)); in PT_THREAD()
240 PT_WAIT_THREAD(&s->outputpt, in PT_THREAD()
241 send_file(s)); in PT_THREAD()
244 PSOCK_CLOSE(&s->sout); in PT_THREAD()
245 PT_END(&s->outputpt); in PT_THREAD()
249 PT_THREAD(handle_input(struct httpd_state *s)) in PT_THREAD() argument
251 PSOCK_BEGIN(&s->sin); in PT_THREAD()
253 PSOCK_READTO(&s->sin, ISO_space); in PT_THREAD()
256 if(strncmp(s->inputbuf, http_get, 4) != 0) { in PT_THREAD()
257 PSOCK_CLOSE_EXIT(&s->sin); in PT_THREAD()
259 PSOCK_READTO(&s->sin, ISO_space); in PT_THREAD()
261 if(s->inputbuf[0] != ISO_slash) { in PT_THREAD()
262 PSOCK_CLOSE_EXIT(&s->sin); in PT_THREAD()
265 if(s->inputbuf[1] == ISO_space) { in PT_THREAD()
266 strncpy(s->filename, http_index_html, sizeof(s->filename)); in PT_THREAD()
268 s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; in PT_THREAD()
269 strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename)); in PT_THREAD()
272 /* httpd_log_file(uip_conn->ripaddr, s->filename);*/ in PT_THREAD()
274 s->state = STATE_OUTPUT; in PT_THREAD()
277 PSOCK_READTO(&s->sin, ISO_nl); in PT_THREAD()
279 if(strncmp(s->inputbuf, http_referer, 8) == 0) { in PT_THREAD()
280 s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0; in PT_THREAD()
281 /* httpd_log(&s->inputbuf[9]);*/ in PT_THREAD()
285 PSOCK_END(&s->sin); in PT_THREAD()
289 handle_connection(struct httpd_state *s) in handle_connection() argument
291 handle_input(s); in handle_connection()
292 if(s->state == STATE_OUTPUT) { in handle_connection()
293 handle_output(s); in handle_connection()
300 struct httpd_state *s = (struct httpd_state *)&(uip_conn->appstate); in httpd_appcall() local
304 PSOCK_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1); in httpd_appcall()
305 PSOCK_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1); in httpd_appcall()
306 PT_INIT(&s->outputpt); in httpd_appcall()
307 s->state = STATE_WAITING; in httpd_appcall()
308 /* timer_set(&s->timer, CLOCK_SECOND * 100);*/ in httpd_appcall()
309 s->timer = 0; in httpd_appcall()
310 handle_connection(s); in httpd_appcall()
311 } else if(s != NULL) { in httpd_appcall()
313 ++s->timer; in httpd_appcall()
314 if(s->timer >= 20) { in httpd_appcall()
318 s->timer = 0; in httpd_appcall()
320 handle_connection(s); in httpd_appcall()