Sync ubus familly tools.

This commit is contained in:
2017-04-08 21:34:59 +02:00
parent 0e9f199c9c
commit 63d0813f93
57 changed files with 413 additions and 564 deletions

View File

@@ -21,9 +21,6 @@ IF(LIBS STREQUAL "LIBS-NOTFOUND")
SET(LIBS "")
ENDIF()
FIND_PATH(ubox_include_dir libubox/usock.h)
INCLUDE_DIRECTORIES(${ubox_include_dir})
SET(SOURCES main.c listen.c client.c utils.c file.c auth.c cgi.c relay.c proc.c plugin.c handler.c)
IF(TLS_SUPPORT)
SET(SOURCES ${SOURCES} tls.c)

View File

@@ -104,11 +104,7 @@ static bool check_cgi_path(struct path_info *pi, const char *url)
}
pi->ip = NULL;
if (conf.cgi_docroot_path)
return uh_path_match(conf.cgi_docroot_path, pi->phys);
return false;
return uh_path_match(conf.cgi_docroot_path, pi->phys);
}
struct dispatch_handler cgi_dispatch = {

View File

@@ -45,10 +45,8 @@ const char * const http_methods[] = {
void uh_http_header(struct client *cl, int code, const char *summary)
{
struct http_request *r = &cl->request;
struct blob_attr *cur;
const char *enc = "Transfer-Encoding: chunked\r\n";
const char *conn;
int rem;
cl->http_code = code;
@@ -66,10 +64,6 @@ void uh_http_header(struct client *cl, int code, const char *summary)
if (!r->connection_close)
ustream_printf(cl->us, "Keep-Alive: timeout=%d\r\n", conf.http_keepalive);
blobmsg_for_each_attr(cur, cl->hdr_response.head, rem)
ustream_printf(cl->us, "%s: %s\r\n", blobmsg_name(cur),
blobmsg_get_string(cur));
}
static void uh_connection_close(struct client *cl)
@@ -120,7 +114,6 @@ void uh_request_done(struct client *cl)
{
uh_chunk_eof(cl);
uh_dispatch_done(cl);
blob_buf_init(&cl->hdr_response, 0);
memset(&cl->dispatch, 0, sizeof(cl->dispatch));
if (!conf.http_keepalive || cl->request.connection_close)
@@ -537,7 +530,6 @@ static void client_close(struct client *cl)
close(cl->sfd.fd.fd);
list_del(&cl->list);
blob_buf_free(&cl->hdr);
blob_buf_free(&cl->hdr_response);
free(cl);
uh_unblock_listeners();

View File

@@ -565,12 +565,11 @@ static void uh_file_free(struct client *cl)
static void uh_file_data(struct client *cl, struct path_info *pi, int fd)
{
/* test preconditions */
if (!cl->dispatch.no_cache &&
(!uh_file_if_modified_since(cl, &pi->stat) ||
!uh_file_if_match(cl, &pi->stat) ||
!uh_file_if_range(cl, &pi->stat) ||
!uh_file_if_unmodified_since(cl, &pi->stat) ||
!uh_file_if_none_match(cl, &pi->stat))) {
if (!uh_file_if_modified_since(cl, &pi->stat) ||
!uh_file_if_match(cl, &pi->stat) ||
!uh_file_if_range(cl, &pi->stat) ||
!uh_file_if_unmodified_since(cl, &pi->stat) ||
!uh_file_if_none_match(cl, &pi->stat)) {
ustream_printf(cl->us, "\r\n");
uh_request_done(cl);
close(fd);
@@ -864,7 +863,6 @@ void uh_handle_request(struct client *cl)
char *url = blobmsg_data(blob_data(cl->hdr.head));
char *error_handler;
blob_buf_init(&cl->hdr_response, 0);
url = uh_handle_alias(url);
uh_handler_run(cl, &url, false);
@@ -879,14 +877,9 @@ void uh_handle_request(struct client *cl)
if (__handle_file_request(cl, url))
return;
if (uh_handler_run(cl, &url, true)) {
if (!url)
return;
uh_handler_run(cl, &url, false);
if (__handle_file_request(cl, url))
return;
}
if (uh_handler_run(cl, &url, true) &&
(!url || __handle_file_request(cl, url)))
return;
req->redirect_status = 404;
if (conf.error_handler) {

View File

@@ -102,32 +102,6 @@ handle_set_uri(struct json_script_ctx *ctx, struct blob_attr *data)
json_script_abort(ctx);
}
static void
handle_add_header(struct json_script_ctx *ctx, struct blob_attr *data)
{
struct client *cl = cur_client;
static struct blobmsg_policy policy[2] = {
{ .type = BLOBMSG_TYPE_STRING },
{ .type = BLOBMSG_TYPE_STRING },
};
struct blob_attr *tb[2];
blobmsg_parse_array(policy, ARRAY_SIZE(tb), tb, blobmsg_data(data), blobmsg_data_len(data));
if (!tb[0] || !tb[1])
return;
blobmsg_add_string(&cl->hdr_response, blobmsg_get_string(tb[0]),
blobmsg_get_string(tb[1]));
}
static void
handle_no_cache(struct json_script_ctx *ctx, struct blob_attr *data)
{
struct client *cl = cur_client;
cl->dispatch.no_cache = true;
}
static void
handle_command(struct json_script_ctx *ctx, const char *name,
struct blob_attr *data, struct blob_attr *vars)
@@ -137,9 +111,7 @@ handle_command(struct json_script_ctx *ctx, const char *name,
void (*func)(struct json_script_ctx *ctx, struct blob_attr *data);
} cmds[] = {
{ "redirect", handle_redirect },
{ "rewrite", handle_set_uri },
{ "add-header", handle_add_header },
{ "no-cache", handle_no_cache },
{ "rewrite", handle_set_uri }
};
int i;

View File

@@ -224,7 +224,6 @@ struct dispatch {
void (*req_free)(struct client *cl);
bool data_blocked;
bool no_cache;
union {
struct {
@@ -259,7 +258,6 @@ struct client {
struct uh_addr srv_addr, peer_addr;
struct blob_buf hdr;
struct blob_buf hdr_response;
struct dispatch dispatch;
};

View File

@@ -208,10 +208,6 @@ bool uh_path_match(const char *prefix, const char *url)
{
int len = strlen(prefix);
/* A prefix of "/" will - by definition - match any url */
if (prefix[0] == '/' && len == 1)
return true;
if (strncmp(url, prefix, len) != 0)
return false;