Procházet zdrojové kódy

Use snac_op in list_maint().

default před 3 týdny
rodič
revize
319d5cae0e
6 změnil soubory, kde provedl 30 přidání a 26 odebrání
  1. 11 8
      data.c
  2. 2 2
      html.c
  3. 8 8
      main.c
  4. 4 4
      mastoapi.c
  5. 3 2
      snac.h
  6. 2 2
      utils.c

+ 11 - 8
data.c

@@ -2474,13 +2474,13 @@ xs_list *tag_search(const char *tag, int skip, int show)
 
 /** lists **/
 
-xs_val *list_maint(snac *user, const char *list, int op)
+xs_val *list_maint(snac *user, const char *list, snac_op op)
 /* list maintenance */
 {
     xs_val *l = NULL;
 
     switch (op) {
-    case 0: /** list of lists **/
+    case OP_LIST: /** list of lists **/
         {
             FILE *f;
             xs *spec = xs_fmt("%s/list/" "*.id", user->basedir);
@@ -2509,9 +2509,9 @@ xs_val *list_maint(snac *user, const char *list, int op)
 
         break;
 
-    case 1: /** create new list (list is the name) **/
+    case OP_ADD: /** create new list (list is the name) **/
         {
-            xs *lol = list_maint(user, NULL, 0);
+            xs *lol = list_maint(user, NULL, OP_LIST);
             int c = 0;
             const xs_list *v;
             int add = 1;
@@ -2546,7 +2546,7 @@ xs_val *list_maint(snac *user, const char *list, int op)
 
         break;
 
-    case 2: /** delete list (list is the id) **/
+    case OP_DEL: /** delete list (list is the id) **/
         {
             if (xs_is_hex(list)) {
                 xs *fn = xs_fmt("%s/list/%s.id", user->basedir, list);
@@ -2565,7 +2565,7 @@ xs_val *list_maint(snac *user, const char *list, int op)
 
         break;
 
-    case 3: /** get list name **/
+    case OP_ID: /** get list name **/
         if (xs_is_hex(list)) {
             FILE *f;
             xs *fn = xs_fmt("%s/list/%s.id", user->basedir, list);
@@ -2578,9 +2578,9 @@ xs_val *list_maint(snac *user, const char *list, int op)
 
         break;
 
-    case 4: /** find list id by name **/
+    case OP_FIND: /** find list id by name **/
         if (xs_is_string(list)) {
-            xs *lol = list_maint(user, NULL, 0);
+            xs *lol = list_maint(user, NULL, OP_LIST);
             const xs_list *li;
 
             xs_list_foreach(lol, li) {
@@ -2590,6 +2590,9 @@ xs_val *list_maint(snac *user, const char *list, int op)
                 }
             }
         }
+
+    default:
+        break;
     }
 
     return l;

+ 2 - 2
html.c

@@ -3534,7 +3534,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
             xs_html_attr("class", "snac-list-of-lists"));
         xs_html_add(body, lol);
 
-        xs *lists = list_maint(user, NULL, 0); /* get list of lists */
+        xs *lists = list_maint(user, NULL, OP_LIST); /* get list of lists */
 
         int ct = 0;
         const char *v;
@@ -5179,7 +5179,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
                 xs *ttl = timeline_top_level(&snac, list);
 
                 xs *base = xs_fmt("/list/%s", lid);
-                xs *name = list_maint(&snac, lid, 3);
+                xs *name = list_maint(&snac, lid, OP_ID);
                 xs *title = xs_fmt(L("Showing timeline for list '%s'"), name);
 
                 *body = html_timeline(&snac, ttl, 0, skip, show,

+ 8 - 8
main.c

@@ -332,7 +332,7 @@ int main(int argc, char *argv[])
     }
 
     if (strcmp(cmd, "lists") == 0) { /** **/
-        xs *lol = list_maint(&snac, NULL, 0);
+        xs *lol = list_maint(&snac, NULL, OP_LIST);
         const xs_list *l;
 
         xs_list_foreach(lol, l) {
@@ -389,7 +389,7 @@ int main(int argc, char *argv[])
         return usage(cmd);
 
     if (strcmp(cmd, "list_members") == 0) { /** **/
-        xs *lid = list_maint(&snac, url, 4);
+        xs *lid = list_maint(&snac, url, OP_FIND);
 
         if (lid != NULL) {
             xs *lcont = list_members(&snac, lid, NULL, OP_LIST);
@@ -410,10 +410,10 @@ int main(int argc, char *argv[])
     }
 
     if (strcmp(cmd, "list_create") == 0) { /** **/
-        xs *lid = list_maint(&snac, url, 4);
+        xs *lid = list_maint(&snac, url, OP_FIND);
 
         if (lid == NULL) {
-            xs *n_lid = list_maint(&snac, url, 1);
+            xs *n_lid = list_maint(&snac, url, OP_ADD);
             printf("New list named '%s' created (%s)\n", url, n_lid);
         }
         else
@@ -423,10 +423,10 @@ int main(int argc, char *argv[])
     }
 
     if (strcmp(cmd, "list_remove") == 0) { /** **/
-        xs *lid = list_maint(&snac, url, 4);
+        xs *lid = list_maint(&snac, url, OP_FIND);
 
         if (lid != NULL) {
-            list_maint(&snac, lid, 2);
+            list_maint(&snac, lid, OP_DEL);
             printf("List '%s' (%s) deleted\n", url, lid);
         }
         else
@@ -439,7 +439,7 @@ int main(int argc, char *argv[])
         const char *account = GET_ARGV();
 
         if (account != NULL) {
-            xs *lid = list_maint(&snac, url, 4);
+            xs *lid = list_maint(&snac, url, OP_FIND);
 
             if (lid != NULL) {
                 xs *actor = NULL;
@@ -466,7 +466,7 @@ int main(int argc, char *argv[])
         const char *account = GET_ARGV();
 
         if (account != NULL) {
-            xs *lid = list_maint(&snac, url, 4);
+            xs *lid = list_maint(&snac, url, OP_FIND);
 
             if (lid != NULL) {
                 xs *md5 = xs_md5_hex(account, strlen(account));

+ 4 - 4
mastoapi.c

@@ -1781,7 +1781,7 @@ xs_list *mastoapi_account_lists(snac *user, const char *uid)
 {
     xs_list *out  = xs_list_new();
     xs *actor_md5 = NULL;
-    xs *lol       = list_maint(user, NULL, 0);
+    xs *lol       = list_maint(user, NULL, OP_LIST);
 
     if (uid) {
         if (!xs_is_hex(uid))
@@ -2549,7 +2549,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
                 else
                 if (xs_is_hex(p)) {
                     xs *out = xs_list_new();
-                    xs *lol = list_maint(&snac1, NULL, 0);
+                    xs *lol = list_maint(&snac1, NULL, OP_LIST);
                     int c = 0;
                     const xs_list *v;
 
@@ -3803,7 +3803,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
             if (xs_type(title) == XSTYPE_STRING) {
                 /* add the list */
                 xs *out = xs_dict_new();
-                xs *lid = list_maint(&snac, title, 1);
+                xs *lid = list_maint(&snac, title, OP_ADD);
 
                 if (!xs_is_null(lid)) {
                     out = xs_dict_append(out, "id", lid);
@@ -4058,7 +4058,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path,
                 else {
                     /* delete list */
                     if (xs_is_hex(p)) {
-                        list_maint(&snac, p, 2);
+                        list_maint(&snac, p, OP_DEL);
                     }
                 }
             }

+ 3 - 2
snac.h

@@ -84,7 +84,8 @@ typedef enum {
     OP_ADD = 1,
     OP_DEL = 2,
     OP_LIST = 3,
-    OP_FIND = 4
+    OP_FIND = 4,
+    OP_ID = 5
 } snac_op;
 
 extern srv_state *p_state;
@@ -259,7 +260,7 @@ void tag_index(const char *id, const xs_dict *obj);
 xs_str *tag_fn(const char *tag);
 xs_list *tag_search(const char *tag, int skip, int show);
 
-xs_val *list_maint(snac *user, const char *list, int op);
+xs_val *list_maint(snac *user, const char *list, snac_op op);
 xs_str *list_timeline_fn(snac *user, const char *list);
 xs_list *list_timeline(snac *user, const char *list, int skip, int show);
 xs_val *list_members(snac *user, const char *list_id, const char *actor_md5, snac_op op);

+ 2 - 2
utils.c

@@ -698,7 +698,7 @@ void export_csv(snac *user)
     if ((f = fopen(fn, "w")) != NULL) {
         snac_log(user, xs_fmt("Creating %s...", fn));
 
-        xs *lol = list_maint(user, NULL, 0);
+        xs *lol = list_maint(user, NULL, OP_LIST);
         const xs_list *li;
 
         xs_list_foreach(lol, li) {
@@ -927,7 +927,7 @@ void import_list_csv(snac *user, const char *ifn)
 
                 if (lname && acct) {
                     /* create the list */
-                    xs *list_id = list_maint(user, lname, 1);
+                    xs *list_id = list_maint(user, lname, OP_ADD);
 
                     xs *url = NULL;
                     xs *uid = NULL;