💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › 6d5b43513d702432f02d9faef22ee… captured on 2023-12-28 at 15:41:47. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
0 /*
1 * ISC License
2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>
3 */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include "macro.h"
8 #include "strlcpy.h"
9 #include "error.h"
10 #include "bookmarks.h"
11 #define ABOUT_INTERNAL
12 #include "about.h"
13
14 int about_bookmarks_param(const char *param) {
15 int id = atoi(param), ret;
16 if (!id && strcmp(param, "0")) return ERROR_INVALID_ARGUMENT;
17 if ((ret = bookmark_remove(id))) return ret;
18 if ((ret = bookmark_rewrite())) return ret;
19 return 0;
20 }
21
22 int about_bookmarks(char **out, size_t *length_out) {
23
24 char *data = NULL;
25 size_t length = 0;
26 size_t i;
27 const char title[] = "# Bookmarks\n\n";
28
29 if (!(data = dyn_strcat(NULL, &length, V(header)))) goto fail;
30 if (!(data = dyn_strcat(data, &length, V(title)))) goto fail;
31
32 for (i = 0; i < bookmark_length; i++) {
33
34 char buf[1024];
35 int len;
36
37 len = snprintf(V(buf), "=>%s %s\n=>/%ld Delete\n\n",
38 bookmarks[i].url, bookmarks[i].name, i) + 1;
39 if (!(data = dyn_strcat(data, &length, buf, len))) goto fail;
40 }
41
42 *out = data;
43 *length_out = length;
44 return 0;
45 fail:
46 free(data);
47 return ERROR_MEMORY_FAILURE;
48 }
49