summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c40
1 files changed, 40 insertions, 0 deletions
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,
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)