2022-09-19 19:13:40 +00:00
|
|
|
/* snac - A simple, minimalistic ActivityPub instance */
|
2023-01-17 08:50:16 +00:00
|
|
|
/* copyright (c) 2022 - 2023 grunfink / MIT license */
|
2022-09-19 18:47:22 +00:00
|
|
|
|
2023-04-05 21:23:19 +00:00
|
|
|
#define VERSION "2.27-dev"
|
2022-09-27 16:01:51 +00:00
|
|
|
|
|
|
|
#define USER_AGENT "snac/" VERSION
|
|
|
|
|
2023-02-07 08:01:57 +00:00
|
|
|
#define DIR_PERM 02770
|
|
|
|
|
2023-01-31 17:33:45 +00:00
|
|
|
extern double disk_layout;
|
2022-09-19 19:13:40 +00:00
|
|
|
extern d_char *srv_basedir;
|
|
|
|
extern d_char *srv_config;
|
|
|
|
extern d_char *srv_baseurl;
|
2022-09-21 16:13:11 +00:00
|
|
|
extern int srv_running;
|
2022-09-19 19:13:40 +00:00
|
|
|
|
|
|
|
extern int dbglevel;
|
|
|
|
|
2022-09-28 07:46:21 +00:00
|
|
|
#define L(s) (s)
|
|
|
|
|
2023-02-07 08:25:01 +00:00
|
|
|
int mkdirx(const char *pathname);
|
|
|
|
|
2022-10-26 04:43:47 +00:00
|
|
|
int valid_status(int status);
|
2022-09-20 10:00:13 +00:00
|
|
|
d_char *tid(int offset);
|
2022-09-28 15:18:30 +00:00
|
|
|
double ftime(void);
|
2022-09-19 20:19:14 +00:00
|
|
|
|
2022-09-19 19:30:19 +00:00
|
|
|
void srv_debug(int level, d_char *str);
|
|
|
|
#define srv_log(str) srv_debug(0, str)
|
|
|
|
|
2022-11-25 09:53:16 +00:00
|
|
|
int srv_open(char *basedir, int auto_upgrade);
|
2022-10-25 08:38:20 +00:00
|
|
|
void srv_free(void);
|
2022-09-19 19:13:40 +00:00
|
|
|
|
2022-09-19 20:19:14 +00:00
|
|
|
typedef struct _snac {
|
2023-02-12 08:17:38 +00:00
|
|
|
xs_str *uid; /* uid */
|
|
|
|
xs_str *basedir; /* user base directory */
|
|
|
|
xs_dict *config; /* user configuration */
|
|
|
|
xs_dict *config_o; /* user configuration admin override */
|
|
|
|
xs_dict *key; /* keypair */
|
|
|
|
xs_str *actor; /* actor url */
|
|
|
|
xs_str *md5; /* actor url md5 */
|
2022-09-19 20:19:14 +00:00
|
|
|
} snac;
|
|
|
|
|
2022-12-04 20:14:18 +00:00
|
|
|
int user_open(snac *snac, const char *uid);
|
2022-09-19 21:03:18 +00:00
|
|
|
void user_free(snac *snac);
|
2022-09-19 21:33:11 +00:00
|
|
|
d_char *user_list(void);
|
2022-09-19 20:23:33 +00:00
|
|
|
|
|
|
|
void snac_debug(snac *snac, int level, d_char *str);
|
|
|
|
#define snac_log(snac, str) snac_debug(snac, 0, str)
|
2022-09-19 20:41:30 +00:00
|
|
|
|
2022-12-04 20:14:18 +00:00
|
|
|
int validate_uid(const char *uid);
|
2022-09-19 20:58:27 +00:00
|
|
|
|
2022-12-04 20:14:18 +00:00
|
|
|
d_char *hash_password(const char *uid, const char *passwd, const char *nonce);
|
|
|
|
int check_password(const char *uid, const char *passwd, const char *hash);
|
2022-09-20 07:48:13 +00:00
|
|
|
|
2023-03-02 16:13:17 +00:00
|
|
|
void srv_archive(const char *direction, const char *url, xs_dict *req,
|
2023-02-02 02:49:38 +00:00
|
|
|
const char *payload, int p_size,
|
|
|
|
int status, xs_dict *headers,
|
|
|
|
const char *body, int b_size);
|
2023-03-01 07:25:36 +00:00
|
|
|
void srv_archive_error(const char *prefix, const xs_str *err,
|
|
|
|
const xs_dict *req, const xs_dict *data);
|
2022-09-25 05:28:42 +00:00
|
|
|
|
2022-11-25 12:33:13 +00:00
|
|
|
double mtime_nl(const char *fn, int *n_link);
|
|
|
|
#define mtime(fn) mtime_nl(fn, NULL)
|
2023-04-12 07:43:23 +00:00
|
|
|
double f_ctime(const char *fn);
|
2022-09-20 07:48:13 +00:00
|
|
|
|
2022-11-24 07:00:35 +00:00
|
|
|
int index_add(const char *fn, const char *md5);
|
2023-02-23 09:42:09 +00:00
|
|
|
int index_gc(const char *fn);
|
2022-11-26 16:35:18 +00:00
|
|
|
int index_first(const char *fn, char *buf, int size);
|
2022-12-10 10:19:26 +00:00
|
|
|
int index_len(const char *fn);
|
2022-11-24 07:00:35 +00:00
|
|
|
d_char *index_list(const char *fn, int max);
|
2022-12-04 20:28:29 +00:00
|
|
|
d_char *index_list_desc(const char *fn, int skip, int show);
|
2022-11-23 19:50:35 +00:00
|
|
|
|
2022-12-03 16:58:49 +00:00
|
|
|
int object_add(const char *id, d_char *obj);
|
|
|
|
int object_add_ow(const char *id, d_char *obj);
|
2022-12-02 20:36:12 +00:00
|
|
|
int object_here_by_md5(char *id);
|
2022-12-02 19:44:51 +00:00
|
|
|
int object_here(char *id);
|
2023-02-05 16:45:00 +00:00
|
|
|
int object_get_by_md5(const char *md5, xs_dict **obj);
|
|
|
|
int object_get(const char *id, xs_dict **obj);
|
2022-11-25 11:09:30 +00:00
|
|
|
int object_del(const char *id);
|
2022-11-27 08:45:06 +00:00
|
|
|
int object_del_if_unref(const char *id);
|
2023-04-12 07:46:42 +00:00
|
|
|
double object_ctime_by_md5(const char *md5);
|
|
|
|
double object_ctime(const char *id);
|
2022-12-03 16:58:49 +00:00
|
|
|
int object_admire(const char *id, const char *actor, int like);
|
2022-11-25 11:09:30 +00:00
|
|
|
|
2022-12-10 10:19:26 +00:00
|
|
|
int object_likes_len(const char *id);
|
|
|
|
int object_announces_len(const char *id);
|
|
|
|
|
2022-12-02 18:14:59 +00:00
|
|
|
d_char *object_children(const char *id);
|
|
|
|
d_char *object_likes(const char *id);
|
|
|
|
d_char *object_announces(const char *id);
|
2022-12-02 20:36:12 +00:00
|
|
|
int object_parent(const char *id, char *buf, int size);
|
2022-12-02 18:14:59 +00:00
|
|
|
|
2022-12-03 16:58:49 +00:00
|
|
|
int object_user_cache_add(snac *snac, const char *id, const char *cachedir);
|
|
|
|
int object_user_cache_del(snac *snac, const char *id, const char *cachedir);
|
|
|
|
|
2022-11-28 09:46:42 +00:00
|
|
|
int follower_add(snac *snac, const char *actor);
|
|
|
|
int follower_del(snac *snac, const char *actor);
|
|
|
|
int follower_check(snac *snac, const char *actor);
|
2022-09-20 07:48:13 +00:00
|
|
|
d_char *follower_list(snac *snac);
|
2022-09-20 08:02:00 +00:00
|
|
|
|
2022-09-30 07:59:13 +00:00
|
|
|
double timeline_mtime(snac *snac);
|
2023-02-08 12:28:03 +00:00
|
|
|
int timeline_here(snac *snac, const char *md5);
|
2023-02-05 16:39:40 +00:00
|
|
|
int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg);
|
2022-10-20 08:34:32 +00:00
|
|
|
int timeline_del(snac *snac, char *id);
|
2022-12-04 20:28:29 +00:00
|
|
|
d_char *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show);
|
|
|
|
d_char *timeline_list(snac *snac, const char *idx_name, int skip, int show);
|
2023-01-11 19:40:13 +00:00
|
|
|
int timeline_add(snac *snac, char *id, char *o_msg);
|
2023-01-11 19:47:36 +00:00
|
|
|
void timeline_admire(snac *snac, char *id, char *admirer, int like);
|
2022-09-20 09:31:56 +00:00
|
|
|
|
2023-02-08 12:21:44 +00:00
|
|
|
xs_list *timeline_top_level(snac *snac, xs_list *list);
|
2022-11-26 17:04:05 +00:00
|
|
|
|
2022-09-28 02:48:23 +00:00
|
|
|
d_char *local_list(snac *snac, int max);
|
|
|
|
|
2022-09-20 09:31:56 +00: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-10-01 07:12:33 +00:00
|
|
|
int following_get(snac *snac, char *actor, d_char **data);
|
2022-11-02 09:49:16 +00:00
|
|
|
d_char *following_list(snac *snac);
|
2022-09-20 09:31:56 +00:00
|
|
|
|
2022-09-20 09:38:18 +00:00
|
|
|
void mute(snac *snac, char *actor);
|
|
|
|
void unmute(snac *snac, char *actor);
|
|
|
|
int is_muted(snac *snac, char *actor);
|
2022-09-20 10:43:49 +00:00
|
|
|
|
2022-11-24 08:39:16 +00:00
|
|
|
void hide(snac *snac, const char *id);
|
|
|
|
int is_hidden(snac *snac, const char *id);
|
|
|
|
|
2022-11-23 15:13:51 +00:00
|
|
|
int actor_add(snac *snac, const char *actor, d_char *msg);
|
|
|
|
int actor_get(snac *snac, const char *actor, d_char **data);
|
2022-09-22 16:50:39 +00:00
|
|
|
|
2022-10-16 16:03:28 +00:00
|
|
|
int static_get(snac *snac, const char *id, d_char **data, int *size);
|
|
|
|
void static_put(snac *snac, const char *id, const char *data, int size);
|
2022-09-28 07:29:09 +00:00
|
|
|
|
2022-09-30 07:59:13 +00:00
|
|
|
double history_mtime(snac *snac, char *id);
|
2022-09-30 07:56:29 +00:00
|
|
|
void history_add(snac *snac, char *id, char *content, int size);
|
|
|
|
d_char *history_get(snac *snac, char *id);
|
2022-10-01 05:45:36 +00:00
|
|
|
int history_del(snac *snac, char *id);
|
2022-10-02 16:16:58 +00:00
|
|
|
d_char *history_list(snac *snac);
|
2022-09-30 07:56:29 +00:00
|
|
|
|
2023-04-05 21:46:51 +00:00
|
|
|
void lastlog_write(snac *snac);
|
|
|
|
|
2023-03-02 07:43:50 +00:00
|
|
|
void inbox_add(const char *inbox);
|
|
|
|
void inbox_add_by_actor(const xs_dict *actor);
|
2023-03-02 08:15:40 +00:00
|
|
|
xs_list *inbox_list(void);
|
2023-03-02 07:43:50 +00:00
|
|
|
|
2023-01-31 20:15:16 +00:00
|
|
|
void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries);
|
2023-02-07 12:31:48 +00:00
|
|
|
void enqueue_output_raw(const char *keyid, const char *seckey,
|
|
|
|
xs_dict *msg, xs_str *inbox, int retries);
|
2023-01-31 20:15:16 +00:00
|
|
|
void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries);
|
2023-01-31 20:49:43 +00:00
|
|
|
void enqueue_output_by_actor(snac *snac, xs_dict *msg, xs_str *actor, int retries);
|
2023-02-02 04:21:16 +00:00
|
|
|
void enqueue_email(xs_str *msg, int retries);
|
2023-02-07 06:37:23 +00:00
|
|
|
void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id);
|
2022-12-16 06:09:25 +00:00
|
|
|
void enqueue_message(snac *snac, char *msg);
|
2022-09-22 15:12:46 +00:00
|
|
|
|
2023-02-02 03:47:59 +00:00
|
|
|
xs_list *user_queue(snac *snac);
|
2023-02-02 04:21:16 +00:00
|
|
|
xs_list *queue(void);
|
2023-02-02 03:44:30 +00:00
|
|
|
xs_dict *dequeue(const char *fn);
|
2022-09-20 19:00:16 +00:00
|
|
|
|
2022-10-04 16:46:12 +00:00
|
|
|
void purge(snac *snac);
|
2022-10-17 09:00:34 +00:00
|
|
|
void purge_all(void);
|
2022-10-04 16:46:12 +00:00
|
|
|
|
2023-02-07 09:29:06 +00:00
|
|
|
xs_dict *http_signed_request_raw(const char *keyid, const char *seckey,
|
|
|
|
const char *method, const char *url,
|
|
|
|
xs_dict *headers,
|
|
|
|
const char *body, int b_size,
|
|
|
|
int *status, xs_str **payload, int *p_size,
|
|
|
|
int timeout);
|
2023-02-02 02:49:38 +00:00
|
|
|
xs_dict *http_signed_request(snac *snac, const char *method, const char *url,
|
|
|
|
xs_dict *headers,
|
|
|
|
const char *body, int b_size,
|
|
|
|
int *status, xs_str **payload, int *p_size,
|
|
|
|
int timeout);
|
2023-03-01 07:25:36 +00:00
|
|
|
int check_signature(snac *snac, xs_dict *req, xs_str **err);
|
2022-09-21 16:27:30 +00:00
|
|
|
|
|
|
|
void httpd(void);
|
2022-09-21 19:12:49 +00:00
|
|
|
|
2022-09-23 15:36:40 +00:00
|
|
|
int webfinger_request(char *qs, char **actor, char **user);
|
2022-09-23 15:40:59 +00:00
|
|
|
int webfinger_get_handler(d_char *req, char *q_path,
|
2022-09-23 18:59:19 +00:00
|
|
|
char **body, int *b_size, char **ctype);
|
2022-09-23 15:33:33 +00:00
|
|
|
|
2023-01-27 17:17:11 +00:00
|
|
|
const char *default_avatar_base64(void);
|
|
|
|
|
2022-09-26 08:08:14 +00:00
|
|
|
d_char *msg_admiration(snac *snac, char *object, char *type);
|
2022-09-27 12:07:36 +00:00
|
|
|
d_char *msg_create(snac *snac, char *object);
|
2022-09-27 13:28:08 +00:00
|
|
|
d_char *msg_follow(snac *snac, char *actor);
|
2023-02-20 08:32:44 +00:00
|
|
|
|
|
|
|
xs_dict *msg_note(snac *snac, xs_str *content, xs_val *rcpts,
|
|
|
|
xs_str *in_reply_to, xs_list *attach, int priv);
|
|
|
|
|
2022-10-01 07:12:33 +00:00
|
|
|
d_char *msg_undo(snac *snac, char *object);
|
2022-10-01 17:37:47 +00:00
|
|
|
d_char *msg_delete(snac *snac, char *id);
|
2022-10-02 15:42:36 +00:00
|
|
|
d_char *msg_actor(snac *snac);
|
2023-03-06 10:26:43 +00:00
|
|
|
xs_dict *msg_update(snac *snac, xs_dict *object);
|
2022-09-26 08:08:14 +00:00
|
|
|
|
2022-09-23 15:33:33 +00:00
|
|
|
int activitypub_request(snac *snac, char *url, d_char **data);
|
2022-09-23 16:46:30 +00:00
|
|
|
int actor_request(snac *snac, char *actor, d_char **data);
|
2023-02-07 09:29:06 +00:00
|
|
|
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);
|
|
|
|
int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg,
|
|
|
|
xs_val **payload, int *p_size, int timeout);
|
2022-11-18 07:10:47 +00:00
|
|
|
d_char *get_actor_inbox(snac *snac, char *actor);
|
2023-01-24 14:06:58 +00:00
|
|
|
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout);
|
2023-04-11 07:50:12 +00:00
|
|
|
int is_msg_public(snac *snac, const xs_dict *msg);
|
|
|
|
int is_msg_for_me(snac *snac, const xs_dict *msg);
|
2023-02-02 04:21:16 +00:00
|
|
|
|
2023-02-22 07:39:54 +00:00
|
|
|
int process_user_queue(snac *snac);
|
2023-02-06 19:07:29 +00:00
|
|
|
void process_queue_item(xs_dict *q_item);
|
2023-02-22 07:39:54 +00:00
|
|
|
int process_queue(void);
|
2023-02-02 04:21:16 +00:00
|
|
|
|
2022-09-23 18:59:19 +00:00
|
|
|
int activitypub_get_handler(d_char *req, char *q_path,
|
|
|
|
char **body, int *b_size, char **ctype);
|
2022-09-23 18:28:23 +00:00
|
|
|
int activitypub_post_handler(d_char *req, char *q_path,
|
|
|
|
char *payload, int p_size,
|
|
|
|
char **body, int *b_size, char **ctype);
|
2022-09-27 07:38:46 +00:00
|
|
|
|
2022-11-16 12:13:31 +00:00
|
|
|
d_char *not_really_markdown(const char *content);
|
|
|
|
d_char *sanitize(const char *str);
|
2022-10-28 16:06:42 +00:00
|
|
|
|
2022-09-28 03:22:08 +00:00
|
|
|
int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype);
|
|
|
|
int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size,
|
|
|
|
char **body, int *b_size, char **ctype);
|
2022-10-04 06:51:24 +00:00
|
|
|
|
2023-01-31 17:38:56 +00:00
|
|
|
int snac_init(const char *_basedir);
|
2022-12-04 20:14:18 +00:00
|
|
|
int adduser(const char *uid);
|
2022-12-04 20:26:24 +00:00
|
|
|
int resetpwd(snac *snac);
|
2023-02-06 19:29:18 +00:00
|
|
|
|
2023-02-11 05:28:36 +00:00
|
|
|
int job_fifo_ready(void);
|
2023-03-02 11:38:02 +00:00
|
|
|
void job_post(const xs_val *job, int urgent);
|
2023-02-06 19:29:18 +00:00
|
|
|
void job_wait(xs_val **job);
|
2023-04-08 04:09:05 +00:00
|
|
|
|
2023-04-08 07:09:43 +00:00
|
|
|
int oauth_get_handler(const xs_dict *req, const char *q_path,
|
|
|
|
char **body, int *b_size, char **ctype);
|
|
|
|
int oauth_post_handler(const xs_dict *req, const char *q_path,
|
2023-04-09 18:34:05 +00:00
|
|
|
const char *payload, int p_size,
|
|
|
|
char **body, int *b_size, char **ctype);
|
|
|
|
int mastoapi_get_handler(const xs_dict *req, const char *q_path,
|
|
|
|
char **body, int *b_size, char **ctype);
|
|
|
|
int mastoapi_post_handler(const xs_dict *req, const char *q_path,
|
|
|
|
const char *payload, int p_size,
|
|
|
|
char **body, int *b_size, char **ctype);
|