commit 29b1249

default  ·  2023-03-02 08:15:40 +0000 UTC
parent e74ae0f
Simplified is_msg_public().
3 files changed,  +30, -41
M data.c
M snac.h
+2, -35
 1@@ -279,46 +279,13 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
 2 }
 3 
 4 
 5-#if 0
 6-d_char *inbox_list(snac *snac, char *msg)
 7-/* returns the list of inboxes that are recipients of this message */
 8-{
 9-    xs *rcpts = recipient_list(snac, msg, 1);
10-    xs_set inboxes;
11-    char *p, *v;
12-
13-    xs_set_init(&inboxes);
14-
15-    p = rcpts;
16-    while (xs_list_iter(&p, &v)) {
17-        xs *inbox;
18-
19-        if ((inbox = get_actor_inbox(snac, v)) != NULL) {
20-            /* add the inbox if it's not already there */
21-            xs_set_add(&inboxes, inbox);
22-        }
23-        else
24-            snac_log(snac, xs_fmt("cannot find inbox for %s", v));
25-    }
26-
27-    return xs_set_result(&inboxes);
28-}
29-#endif
30-
31-int is_msg_public(snac *snac, char *msg)
32+int is_msg_public(snac *snac, xs_dict *msg)
33 /* checks if a message is public */
34 {
35     int ret = 0;
36     xs *rcpts = recipient_list(snac, msg, 0);
37-    char *p, *v;
38-
39-    p = rcpts;
40-    while (!ret && xs_list_iter(&p, &v)) {
41-        if (strcmp(v, public_address) == 0)
42-            ret = 1;
43-    }
44 
45-    return ret;
46+    return xs_list_in(rcpts, public_address) != -1;
47 }
48 
49 
M data.c
+26, -5
 1@@ -1375,7 +1375,7 @@ void inbox_add(const char *inbox)
 2     xs *fn  = xs_fmt("%s/inbox/%s", srv_basedir, md5);
 3     FILE *f;
 4 
 5-    if ((f = fopen(fn, "w")) != NULL) {
 6+    if (strlen(inbox) < 256 && (f = fopen(fn, "w")) != NULL) {
 7         pthread_mutex_lock(&data_mutex);
 8 
 9         fprintf(f, "%s\n", inbox);
10@@ -1397,15 +1397,36 @@ void inbox_add_by_actor(const xs_dict *actor)
11 }
12 
13 
14-#if 0
15 xs_list *inbox_list(void)
16 /* returns the collected inboxes as a list */
17 {
18-    xs_list *l = xs_list_new();
19+    xs_list *ibl = xs_list_new();
20+    xs *spec     = xs_fmt("%s/inbox/" "*", srv_basedir);
21+    xs *files    = xs_glob(spec, 0, 0);
22+    xs_list *p   = files;
23+    xs_val *v;
24+
25+    while (xs_list_iter(&p, &v)) {
26+        FILE *f;
27+
28+        if ((f = fopen(v, "r")) != NULL) {
29+            char line[256];
30+
31+            if (fgets(line, sizeof(line), f)) {
32+                fclose(f);
33+
34+                int i = strlen(line);
35+
36+                if (i) {
37+                    line[i - 1] = '\0';
38+                    ibl = xs_list_append(ibl, line);
39+                }
40+            }
41+        }
42+    }
43 
44-    return l;
45+    return ibl;
46 }
47-#endif
48 
49 
50 /** the queue **/
M snac.h
+2, -1
 1@@ -134,6 +134,7 @@ d_char *history_list(snac *snac);
 2 
 3 void inbox_add(const char *inbox);
 4 void inbox_add_by_actor(const xs_dict *actor);
 5+xs_list *inbox_list(void);
 6 
 7 void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries);
 8 void enqueue_output_raw(const char *keyid, const char *seckey,
 9@@ -193,7 +194,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg,
10                   xs_val **payload, int *p_size, int timeout);
11 d_char *get_actor_inbox(snac *snac, char *actor);
12 int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout);
13-int is_msg_public(snac *snac, char *msg);
14+int is_msg_public(snac *snac, xs_dict *msg);
15 
16 int process_user_queue(snac *snac);
17 void process_queue_item(xs_dict *q_item);