1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

more axhttpd work

git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@55 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
cameronrich 2007-01-24 08:41:30 +00:00
parent 2234c125f0
commit bb61a8921c
14 changed files with 157 additions and 6071 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,40 +0,0 @@
/* confdata.c */
#define conf_parse (*conf_parse_p)
#define conf_read (*conf_read_p)
#define conf_write (*conf_write_p)
/* menu.c */
#define rootmenu (*rootmenu_p)
#define menu_is_visible (*menu_is_visible_p)
#define menu_get_prompt (*menu_get_prompt_p)
#define menu_get_root_menu (*menu_get_root_menu_p)
#define menu_get_parent_menu (*menu_get_parent_menu_p)
/* symbol.c */
#define symbol_hash (*symbol_hash_p)
#define sym_change_count (*sym_change_count_p)
#define sym_lookup (*sym_lookup_p)
#define sym_find (*sym_find_p)
#define sym_re_search (*sym_re_search_p)
#define sym_type_name (*sym_type_name_p)
#define sym_calc_value (*sym_calc_value_p)
#define sym_get_type (*sym_get_type_p)
#define sym_tristate_within_range (*sym_tristate_within_range_p)
#define sym_set_tristate_value (*sym_set_tristate_value_p)
#define sym_toggle_tristate_value (*sym_toggle_tristate_value_p)
#define sym_string_valid (*sym_string_valid_p)
#define sym_string_within_range (*sym_string_within_range_p)
#define sym_set_string_value (*sym_set_string_value_p)
#define sym_is_changable (*sym_is_changable_p)
#define sym_get_choice_prop (*sym_get_choice_prop_p)
#define sym_get_default_prop (*sym_get_default_prop_p)
#define sym_get_string_value (*sym_get_string_value_p)
#define prop_get_type_name (*prop_get_type_name_p)
/* expr.c */
#define expr_compare_type (*expr_compare_type_p)
#define expr_print (*expr_print_p)

File diff suppressed because it is too large Load Diff

View File

@ -1,125 +0,0 @@
/* A Bison parser, made from zconf.y, by GNU bison 1.75. */
/* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, when this file is copied by Bison into a
Bison output file, you may use that output file without restriction.
This special exception was added by the Free Software Foundation
in version 1.24 of Bison. */
#ifndef BISON_ZCONF_TAB_H
# define BISON_ZCONF_TAB_H
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
T_MAINMENU = 258,
T_MENU = 259,
T_ENDMENU = 260,
T_SOURCE = 261,
T_CHOICE = 262,
T_ENDCHOICE = 263,
T_COMMENT = 264,
T_CONFIG = 265,
T_HELP = 266,
T_HELPTEXT = 267,
T_IF = 268,
T_ENDIF = 269,
T_DEPENDS = 270,
T_REQUIRES = 271,
T_OPTIONAL = 272,
T_PROMPT = 273,
T_DEFAULT = 274,
T_TRISTATE = 275,
T_BOOLEAN = 276,
T_INT = 277,
T_HEX = 278,
T_WORD = 279,
T_STRING = 280,
T_UNEQUAL = 281,
T_EOF = 282,
T_EOL = 283,
T_CLOSE_PAREN = 284,
T_OPEN_PAREN = 285,
T_ON = 286,
T_OR = 287,
T_AND = 288,
T_EQUAL = 289,
T_NOT = 290
};
#endif
#define T_MAINMENU 258
#define T_MENU 259
#define T_ENDMENU 260
#define T_SOURCE 261
#define T_CHOICE 262
#define T_ENDCHOICE 263
#define T_COMMENT 264
#define T_CONFIG 265
#define T_HELP 266
#define T_HELPTEXT 267
#define T_IF 268
#define T_ENDIF 269
#define T_DEPENDS 270
#define T_REQUIRES 271
#define T_OPTIONAL 272
#define T_PROMPT 273
#define T_DEFAULT 274
#define T_TRISTATE 275
#define T_BOOLEAN 276
#define T_INT 277
#define T_HEX 278
#define T_WORD 279
#define T_STRING 280
#define T_UNEQUAL 281
#define T_EOF 282
#define T_EOL 283
#define T_CLOSE_PAREN 284
#define T_OPEN_PAREN 285
#define T_ON 286
#define T_OR 287
#define T_AND 288
#define T_EQUAL 289
#define T_NOT 290
#ifndef YYSTYPE
#line 33 "zconf.y"
typedef union {
int token;
char *string;
struct symbol *symbol;
struct expr *expr;
struct menu *menu;
} yystype;
/* Line 1281 of /usr/share/bison/yacc.c. */
#line 118 "zconf.tab.h"
# define YYSTYPE yystype
#endif
extern YYSTYPE zconflval;
#endif /* not BISON_ZCONF_TAB_H */

