uIP 1.0 based webserver for LPC1114 + ENC28J60

Dependencies:   mbed TMP102

Committer:
ban4jp
Date:
Mon Jun 30 16:00:08 2014 +0000
Revision:
3:a2715e9c7737
Parent:
2:4da9ed411bdc
backported from Contiki 2.7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ban4jp 0:685224d2f66d 1 /**
ban4jp 0:685224d2f66d 2 * \addtogroup apps
ban4jp 0:685224d2f66d 3 * @{
ban4jp 0:685224d2f66d 4 */
ban4jp 0:685224d2f66d 5
ban4jp 0:685224d2f66d 6 /**
ban4jp 0:685224d2f66d 7 * \defgroup httpd Web server
ban4jp 0:685224d2f66d 8 * @{
ban4jp 0:685224d2f66d 9 * The uIP web server is a very simplistic implementation of an HTTP
ban4jp 0:685224d2f66d 10 * server. It can serve web pages and files from a read-only ROM
ban4jp 0:685224d2f66d 11 * filesystem, and provides a very small scripting language.
ban4jp 0:685224d2f66d 12
ban4jp 0:685224d2f66d 13 */
ban4jp 0:685224d2f66d 14
ban4jp 0:685224d2f66d 15 /**
ban4jp 0:685224d2f66d 16 * \file
ban4jp 0:685224d2f66d 17 * Web server
ban4jp 0:685224d2f66d 18 * \author
ban4jp 0:685224d2f66d 19 * Adam Dunkels <adam@sics.se>
ban4jp 0:685224d2f66d 20 */
ban4jp 0:685224d2f66d 21
ban4jp 0:685224d2f66d 22
ban4jp 0:685224d2f66d 23 /*
ban4jp 0:685224d2f66d 24 * Copyright (c) 2004, Adam Dunkels.
ban4jp 0:685224d2f66d 25 * All rights reserved.
ban4jp 0:685224d2f66d 26 *
ban4jp 0:685224d2f66d 27 * Redistribution and use in source and binary forms, with or without
ban4jp 0:685224d2f66d 28 * modification, are permitted provided that the following conditions
ban4jp 0:685224d2f66d 29 * are met:
ban4jp 0:685224d2f66d 30 * 1. Redistributions of source code must retain the above copyright
ban4jp 0:685224d2f66d 31 * notice, this list of conditions and the following disclaimer.
ban4jp 0:685224d2f66d 32 * 2. Redistributions in binary form must reproduce the above copyright
ban4jp 0:685224d2f66d 33 * notice, this list of conditions and the following disclaimer in the
ban4jp 0:685224d2f66d 34 * documentation and/or other materials provided with the distribution.
ban4jp 0:685224d2f66d 35 * 3. Neither the name of the Institute nor the names of its contributors
ban4jp 0:685224d2f66d 36 * may be used to endorse or promote products derived from this software
ban4jp 0:685224d2f66d 37 * without specific prior written permission.
ban4jp 0:685224d2f66d 38 *
ban4jp 0:685224d2f66d 39 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
ban4jp 0:685224d2f66d 40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ban4jp 0:685224d2f66d 41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ban4jp 0:685224d2f66d 42 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
ban4jp 0:685224d2f66d 43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ban4jp 0:685224d2f66d 44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
ban4jp 0:685224d2f66d 45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
ban4jp 0:685224d2f66d 46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
ban4jp 0:685224d2f66d 47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
ban4jp 0:685224d2f66d 48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ban4jp 0:685224d2f66d 49 * SUCH DAMAGE.
ban4jp 0:685224d2f66d 50 *
ban4jp 0:685224d2f66d 51 * This file is part of the uIP TCP/IP stack.
ban4jp 0:685224d2f66d 52 *
ban4jp 0:685224d2f66d 53 * Author: Adam Dunkels <adam@sics.se>
ban4jp 0:685224d2f66d 54 *
ban4jp 0:685224d2f66d 55 * $Id: httpd.c,v 1.2 2006/06/11 21:46:38 adam Exp $
ban4jp 0:685224d2f66d 56 */
ban4jp 0:685224d2f66d 57
ban4jp 2:4da9ed411bdc 58 extern "C" {
ban4jp 2:4da9ed411bdc 59 #include "uip.h"
ban4jp 2:4da9ed411bdc 60 #include "httpd.h"
ban4jp 2:4da9ed411bdc 61 }
ban4jp 2:4da9ed411bdc 62 //#include "httpd-fs.h"
ban4jp 0:685224d2f66d 63 #include "httpd-cgi.h"
ban4jp 0:685224d2f66d 64 #include "http-strings.h"
ban4jp 0:685224d2f66d 65
ban4jp 0:685224d2f66d 66 #include <string.h>
ban4jp 0:685224d2f66d 67
ban4jp 0:685224d2f66d 68 #define STATE_WAITING 0
ban4jp 0:685224d2f66d 69 #define STATE_OUTPUT 1
ban4jp 0:685224d2f66d 70
ban4jp 0:685224d2f66d 71 #define ISO_nl 0x0a
ban4jp 0:685224d2f66d 72 #define ISO_space 0x20
ban4jp 0:685224d2f66d 73 #define ISO_bang 0x21
ban4jp 0:685224d2f66d 74 #define ISO_percent 0x25
ban4jp 0:685224d2f66d 75 #define ISO_period 0x2e
ban4jp 0:685224d2f66d 76 #define ISO_slash 0x2f
ban4jp 0:685224d2f66d 77 #define ISO_colon 0x3a
ban4jp 0:685224d2f66d 78
ban4jp 0:685224d2f66d 79
ban4jp 0:685224d2f66d 80 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 81 static unsigned short
ban4jp 0:685224d2f66d 82 generate_part_of_file(void *state)
ban4jp 0:685224d2f66d 83 {
ban4jp 0:685224d2f66d 84 struct httpd_state *s = (struct httpd_state *)state;
ban4jp 0:685224d2f66d 85
ban4jp 0:685224d2f66d 86 if(s->file.len > uip_mss()) {
ban4jp 0:685224d2f66d 87 s->len = uip_mss();
ban4jp 0:685224d2f66d 88 } else {
ban4jp 0:685224d2f66d 89 s->len = s->file.len;
ban4jp 0:685224d2f66d 90 }
ban4jp 0:685224d2f66d 91 memcpy(uip_appdata, s->file.data, s->len);
ban4jp 0:685224d2f66d 92
ban4jp 0:685224d2f66d 93 return s->len;
ban4jp 0:685224d2f66d 94 }
ban4jp 0:685224d2f66d 95 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 96 static
ban4jp 0:685224d2f66d 97 PT_THREAD(send_file(struct httpd_state *s))
ban4jp 0:685224d2f66d 98 {
ban4jp 0:685224d2f66d 99 PSOCK_BEGIN(&s->sout);
ban4jp 0:685224d2f66d 100
ban4jp 0:685224d2f66d 101 do {
ban4jp 0:685224d2f66d 102 PSOCK_GENERATOR_SEND(&s->sout, generate_part_of_file, s);
ban4jp 0:685224d2f66d 103 s->file.len -= s->len;
ban4jp 0:685224d2f66d 104 s->file.data += s->len;
ban4jp 0:685224d2f66d 105 } while(s->file.len > 0);
ban4jp 0:685224d2f66d 106
ban4jp 0:685224d2f66d 107 PSOCK_END(&s->sout);
ban4jp 0:685224d2f66d 108 }
ban4jp 0:685224d2f66d 109 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 110 static
ban4jp 0:685224d2f66d 111 PT_THREAD(send_part_of_file(struct httpd_state *s))
ban4jp 0:685224d2f66d 112 {
ban4jp 0:685224d2f66d 113 PSOCK_BEGIN(&s->sout);
ban4jp 0:685224d2f66d 114
ban4jp 0:685224d2f66d 115 PSOCK_SEND(&s->sout, s->file.data, s->len);
ban4jp 0:685224d2f66d 116
ban4jp 0:685224d2f66d 117 PSOCK_END(&s->sout);
ban4jp 0:685224d2f66d 118 }
ban4jp 0:685224d2f66d 119 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 120 static void
ban4jp 0:685224d2f66d 121 next_scriptstate(struct httpd_state *s)
ban4jp 0:685224d2f66d 122 {
ban4jp 0:685224d2f66d 123 char *p;
ban4jp 3:a2715e9c7737 124
ban4jp 3:a2715e9c7737 125 if((p = strchr(s->scriptptr, ISO_nl)) != NULL) {
ban4jp 3:a2715e9c7737 126 p += 1;
ban4jp 3:a2715e9c7737 127 s->scriptlen -= (unsigned short)(p - s->scriptptr);
ban4jp 3:a2715e9c7737 128 s->scriptptr = p;
ban4jp 3:a2715e9c7737 129 } else {
ban4jp 3:a2715e9c7737 130 s->scriptlen = 0;
ban4jp 3:a2715e9c7737 131 }
ban4jp 0:685224d2f66d 132 }
ban4jp 0:685224d2f66d 133 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 134 static
ban4jp 0:685224d2f66d 135 PT_THREAD(handle_script(struct httpd_state *s))
ban4jp 0:685224d2f66d 136 {
ban4jp 0:685224d2f66d 137 char *ptr;
ban4jp 0:685224d2f66d 138
ban4jp 0:685224d2f66d 139 PT_BEGIN(&s->scriptpt);
ban4jp 0:685224d2f66d 140
ban4jp 0:685224d2f66d 141
ban4jp 0:685224d2f66d 142 while(s->file.len > 0) {
ban4jp 0:685224d2f66d 143
ban4jp 0:685224d2f66d 144 /* Check if we should start executing a script. */
ban4jp 0:685224d2f66d 145 if(*s->file.data == ISO_percent &&
ban4jp 0:685224d2f66d 146 *(s->file.data + 1) == ISO_bang) {
ban4jp 0:685224d2f66d 147 s->scriptptr = s->file.data + 3;
ban4jp 0:685224d2f66d 148 s->scriptlen = s->file.len - 3;
ban4jp 0:685224d2f66d 149 if(*(s->scriptptr - 1) == ISO_colon) {
ban4jp 2:4da9ed411bdc 150 httpd_fs_open(s->scriptptr + 1, &s->file);
ban4jp 2:4da9ed411bdc 151 PT_WAIT_THREAD(&s->scriptpt, send_file(s));
ban4jp 0:685224d2f66d 152 } else {
ban4jp 2:4da9ed411bdc 153 PT_WAIT_THREAD(&s->scriptpt,
ban4jp 2:4da9ed411bdc 154 httpd_cgi(s->scriptptr)(s, s->scriptptr));
ban4jp 0:685224d2f66d 155 }
ban4jp 0:685224d2f66d 156 next_scriptstate(s);
ban4jp 0:685224d2f66d 157
ban4jp 0:685224d2f66d 158 /* The script is over, so we reset the pointers and continue
ban4jp 2:4da9ed411bdc 159 sending the rest of the file. */
ban4jp 0:685224d2f66d 160 s->file.data = s->scriptptr;
ban4jp 0:685224d2f66d 161 s->file.len = s->scriptlen;
ban4jp 0:685224d2f66d 162 } else {
ban4jp 0:685224d2f66d 163 /* See if we find the start of script marker in the block of HTML
ban4jp 2:4da9ed411bdc 164 to be sent. */
ban4jp 0:685224d2f66d 165
ban4jp 0:685224d2f66d 166 if(s->file.len > uip_mss()) {
ban4jp 2:4da9ed411bdc 167 s->len = uip_mss();
ban4jp 0:685224d2f66d 168 } else {
ban4jp 2:4da9ed411bdc 169 s->len = s->file.len;
ban4jp 0:685224d2f66d 170 }
ban4jp 0:685224d2f66d 171
ban4jp 0:685224d2f66d 172 if(*s->file.data == ISO_percent) {
ban4jp 2:4da9ed411bdc 173 ptr = strchr(s->file.data + 1, ISO_percent);
ban4jp 0:685224d2f66d 174 } else {
ban4jp 2:4da9ed411bdc 175 ptr = strchr(s->file.data, ISO_percent);
ban4jp 0:685224d2f66d 176 }
ban4jp 0:685224d2f66d 177 if(ptr != NULL &&
ban4jp 2:4da9ed411bdc 178 ptr != s->file.data) {
ban4jp 2:4da9ed411bdc 179 s->len = (int)(ptr - s->file.data);
ban4jp 2:4da9ed411bdc 180 if(s->len >= uip_mss()) {
ban4jp 2:4da9ed411bdc 181 s->len = uip_mss();
ban4jp 2:4da9ed411bdc 182 }
ban4jp 0:685224d2f66d 183 }
ban4jp 0:685224d2f66d 184 PT_WAIT_THREAD(&s->scriptpt, send_part_of_file(s));
ban4jp 0:685224d2f66d 185 s->file.data += s->len;
ban4jp 0:685224d2f66d 186 s->file.len -= s->len;
ban4jp 0:685224d2f66d 187
ban4jp 0:685224d2f66d 188 }
ban4jp 0:685224d2f66d 189 }
ban4jp 0:685224d2f66d 190
ban4jp 0:685224d2f66d 191 PT_END(&s->scriptpt);
ban4jp 0:685224d2f66d 192 }
ban4jp 0:685224d2f66d 193 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 194 static
ban4jp 0:685224d2f66d 195 PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
ban4jp 0:685224d2f66d 196 {
ban4jp 0:685224d2f66d 197 char *ptr;
ban4jp 0:685224d2f66d 198
ban4jp 0:685224d2f66d 199 PSOCK_BEGIN(&s->sout);
ban4jp 0:685224d2f66d 200
ban4jp 0:685224d2f66d 201 PSOCK_SEND_STR(&s->sout, statushdr);
ban4jp 0:685224d2f66d 202
ban4jp 0:685224d2f66d 203 ptr = strrchr(s->filename, ISO_period);
ban4jp 0:685224d2f66d 204 if(ptr == NULL) {
ban4jp 0:685224d2f66d 205 PSOCK_SEND_STR(&s->sout, http_content_type_binary);
ban4jp 2:4da9ed411bdc 206 } else if(strncmp(http_html, ptr, sizeof(http_html)-1) == 0 ||
ban4jp 2:4da9ed411bdc 207 strncmp(http_shtml, ptr, sizeof(http_shtml)-1) == 0) {
ban4jp 0:685224d2f66d 208 PSOCK_SEND_STR(&s->sout, http_content_type_html);
ban4jp 2:4da9ed411bdc 209 } else if(strncmp(http_json, ptr, sizeof(http_json)-1) == 0) {
ban4jp 2:4da9ed411bdc 210 PSOCK_SEND_STR(&s->sout, http_content_type_json);
ban4jp 2:4da9ed411bdc 211 } else if(strncmp(http_xml, ptr, sizeof(http_xml)-1) == 0) {
ban4jp 2:4da9ed411bdc 212 PSOCK_SEND_STR(&s->sout, http_content_type_xml);
ban4jp 2:4da9ed411bdc 213 } else if(strncmp(http_css, ptr, sizeof(http_css)-1) == 0) {
ban4jp 0:685224d2f66d 214 PSOCK_SEND_STR(&s->sout, http_content_type_css);
ban4jp 2:4da9ed411bdc 215 } else if(strncmp(http_png, ptr, sizeof(http_png)-1) == 0) {
ban4jp 0:685224d2f66d 216 PSOCK_SEND_STR(&s->sout, http_content_type_png);
ban4jp 2:4da9ed411bdc 217 } else if(strncmp(http_gif, ptr, sizeof(http_gif)-1) == 0) {
ban4jp 0:685224d2f66d 218 PSOCK_SEND_STR(&s->sout, http_content_type_gif);
ban4jp 2:4da9ed411bdc 219 } else if(strncmp(http_jpg, ptr, sizeof(http_jpg)-1) == 0) {
ban4jp 0:685224d2f66d 220 PSOCK_SEND_STR(&s->sout, http_content_type_jpg);
ban4jp 0:685224d2f66d 221 } else {
ban4jp 0:685224d2f66d 222 PSOCK_SEND_STR(&s->sout, http_content_type_plain);
ban4jp 0:685224d2f66d 223 }
ban4jp 0:685224d2f66d 224 PSOCK_END(&s->sout);
ban4jp 0:685224d2f66d 225 }
ban4jp 0:685224d2f66d 226 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 227 static
ban4jp 0:685224d2f66d 228 PT_THREAD(handle_output(struct httpd_state *s))
ban4jp 0:685224d2f66d 229 {
ban4jp 0:685224d2f66d 230 char *ptr;
ban4jp 0:685224d2f66d 231
ban4jp 0:685224d2f66d 232 PT_BEGIN(&s->outputpt);
ban4jp 0:685224d2f66d 233
ban4jp 0:685224d2f66d 234 if(!httpd_fs_open(s->filename, &s->file)) {
ban4jp 0:685224d2f66d 235 httpd_fs_open(http_404_html, &s->file);
ban4jp 0:685224d2f66d 236 strcpy(s->filename, http_404_html);
ban4jp 0:685224d2f66d 237 PT_WAIT_THREAD(&s->outputpt,
ban4jp 2:4da9ed411bdc 238 send_headers(s,
ban4jp 2:4da9ed411bdc 239 http_header_404));
ban4jp 0:685224d2f66d 240 PT_WAIT_THREAD(&s->outputpt,
ban4jp 2:4da9ed411bdc 241 send_file(s));
ban4jp 0:685224d2f66d 242 } else {
ban4jp 0:685224d2f66d 243 PT_WAIT_THREAD(&s->outputpt,
ban4jp 2:4da9ed411bdc 244 send_headers(s,
ban4jp 2:4da9ed411bdc 245 http_header_200));
ban4jp 0:685224d2f66d 246 ptr = strchr(s->filename, ISO_period);
ban4jp 2:4da9ed411bdc 247 if(ptr != NULL && (strncmp(ptr, http_shtml, sizeof(http_shtml)-1) == 0 ||
ban4jp 2:4da9ed411bdc 248 strncmp(ptr, http_json, sizeof(http_json)-1) == 0 ||
ban4jp 2:4da9ed411bdc 249 strncmp(ptr, http_xml, sizeof(http_xml)-1) == 0)) {
ban4jp 0:685224d2f66d 250 PT_INIT(&s->scriptpt);
ban4jp 0:685224d2f66d 251 PT_WAIT_THREAD(&s->outputpt, handle_script(s));
ban4jp 0:685224d2f66d 252 } else {
ban4jp 0:685224d2f66d 253 PT_WAIT_THREAD(&s->outputpt,
ban4jp 2:4da9ed411bdc 254 send_file(s));
ban4jp 0:685224d2f66d 255 }
ban4jp 0:685224d2f66d 256 }
ban4jp 0:685224d2f66d 257 PSOCK_CLOSE(&s->sout);
ban4jp 0:685224d2f66d 258 PT_END(&s->outputpt);
ban4jp 0:685224d2f66d 259 }
ban4jp 0:685224d2f66d 260 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 261 static
ban4jp 0:685224d2f66d 262 PT_THREAD(handle_input(struct httpd_state *s))
ban4jp 0:685224d2f66d 263 {
ban4jp 0:685224d2f66d 264 PSOCK_BEGIN(&s->sin);
ban4jp 0:685224d2f66d 265
ban4jp 0:685224d2f66d 266 PSOCK_READTO(&s->sin, ISO_space);
ban4jp 0:685224d2f66d 267
ban4jp 0:685224d2f66d 268
ban4jp 2:4da9ed411bdc 269 if(strncmp(s->inputbuf, http_get, sizeof(http_get)-1) != 0) {
ban4jp 0:685224d2f66d 270 PSOCK_CLOSE_EXIT(&s->sin);
ban4jp 0:685224d2f66d 271 }
ban4jp 0:685224d2f66d 272 PSOCK_READTO(&s->sin, ISO_space);
ban4jp 0:685224d2f66d 273
ban4jp 0:685224d2f66d 274 if(s->inputbuf[0] != ISO_slash) {
ban4jp 0:685224d2f66d 275 PSOCK_CLOSE_EXIT(&s->sin);
ban4jp 0:685224d2f66d 276 }
ban4jp 0:685224d2f66d 277
ban4jp 0:685224d2f66d 278 if(s->inputbuf[1] == ISO_space) {
ban4jp 0:685224d2f66d 279 strncpy(s->filename, http_index_html, sizeof(s->filename));
ban4jp 0:685224d2f66d 280 } else {
ban4jp 0:685224d2f66d 281 s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
ban4jp 3:a2715e9c7737 282 strncpy(s->filename, s->inputbuf, sizeof(s->filename));
ban4jp 0:685224d2f66d 283 }
ban4jp 0:685224d2f66d 284
ban4jp 0:685224d2f66d 285 /* httpd_log_file(uip_conn->ripaddr, s->filename);*/
ban4jp 0:685224d2f66d 286
ban4jp 0:685224d2f66d 287 s->state = STATE_OUTPUT;
ban4jp 0:685224d2f66d 288
ban4jp 0:685224d2f66d 289 while(1) {
ban4jp 0:685224d2f66d 290 PSOCK_READTO(&s->sin, ISO_nl);
ban4jp 0:685224d2f66d 291
ban4jp 2:4da9ed411bdc 292 if(strncmp(s->inputbuf, http_referer, sizeof(http_referer)-1) == 0) {
ban4jp 0:685224d2f66d 293 s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
ban4jp 0:685224d2f66d 294 /* httpd_log(&s->inputbuf[9]);*/
ban4jp 0:685224d2f66d 295 }
ban4jp 0:685224d2f66d 296 }
ban4jp 0:685224d2f66d 297
ban4jp 0:685224d2f66d 298 PSOCK_END(&s->sin);
ban4jp 0:685224d2f66d 299 }
ban4jp 0:685224d2f66d 300 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 301 static void
ban4jp 0:685224d2f66d 302 handle_connection(struct httpd_state *s)
ban4jp 0:685224d2f66d 303 {
ban4jp 0:685224d2f66d 304 handle_input(s);
ban4jp 0:685224d2f66d 305 if(s->state == STATE_OUTPUT) {
ban4jp 0:685224d2f66d 306 handle_output(s);
ban4jp 0:685224d2f66d 307 }
ban4jp 0:685224d2f66d 308 }
ban4jp 0:685224d2f66d 309 /*---------------------------------------------------------------------------*/
ban4jp 2:4da9ed411bdc 310 extern "C" void
ban4jp 0:685224d2f66d 311 httpd_appcall(void)
ban4jp 0:685224d2f66d 312 {
ban4jp 0:685224d2f66d 313 struct httpd_state *s = (struct httpd_state *)&(uip_conn->appstate);
ban4jp 0:685224d2f66d 314
ban4jp 0:685224d2f66d 315 if(uip_closed() || uip_aborted() || uip_timedout()) {
ban4jp 0:685224d2f66d 316 } else if(uip_connected()) {
ban4jp 0:685224d2f66d 317 PSOCK_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1);
ban4jp 0:685224d2f66d 318 PSOCK_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1);
ban4jp 0:685224d2f66d 319 PT_INIT(&s->outputpt);
ban4jp 0:685224d2f66d 320 s->state = STATE_WAITING;
ban4jp 0:685224d2f66d 321 /* timer_set(&s->timer, CLOCK_SECOND * 100);*/
ban4jp 0:685224d2f66d 322 s->timer = 0;
ban4jp 0:685224d2f66d 323 handle_connection(s);
ban4jp 0:685224d2f66d 324 } else if(s != NULL) {
ban4jp 0:685224d2f66d 325 if(uip_poll()) {
ban4jp 0:685224d2f66d 326 ++s->timer;
ban4jp 0:685224d2f66d 327 if(s->timer >= 20) {
ban4jp 2:4da9ed411bdc 328 uip_abort();
ban4jp 0:685224d2f66d 329 }
ban4jp 0:685224d2f66d 330 } else {
ban4jp 0:685224d2f66d 331 s->timer = 0;
ban4jp 0:685224d2f66d 332 }
ban4jp 0:685224d2f66d 333 handle_connection(s);
ban4jp 0:685224d2f66d 334 } else {
ban4jp 0:685224d2f66d 335 uip_abort();
ban4jp 0:685224d2f66d 336 }
ban4jp 0:685224d2f66d 337 }
ban4jp 0:685224d2f66d 338 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 339 /**
ban4jp 0:685224d2f66d 340 * \brief Initialize the web server
ban4jp 0:685224d2f66d 341 *
ban4jp 0:685224d2f66d 342 * This function initializes the web server and should be
ban4jp 0:685224d2f66d 343 * called at system boot-up.
ban4jp 0:685224d2f66d 344 */
ban4jp 2:4da9ed411bdc 345 extern "C" void
ban4jp 0:685224d2f66d 346 httpd_init(void)
ban4jp 0:685224d2f66d 347 {
ban4jp 3:a2715e9c7737 348 uip_listen(UIP_HTONS(80));
ban4jp 0:685224d2f66d 349 }
ban4jp 0:685224d2f66d 350 /*---------------------------------------------------------------------------*/
ban4jp 0:685224d2f66d 351 /** @} */