aboutsummaryrefslogtreecommitdiff
path: root/form_footer.c
diff options
context:
space:
mode:
Diffstat (limited to 'form_footer.c')
-rw-r--r--form_footer.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/form_footer.c b/form_footer.c
new file mode 100644
index 0000000..c29dfd4
--- /dev/null
+++ b/form_footer.c
@@ -0,0 +1,105 @@
+#include "form.h"
+#include "defs.h"
+#include <libweb/html.h>
+#include <stdio.h>
+#include <string.h>
+
+static int poweredby(struct html_node *const footer)
+{
+ int ret = -1;
+ struct html_node *const a = html_node_alloc("a"), *p;
+ struct dynstr d;
+
+ dynstr_init(&d);
+
+ if (!a)
+ {
+ fprintf(stderr, "%s: html_node_alloc failed\n", __func__);
+ goto end;
+ }
+ else if (!(p = html_node_add_child(footer, "p")))
+ {
+ fprintf(stderr, "%s: html_node_add_child failed\n", __func__);
+ goto end;
+ }
+ else if (html_node_add_attr(a, "href", PROJECT_URL))
+ {
+ fprintf(stderr, "%s: html_node_add_attr failed\n", __func__);
+ goto end;
+ }
+ else if (html_node_set_value(a, PROJECT_NAME))
+ {
+ fprintf(stderr, "%s: html_node_set_value a failed\n", __func__);
+ goto end;
+ }
+ else if (dynstr_append(&d, "Powered by&nbsp;"))
+ {
+ fprintf(stderr, "%s: dynstr_append failed\n", __func__);
+ goto end;
+ }
+ else if (html_serialize(a, &d))
+ {
+ fprintf(stderr, "%s: html_serialize failed\n", __func__);
+ goto end;
+ }
+ else if (html_node_set_value_unescaped(p, d.str))
+ {
+ fprintf(stderr, "%s: html_node_set_value_unescaped failed\n", __func__);
+ goto end;
+ }
+
+ ret = 0;
+
+end:
+ dynstr_free(&d);
+ html_node_free(a);
+ return ret;
+}
+
+static int back(struct html_node *const footer)
+{
+ struct html_node *const a = html_node_add_child(footer, "a");
+
+ if (!a)
+ {
+ fprintf(stderr, "%s: html_node_add_child failed\n", __func__);
+ return -1;
+ }
+ else if (html_node_add_attr(a, "href", "/"))
+ {
+ fprintf(stderr, "%s: html_node_add_attr failed\n", __func__);
+ return -1;
+ }
+ else if (html_node_set_value(a, "Back to index"))
+ {
+ fprintf(stderr, "%s: html_node_set_value failed\n", __func__);
+ return -1;
+ }
+
+ return 0;
+}
+
+int form_footer(struct html_node *const n, const char *const resource)
+{
+ struct html_node *const footer = html_node_add_child(n, "footer");
+
+ if (!footer)
+ {
+ fprintf(stderr, "%s: html_node_add_child failed\n", __func__);
+ return -1;
+ }
+ else if (strcmp(resource, "/")
+ && strcmp(resource, "/index.html")
+ && back(footer))
+ {
+ fprintf(stderr, "%s: back failed\n", __func__);
+ return -1;
+ }
+ else if (poweredby(footer))
+ {
+ fprintf(stderr, "%s: poweredby failed\n", __func__);
+ return -1;
+ }
+
+ return 0;
+}