diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-10-06 21:07:59 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-10-06 21:07:59 +0200 |
| commit | 11ea1cc36a03cc1b68a57ab66a17ec249cb612a6 (patch) | |
| tree | dd4050b6d96c3f0f2f23700dce0fdab169828d49 | |
| parent | 8e48f19b6ca68d525723ac049e984146f8bc17f1 (diff) | |
page.c: Report logged user name on directory preview
Thanks to Avron for the suggestion. [1]
[1]: https://codeberg.org/xavidcr/slcl/issues/2
| -rw-r--r-- | page.c | 53 |
1 files changed, 39 insertions, 14 deletions
@@ -954,52 +954,76 @@ end: return ret; } -static int prepare_logout_form(struct html_node *const n) +static int prepare_logout_form(struct html_node *const n, + const char *const username) { - struct html_node *div, *form, *input; + int ret = -1; + struct dynstr d; + struct html_node *div, *label, *form, *input; + + dynstr_init(&d); if (!(div = html_node_add_child(n, "div"))) { fprintf(stderr, "%s: html_node_add_child div failed\n", __func__); - return -1; + goto end; + } + else if (!(label = html_node_add_child(div, "label"))) + { + fprintf(stderr, "%s: html_node_add_child label failed\n", __func__); + goto end; } else if (!(form = html_node_add_child(div, "form"))) { fprintf(stderr, "%s: html_node_add_child form failed\n", __func__); - return -1; + goto end; } else if (!(input = html_node_add_child(form, "input"))) { fprintf(stderr, "%s: html_node_add_child input failed\n", __func__); - return -1; + goto end; } else if (html_node_add_attr(div, "class", "userform")) { fprintf(stderr, "%s: html_node_add_attr div failed\n", __func__); - return -1; + goto end; + } + else if (dynstr_append(&d, "Logged in as %s", username)) + { + fprintf(stderr, "%s: dynstr_append failed\n", __func__); + goto end; + } + else if (html_node_set_value(label, d.str)) + { + fprintf(stderr, "%s: html_node_add_attr div failed\n", __func__); + goto end; } else if (html_node_add_attr(form, "method", "post")) { fprintf(stderr, "%s: html_node_add_attr method failed\n", __func__); - return -1; + goto end; } else if (html_node_add_attr(form, "action", "/logout")) { fprintf(stderr, "%s: html_node_add_attr action failed\n", __func__); - return -1; + goto end; } else if (html_node_add_attr(input, "type", "submit")) { fprintf(stderr, "%s: html_node_add_attr type failed\n", __func__); - return -1; + goto end; } else if (html_node_add_attr(input, "value", "Logout")) { fprintf(stderr, "%s: html_node_add_attr value failed\n", __func__); - return -1; + goto end; } - return 0; + ret = 0; + +end: + dynstr_free(&d); + return ret; } static int prepare_footer(struct html_node *const n) @@ -1133,7 +1157,7 @@ end: static struct html_node *resource_layout(const char *const dir, const struct page_quota *const q, struct html_node **const body, - struct html_node **const table) + struct html_node **const table, const char *const username) { const char *const fdir = dir + strlen("/user"); struct html_node *const html = html_node_alloc("html"), @@ -1194,7 +1218,7 @@ static struct html_node *resource_layout(const char *const dir, fprintf(stderr, "%s: prepare_quota_form failed\n", __func__); goto end; } - else if (prepare_logout_form(*body)) + else if (prepare_logout_form(*body, username)) { fprintf(stderr, "%s: prepare_logout_form failed\n", __func__); goto end; @@ -1615,7 +1639,8 @@ static int list_dir(const struct page_resource *const pr) int ret = -1; struct dynstr out; struct html_node *table, *body, - *const html = resource_layout(pr->dir, pr->q, &body, &table); + *const html = resource_layout(pr->dir, pr->q, &body, &table, + pr->username); struct element_stats st; dynstr_init(&out); |
