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:
parent
2234c125f0
commit
bb61a8921c
File diff suppressed because it is too large
Load Diff
@ -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
@ -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 */
|
|
||||||
|
|
@ -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
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -54,7 +54,6 @@ else
|
|||||||
web_server : $(TARGET)
|
web_server : $(TARGET)
|
||||||
|
|
||||||
OBJ= \
|
OBJ= \
|
||||||
conn.o \
|
|
||||||
main.o \
|
main.o \
|
||||||
proc.o \
|
proc.o \
|
||||||
mime_types.o
|
mime_types.o
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
axhttpd is a small embedded web server using the axTLS library.
|
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:
|
It is based originally on the web server written by Doug Currie which is at:
|
||||||
http://www.hcsw.org/awhttpd).
|
http://www.hcsw.org/awhttpd.
|
||||||
|
|
||||||
|
@ -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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -107,7 +107,6 @@ extern struct cgiextstruct *cgiexts;
|
|||||||
extern char *webroot;
|
extern char *webroot;
|
||||||
|
|
||||||
// conn.c prototypes
|
// conn.c prototypes
|
||||||
void addconnection(int sd, char *ip, int is_ssl);
|
|
||||||
void removeconnection(struct connstruct *cn);
|
void removeconnection(struct connstruct *cn);
|
||||||
|
|
||||||
// proc.c prototypes
|
// proc.c prototypes
|
||||||
|
99
httpd/main.c
99
httpd/main.c
@ -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
|
* 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
|
* 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 void addtoservers(int sd);
|
||||||
static int openlistener(int port);
|
static int openlistener(int port);
|
||||||
static void handlenewconnection(int listenfd, int is_ssl);
|
static void handlenewconnection(int listenfd, int is_ssl);
|
||||||
|
static void addconnection(int sd, char *ip, int is_ssl);
|
||||||
#if defined(CONFIG_HTTP_PERM_CHECK)
|
#if defined(CONFIG_HTTP_PERM_CHECK)
|
||||||
static void procpermcheck(const char *pathtocheck);
|
static void procpermcheck(const char *pathtocheck);
|
||||||
#endif
|
#endif
|
||||||
@ -534,3 +535,99 @@ int isdir(const char *tpbuf)
|
|||||||
return 0;
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
111
httpd/proc.c
111
httpd/proc.c
@ -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
|
* 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
|
* 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_read(struct connstruct *cn, void *buf, size_t count);
|
||||||
static int special_write(struct connstruct *cn,
|
static int special_write(struct connstruct *cn,
|
||||||
const uint8_t *buf, size_t count);
|
const uint8_t *buf, size_t count);
|
||||||
static void send301(struct connstruct *cn);
|
|
||||||
static void send404(struct connstruct *cn);
|
static void send404(struct connstruct *cn);
|
||||||
static int procindex(struct connstruct *cn, struct stat *stp);
|
static int procindex(struct connstruct *cn, struct stat *stp);
|
||||||
static int hexit(char c);
|
static int hexit(char c);
|
||||||
@ -41,7 +40,6 @@ static int sanitizehost(char *buf);
|
|||||||
#if defined(CONFIG_HTTP_DIRECTORIES)
|
#if defined(CONFIG_HTTP_DIRECTORIES)
|
||||||
static void urlencode(const uint8_t *s, uint8_t *t);
|
static void urlencode(const uint8_t *s, uint8_t *t);
|
||||||
static void procdirlisting(struct connstruct *cn);
|
static void procdirlisting(struct connstruct *cn);
|
||||||
static int issockwriteable(int sd);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_HTTP_HAS_CGI)
|
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||||
static void proccgi(struct connstruct *cn, int has_pathinfo);
|
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)
|
if (sanitizefile(value) == 0)
|
||||||
{
|
{
|
||||||
|
printf("#3\n");
|
||||||
|
TTY_FLUSH();
|
||||||
send404(cn);
|
send404(cn);
|
||||||
removeconnection(cn);
|
removeconnection(cn);
|
||||||
return 0;
|
return 0;
|
||||||
@ -96,7 +96,7 @@ static int procheadelem(struct connstruct *cn, char *buf)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (strcmp(buf, "Host:")==0)
|
else if (strcmp(buf, "Host:") == 0)
|
||||||
{
|
{
|
||||||
if (sanitizehost(value) == 0)
|
if (sanitizehost(value) == 0)
|
||||||
{
|
{
|
||||||
@ -107,12 +107,11 @@ static int procheadelem(struct connstruct *cn, char *buf)
|
|||||||
|
|
||||||
my_strncpy(cn->virtualhostreq, value, MAXREQUESTLENGTH);
|
my_strncpy(cn->virtualhostreq, value, MAXREQUESTLENGTH);
|
||||||
}
|
}
|
||||||
else if (strcmp(buf, "Connection:")==0 &&
|
else if (strcmp(buf, "Connection:") == 0 && strcmp(value, "close") == 0)
|
||||||
strcmp(value, "close")==0)
|
|
||||||
{
|
{
|
||||||
cn->close_when_done = 1;
|
cn->close_when_done = 1;
|
||||||
}
|
}
|
||||||
else if (strcmp(buf, "If-Modified-Since:") ==0 )
|
else if (strcmp(buf, "If-Modified-Since:") == 0)
|
||||||
{
|
{
|
||||||
/* TODO: parse this date properly with getdate() or similar */
|
/* TODO: parse this date properly with getdate() or similar */
|
||||||
cn->modified_since = 1;
|
cn->modified_since = 1;
|
||||||
@ -161,8 +160,8 @@ static void procdirlisting(struct connstruct *cn)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\nContent-Type: text/html\n\n"
|
snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\nContent-Type: text/html\n\n"
|
||||||
"<HTML><BODY>\n<TITLE>Directory Listing</TITLE>\n"
|
"<html><body>\n<title>Directory Listing</title>\n"
|
||||||
"<H2>Directory listing of %s://%s%s</H2><BR>\n",
|
"<h3>Directory listing of %s://%s%s</h3><br />\n",
|
||||||
cn->is_ssl ? "https" : "http", cn->virtualhostreq, cn->filereq);
|
cn->is_ssl ? "https" : "http", cn->virtualhostreq, cn->filereq);
|
||||||
special_write(cn, buf, strlen(buf));
|
special_write(cn, buf, strlen(buf));
|
||||||
cn->state = STATE_DOING_DIR;
|
cn->state = STATE_DOING_DIR;
|
||||||
@ -175,18 +174,19 @@ void procdodir(struct connstruct *cn)
|
|||||||
#endif
|
#endif
|
||||||
char buf[MAXREQUESTLENGTH];
|
char buf[MAXREQUESTLENGTH];
|
||||||
char encbuf[1024];
|
char encbuf[1024];
|
||||||
int putslash;
|
|
||||||
char *file;
|
char *file;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
buf[0] = 0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if (!FindNextFile(cn->dirp, &cn->file_data))
|
if (!FindNextFile(cn->dirp, &cn->file_data))
|
||||||
#else
|
#else
|
||||||
if ((dp = readdir(cn->dirp)) == NULL)
|
if ((dp = readdir(cn->dirp)) == NULL)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "</BODY></HTML>\n");
|
snprintf(buf, sizeof(buf), "</body></html>\n");
|
||||||
special_write(cn, buf, strlen(buf));
|
special_write(cn, buf, strlen(buf));
|
||||||
removeconnection(cn);
|
removeconnection(cn);
|
||||||
return;
|
return;
|
||||||
@ -198,31 +198,23 @@ void procdodir(struct connstruct *cn)
|
|||||||
file = dp->d_name;
|
file = dp->d_name;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// if no index file, don't display the ".." directory
|
||||||
if (cn->filereq[0] == '/' && cn->filereq[1] == '\0' &&
|
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);
|
snprintf(buf, sizeof(buf), "%s%s", cn->actualfile, file);
|
||||||
putslash = isdir(buf);
|
if (isdir(buf))
|
||||||
|
strcat(file, "/");
|
||||||
urlencode(file, encbuf);
|
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)
|
snprintf(buf, sizeof(buf), "<a href=\"%s%s\">%s</a><br />\n",
|
||||||
{
|
cn->filereq, encbuf, file);
|
||||||
fd_set wfds;
|
} while (special_write(cn, buf, strlen(buf)));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encode funny chars -> %xx in newly allocated storage */
|
/* 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 ((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
|
// Check to see if this dir has an index file
|
||||||
if (procindex(cn, &stbuf) == 0)
|
if (procindex(cn, &stbuf) == 0)
|
||||||
{
|
{
|
||||||
@ -394,11 +379,11 @@ void procsendhead(struct connstruct *cn)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// If the index isn't a CGI, we continue on with the index file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cn->modified_since)
|
if (cn->modified_since)
|
||||||
{
|
{
|
||||||
|
// file has already been read before
|
||||||
snprintf(buf, sizeof(buf), "HTTP/1.1 304 Not Modified\nServer: "
|
snprintf(buf, sizeof(buf), "HTTP/1.1 304 Not Modified\nServer: "
|
||||||
"axhttpd V%s\nDate: %s\n", VERSION, date);
|
"axhttpd V%s\nDate: %s\n", VERSION, date);
|
||||||
special_write(cn, buf, strlen(buf));
|
special_write(cn, buf, strlen(buf));
|
||||||
@ -406,20 +391,18 @@ void procsendhead(struct connstruct *cn)
|
|||||||
cn->state = STATE_WANT_TO_READ_HEAD;
|
cn->state = STATE_WANT_TO_READ_HEAD;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_HTTP_VERBOSE
|
#ifdef CONFIG_HTTP_VERBOSE
|
||||||
printf("axhttpd: %s send %s\n",
|
printf("axhttpd: %s send %s\n",
|
||||||
cn->is_ssl ? "https" : "http", cn->actualfile);
|
cn->is_ssl ? "https" : "http", cn->actualfile);
|
||||||
TTY_FLUSH();
|
TTY_FLUSH();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\nServer: axhttpd V%s\n"
|
snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\nServer: axhttpd V%s\n"
|
||||||
"Content-Type: %s\nContent-Length: %ld\n"
|
"Content-Type: %s\nContent-Length: %ld\n"
|
||||||
"Date: %sLast-Modified: %s\n", VERSION,
|
"Date: %sLast-Modified: %s\n", VERSION,
|
||||||
getmimetype(cn->actualfile), (long) stbuf.st_size,
|
getmimetype(cn->actualfile), (long) stbuf.st_size,
|
||||||
date, ctime(&(stbuf.st_mtime))); // ctime() has a \n on the end
|
date, ctime(&(stbuf.st_mtime))); // ctime() has a \n on the end
|
||||||
}
|
|
||||||
|
|
||||||
special_write(cn, buf, strlen(buf));
|
special_write(cn, buf, strlen(buf));
|
||||||
|
|
||||||
@ -801,25 +784,12 @@ static int hexit(char c)
|
|||||||
return 0;
|
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)
|
static void send404(struct connstruct *cn)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
strcpy(buf, "HTTP/1.0 404 Not Found\nContent-Type: text/html\n\n"
|
strcpy(buf, "HTTP/1.0 404 Not Found\nContent-Type: text/html\n\n"
|
||||||
"<HTML><BODY>\n<TITLE>404 Not Found</TITLE><H1>"
|
"<html><body>\n<title>404 Not Found</title><h1>"
|
||||||
"404 Not Found</H1>\n</BODY></HTML>\n");
|
"404 Not Found</h1>\n</body></html>\n");
|
||||||
special_write(cn, buf, strlen(buf));
|
special_write(cn, buf, strlen(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -856,7 +826,6 @@ static int sanitizefile(const char *buf)
|
|||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
// Check for "/." : In other words, don't send files starting with a .
|
// Check for "/." : In other words, don't send files starting with a .
|
||||||
// Notice, GOBBLES, that this includes ".."
|
|
||||||
if (buf[i] == '/' && buf[i+1] == '.')
|
if (buf[i] == '/' && buf[i+1] == '.')
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -876,10 +845,12 @@ static int sanitizehost(char *buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enforce some basic URL rules...
|
// Enforce some basic URL rules...
|
||||||
if (isalnum(*buf)==0 && *buf != '-' && *buf != '.') return 0;
|
if ((isalnum(*buf) == 0 && *buf != '-' && *buf != '.') ||
|
||||||
if (*buf == '.' && *(buf+1) == '.') return 0;
|
(*buf == '.' && *(buf+1) == '.') ||
|
||||||
if (*buf == '.' && *(buf+1) == '-') return 0;
|
(*buf == '.' && *(buf+1) == '-') ||
|
||||||
if (*buf == '-' && *(buf+1) == '.') return 0;
|
(*buf == '-' && *(buf+1) == '.'))
|
||||||
|
return 0;
|
||||||
|
|
||||||
buf++;
|
buf++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
# 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
|
# it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
12
ssl/bigint.c
12
ssl/bigint.c
@ -285,7 +285,7 @@ bigint *bi_add(BI_CTX *ctx, bigint *bia, bigint *bib)
|
|||||||
* @param bia [in] A bigint.
|
* @param bia [in] A bigint.
|
||||||
* @param bib [in] Another bigint.
|
* @param bib [in] Another bigint.
|
||||||
* @param is_negative [out] If defined, indicates that the result was negative.
|
* @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.
|
* @return The result of the subtraction. The result is always positive.
|
||||||
*/
|
*/
|
||||||
bigint *bi_subtract(BI_CTX *ctx,
|
bigint *bi_subtract(BI_CTX *ctx,
|
||||||
@ -1059,7 +1059,7 @@ static bigint *alloc(BI_CTX *ctx, int size)
|
|||||||
#ifdef CONFIG_SSL_FULL_MODE
|
#ifdef CONFIG_SSL_FULL_MODE
|
||||||
printf("alloc: refs was not 0\n");
|
printf("alloc: refs was not 0\n");
|
||||||
#endif
|
#endif
|
||||||
abort();
|
abort(); /* create a stack trace from a core dump */
|
||||||
}
|
}
|
||||||
|
|
||||||
more_comps(biR, size);
|
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
|
* Barrett reduction has no need for some parts of the product, so ignore bits
|
||||||
* of the multiply. This routine gives Barrett its big performance
|
* 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,
|
static bigint *partial_multiply(BI_CTX *ctx, bigint *bia, bigint *bib,
|
||||||
int inner_partial, int outer_partial)
|
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 ctx [in] The bigint session context.
|
||||||
* @param bi [in] A bigint.
|
* @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)
|
bigint *bi_barrett(BI_CTX *ctx, bigint *bi)
|
||||||
{
|
{
|
||||||
@ -1308,7 +1308,7 @@ bigint *bi_barrett(BI_CTX *ctx, bigint *bi)
|
|||||||
check(bi);
|
check(bi);
|
||||||
check(bim);
|
check(bim);
|
||||||
|
|
||||||
/* use classical method instead - Barrett cannot help here */
|
/* use Classical method instead - Barrett cannot help here */
|
||||||
if (bi->size > k*2)
|
if (bi->size > k*2)
|
||||||
{
|
{
|
||||||
return bi_mod(ctx, bi);
|
return bi_mod(ctx, bi);
|
||||||
|
@ -70,7 +70,7 @@ void buf_grow(BUF_MEM *bm, int len)
|
|||||||
/* add 1kB just to be sure */
|
/* add 1kB just to be sure */
|
||||||
bm->pre_data = (uint8_t *)realloc(bm->pre_data, len+1024+BM_RECORD_OFFSET);
|
bm->pre_data = (uint8_t *)realloc(bm->pre_data, len+1024+BM_RECORD_OFFSET);
|
||||||
bm->data = bm->pre_data+BM_RECORD_OFFSET;
|
bm->data = bm->pre_data+BM_RECORD_OFFSET;
|
||||||
bm->max_len = len+1024;
|
bm->max_len = len + 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -769,7 +769,7 @@ static void prf(const uint8_t *sec, int sec_len, uint8_t *seed, int seed_len,
|
|||||||
len = sec_len/2;
|
len = sec_len/2;
|
||||||
S1 = sec;
|
S1 = sec;
|
||||||
S2 = &sec[len];
|
S2 = &sec[len];
|
||||||
len += (sec_len&1); /* add for odd, make longer */
|
len += (sec_len & 1); /* add for odd, make longer */
|
||||||
|
|
||||||
p_hash_md5(S1, len, seed, seed_len, xbuf, olen);
|
p_hash_md5(S1, len, seed, seed_len, xbuf, olen);
|
||||||
p_hash_sha1(S2, len, seed, seed_len, ybuf, olen);
|
p_hash_sha1(S2, len, seed, seed_len, ybuf, olen);
|
||||||
@ -842,6 +842,7 @@ void finished_digest(SSL *ssl, const char *label, uint8_t *digest)
|
|||||||
{
|
{
|
||||||
memcpy(digest, mac_buf, MD5_SIZE + SHA1_SIZE);
|
memcpy(digest, mac_buf, MD5_SIZE + SHA1_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
printf("label: %s\n", label);
|
printf("label: %s\n", label);
|
||||||
print_blob("master secret", ssl->master_secret, 48);
|
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 ret = SSL_OK;
|
||||||
int read_len, is_record;
|
int read_len, is_record;
|
||||||
uint8_t *buf = ssl->bm_buf.data;
|
|
||||||
int is_client = IS_SET_SSL_FLAG(SSL_IS_CLIENT);
|
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],
|
read_len = SOCKET_READ(ssl->client_fd, &buf[ssl->bm_buf.index],
|
||||||
ssl->need_bytes-ssl->got_bytes);
|
ssl->need_bytes-ssl->got_bytes);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user