/*---------------------------------------------------------------------------*/ static unsigned short generate_header(void *hstr) { uint8_t slen = httpd_strlen((char *) hstr); httpd_memcpy(uip_appdata, httpd_str_content, sizeof (httpd_str_content) - 1); httpd_memcpy(uip_appdata + sizeof (httpd_str_content) - 1, (char *) hstr, slen); slen += sizeof (httpd_str_content) - 1; httpd_memcpy(uip_appdata + slen, httpd_str_crlf, sizeof (httpd_str_crlf) - 1); return slen + 4; }
/*---------------------------------------------------------------------------*/ static unsigned short generate_status(void *sstr) { uint8_t slen = httpd_strlen((char *) sstr); httpd_memcpy(uip_appdata, httpd_str_http, sizeof (httpd_str_http) - 1); httpd_memcpy(uip_appdata + sizeof (httpd_str_http) - 1, (char *) sstr, slen); slen += sizeof (httpd_str_http) - 1; httpd_memcpy(uip_appdata + slen, httpd_str_server, sizeof (httpd_str_server) - 1); return slen + sizeof (httpd_str_server) - 1; }
/*-----------------------------------------------------------------------------------*/ uint16_t httpd_fs_open(const char *name, struct httpd_fs_file *file) { #if WEBSERVER_CONF_FILESTATS u16_t i = 0; #endif struct httpd_fsdata_file_noconst *f,fram; for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT; f != NULL; f = (struct httpd_fsdata_file_noconst *)fram.next) { /*Get the linked list entry into ram from wherever it is */ httpd_memcpy(&fram,f,sizeof(fram)); /*Compare name passed in RAM with name in whatever flash the file is in */ /*makefsdata adds an extra zero byte at the end of the file */ if(httpd_fs_strcmp((char *)name, fram.name) == 0) { if (file) { file->data = fram.data; file->len = fram.len-1; #if WEBSERVER_CONF_FILESTATS==2 //increment count in linked list field if it is in RAM f->count++; } return f->count; } ++i #elif WEBSERVER_CONF_FILESTATS==1 //increment count in RAM array when linked list is in flash ++httpd_filecount[i]; } return httpd_filecount[i]; }
/*---------------------------------------------------------------------------*/ static unsigned short generate_file_stats(void *arg) { struct httpd_state *s = (struct httpd_state *)arg; #if WEBSERVER_CONF_LOADTIME static const char httpd_cgi_filestat1[] HTTPD_STRING_ATTR = "<p align=\"right\"><br><br><i>This page has been sent %u times (%1u.%u sec)</i></body></html>"; #else static const char httpd_cgi_filestat1[] HTTPD_STRING_ATTR = "<p align=\"right\"><br><br><i>This page has been sent %u times</i></body></html>"; #endif static const char httpd_cgi_filestat2[] HTTPD_STRING_ATTR = "<tr><td><a href=\"%s\">%s</a></td><td>%d</td>"; static const char httpd_cgi_filestat3[] HTTPD_STRING_ATTR = "%5u"; char tmp[20]; struct httpd_fsdata_file_noconst *f,fram; u16_t i; unsigned short numprinted; /* Transfer arg from whichever flash that contains the html file to RAM */ httpd_fs_cpy(&tmp, s->u.ptr, 20); /* Count for this page, with common page footer */ if (tmp[0]=='.') { #if WEBSERVER_CONF_LOADTIME s->pagetime = clock_time() - s->pagetime; numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat1, httpd_fs_open(s->filename, 0), (unsigned int)s->pagetime/CLOCK_SECOND,(unsigned int)s->pagetime%CLOCK_SECOND); #else numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat1, httpd_fs_open(s->filename, 0)); #endif /* Count for all files */ /* Note buffer will overflow if there are too many files! */ } else if (tmp[0]=='*') { i=0;numprinted=0; for(f = (struct httpd_fsdata_file_noconst *)httpd_fs_get_root(); f != NULL; f = (struct httpd_fsdata_file_noconst *)fram.next) { /* Get the linked list file entry into RAM from from wherever it is*/ httpd_memcpy(&fram,f,sizeof(fram)); /* Get the file name from whatever memory it is in */ httpd_fs_cpy(&tmp, fram.name, sizeof(tmp)); #if WEBSERVER_CONF_FILESTATS==2 numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_filestat2, tmp, tmp, f->count); #else numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_filestat2, tmp, tmp, httpd_filecount[i]); #endif i++; } /* Count for specified file */ } else { numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat3, httpd_fs_open(tmp, 0)); } return numprinted; }
/*---------------------------------------------------------------------------*/ static unsigned short generate_file_stats(void *arg) { static const char httpd_cgi_filestat1[] HTTPD_STRING_ATTR = "<p class=right><br><br><i>This page has been sent %u times</i></div></body></html>"; static const char httpd_cgi_filestat2[] HTTPD_STRING_ATTR = "<tr><td><a href=\"%s\">%s</a></td><td>%d</td>"; static const char httpd_cgi_filestat3[] HTTPD_STRING_ATTR = "%5u"; char tmp[20]; struct httpd_fsdata_file_noconst *f,fram; uint16_t i; unsigned short numprinted; /* Transfer arg from whichever flash that contains the html file to RAM */ httpd_fs_cpy(&tmp, (char *)arg, 20); /* Count for this page, with common page footer */ if (tmp[0]=='.') { numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat1, httpd_fs_open(thisfilename, 0)); /* Count for all files */ /* Note buffer will overflow if there are too many files! */ } else if (tmp[0]=='*') { i=0;numprinted=0; for(f = (struct httpd_fsdata_file_noconst *)httpd_fs_get_root(); f != NULL; f = (struct httpd_fsdata_file_noconst *)fram.next) { /* Get the linked list file entry into RAM from from wherever it is*/ httpd_memcpy(&fram,f,sizeof(fram)); /* Get the file name from whatever memory it is in */ httpd_fs_cpy(&tmp, fram.name, sizeof(tmp)); #if HTTPD_FS_STATISTICS==1 numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_filestat2, tmp, tmp, f->count); #elif HTTPD_FS_STATISTICS==2 numprinted+=httpd_snprintf((char *)uip_appdata+numprinted, uip_mss()-numprinted, httpd_cgi_filestat2, tmp, tmp, httpd_filecount[i]); #endif i++; } /* Count for specified file */ } else { numprinted=httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_filestat3, httpd_fs_open(tmp, 0)); } #if DEBUGLOGIC return 0; #endif return numprinted; }