refactor(lander): fully integrate new lnm framework router
ci/woodpecker/push/build Pipeline was successful Details

new-lnm-integration
Jef Roosens 2024-03-03 09:41:56 +01:00
parent 44ba4b053e
commit 94da7584aa
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 77 additions and 38 deletions

View File

@ -43,8 +43,12 @@ lnm_http_step_err lander_get_entry(lnm_http_conn *conn);
lnm_http_step_err lander_post_redirect(lnm_http_conn *conn);
lnm_http_step_err lander_post_redirect_secure(lnm_http_conn *conn);
lnm_http_step_err lander_post_paste(lnm_http_conn *conn);
lnm_http_step_err lander_post_paste_secure(lnm_http_conn *conn);
lnm_http_step_err lander_stream_body_to_entry(lnm_http_conn *conn);
lnm_http_step_err lander_post_redirect_body_to_attr(lnm_http_conn *conn);
@ -53,6 +57,8 @@ lnm_http_step_err lander_remove_entry(lnm_http_conn *conn);
lnm_http_step_err lander_post_file(lnm_http_conn *conn);
lnm_http_step_err lander_post_file_secure(lnm_http_conn *conn);
/**
* Store the requested header as an attribute, if it's present.
*/

View File

@ -1,3 +1,4 @@
#include "lnm/http/req.h"
#include "lnm/loop.h"
#include "lander.h"
@ -8,9 +9,8 @@ lnm_http_step_err lander_remove_entry(lnm_http_conn *conn) {
lnm_http_loop_gctx *gctx = ctx->g;
lander_gctx *c_gctx = gctx->c;
const char *key_s =
&ctx->req.buf.s[ctx->req.path.o + ctx->req.path.groups[1].rm_so];
int key_len = ctx->req.path.groups[1].rm_eo - ctx->req.path.groups[1].rm_so;
const char *key_s;
size_t key_len = lnm_http_req_route_segment(&key_s, &ctx->req, "key");
lsm_str *key;
lsm_str_init_copy_n(&key, (char *)key_s, key_len);

View File

@ -1,7 +1,7 @@
#include <string.h>
#include "lnm/loop.h"
#include "lnm/http/req.h"
#include "lnm/loop.h"
#include "lsm/store.h"
#include "lander.h"
@ -66,11 +66,12 @@ bool lander_insert_entry(lnm_http_loop_ctx *ctx, bool secure) {
return true;
}
lnm_http_step_err lander_post_redirect(lnm_http_conn *conn) {
static lnm_http_step_err __lander_post_redirect(lnm_http_conn *conn,
bool secure) {
lnm_http_loop_ctx *ctx = conn->ctx;
lander_ctx *c_ctx = ctx->c;
if (!lander_insert_entry(ctx, false)) {
if (!lander_insert_entry(ctx, secure)) {
return lnm_http_step_err_res;
}
@ -80,6 +81,14 @@ lnm_http_step_err lander_post_redirect(lnm_http_conn *conn) {
return lnm_http_step_err_done;
}
lnm_http_step_err lander_post_redirect(lnm_http_conn *conn) {
return __lander_post_redirect(conn, false);
}
lnm_http_step_err lander_post_redirect_secure(lnm_http_conn *conn) {
return __lander_post_redirect(conn, true);
}
lnm_http_step_err lander_post_redirect_body_to_attr(lnm_http_conn *conn) {
lnm_http_loop_ctx *ctx = conn->ctx;
lander_ctx *c_ctx = ctx->c;
@ -91,11 +100,11 @@ lnm_http_step_err lander_post_redirect_body_to_attr(lnm_http_conn *conn) {
return lnm_http_step_err_done;
}
lnm_http_step_err lander_post_paste(lnm_http_conn *conn) {
static lnm_http_step_err __lander_post_paste(lnm_http_conn *conn, bool secure) {
lnm_http_loop_ctx *ctx = conn->ctx;
lander_ctx *c_ctx = ctx->c;
if (!lander_insert_entry(ctx, false)) {
if (!lander_insert_entry(ctx, secure)) {
return lnm_http_step_err_res;
}
@ -106,11 +115,19 @@ lnm_http_step_err lander_post_paste(lnm_http_conn *conn) {
return lnm_http_step_err_done;
}
lnm_http_step_err lander_post_file(lnm_http_conn *conn) {
lnm_http_step_err lander_post_paste(lnm_http_conn *conn) {
return __lander_post_paste(conn, false);
}
lnm_http_step_err lander_post_paste_secure(lnm_http_conn *conn) {
return __lander_post_paste(conn, true);
}
static lnm_http_step_err __lander_post_file(lnm_http_conn *conn, bool secure) {
lnm_http_loop_ctx *ctx = conn->ctx;
lander_ctx *c_ctx = ctx->c;
if (!lander_insert_entry(ctx, false)) {
if (!lander_insert_entry(ctx, secure)) {
return lnm_http_step_err_res;
}
@ -122,3 +139,11 @@ lnm_http_step_err lander_post_file(lnm_http_conn *conn) {
return lnm_http_step_err_done;
}
lnm_http_step_err lander_post_file(lnm_http_conn *conn) {
return __lander_post_file(conn, false);
}
lnm_http_step_err lander_post_file_secure(lnm_http_conn *conn) {
return __lander_post_file(conn, true);
}

View File

@ -28,50 +28,58 @@ lnm_http_loop *loop_init(lander_gctx *gctx, const char *api_key) {
lnm_http_router_add(&route, router, lnm_http_method_get, "/:key");
lnm_http_route_step_append(route, lander_get_entry, false);
lnm_http_router_add(&route, router, lnm_http_method_delete, "/:key");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
lnm_http_route_step_append(route, lander_remove_entry, false);
lnm_http_router_add(&route, router, lnm_http_method_post, "/s/");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
lnm_http_route_step_append(route, lander_post_redirect, false);
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);
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);
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);
lnm_http_router_add(&route, router, lnm_http_method_post, "/s/:key");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
lnm_http_route_step_append(route, lander_post_redirect, false);
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);
lnm_http_router_add(&route, router, lnm_http_method_post, "/p/");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
lnm_http_route_step_append(route, lander_post_paste, false);
lnm_http_route_step_append(route, lander_stream_body_to_entry, false);
lnm_http_router_add(&route, router, lnm_http_method_post, "/pl/");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
lnm_http_route_step_append(route, lander_post_paste_secure, false);
lnm_http_route_step_append(route, lander_stream_body_to_entry, false);
lnm_http_router_add(&route, router, lnm_http_method_post, "/p/:key");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
lnm_http_route_step_append(route, lander_post_paste, false);
lnm_http_route_step_append(route, lander_stream_body_to_entry, false);
lnm_http_router_add(&route, router, lnm_http_method_post, "/f/");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
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, "/fl/");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
lnm_http_route_step_append(route, lander_post_file_secure, false);
lnm_http_route_step_append(route, lander_stream_body_to_entry, false);
lnm_http_router_add(&route, router, lnm_http_method_post, "/f/:key");
lnm_http_route_step_append(route, lnm_http_loop_step_auth, false);
lnm_http_route_step_append(route, lander_post_file, false);
lnm_http_route_step_append(route, lander_stream_body_to_entry, false);
/* lnm_http_step_init(&step, lnm_http_loop_step_auth); */
/* lnm_http_route_init_regex(&route, lnm_http_method_post, "^/s(l?)/([^/]*)$", 2, */
/* step); */
/* lnm_http_step_append(&step, step, lander_post_redirect); */
/* 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_post, "^/p(l?)/([^/]*)$", 2, */
/* step); */
/* lnm_http_step_append(&step, step, lander_post_paste); */
/* lnm_http_step_append(&step, step, lander_stream_body_to_entry); */
/* 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_post, "^/f(l?)/([^/]*)$", 2, */
/* step); */
/* lnm_http_step_append(&step, step, lander_post_file); */
/* lnm_http_step_append(&step, step, lander_stream_body_to_entry); */
/* 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); */
lnm_http_loop_router_set(hl, router);
return hl;