X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuhttpd.git;a=blobdiff_plain;f=handler.c;h=04e71e0f9ef65f6d99f6d3e82917916fbe2b5616;hp=6ec18af027710f4cb82d628c344d2f00e922cd15;hb=a8bf9c00842224edb394e79909053f7628ee6a82;hpb=c86ae76cad0f94be49fdc78699784d105f58d9a1 diff --git a/handler.c b/handler.c index 6ec18af..04e71e0 100644 --- a/handler.c +++ b/handler.c @@ -41,19 +41,30 @@ static void handle_redirect(struct json_script_ctx *ctx, struct blob_attr *data) { struct client *cl = cur_client; - static struct blobmsg_policy policy = { - .type = BLOBMSG_TYPE_STRING, + static struct blobmsg_policy policy[3] = { + { .type = BLOBMSG_TYPE_STRING }, + { .type = BLOBMSG_TYPE_INT32 }, + { .type = BLOBMSG_TYPE_STRING }, }; - struct blob_attr *tb; + struct blob_attr *tb[3]; + const char *status = "Found"; + int code = 302; - blobmsg_parse_array(&policy, 1, &tb, blobmsg_data(data), blobmsg_data_len(data)); - if (!tb) + blobmsg_parse_array(policy, ARRAY_SIZE(policy), tb, blobmsg_data(data), blobmsg_data_len(data)); + if (!tb[0]) return; - uh_http_header(cl, 302, "Found"); - ustream_printf(cl->us, "Content-Length: 0\r\n"); + if (tb[1]) { + code = blobmsg_get_u32(tb[1]); + if (tb[2]) + status = blobmsg_get_string(tb[2]); + } + + uh_http_header(cl, code, status); + if (!uh_use_chunked(cl)) + ustream_printf(cl->us, "Content-Length: 0\r\n"); ustream_printf(cl->us, "Location: %s\r\n\r\n", - blobmsg_get_string(tb)); + blobmsg_get_string(tb[0])); uh_request_done(cl); *cur_url = NULL; @@ -92,6 +103,32 @@ handle_set_uri(struct json_script_ctx *ctx, struct blob_attr *data) } 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) { @@ -100,7 +137,9 @@ 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 } + { "rewrite", handle_set_uri }, + { "add-header", handle_add_header }, + { "no-cache", handle_no_cache }, }; int i;