46 #include "contiki-net.h"
48 #include "httpd-cgi.h"
57 static struct httpd_cgi_call *calls =
NULL;
72 static const char closed[] =
73 {0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};
74 static const char syn_rcvd[] =
75 {0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56,
77 static const char syn_sent[] =
78 {0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e,
80 static const char established[] =
81 {0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48,
83 static const char fin_wait_1[] =
84 {0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
86 static const char fin_wait_2[] =
87 {0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
89 static const char closing[] =
90 {0x43, 0x4c, 0x4f, 0x53, 0x49,
92 static const char time_wait[] =
93 {0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41,
95 static const char last_ack[] =
96 {0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43,
98 static const char none[] =
"NONE";
99 static const char init[] =
"INIT";
100 static const char running[] =
"RUNNING";
101 static const char needs_poll[] =
"NEEDS POLL";
103 static const char *states[] = {
121 PT_THREAD(nullfunction(
struct httpd_state *s,
char *ptr))
128 httpd_cgi(
char *name)
130 struct httpd_cgi_call *f;
133 for(f = calls; f !=
NULL; f = f->next) {
134 if(strncmp(f->name, name, strlen(f->name)) == 0) {
141 static unsigned short
142 generate_file_stats(
void *arg)
144 char *f = (
char *)arg;
145 return sprintf((
char *)
uip_appdata,
"%5u", httpd_fs_count(f));
149 PT_THREAD(file_stats(
struct httpd_state *s,
char *ptr))
158 static unsigned short
159 make_tcp_stats(
void *arg)
162 struct httpd_state *s = (
struct httpd_state *)arg;
164 conn = &uip_conns[s->u.count];
166 "<tr align=\"center\"><td>%d</td><td>%u.%u.%u.%u:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\r\n",
176 (uip_outstanding(conn))?
'*':
' ',
181 PT_THREAD(tcp_stats(
struct httpd_state *s,
char *ptr))
186 for(s->u.count = 0; s->u.count <
UIP_CONNS; ++s->u.count) {
187 if((uip_conns[s->u.count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) {
195 static unsigned short
196 make_processes(
void *p)
200 strncpy(name, PROCESS_NAME_STRING((
struct process *)p), 40);
201 petsciiconv_toascii(name, 40);
204 "<tr align=\"center\"><td>%p</td><td>%s</td><td>%p</td><td>%s</td></tr>\r\n",
206 (
char *)((
struct process *)p)->thread,
207 states[9 + ((
struct process *)p)->state]);
211 PT_THREAD(processes(
struct httpd_state *s,
char *ptr))
214 for(s->u.ptr = PROCESS_LIST(); s->u.ptr !=
NULL; s->u.ptr = ((
struct process *)s->u.ptr)->next) {
221 httpd_cgi_add(
struct httpd_cgi_call *c)
223 struct httpd_cgi_call *l;
229 for(l = calls; l->next !=
NULL; l = l->next);
235 HTTPD_CGI_CALL(file,
"file-stats", file_stats);
236 HTTPD_CGI_CALL(tcp,
"tcp-connections", tcp_stats);
237 HTTPD_CGI_CALL(proc,
"processes", processes);
242 httpd_cgi_add(&file);
244 httpd_cgi_add(&proc);