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"
|
||||
#endif
|
||||
|
||||
#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
|
||||
#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
|
||||
|
||||
#ifndef CONFIG_NETUTILS_HTTPD_PATH
|
||||
# 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.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, returns >=0. On failure, returns a negative number indicating
|
||||
* the failure code.
|
||||
* On success, returns >=0. On failure, returns a negative number
|
||||
* 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,
|
||||
unsigned int nbytes)
|
||||
{
|
||||
/* CONFIG_DEBUG_FEATURES, CONFIG_DEBUG_INFO, and CONFIG_DEBUG_NET have to be
|
||||
* defined or the following does nothing.
|
||||
/* CONFIG_DEBUG_FEATURES, CONFIG_DEBUG_INFO, and CONFIG_DEBUG_NET have to
|
||||
* be defined or the following does nothing.
|
||||
*/
|
||||
|
||||
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)
|
||||
{
|
||||
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_scriptptr = p;
|
||||
}
|
||||
@ -321,12 +321,12 @@ static int handle_script(struct httpd_state *pstate)
|
||||
{
|
||||
/* Check if we should start executing a script */
|
||||
|
||||
if (*pstate->ht_file.data == ISO_percent &&
|
||||
*(pstate->ht_file.data + 1) == ISO_bang)
|
||||
if (*pstate->ht_file.data == ISO_PERCENT &&
|
||||
*(pstate->ht_file.data + 1) == ISO_BANG)
|
||||
{
|
||||
pstate->ht_scriptptr = pstate->ht_file.data + 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,
|
||||
&pstate->ht_file) != OK)
|
||||
@ -378,13 +378,13 @@ static int handle_script(struct httpd_state *pstate)
|
||||
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
|
||||
{
|
||||
ptr = strchr(pstate->ht_file.data, ISO_percent);
|
||||
ptr = strchr(pstate->ht_file.data, ISO_PERCENT);
|
||||
}
|
||||
|
||||
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 *ptr;
|
||||
char contentlen[HTTPD_MAX_CONTENTLEN] =
|
||||
{
|
||||
0
|
||||
};
|
||||
{
|
||||
0
|
||||
};
|
||||
|
||||
char header[HTTPD_MAX_HEADERLEN];
|
||||
int hdrlen;
|
||||
int i;
|
||||
@ -456,42 +457,54 @@ static int send_headers(struct httpd_state *pstate, int status, int len)
|
||||
{
|
||||
const char *ext;
|
||||
const char *mime;
|
||||
} a[] =
|
||||
{
|
||||
}
|
||||
|
||||
a[] =
|
||||
{
|
||||
#ifndef CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE
|
||||
{
|
||||
"shtml", "text/html"
|
||||
},
|
||||
#endif
|
||||
|
||||
{
|
||||
"html", "text/html"
|
||||
},
|
||||
|
||||
{
|
||||
"css", "text/css"
|
||||
},
|
||||
|
||||
{
|
||||
"txt", "text/plain"
|
||||
},
|
||||
|
||||
{
|
||||
"js", "text/javascript"
|
||||
},
|
||||
|
||||
{
|
||||
"png", "image/png"
|
||||
},
|
||||
|
||||
{
|
||||
"gif", "image/gif"
|
||||
},
|
||||
|
||||
{
|
||||
"jpeg", "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)
|
||||
{
|
||||
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);
|
||||
|
||||
#ifdef CONFIG_NETUTILS_HTTPD_CGIPATH
|
||||
{
|
||||
httpd_cgifunction f;
|
||||
{
|
||||
httpd_cgifunction f;
|
||||
|
||||
f = httpd_cgi(pstate->ht_filename);
|
||||
if (f != NULL)
|
||||
{
|
||||
f = httpd_cgi(pstate->ht_filename);
|
||||
if (f != NULL)
|
||||
{
|
||||
#ifndef CONFIG_NETUTILS_HTTPD_KEEPALIVE_DISABLE
|
||||
pstate->ht_keepalive = false;
|
||||
pstate->ht_keepalive = false;
|
||||
#endif
|
||||
f(pstate, pstate->ht_filename);
|
||||
f(pstate, pstate->ht_filename);
|
||||
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (httpd_openindex(pstate) != OK)
|
||||
@ -662,7 +675,7 @@ static int httpd_sendfile(struct httpd_state *pstate)
|
||||
}
|
||||
|
||||
#ifndef CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE
|
||||
ptr = strchr(pstate->ht_filename, ISO_period);
|
||||
ptr = strchr(pstate->ht_filename, ISO_PERIOD);
|
||||
if (ptr != NULL &&
|
||||
strncmp(ptr, ".shtml", strlen(".shtml")) == 0)
|
||||
{
|
||||
@ -710,11 +723,11 @@ static inline int httpd_parse(struct httpd_state *pstate)
|
||||
char *o;
|
||||
|
||||
enum
|
||||
{
|
||||
STATE_METHOD,
|
||||
STATE_HEADER,
|
||||
STATE_BODY
|
||||
} state;
|
||||
{
|
||||
STATE_METHOD,
|
||||
STATE_HEADER,
|
||||
STATE_BODY
|
||||
} state;
|
||||
|
||||
state = STATE_METHOD;
|
||||
o = pstate->ht_buffer;
|
||||
@ -730,33 +743,34 @@ static inline int httpd_parse(struct httpd_state *pstate)
|
||||
return 413;
|
||||
}
|
||||
|
||||
{
|
||||
ssize_t r;
|
||||
{
|
||||
ssize_t r;
|
||||
|
||||
r = recv(pstate->ht_sockfd, o,
|
||||
sizeof pstate->ht_buffer - (o - pstate->ht_buffer), 0);
|
||||
if (r == 0)
|
||||
{
|
||||
nwarn("WARNING: [%d] connection lost\n", pstate->ht_sockfd);
|
||||
return ERROR;
|
||||
}
|
||||
r = recv(pstate->ht_sockfd, o,
|
||||
sizeof pstate->ht_buffer - (o - pstate->ht_buffer), 0);
|
||||
if (r == 0)
|
||||
{
|
||||
nwarn("WARNING: [%d] connection lost\n", pstate->ht_sockfd);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#if CONFIG_NETUTILS_HTTPD_TIMEOUT > 0
|
||||
if (r == -1 && errno == EWOULDBLOCK)
|
||||
{
|
||||
nwarn("WARNING: [%d] recv timeout\n");
|
||||
return 408;
|
||||
}
|
||||
if (r == -1 && errno == EWOULDBLOCK)
|
||||
{
|
||||
nwarn("WARNING: [%d] recv timeout\n");
|
||||
return 408;
|
||||
}
|
||||
#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
|
||||
* 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;
|
||||
|
||||
case STATE_BODY:
|
||||
|
||||
/* Not implemented */
|
||||
|
||||
break;
|
||||
@ -893,7 +908,7 @@ static void *httpd_handler(void *arg)
|
||||
{
|
||||
struct httpd_state *pstate =
|
||||
(struct httpd_state *)malloc(sizeof(struct httpd_state));
|
||||
int sockfd = (int)arg;
|
||||
int sockfd = (intptr_t)arg;
|
||||
|
||||
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);
|
||||
|
||||
/* 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
|
||||
ling.l_onoff = 1;
|
||||
|
Loading…
Reference in New Issue
Block a user