activitypub.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "snac.h"
  8. const char *public_address = "https:/" "/www.w3.org/ns/activitystreams#Public";
  9. int activitypub_request(snac *snac, char *url, d_char **data)
  10. /* request an object */
  11. {
  12. int status;
  13. xs *response = NULL;
  14. xs *payload;
  15. int p_size;
  16. /* check if it's an url for this same site */
  17. /* ... */
  18. /* get from the net */
  19. response = http_signed_request(snac, "GET", url,
  20. NULL, NULL, 0, &status, &payload, &p_size);
  21. {
  22. xs *j = xs_json_loads(response);
  23. printf("%s\n", j);
  24. }
  25. if (valid_status(status)) {
  26. *data = xs_json_loads(payload);
  27. }
  28. return status;
  29. }
  30. #if 0
  31. int actor_request(snac *snac, char *actor, d_char **data)
  32. /* request an actor */
  33. {
  34. int status;
  35. xs *response = NULL;
  36. xs *payload;
  37. int p_size;
  38. /* get from disk first */
  39. status = actor_get(snac, actor, data);
  40. if (status == 200)
  41. return;
  42. /* get from the net */
  43. response = http_signed_request(snac, "GET", actor,
  44. NULL, NULL, 0, &status, &payload, &p_size);
  45. // response = http_signed_request(&snac, "GET", "https://mastodon.social/users/VictorMoral",
  46. // headers, NULL, 0, &status, &payload, &p_size);
  47. return status;
  48. }
  49. #endif