diff options
| author | 2023-04-23 05:33:54 +0200 | |
|---|---|---|
| committer | 2023-04-23 05:33:54 +0200 | |
| commit | 5b93e9069e64b2f25a6e17de9d7a2e0aee209ac5 (patch) | |
| tree | cc7c9e84b69434baf7b70c0cebfd7200d59a7045 | |
| parent | Version 2.28 RELEASED. (diff) | |
| download | penes-snac2-5b93e9069e64b2f25a6e17de9d7a2e0aee209ac5.tar.gz penes-snac2-5b93e9069e64b2f25a6e17de9d7a2e0aee209ac5.tar.xz penes-snac2-5b93e9069e64b2f25a6e17de9d7a2e0aee209ac5.zip | |
Added mastoapi code for account search.
| -rw-r--r-- | activitypub.c | 4 | ||||
| -rw-r--r-- | mastoapi.c | 40 | ||||
| -rw-r--r-- | snac.h | 6 | ||||
| -rw-r--r-- | webfinger.c | 2 |
4 files changed, 46 insertions, 6 deletions
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) | |||
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | int activitypub_request(snac *snac, char *url, d_char **data) | 49 | int activitypub_request(snac *snac, const char *url, xs_dict **data) |
| 50 | /* request an object */ | 50 | /* request an object */ |
| 51 | { | 51 | { |
| 52 | int status; | 52 | int status; |
| @@ -91,7 +91,7 @@ int activitypub_request(snac *snac, char *url, d_char **data) | |||
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | 93 | ||
| 94 | int actor_request(snac *snac, char *actor, d_char **data) | 94 | int actor_request(snac *snac, const char *actor, xs_dict **data) |
| 95 | /* request an actor */ | 95 | /* request an actor */ |
| 96 | { | 96 | { |
| 97 | int status, status2; | 97 | int status, status2; |
| @@ -1179,6 +1179,46 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1179 | *ctype = "application/json"; | 1179 | *ctype = "application/json"; |
| 1180 | status = 200; | 1180 | status = 200; |
| 1181 | } | 1181 | } |
| 1182 | else | ||
| 1183 | if (strcmp(cmd, "/v2/search") == 0) { | ||
| 1184 | const char *q = xs_dict_get(args, "q"); | ||
| 1185 | const char *type = xs_dict_get(args, "type"); | ||
| 1186 | const char *offset = xs_dict_get(args, "offset"); | ||
| 1187 | |||
| 1188 | xs *acl = xs_list_new(); | ||
| 1189 | xs *stl = xs_list_new(); | ||
| 1190 | xs *htl = xs_list_new(); | ||
| 1191 | xs *res = xs_dict_new(); | ||
| 1192 | |||
| 1193 | if (xs_is_null(offset) || strcmp(offset, "0") == 0) { | ||
| 1194 | /* reply something only for offset 0; otherwise, | ||
| 1195 | apps like Tusky keep asking again and again */ | ||
| 1196 | |||
| 1197 | if (!xs_is_null(q) && strcmp(type, "accounts") == 0) { | ||
| 1198 | /* do a webfinger query */ | ||
| 1199 | char *actor = NULL; | ||
| 1200 | char *user = NULL; | ||
| 1201 | |||
| 1202 | if (valid_status(webfinger_request(q, &actor, &user))) { | ||
| 1203 | xs *actor_o = NULL; | ||
| 1204 | |||
| 1205 | if (valid_status(actor_request(&snac1, actor, &actor_o))) { | ||
| 1206 | xs *acct = mastoapi_account(actor_o); | ||
| 1207 | |||
| 1208 | acl = xs_list_append(acl, acct); | ||
| 1209 | } | ||
| 1210 | } | ||
| 1211 | } | ||
| 1212 | } | ||
| 1213 | |||
| 1214 | res = xs_dict_append(res, "accounts", acl); | ||
| 1215 | res = xs_dict_append(res, "statuses", stl); | ||
| 1216 | res = xs_dict_append(res, "hashtags", htl); | ||
| 1217 | |||
| 1218 | *body = xs_json_dumps_pp(res, 4); | ||
| 1219 | *ctype = "application/json"; | ||
| 1220 | status = 200; | ||
| 1221 | } | ||
| 1182 | 1222 | ||
| 1183 | /* user cleanup */ | 1223 | /* user cleanup */ |
| 1184 | if (logged_in) | 1224 | if (logged_in) |
| @@ -183,7 +183,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err); | |||
| 183 | 183 | ||
| 184 | void httpd(void); | 184 | void httpd(void); |
| 185 | 185 | ||
| 186 | int webfinger_request(char *qs, char **actor, char **user); | 186 | int webfinger_request(const char *qs, char **actor, char **user); |
| 187 | int webfinger_get_handler(d_char *req, char *q_path, | 187 | int webfinger_get_handler(d_char *req, char *q_path, |
| 188 | char **body, int *b_size, char **ctype); | 188 | char **body, int *b_size, char **ctype); |
| 189 | 189 | ||
| @@ -201,8 +201,8 @@ d_char *msg_delete(snac *snac, char *id); | |||
| 201 | d_char *msg_actor(snac *snac); | 201 | d_char *msg_actor(snac *snac); |
| 202 | xs_dict *msg_update(snac *snac, xs_dict *object); | 202 | xs_dict *msg_update(snac *snac, xs_dict *object); |
| 203 | 203 | ||
| 204 | int activitypub_request(snac *snac, char *url, d_char **data); | 204 | int activitypub_request(snac *snac, const char *url, xs_dict **data); |
| 205 | int actor_request(snac *snac, char *actor, d_char **data); | 205 | int actor_request(snac *snac, const char *actor, xs_dict **data); |
| 206 | int send_to_inbox_raw(const char *keyid, const char *seckey, | 206 | int send_to_inbox_raw(const char *keyid, const char *seckey, |
| 207 | const xs_str *inbox, const xs_dict *msg, | 207 | const xs_str *inbox, const xs_dict *msg, |
| 208 | xs_val **payload, int *p_size, int timeout); | 208 | 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 @@ | |||
| 8 | 8 | ||
| 9 | #include "snac.h" | 9 | #include "snac.h" |
| 10 | 10 | ||
| 11 | int webfinger_request(char *qs, char **actor, char **user) | 11 | int webfinger_request(const char *qs, char **actor, char **user) |
| 12 | /* queries the webfinger for qs and fills the required fields */ | 12 | /* queries the webfinger for qs and fills the required fields */ |
| 13 | { | 13 | { |
| 14 | int status; | 14 | int status; |