/*-----------------------------------------------------------------------------------*/ int httpd_fs_open(const char *name, struct httpd_fs_file *file) { #if HTTPD_FS_STATISTICS uint16_t i = 0; #endif /* HTTPD_FS_STATISTICS */ char* ch; struct httpd_fsdata_file_noconst *f; libputs_arch(name); for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT; f != NULL; f = (struct httpd_fsdata_file_noconst *)f->next) { if(httpd_fs_strcmp(name, f->name) == 0) { file->data = f->data; file->len = f->len; #if HTTPD_FS_STATISTICS ++count[i]; #endif /* HTTPD_FS_STATISTICS */ return 1; } #if HTTPD_FS_STATISTICS ++i; #endif /* HTTPD_FS_STATISTICS */ } return 0; }
/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_input(struct httpd_state *s)) { PSOCK_BEGIN(&s->sin); PSOCK_READTO(&s->sin, ' '); if(strncmp(s->inputbuf, "GET ", 4) != 0) { PSOCK_CLOSE_EXIT(&s->sin); } PSOCK_READTO(&s->sin, ' '); if(s->inputbuf[0] != '/') { PSOCK_CLOSE_EXIT(&s->sin); } if(s->inputbuf[1] == ' ') { strncpy(s->filename, "index.html", sizeof(s->filename)); } else { s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; strncpy(s->filename, &s->inputbuf[1], sizeof(s->filename)); } // webserver_log_file(&uip_conn->ripaddr, s->filename); libputs_arch(s->filename); s->state = STATE_OUTPUT; while(1) { PSOCK_READTO(&s->sin, '\n'); if(strncmp(s->inputbuf, "Referer:", 8) == 0) { s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0; libputs_arch(&s->inputbuf[9]); // webserver_log(&s->inputbuf[9]); } } PSOCK_END(&s->sin); }
/*---------------------------------------------------------------------------*/ static PT_THREAD(handle_input(struct httpd_state *s)) { PSOCK_BEGIN(&s->sin); PSOCK_READTO(&s->sin, ISO_space); if(strncmp(s->inputbuf, http_get, 4) != 0) { PSOCK_CLOSE_EXIT(&s->sin); } PSOCK_READTO(&s->sin, ISO_space); if(s->inputbuf[0] != ISO_slash) { PSOCK_CLOSE_EXIT(&s->sin); } if(s->inputbuf[1] == ISO_space) { strncpy(s->filename, http_index_html, sizeof(s->filename)); } else { s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename)); } libputs_arch(s->filename); s->state = STATE_OUTPUT; while(1) { PSOCK_READTO(&s->sin, ISO_nl); if(strncmp(s->inputbuf, http_referer, 8) == 0) { s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0; } } PSOCK_END(&s->sin); }