diff options
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/activitypub.c b/activitypub.c index 8924f1c..7cb0f37 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include "xs_encdec.h" | 5 | #include "xs_encdec.h" |
| 6 | #include "xs_json.h" | 6 | #include "xs_json.h" |
| 7 | #include "xs_curl.h" | 7 | #include "xs_curl.h" |
| 8 | #include "xs_mime.h" | ||
| 8 | 9 | ||
| 9 | #include "snac.h" | 10 | #include "snac.h" |
| 10 | 11 | ||
| @@ -195,6 +196,59 @@ d_char *msg_update(snac *snac, char *object) | |||
| 195 | } | 196 | } |
| 196 | 197 | ||
| 197 | 198 | ||
| 199 | d_char *msg_actor(snac *snac) | ||
| 200 | /* create a Person message for this actor */ | ||
| 201 | { | ||
| 202 | xs *ctxt = xs_list_new(); | ||
| 203 | xs *icon = xs_dict_new(); | ||
| 204 | xs *keys = xs_dict_new(); | ||
| 205 | xs *avtr = NULL; | ||
| 206 | xs *kid = NULL; | ||
| 207 | d_char *msg = msg_base(snac, "Person", snac->actor, NULL, NULL); | ||
| 208 | char *p; | ||
| 209 | int n; | ||
| 210 | |||
| 211 | /* change the @context (is this really necessary?) */ | ||
| 212 | ctxt = xs_list_append(ctxt, "https:/" "/www.w3.org/ns/activitystreams"); | ||
| 213 | ctxt = xs_list_append(ctxt, "https:/" "/w3id.org/security/v1"); | ||
| 214 | msg = xs_dict_set(msg, "@context", ctxt); | ||
| 215 | |||
| 216 | msg = xs_dict_set(msg, "url", snac->actor); | ||
| 217 | msg = xs_dict_set(msg, "name", xs_dict_get(snac->config, "name")); | ||
| 218 | msg = xs_dict_set(msg, "preferredUsername", snac->uid); | ||
| 219 | msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published")); | ||
| 220 | msg = xs_dict_set(msg, "summary", xs_dict_get(snac->config, "bio")); | ||
| 221 | |||
| 222 | char *folders[] = { "inbox", "outbox", "followers", "following", NULL }; | ||
| 223 | |||
| 224 | for (n = 0; folders[n]; n++) { | ||
| 225 | xs *f = xs_fmt("%s/%s", snac->actor, folders[n]); | ||
| 226 | msg = xs_dict_set(msg, folders[n], f); | ||
| 227 | } | ||
| 228 | |||
| 229 | p = xs_dict_get(snac->config, "avatar"); | ||
| 230 | |||
| 231 | if (*p == '\0') | ||
| 232 | avtr = xs_fmt("%s/susie.png", srv_baseurl); | ||
| 233 | else | ||
| 234 | avtr = xs_dup(p); | ||
| 235 | |||
| 236 | icon = xs_dict_append(icon, "type", "Image"); | ||
| 237 | icon = xs_dict_append(icon, "mediaType", xs_mime_by_ext(avtr)); | ||
| 238 | icon = xs_dict_append(icon, "url", avtr); | ||
| 239 | msg = xs_dict_set(msg, "icon", icon); | ||
| 240 | |||
| 241 | kid = xs_fmt("%s#main-key", snac->actor); | ||
| 242 | |||
| 243 | keys = xs_dict_append(keys, "id", kid); | ||
| 244 | keys = xs_dict_append(keys, "owner", snac->actor); | ||
| 245 | keys = xs_dict_append(keys, "publicKeyPem", xs_dict_get(snac->key, "public")); | ||
| 246 | msg = xs_dict_set(msg, "publicKey", keys); | ||
| 247 | |||
| 248 | return msg; | ||
| 249 | } | ||
| 250 | |||
| 251 | |||
| 198 | /** queues **/ | 252 | /** queues **/ |
| 199 | 253 | ||
| 200 | void process_message(snac *snac, char *msg, char *req) | 254 | void process_message(snac *snac, char *msg, char *req) |
| @@ -356,6 +410,7 @@ int activitypub_get_handler(d_char *req, char *q_path, | |||
| 356 | 410 | ||
| 357 | if (p_path == NULL) { | 411 | if (p_path == NULL) { |
| 358 | /* if there was no component after the user, it's an actor request */ | 412 | /* if there was no component after the user, it's an actor request */ |
| 413 | msg = msg_actor(&snac); | ||
| 359 | } | 414 | } |
| 360 | else | 415 | else |
| 361 | if (strcmp(p_path, "outbox") == 0) { | 416 | if (strcmp(p_path, "outbox") == 0) { |