2022-09-19 19:13:40 +00:00
|
|
|
/* snac - A simple, minimalistic ActivityPub instance */
|
2022-09-19 18:47:22 +00:00
|
|
|
/* copyright (c) 2022 grunfink - MIT license */
|
|
|
|
|
2022-11-23 14:46:43 +00:00
|
|
|
#define VERSION "2.12"
|
2022-09-27 16:01:51 +00:00
|
|
|
|
|
|
|
#define USER_AGENT "snac/" VERSION
|
|
|
|
|
2022-11-23 12:32:23 +00:00
|
|
|
extern double db_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 05:05:23 +00:00
|
|
|
extern const char *susie;
|
|
|
|
|
2022-09-28 07:46:21 +00:00
|
|
|
#define L(s) (s)
|
|
|
|
|
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 {
|
|
|
|
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-19 21:03:18 +00:00
|
|
|
int user_open(snac *snac, char *uid);
|
|
|
|
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
|
|
|
|
|
|
|
int validate_uid(char *uid);
|
2022-09-19 20:58:27 +00:00
|
|
|
|
|
|
|
d_char *hash_password(char *uid, char *passwd, char *nonce);
|
|
|
|
int check_password(char *uid, char *passwd, char *hash);
|
2022-09-20 07:48:13 +00:00
|
|
|
|
2022-09-25 05:28:42 +00:00
|
|
|
void srv_archive(char *direction, char *req, char *payload, int p_size,
|
|
|
|
int status, char *headers, char *body, int b_size);
|
|
|
|
|
2022-11-25 12:33:13 +00:00
|
|
|
double mtime_nl(const char *fn, int *n_link);
|
|
|
|
#define mtime(fn) mtime_nl(fn, NULL)
|
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);
|
|
|
|
int index_del(const char *fn, const char *md5);
|
2022-11-26 16:35:18 +00:00
|
|
|
int index_first(const char *fn, char *buf, int size);
|
2022-11-24 07:00:35 +00:00
|
|
|
d_char *index_list(const char *fn, int max);
|
|
|
|
d_char *index_list_desc(const char *fn, int max);
|
2022-11-23 19:50:35 +00:00
|
|
|
|
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);
|
2022-11-25 11:09:30 +00:00
|
|
|
|
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);
|
2022-09-25 16:28:15 +00:00
|
|
|
int timeline_here(snac *snac, char *id);
|
2022-09-29 11:15:57 +00:00
|
|
|
d_char *_timeline_find_fn(snac *snac, char *id);
|
2022-09-20 08:49:24 +00:00
|
|
|
d_char *timeline_find(snac *snac, char *id);
|
2022-10-20 08:34:32 +00:00
|
|
|
int timeline_del(snac *snac, char *id);
|
2022-09-20 08:49:24 +00:00
|
|
|
d_char *timeline_get(snac *snac, char *fn);
|
2022-09-28 02:48:23 +00:00
|
|
|
d_char *timeline_list(snac *snac, int max);
|
2022-09-26 05:13:39 +00:00
|
|
|
int timeline_add(snac *snac, char *id, char *o_msg, char *parent, char *referrer);
|
2022-09-25 15:42:39 +00:00
|
|
|
void timeline_admire(snac *snac, char *id, char *admirer, int like);
|
2022-09-20 09:31:56 +00:00
|
|
|
|
2022-11-26 17:52:51 +00:00
|
|
|
d_char *timeline_top_level(snac *snac, d_char *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
|
|
|
|
2022-09-28 18:41:07 +00:00
|
|
|
void enqueue_input(snac *snac, char *msg, char *req, int retries);
|
2022-11-17 17:33:54 +00:00
|
|
|
void enqueue_output(snac *snac, char *msg, char *inbox, int retries);
|
2022-11-18 07:21:40 +00:00
|
|
|
void enqueue_output_by_actor(snac *snac, char *msg, char *actor, int retries);
|
2022-10-21 17:07:20 +00:00
|
|
|
void enqueue_email(snac *snac, char *msg, int retries);
|
2022-09-22 15:12:46 +00:00
|
|
|
|
2022-09-20 10:43:49 +00:00
|
|
|
d_char *queue(snac *snac);
|
2022-09-20 10:50:37 +00:00
|
|
|
d_char *dequeue(snac *snac, 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
|
|
|
|
2022-09-20 19:00:16 +00: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-29 12:44:24 +00:00
|
|
|
int check_signature(snac *snac, char *req);
|
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
|
|
|
|
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);
|
2022-10-10 07:03:07 +00:00
|
|
|
d_char *msg_note(snac *snac, char *content, char *rcpts, char *in_reply_to, char *attach);
|
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);
|
|
|
|
d_char *msg_update(snac *snac, char *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);
|
2022-09-23 17:07:45 +00:00
|
|
|
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size);
|
2022-11-18 07:10:47 +00:00
|
|
|
d_char *get_actor_inbox(snac *snac, char *actor);
|
2022-09-23 17:07:45 +00:00
|
|
|
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size);
|
2022-09-28 05:05:23 +00:00
|
|
|
int is_msg_public(snac *snac, char *msg);
|
2022-09-23 17:37:01 +00:00
|
|
|
void process_queue(snac *snac);
|
2022-09-26 09:19:45 +00:00
|
|
|
void post(snac *snac, char *msg);
|
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
|
|
|
|
|
|
|
int initdb(const char *_basedir);
|
2022-10-04 07:40:16 +00:00
|
|
|
int adduser(char *uid);
|