feat(lander): store entry type as single byte
This commit is contained in:
parent
9c03a36aa2
commit
0efcdece48
4 changed files with 57 additions and 43 deletions
|
|
@ -26,35 +26,6 @@ bool lander_get_index(event_loop_conn *conn) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool lander_get_entry(event_loop_conn *conn) {
|
||||
http_loop_ctx *ctx = conn->ctx;
|
||||
lander_gctx *c_gctx = ctx->g->c;
|
||||
|
||||
const char *key = &ctx->req.path[ctx->req.regex_groups[1].rm_so];
|
||||
int key_len = ctx->req.regex_groups[1].rm_eo - ctx->req.regex_groups[1].rm_so;
|
||||
|
||||
Entry *entry;
|
||||
TrieExitCode res = trie_search_len(c_gctx->trie, &entry, key, key_len);
|
||||
|
||||
if (res == NotFound) {
|
||||
ctx->res.status = http_not_found;
|
||||
} else if (entry->type == Redirect) {
|
||||
ctx->res.status = http_moved_permanently;
|
||||
http_res_add_header(&ctx->res, http_header_location, entry->string, false);
|
||||
} else if (entry->type == Paste) {
|
||||
char fname[strlen(c_gctx->data_dir) + 8 + key_len + 1];
|
||||
sprintf(fname, "%s/pastes/%.*s", c_gctx->data_dir, key_len, key);
|
||||
|
||||
http_res_set_body_file(&ctx->res, fname);
|
||||
// TODO don't call everything a text file
|
||||
http_res_set_mime_type(&ctx->res, http_mime_txt);
|
||||
}
|
||||
|
||||
conn->state = event_loop_conn_state_res;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lander_get_entry_lsm(event_loop_conn *conn) {
|
||||
http_loop_ctx *ctx = conn->ctx;
|
||||
lander_ctx *c_ctx = ctx->c;
|
||||
|
|
@ -79,8 +50,8 @@ bool lander_get_entry_lsm(event_loop_conn *conn) {
|
|||
}
|
||||
|
||||
lander_entry_type t;
|
||||
lsm_entry_attr_get_num((uint64_t *)&t, c_ctx->entry,
|
||||
lander_attr_type_entry_type);
|
||||
lsm_entry_attr_get_uint8_t((uint8_t *)&t, c_ctx->entry,
|
||||
lander_attr_type_entry_type);
|
||||
|
||||
if (t == lander_entry_type_redirect) {
|
||||
// For redirects, the URL is stored as an in-memory attribute
|
||||
|
|
@ -113,6 +84,7 @@ bool lander_get_entry_lsm(event_loop_conn *conn) {
|
|||
c_ctx->entry = NULL;
|
||||
} else {
|
||||
ctx->res.body.expected_len = lsm_entry_data_len(c_ctx->entry);
|
||||
http_res_set_mime_type(&ctx->res, http_mime_txt);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -132,8 +132,8 @@ bool lander_post_redirect_lsm(event_loop_conn *conn) {
|
|||
return true;
|
||||
}
|
||||
|
||||
lsm_entry_attr_insert_num(c_ctx->entry, lander_attr_type_entry_type,
|
||||
lander_entry_type_redirect);
|
||||
lsm_entry_attr_insert_uint8_t(c_ctx->entry, lander_attr_type_entry_type,
|
||||
lander_entry_type_redirect);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -171,8 +171,8 @@ bool lander_post_paste_lsm(event_loop_conn *conn) {
|
|||
return true;
|
||||
}
|
||||
|
||||
lsm_entry_attr_insert_num(c_ctx->entry, lander_attr_type_entry_type,
|
||||
lander_entry_type_paste);
|
||||
lsm_entry_attr_insert_uint8_t(c_ctx->entry, lander_attr_type_entry_type,
|
||||
lander_entry_type_paste);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue