mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-12 01:53:07 +03:00
cgi file uploads now work above 1kB in size
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@157 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
@ -36,8 +36,10 @@
|
|||||||
#define HAVE_IPV6
|
#define HAVE_IPV6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAXPOSTDATASIZE 30000
|
#define MAXPOSTDATASIZE 30000 /* adjust for file upload
|
||||||
|
size*/
|
||||||
#define MAXREQUESTLENGTH 256
|
#define MAXREQUESTLENGTH 256
|
||||||
|
#define MAXREADLENGTH 8800 /* FF3=4096, IE7=8760 */
|
||||||
#define BLOCKSIZE 4096
|
#define BLOCKSIZE 4096
|
||||||
|
|
||||||
#define INITIAL_CONNECTION_SLOTS 10
|
#define INITIAL_CONNECTION_SLOTS 10
|
||||||
@ -87,6 +89,7 @@ struct connstruct
|
|||||||
|
|
||||||
#if defined(CONFIG_HTTP_HAS_CGI)
|
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||||
uint8_t is_cgi;
|
uint8_t is_cgi;
|
||||||
|
char cgicontenttype[MAXREQUESTLENGTH];
|
||||||
#ifdef CONFIG_HTTP_ENABLE_LUA
|
#ifdef CONFIG_HTTP_ENABLE_LUA
|
||||||
uint8_t is_lua;
|
uint8_t is_lua;
|
||||||
#endif
|
#endif
|
||||||
|
50
httpd/proc.c
50
httpd/proc.c
@ -159,6 +159,10 @@ static int procheadelem(struct connstruct *cn, char *buf)
|
|||||||
{
|
{
|
||||||
sscanf(value, "%d", &cn->content_length);
|
sscanf(value, "%d", &cn->content_length);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(buf, "Content-Type:") == 0)
|
||||||
|
{
|
||||||
|
my_strncpy(cn->cgicontenttype, value, MAXREQUESTLENGTH);
|
||||||
|
}
|
||||||
else if (strcmp(buf, "Cookie:") == 0)
|
else if (strcmp(buf, "Cookie:") == 0)
|
||||||
{
|
{
|
||||||
my_strncpy(cn->cookie, value, MAXREQUESTLENGTH);
|
my_strncpy(cn->cookie, value, MAXREQUESTLENGTH);
|
||||||
@ -301,10 +305,10 @@ static void urlencode(const uint8_t *s, char *t)
|
|||||||
|
|
||||||
void procreadhead(struct connstruct *cn)
|
void procreadhead(struct connstruct *cn)
|
||||||
{
|
{
|
||||||
char buf[MAXREQUESTLENGTH*4], *tp, *next;
|
char buf[MAXREADLENGTH], *tp, *next;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
memset(buf, 0, MAXREQUESTLENGTH*4);
|
memset(buf, 0, sizeof(buf));
|
||||||
rv = special_read(cn, buf, sizeof(buf)-1);
|
rv = special_read(cn, buf, sizeof(buf)-1);
|
||||||
if (rv <= 0)
|
if (rv <= 0)
|
||||||
{
|
{
|
||||||
@ -390,7 +394,6 @@ void procsendhead(struct connstruct *cn)
|
|||||||
file_exists = stat(cn->actualfile, &stbuf);
|
file_exists = stat(cn->actualfile, &stbuf);
|
||||||
|
|
||||||
#if defined(CONFIG_HTTP_HAS_CGI)
|
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||||
|
|
||||||
if (file_exists != -1 && cn->is_cgi)
|
if (file_exists != -1 && cn->is_cgi)
|
||||||
{
|
{
|
||||||
if ((stbuf.st_mode & S_IEXEC) == 0 || isdir(cn->actualfile))
|
if ((stbuf.st_mode & S_IEXEC) == 0 || isdir(cn->actualfile))
|
||||||
@ -669,13 +672,15 @@ static void proccgi(struct connstruct *cn)
|
|||||||
type = "GET";
|
type = "GET";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||||
case TYPE_POST:
|
case TYPE_POST:
|
||||||
type = "POST";
|
type = "POST";
|
||||||
sprintf(cgienv[cgi_index++],
|
sprintf(cgienv[cgi_index++],
|
||||||
"CONTENT_LENGTH=%d", cn->content_length);
|
"CONTENT_LENGTH=%d", cn->content_length);
|
||||||
strcpy(cgienv[cgi_index++], /* hard-code? */
|
snprintf(cgienv[cgi_index++], MAXREQUESTLENGTH,
|
||||||
"CONTENT_TYPE=application/x-www-form-urlencoded");
|
"CONTENT_TYPE=%s", cn->cgicontenttype);
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(cgienv[cgi_index++], "REQUEST_METHOD=%s", type);
|
sprintf(cgienv[cgi_index++], "REQUEST_METHOD=%s", type);
|
||||||
@ -746,7 +751,9 @@ static void decode_path_info(struct connstruct *cn, char *path_info)
|
|||||||
{
|
{
|
||||||
char *cgi_delim;
|
char *cgi_delim;
|
||||||
|
|
||||||
|
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||||
cn->is_cgi = 0;
|
cn->is_cgi = 0;
|
||||||
|
#endif
|
||||||
#ifdef CONFIG_HTTP_ENABLE_LUA
|
#ifdef CONFIG_HTTP_ENABLE_LUA
|
||||||
cn->is_lua = 0;
|
cn->is_lua = 0;
|
||||||
#endif
|
#endif
|
||||||
@ -763,6 +770,7 @@ static void decode_path_info(struct connstruct *cn, char *path_info)
|
|||||||
my_strncpy(cn->uri_query, cgi_delim+1, MAXREQUESTLENGTH);
|
my_strncpy(cn->uri_query, cgi_delim+1, MAXREQUESTLENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_HTTP_HAS_CGI)
|
||||||
if ((cgi_delim = cgi_filetype_match(cn, path_info)) != NULL)
|
if ((cgi_delim = cgi_filetype_match(cn, path_info)) != NULL)
|
||||||
{
|
{
|
||||||
cn->is_cgi = 1; /* definitely a CGI script */
|
cn->is_cgi = 1; /* definitely a CGI script */
|
||||||
@ -774,6 +782,7 @@ static void decode_path_info(struct connstruct *cn, char *path_info)
|
|||||||
*cgi_delim = '\0';
|
*cgi_delim = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* the bit at the start must be the script name */
|
/* the bit at the start must be the script name */
|
||||||
my_strncpy(cn->filereq, path_info, MAXREQUESTLENGTH);
|
my_strncpy(cn->filereq, path_info, MAXREQUESTLENGTH);
|
||||||
@ -787,7 +796,7 @@ static int init_read_post_data(char *buf, char *data,
|
|||||||
char *post_data;
|
char *post_data;
|
||||||
|
|
||||||
/* Too much Post data to send. MAXPOSTDATASIZE should be
|
/* Too much Post data to send. MAXPOSTDATASIZE should be
|
||||||
configured (now it can be chaged in the header file) */
|
configured (now it can be changed in the header file) */
|
||||||
if (cn->content_length > MAXPOSTDATASIZE)
|
if (cn->content_length > MAXPOSTDATASIZE)
|
||||||
{
|
{
|
||||||
send_error(cn, 418);
|
send_error(cn, 418);
|
||||||
@ -800,17 +809,9 @@ static int init_read_post_data(char *buf, char *data,
|
|||||||
|
|
||||||
if (cn->post_data == NULL)
|
if (cn->post_data == NULL)
|
||||||
{
|
{
|
||||||
cn->post_data = (char *) calloc(1, (cn->content_length + 1));
|
|
||||||
/* Allocate buffer for the POST data that will be used by proccgi
|
/* Allocate buffer for the POST data that will be used by proccgi
|
||||||
to send POST data to the CGI script */
|
to send POST data to the CGI script */
|
||||||
|
cn->post_data = (char *)ax_calloc(1, (cn->content_length + 1));
|
||||||
if (cn->post_data == NULL)
|
|
||||||
{
|
|
||||||
printf("axhttpd: could not allocate memory for POST data\n");
|
|
||||||
TTY_FLUSH();
|
|
||||||
send_error(cn, 599);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cn->post_state = 0;
|
cn->post_state = 0;
|
||||||
@ -820,9 +821,7 @@ static int init_read_post_data(char *buf, char *data,
|
|||||||
while (next < &buf[rv])
|
while (next < &buf[rv])
|
||||||
{
|
{
|
||||||
/* copy POST data to buffer */
|
/* copy POST data to buffer */
|
||||||
*post_data = *next;
|
*post_data++ = *next++;
|
||||||
post_data++;
|
|
||||||
next++;
|
|
||||||
cn->post_read++;
|
cn->post_read++;
|
||||||
if (cn->post_read == cn->content_length)
|
if (cn->post_read == cn->content_length)
|
||||||
{
|
{
|
||||||
@ -839,11 +838,11 @@ static int init_read_post_data(char *buf, char *data,
|
|||||||
|
|
||||||
void read_post_data(struct connstruct *cn)
|
void read_post_data(struct connstruct *cn)
|
||||||
{
|
{
|
||||||
char buf[MAXREQUESTLENGTH*4], *next;
|
char buf[MAXREADLENGTH], *next;
|
||||||
char *post_data;
|
char *post_data;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
bzero(buf,MAXREQUESTLENGTH*4);
|
memset(buf, 0, sizeof(buf));
|
||||||
rv = special_read(cn, buf, sizeof(buf)-1);
|
rv = special_read(cn, buf, sizeof(buf)-1);
|
||||||
if (rv <= 0)
|
if (rv <= 0)
|
||||||
{
|
{
|
||||||
@ -854,15 +853,13 @@ void read_post_data(struct connstruct *cn)
|
|||||||
|
|
||||||
buf[rv] = '\0';
|
buf[rv] = '\0';
|
||||||
next = buf;
|
next = buf;
|
||||||
|
|
||||||
post_data = &cn->post_data[cn->post_read];
|
post_data = &cn->post_data[cn->post_read];
|
||||||
|
|
||||||
while (next < &buf[rv])
|
while (next < &buf[rv])
|
||||||
{
|
{
|
||||||
*post_data = *next;
|
*post_data++ = *next++;
|
||||||
post_data++;
|
|
||||||
next++;
|
|
||||||
cn->post_read++;
|
cn->post_read++;
|
||||||
|
|
||||||
if (cn->post_read == cn->content_length)
|
if (cn->post_read == cn->content_length)
|
||||||
{
|
{
|
||||||
/* No more POST data to be copied */
|
/* No more POST data to be copied */
|
||||||
@ -1174,7 +1171,7 @@ static void send_error(struct connstruct *cn, int err)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 418:
|
case 418:
|
||||||
title = "POST data size is to large";
|
title = "POST data size is too large";
|
||||||
text = title;
|
text = title;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1191,6 +1188,9 @@ static void send_error(struct connstruct *cn, int err)
|
|||||||
"<html>\n<head>\n<title>%d %s</title></head>\n"
|
"<html>\n<head>\n<title>%d %s</title></head>\n"
|
||||||
"<body><h1>%d %s</h1>\n</body></html>\n",
|
"<body><h1>%d %s</h1>\n</body></html>\n",
|
||||||
err, title, err, title, err, text);
|
err, title, err, title, err, text);
|
||||||
|
#ifdef CONFIG_HTTP_VERBOSE
|
||||||
|
printf("axhttpd: http error: %s [%d]\n", title, err); TTY_FLUSH();
|
||||||
|
#endif
|
||||||
special_write(cn, buf, strlen(buf));
|
special_write(cn, buf, strlen(buf));
|
||||||
removeconnection(cn);
|
removeconnection(cn);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user