View File

@ -1,5 +1,5 @@
#
# Copyright(C) 2006 Cameron Rich
# Copyright(C) 2007 Cameron Rich
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -54,7 +54,6 @@ else
web_server : $(TARGET)
OBJ= \
conn.o \
main.o \
proc.o \
mime_types.o

View File

@ -1,6 +1,6 @@
axhttpd is a small embedded web server using the axTLS library.
It is based originally on the web server written by Doug Currie and is at:
http://www.hcsw.org/awhttpd).
It is based originally on the web server written by Doug Currie which is at:
http://www.hcsw.org/awhttpd.

View File

@ -1,5 +1,5 @@
/*
* Copyright(C) 2006 Cameron Rich
* Copyright(C) 2007 Cameron Rich
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -107,7 +107,6 @@ extern struct cgiextstruct *cgiexts;
extern char *webroot;
// conn.c prototypes
void addconnection(int sd, char *ip, int is_ssl);
void removeconnection(struct connstruct *cn);
// proc.c prototypes

View File

@ -1,5 +1,5 @@
/*
* Copyright(C) 2006 Cameron Rich
* Copyright(C) 2007 Cameron Rich
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,6 +33,7 @@ char *webroot = CONFIG_HTTP_WEBROOT;
static void addtoservers(int sd);
static int openlistener(int port);
static void handlenewconnection(int listenfd, int is_ssl);
static void addconnection(int sd, char *ip, int is_ssl);
#if defined(CONFIG_HTTP_PERM_CHECK)
static void procpermcheck(const char *pathtocheck);
#endif
@ -534,3 +535,99 @@ int isdir(const char *tpbuf)
return 0;
}
static void addconnection(int sd, char *ip, int is_ssl)
{
struct connstruct *tp;
// Get ourselves a connstruct
if (freeconns == NULL)
tp = (struct connstruct *)malloc(sizeof(struct connstruct));
else
{
tp = freeconns;
freeconns = tp->next;
}
// Attach it to the used list
tp->next = usedconns;
usedconns = tp;
tp->networkdesc = sd;
if (is_ssl)
ssl_server_new(servers->ssl_ctx, sd);
tp->is_ssl = is_ssl;
tp->filedesc = -1;
#if defined(CONFIG_HTTP_HAS_DIRECTORIES)
tp->dirp = NULL;
#endif
*(tp->actualfile) = '\0';
*(tp->filereq) = '\0';
#if defined(CONFIG_HTTP_HAS_CGI)
*(tp->cgiargs) = '\0';
#endif
*(tp->virtualhostreq) = '\0';
tp->state = STATE_WANT_TO_READ_HEAD;
tp->reqtype = TYPE_GET;
my_strncpy(tp->ip, ip, MAXIPLEN);
tp->close_when_done = 0;
tp->modified_since = 0;
tp->timeout = time(NULL) + CONFIG_HTTP_TIMEOUT;
}
void removeconnection(struct connstruct *cn)
{
struct connstruct *tp;
int shouldret = 0;
tp = usedconns;
if (tp == NULL || cn == NULL)
shouldret = 1;
else if (tp == cn)
usedconns = tp->next;
else
{
while (tp != NULL)
{
if (tp->next == cn)
{
tp->next = (tp->next)->next;
shouldret = 0;
break;
}
tp = tp->next;
shouldret = 1;
}
}
if (shouldret)
return;
// If we did, add it to the free list
cn->next = freeconns;
freeconns = cn;
// Close it all down
if (cn->networkdesc != -1)
{
if (cn->is_ssl)
ssl_free(ssl_find(servers->ssl_ctx, cn->networkdesc));
SOCKET_CLOSE(cn->networkdesc);
}
if (cn->filedesc != -1)
close(cn->filedesc);
#if defined(CONFIG_HTTP_HAS_DIRECTORIES)
if (cn->dirp != NULL)
#ifdef WIN32
FindClose(cn->dirp);
#else
closedir(cn->dirp);
#endif
#endif
}

View File

@ -1,5 +1,5 @@
/*
* Copyright(C) 2006 Cameron Rich
* Copyright(C) 2007 Cameron Rich
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -1,5 +1,5 @@
/*
* Copyright(C) 2006 Cameron Rich
* Copyright(C) 2007 Cameron Rich
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -29,7 +29,6 @@
static int special_read(struct connstruct *cn, void *buf, size_t count);
static int special_write(struct connstruct *cn,
const uint8_t *buf, size_t count);
static void send301(struct connstruct *cn);
static void send404(struct connstruct *cn);
static int procindex(struct connstruct *cn, struct stat *stp);
static int hexit(char c);
@ -41,7 +40,6 @@ static int sanitizehost(char *buf);
#if defined(CONFIG_HTTP_DIRECTORIES)
static void urlencode(const uint8_t *s, uint8_t *t);
static void procdirlisting(struct connstruct *cn);
static int issockwriteable(int sd);
#endif
#if defined(CONFIG_HTTP_HAS_CGI)
static void proccgi(struct connstruct *cn, int has_pathinfo);
@ -81,6 +79,8 @@ static int procheadelem(struct connstruct *cn, char *buf)
if (sanitizefile(value) == 0)
{
printf("#3\n");
TTY_FLUSH();
send404(cn);
removeconnection(cn);
return 0;
@ -107,8 +107,7 @@ static int procheadelem(struct connstruct *cn, char *buf)
my_strncpy(cn->virtualhostreq, value, MAXREQUESTLENGTH);
}
else if (strcmp(buf, "Connection:")==0 &&
strcmp(value, "close")==0)
else if (strcmp(buf, "Connection:") == 0 && strcmp(value, "close") == 0)
{
cn->close_when_done = 1;
}
@ -161,8 +160,8 @@ static void procdirlisting(struct connstruct *cn)
#endif
snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\nContent-Type: text/html\n\n"
"<HTML><BODY>\n<TITLE>Directory Listing</TITLE>\n"
"<H2>Directory listing of %s://%s%s</H2><BR>\n",
"<html><body>\n<title>Directory Listing</title>\n"
"<h3>Directory listing of %s://%s%s</h3><br />\n",
cn->is_ssl ? "https" : "http", cn->virtualhostreq, cn->filereq);
special_write(cn, buf, strlen(buf));
cn->state = STATE_DOING_DIR;
@ -175,18 +174,19 @@ void procdodir(struct connstruct *cn)
#endif
char buf[MAXREQUESTLENGTH];
char encbuf[1024];
int putslash;
char *file;
do
{
buf[0] = 0;
#ifdef WIN32
if (!FindNextFile(cn->dirp, &cn->file_data))
#else
if ((dp = readdir(cn->dirp)) == NULL)
#endif
{
snprintf(buf, sizeof(buf), "</BODY></HTML>\n");
snprintf(buf, sizeof(buf), "</body></html>\n");
special_write(cn, buf, strlen(buf));
removeconnection(cn);
return;
@ -198,31 +198,23 @@ void procdodir(struct connstruct *cn)
file = dp->d_name;
#endif
// if no index file, don't display the ".." directory
if (cn->filereq[0] == '/' && cn->filereq[1] == '\0' &&
strcmp(file, "..") == 0) continue;
strcmp(file, "..") == 0)
continue;
// don't display files beginning with "."
if (file[0] == '.' && file[1] != '.')
continue;
snprintf(buf, sizeof(buf), "%s%s", cn->actualfile, file);
putslash = isdir(buf);
if (isdir(buf))
strcat(file, "/");
urlencode(file, encbuf);
snprintf(buf, sizeof(buf), "<A HREF=\"%s%s\">%s%s</A><BR>\n",
encbuf, putslash ? "/" : "", file, putslash ? "/" : "");
special_write(cn, buf, strlen(buf));
} while (issockwriteable(cn->networkdesc));
}
static int issockwriteable(int sd)
{
fd_set wfds;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&wfds);
FD_SET(sd, &wfds);
select(FD_SETSIZE, NULL, &wfds, NULL, &tv);
return FD_ISSET(sd, &wfds);
snprintf(buf, sizeof(buf), "<a href=\"%s%s\">%s</a><br />\n",
cn->filereq, encbuf, file);
} while (special_write(cn, buf, strlen(buf)));
}
/* Encode funny chars -> %xx in newly allocated storage */
@ -358,13 +350,6 @@ void procsendhead(struct connstruct *cn)
if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
{
if (cn->filereq[strlen(cn->filereq)-1] != '/')
{
send301(cn);
removeconnection(cn);
return;
}
// Check to see if this dir has an index file
if (procindex(cn, &stbuf) == 0)
{
@ -394,11 +379,11 @@ void procsendhead(struct connstruct *cn)
return;
}
#endif
// If the index isn't a CGI, we continue on with the index file
}
if (cn->modified_since)
{
// file has already been read before
snprintf(buf, sizeof(buf), "HTTP/1.1 304 Not Modified\nServer: "
"axhttpd V%s\nDate: %s\n", VERSION, date);
special_write(cn, buf, strlen(buf));
@ -406,8 +391,7 @@ void procsendhead(struct connstruct *cn)
cn->state = STATE_WANT_TO_READ_HEAD;
return;
}
else
{
#ifdef CONFIG_HTTP_VERBOSE
printf("axhttpd: %s send %s\n",
cn->is_ssl ? "https" : "http", cn->actualfile);
@ -419,7 +403,6 @@ void procsendhead(struct connstruct *cn)
"Date: %sLast-Modified: %s\n", VERSION,
getmimetype(cn->actualfile), (long) stbuf.st_size,
date, ctime(&(stbuf.st_mtime))); // ctime() has a \n on the end
}
special_write(cn, buf, strlen(buf));
@ -801,25 +784,12 @@ static int hexit(char c)
return 0;
}
static void send301(struct connstruct *cn)
{
char buf[2048];
snprintf(buf, sizeof(buf),
"HTTP/1.1 301 Moved Permanently\nLocation: %s/\n\n"
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
"<HTML><HEAD>\n<TITLE>301 Moved Permanently</TITLE>\n"
"</HEAD><BODY>\n<H1>Moved Permanently</H1>\n"
"The document has moved <A HREF=\"%s/\">here</A>.<P>\n"
"<HR>\n</BODY></HTML>\n", cn->filereq, cn->filereq);
special_write(cn, buf, strlen(buf));
}
static void send404(struct connstruct *cn)
{
char buf[1024];
strcpy(buf, "HTTP/1.0 404 Not Found\nContent-Type: text/html\n\n"
"<HTML><BODY>\n<TITLE>404 Not Found</TITLE><H1>"
"404 Not Found</H1>\n</BODY></HTML>\n");
"<html><body>\n<title>404 Not Found</title><h1>"
"404 Not Found</h1>\n</body></html>\n");
special_write(cn, buf, strlen(buf));
}
@ -856,7 +826,6 @@ static int sanitizefile(const char *buf)
for (i = 0; i < len; i++)
{
// Check for "/." : In other words, don't send files starting with a .
// Notice, GOBBLES, that this includes ".."
if (buf[i] == '/' && buf[i+1] == '.')
return 0;
}
@ -876,10 +845,12 @@ static int sanitizehost(char *buf)
}
// Enforce some basic URL rules...
if (isalnum(*buf)==0 && *buf != '-' && *buf != '.') return 0;
if (*buf == '.' && *(buf+1) == '.') return 0;
if (*buf == '.' && *(buf+1) == '-') return 0;
if (*buf == '-' && *(buf+1) == '.') return 0;
if ((isalnum(*buf) == 0 && *buf != '-' && *buf != '.') ||
(*buf == '.' && *(buf+1) == '.') ||
(*buf == '.' && *(buf+1) == '-') ||
(*buf == '-' && *(buf+1) == '.'))
return 0;
buf++;
}

