diff --git a/include/lander.h b/include/lander.h index 96efca9..76fdf17 100644 --- a/include/lander.h +++ b/include/lander.h @@ -68,6 +68,8 @@ lnm_http_step_err lander_post_file_secure(lnm_http_conn *conn); lnm_http_step_err lander_post_index(lnm_http_conn *conn); +lnm_http_step_err lander_post_index_secure(lnm_http_conn *conn); + /** * Store the requested header as an attribute, if it's present. */ diff --git a/src/lander/lander_post.c b/src/lander/lander_post.c index 89aecda..0572c9a 100644 --- a/src/lander/lander_post.c +++ b/src/lander/lander_post.c @@ -148,11 +148,11 @@ lnm_http_step_err lander_post_file_secure(lnm_http_conn *conn) { return __lander_post_file(conn, true); } -lnm_http_step_err lander_post_index(lnm_http_conn *conn) { +static lnm_http_step_err __lander_post_index(lnm_http_conn *conn, bool secure) { lnm_http_loop_ctx *ctx = conn->ctx; lander_ctx *c_ctx = ctx->c; - if (!lander_insert_entry(ctx)) { + if (!lander_insert_entry(ctx, secure)) { return lnm_http_step_err_res; } @@ -165,3 +165,11 @@ lnm_http_step_err lander_post_index(lnm_http_conn *conn) { return lnm_http_step_err_done; } + +lnm_http_step_err lander_post_index(lnm_http_conn *conn) { + return __lander_post_index(conn, false); +} + +lnm_http_step_err lander_post_index_secure(lnm_http_conn *conn) { + return __lander_post_index(conn, true); +} diff --git a/src/main.c b/src/main.c index e55e9df..84deafd 100644 --- a/src/main.c +++ b/src/main.c @@ -72,7 +72,6 @@ lnm_http_loop *loop_init(lander_gctx *gctx, const char *api_key) { lnm_http_route_step_append(route, lnm_http_loop_step_body_to_buf, false); lnm_http_route_step_append(route, lander_post_redirect_body_to_attr, false); -<<<<<<< HEAD lnm_http_router_add(&route, router, lnm_http_method_post, "/sl/"); lnm_http_route_step_append(route, lnm_http_loop_step_auth, false); lnm_http_route_step_append(route, lander_post_redirect_secure, false); @@ -115,22 +114,20 @@ lnm_http_loop *loop_init(lander_gctx *gctx, const char *api_key) { lnm_http_route_step_append(route, lander_post_file, false); lnm_http_route_step_append(route, lander_stream_body_to_entry, false); + lnm_http_router_add(&route, router, lnm_http_method_post, "/i/"); + lnm_http_route_step_append(route, lnm_http_loop_step_auth, false); + lnm_http_route_step_append(route, lander_post_index, false); + + lnm_http_router_add(&route, router, lnm_http_method_post, "/il/"); + lnm_http_route_step_append(route, lnm_http_loop_step_auth, false); + lnm_http_route_step_append(route, lander_post_index_secure, false); + + lnm_http_router_add(&route, router, lnm_http_method_post, "/i/:key"); + lnm_http_route_step_append(route, lnm_http_loop_step_auth, false); + lnm_http_route_step_append(route, lander_post_index, false); + lnm_http_loop_router_set(hl, router); - lnm_http_step_init(&step, lnm_http_loop_step_auth); - lnm_http_route_init_regex(&route, lnm_http_method_post, "^/i(l?)/([^/]+)$", 2, - step); - lnm_http_step_append(&step, step, lander_post_index); - /* lnm_http_step_append(&step, step, lnm_http_loop_step_body_to_buf); */ - /* lnm_http_step_append(&step, step, lander_post_redirect_body_to_attr); */ - lnm_http_loop_route_add(hl, route); - - lnm_http_step_init(&step, lnm_http_loop_step_auth); - lnm_http_route_init_regex(&route, lnm_http_method_delete, "^/([^/]+)$", 1, - step); - lnm_http_step_append(&step, step, lander_remove_entry); - lnm_http_loop_route_add(hl, route); - return hl; }