summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2023-06-01 17:14:50 +0200
committerGravatar default2023-06-01 17:14:50 +0200
commite66b3ff8daa86753855e536a3b769f01d66a92bf (patch)
tree2d2579c2e73fd25809c8711fec7d46b2cceb5a29 /activitypub.c
parentFixed typo in notify(). (diff)
downloadsnac2-e66b3ff8daa86753855e536a3b769f01d66a92bf.tar.gz
snac2-e66b3ff8daa86753855e536a3b769f01d66a92bf.tar.xz
snac2-e66b3ff8daa86753855e536a3b769f01d66a92bf.zip
Disallow empty or repeated options in msg_question().
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/activitypub.c b/activitypub.c
index dddeb20..4919a61 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -1057,6 +1057,7 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
1057 xs *ntid = tid(0); 1057 xs *ntid = tid(0);
1058 xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0); 1058 xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0);
1059 int max = 8; 1059 int max = 8;
1060 xs_set seen;
1060 1061
1061 msg = xs_dict_set(msg, "type", "Question"); 1062 msg = xs_dict_set(msg, "type", "Question");
1062 1063
@@ -1068,20 +1069,30 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
1068 xs_str *v; 1069 xs_str *v;
1069 xs *replies = xs_json_loads("{\"type\":\"Collection\",\"totalItems\":0}"); 1070 xs *replies = xs_json_loads("{\"type\":\"Collection\",\"totalItems\":0}");
1070 1071
1071 while (max-- && xs_list_iter(&p, &v)) { 1072 xs_set_init(&seen);
1072 xs *v2 = xs_dup(v);
1073 xs *d = xs_dict_new();
1074 1073
1075 if (strlen(v2) > 60) { 1074 while (max && xs_list_iter(&p, &v)) {
1076 v2[60] = '\0'; 1075 if (*v) {
1077 v2 = xs_str_cat(v2, "..."); 1076 xs *v2 = xs_dup(v);
1078 } 1077 xs *d = xs_dict_new();
1078
1079 if (strlen(v2) > 60) {
1080 v2[60] = '\0';
1081 v2 = xs_str_cat(v2, "...");
1082 }
1083
1084 if (xs_set_add(&seen, v2) == 1) {
1085 d = xs_dict_append(d, "name", v2);
1086 d = xs_dict_append(d, "replies", replies);
1087 o = xs_list_append(o, d);
1079 1088
1080 d = xs_dict_append(d, "name", v2); 1089 max--;
1081 d = xs_dict_append(d, "replies", replies); 1090 }
1082 o = xs_list_append(o, d); 1091 }
1083 } 1092 }
1084 1093
1094 xs_set_free(&seen);
1095
1085 msg = xs_dict_append(msg, multiple ? "anyOf" : "oneOf", o); 1096 msg = xs_dict_append(msg, multiple ? "anyOf" : "oneOf", o);
1086 1097
1087 /* set the end time */ 1098 /* set the end time */