View File

@ -1,5 +1,5 @@
#
# Copyright(C) 2006 Cameron Rich
# Copyright(C) 2007 Cameron Rich
#
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by

View File

@ -285,7 +285,7 @@ bigint *bi_add(BI_CTX *ctx, bigint *bia, bigint *bib)
* @param bia [in] A bigint.
* @param bib [in] Another bigint.
* @param is_negative [out] If defined, indicates that the result was negative.
* is_negative may be NULL.
* is_negative may be null.
* @return The result of the subtraction. The result is always positive.
*/
bigint *bi_subtract(BI_CTX *ctx,
@ -1059,7 +1059,7 @@ static bigint *alloc(BI_CTX *ctx, int size)
#ifdef CONFIG_SSL_FULL_MODE
printf("alloc: refs was not 0\n");
#endif
abort();
abort(); /* create a stack trace from a core dump */
}
more_comps(biR, size);
@ -1220,7 +1220,7 @@ static bigint *comp_mod(bigint *bi, int mod)
/*
* Barrett reduction has no need for some parts of the product, so ignore bits
* of the multiply. This routine gives Barrett its big performance
* improvements over classical/Montgomery reduction methods.
* improvements over Classical/Montgomery reduction methods.
*/
static bigint *partial_multiply(BI_CTX *ctx, bigint *bia, bigint *bib,
int inner_partial, int outer_partial)
@ -1293,10 +1293,10 @@ static bigint *partial_multiply(BI_CTX *ctx, bigint *bia, bigint *bib,
}
/**
* @brief Perform a single barrett reduction.
* @brief Perform a single Barrett reduction.
* @param ctx [in] The bigint session context.
* @param bi [in] A bigint.
* @return The result of the barrett reduction.
* @return The result of the Barrett reduction.
*/
bigint *bi_barrett(BI_CTX *ctx, bigint *bi)
{
@ -1308,7 +1308,7 @@ bigint *bi_barrett(BI_CTX *ctx, bigint *bi)
check(bi);
check(bim);
/* use classical method instead - Barrett cannot help here */
/* use Classical method instead - Barrett cannot help here */
if (bi->size > k*2)
{
return bi_mod(ctx, bi);

View File

@ -842,6 +842,7 @@ void finished_digest(SSL *ssl, const char *label, uint8_t *digest)
{
memcpy(digest, mac_buf, MD5_SIZE + SHA1_SIZE);
}
#if 0
printf("label: %s\n", label);
print_blob("master secret", ssl->master_secret, 48);
@ -1121,9 +1122,11 @@ int basic_read(SSL *ssl, uint8_t **in_data)
{
int ret = SSL_OK;
int read_len, is_record;
uint8_t *buf = ssl->bm_buf.data;
int is_client = IS_SET_SSL_FLAG(SSL_IS_CLIENT);
uint8_t *buf;
buf_grow(&ssl->bm_buf, ssl->need_bytes);
buf = ssl->bm_buf.data;
read_len = SOCKET_READ(ssl->client_fd, &buf[ssl->bm_buf.index],
ssl->need_bytes-ssl->got_bytes);