uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Committer:
ban4jp
Date:
Sun Jun 15 17:03:02 2014 +0000
Revision:
1:b4d28172cacd
Parent:
0:685224d2f66d
update "httpd-fsdata.c".;   Convert contents, hex to char.;   Fixed Invalid html tags and contents data.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ban4jp 0:685224d2f66d 1 /**
ban4jp 0:685224d2f66d 2 * \addtogroup httpd
ban4jp 0:685224d2f66d 3 * @{
ban4jp 0:685224d2f66d 4 */
ban4jp 0:685224d2f66d 5
ban4jp 0:685224d2f66d 6 /**
ban4jp 0:685224d2f66d 7 * \file
ban4jp 0:685224d2f66d 8 * Web server script interface
ban4jp 0:685224d2f66d 9 * \author
ban4jp 0:685224d2f66d 10 * Adam Dunkels <adam@sics.se>
ban4jp 0:685224d2f66d 11 *
ban4jp 0:685224d2f66d 12 */
ban4jp 0:685224d2f66d 13
ban4jp 0:685224d2f66d 14 /*
ban4jp 0:685224d2f66d 15 * Copyright (c) 2001-2006, Adam Dunkels.
ban4jp 0:685224d2f66d 16 * All rights reserved.
ban4jp 0:685224d2f66d 17 *
ban4jp 0:685224d2f66d 18 * Redistribution and use in source and binary forms, with or without
ban4jp 0:685224d2f66d 19 * modification, are permitted provided that the following conditions
ban4jp 0:685224d2f66d 20 * are met:
ban4jp 0:685224d2f66d 21 * 1. Redistributions of source code must retain the above copyright
ban4jp 0:685224d2f66d 22 * notice, this list of conditions and the following disclaimer.
ban4jp 0:685224d2f66d 23 * 2. Redistributions in binary form must reproduce the above copyright
ban4jp 0:685224d2f66d 24 * notice, this list of conditions and the following disclaimer in the
ban4jp 0:685224d2f66d 25 * documentation and/or other materials provided with the distribution.
ban4jp 0:685224d2f66d 26 * 3. The name of the author may not be used to endorse or promote
ban4jp 0:685224d2f66d 27 * products derived from this software without specific prior
ban4jp 0:685224d2f66d 28 * written permission.
ban4jp 0:685224d2f66d 29 *
ban4jp 0:685224d2f66d 30 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
ban4jp 0:685224d2f66d 31 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
ban4jp 0:685224d2f66d 32 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ban4jp 0:685224d2f66d 33 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
ban4jp 0:685224d2f66d 34 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ban4jp 0:685224d2f66d 35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
ban4jp 0:685224d2f66d 36 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ban4jp 0:685224d2f66d 37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
ban4jp 0:685224d2f66d 38 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
ban4jp 0:685224d2f66d 39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
ban4jp 0:685224d2f66d 40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ban4jp 0:685224d2f66d 41 *
ban4jp 0:685224d2f66d 42 * This file is part of the uIP TCP/IP stack.
ban4jp 0:685224d2f66d 43 *
ban4jp 0:685224d2f66d 44 * $Id: httpd-cgi.c,v 1.2 2006/06/11 21:46:37 adam Exp $
ban4jp 0:685224d2f66d 45 *
ban4jp 0:685224d2f66d 46 */
ban4jp 0:685224d2f66d 47
ban4jp 0:685224d2f66d 48 #include "uip.h"
ban4jp 0:685224d2f66d 49 #include "psock.h"
ban4jp 0:685224d2f66d 50 #include "httpd.h"
ban4jp 0:685224d2f66d 51 #include "httpd-cgi.h"
ban4jp 0:685224d2f66d 52 #include "httpd-fs.h"
ban4jp 0:685224d2f66d 53
ban4jp 0:685224d2f66d 54 #include <stdio.h>
ban4jp 0:685224d2f66d 55 #include <string.h>
ban4jp 0:685224d2f66d 56
ban4jp 0:685224d2f66d 57 HTTPD_CGI_CALL(file, "file-stats", file_stats);
ban4jp 0:685224d2f66d 58 HTTPD_CGI_CALL(tcp, "tcp-connections", tcp_stats);
ban4jp 0:685224d2f66d 59 HTTPD_CGI_CALL(net, "net-stats", net_stats);
ban4jp 0:685224d2f66d 60
ban4jp 0:685224d2f66d 61 static const struct httpd_cgi_call *calls[] = { &file, &tcp, &net, NULL };
ban4jp 0:685224d2f66d 62
ban4jp 0:685224d2f66d 63 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 64 static
ban4jp 0:685224d2f66d 65 PT_THREAD(nullfunction(struct httpd_state *s, char *ptr))
ban4jp 0:685224d2f66d 66 {
ban4jp 0:685224d2f66d 67 PSOCK_BEGIN(&s->sout);
ban4jp 0:685224d2f66d 68 PSOCK_END(&s->sout);
ban4jp 0:685224d2f66d 69 }
ban4jp 0:685224d2f66d 70 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 71 httpd_cgifunction
ban4jp 0:685224d2f66d 72 httpd_cgi(char *name)
ban4jp 0:685224d2f66d 73 {
ban4jp 0:685224d2f66d 74 const struct httpd_cgi_call **f;
ban4jp 0:685224d2f66d 75
ban4jp 0:685224d2f66d 76 /* Find the matching name in the table, return the function. */
ban4jp 0:685224d2f66d 77 for(f = calls; *f != NULL; ++f) {
ban4jp 0:685224d2f66d 78 if(strncmp((*f)->name, name, strlen((*f)->name)) == 0) {
ban4jp 0:685224d2f66d 79 return (*f)->function;
ban4jp 0:685224d2f66d 80 }
ban4jp 0:685224d2f66d 81 }
ban4jp 0:685224d2f66d 82 return nullfunction;
ban4jp 0:685224d2f66d 83 }
ban4jp 0:685224d2f66d 84 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 85 static unsigned short
ban4jp 0:685224d2f66d 86 generate_file_stats(void *arg)
ban4jp 0:685224d2f66d 87 {
ban4jp 0:685224d2f66d 88 char *f = (char *)arg;
ban4jp 1:b4d28172cacd 89 return snprintf((char *)uip_appdata, UIP_APPDATA_SIZE, "%u", httpd_fs_count(f));
ban4jp 0:685224d2f66d 90 }
ban4jp 0:685224d2f66d 91 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 92 static
ban4jp 0:685224d2f66d 93 PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
ban4jp 0:685224d2f66d 94 {
ban4jp 0:685224d2f66d 95 PSOCK_BEGIN(&s->sout);
ban4jp 0:685224d2f66d 96
ban4jp 0:685224d2f66d 97 PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, strchr(ptr, ' ') + 1);
ban4jp 0:685224d2f66d 98
ban4jp 0:685224d2f66d 99 PSOCK_END(&s->sout);
ban4jp 0:685224d2f66d 100 }
ban4jp 0:685224d2f66d 101 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 102 static const char closed[] = /* "CLOSED",*/
ban4jp 0:685224d2f66d 103 {0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0};
ban4jp 0:685224d2f66d 104 static const char syn_rcvd[] = /* "SYN-RCVD",*/
ban4jp 0:685224d2f66d 105 {0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56,
ban4jp 0:685224d2f66d 106 0x44, 0};
ban4jp 0:685224d2f66d 107 static const char syn_sent[] = /* "SYN-SENT",*/
ban4jp 0:685224d2f66d 108 {0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e,
ban4jp 0:685224d2f66d 109 0x54, 0};
ban4jp 0:685224d2f66d 110 static const char established[] = /* "ESTABLISHED",*/
ban4jp 0:685224d2f66d 111 {0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48,
ban4jp 0:685224d2f66d 112 0x45, 0x44, 0};
ban4jp 0:685224d2f66d 113 static const char fin_wait_1[] = /* "FIN-WAIT-1",*/
ban4jp 0:685224d2f66d 114 {0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
ban4jp 0:685224d2f66d 115 0x54, 0x2d, 0x31, 0};
ban4jp 0:685224d2f66d 116 static const char fin_wait_2[] = /* "FIN-WAIT-2",*/
ban4jp 0:685224d2f66d 117 {0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49,
ban4jp 0:685224d2f66d 118 0x54, 0x2d, 0x32, 0};
ban4jp 0:685224d2f66d 119 static const char closing[] = /* "CLOSING",*/
ban4jp 0:685224d2f66d 120 {0x43, 0x4c, 0x4f, 0x53, 0x49,
ban4jp 0:685224d2f66d 121 0x4e, 0x47, 0};
ban4jp 0:685224d2f66d 122 static const char time_wait[] = /* "TIME-WAIT,"*/
ban4jp 0:685224d2f66d 123 {0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41,
ban4jp 0:685224d2f66d 124 0x49, 0x54, 0};
ban4jp 0:685224d2f66d 125 static const char last_ack[] = /* "LAST-ACK"*/
ban4jp 0:685224d2f66d 126 {0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43,
ban4jp 0:685224d2f66d 127 0x4b, 0};
ban4jp 0:685224d2f66d 128
ban4jp 0:685224d2f66d 129 static const char *states[] = {
ban4jp 0:685224d2f66d 130 closed,
ban4jp 0:685224d2f66d 131 syn_rcvd,
ban4jp 0:685224d2f66d 132 syn_sent,
ban4jp 0:685224d2f66d 133 established,
ban4jp 0:685224d2f66d 134 fin_wait_1,
ban4jp 0:685224d2f66d 135 fin_wait_2,
ban4jp 0:685224d2f66d 136 closing,
ban4jp 0:685224d2f66d 137 time_wait,
ban4jp 0:685224d2f66d 138 last_ack};
ban4jp 0:685224d2f66d 139
ban4jp 0:685224d2f66d 140
ban4jp 0:685224d2f66d 141 static unsigned short
ban4jp 0:685224d2f66d 142 generate_tcp_stats(void *arg)
ban4jp 0:685224d2f66d 143 {
ban4jp 0:685224d2f66d 144 struct uip_conn *conn;
ban4jp 0:685224d2f66d 145 struct httpd_state *s = (struct httpd_state *)arg;
ban4jp 0:685224d2f66d 146
ban4jp 0:685224d2f66d 147 conn = &uip_conns[s->count];
ban4jp 0:685224d2f66d 148 return snprintf((char *)uip_appdata, UIP_APPDATA_SIZE,
ban4jp 1:b4d28172cacd 149 "<tr><td>%d</td><td>%u.%u.%u.%u:%u</td><td>%s</td><td>%u</td><td>%u</td><td>%c %c</td></tr>\n",
ban4jp 0:685224d2f66d 150 htons(conn->lport),
ban4jp 0:685224d2f66d 151 htons(conn->ripaddr[0]) >> 8,
ban4jp 0:685224d2f66d 152 htons(conn->ripaddr[0]) & 0xff,
ban4jp 0:685224d2f66d 153 htons(conn->ripaddr[1]) >> 8,
ban4jp 0:685224d2f66d 154 htons(conn->ripaddr[1]) & 0xff,
ban4jp 0:685224d2f66d 155 htons(conn->rport),
ban4jp 0:685224d2f66d 156 states[conn->tcpstateflags & UIP_TS_MASK],
ban4jp 0:685224d2f66d 157 conn->nrtx,
ban4jp 0:685224d2f66d 158 conn->timer,
ban4jp 0:685224d2f66d 159 (uip_outstanding(conn))? '*':' ',
ban4jp 0:685224d2f66d 160 (uip_stopped(conn))? '!':' ');
ban4jp 0:685224d2f66d 161 }
ban4jp 0:685224d2f66d 162 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 163 static
ban4jp 0:685224d2f66d 164 PT_THREAD(tcp_stats(struct httpd_state *s, char *ptr))
ban4jp 0:685224d2f66d 165 {
ban4jp 0:685224d2f66d 166
ban4jp 0:685224d2f66d 167 PSOCK_BEGIN(&s->sout);
ban4jp 0:685224d2f66d 168
ban4jp 0:685224d2f66d 169 for(s->count = 0; s->count < UIP_CONNS; ++s->count) {
ban4jp 0:685224d2f66d 170 if((uip_conns[s->count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) {
ban4jp 0:685224d2f66d 171 PSOCK_GENERATOR_SEND(&s->sout, generate_tcp_stats, s);
ban4jp 0:685224d2f66d 172 }
ban4jp 0:685224d2f66d 173 }
ban4jp 0:685224d2f66d 174
ban4jp 0:685224d2f66d 175 PSOCK_END(&s->sout);
ban4jp 0:685224d2f66d 176 }
ban4jp 0:685224d2f66d 177 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 178 static unsigned short
ban4jp 0:685224d2f66d 179 generate_net_stats(void *arg)
ban4jp 0:685224d2f66d 180 {
ban4jp 0:685224d2f66d 181 struct httpd_state *s = (struct httpd_state *)arg;
ban4jp 0:685224d2f66d 182 return snprintf((char *)uip_appdata, UIP_APPDATA_SIZE,
ban4jp 1:b4d28172cacd 183 "%u\n", ((uip_stats_t *)&uip_stat)[s->count]);
ban4jp 0:685224d2f66d 184 }
ban4jp 0:685224d2f66d 185
ban4jp 0:685224d2f66d 186 static
ban4jp 0:685224d2f66d 187 PT_THREAD(net_stats(struct httpd_state *s, char *ptr))
ban4jp 0:685224d2f66d 188 {
ban4jp 0:685224d2f66d 189 PSOCK_BEGIN(&s->sout);
ban4jp 0:685224d2f66d 190
ban4jp 0:685224d2f66d 191 #if UIP_STATISTICS
ban4jp 0:685224d2f66d 192
ban4jp 0:685224d2f66d 193 for(s->count = 0; s->count < sizeof(uip_stat) / sizeof(uip_stats_t);
ban4jp 0:685224d2f66d 194 ++s->count) {
ban4jp 0:685224d2f66d 195 PSOCK_GENERATOR_SEND(&s->sout, generate_net_stats, s);
ban4jp 0:685224d2f66d 196 }
ban4jp 0:685224d2f66d 197
ban4jp 0:685224d2f66d 198 #endif /* UIP_STATISTICS */
ban4jp 0:685224d2f66d 199
ban4jp 0:685224d2f66d 200 PSOCK_END(&s->sout);
ban4jp 0:685224d2f66d 201 }
ban4jp 0:685224d2f66d 202 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 203 /** @} */