netutils/webserver: fix build error
This commit is contained in:
parent
a8a70f219d
commit
a3e27eb1a0
@ -85,13 +85,13 @@
|
|||||||
# error "CONFIG_NETUTILS_HTTPD_SENDFILE and CONFIG_NETUTILS_HTTPD_MMAP are mutually exclusive"
|
# error "CONFIG_NETUTILS_HTTPD_SENDFILE and CONFIG_NETUTILS_HTTPD_MMAP are mutually exclusive"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ISO_nl 0x0a
|
#define ISO_NL 0x0a
|
||||||
#define ISO_space 0x20
|
#define ISO_SPACE 0x20
|
||||||
#define ISO_bang 0x21
|
#define ISO_BANG 0x21
|
||||||
#define ISO_percent 0x25
|
#define ISO_PERCENT 0x25
|
||||||
#define ISO_period 0x2e
|
#define ISO_PERIOD 0x2e
|
||||||
#define ISO_slash 0x2f
|
#define ISO_SLASH 0x2f
|
||||||
#define ISO_colon 0x3a
|
#define ISO_COLON 0x3a
|
||||||
|
|
||||||
#ifndef CONFIG_NETUTILS_HTTPD_PATH
|
#ifndef CONFIG_NETUTILS_HTTPD_PATH
|
||||||
# define CONFIG_NETUTILS_HTTPD_PATH "/mnt"
|
# define CONFIG_NETUTILS_HTTPD_PATH "/mnt"
|
||||||
@ -207,8 +207,8 @@ static int httpd_close(struct httpd_fs_file *file)
|
|||||||
* data block. If False, just sends the data.
|
* data block. If False, just sends the data.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, returns >=0. On failure, returns a negative number indicating
|
* On success, returns >=0. On failure, returns a negative number
|
||||||
* the failure code.
|
* indicating the failure code.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@ -266,8 +266,8 @@ int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked)
|
|||||||
static void httpd_dumpbuffer(FAR const char *msg, FAR const char *buffer,
|
static void httpd_dumpbuffer(FAR const char *msg, FAR const char *buffer,
|
||||||
unsigned int nbytes)
|
unsigned int nbytes)
|
||||||
{
|
{
|
||||||
/* CONFIG_DEBUG_FEATURES, CONFIG_DEBUG_INFO, and CONFIG_DEBUG_NET have to be
|
/* CONFIG_DEBUG_FEATURES, CONFIG_DEBUG_INFO, and CONFIG_DEBUG_NET have to
|
||||||
* defined or the following does nothing.
|
* be defined or the following does nothing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ninfodumpbuffer(msg, (FAR const uint8_t *)buffer, nbytes);
|
ninfodumpbuffer(msg, (FAR const uint8_t *)buffer, nbytes);
|
||||||
@ -299,7 +299,7 @@ static void httpd_dumppstate(struct httpd_state *pstate, const char *msg)
|
|||||||
static void next_scriptstate(struct httpd_state *pstate)
|
static void next_scriptstate(struct httpd_state *pstate)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
p = strchr(pstate->ht_scriptptr, ISO_nl) + 1;
|
p = strchr(pstate->ht_scriptptr, ISO_NL) + 1;
|
||||||
pstate->ht_scriptlen -= (unsigned short)(p - pstate->ht_scriptptr);
|
pstate->ht_scriptlen -= (unsigned short)(p - pstate->ht_scriptptr);
|
||||||
pstate->ht_scriptptr = p;
|
pstate->ht_scriptptr = p;
|
||||||
}
|
}
|
||||||
@ -321,12 +321,12 @@ static int handle_script(struct httpd_state *pstate)
|
|||||||
{
|
{
|
||||||
/* Check if we should start executing a script */
|
/* Check if we should start executing a script */
|
||||||
|
|
||||||
if (*pstate->ht_file.data == ISO_percent &&
|
if (*pstate->ht_file.data == ISO_PERCENT &&
|
||||||
*(pstate->ht_file.data + 1) == ISO_bang)
|
*(pstate->ht_file.data + 1) == ISO_BANG)
|
||||||
{
|
{
|
||||||
pstate->ht_scriptptr = pstate->ht_file.data + 3;
|
pstate->ht_scriptptr = pstate->ht_file.data + 3;
|
||||||
pstate->ht_scriptlen = pstate->ht_file.len - 3;
|
pstate->ht_scriptlen = pstate->ht_file.len - 3;
|
||||||
if (*(pstate->ht_scriptptr - 1) == ISO_colon)
|
if (*(pstate->ht_scriptptr - 1) == ISO_COLON)
|
||||||
{
|
{
|
||||||
if (httpd_open(pstate->ht_scriptptr + 1,
|
if (httpd_open(pstate->ht_scriptptr + 1,
|
||||||
&pstate->ht_file) != OK)
|
&pstate->ht_file) != OK)
|
||||||
@ -378,13 +378,13 @@ static int handle_script(struct httpd_state *pstate)
|
|||||||
len = pstate->ht_file.len;
|
len = pstate->ht_file.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*pstate->ht_file.data == ISO_percent)
|
if (*pstate->ht_file.data == ISO_PERCENT)
|
||||||
{
|
{
|
||||||
ptr = strchr(pstate->ht_file.data + 1, ISO_percent);
|
ptr = strchr(pstate->ht_file.data + 1, ISO_PERCENT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ptr = strchr(pstate->ht_file.data, ISO_percent);
|
ptr = strchr(pstate->ht_file.data, ISO_PERCENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ptr != NULL && ptr != pstate->ht_file.data)
|
if (ptr != NULL && ptr != pstate->ht_file.data)
|
||||||
@ -445,9 +445,10 @@ static int send_headers(struct httpd_state *pstate, int status, int len)
|
|||||||
const char *mime;
|
const char *mime;
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
char contentlen[HTTPD_MAX_CONTENTLEN] =
|
char contentlen[HTTPD_MAX_CONTENTLEN] =
|
||||||
{
|
{
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
char header[HTTPD_MAX_HEADERLEN];
|
char header[HTTPD_MAX_HEADERLEN];
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
int i;
|
int i;
|
||||||
@ -456,42 +457,54 @@ static int send_headers(struct httpd_state *pstate, int status, int len)
|
|||||||
{
|
{
|
||||||
const char *ext;
|
const char *ext;
|
||||||
const char *mime;
|
const char *mime;
|
||||||
} a[] =
|
}
|
||||||
{
|
|
||||||
|
a[] =
|
||||||
|
{
|
||||||
#ifndef CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE
|
#ifndef CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE
|
||||||
{
|
{
|
||||||
"shtml", "text/html"
|
"shtml", "text/html"
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
"html", "text/html"
|
"html", "text/html"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"css", "text/css"
|
"css", "text/css"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"txt", "text/plain"
|
"txt", "text/plain"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"js", "text/javascript"
|
"js", "text/javascript"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"png", "image/png"
|
"png", "image/png"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"gif", "image/gif"
|
"gif", "image/gif"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"jpeg", "image/jpeg"
|
"jpeg", "image/jpeg"
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"jpg", "image/jpeg"
|
"jpg", "image/jpeg"
|
||||||
},
|
},
|
||||||
{ "mp3", "audio/mpeg"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ptr = strrchr(pstate->ht_filename, ISO_period);
|
{
|
||||||
|
"mp3", "audio/mpeg"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ptr = strrchr(pstate->ht_filename, ISO_PERIOD);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
mime = "application/octet-stream";
|
mime = "application/octet-stream";
|
||||||
@ -638,20 +651,20 @@ static int httpd_sendfile(struct httpd_state *pstate)
|
|||||||
ninfo("[%d] sending file '%s'\n", pstate->ht_sockfd, pstate->ht_filename);
|
ninfo("[%d] sending file '%s'\n", pstate->ht_sockfd, pstate->ht_filename);
|
||||||
|
|
||||||
#ifdef CONFIG_NETUTILS_HTTPD_CGIPATH
|
#ifdef CONFIG_NETUTILS_HTTPD_CGIPATH
|
||||||
{
|
{
|
||||||
httpd_cgifunction f;
|
httpd_cgifunction f;
|
||||||
|
|
||||||
f = httpd_cgi(pstate->ht_filename);
|
f = httpd_cgi(pstate->ht_filename);
|
||||||
if (f != NULL)
|
if (f != NULL)
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_NETUTILS_HTTPD_KEEPALIVE_DISABLE
|
#ifndef CONFIG_NETUTILS_HTTPD_KEEPALIVE_DISABLE
|
||||||
pstate->ht_keepalive = false;
|
pstate->ht_keepalive = false;
|
||||||
#endif
|
#endif
|
||||||
f(pstate, pstate->ht_filename);
|
f(pstate, pstate->ht_filename);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (httpd_openindex(pstate) != OK)
|
if (httpd_openindex(pstate) != OK)
|
||||||
@ -662,7 +675,7 @@ static int httpd_sendfile(struct httpd_state *pstate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE
|
#ifndef CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE
|
||||||
ptr = strchr(pstate->ht_filename, ISO_period);
|
ptr = strchr(pstate->ht_filename, ISO_PERIOD);
|
||||||
if (ptr != NULL &&
|
if (ptr != NULL &&
|
||||||
strncmp(ptr, ".shtml", strlen(".shtml")) == 0)
|
strncmp(ptr, ".shtml", strlen(".shtml")) == 0)
|
||||||
{
|
{
|
||||||
@ -710,11 +723,11 @@ static inline int httpd_parse(struct httpd_state *pstate)
|
|||||||
char *o;
|
char *o;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
STATE_METHOD,
|
STATE_METHOD,
|
||||||
STATE_HEADER,
|
STATE_HEADER,
|
||||||
STATE_BODY
|
STATE_BODY
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
state = STATE_METHOD;
|
state = STATE_METHOD;
|
||||||
o = pstate->ht_buffer;
|
o = pstate->ht_buffer;
|
||||||
@ -730,33 +743,34 @@ static inline int httpd_parse(struct httpd_state *pstate)
|
|||||||
return 413;
|
return 413;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|
||||||
r = recv(pstate->ht_sockfd, o,
|
r = recv(pstate->ht_sockfd, o,
|
||||||
sizeof pstate->ht_buffer - (o - pstate->ht_buffer), 0);
|
sizeof pstate->ht_buffer - (o - pstate->ht_buffer), 0);
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
{
|
{
|
||||||
nwarn("WARNING: [%d] connection lost\n", pstate->ht_sockfd);
|
nwarn("WARNING: [%d] connection lost\n", pstate->ht_sockfd);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_NETUTILS_HTTPD_TIMEOUT > 0
|
#if CONFIG_NETUTILS_HTTPD_TIMEOUT > 0
|
||||||
if (r == -1 && errno == EWOULDBLOCK)
|
if (r == -1 && errno == EWOULDBLOCK)
|
||||||
{
|
{
|
||||||
nwarn("WARNING: [%d] recv timeout\n");
|
nwarn("WARNING: [%d] recv timeout\n");
|
||||||
return 408;
|
return 408;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (r == -1)
|
|
||||||
{
|
|
||||||
nerr("ERROR: [%d] recv failed: %d\n",
|
|
||||||
pstate->ht_sockfd, errno);
|
|
||||||
return 400;
|
|
||||||
}
|
|
||||||
|
|
||||||
o += r;
|
if (r == -1)
|
||||||
}
|
{
|
||||||
|
nerr("ERROR: [%d] recv failed: %d\n",
|
||||||
|
pstate->ht_sockfd, errno);
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
o += r;
|
||||||
|
}
|
||||||
|
|
||||||
/* Here o marks the end of the total block currently awaiting
|
/* Here o marks the end of the total block currently awaiting
|
||||||
* processing. There may be multiple lines in a block; next we deal
|
* processing. There may be multiple lines in a block; next we deal
|
||||||
@ -853,6 +867,7 @@ static inline int httpd_parse(struct httpd_state *pstate)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_BODY:
|
case STATE_BODY:
|
||||||
|
|
||||||
/* Not implemented */
|
/* Not implemented */
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -893,7 +908,7 @@ static void *httpd_handler(void *arg)
|
|||||||
{
|
{
|
||||||
struct httpd_state *pstate =
|
struct httpd_state *pstate =
|
||||||
(struct httpd_state *)malloc(sizeof(struct httpd_state));
|
(struct httpd_state *)malloc(sizeof(struct httpd_state));
|
||||||
int sockfd = (int)arg;
|
int sockfd = (intptr_t)arg;
|
||||||
|
|
||||||
ninfo("[%d] Started\n", sockfd);
|
ninfo("[%d] Started\n", sockfd);
|
||||||
|
|
||||||
@ -978,7 +993,9 @@ static void single_server(uint16_t portno, pthread_startroutine_t handler,
|
|||||||
|
|
||||||
ninfo("Connection accepted -- serving sd=%d\n", acceptsd);
|
ninfo("Connection accepted -- serving sd=%d\n", acceptsd);
|
||||||
|
|
||||||
/* Configure to "linger" until all data is sent when the socket is closed */
|
/* Configure to "linger" until all data is sent
|
||||||
|
* when the socket is closed
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_NET_SOLINGER
|
#ifdef CONFIG_NET_SOLINGER
|
||||||
ling.l_onoff = 1;
|
ling.l_onoff = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user