32 lines
783 B
C
32 lines
783 B
C
#include "lnm/http/req.h"
|
|
#include "lnm/loop.h"
|
|
|
|
#include "lander.h"
|
|
|
|
lnm_http_step_err lander_remove_entry(lnm_http_conn *conn) {
|
|
lnm_http_loop_ctx *ctx = conn->ctx;
|
|
lander_ctx *c_ctx = ctx->c;
|
|
lnm_http_loop_gctx *gctx = ctx->g;
|
|
lander_gctx *c_gctx = gctx->c;
|
|
|
|
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);
|
|
|
|
switch (lsm_store_open_write(&c_ctx->entry, c_gctx->store, key)) {
|
|
case lsm_error_ok:
|
|
lsm_entry_remove(c_ctx->entry);
|
|
break;
|
|
case lsm_error_not_found:
|
|
ctx->res.status = lnm_http_status_not_found;
|
|
break;
|
|
default:
|
|
ctx->res.status = lnm_http_status_internal_server_error;
|
|
break;
|
|
}
|
|
|
|
return lnm_http_step_err_done;
|
|
}
|