activitypub.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /* snac - A simple, minimalistic ActivityPub instance */
  2. /* copyright (c) 2022 grunfink - MIT license */
  3. #include "xs.h"
  4. #include "xs_encdec.h"
  5. #include "xs_json.h"
  6. #include "xs_curl.h"
  7. #include "xs_mime.h"
  8. #include "xs_openssl.h"
  9. #include "snac.h"
  10. const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public";
  11. int activitypub_request(snac *snac, char *url, d_char **data)
  12. /* request an object */
  13. {
  14. int status;
  15. xs *response = NULL;
  16. xs *payload = NULL;
  17. int p_size;
  18. char *ctype;
  19. /* check if it's an url for this same site */
  20. /* ... */
  21. /* get from the net */
  22. response = http_signed_request(snac, "GET", url,
  23. NULL, NULL, 0, &status, &payload, &p_size);
  24. if (valid_status(status)) {
  25. /* ensure it's ActivityPub data */
  26. ctype = xs_dict_get(response, "content-type");
  27. if (xs_str_in(ctype, "application/activity+json") != -1 ||
  28. xs_str_in(ctype, "application/ld+json") != -1)
  29. *data = xs_json_loads(payload);
  30. else
  31. status = 500;
  32. }
  33. if (!valid_status(status))
  34. *data = NULL;
  35. return status;
  36. }
  37. int actor_request(snac *snac, char *actor, d_char **data)
  38. /* request an actor */
  39. {
  40. int status, status2;
  41. xs *payload = NULL;
  42. /* get from disk first */
  43. status = actor_get(snac, actor, data);
  44. if (status == 200)
  45. return status;
  46. /* actor data non-existent or stale: get from the net */
  47. status2 = activitypub_request(snac, actor, &payload);
  48. if (valid_status(status2)) {
  49. /* renew data */
  50. status = actor_add(snac, actor, payload);
  51. *data = payload;
  52. payload = NULL;
  53. }
  54. return status;
  55. }
  56. void timeline_request(snac *snac, char *id, char *referrer)
  57. /* ensures that an entry and its ancestors are in the timeline */
  58. {
  59. if (!xs_is_null(id)) {
  60. /* is the admired object already there? */
  61. if (!timeline_here(snac, id)) {
  62. int status;
  63. xs *object = NULL;
  64. /* no; download it */
  65. status = activitypub_request(snac, id, &object);
  66. if (valid_status(status)) {
  67. /* does it have an ancestor? */
  68. char *in_reply_to = xs_dict_get(object, "inReplyTo");
  69. /* recurse! */
  70. timeline_request(snac, in_reply_to, referrer);
  71. /* finally store */
  72. timeline_add(snac, id, object, in_reply_to, referrer);
  73. }
  74. }
  75. }
  76. }
  77. int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size)
  78. /* sends a message to an Inbox */
  79. {
  80. int status;
  81. d_char *response;
  82. xs *j_msg = xs_json_dumps_pp(msg, 4);
  83. response = http_signed_request(snac, "POST", inbox,
  84. NULL, j_msg, strlen(j_msg), &status, payload, p_size);
  85. free(response);
  86. return status;
  87. }
  88. int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size)
  89. /* sends a message to an actor */
  90. {
  91. int status;
  92. xs *data = NULL;
  93. /* resolve the actor first */
  94. status = actor_request(snac, actor, &data);
  95. if (valid_status(status)) {
  96. char *inbox = xs_dict_get(data, "inbox");
  97. if (inbox != NULL)
  98. status = send_to_inbox(snac, inbox, msg, payload, p_size);
  99. else
  100. status = 400;
  101. }
  102. snac_log(snac, xs_fmt("send_to_actor %s %d", actor, status));
  103. return status;
  104. }
  105. /** messages **/
  106. d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char *object)
  107. /* creates a base ActivityPub message */
  108. {
  109. xs *did = NULL;
  110. xs *published = NULL;
  111. /* generated values */
  112. if (date && strcmp(date, "@now") == 0)
  113. date = published = xs_utc_time("%Y-%m-%dT%H:%M:%SZ");
  114. if (id != NULL) {
  115. if (strcmp(id, "@dummy") == 0) {
  116. xs *ntid = tid(0);
  117. id = did = xs_fmt("%s/d/%s/%s", snac->actor, ntid, type);
  118. }
  119. else
  120. if (strcmp(id, "@object") == 0) {
  121. if (object != NULL)
  122. id = did = xs_fmt("%s/%s", xs_dict_get(object, "id"), type);
  123. else
  124. id = NULL;
  125. }
  126. }
  127. d_char *msg = xs_dict_new();
  128. msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams");
  129. msg = xs_dict_append(msg, "type", type);
  130. if (id != NULL)
  131. msg = xs_dict_append(msg, "id", id);
  132. if (actor != NULL)
  133. msg = xs_dict_append(msg, "actor", actor);
  134. if (date != NULL)
  135. msg = xs_dict_append(msg, "published", date);
  136. if (object != NULL)
  137. msg = xs_dict_append(msg, "object", object);
  138. return msg;
  139. }
  140. d_char *msg_collection(snac *snac, char *id)
  141. /* creates an empty OrderedCollection message */
  142. {
  143. d_char *msg = msg_base(snac, "OrderedCollection", id, NULL, NULL, NULL);
  144. xs *ol = xs_list_new();
  145. xs *nz = xs_number_new(0);
  146. msg = xs_dict_append(msg, "attributedTo", snac->actor);
  147. msg = xs_dict_append(msg, "orderedItems", ol);
  148. msg = xs_dict_append(msg, "totalItems", nz);
  149. return msg;
  150. }
  151. d_char *msg_accept(snac *snac, char *object, char *to)
  152. /* creates an Accept message (as a response to a Follow) */
  153. {
  154. d_char *msg = msg_base(snac, "Accept", "@dummy", snac->actor, NULL, object);
  155. msg = xs_dict_append(msg, "to", to);
  156. return msg;
  157. }
  158. d_char *msg_update(snac *snac, char *object)
  159. /* creates an Update message */
  160. {
  161. d_char *msg = msg_base(snac, "Update", "@object", snac->actor, "@now", object);
  162. msg = xs_dict_append(msg, "to", public_address);
  163. return msg;
  164. }
  165. d_char *msg_admiration(snac *snac, char *object, char *type)
  166. /* creates a Like or Announce message */
  167. {
  168. xs *a_msg = NULL;
  169. d_char *msg = NULL;
  170. /* call the object */
  171. timeline_request(snac, object, snac->actor);
  172. if ((a_msg = timeline_find(snac, object)) != NULL) {
  173. xs *rcpts = xs_list_new();
  174. msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object);
  175. rcpts = xs_list_append(rcpts, public_address);
  176. rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo"));
  177. msg = xs_dict_append(msg, "to", rcpts);
  178. }
  179. else
  180. snac_log(snac, xs_fmt("msg_admiration cannot retrieve object %s", object));
  181. return msg;
  182. }
  183. d_char *msg_actor(snac *snac)
  184. /* create a Person message for this actor */
  185. {
  186. xs *ctxt = xs_list_new();
  187. xs *icon = xs_dict_new();
  188. xs *keys = xs_dict_new();
  189. xs *avtr = NULL;
  190. xs *kid = NULL;
  191. xs *f_bio = NULL;
  192. d_char *msg = msg_base(snac, "Person", snac->actor, NULL, NULL, NULL);
  193. char *p;
  194. int n;
  195. /* change the @context (is this really necessary?) */
  196. ctxt = xs_list_append(ctxt, "https:/" "/www.w3.org/ns/activitystreams");
  197. ctxt = xs_list_append(ctxt, "https:/" "/w3id.org/security/v1");
  198. msg = xs_dict_set(msg, "@context", ctxt);
  199. msg = xs_dict_set(msg, "url", snac->actor);
  200. msg = xs_dict_set(msg, "name", xs_dict_get(snac->config, "name"));
  201. msg = xs_dict_set(msg, "preferredUsername", snac->uid);
  202. msg = xs_dict_set(msg, "published", xs_dict_get(snac->config, "published"));
  203. not_really_markdown(xs_dict_get(snac->config, "bio"), &f_bio);
  204. msg = xs_dict_set(msg, "summary", f_bio);
  205. char *folders[] = { "inbox", "outbox", "followers", "following", NULL };
  206. for (n = 0; folders[n]; n++) {
  207. xs *f = xs_fmt("%s/%s", snac->actor, folders[n]);
  208. msg = xs_dict_set(msg, folders[n], f);
  209. }
  210. p = xs_dict_get(snac->config, "avatar");
  211. if (*p == '\0')
  212. avtr = xs_fmt("%s/susie.png", srv_baseurl);
  213. else
  214. avtr = xs_dup(p);
  215. icon = xs_dict_append(icon, "type", "Image");
  216. icon = xs_dict_append(icon, "mediaType", xs_mime_by_ext(avtr));
  217. icon = xs_dict_append(icon, "url", avtr);
  218. msg = xs_dict_set(msg, "icon", icon);
  219. kid = xs_fmt("%s#main-key", snac->actor);
  220. keys = xs_dict_append(keys, "id", kid);
  221. keys = xs_dict_append(keys, "owner", snac->actor);
  222. keys = xs_dict_append(keys, "publicKeyPem", xs_dict_get(snac->key, "public"));
  223. msg = xs_dict_set(msg, "publicKey", keys);
  224. return msg;
  225. }
  226. d_char *msg_create(snac *snac, char *object)
  227. /* creates a 'Create' message */
  228. {
  229. d_char *msg = msg_base(snac, "Create", "@object", snac->actor, "@now", object);
  230. msg = xs_dict_append(msg, "attributedTo", xs_dict_get(object, "attributedTo"));
  231. msg = xs_dict_append(msg, "to", xs_dict_get(object, "to"));
  232. msg = xs_dict_append(msg, "cc", xs_dict_get(object, "cc"));
  233. return msg;
  234. }
  235. d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to)
  236. /* creates a 'Note' message */
  237. {
  238. xs *ntid = tid(0);
  239. xs *id = xs_fmt("%s/p/%s", snac->actor, ntid);
  240. xs *ctxt = xs_fmt("%s#ctxt", id);
  241. xs *fc1 = NULL;
  242. xs *to = NULL;
  243. xs *cc = xs_list_new();
  244. xs *irt = NULL;
  245. xs *tag = NULL;
  246. d_char *msg = msg_base(snac, "Note", id, NULL, "@now", NULL);
  247. char *p, *v;
  248. if (rcpts == NULL)
  249. to = xs_list_new();
  250. else
  251. to = xs_dup(rcpts);
  252. /* format the content */
  253. not_really_markdown(content, &fc1);
  254. if (in_reply_to != NULL) {
  255. irt = xs_dup(in_reply_to);
  256. }
  257. else
  258. irt = xs_val_new(XSTYPE_NULL);
  259. if (tag == NULL)
  260. tag = xs_list_new();
  261. /* add all mentions to the cc */
  262. p = tag;
  263. while (xs_list_iter(&p, &v)) {
  264. if (xs_type(v) == XSTYPE_DICT) {
  265. char *t;
  266. if ((t = xs_dict_get(v, "type")) != NULL && strcmp(t, "Mention") == 0) {
  267. if ((t = xs_dict_get(v, "href")) != NULL)
  268. cc = xs_list_append(cc, t);
  269. }
  270. }
  271. }
  272. /* no recipients? must be for everybody */
  273. if (xs_list_len(to) == 0)
  274. to = xs_list_append(to, public_address);
  275. msg = xs_dict_append(msg, "attributedTo", snac->actor);
  276. msg = xs_dict_append(msg, "summary", "");
  277. msg = xs_dict_append(msg, "content", fc1);
  278. msg = xs_dict_append(msg, "context", ctxt);
  279. msg = xs_dict_append(msg, "url", id);
  280. msg = xs_dict_append(msg, "to", to);
  281. msg = xs_dict_append(msg, "cc", cc);
  282. msg = xs_dict_append(msg, "inReplyTo", irt);
  283. msg = xs_dict_append(msg, "tag", tag);
  284. return msg;
  285. }
  286. /** queues **/
  287. void process_message(snac *snac, char *msg, char *req)
  288. /* processes an ActivityPub message from the input queue */
  289. {
  290. /* actor and type exist, were checked previously */
  291. char *actor = xs_dict_get(msg, "actor");
  292. char *type = xs_dict_get(msg, "type");
  293. char *object, *utype;
  294. object = xs_dict_get(msg, "object");
  295. if (object != NULL && xs_type(object) == XSTYPE_DICT)
  296. utype = xs_dict_get(object, "type");
  297. else
  298. utype = "(null)";
  299. /* check the signature */
  300. /* ... */
  301. if (strcmp(type, "Follow") == 0) {
  302. xs *reply = msg_accept(snac, msg, actor);
  303. post(snac, reply);
  304. timeline_add(snac, xs_dict_get(msg, "id"), msg, NULL, NULL);
  305. follower_add(snac, actor, msg);
  306. snac_log(snac, xs_fmt("New follower %s", actor));
  307. }
  308. else
  309. /*
  310. if (strcmp(type, "Undo") == 0) {
  311. }
  312. else
  313. */
  314. if (strcmp(type, "Create") == 0) {
  315. if (strcmp(utype, "Note") == 0) {
  316. if (is_muted(snac, actor))
  317. snac_log(snac, xs_fmt("ignored 'Note' from muted actor %s", actor));
  318. else {
  319. char *id = xs_dict_get(object, "id");
  320. char *in_reply_to = xs_dict_get(object, "inReplyTo");
  321. timeline_request(snac, in_reply_to, NULL);
  322. if (timeline_add(snac, id, object, in_reply_to, NULL))
  323. snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
  324. }
  325. }
  326. else
  327. snac_debug(snac, 1, xs_fmt("ignored 'Create' for object type '%s'", utype));
  328. }
  329. else
  330. /*
  331. if (strcmp(type, "Accept") == 0) {
  332. }
  333. else
  334. */
  335. if (strcmp(type, "Like") == 0) {
  336. if (xs_type(object) == XSTYPE_DICT)
  337. object = xs_dict_get(object, "id");
  338. timeline_admire(snac, object, actor, 1);
  339. snac_log(snac, xs_fmt("new 'Like' %s %s", actor, object));
  340. }
  341. else
  342. if (strcmp(type, "Announce") == 0) {
  343. if (xs_type(object) == XSTYPE_DICT)
  344. object = xs_dict_get(object, "id");
  345. timeline_request(snac, object, actor);
  346. timeline_admire(snac, object, actor, 0);
  347. snac_log(snac, xs_fmt("new 'Announce' %s %s", actor, object));
  348. }
  349. /*
  350. else
  351. if (strcmp(type, "Update") == 0) {
  352. }
  353. else
  354. if (strcmp(type, "Delete") == 0) {
  355. }
  356. */
  357. else
  358. snac_debug(snac, 1, xs_fmt("process_message type '%s' ignored", type));
  359. }
  360. void process_queue(snac *snac)
  361. /* processes the queue */
  362. {
  363. xs *list;
  364. char *p, *fn;
  365. int queue_retry_max = xs_number_get(xs_dict_get(srv_config, "queue_retry_max"));
  366. list = queue(snac);
  367. p = list;
  368. while (xs_list_iter(&p, &fn)) {
  369. xs *q_item = dequeue(snac, fn);
  370. char *type;
  371. if (q_item == NULL) {
  372. snac_log(snac, xs_fmt("process_queue q_item error"));
  373. continue;
  374. }
  375. if ((type = xs_dict_get(q_item, "type")) == NULL)
  376. type = "output";
  377. if (strcmp(type, "output") == 0) {
  378. int status;
  379. char *actor = xs_dict_get(q_item, "actor");
  380. char *msg = xs_dict_get(q_item, "object");
  381. int retries = xs_number_get(xs_dict_get(q_item, "retries"));
  382. xs *payload = NULL;
  383. int p_size = 0;
  384. /* deliver */
  385. status = send_to_actor(snac, actor, msg, &payload, &p_size);
  386. if (!valid_status(status)) {
  387. /* error sending; reenqueue? */
  388. if (retries > queue_retry_max)
  389. snac_log(snac, xs_fmt("process_queue giving up %s %d", actor, status));
  390. else {
  391. /* reenqueue */
  392. enqueue_output(snac, msg, actor, retries + 1);
  393. snac_log(snac, xs_fmt("process_queue requeue %s %d", actor, retries + 1));
  394. }
  395. }
  396. }
  397. else
  398. if (strcmp(type, "input") == 0) {
  399. /* process the message */
  400. char *msg = xs_dict_get(q_item, "object");
  401. char *req = xs_dict_get(q_item, "req");
  402. process_message(snac, msg, req);
  403. }
  404. }
  405. }
  406. d_char *recipient_list(snac *snac, char *msg, int expand_public)
  407. /* returns the list of recipients for a message */
  408. {
  409. d_char *list = xs_list_new();
  410. char *to = xs_dict_get(msg, "to");
  411. char *cc = xs_dict_get(msg, "cc");
  412. int n;
  413. char *lists[] = { to, cc, NULL };
  414. for (n = 0; lists[n]; n++) {
  415. char *l = lists[n];
  416. char *v;
  417. if (xs_type(l) == XSTYPE_STRING) {
  418. if (xs_list_in(list, l) == -1)
  419. list = xs_list_append(list, l);
  420. }
  421. else
  422. while (xs_list_iter(&l, &v)) {
  423. if (expand_public && strcmp(v, public_address) == 0) {
  424. /* iterate the followers and add them */
  425. xs *fwers = follower_list(snac);
  426. char *fw;
  427. char *p = fwers;
  428. while (xs_list_iter(&p, &fw)) {
  429. char *actor = xs_dict_get(fw, "actor");
  430. if (xs_list_in(list, actor) == -1)
  431. list = xs_list_append(list, actor);
  432. }
  433. }
  434. else
  435. if (xs_list_in(list, v) == -1)
  436. list = xs_list_append(list, v);
  437. }
  438. }
  439. return list;
  440. }
  441. int is_msg_public(snac *snac, char *msg)
  442. /* checks if a message is public */
  443. {
  444. int ret = 0;
  445. xs *rcpts = recipient_list(snac, msg, 0);
  446. char *p, *v;
  447. p = rcpts;
  448. while (!ret && xs_list_iter(&p, &v)) {
  449. if (strcmp(v, public_address) == 0)
  450. ret = 1;
  451. }
  452. return ret;
  453. }
  454. void post(snac *snac, char *msg)
  455. /* enqueues a message to all its recipients */
  456. {
  457. xs *rcpts = recipient_list(snac, msg, 1);
  458. char *p, *v;
  459. p = rcpts;
  460. while (xs_list_iter(&p, &v)) {
  461. enqueue_output(snac, msg, v, 0);
  462. }
  463. }
  464. /** HTTP handlers */
  465. int activitypub_get_handler(d_char *req, char *q_path,
  466. char **body, int *b_size, char **ctype)
  467. {
  468. int status = 200;
  469. char *accept = xs_dict_get(req, "accept");
  470. snac snac;
  471. xs *msg = NULL;
  472. if (accept == NULL)
  473. return 400;
  474. if (xs_str_in(accept, "application/activity+json") == -1 &&
  475. xs_str_in(accept, "application/ld+json") == -1)
  476. return 0;
  477. xs *l = xs_split_n(q_path, "/", 2);
  478. char *uid, *p_path;
  479. uid = xs_list_get(l, 1);
  480. if (!user_open(&snac, uid)) {
  481. /* invalid user */
  482. srv_log(xs_fmt("activitypub_get_handler bad user %s", uid));
  483. return 404;
  484. }
  485. p_path = xs_list_get(l, 2);
  486. *ctype = "application/activity+json";
  487. if (p_path == NULL) {
  488. /* if there was no component after the user, it's an actor request */
  489. msg = msg_actor(&snac);
  490. *ctype = "application/ld+json";
  491. }
  492. else
  493. if (strcmp(p_path, "outbox") == 0) {
  494. xs *id = xs_fmt("%s/outbox", snac.actor);
  495. msg = msg_collection(&snac, id);
  496. /* replace the 'orderedItems' with the latest posts */
  497. /* ... */
  498. }
  499. else
  500. if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) {
  501. xs *id = xs_fmt("%s/%s", snac.actor, p_path);
  502. msg = msg_collection(&snac, id);
  503. }
  504. else
  505. if (xs_startswith(p_path, "p/")) {
  506. }
  507. else
  508. status = 404;
  509. if (status == 200 && msg != NULL) {
  510. *body = xs_json_dumps_pp(msg, 4);
  511. *b_size = strlen(*body);
  512. }
  513. user_free(&snac);
  514. return status;
  515. }
  516. int activitypub_post_handler(d_char *req, char *q_path,
  517. d_char *payload, int p_size,
  518. char **body, int *b_size, char **ctype)
  519. /* processes an input message */
  520. {
  521. int status = 202; /* accepted */
  522. char *i_ctype = xs_dict_get(req, "content-type");
  523. snac snac;
  524. char *v;
  525. if (i_ctype == NULL)
  526. return 400;
  527. if (xs_str_in(i_ctype, "application/activity+json") == -1 &&
  528. xs_str_in(i_ctype, "application/ld+json") == -1)
  529. return 0;
  530. /* decode the message */
  531. xs *msg = xs_json_loads(payload);
  532. if (msg == NULL) {
  533. srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path));
  534. status = 400;
  535. }
  536. /* get the user and path */
  537. xs *l = xs_split_n(q_path, "/", 2);
  538. char *uid;
  539. if (xs_list_len(l) != 3 || strcmp(xs_list_get(l, 2), "inbox") != 0) {
  540. /* strange q_path */
  541. srv_debug(1, xs_fmt("activitypub_post_handler unsupported path %s", q_path));
  542. return 404;
  543. }
  544. uid = xs_list_get(l, 1);
  545. if (!user_open(&snac, uid)) {
  546. /* invalid user */
  547. srv_debug(1, xs_fmt("activitypub_post_handler bad user %s", uid));
  548. return 404;
  549. }
  550. /* if it has a digest, check it now, because
  551. later the payload won't be exactly the same */
  552. if ((v = xs_dict_get(req, "digest")) != NULL) {
  553. xs *s1 = xs_sha256_base64(payload, p_size);
  554. xs *s2 = xs_fmt("SHA-256=%s", s1);
  555. if (strcmp(s2, v) == 0)
  556. srv_log(xs_fmt("digest check OK"));
  557. else
  558. srv_log(xs_fmt("digest check FAILED"));
  559. }
  560. enqueue_input(&snac, msg, req);
  561. user_free(&snac);
  562. if (valid_status(status))
  563. *ctype = "application/activity+json";
  564. return status;
  565. }