2022-09-19 22:13:40 +03:00
|
|
|
/* snac - A simple, minimalistic ActivityPub instance */
|
2022-09-19 21:47:22 +03:00
|
|
|
/* copyright (c) 2022 grunfink - MIT license */
|
|
|
|
|
2022-09-19 22:13:40 +03:00
|
|
|
extern d_char *srv_basedir;
|
|
|
|
extern d_char *srv_config;
|
|
|
|
extern d_char *srv_baseurl;
|
2022-09-21 19:13:11 +03:00
|
|
|
extern int srv_running;
|
2022-09-19 22:13:40 +03:00
|
|
|
|
|
|
|
extern int dbglevel;
|
|
|
|
|
2022-09-22 12:50:53 +03:00
|
|
|
#define valid_status(status) ((status) >= 200 && (status) <= 299)
|
|
|
|
|
2022-09-19 22:24:55 +03:00
|
|
|
d_char *xs_time(char *fmt, int local);
|
|
|
|
#define xs_local_time(fmt) xs_time(fmt, 1)
|
|
|
|
#define xs_utc_time(fmt) xs_time(fmt, 0)
|
|
|
|
|
2022-09-20 13:00:13 +03:00
|
|
|
d_char *tid(int offset);
|
2022-09-19 23:19:14 +03:00
|
|
|
|
2022-09-19 22:30:19 +03:00
|
|
|
void srv_debug(int level, d_char *str);
|
|
|
|
#define srv_log(str) srv_debug(0, str)
|
|
|
|
|
2022-09-19 22:13:40 +03:00
|
|
|
int srv_open(char *basedir);
|
|
|
|
|
2022-09-19 23:19:14 +03:00
|
|
|
typedef struct _snac {
|
|
|
|
d_char *uid; /* uid */
|
|
|
|
d_char *basedir; /* user base directory */
|
|
|
|
d_char *config; /* user configuration */
|
|
|
|
d_char *key; /* keypair */
|
|
|
|
d_char *actor; /* actor url */
|
|
|
|
} snac;
|
|
|
|
|
2022-09-20 00:03:18 +03:00
|
|
|
int user_open(snac *snac, char *uid);
|
|
|
|
void user_free(snac *snac);
|
2022-09-20 00:33:11 +03:00
|
|
|
d_char *user_list(void);
|
2022-09-19 23:23:33 +03:00
|
|
|
|
|
|
|
void snac_debug(snac *snac, int level, d_char *str);
|
|
|
|
#define snac_log(snac, str) snac_debug(snac, 0, str)
|
2022-09-19 23:41:30 +03:00
|
|
|
|
|
|
|
int validate_uid(char *uid);
|
2022-09-19 23:58:27 +03:00
|
|
|
|
|
|
|
d_char *hash_password(char *uid, char *passwd, char *nonce);
|
|
|
|
int check_password(char *uid, char *passwd, char *hash);
|
2022-09-20 10:48:13 +03:00
|
|
|
|
2022-09-25 08:28:42 +03:00
|
|
|
void srv_archive(char *direction, char *req, char *payload, int p_size,
|
|
|
|
int status, char *headers, char *body, int b_size);
|
|
|
|
|
2022-09-20 10:48:13 +03:00
|
|
|
float mtime(char *fn);
|
|
|
|
|
|
|
|
int follower_add(snac *snac, char *actor, char *msg);
|
|
|
|
int follower_del(snac *snac, char *actor);
|
|
|
|
int follower_check(snac *snac, char *actor);
|
|
|
|
d_char *follower_list(snac *snac);
|
2022-09-20 11:02:00 +03:00
|
|
|
|
2022-09-20 11:49:24 +03:00
|
|
|
d_char *timeline_find(snac *snac, char *id);
|
2022-09-20 11:02:00 +03:00
|
|
|
void timeline_del(snac *snac, char *id);
|
2022-09-20 11:49:24 +03:00
|
|
|
d_char *timeline_get(snac *snac, char *fn);
|
|
|
|
d_char *timeline_list(snac *snac);
|
2022-09-25 08:58:25 +03:00
|
|
|
void timeline_add(snac *snac, char *id, char *msg, char *parent);
|
2022-09-20 12:31:56 +03:00
|
|
|
|
|
|
|
int following_add(snac *snac, char *actor, char *msg);
|
|
|
|
int following_del(snac *snac, char *actor);
|
|
|
|
int following_check(snac *snac, char *actor);
|
|
|
|
|
2022-09-20 12:38:18 +03:00
|
|
|
void mute(snac *snac, char *actor);
|
|
|
|
void unmute(snac *snac, char *actor);
|
|
|
|
int is_muted(snac *snac, char *actor);
|
2022-09-20 13:43:49 +03:00
|
|
|
|
2022-09-22 19:50:39 +03:00
|
|
|
int actor_add(snac *snac, char *actor, char *msg);
|
2022-09-22 19:52:42 +03:00
|
|
|
int actor_get(snac *snac, char *actor, d_char **data);
|
2022-09-22 19:50:39 +03:00
|
|
|
|
2022-09-24 11:03:27 +03:00
|
|
|
void enqueue_input(snac *snac, char *msg, char *req);
|
|
|
|
void enqueue_output(snac *snac, char *msg, char *actor, int retries);
|
2022-09-22 18:12:46 +03:00
|
|
|
|
2022-09-20 13:43:49 +03:00
|
|
|
d_char *queue(snac *snac);
|
2022-09-20 13:50:37 +03:00
|
|
|
d_char *dequeue(snac *snac, char *fn);
|
2022-09-20 22:00:16 +03:00
|
|
|
|
|
|
|
d_char *http_signed_request(snac *snac, char *method, char *url,
|
|
|
|
d_char *headers,
|
|
|
|
d_char *body, int b_size,
|
|
|
|
int *status, d_char **payload, int *p_size);
|
2022-09-21 19:27:30 +03:00
|
|
|
|
|
|
|
void httpd(void);
|
2022-09-21 22:12:49 +03:00
|
|
|
|
2022-09-23 18:36:40 +03:00
|
|
|
int webfinger_request(char *qs, char **actor, char **user);
|
2022-09-23 18:40:59 +03:00
|
|
|
int webfinger_get_handler(d_char *req, char *q_path,
|
2022-09-23 21:59:19 +03:00
|
|
|
char **body, int *b_size, char **ctype);
|
2022-09-23 18:33:33 +03:00
|
|
|
|
|
|
|
int activitypub_request(snac *snac, char *url, d_char **data);
|
2022-09-23 19:46:30 +03:00
|
|
|
int actor_request(snac *snac, char *actor, d_char **data);
|
2022-09-23 20:07:45 +03:00
|
|
|
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size);
|
|
|
|
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size);
|
2022-09-23 20:37:01 +03:00
|
|
|
void process_queue(snac *snac);
|
2022-09-23 21:59:19 +03:00
|
|
|
int activitypub_get_handler(d_char *req, char *q_path,
|
|
|
|
char **body, int *b_size, char **ctype);
|
2022-09-23 21:28:23 +03:00
|
|
|
int activitypub_post_handler(d_char *req, char *q_path,
|
|
|
|
char *payload, int p_size,
|
|
|
|
char **body, int *b_size, char **ctype);
|