|
|
@@ -15,8 +15,9 @@ int activitypub_request(snac *snac, char *url, d_char **data)
|
|
|
{
|
|
|
int status;
|
|
|
xs *response = NULL;
|
|
|
- xs *payload;
|
|
|
+ xs *payload = NULL;
|
|
|
int p_size;
|
|
|
+ char *ctype;
|
|
|
|
|
|
/* check if it's an url for this same site */
|
|
|
/* ... */
|
|
|
@@ -25,41 +26,51 @@ int activitypub_request(snac *snac, char *url, d_char **data)
|
|
|
response = http_signed_request(snac, "GET", url,
|
|
|
NULL, NULL, 0, &status, &payload, &p_size);
|
|
|
|
|
|
- {
|
|
|
- xs *j = xs_json_loads(response);
|
|
|
- printf("%s\n", j);
|
|
|
- }
|
|
|
-
|
|
|
if (valid_status(status)) {
|
|
|
- *data = xs_json_loads(payload);
|
|
|
+ if (dbglevel >= 3) {
|
|
|
+ xs *j = xs_json_dumps_pp(response, 4);
|
|
|
+ fprintf(stderr, "%s\n", j);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* ensure it's ActivityPub data */
|
|
|
+ ctype = xs_dict_get(response, "content-type");
|
|
|
+
|
|
|
+ if (xs_str_in(ctype, "application/activity+json") != -1)
|
|
|
+ *data = xs_json_loads(payload);
|
|
|
+ else
|
|
|
+ status = 500;
|
|
|
}
|
|
|
|
|
|
+ if (!valid_status(status))
|
|
|
+ *data = NULL;
|
|
|
+
|
|
|
return status;
|
|
|
}
|
|
|
|
|
|
|
|
|
-#if 0
|
|
|
int actor_request(snac *snac, char *actor, d_char **data)
|
|
|
/* request an actor */
|
|
|
{
|
|
|
- int status;
|
|
|
- xs *response = NULL;
|
|
|
- xs *payload;
|
|
|
- int p_size;
|
|
|
+ int status, status2;
|
|
|
+ xs *payload = NULL;
|
|
|
|
|
|
/* get from disk first */
|
|
|
status = actor_get(snac, actor, data);
|
|
|
|
|
|
if (status == 200)
|
|
|
- return;
|
|
|
+ return status;
|
|
|
|
|
|
- /* get from the net */
|
|
|
- response = http_signed_request(snac, "GET", actor,
|
|
|
- NULL, NULL, 0, &status, &payload, &p_size);
|
|
|
+ /* actor data non-existent or stale: get from the net */
|
|
|
+ status2 = activitypub_request(snac, actor, &payload);
|
|
|
|
|
|
-// response = http_signed_request(&snac, "GET", "https://mastodon.social/users/VictorMoral",
|
|
|
-// headers, NULL, 0, &status, &payload, &p_size);
|
|
|
+ if (valid_status(status2)) {
|
|
|
+ /* renew data */
|
|
|
+ xs *j = xs_json_dumps_pp(payload, 4);
|
|
|
+ status = actor_add(snac, actor, j);
|
|
|
+
|
|
|
+ *data = payload;
|
|
|
+ payload = NULL;
|
|
|
+ }
|
|
|
|
|
|
return status;
|
|
|
}
|
|
|
-#endif
|