diff --git a/activitypub.c b/activitypub.c index 6fa7607..b842118 100644 --- a/activitypub.c +++ b/activitypub.c @@ -46,7 +46,7 @@ const char *default_avatar_base64(void) } -int activitypub_request(snac *snac, char *url, d_char **data) +int activitypub_request(snac *snac, const char *url, xs_dict **data) /* request an object */ { int status; @@ -91,7 +91,7 @@ int activitypub_request(snac *snac, char *url, d_char **data) } -int actor_request(snac *snac, char *actor, d_char **data) +int actor_request(snac *snac, const char *actor, xs_dict **data) /* request an actor */ { int status, status2; diff --git a/mastoapi.c b/mastoapi.c index f924c2b..08941cf 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1179,6 +1179,46 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, *ctype = "application/json"; status = 200; } + else + if (strcmp(cmd, "/v2/search") == 0) { + const char *q = xs_dict_get(args, "q"); + const char *type = xs_dict_get(args, "type"); + const char *offset = xs_dict_get(args, "offset"); + + xs *acl = xs_list_new(); + xs *stl = xs_list_new(); + xs *htl = xs_list_new(); + xs *res = xs_dict_new(); + + if (xs_is_null(offset) || strcmp(offset, "0") == 0) { + /* reply something only for offset 0; otherwise, + apps like Tusky keep asking again and again */ + + if (!xs_is_null(q) && strcmp(type, "accounts") == 0) { + /* do a webfinger query */ + char *actor = NULL; + char *user = NULL; + + if (valid_status(webfinger_request(q, &actor, &user))) { + xs *actor_o = NULL; + + if (valid_status(actor_request(&snac1, actor, &actor_o))) { + xs *acct = mastoapi_account(actor_o); + + acl = xs_list_append(acl, acct); + } + } + } + } + + res = xs_dict_append(res, "accounts", acl); + res = xs_dict_append(res, "statuses", stl); + res = xs_dict_append(res, "hashtags", htl); + + *body = xs_json_dumps_pp(res, 4); + *ctype = "application/json"; + status = 200; + } /* user cleanup */ if (logged_in) diff --git a/snac.h b/snac.h index bed2b0b..5cb639d 100644 --- a/snac.h +++ b/snac.h @@ -183,7 +183,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err); void httpd(void); -int webfinger_request(char *qs, char **actor, char **user); +int webfinger_request(const char *qs, char **actor, char **user); int webfinger_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype); @@ -201,8 +201,8 @@ d_char *msg_delete(snac *snac, char *id); d_char *msg_actor(snac *snac); xs_dict *msg_update(snac *snac, xs_dict *object); -int activitypub_request(snac *snac, char *url, d_char **data); -int actor_request(snac *snac, char *actor, d_char **data); +int activitypub_request(snac *snac, const char *url, xs_dict **data); +int actor_request(snac *snac, const char *actor, xs_dict **data); int send_to_inbox_raw(const char *keyid, const char *seckey, const xs_str *inbox, const xs_dict *msg, xs_val **payload, int *p_size, int timeout); diff --git a/webfinger.c b/webfinger.c index 4d1abe6..eb6b2ad 100644 --- a/webfinger.c +++ b/webfinger.c @@ -8,7 +8,7 @@ #include "snac.h" -int webfinger_request(char *qs, char **actor, char **user) +int webfinger_request(const char *qs, char **actor, char **user) /* queries the webfinger for qs and fills the required fields */ { int status;