commit f209c32

default  ·  2022-11-28 14:49:56 +0000 UTC
parent 3699b61
Use xs_set in recipient_list() and inbox_list().
3 files changed,  +16, -14
+14, -13
 1@@ -9,6 +9,7 @@
 2 #include "xs_openssl.h"
 3 #include "xs_regex.h"
 4 #include "xs_time.h"
 5+#include "xs_set.h"
 6 
 7 #include "snac.h"
 8 
 9@@ -169,11 +170,13 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s
10 d_char *recipient_list(snac *snac, char *msg, int expand_public)
11 /* returns the list of recipients for a message */
12 {
13-    d_char *list = xs_list_new();
14     char *to = xs_dict_get(msg, "to");
15     char *cc = xs_dict_get(msg, "cc");
16+    xs_set rcpts;
17     int n;
18 
19+    xs_set_init(&rcpts);
20+
21     char *lists[] = { to, cc, NULL };
22     for (n = 0; lists[n]; n++) {
23         char *l = lists[n];
24@@ -195,40 +198,38 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
25                 char *actor;
26 
27                 char *p = fwers;
28-                while (xs_list_iter(&p, &actor)) {
29-                    if (xs_list_in(list, actor) == -1)
30-                        list = xs_list_append(list, actor);
31-                }
32+                while (xs_list_iter(&p, &actor))
33+                    xs_set_add(&rcpts, actor);
34             }
35             else
36-            if (xs_list_in(list, v) == -1)
37-                list = xs_list_append(list, v);
38+                xs_set_add(&rcpts, v);
39         }
40     }
41 
42-    return list;
43+    return xs_set_result(&rcpts);
44 }
45 
46 
47 d_char *inbox_list(snac *snac, char *msg)
48 /* returns the list of inboxes that are recipients of this message */
49 {
50-    d_char *list = xs_list_new();
51-    xs *rcpts    = recipient_list(snac, msg, 1);
52+    xs *rcpts = recipient_list(snac, msg, 1);
53+    xs_set inboxes;
54     char *p, *v;
55 
56+    xs_set_init(&inboxes);
57+
58     p = rcpts;
59     while (xs_list_iter(&p, &v)) {
60         xs *inbox;
61 
62         if ((inbox = get_actor_inbox(snac, v)) != NULL) {
63             /* add the inbox if it's not already there */
64-            if (xs_list_in(list, inbox) == -1)
65-                list = xs_list_append(list, inbox);
66+            xs_set_add(&inboxes, inbox);
67         }
68     }
69 
70-    return list;
71+    return xs_set_result(&inboxes);
72 }
73 
74 
+1, -0
1@@ -12,6 +12,7 @@ typedef struct _xs_set {
2 } xs_set;
3 
4 void xs_set_init(xs_set *s);
5+d_char *xs_set_result(xs_set *s);
6 void xs_set_free(xs_set *s);
7 int xs_set_add(xs_set *s, const char *data);
8 
+1, -1
1@@ -1 +1 @@
2-/* e9effd101e5ad45cc4209759ae25e4a6de9259e8 */
3+/* c18371e1f1d3de0f872354f93024a736caebea4d */