diff options
| author | 2023-03-01 09:22:32 +0100 | |
|---|---|---|
| committer | 2023-03-01 09:22:32 +0100 | |
| commit | eb0c7eabbb88bed8e30fd7dcd337ce48a5f46a8f (patch) | |
| tree | 868a80c896ea59cecff2fc7ac44ab15064f96be0 | |
| parent | New function srv_archive_error(). (diff) | |
| download | snac2-eb0c7eabbb88bed8e30fd7dcd337ce48a5f46a8f.tar.gz snac2-eb0c7eabbb88bed8e30fd7dcd337ce48a5f46a8f.tar.xz snac2-eb0c7eabbb88bed8e30fd7dcd337ce48a5f46a8f.zip | |
Minor refactoring to actor_request().
Including commented out experimental code for collecting sharedInboxes.
| -rw-r--r-- | activitypub.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/activitypub.c b/activitypub.c index bb68a7d..a259a25 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -96,24 +96,43 @@ int actor_request(snac *snac, char *actor, d_char **data) | |||
| 96 | int status, status2; | 96 | int status, status2; |
| 97 | xs *payload = NULL; | 97 | xs *payload = NULL; |
| 98 | 98 | ||
| 99 | if (data) | ||
| 100 | *data = NULL; | ||
| 101 | |||
| 99 | /* get from disk first */ | 102 | /* get from disk first */ |
| 100 | status = actor_get(snac, actor, data); | 103 | status = actor_get(snac, actor, data); |
| 101 | 104 | ||
| 102 | if (status == 200) | 105 | if (status != 200) { |
| 103 | return status; | 106 | /* actor data non-existent or stale: get from the net */ |
| 107 | status2 = activitypub_request(snac, actor, &payload); | ||
| 108 | |||
| 109 | if (valid_status(status2)) { | ||
| 110 | /* renew data */ | ||
| 111 | status = actor_add(snac, actor, payload); | ||
| 112 | |||
| 113 | if (data != NULL) { | ||
| 114 | *data = payload; | ||
| 115 | payload = NULL; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | } | ||
| 104 | 119 | ||
| 105 | /* actor data non-existent or stale: get from the net */ | 120 | #if 0 |
| 106 | status2 = activitypub_request(snac, actor, &payload); | 121 | if (valid_status(status) && data && *data) { |
| 122 | xs *fn = xs_fmt("%s/inboxes.lst", srv_basedir); | ||
| 123 | FILE *f; | ||
| 107 | 124 | ||
| 108 | if (valid_status(status2)) { | 125 | if ((f = fopen(fn, "a")) != NULL) { |
| 109 | /* renew data */ | 126 | char *v; |
| 110 | status = actor_add(snac, actor, payload); | 127 | if (!xs_is_null(v = xs_dict_get(*data, "endpoints")) && |
| 128 | !xs_is_null(v = xs_dict_get(v, "sharedInbox"))) { | ||
| 129 | fprintf(f, "%s\n", v); | ||
| 130 | } | ||
| 111 | 131 | ||
| 112 | if (data != NULL) { | 132 | fclose(f); |
| 113 | *data = payload; | ||
| 114 | payload = NULL; | ||
| 115 | } | 133 | } |
| 116 | } | 134 | } |
| 135 | #endif | ||
| 117 | 136 | ||
| 118 | return status; | 137 | return status; |
| 119 | } | 138 | } |