Initial version
This commit is contained in:
@ -0,0 +1,486 @@
|
||||
const char http_http[8] = /* "http://" */ { 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, };
|
||||
const char http_200[5] = /* "200 " */ { 0x32, 0x30, 0x30, 0x20, };
|
||||
const char http_301[5] = /* "301 " */ { 0x33, 0x30, 0x31, 0x20, };
|
||||
const char http_302[5] = /* "302 " */ { 0x33, 0x30, 0x32, 0x20, };
|
||||
const char http_get[5] = /* "GET " */ { 0x47, 0x45, 0x54, 0x20, };
|
||||
const char http_10[9] = /* "HTTP/1.0" */ { 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30, };
|
||||
const char http_11[9] = /* "HTTP/1.1" */ { 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, };
|
||||
const char http_content_type[15] =
|
||||
|
||||
/* "content-type: " */
|
||||
{ 0x63,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
};
|
||||
const char http_texthtml[10] = /* "text/html" */ { 0x74, 0x65, 0x78, 0x74, 0x2f, 0x68, 0x74, 0x6d, 0x6c, };
|
||||
const char http_location[11] = /* "location: " */ { 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, };
|
||||
const char http_host[7] = /* "host: " */ { 0x68, 0x6f, 0x73, 0x74, 0x3a, 0x20, };
|
||||
const char http_crnl[3] = /* "\r\n" */ { 0xd, 0xa, };
|
||||
const char http_index_html[12] = /* "/index.html" */ { 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x68, 0x74, 0x6d, 0x6c, };
|
||||
const char http_404_html[10] = /* "/404.html" */ { 0x2f, 0x34, 0x30, 0x34, 0x2e, 0x68, 0x74, 0x6d, 0x6c, };
|
||||
const char http_referer[9] = /* "Referer:" */ { 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x72, 0x3a, };
|
||||
const char http_header_200[84] =
|
||||
|
||||
/* "HTTP/1.0 200 OK\r\nServer: uIP/1.0 http://www.sics.se/~adam/uip/\r\nConnection: close\r\n" */
|
||||
{ 0x48,
|
||||
0x54,
|
||||
0x54,
|
||||
0x50,
|
||||
0x2f,
|
||||
0x31,
|
||||
0x2e,
|
||||
0x30,
|
||||
0x20,
|
||||
0x32,
|
||||
0x30,
|
||||
0x30,
|
||||
0x20,
|
||||
0x4f,
|
||||
0x4b,
|
||||
0xd,
|
||||
0xa,
|
||||
0x53,
|
||||
0x65,
|
||||
0x72,
|
||||
0x76,
|
||||
0x65,
|
||||
0x72,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x75,
|
||||
0x49,
|
||||
0x50,
|
||||
0x2f,
|
||||
0x31,
|
||||
0x2e,
|
||||
0x30,
|
||||
0x20,
|
||||
0x68,
|
||||
0x74,
|
||||
0x74,
|
||||
0x70,
|
||||
0x3a,
|
||||
0x2f,
|
||||
0x2f,
|
||||
0x77,
|
||||
0x77,
|
||||
0x77,
|
||||
0x2e,
|
||||
0x73,
|
||||
0x69,
|
||||
0x63,
|
||||
0x73,
|
||||
0x2e,
|
||||
0x73,
|
||||
0x65,
|
||||
0x2f,
|
||||
0x7e,
|
||||
0x61,
|
||||
0x64,
|
||||
0x61,
|
||||
0x6d,
|
||||
0x2f,
|
||||
0x75,
|
||||
0x69,
|
||||
0x70,
|
||||
0x2f,
|
||||
0xd,
|
||||
0xa,
|
||||
0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x6e,
|
||||
0x65,
|
||||
0x63,
|
||||
0x74,
|
||||
0x69,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x63,
|
||||
0x6c,
|
||||
0x6f,
|
||||
0x73,
|
||||
0x65,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_header_404[91] =
|
||||
|
||||
/* "HTTP/1.0 404 Not found\r\nServer: uIP/1.0 http://www.sics.se/~adam/uip/\r\nConnection: close\r\n" */
|
||||
{ 0x48,
|
||||
0x54,
|
||||
0x54,
|
||||
0x50,
|
||||
0x2f,
|
||||
0x31,
|
||||
0x2e,
|
||||
0x30,
|
||||
0x20,
|
||||
0x34,
|
||||
0x30,
|
||||
0x34,
|
||||
0x20,
|
||||
0x4e,
|
||||
0x6f,
|
||||
0x74,
|
||||
0x20,
|
||||
0x66,
|
||||
0x6f,
|
||||
0x75,
|
||||
0x6e,
|
||||
0x64,
|
||||
0xd,
|
||||
0xa,
|
||||
0x53,
|
||||
0x65,
|
||||
0x72,
|
||||
0x76,
|
||||
0x65,
|
||||
0x72,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x75,
|
||||
0x49,
|
||||
0x50,
|
||||
0x2f,
|
||||
0x31,
|
||||
0x2e,
|
||||
0x30,
|
||||
0x20,
|
||||
0x68,
|
||||
0x74,
|
||||
0x74,
|
||||
0x70,
|
||||
0x3a,
|
||||
0x2f,
|
||||
0x2f,
|
||||
0x77,
|
||||
0x77,
|
||||
0x77,
|
||||
0x2e,
|
||||
0x73,
|
||||
0x69,
|
||||
0x63,
|
||||
0x73,
|
||||
0x2e,
|
||||
0x73,
|
||||
0x65,
|
||||
0x2f,
|
||||
0x7e,
|
||||
0x61,
|
||||
0x64,
|
||||
0x61,
|
||||
0x6d,
|
||||
0x2f,
|
||||
0x75,
|
||||
0x69,
|
||||
0x70,
|
||||
0x2f,
|
||||
0xd,
|
||||
0xa,
|
||||
0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x6e,
|
||||
0x65,
|
||||
0x63,
|
||||
0x74,
|
||||
0x69,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x63,
|
||||
0x6c,
|
||||
0x6f,
|
||||
0x73,
|
||||
0x65,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_content_type_plain[29] =
|
||||
|
||||
/* "Content-type: text/plain\r\n\r\n" */
|
||||
{ 0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x74,
|
||||
0x65,
|
||||
0x78,
|
||||
0x74,
|
||||
0x2f,
|
||||
0x70,
|
||||
0x6c,
|
||||
0x61,
|
||||
0x69,
|
||||
0x6e,
|
||||
0xd,
|
||||
0xa,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_content_type_html[28] =
|
||||
|
||||
/* "Content-type: text/html\r\n\r\n" */
|
||||
{ 0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x74,
|
||||
0x65,
|
||||
0x78,
|
||||
0x74,
|
||||
0x2f,
|
||||
0x68,
|
||||
0x74,
|
||||
0x6d,
|
||||
0x6c,
|
||||
0xd,
|
||||
0xa,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_content_type_css[27] =
|
||||
|
||||
/* "Content-type: text/css\r\n\r\n" */
|
||||
{ 0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x74,
|
||||
0x65,
|
||||
0x78,
|
||||
0x74,
|
||||
0x2f,
|
||||
0x63,
|
||||
0x73,
|
||||
0x73,
|
||||
0xd,
|
||||
0xa,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_content_type_text[28] =
|
||||
|
||||
/* "Content-type: text/text\r\n\r\n" */
|
||||
{ 0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x74,
|
||||
0x65,
|
||||
0x78,
|
||||
0x74,
|
||||
0x2f,
|
||||
0x74,
|
||||
0x65,
|
||||
0x78,
|
||||
0x74,
|
||||
0xd,
|
||||
0xa,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_content_type_png[28] =
|
||||
|
||||
/* "Content-type: image/png\r\n\r\n" */
|
||||
{ 0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x69,
|
||||
0x6d,
|
||||
0x61,
|
||||
0x67,
|
||||
0x65,
|
||||
0x2f,
|
||||
0x70,
|
||||
0x6e,
|
||||
0x67,
|
||||
0xd,
|
||||
0xa,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_content_type_gif[28] =
|
||||
|
||||
/* "Content-type: image/gif\r\n\r\n" */
|
||||
{ 0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x69,
|
||||
0x6d,
|
||||
0x61,
|
||||
0x67,
|
||||
0x65,
|
||||
0x2f,
|
||||
0x67,
|
||||
0x69,
|
||||
0x66,
|
||||
0xd,
|
||||
0xa,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_content_type_jpg[29] =
|
||||
|
||||
/* "Content-type: image/jpeg\r\n\r\n" */
|
||||
{ 0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x69,
|
||||
0x6d,
|
||||
0x61,
|
||||
0x67,
|
||||
0x65,
|
||||
0x2f,
|
||||
0x6a,
|
||||
0x70,
|
||||
0x65,
|
||||
0x67,
|
||||
0xd,
|
||||
0xa,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_content_type_binary[43] =
|
||||
|
||||
/* "Content-type: application/octet-stream\r\n\r\n" */
|
||||
{ 0x43,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x65,
|
||||
0x6e,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x74,
|
||||
0x79,
|
||||
0x70,
|
||||
0x65,
|
||||
0x3a,
|
||||
0x20,
|
||||
0x61,
|
||||
0x70,
|
||||
0x70,
|
||||
0x6c,
|
||||
0x69,
|
||||
0x63,
|
||||
0x61,
|
||||
0x74,
|
||||
0x69,
|
||||
0x6f,
|
||||
0x6e,
|
||||
0x2f,
|
||||
0x6f,
|
||||
0x63,
|
||||
0x74,
|
||||
0x65,
|
||||
0x74,
|
||||
0x2d,
|
||||
0x73,
|
||||
0x74,
|
||||
0x72,
|
||||
0x65,
|
||||
0x61,
|
||||
0x6d,
|
||||
0xd,
|
||||
0xa,
|
||||
0xd,
|
||||
0xa,
|
||||
};
|
||||
const char http_html[6] = /* ".html" */ { 0x2e, 0x68, 0x74, 0x6d, 0x6c, };
|
||||
const char http_shtml[7] = /* ".shtml" */ { 0x2e, 0x73, 0x68, 0x74, 0x6d, 0x6c, };
|
||||
const char http_htm[5] = /* ".htm" */ { 0x2e, 0x68, 0x74, 0x6d, };
|
||||
const char http_css[5] = /* ".css" */ { 0x2e, 0x63, 0x73, 0x73, };
|
||||
const char http_png[5] = /* ".png" */ { 0x2e, 0x70, 0x6e, 0x67, };
|
||||
const char http_gif[5] = /* ".gif" */ { 0x2e, 0x67, 0x69, 0x66, };
|
||||
const char http_jpg[5] = /* ".jpg" */ { 0x2e, 0x6a, 0x70, 0x67, };
|
||||
const char http_text[5] = /* ".txt" */ { 0x2e, 0x74, 0x78, 0x74, };
|
||||
const char http_txt[5] = /* ".txt" */ { 0x2e, 0x74, 0x78, 0x74, };
|
@ -0,0 +1,34 @@
|
||||
extern const char http_http[8];
|
||||
extern const char http_200[5];
|
||||
extern const char http_301[5];
|
||||
extern const char http_302[5];
|
||||
extern const char http_get[5];
|
||||
extern const char http_10[9];
|
||||
extern const char http_11[9];
|
||||
extern const char http_content_type[15];
|
||||
extern const char http_texthtml[10];
|
||||
extern const char http_location[11];
|
||||
extern const char http_host[7];
|
||||
extern const char http_crnl[3];
|
||||
extern const char http_index_html[12];
|
||||
extern const char http_404_html[10];
|
||||
extern const char http_referer[9];
|
||||
extern const char http_header_200[84];
|
||||
extern const char http_header_404[91];
|
||||
extern const char http_content_type_plain[29];
|
||||
extern const char http_content_type_html[28];
|
||||
extern const char http_content_type_css[27];
|
||||
extern const char http_content_type_text[28];
|
||||
extern const char http_content_type_png[28];
|
||||
extern const char http_content_type_gif[28];
|
||||
extern const char http_content_type_jpg[29];
|
||||
extern const char http_content_type_binary[43];
|
||||
extern const char http_html[6];
|
||||
extern const char http_shtml[7];
|
||||
extern const char http_htm[5];
|
||||
extern const char http_css[5];
|
||||
extern const char http_png[5];
|
||||
extern const char http_gif[5];
|
||||
extern const char http_jpg[5];
|
||||
extern const char http_text[5];
|
||||
extern const char http_txt[5];
|
@ -0,0 +1,169 @@
|
||||
/**
|
||||
* \addtogroup httpd
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Web server script interface
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2006, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: httpd-cgi.c,v 1.2 2006/06/11 21:46:37 adam Exp $
|
||||
*
|
||||
*/
|
||||
#include "net/uip.h"
|
||||
#include "net/psock.h"
|
||||
#include "httpd.h"
|
||||
#include "httpd-cgi.h"
|
||||
#include "httpd-fs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
HTTPD_CGI_CALL( file, "file-stats", file_stats );
|
||||
HTTPD_CGI_CALL( tcp, "tcp-connections", tcp_stats );
|
||||
HTTPD_CGI_CALL( net, "net-stats", net_stats );
|
||||
|
||||
static const struct httpd_cgi_call *calls[] = { &file, &tcp, &net, NULL };
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( nullfunction ( struct httpd_state *s, char *ptr ) )
|
||||
{
|
||||
PSOCK_BEGIN( &s->sout );
|
||||
PSOCK_END( &s->sout );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
httpd_cgifunction httpd_cgi( char *name )
|
||||
{
|
||||
const struct httpd_cgi_call **f;
|
||||
|
||||
/* Find the matching name in the table, return the function. */
|
||||
for( f = calls; *f != NULL; ++f )
|
||||
{
|
||||
if( strncmp((*f)->name, name, strlen((*f)->name)) == 0 )
|
||||
{
|
||||
return( *f )->function;
|
||||
}
|
||||
}
|
||||
|
||||
return nullfunction;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned short generate_file_stats( void *arg )
|
||||
{
|
||||
char *f = ( char * ) arg;
|
||||
return snprintf( ( char * ) uip_appdata, UIP_APPDATA_SIZE, "%5u", httpd_fs_count(f) );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( file_stats ( struct httpd_state *s, char *ptr ) )
|
||||
{
|
||||
PSOCK_BEGIN( &s->sout );
|
||||
|
||||
PSOCK_GENERATOR_SEND( &s->sout, generate_file_stats, strchr(ptr, ' ') + 1 );
|
||||
|
||||
PSOCK_END( &s->sout );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const char closed[] = /* "CLOSED",*/ { 0x43, 0x4c, 0x4f, 0x53, 0x45, 0x44, 0 };
|
||||
static const char syn_rcvd[] = /* "SYN-RCVD",*/ { 0x53, 0x59, 0x4e, 0x2d, 0x52, 0x43, 0x56, 0x44, 0 };
|
||||
static const char syn_sent[] = /* "SYN-SENT",*/ { 0x53, 0x59, 0x4e, 0x2d, 0x53, 0x45, 0x4e, 0x54, 0 };
|
||||
static const char established[] = /* "ESTABLISHED",*/ { 0x45, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x49, 0x53, 0x48, 0x45, 0x44, 0 };
|
||||
static const char fin_wait_1[] = /* "FIN-WAIT-1",*/ { 0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49, 0x54, 0x2d, 0x31, 0 };
|
||||
static const char fin_wait_2[] = /* "FIN-WAIT-2",*/ { 0x46, 0x49, 0x4e, 0x2d, 0x57, 0x41, 0x49, 0x54, 0x2d, 0x32, 0 };
|
||||
static const char closing[] = /* "CLOSING",*/ { 0x43, 0x4c, 0x4f, 0x53, 0x49, 0x4e, 0x47, 0 };
|
||||
static const char time_wait[] = /* "TIME-WAIT,"*/ { 0x54, 0x49, 0x4d, 0x45, 0x2d, 0x57, 0x41, 0x49, 0x54, 0 };
|
||||
static const char last_ack[] = /* "LAST-ACK"*/ { 0x4c, 0x41, 0x53, 0x54, 0x2d, 0x41, 0x43, 0x4b, 0 };
|
||||
|
||||
static const char *states[] = { closed, syn_rcvd, syn_sent, established, fin_wait_1, fin_wait_2, closing, time_wait, last_ack };
|
||||
|
||||
static unsigned short generate_tcp_stats( void *arg )
|
||||
{
|
||||
struct uip_conn *conn;
|
||||
struct httpd_state *s = ( struct httpd_state * ) arg;
|
||||
|
||||
conn = &uip_conns[s->count];
|
||||
return snprintf( ( char * ) uip_appdata, UIP_APPDATA_SIZE,
|
||||
"<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>\r\n", htons(conn->lport),
|
||||
htons(conn->ripaddr[0]) >> 8, htons(conn->ripaddr[0]) & 0xff, htons(conn->ripaddr[1]) >> 8,
|
||||
htons(conn->ripaddr[1]) & 0xff, htons(conn->rport), states[conn->tcpstateflags & UIP_TS_MASK], conn->nrtx, conn->timer,
|
||||
(uip_outstanding(conn)) ? '*' : ' ', (uip_stopped(conn)) ? '!' : ' ' );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( tcp_stats ( struct httpd_state *s, char *ptr ) )
|
||||
{
|
||||
PSOCK_BEGIN( &s->sout );
|
||||
|
||||
for( s->count = 0; s->count < UIP_CONNS; ++s->count )
|
||||
{
|
||||
if( (uip_conns[s->count].tcpstateflags & UIP_TS_MASK) != UIP_CLOSED )
|
||||
{
|
||||
PSOCK_GENERATOR_SEND( &s->sout, generate_tcp_stats, s );
|
||||
}
|
||||
}
|
||||
|
||||
PSOCK_END( &s->sout );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned short generate_net_stats( void *arg )
|
||||
{
|
||||
struct httpd_state *s = ( struct httpd_state * ) arg;
|
||||
return snprintf( ( char * ) uip_appdata, UIP_APPDATA_SIZE, "%5u\n", (( uip_stats_t * ) &uip_stat)[s->count] );
|
||||
}
|
||||
|
||||
static PT_THREAD( net_stats ( struct httpd_state *s, char *ptr ) )
|
||||
{
|
||||
PSOCK_BEGIN( &s->sout );
|
||||
|
||||
#if UIP_STATISTICS
|
||||
for( s->count = 0; s->count < sizeof(uip_stat) / sizeof(uip_stats_t); ++s->count )
|
||||
{
|
||||
PSOCK_GENERATOR_SEND( &s->sout, generate_net_stats, s );
|
||||
}
|
||||
|
||||
#endif /* UIP_STATISTICS */
|
||||
|
||||
PSOCK_END( &s->sout );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @} */
|
@ -0,0 +1,85 @@
|
||||
/**
|
||||
* \addtogroup httpd
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Web server script interface header file
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: httpd-cgi.h,v 1.2 2006/06/11 21:46:38 adam Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __HTTPD_CGI_H__
|
||||
#define __HTTPD_CGI_H__
|
||||
|
||||
#include "net/psock.h"
|
||||
#include "httpd.h"
|
||||
|
||||
typedef PT_THREAD( (*httpd_cgifunction) ( struct httpd_state *, char * ) );
|
||||
|
||||
httpd_cgifunction httpd_cgi( char *name );
|
||||
|
||||
struct httpd_cgi_call
|
||||
{
|
||||
const char *name;
|
||||
const httpd_cgifunction function;
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief HTTPD CGI function declaration
|
||||
* \param name The C variable name of the function
|
||||
* \param str The string name of the function, used in the script file
|
||||
* \param function A pointer to the function that implements it
|
||||
*
|
||||
* This macro is used for declaring a HTTPD CGI
|
||||
* function. This function is then added to the list of
|
||||
* HTTPD CGI functions with the httpd_cgi_add() function.
|
||||
*
|
||||
* \hideinitializer
|
||||
*/
|
||||
#define HTTPD_CGI_CALL( name, str, function ) \
|
||||
static PT_THREAD( function ( struct httpd_state *, char * ) ); \
|
||||
static const struct httpd_cgi_call name = \
|
||||
{ \
|
||||
str, function \
|
||||
}
|
||||
|
||||
void httpd_cgi_init( void );
|
||||
#endif /* __HTTPD_CGI_H__ */
|
||||
|
||||
/** @} */
|
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2001, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd-fs.c,v 1.1 2006/06/07 09:13:08 adam Exp $
|
||||
*/
|
||||
#include "httpd.h"
|
||||
#include "httpd-fs.h"
|
||||
#include "httpd-fsdata.h"
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0
|
||||
#endif /* NULL */
|
||||
|
||||
#include "httpd-fsdata.c"
|
||||
|
||||
#if HTTPD_FS_STATISTICS
|
||||
static u16_t count[HTTPD_FS_NUMFILES];
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
static u8_t httpd_fs_strcmp( const char *str1, const char *str2 )
|
||||
{
|
||||
u8_t i;
|
||||
i = 0;
|
||||
loop:
|
||||
if( str2[i] == 0 || str1[i] == '\r' || str1[i] == '\n' )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( str1[i] != str2[i] )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
++i;
|
||||
goto loop;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int httpd_fs_open( const char *name, struct httpd_fs_file *file )
|
||||
{
|
||||
#if HTTPD_FS_STATISTICS
|
||||
u16_t i = 0;
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
struct httpd_fsdata_file_noconst *f;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void httpd_fs_init( void )
|
||||
{
|
||||
#if HTTPD_FS_STATISTICS
|
||||
u16_t i;
|
||||
for( i = 0; i < HTTPD_FS_NUMFILES; i++ )
|
||||
{
|
||||
count[i] = 0;
|
||||
}
|
||||
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if HTTPD_FS_STATISTICS
|
||||
u16_t httpd_fs_count( char *name )
|
||||
{
|
||||
struct httpd_fsdata_file_noconst *f;
|
||||
u16_t i;
|
||||
|
||||
i = 0;
|
||||
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 )
|
||||
{
|
||||
return count[i];
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2001, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd-fs.h,v 1.1 2006/06/07 09:13:08 adam Exp $
|
||||
*/
|
||||
#ifndef __HTTPD_FS_H__
|
||||
#define __HTTPD_FS_H__
|
||||
|
||||
#define HTTPD_FS_STATISTICS 1
|
||||
|
||||
struct httpd_fs_file
|
||||
{
|
||||
char *data;
|
||||
int len;
|
||||
};
|
||||
|
||||
/* file must be allocated by caller and will be filled in
|
||||
by the function. */
|
||||
int httpd_fs_open( const char *name, struct httpd_fs_file *file );
|
||||
|
||||
#ifdef HTTPD_FS_STATISTICS
|
||||
#if HTTPD_FS_STATISTICS == 1
|
||||
u16_t httpd_fs_count( char *name );
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
|
||||
void httpd_fs_init( void );
|
||||
#endif /* __HTTPD_FS_H__ */
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2001, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd-fsdata.h,v 1.1 2006/06/17 22:41:14 adamdunkels Exp $
|
||||
*/
|
||||
#ifndef __HTTPD_FSDATA_H__
|
||||
#define __HTTPD_FSDATA_H__
|
||||
|
||||
struct httpd_fsdata_file {
|
||||
const struct httpd_fsdata_file *next;
|
||||
const char *name;
|
||||
const char *data;
|
||||
const int len;
|
||||
#ifdef HTTPD_FS_STATISTICS
|
||||
#if HTTPD_FS_STATISTICS == 1
|
||||
u16_t count;
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
};
|
||||
|
||||
struct httpd_fsdata_file_noconst {
|
||||
struct httpd_fsdata_file *next;
|
||||
char *name;
|
||||
char *data;
|
||||
int len;
|
||||
#ifdef HTTPD_FS_STATISTICS
|
||||
#if HTTPD_FS_STATISTICS == 1
|
||||
u16_t count;
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
#endif /* HTTPD_FS_STATISTICS */
|
||||
};
|
||||
|
||||
#endif /* __HTTPD_FSDATA_H__ */
|
@ -0,0 +1,400 @@
|
||||
/**
|
||||
* \addtogroup apps
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \defgroup httpd Web server
|
||||
* @{
|
||||
* The uIP web server is a very simplistic implementation of an HTTP
|
||||
* server. It can serve web pages and files from a read-only ROM
|
||||
* filesystem, and provides a very small scripting language.
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Web server
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* $Id: httpd.c,v 1.2 2006/06/11 21:46:38 adam Exp $
|
||||
*/
|
||||
#include "net/uip.h"
|
||||
#include "apps/httpd/httpd.h"
|
||||
#include "apps/httpd/httpd-fs.h"
|
||||
#include "apps/httpd/httpd-cgi.h"
|
||||
#include "apps/httpd/http-strings.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define STATE_WAITING 0
|
||||
#define STATE_OUTPUT 1
|
||||
|
||||
#define ISO_nl 0x0a
|
||||
#define ISO_space 0x20
|
||||
#define ISO_bang 0x21
|
||||
#define ISO_percent 0x25
|
||||
#define ISO_period 0x2e
|
||||
#define ISO_slash 0x2f
|
||||
#define ISO_colon 0x3a
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static unsigned short generate_part_of_file( void *state )
|
||||
{
|
||||
struct httpd_state *s = ( struct httpd_state * ) state;
|
||||
|
||||
if( s->file.len > uip_mss() )
|
||||
{
|
||||
s->len = uip_mss();
|
||||
}
|
||||
else
|
||||
{
|
||||
s->len = s->file.len;
|
||||
}
|
||||
|
||||
memcpy( uip_appdata, s->file.data, s->len );
|
||||
|
||||
return s->len;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( send_file ( struct httpd_state *s ) )
|
||||
{
|
||||
PSOCK_BEGIN( &s->sout );
|
||||
|
||||
( void ) PT_YIELD_FLAG;
|
||||
|
||||
do
|
||||
{
|
||||
PSOCK_GENERATOR_SEND( &s->sout, generate_part_of_file, s );
|
||||
s->file.len -= s->len;
|
||||
s->file.data += s->len;
|
||||
} while( s->file.len > 0 );
|
||||
|
||||
PSOCK_END( &s->sout );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( send_part_of_file ( struct httpd_state *s ) )
|
||||
{
|
||||
PSOCK_BEGIN( &s->sout );
|
||||
( void ) PT_YIELD_FLAG;
|
||||
|
||||
PSOCK_SEND( &s->sout, s->file.data, s->len );
|
||||
|
||||
PSOCK_END( &s->sout );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void next_scriptstate( struct httpd_state *s )
|
||||
{
|
||||
char *p;
|
||||
p = strchr( s->scriptptr, ISO_nl ) + 1;
|
||||
s->scriptlen -= ( unsigned short ) ( p - s->scriptptr );
|
||||
s->scriptptr = p;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( handle_script ( struct httpd_state *s ) )
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
PT_BEGIN( &s->scriptpt );
|
||||
( void ) PT_YIELD_FLAG;
|
||||
while( s->file.len > 0 )
|
||||
{
|
||||
/* Check if we should start executing a script. */
|
||||
if( *s->file.data == ISO_percent && *(s->file.data + 1) == ISO_bang )
|
||||
{
|
||||
s->scriptptr = s->file.data + 3;
|
||||
s->scriptlen = s->file.len - 3;
|
||||
if( *(s->scriptptr - 1) == ISO_colon )
|
||||
{
|
||||
httpd_fs_open( s->scriptptr + 1, &s->file );
|
||||
PT_WAIT_THREAD( &s->scriptpt, send_file(s) );
|
||||
}
|
||||
else
|
||||
{
|
||||
PT_WAIT_THREAD( &s->scriptpt, httpd_cgi(s->scriptptr) (s, s->scriptptr) );
|
||||
}
|
||||
|
||||
next_scriptstate( s );
|
||||
|
||||
/* The script is over, so we reset the pointers and continue
|
||||
sending the rest of the file. */
|
||||
s->file.data = s->scriptptr;
|
||||
s->file.len = s->scriptlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* See if we find the start of script marker in the block of HTML
|
||||
to be sent. */
|
||||
if( s->file.len > uip_mss() )
|
||||
{
|
||||
s->len = uip_mss();
|
||||
}
|
||||
else
|
||||
{
|
||||
s->len = s->file.len;
|
||||
}
|
||||
|
||||
if( *s->file.data == ISO_percent )
|
||||
{
|
||||
ptr = strchr( s->file.data + 1, ISO_percent );
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = strchr( s->file.data, ISO_percent );
|
||||
}
|
||||
|
||||
if( ptr != NULL && ptr != s->file.data )
|
||||
{
|
||||
s->len = ( int ) ( ptr - s->file.data );
|
||||
if( s->len >= uip_mss() )
|
||||
{
|
||||
s->len = uip_mss();
|
||||
}
|
||||
}
|
||||
|
||||
PT_WAIT_THREAD( &s->scriptpt, send_part_of_file(s) );
|
||||
s->file.data += s->len;
|
||||
s->file.len -= s->len;
|
||||
}
|
||||
}
|
||||
|
||||
PT_END( &s->scriptpt );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( send_headers ( struct httpd_state *s, const char *statushdr ) )
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
PSOCK_BEGIN( &s->sout );
|
||||
( void ) PT_YIELD_FLAG;
|
||||
PSOCK_SEND_STR( &s->sout, statushdr );
|
||||
|
||||
ptr = strrchr( s->filename, ISO_period );
|
||||
if( ptr == NULL )
|
||||
{
|
||||
PSOCK_SEND_STR( &s->sout, http_content_type_binary );
|
||||
}
|
||||
else if( strncmp(http_html, ptr, 5) == 0 || strncmp(http_shtml, ptr, 6) == 0 )
|
||||
{
|
||||
PSOCK_SEND_STR( &s->sout, http_content_type_html );
|
||||
}
|
||||
else if( strncmp(http_css, ptr, 4) == 0 )
|
||||
{
|
||||
PSOCK_SEND_STR( &s->sout, http_content_type_css );
|
||||
}
|
||||
else if( strncmp(http_png, ptr, 4) == 0 )
|
||||
{
|
||||
PSOCK_SEND_STR( &s->sout, http_content_type_png );
|
||||
}
|
||||
else if( strncmp(http_gif, ptr, 4) == 0 )
|
||||
{
|
||||
PSOCK_SEND_STR( &s->sout, http_content_type_gif );
|
||||
}
|
||||
else if( strncmp(http_jpg, ptr, 4) == 0 )
|
||||
{
|
||||
PSOCK_SEND_STR( &s->sout, http_content_type_jpg );
|
||||
}
|
||||
else
|
||||
{
|
||||
PSOCK_SEND_STR( &s->sout, http_content_type_plain );
|
||||
}
|
||||
|
||||
PSOCK_END( &s->sout );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( handle_output ( struct httpd_state *s ) )
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
PT_BEGIN( &s->outputpt );
|
||||
( void ) PT_YIELD_FLAG;
|
||||
if( !httpd_fs_open(s->filename, &s->file) )
|
||||
{
|
||||
httpd_fs_open( http_404_html, &s->file );
|
||||
strcpy( s->filename, http_404_html );
|
||||
PT_WAIT_THREAD( &s->outputpt, send_headers(s, http_header_404) );
|
||||
PT_WAIT_THREAD( &s->outputpt, send_file(s) );
|
||||
}
|
||||
else
|
||||
{
|
||||
PT_WAIT_THREAD( &s->outputpt, send_headers(s, http_header_200) );
|
||||
ptr = strchr( s->filename, ISO_period );
|
||||
if( ptr != NULL && strncmp(ptr, http_shtml, 6) == 0 )
|
||||
{
|
||||
PT_INIT( &s->scriptpt );
|
||||
PT_WAIT_THREAD( &s->outputpt, handle_script(s) );
|
||||
}
|
||||
else
|
||||
{
|
||||
PT_WAIT_THREAD( &s->outputpt, send_file(s) );
|
||||
}
|
||||
}
|
||||
|
||||
PSOCK_CLOSE( &s->sout );
|
||||
PT_END( &s->outputpt );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static PT_THREAD( handle_input ( struct httpd_state *s ) )
|
||||
{
|
||||
PSOCK_BEGIN( &s->sin );
|
||||
( void ) PT_YIELD_FLAG;
|
||||
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;
|
||||
|
||||
/* Process any form input being sent to the server. */
|
||||
#if UIP_CONF_PROCESS_HTTPD_FORMS == 1
|
||||
{
|
||||
extern void vApplicationProcessFormInput( char *pcInputString );
|
||||
vApplicationProcessFormInput( s->inputbuf );
|
||||
}
|
||||
#endif
|
||||
|
||||
strncpy( s->filename, &s->inputbuf[0], sizeof(s->filename) );
|
||||
}
|
||||
|
||||
/* httpd_log_file(uip_conn->ripaddr, 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;
|
||||
|
||||
/* httpd_log(&s->inputbuf[9]);*/
|
||||
}
|
||||
}
|
||||
|
||||
PSOCK_END( &s->sin );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void handle_connection( struct httpd_state *s )
|
||||
{
|
||||
handle_input( s );
|
||||
if( s->state == STATE_OUTPUT )
|
||||
{
|
||||
handle_output( s );
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void httpd_appcall( void )
|
||||
{
|
||||
struct httpd_state *s = ( struct httpd_state * ) &( uip_conn->appstate );
|
||||
|
||||
if( uip_closed() || uip_aborted() || uip_timedout() )
|
||||
{
|
||||
}
|
||||
else if( uip_connected() )
|
||||
{
|
||||
PSOCK_INIT( &s->sin, s->inputbuf, sizeof(s->inputbuf) - 1 );
|
||||
PSOCK_INIT( &s->sout, s->inputbuf, sizeof(s->inputbuf) - 1 );
|
||||
PT_INIT( &s->outputpt );
|
||||
s->state = STATE_WAITING;
|
||||
|
||||
/* timer_set(&s->timer, CLOCK_SECOND * 100);*/
|
||||
s->timer = 0;
|
||||
handle_connection( s );
|
||||
}
|
||||
else if( s != NULL )
|
||||
{
|
||||
if( uip_poll() )
|
||||
{
|
||||
++s->timer;
|
||||
if( s->timer >= 20 )
|
||||
{
|
||||
uip_abort();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
s->timer = 0;
|
||||
}
|
||||
|
||||
handle_connection( s );
|
||||
}
|
||||
else
|
||||
{
|
||||
uip_abort();
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* \brief Initialize the web server
|
||||
*
|
||||
* This function initializes the web server and should be
|
||||
* called at system boot-up.
|
||||
*/
|
||||
void httpd_init( void )
|
||||
{
|
||||
uip_listen( HTONS(80) );
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/** @} */
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2005, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the uIP TCP/IP stack.
|
||||
*
|
||||
* $Id: httpd.h,v 1.2 2006/06/11 21:46:38 adam Exp $
|
||||
*
|
||||
*/
|
||||
#ifndef __HTTPD_H__
|
||||
#define __HTTPD_H__
|
||||
|
||||
#include "net/psock.h"
|
||||
#include "httpd-fs.h"
|
||||
|
||||
struct httpd_state
|
||||
{
|
||||
unsigned char timer;
|
||||
struct psock sin, sout;
|
||||
struct pt outputpt, scriptpt;
|
||||
char inputbuf[50];
|
||||
char filename[20];
|
||||
char state;
|
||||
struct httpd_fs_file file;
|
||||
int len;
|
||||
char *scriptptr;
|
||||
int scriptlen;
|
||||
|
||||
unsigned short count;
|
||||
};
|
||||
|
||||
void httpd_init( void );
|
||||
void httpd_appcall( void );
|
||||
|
||||
void httpd_log( char *msg );
|
||||
void httpd_log_file( u16_t *requester, char *file );
|
||||
#endif /* __HTTPD_H__ */
|
@ -0,0 +1,78 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
open(OUTPUT, "> httpd-fsdata.c");
|
||||
|
||||
chdir("httpd-fs");
|
||||
|
||||
opendir(DIR, ".");
|
||||
@files = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);
|
||||
closedir(DIR);
|
||||
|
||||
foreach $file (@files) {
|
||||
|
||||
if(-d $file && $file !~ /^\./) {
|
||||
print "Processing directory $file\n";
|
||||
opendir(DIR, $file);
|
||||
@newfiles = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR);
|
||||
closedir(DIR);
|
||||
printf "Adding files @newfiles\n";
|
||||
@files = (@files, map { $_ = "$file/$_" } @newfiles);
|
||||
next;
|
||||
}
|
||||
}
|
||||
|
||||
foreach $file (@files) {
|
||||
if(-f $file) {
|
||||
|
||||
print "Adding file $file\n";
|
||||
|
||||
open(FILE, $file) || die "Could not open file $file\n";
|
||||
|
||||
$file =~ s-^-/-;
|
||||
$fvar = $file;
|
||||
$fvar =~ s-/-_-g;
|
||||
$fvar =~ s-\.-_-g;
|
||||
# for AVR, add PROGMEM here
|
||||
print(OUTPUT "static const unsigned char data".$fvar."[] = {\n");
|
||||
print(OUTPUT "\t/* $file */\n\t");
|
||||
for($j = 0; $j < length($file); $j++) {
|
||||
printf(OUTPUT "%#02x, ", unpack("C", substr($file, $j, 1)));
|
||||
}
|
||||
printf(OUTPUT "0,\n");
|
||||
|
||||
|
||||
$i = 0;
|
||||
while(read(FILE, $data, 1)) {
|
||||
if($i == 0) {
|
||||
print(OUTPUT "\t");
|
||||
}
|
||||
printf(OUTPUT "%#02x, ", unpack("C", $data));
|
||||
$i++;
|
||||
if($i == 10) {
|
||||
print(OUTPUT "\n");
|
||||
$i = 0;
|
||||
}
|
||||
}
|
||||
print(OUTPUT "0};\n\n");
|
||||
close(FILE);
|
||||
push(@fvars, $fvar);
|
||||
push(@pfiles, $file);
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 0; $i < @fvars; $i++) {
|
||||
$file = $pfiles[$i];
|
||||
$fvar = $fvars[$i];
|
||||
|
||||
if($i == 0) {
|
||||
$prevfile = "NULL";
|
||||
} else {
|
||||
$prevfile = "file" . $fvars[$i - 1];
|
||||
}
|
||||
print(OUTPUT "const struct httpd_fsdata_file file".$fvar."[] = {{$prevfile, data$fvar, ");
|
||||
print(OUTPUT "data$fvar + ". (length($file) + 1) .", ");
|
||||
print(OUTPUT "sizeof(data$fvar) - ". (length($file) + 1) ."}};\n\n");
|
||||
}
|
||||
|
||||
print(OUTPUT "#define HTTPD_FS_ROOT file$fvars[$i - 1]\n\n");
|
||||
print(OUTPUT "#define HTTPD_FS_NUMFILES $i\n");
|
Reference in New Issue
Block a user