summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2022-09-24 10:43:57 +0200
committerGravatar default2022-09-24 10:43:57 +0200
commitea57b47264782f0e40c224abc4e669295929c3f4 (patch)
tree536d5c05ae4be587cbd7159e262b59335f4c7c76 /activitypub.c
parentMore log tweaks. (diff)
downloadsnac2-ea57b47264782f0e40c224abc4e669295929c3f4.tar.gz
snac2-ea57b47264782f0e40c224abc4e669295929c3f4.tar.xz
snac2-ea57b47264782f0e40c224abc4e669295929c3f4.zip
Started creating messages.
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c61
1 files changed, 49 insertions, 12 deletions
diff --git a/activitypub.c b/activitypub.c
index 7701ecf..7533b0b 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -115,8 +115,50 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s
115} 115}
116 116
117 117
118void process_message(snac *snac, char *msg) 118/** messages **/
119/* processes an ActivityPub message */ 119
120d_char *msg_base(snac *snac, char *type, char *id, char *actor)
121/* creates a base ActivityPub message */
122{
123 d_char *msg = xs_dict_new();
124
125 msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams");
126 msg = xs_dict_append(msg, "type", type);
127
128 if (id != NULL)
129 msg = xs_dict_append(msg, "id", id);
130
131 if (actor != NULL) {
132 /* if actor is "", replace it with this actor */
133 if (actor[0] == '\0')
134 actor = snac->actor;
135
136 msg = xs_dict_append(msg, "actor", actor);
137 }
138
139 return msg;
140}
141
142
143d_char *msg_collection(snac *snac, char *id)
144/* creates an empty OrderedCollection message */
145{
146 d_char *msg = msg_base(snac, "OrderedCollection", id, NULL);
147 xs *ol = xs_list_new();
148 xs *nz = xs_number_new(0);
149
150 msg = xs_dict_append(msg, "attributedTo", snac->actor);
151 msg = xs_dict_append(msg, "orderedItems", ol);
152 msg = xs_dict_append(msg, "totalItems", nz);
153
154 return msg;
155}
156
157
158/** queues **/
159
160void process_message(snac *snac, char *msg, char *req)
161/* processes an ActivityPub message from the input queue */
120{ 162{
121 /* they exist, were checked previously */ 163 /* they exist, were checked previously */
122 char *actor = xs_dict_get(msg, "actor"); 164 char *actor = xs_dict_get(msg, "actor");
@@ -191,8 +233,9 @@ void process_queue(snac *snac)
191 if (strcmp(type, "input") == 0) { 233 if (strcmp(type, "input") == 0) {
192 /* process the message */ 234 /* process the message */
193 char *msg = xs_dict_get(q_item, "object"); 235 char *msg = xs_dict_get(q_item, "object");
236 char *req = xs_dict_get(q_item, "req");
194 237
195 process_message(snac, msg); 238 process_message(snac, msg, req);
196 } 239 }
197 } 240 }
198} 241}
@@ -231,19 +274,13 @@ int activitypub_get_handler(d_char *req, char *q_path,
231 } 274 }
232 else 275 else
233 if (strcmp(p_path, "outbox") == 0) { 276 if (strcmp(p_path, "outbox") == 0) {
277 xs *id = xs_fmt("%s/outbox", snac.actor);
278 msg = msg_collection(&snac, id);
234 } 279 }
235 else 280 else
236 if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) { 281 if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) {
237 xs *id = xs_fmt("%s/%s", snac.actor, p_path); 282 xs *id = xs_fmt("%s/%s", snac.actor, p_path);
238 xs *ol = xs_list_new(); 283 msg = msg_collection(&snac, id);
239 xs *nz = xs_number_new(0);
240
241 msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams");
242 msg = xs_dict_append(msg, "attributedTo", snac.actor);
243 msg = xs_dict_append(msg, "id", id);
244 msg = xs_dict_append(msg, "orderedItems", ol);
245 msg = xs_dict_append(msg, "totalItems", nz);
246 msg = xs_dict_append(msg, "type", "OrderedCollection");
247 } 284 }
248 else 285 else
249 if (xs_startswith(p_path, "p/")) { 286 if (xs_startswith(p_path, "p/")) {