mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-11-24 03:30:37 +02:00
[package] uhttpd: display errors in init script, code formatting changes, bump package version
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@31572 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
37f687e099
commit
d0f3681e1e
@ -8,7 +8,7 @@
|
|||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=uhttpd
|
PKG_NAME:=uhttpd
|
||||||
PKG_RELEASE:=31
|
PKG_RELEASE:=32
|
||||||
|
|
||||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
|
||||||
PKG_CONFIG_DEPENDS := \
|
PKG_CONFIG_DEPENDS := \
|
||||||
|
@ -108,6 +108,11 @@ start_instance()
|
|||||||
|
|
||||||
SERVICE_PID_FILE=/var/run/uhttpd_${cfg}.pid
|
SERVICE_PID_FILE=/var/run/uhttpd_${cfg}.pid
|
||||||
service_start $UHTTPD_BIN -f $UHTTPD_ARGS
|
service_start $UHTTPD_BIN -f $UHTTPD_ARGS
|
||||||
|
|
||||||
|
# Check if daemon is running, if not then
|
||||||
|
# re-execute in foreground to display error.
|
||||||
|
sleep 1 && service_check $UHTTPD_BIN || \
|
||||||
|
$UHTTPD_BIN -f $UHTTPD_ARGS
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_instance()
|
stop_instance()
|
||||||
|
@ -31,8 +31,8 @@ static struct http_response * uh_cgi_header_parse(char *buf, int len, int *off)
|
|||||||
|
|
||||||
|
|
||||||
if (((bufptr = strfind(buf, len, "\r\n\r\n", 4)) != NULL) ||
|
if (((bufptr = strfind(buf, len, "\r\n\r\n", 4)) != NULL) ||
|
||||||
((bufptr = strfind(buf, len, "\n\n", 2)) != NULL)
|
((bufptr = strfind(buf, len, "\n\n", 2)) != NULL))
|
||||||
) {
|
{
|
||||||
*off = (int)(bufptr - buf) + ((bufptr[0] == '\r') ? 4 : 2);
|
*off = (int)(bufptr - buf) + ((bufptr[0] == '\r') ? 4 : 2);
|
||||||
|
|
||||||
memset(&res, 0, sizeof(res));
|
memset(&res, 0, sizeof(res));
|
||||||
@ -79,9 +79,12 @@ static struct http_response * uh_cgi_header_parse(char *buf, int len, int *off)
|
|||||||
if (res.statuscode < 100)
|
if (res.statuscode < 100)
|
||||||
res.statuscode = 200;
|
res.statuscode = 200;
|
||||||
|
|
||||||
if( ((bufptr = strchr(bufptr, ' ')) != NULL) && (&bufptr[1] != 0) )
|
if (((bufptr = strchr(bufptr, ' ')) != NULL) &&
|
||||||
|
(&bufptr[1] != 0))
|
||||||
|
{
|
||||||
res.statusmsg = &bufptr[1];
|
res.statusmsg = &bufptr[1];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res.headers[hdrcount++] = hdrname;
|
res.headers[hdrcount++] = hdrname;
|
||||||
@ -105,7 +108,8 @@ static struct http_response * uh_cgi_header_parse(char *buf, int len, int *off)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char * uh_cgi_header_lookup(struct http_response *res, const char *hdrname)
|
static char * uh_cgi_header_lookup(struct http_response *res,
|
||||||
|
const char *hdrname)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -118,16 +122,16 @@ static char * uh_cgi_header_lookup(struct http_response *res, const char *hdrnam
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_cgi_error_500(struct client *cl, struct http_request *req, const char *message)
|
static int uh_cgi_error_500(struct client *cl, struct http_request *req,
|
||||||
|
const char *message)
|
||||||
{
|
{
|
||||||
if (uh_http_sendf(cl, NULL,
|
if (uh_http_sendf(cl, NULL,
|
||||||
"HTTP/%.1f 500 Internal Server Error\r\n"
|
"HTTP/%.1f 500 Internal Server Error\r\n"
|
||||||
"Content-Type: text/plain\r\n%s\r\n",
|
"Content-Type: text/plain\r\n%s\r\n",
|
||||||
req->version,
|
req->version,
|
||||||
(req->version > 1.0)
|
(req->version > 1.0)
|
||||||
? "Transfer-Encoding: chunked\r\n" : ""
|
? "Transfer-Encoding: chunked\r\n" : "") >= 0)
|
||||||
) >= 0
|
{
|
||||||
) {
|
|
||||||
return uh_http_send(cl, req, message, -1);
|
return uh_http_send(cl, req, message, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,10 +139,9 @@ static int uh_cgi_error_500(struct client *cl, struct http_request *req, const c
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void uh_cgi_request(
|
void uh_cgi_request(struct client *cl, struct http_request *req,
|
||||||
struct client *cl, struct http_request *req,
|
struct path_info *pi, struct interpreter *ip)
|
||||||
struct path_info *pi, struct interpreter *ip
|
{
|
||||||
) {
|
|
||||||
int i, hdroff, bufoff, rv;
|
int i, hdroff, bufoff, rv;
|
||||||
int hdrlen = 0;
|
int hdrlen = 0;
|
||||||
int buflen = 0;
|
int buflen = 0;
|
||||||
@ -213,8 +216,8 @@ void uh_cgi_request(
|
|||||||
|
|
||||||
/* check for regular, world-executable file _or_ interpreter */
|
/* check for regular, world-executable file _or_ interpreter */
|
||||||
if (((pi->stat.st_mode & S_IFREG) &&
|
if (((pi->stat.st_mode & S_IFREG) &&
|
||||||
(pi->stat.st_mode & S_IXOTH)) || (ip != NULL)
|
(pi->stat.st_mode & S_IXOTH)) || (ip != NULL))
|
||||||
) {
|
{
|
||||||
/* build environment */
|
/* build environment */
|
||||||
clearenv();
|
clearenv();
|
||||||
|
|
||||||
@ -338,21 +341,17 @@ void uh_cgi_request(
|
|||||||
execl(pi->phys, pi->phys, NULL);
|
execl(pi->phys, pi->phys, NULL);
|
||||||
|
|
||||||
/* in case it fails ... */
|
/* in case it fails ... */
|
||||||
printf(
|
printf("Status: 500 Internal Server Error\r\n\r\n"
|
||||||
"Status: 500 Internal Server Error\r\n\r\n"
|
|
||||||
"Unable to launch the requested CGI program:\n"
|
"Unable to launch the requested CGI program:\n"
|
||||||
" %s: %s\n",
|
" %s: %s\n",
|
||||||
ip ? ip->path : pi->phys, strerror(errno)
|
ip ? ip->path : pi->phys, strerror(errno));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 403 */
|
/* 403 */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf(
|
printf("Status: 403 Forbidden\r\n\r\n"
|
||||||
"Status: 403 Forbidden\r\n\r\n"
|
"Access to this resource is forbidden\n");
|
||||||
"Access to this resource is forbidden\n"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close(wfd[0]);
|
close(wfd[0]);
|
||||||
@ -399,7 +398,9 @@ void uh_cgi_request(
|
|||||||
timeout.tv_usec = 0;
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
ensure_out(rv = select_intr(fd_max, &reader,
|
ensure_out(rv = select_intr(fd_max, &reader,
|
||||||
(content_length > -1) ? &writer : NULL, NULL, &timeout));
|
(content_length > -1)
|
||||||
|
? &writer : NULL,
|
||||||
|
NULL, &timeout));
|
||||||
|
|
||||||
/* timeout */
|
/* timeout */
|
||||||
if (rv == 0)
|
if (rv == 0)
|
||||||
@ -603,4 +604,3 @@ void uh_cgi_request(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,8 +56,7 @@ static const char * uh_file_mktag(struct stat *s)
|
|||||||
snprintf(tag, sizeof(tag), "\"%x-%x-%x\"",
|
snprintf(tag, sizeof(tag), "\"%x-%x-%x\"",
|
||||||
(unsigned int) s->st_ino,
|
(unsigned int) s->st_ino,
|
||||||
(unsigned int) s->st_size,
|
(unsigned int) s->st_size,
|
||||||
(unsigned int) s->st_mtime
|
(unsigned int) s->st_mtime);
|
||||||
);
|
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
@ -98,26 +97,30 @@ static char * uh_file_header_lookup(struct http_request *req, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int uh_file_response_ok_hdrs(struct client *cl, struct http_request *req, struct stat *s)
|
static int uh_file_response_ok_hdrs(struct client *cl, struct http_request *req,
|
||||||
|
struct stat *s)
|
||||||
{
|
{
|
||||||
ensure_ret(uh_http_sendf(cl, NULL, "Connection: close\r\n"));
|
ensure_ret(uh_http_sendf(cl, NULL, "Connection: close\r\n"));
|
||||||
|
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
ensure_ret(uh_http_sendf(cl, NULL, "ETag: %s\r\n", uh_file_mktag(s)));
|
ensure_ret(uh_http_sendf(cl, NULL, "ETag: %s\r\n", uh_file_mktag(s)));
|
||||||
ensure_ret(uh_http_sendf(cl, NULL, "Last-Modified: %s\r\n", uh_file_unix2date(s->st_mtime)));
|
ensure_ret(uh_http_sendf(cl, NULL, "Last-Modified: %s\r\n",
|
||||||
|
uh_file_unix2date(s->st_mtime)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return uh_http_sendf(cl, NULL, "Date: %s\r\n", uh_file_unix2date(time(NULL)));
|
return uh_http_sendf(cl, NULL, "Date: %s\r\n", uh_file_unix2date(time(NULL)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_file_response_200(struct client *cl, struct http_request *req, struct stat *s)
|
static int uh_file_response_200(struct client *cl, struct http_request *req,
|
||||||
|
struct stat *s)
|
||||||
{
|
{
|
||||||
ensure_ret(uh_http_sendf(cl, NULL, "HTTP/%.1f 200 OK\r\n", req->version));
|
ensure_ret(uh_http_sendf(cl, NULL, "HTTP/%.1f 200 OK\r\n", req->version));
|
||||||
return uh_file_response_ok_hdrs(cl, req, s);
|
return uh_file_response_ok_hdrs(cl, req, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_file_response_304(struct client *cl, struct http_request *req, struct stat *s)
|
static int uh_file_response_304(struct client *cl, struct http_request *req,
|
||||||
|
struct stat *s)
|
||||||
{
|
{
|
||||||
ensure_ret(uh_http_sendf(cl, NULL, "HTTP/%.1f 304 Not Modified\r\n", req->version));
|
ensure_ret(uh_http_sendf(cl, NULL, "HTTP/%.1f 304 Not Modified\r\n", req->version));
|
||||||
return uh_file_response_ok_hdrs(cl, req, s);
|
return uh_file_response_ok_hdrs(cl, req, s);
|
||||||
@ -130,7 +133,8 @@ static int uh_file_response_412(struct client *cl, struct http_request *req)
|
|||||||
"Connection: close\r\n", req->version);
|
"Connection: close\r\n", req->version);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_file_if_match(struct client *cl, struct http_request *req, struct stat *s, int *ok)
|
static int uh_file_if_match(struct client *cl, struct http_request *req,
|
||||||
|
struct stat *s, int *ok)
|
||||||
{
|
{
|
||||||
const char *tag = uh_file_mktag(s);
|
const char *tag = uh_file_mktag(s);
|
||||||
char *hdr = uh_file_header_lookup(req, "If-Match");
|
char *hdr = uh_file_header_lookup(req, "If-Match");
|
||||||
@ -164,7 +168,9 @@ static int uh_file_if_match(struct client *cl, struct http_request *req, struct
|
|||||||
return *ok;
|
return *ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_file_if_modified_since(struct client *cl, struct http_request *req, struct stat *s, int *ok)
|
static int uh_file_if_modified_since(struct client *cl,
|
||||||
|
struct http_request *req, struct stat *s,
|
||||||
|
int *ok)
|
||||||
{
|
{
|
||||||
char *hdr = uh_file_header_lookup(req, "If-Modified-Since");
|
char *hdr = uh_file_header_lookup(req, "If-Modified-Since");
|
||||||
*ok = 1;
|
*ok = 1;
|
||||||
@ -181,7 +187,8 @@ static int uh_file_if_modified_since(struct client *cl, struct http_request *req
|
|||||||
return *ok;
|
return *ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_file_if_none_match(struct client *cl, struct http_request *req, struct stat *s, int *ok)
|
static int uh_file_if_none_match(struct client *cl, struct http_request *req,
|
||||||
|
struct stat *s, int *ok)
|
||||||
{
|
{
|
||||||
const char *tag = uh_file_mktag(s);
|
const char *tag = uh_file_mktag(s);
|
||||||
char *hdr = uh_file_header_lookup(req, "If-None-Match");
|
char *hdr = uh_file_header_lookup(req, "If-None-Match");
|
||||||
@ -206,9 +213,13 @@ static int uh_file_if_none_match(struct client *cl, struct http_request *req, st
|
|||||||
|
|
||||||
if ((req->method == UH_HTTP_MSG_GET) ||
|
if ((req->method == UH_HTTP_MSG_GET) ||
|
||||||
(req->method == UH_HTTP_MSG_HEAD))
|
(req->method == UH_HTTP_MSG_HEAD))
|
||||||
|
{
|
||||||
ensure_ret(uh_file_response_304(cl, req, s));
|
ensure_ret(uh_file_response_304(cl, req, s));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ensure_ret(uh_file_response_412(cl, req));
|
ensure_ret(uh_file_response_412(cl, req));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -218,7 +229,8 @@ static int uh_file_if_none_match(struct client *cl, struct http_request *req, st
|
|||||||
return *ok;
|
return *ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_file_if_range(struct client *cl, struct http_request *req, struct stat *s, int *ok)
|
static int uh_file_if_range(struct client *cl, struct http_request *req,
|
||||||
|
struct stat *s, int *ok)
|
||||||
{
|
{
|
||||||
char *hdr = uh_file_header_lookup(req, "If-Range");
|
char *hdr = uh_file_header_lookup(req, "If-Range");
|
||||||
*ok = 1;
|
*ok = 1;
|
||||||
@ -232,7 +244,9 @@ static int uh_file_if_range(struct client *cl, struct http_request *req, struct
|
|||||||
return *ok;
|
return *ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_file_if_unmodified_since(struct client *cl, struct http_request *req, struct stat *s, int *ok)
|
static int uh_file_if_unmodified_since(struct client *cl,
|
||||||
|
struct http_request *req, struct stat *s,
|
||||||
|
int *ok)
|
||||||
{
|
{
|
||||||
char *hdr = uh_file_header_lookup(req, "If-Unmodified-Since");
|
char *hdr = uh_file_header_lookup(req, "If-Unmodified-Since");
|
||||||
*ok = 1;
|
*ok = 1;
|
||||||
@ -255,7 +269,8 @@ static int uh_file_scandir_filter_dir(const struct dirent *e)
|
|||||||
return strcmp(e->d_name, ".") ? 1 : 0;
|
return strcmp(e->d_name, ".") ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void uh_file_dirlist(struct client *cl, struct http_request *req, struct path_info *pi)
|
static void uh_file_dirlist(struct client *cl, struct http_request *req,
|
||||||
|
struct path_info *pi)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -267,10 +282,10 @@ static void uh_file_dirlist(struct client *cl, struct http_request *req, struct
|
|||||||
ensure_out(uh_http_sendf(cl, req,
|
ensure_out(uh_http_sendf(cl, req,
|
||||||
"<html><head><title>Index of %s</title></head>"
|
"<html><head><title>Index of %s</title></head>"
|
||||||
"<body><h1>Index of %s</h1><hr /><ol>",
|
"<body><h1>Index of %s</h1><hr /><ol>",
|
||||||
pi->name, pi->name
|
pi->name, pi->name));
|
||||||
));
|
|
||||||
|
|
||||||
if( (count = scandir(pi->phys, &files, uh_file_scandir_filter_dir, alphasort)) > 0 )
|
if ((count = scandir(pi->phys, &files, uh_file_scandir_filter_dir,
|
||||||
|
alphasort)) > 0)
|
||||||
{
|
{
|
||||||
memset(filename, 0, sizeof(filename));
|
memset(filename, 0, sizeof(filename));
|
||||||
memcpy(filename, pi->phys, sizeof(filename));
|
memcpy(filename, pi->phys, sizeof(filename));
|
||||||
@ -283,15 +298,18 @@ static void uh_file_dirlist(struct client *cl, struct http_request *req, struct
|
|||||||
sizeof(filename) - strlen(files[i]->d_name));
|
sizeof(filename) - strlen(files[i]->d_name));
|
||||||
|
|
||||||
if (!stat(filename, &s) &&
|
if (!stat(filename, &s) &&
|
||||||
(s.st_mode & S_IFDIR) && (s.st_mode & S_IXOTH)
|
(s.st_mode & S_IFDIR) && (s.st_mode & S_IXOTH))
|
||||||
)
|
{
|
||||||
ensure_out(uh_http_sendf(cl, req,
|
ensure_out(uh_http_sendf(cl, req,
|
||||||
"<li><strong><a href='%s%s'>%s</a>/</strong><br />"
|
"<li><strong><a href='%s%s'>%s</a>/"
|
||||||
"<small>modified: %s<br />directory - %.02f kbyte"
|
"</strong><br /><small>modified: %s"
|
||||||
"<br /><br /></small></li>",
|
"<br />directory - %.02f kbyte<br />"
|
||||||
pi->name, files[i]->d_name, files[i]->d_name,
|
"<br /></small></li>",
|
||||||
uh_file_unix2date(s.st_mtime), s.st_size / 1024.0
|
pi->name, files[i]->d_name,
|
||||||
));
|
files[i]->d_name,
|
||||||
|
uh_file_unix2date(s.st_mtime),
|
||||||
|
s.st_size / 1024.0));
|
||||||
|
}
|
||||||
|
|
||||||
*pathptr = 0;
|
*pathptr = 0;
|
||||||
}
|
}
|
||||||
@ -303,16 +321,19 @@ static void uh_file_dirlist(struct client *cl, struct http_request *req, struct
|
|||||||
sizeof(filename) - strlen(files[i]->d_name));
|
sizeof(filename) - strlen(files[i]->d_name));
|
||||||
|
|
||||||
if (!stat(filename, &s) &&
|
if (!stat(filename, &s) &&
|
||||||
!(s.st_mode & S_IFDIR) && (s.st_mode & S_IROTH)
|
!(s.st_mode & S_IFDIR) && (s.st_mode & S_IROTH))
|
||||||
)
|
{
|
||||||
ensure_out(uh_http_sendf(cl, req,
|
ensure_out(uh_http_sendf(cl, req,
|
||||||
"<li><strong><a href='%s%s'>%s</a></strong><br />"
|
"<li><strong><a href='%s%s'>%s</a>"
|
||||||
"<small>modified: %s<br />%s - %.02f kbyte<br />"
|
"</strong><br /><small>modified: %s"
|
||||||
|
"<br />%s - %.02f kbyte<br />"
|
||||||
"<br /></small></li>",
|
"<br /></small></li>",
|
||||||
pi->name, files[i]->d_name, files[i]->d_name,
|
pi->name, files[i]->d_name,
|
||||||
|
files[i]->d_name,
|
||||||
uh_file_unix2date(s.st_mtime),
|
uh_file_unix2date(s.st_mtime),
|
||||||
uh_file_mime_lookup(filename), s.st_size / 1024.0
|
uh_file_mime_lookup(filename),
|
||||||
));
|
s.st_size / 1024.0));
|
||||||
|
}
|
||||||
|
|
||||||
*pathptr = 0;
|
*pathptr = 0;
|
||||||
}
|
}
|
||||||
@ -409,4 +430,3 @@ out:
|
|||||||
if (fd > -1)
|
if (fd > -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,9 +479,10 @@ void uh_lua_request(struct client *cl, struct http_request *req, lua_State *L)
|
|||||||
|
|
||||||
/* wait until we can read or write or both */
|
/* wait until we can read or write or both */
|
||||||
if (select_intr(fd_max, &reader,
|
if (select_intr(fd_max, &reader,
|
||||||
(content_length > -1) ? &writer : NULL, NULL,
|
(content_length > -1) ? &writer : NULL,
|
||||||
(data_sent < 1) ? &timeout : NULL) > 0
|
NULL,
|
||||||
) {
|
(data_sent < 1) ? &timeout : NULL) > 0)
|
||||||
|
{
|
||||||
/* ready to write to Lua child */
|
/* ready to write to Lua child */
|
||||||
if (FD_ISSET(wfd[1], &writer))
|
if (FD_ISSET(wfd[1], &writer))
|
||||||
{
|
{
|
||||||
|
@ -220,7 +220,8 @@ int uh_tcp_recv(struct client *cl, char *buf, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int uh_http_sendhf(struct client *cl, int code, const char *summary, const char *fmt, ...)
|
int uh_http_sendhf(struct client *cl, int code, const char *summary,
|
||||||
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
@ -271,9 +272,9 @@ int uh_http_sendc(struct client *cl, const char *data, int len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uh_http_sendf(
|
int uh_http_sendf(struct client *cl, struct http_request *req,
|
||||||
struct client *cl, struct http_request *req, const char *fmt, ...
|
const char *fmt, ...)
|
||||||
) {
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char buffer[UH_LIMIT_MSGHEAD];
|
char buffer[UH_LIMIT_MSGHEAD];
|
||||||
int len;
|
int len;
|
||||||
@ -290,9 +291,9 @@ int uh_http_sendf(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uh_http_send(
|
int uh_http_send(struct client *cl, struct http_request *req,
|
||||||
struct client *cl, struct http_request *req, const char *buf, int len
|
const char *buf, int len)
|
||||||
) {
|
{
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
len = strlen(buf);
|
len = strlen(buf);
|
||||||
|
|
||||||
@ -475,8 +476,8 @@ static char * canonpath(const char *path, char *path_resolved)
|
|||||||
|
|
||||||
/* collapse /x/../ */
|
/* collapse /x/../ */
|
||||||
else if ((path_cpy[2] == '.') &&
|
else if ((path_cpy[2] == '.') &&
|
||||||
((path_cpy[3] == '/') || (path_cpy[3] == '\0'))
|
((path_cpy[3] == '/') || (path_cpy[3] == '\0')))
|
||||||
) {
|
{
|
||||||
while ((path_res > path_resolved) && (*--path_res != '/'))
|
while ((path_res > path_resolved) && (*--path_res != '/'))
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -542,22 +543,26 @@ struct path_info * uh_path_lookup(struct client *cl, const char *url)
|
|||||||
|
|
||||||
/* urldecode component w/o query */
|
/* urldecode component w/o query */
|
||||||
if (pathptr > url)
|
if (pathptr > url)
|
||||||
if ( uh_urldecode(
|
{
|
||||||
&buffer[strlen(docroot)],
|
if (uh_urldecode(&buffer[strlen(docroot)],
|
||||||
sizeof(buffer) - strlen(docroot) - 1,
|
sizeof(buffer) - strlen(docroot) - 1,
|
||||||
url, pathptr - url ) < 0)
|
url, pathptr - url ) < 0)
|
||||||
|
{
|
||||||
return NULL; /* bad URL */
|
return NULL; /* bad URL */
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* no query string, decode all of url */
|
/* no query string, decode all of url */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( uh_urldecode(
|
if (uh_urldecode(&buffer[strlen(docroot)],
|
||||||
&buffer[strlen(docroot)],
|
|
||||||
sizeof(buffer) - strlen(docroot) - 1,
|
sizeof(buffer) - strlen(docroot) - 1,
|
||||||
url, strlen(url) ) < 0)
|
url, strlen(url) ) < 0)
|
||||||
|
{
|
||||||
return NULL; /* bad URL */
|
return NULL; /* bad URL */
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* create canon path */
|
/* create canon path */
|
||||||
for (i = strlen(buffer), slash = (buffer[max(0, i-1)] == '/'); i >= 0; i--)
|
for (i = strlen(buffer), slash = (buffer[max(0, i-1)] == '/'); i >= 0; i--)
|
||||||
@ -568,8 +573,8 @@ struct path_info * uh_path_lookup(struct client *cl, const char *url)
|
|||||||
memcpy(path_info, buffer, min(i + 1, sizeof(path_info) - 1));
|
memcpy(path_info, buffer, min(i + 1, sizeof(path_info) - 1));
|
||||||
|
|
||||||
if (no_sym ? realpath(path_info, path_phys)
|
if (no_sym ? realpath(path_info, path_phys)
|
||||||
: canonpath(path_info, path_phys)
|
: canonpath(path_info, path_phys))
|
||||||
) {
|
{
|
||||||
memset(path_info, 0, sizeof(path_info));
|
memset(path_info, 0, sizeof(path_info));
|
||||||
memcpy(path_info, &buffer[i],
|
memcpy(path_info, &buffer[i],
|
||||||
min(strlen(buffer) - i, sizeof(path_info) - 1));
|
min(strlen(buffer) - i, sizeof(path_info) - 1));
|
||||||
@ -582,8 +587,8 @@ struct path_info * uh_path_lookup(struct client *cl, const char *url)
|
|||||||
/* check whether found path is within docroot */
|
/* check whether found path is within docroot */
|
||||||
if (strncmp(path_phys, docroot, strlen(docroot)) ||
|
if (strncmp(path_phys, docroot, strlen(docroot)) ||
|
||||||
((path_phys[strlen(docroot)] != 0) &&
|
((path_phys[strlen(docroot)] != 0) &&
|
||||||
(path_phys[strlen(docroot)] != '/'))
|
(path_phys[strlen(docroot)] != '/')))
|
||||||
) {
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -701,8 +706,8 @@ struct auth_realm * uh_auth_add(char *path, char *user, char *pass)
|
|||||||
|
|
||||||
/* try to resolve passwd entry */
|
/* try to resolve passwd entry */
|
||||||
if (((pwd = getpwnam(&pass[3])) != NULL) && pwd->pw_passwd &&
|
if (((pwd = getpwnam(&pass[3])) != NULL) && pwd->pw_passwd &&
|
||||||
(pwd->pw_passwd[0] != '!') && (pwd->pw_passwd[0] != 0)
|
(pwd->pw_passwd[0] != '!') && (pwd->pw_passwd[0] != 0))
|
||||||
) {
|
{
|
||||||
memcpy(new->pass, pwd->pw_passwd,
|
memcpy(new->pass, pwd->pw_passwd,
|
||||||
min(strlen(pwd->pw_passwd), sizeof(new->pass) - 1));
|
min(strlen(pwd->pw_passwd), sizeof(new->pass) - 1));
|
||||||
}
|
}
|
||||||
@ -729,9 +734,9 @@ struct auth_realm * uh_auth_add(char *path, char *user, char *pass)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uh_auth_check(
|
int uh_auth_check(struct client *cl, struct http_request *req,
|
||||||
struct client *cl, struct http_request *req, struct path_info *pi
|
struct path_info *pi)
|
||||||
) {
|
{
|
||||||
int i, plen, rlen, protected;
|
int i, plen, rlen, protected;
|
||||||
char buffer[UH_LIMIT_MSGHEAD];
|
char buffer[UH_LIMIT_MSGHEAD];
|
||||||
char *user = NULL;
|
char *user = NULL;
|
||||||
@ -763,8 +768,8 @@ int uh_auth_check(
|
|||||||
{
|
{
|
||||||
if (!strcasecmp(req->headers[i], "Authorization") &&
|
if (!strcasecmp(req->headers[i], "Authorization") &&
|
||||||
(strlen(req->headers[i+1]) > 6) &&
|
(strlen(req->headers[i+1]) > 6) &&
|
||||||
!strncasecmp(req->headers[i+1], "Basic ", 6)
|
!strncasecmp(req->headers[i+1], "Basic ", 6))
|
||||||
) {
|
{
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
uh_b64decode(buffer, sizeof(buffer) - 1,
|
uh_b64decode(buffer, sizeof(buffer) - 1,
|
||||||
(unsigned char *) &req->headers[i+1][6],
|
(unsigned char *) &req->headers[i+1][6],
|
||||||
@ -790,8 +795,8 @@ int uh_auth_check(
|
|||||||
|
|
||||||
if ((plen >= rlen) &&
|
if ((plen >= rlen) &&
|
||||||
!strncasecmp(pi->name, realm->path, rlen) &&
|
!strncasecmp(pi->name, realm->path, rlen) &&
|
||||||
!strcmp(user, realm->user)
|
!strcmp(user, realm->user))
|
||||||
) {
|
{
|
||||||
req->realm = realm;
|
req->realm = realm;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -933,8 +938,7 @@ struct interpreter * uh_interpreter_add(const char *extn, const char *path)
|
|||||||
{
|
{
|
||||||
struct interpreter *new = NULL;
|
struct interpreter *new = NULL;
|
||||||
|
|
||||||
if( (new = (struct interpreter *)
|
if ((new = (struct interpreter *)malloc(sizeof(struct interpreter))) != NULL)
|
||||||
malloc(sizeof(struct interpreter))) != NULL )
|
|
||||||
{
|
{
|
||||||
memset(new, 0, sizeof(struct interpreter));
|
memset(new, 0, sizeof(struct interpreter));
|
||||||
|
|
||||||
|
@ -69,7 +69,9 @@ static void uh_config_parse(struct config *conf)
|
|||||||
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
||||||
!(col2 = strchr(col1, ':')) || (*col2++ = 0) ||
|
!(col2 = strchr(col1, ':')) || (*col2++ = 0) ||
|
||||||
!(eol = strchr(col2, '\n')) || (*eol++ = 0))
|
!(eol = strchr(col2, '\n')) || (*eol++ = 0))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!uh_auth_add(line, col1, col2))
|
if (!uh_auth_add(line, col1, col2))
|
||||||
{
|
{
|
||||||
@ -83,7 +85,9 @@ static void uh_config_parse(struct config *conf)
|
|||||||
{
|
{
|
||||||
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
||||||
!(eol = strchr(col1, '\n')) || (*eol++ = 0))
|
!(eol = strchr(col1, '\n')) || (*eol++ = 0))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
conf->index_file = strdup(col1);
|
conf->index_file = strdup(col1);
|
||||||
}
|
}
|
||||||
@ -91,7 +95,9 @@ static void uh_config_parse(struct config *conf)
|
|||||||
{
|
{
|
||||||
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
if (!(col1 = strchr(line, ':')) || (*col1++ = 0) ||
|
||||||
!(eol = strchr(col1, '\n')) || (*eol++ = 0))
|
!(eol = strchr(col1, '\n')) || (*eol++ = 0))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
conf->error_handler = strdup(col1);
|
conf->error_handler = strdup(col1);
|
||||||
}
|
}
|
||||||
@ -101,7 +107,9 @@ static void uh_config_parse(struct config *conf)
|
|||||||
if (!(col1 = strchr(line, '*')) || (*col1++ = 0) ||
|
if (!(col1 = strchr(line, '*')) || (*col1++ = 0) ||
|
||||||
!(col2 = strchr(col1, ':')) || (*col2++ = 0) ||
|
!(col2 = strchr(col1, ':')) || (*col2++ = 0) ||
|
||||||
!(eol = strchr(col2, '\n')) || (*eol++ = 0))
|
!(eol = strchr(col2, '\n')) || (*eol++ = 0))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!uh_interpreter_add(col1, col2))
|
if (!uh_interpreter_add(col1, col2))
|
||||||
{
|
{
|
||||||
@ -118,10 +126,11 @@ static void uh_config_parse(struct config *conf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int uh_socket_bind(
|
static int uh_socket_bind(fd_set *serv_fds, int *max_fd,
|
||||||
fd_set *serv_fds, int *max_fd, const char *host, const char *port,
|
const char *host, const char *port,
|
||||||
struct addrinfo *hints, int do_tls, struct config *conf
|
struct addrinfo *hints, int do_tls,
|
||||||
) {
|
struct config *conf)
|
||||||
|
{
|
||||||
int sock = -1;
|
int sock = -1;
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
int status;
|
int status;
|
||||||
@ -225,7 +234,8 @@ static int uh_socket_bind(
|
|||||||
return bound;
|
return bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct http_request * uh_http_header_parse(struct client *cl, char *buffer, int buflen)
|
static struct http_request * uh_http_header_parse(struct client *cl,
|
||||||
|
char *buffer, int buflen)
|
||||||
{
|
{
|
||||||
char *method = &buffer[0];
|
char *method = &buffer[0];
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
@ -338,8 +348,8 @@ static struct http_request * uh_http_header_parse(struct client *cl, char *buffe
|
|||||||
|
|
||||||
/* have name but no value and found a colon, start of value */
|
/* have name but no value and found a colon, start of value */
|
||||||
else if (hdrname && !hdrdata &&
|
else if (hdrname && !hdrdata &&
|
||||||
((i+1) < buflen) && (buffer[i] == ':')
|
((i+1) < buflen) && (buffer[i] == ':'))
|
||||||
) {
|
{
|
||||||
buffer[i] = 0;
|
buffer[i] = 0;
|
||||||
hdrdata = &buffer[i+1];
|
hdrdata = &buffer[i+1];
|
||||||
|
|
||||||
@ -437,8 +447,8 @@ static int uh_path_match(const char *prefix, const char *url)
|
|||||||
if ((strstr(url, prefix) == url) &&
|
if ((strstr(url, prefix) == url) &&
|
||||||
((prefix[strlen(prefix)-1] == '/') ||
|
((prefix[strlen(prefix)-1] == '/') ||
|
||||||
(strlen(url) == strlen(prefix)) ||
|
(strlen(url) == strlen(prefix)) ||
|
||||||
(url[strlen(prefix)] == '/'))
|
(url[strlen(prefix)] == '/')))
|
||||||
) {
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,9 +456,9 @@ static int uh_path_match(const char *prefix, const char *url)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void uh_dispatch_request(
|
static void uh_dispatch_request(struct client *cl, struct http_request *req,
|
||||||
struct client *cl, struct http_request *req, struct path_info *pin
|
struct path_info *pin)
|
||||||
) {
|
{
|
||||||
#ifdef HAVE_CGI
|
#ifdef HAVE_CGI
|
||||||
struct interpreter *ipr = NULL;
|
struct interpreter *ipr = NULL;
|
||||||
|
|
||||||
@ -543,7 +553,8 @@ static void uh_mainloop(struct config *conf, fd_set serv_fds, int max_fd)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"uh_client_add(): Cannot allocate memory\n");
|
"uh_client_add(): "
|
||||||
|
"Cannot allocate memory\n");
|
||||||
|
|
||||||
close(new_fd);
|
close(new_fd);
|
||||||
}
|
}
|
||||||
@ -668,8 +679,8 @@ static inline int uh_inittls(struct config *conf)
|
|||||||
!(conf->tls_accept = dlsym(lib, "uh_tls_client_accept")) ||
|
!(conf->tls_accept = dlsym(lib, "uh_tls_client_accept")) ||
|
||||||
!(conf->tls_close = dlsym(lib, "uh_tls_client_close")) ||
|
!(conf->tls_close = dlsym(lib, "uh_tls_client_close")) ||
|
||||||
!(conf->tls_recv = dlsym(lib, "uh_tls_client_recv")) ||
|
!(conf->tls_recv = dlsym(lib, "uh_tls_client_recv")) ||
|
||||||
!(conf->tls_send = dlsym(lib, "uh_tls_client_send"))
|
!(conf->tls_send = dlsym(lib, "uh_tls_client_send")))
|
||||||
) {
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error: Failed to lookup required symbols "
|
"Error: Failed to lookup required symbols "
|
||||||
"in TLS plugin: %s\n", dlerror()
|
"in TLS plugin: %s\n", dlerror()
|
||||||
@ -756,8 +767,8 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv,
|
while ((opt = getopt(argc, argv,
|
||||||
"fSDRC:K:E:I:p:s:h:c:l:L:d:r:m:x:i:t:T:A:")) > 0
|
"fSDRC:K:E:I:p:s:h:c:l:L:d:r:m:x:i:t:T:A:")) > 0)
|
||||||
) {
|
{
|
||||||
switch(opt)
|
switch(opt)
|
||||||
{
|
{
|
||||||
/* [addr:]port */
|
/* [addr:]port */
|
||||||
@ -796,10 +807,9 @@ int main (int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* bind sockets */
|
/* bind sockets */
|
||||||
bound += uh_socket_bind(
|
bound += uh_socket_bind(&serv_fds, &max_fd,
|
||||||
&serv_fds, &max_fd, bind[0] ? bind : NULL, port,
|
bind[0] ? bind : NULL,
|
||||||
&hints, (opt == 's'), &conf
|
port, &hints, (opt == 's'), &conf);
|
||||||
);
|
|
||||||
|
|
||||||
memset(bind, 0, sizeof(bind));
|
memset(bind, 0, sizeof(bind));
|
||||||
break;
|
break;
|
||||||
@ -1065,16 +1075,15 @@ int main (int argc, char **argv)
|
|||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Notice: Unable to load Lua plugin - disabling Lua support! "
|
"Notice: Unable to load Lua plugin - disabling Lua support! "
|
||||||
"(Reason: %s)\n", dlerror()
|
"(Reason: %s)\n", dlerror());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* resolve functions */
|
/* resolve functions */
|
||||||
if (!(conf.lua_init = dlsym(lib, "uh_lua_init")) ||
|
if (!(conf.lua_init = dlsym(lib, "uh_lua_init")) ||
|
||||||
!(conf.lua_close = dlsym(lib, "uh_lua_close")) ||
|
!(conf.lua_close = dlsym(lib, "uh_lua_close")) ||
|
||||||
!(conf.lua_request = dlsym(lib, "uh_lua_request"))
|
!(conf.lua_request = dlsym(lib, "uh_lua_request")))
|
||||||
) {
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error: Failed to lookup required symbols "
|
"Error: Failed to lookup required symbols "
|
||||||
"in Lua plugin: %s\n", dlerror()
|
"in Lua plugin: %s\n", dlerror()
|
||||||
|
Loading…
Reference in New Issue
Block a user