commit 319d5ca
default
·
2026-08-26 06:17:03 +0000 UTC
parent 1203080
Use snac_op in list_maint().
M
data.c
+11,
-8
1@@ -2474,13 +2474,13 @@ xs_list *tag_search(const char *tag, int skip, int show)
2
3 /** lists **/
4
5-xs_val *list_maint(snac *user, const char *list, int op)
6+xs_val *list_maint(snac *user, const char *list, snac_op op)
7 /* list maintenance */
8 {
9 xs_val *l = NULL;
10
11 switch (op) {
12- case 0: /** list of lists **/
13+ case OP_LIST: /** list of lists **/
14 {
15 FILE *f;
16 xs *spec = xs_fmt("%s/list/" "*.id", user->basedir);
17@@ -2509,9 +2509,9 @@ xs_val *list_maint(snac *user, const char *list, int op)
18
19 break;
20
21- case 1: /** create new list (list is the name) **/
22+ case OP_ADD: /** create new list (list is the name) **/
23 {
24- xs *lol = list_maint(user, NULL, 0);
25+ xs *lol = list_maint(user, NULL, OP_LIST);
26 int c = 0;
27 const xs_list *v;
28 int add = 1;
29@@ -2546,7 +2546,7 @@ xs_val *list_maint(snac *user, const char *list, int op)
30
31 break;
32
33- case 2: /** delete list (list is the id) **/
34+ case OP_DEL: /** delete list (list is the id) **/
35 {
36 if (xs_is_hex(list)) {
37 xs *fn = xs_fmt("%s/list/%s.id", user->basedir, list);
38@@ -2565,7 +2565,7 @@ xs_val *list_maint(snac *user, const char *list, int op)
39
40 break;
41
42- case 3: /** get list name **/
43+ case OP_ID: /** get list name **/
44 if (xs_is_hex(list)) {
45 FILE *f;
46 xs *fn = xs_fmt("%s/list/%s.id", user->basedir, list);
47@@ -2578,9 +2578,9 @@ xs_val *list_maint(snac *user, const char *list, int op)
48
49 break;
50
51- case 4: /** find list id by name **/
52+ case OP_FIND: /** find list id by name **/
53 if (xs_is_string(list)) {
54- xs *lol = list_maint(user, NULL, 0);
55+ xs *lol = list_maint(user, NULL, OP_LIST);
56 const xs_list *li;
57
58 xs_list_foreach(lol, li) {
59@@ -2590,6 +2590,9 @@ xs_val *list_maint(snac *user, const char *list, int op)
60 }
61 }
62 }
63+
64+ default:
65+ break;
66 }
67
68 return l;
M
html.c
+2,
-2
1@@ -3534,7 +3534,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
2 xs_html_attr("class", "snac-list-of-lists"));
3 xs_html_add(body, lol);
4
5- xs *lists = list_maint(user, NULL, 0); /* get list of lists */
6+ xs *lists = list_maint(user, NULL, OP_LIST); /* get list of lists */
7
8 int ct = 0;
9 const char *v;
10@@ -5179,7 +5179,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
11 xs *ttl = timeline_top_level(&snac, list);
12
13 xs *base = xs_fmt("/list/%s", lid);
14- xs *name = list_maint(&snac, lid, 3);
15+ xs *name = list_maint(&snac, lid, OP_ID);
16 xs *title = xs_fmt(L("Showing timeline for list '%s'"), name);
17
18 *body = html_timeline(&snac, ttl, 0, skip, show,
M
main.c
+8,
-8
1@@ -332,7 +332,7 @@ int main(int argc, char *argv[])
2 }
3
4 if (strcmp(cmd, "lists") == 0) { /** **/
5- xs *lol = list_maint(&snac, NULL, 0);
6+ xs *lol = list_maint(&snac, NULL, OP_LIST);
7 const xs_list *l;
8
9 xs_list_foreach(lol, l) {
10@@ -389,7 +389,7 @@ int main(int argc, char *argv[])
11 return usage(cmd);
12
13 if (strcmp(cmd, "list_members") == 0) { /** **/
14- xs *lid = list_maint(&snac, url, 4);
15+ xs *lid = list_maint(&snac, url, OP_FIND);
16
17 if (lid != NULL) {
18 xs *lcont = list_members(&snac, lid, NULL, OP_LIST);
19@@ -410,10 +410,10 @@ int main(int argc, char *argv[])
20 }
21
22 if (strcmp(cmd, "list_create") == 0) { /** **/
23- xs *lid = list_maint(&snac, url, 4);
24+ xs *lid = list_maint(&snac, url, OP_FIND);
25
26 if (lid == NULL) {
27- xs *n_lid = list_maint(&snac, url, 1);
28+ xs *n_lid = list_maint(&snac, url, OP_ADD);
29 printf("New list named '%s' created (%s)\n", url, n_lid);
30 }
31 else
32@@ -423,10 +423,10 @@ int main(int argc, char *argv[])
33 }
34
35 if (strcmp(cmd, "list_remove") == 0) { /** **/
36- xs *lid = list_maint(&snac, url, 4);
37+ xs *lid = list_maint(&snac, url, OP_FIND);
38
39 if (lid != NULL) {
40- list_maint(&snac, lid, 2);
41+ list_maint(&snac, lid, OP_DEL);
42 printf("List '%s' (%s) deleted\n", url, lid);
43 }
44 else
45@@ -439,7 +439,7 @@ int main(int argc, char *argv[])
46 const char *account = GET_ARGV();
47
48 if (account != NULL) {
49- xs *lid = list_maint(&snac, url, 4);
50+ xs *lid = list_maint(&snac, url, OP_FIND);
51
52 if (lid != NULL) {
53 xs *actor = NULL;
54@@ -466,7 +466,7 @@ int main(int argc, char *argv[])
55 const char *account = GET_ARGV();
56
57 if (account != NULL) {
58- xs *lid = list_maint(&snac, url, 4);
59+ xs *lid = list_maint(&snac, url, OP_FIND);
60
61 if (lid != NULL) {
62 xs *md5 = xs_md5_hex(account, strlen(account));
+4,
-4
1@@ -1781,7 +1781,7 @@ xs_list *mastoapi_account_lists(snac *user, const char *uid)
2 {
3 xs_list *out = xs_list_new();
4 xs *actor_md5 = NULL;
5- xs *lol = list_maint(user, NULL, 0);
6+ xs *lol = list_maint(user, NULL, OP_LIST);
7
8 if (uid) {
9 if (!xs_is_hex(uid))
10@@ -2549,7 +2549,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
11 else
12 if (xs_is_hex(p)) {
13 xs *out = xs_list_new();
14- xs *lol = list_maint(&snac1, NULL, 0);
15+ xs *lol = list_maint(&snac1, NULL, OP_LIST);
16 int c = 0;
17 const xs_list *v;
18
19@@ -3803,7 +3803,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
20 if (xs_type(title) == XSTYPE_STRING) {
21 /* add the list */
22 xs *out = xs_dict_new();
23- xs *lid = list_maint(&snac, title, 1);
24+ xs *lid = list_maint(&snac, title, OP_ADD);
25
26 if (!xs_is_null(lid)) {
27 out = xs_dict_append(out, "id", lid);
28@@ -4058,7 +4058,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path,
29 else {
30 /* delete list */
31 if (xs_is_hex(p)) {
32- list_maint(&snac, p, 2);
33+ list_maint(&snac, p, OP_DEL);
34 }
35 }
36 }
M
snac.h
+3,
-2
1@@ -84,7 +84,8 @@ typedef enum {
2 OP_ADD = 1,
3 OP_DEL = 2,
4 OP_LIST = 3,
5- OP_FIND = 4
6+ OP_FIND = 4,
7+ OP_ID = 5
8 } snac_op;
9
10 extern srv_state *p_state;
11@@ -259,7 +260,7 @@ void tag_index(const char *id, const xs_dict *obj);
12 xs_str *tag_fn(const char *tag);
13 xs_list *tag_search(const char *tag, int skip, int show);
14
15-xs_val *list_maint(snac *user, const char *list, int op);
16+xs_val *list_maint(snac *user, const char *list, snac_op op);
17 xs_str *list_timeline_fn(snac *user, const char *list);
18 xs_list *list_timeline(snac *user, const char *list, int skip, int show);
19 xs_val *list_members(snac *user, const char *list_id, const char *actor_md5, snac_op op);
M
utils.c
+2,
-2
1@@ -698,7 +698,7 @@ void export_csv(snac *user)
2 if ((f = fopen(fn, "w")) != NULL) {
3 snac_log(user, xs_fmt("Creating %s...", fn));
4
5- xs *lol = list_maint(user, NULL, 0);
6+ xs *lol = list_maint(user, NULL, OP_LIST);
7 const xs_list *li;
8
9 xs_list_foreach(lol, li) {
10@@ -927,7 +927,7 @@ void import_list_csv(snac *user, const char *ifn)
11
12 if (lname && acct) {
13 /* create the list */
14- xs *list_id = list_maint(user, lname, 1);
15+ xs *list_id = list_maint(user, lname, OP_ADD);
16
17 xs *url = NULL;
18 xs *uid = NULL;