mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-10 03:50:38 +03:00
Added mastoapi code for account search.
This commit is contained in:
parent
99529a9874
commit
5b93e9069e
@ -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 */
|
/* request an object */
|
||||||
{
|
{
|
||||||
int status;
|
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 */
|
/* request an actor */
|
||||||
{
|
{
|
||||||
int status, status2;
|
int status, status2;
|
||||||
|
40
mastoapi.c
40
mastoapi.c
@ -1179,6 +1179,46 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|||||||
*ctype = "application/json";
|
*ctype = "application/json";
|
||||||
status = 200;
|
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 */
|
/* user cleanup */
|
||||||
if (logged_in)
|
if (logged_in)
|
||||||
|
6
snac.h
6
snac.h
@ -183,7 +183,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err);
|
|||||||
|
|
||||||
void httpd(void);
|
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,
|
int webfinger_get_handler(d_char *req, char *q_path,
|
||||||
char **body, int *b_size, char **ctype);
|
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);
|
d_char *msg_actor(snac *snac);
|
||||||
xs_dict *msg_update(snac *snac, xs_dict *object);
|
xs_dict *msg_update(snac *snac, xs_dict *object);
|
||||||
|
|
||||||
int activitypub_request(snac *snac, char *url, d_char **data);
|
int activitypub_request(snac *snac, const char *url, xs_dict **data);
|
||||||
int actor_request(snac *snac, char *actor, d_char **data);
|
int actor_request(snac *snac, const char *actor, xs_dict **data);
|
||||||
int send_to_inbox_raw(const char *keyid, const char *seckey,
|
int send_to_inbox_raw(const char *keyid, const char *seckey,
|
||||||
const xs_str *inbox, const xs_dict *msg,
|
const xs_str *inbox, const xs_dict *msg,
|
||||||
xs_val **payload, int *p_size, int timeout);
|
xs_val **payload, int *p_size, int timeout);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "snac.h"
|
#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 */
|
/* queries the webfinger for qs and fills the required fields */
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
Loading…
Reference in New Issue
Block a user