diff options
| author | 2024-05-25 08:05:36 +0000 | |
|---|---|---|
| committer | 2024-05-25 08:05:36 +0000 | |
| commit | 84a767dd0878013194ed7551b5ae6ef715e841a6 (patch) | |
| tree | 9fb1b2b89e0bfbb4b8bf1e85d840c8653e646bb7 /snac.h | |
| parent | Prevent some browsers from caching servers basic auth request (diff) | |
| parent | Backport from xs (fix regex.h compilation with tcc). (diff) | |
| download | snac2-84a767dd0878013194ed7551b5ae6ef715e841a6.tar.gz snac2-84a767dd0878013194ed7551b5ae6ef715e841a6.tar.xz snac2-84a767dd0878013194ed7551b5ae6ef715e841a6.zip | |
Merge pull request 'master' (#1) from grunfink/snac2:master into master
Reviewed-on: https://codeberg.org/louis77/snac2/pulls/1
Diffstat (limited to 'snac.h')
| -rw-r--r-- | snac.h | 69 |
1 files changed, 41 insertions, 28 deletions
| @@ -1,7 +1,7 @@ | |||
| 1 | /* snac - A simple, minimalistic ActivityPub instance */ | 1 | /* snac - A simple, minimalistic ActivityPub instance */ |
| 2 | /* copyright (c) 2022 - 2024 grunfink et al. / MIT license */ | 2 | /* copyright (c) 2022 - 2024 grunfink et al. / MIT license */ |
| 3 | 3 | ||
| 4 | #define VERSION "2.52-dev" | 4 | #define VERSION "2.53" |
| 5 | 5 | ||
| 6 | #define USER_AGENT "snac/" VERSION | 6 | #define USER_AGENT "snac/" VERSION |
| 7 | 7 | ||
| @@ -29,6 +29,8 @@ extern int dbglevel; | |||
| 29 | 29 | ||
| 30 | #define L(s) (s) | 30 | #define L(s) (s) |
| 31 | 31 | ||
| 32 | #define POSTLIKE_OBJECT_TYPE "Note|Question|Page|Article|Video|Event" | ||
| 33 | |||
| 32 | int mkdirx(const char *pathname); | 34 | int mkdirx(const char *pathname); |
| 33 | 35 | ||
| 34 | int valid_status(int status); | 36 | int valid_status(int status); |
| @@ -67,7 +69,7 @@ void snac_log(snac *user, xs_str *str); | |||
| 67 | #define snac_debug(user, level, str) do { if (dbglevel >= (level)) \ | 69 | #define snac_debug(user, level, str) do { if (dbglevel >= (level)) \ |
| 68 | { snac_log((user), (str)); } } while (0) | 70 | { snac_log((user), (str)); } } while (0) |
| 69 | 71 | ||
| 70 | int srv_open(char *basedir, int auto_upgrade); | 72 | int srv_open(const char *basedir, int auto_upgrade); |
| 71 | void srv_free(void); | 73 | void srv_free(void); |
| 72 | 74 | ||
| 73 | int user_open(snac *snac, const char *uid); | 75 | int user_open(snac *snac, const char *uid); |
| @@ -86,7 +88,7 @@ void srv_archive(const char *direction, const char *url, xs_dict *req, | |||
| 86 | const char *body, int b_size); | 88 | const char *body, int b_size); |
| 87 | void srv_archive_error(const char *prefix, const xs_str *err, | 89 | void srv_archive_error(const char *prefix, const xs_str *err, |
| 88 | const xs_dict *req, const xs_val *data); | 90 | const xs_dict *req, const xs_val *data); |
| 89 | void srv_archive_qitem(char *prefix, xs_dict *q_item); | 91 | void srv_archive_qitem(const char *prefix, xs_dict *q_item); |
| 90 | 92 | ||
| 91 | double mtime_nl(const char *fn, int *n_link); | 93 | double mtime_nl(const char *fn, int *n_link); |
| 92 | #define mtime(fn) mtime_nl(fn, NULL) | 94 | #define mtime(fn) mtime_nl(fn, NULL) |
| @@ -137,13 +139,13 @@ double timeline_mtime(snac *snac); | |||
| 137 | int timeline_touch(snac *snac); | 139 | int timeline_touch(snac *snac); |
| 138 | int timeline_here(snac *snac, const char *md5); | 140 | int timeline_here(snac *snac, const char *md5); |
| 139 | int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg); | 141 | int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg); |
| 140 | int timeline_del(snac *snac, char *id); | 142 | int timeline_del(snac *snac, const char *id); |
| 141 | xs_list *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show); | 143 | xs_list *timeline_simple_list(snac *snac, const char *idx_name, int skip, int show); |
| 142 | xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show); | 144 | xs_list *timeline_list(snac *snac, const char *idx_name, int skip, int show); |
| 143 | int timeline_add(snac *snac, const char *id, const xs_dict *o_msg); | 145 | int timeline_add(snac *snac, const char *id, const xs_dict *o_msg); |
| 144 | int timeline_admire(snac *snac, const char *id, const char *admirer, int like); | 146 | int timeline_admire(snac *snac, const char *id, const char *admirer, int like); |
| 145 | 147 | ||
| 146 | xs_list *timeline_top_level(snac *snac, xs_list *list); | 148 | xs_list *timeline_top_level(snac *snac, const xs_list *list); |
| 147 | xs_list *local_list(snac *snac, int max); | 149 | xs_list *local_list(snac *snac, int max); |
| 148 | xs_list *timeline_instance_list(int skip, int show); | 150 | xs_list *timeline_instance_list(int skip, int show); |
| 149 | 151 | ||
| @@ -172,9 +174,14 @@ void hide(snac *snac, const char *id); | |||
| 172 | int is_hidden(snac *snac, const char *id); | 174 | int is_hidden(snac *snac, const char *id); |
| 173 | 175 | ||
| 174 | void tag_index(const char *id, const xs_dict *obj); | 176 | void tag_index(const char *id, const xs_dict *obj); |
| 175 | xs_list *tag_search(char *tag, int skip, int show); | 177 | xs_list *tag_search(const char *tag, int skip, int show); |
| 178 | |||
| 179 | xs_val *list_maint(snac *user, const char *list, int op); | ||
| 180 | xs_list *list_timeline(snac *user, const char *list, int skip, int show); | ||
| 181 | xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op); | ||
| 182 | void list_distribute(snac *user, const char *who, const xs_dict *post); | ||
| 176 | 183 | ||
| 177 | int actor_add(const char *actor, xs_dict *msg); | 184 | int actor_add(const char *actor, const xs_dict *msg); |
| 178 | int actor_get(const char *actor, xs_dict **data); | 185 | int actor_get(const char *actor, xs_dict **data); |
| 179 | int actor_get_refresh(snac *user, const char *actor, xs_dict **data); | 186 | int actor_get_refresh(snac *user, const char *actor, xs_dict **data); |
| 180 | 187 | ||
| @@ -209,22 +216,27 @@ int is_instance_blocked(const char *instance); | |||
| 209 | int instance_block(const char *instance); | 216 | int instance_block(const char *instance); |
| 210 | int instance_unblock(const char *instance); | 217 | int instance_unblock(const char *instance); |
| 211 | 218 | ||
| 212 | int content_check(const char *file, const xs_dict *msg); | 219 | int content_match(const char *file, const xs_dict *msg); |
| 220 | xs_list *content_search(snac *user, const char *regex, | ||
| 221 | int priv, int skip, int show, int max_secs, int *timeout); | ||
| 213 | 222 | ||
| 214 | void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); | 223 | void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); |
| 215 | void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries); | 224 | void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries); |
| 216 | void enqueue_output_raw(const char *keyid, const char *seckey, | 225 | void enqueue_output_raw(const char *keyid, const char *seckey, |
| 217 | xs_dict *msg, xs_str *inbox, int retries, int p_status); | 226 | const xs_dict *msg, const xs_str *inbox, |
| 218 | void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries, int p_status); | 227 | int retries, int p_status); |
| 219 | void enqueue_output_by_actor(snac *snac, xs_dict *msg, const xs_str *actor, int retries); | 228 | void enqueue_output(snac *snac, const xs_dict *msg, |
| 220 | void enqueue_email(xs_str *msg, int retries); | 229 | const xs_str *inbox, int retries, int p_status); |
| 230 | void enqueue_output_by_actor(snac *snac, const xs_dict *msg, | ||
| 231 | const xs_str *actor, int retries); | ||
| 232 | void enqueue_email(const xs_str *msg, int retries); | ||
| 221 | void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); | 233 | void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); |
| 222 | void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_token); | 234 | void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_token); |
| 223 | void enqueue_message(snac *snac, const xs_dict *msg); | 235 | void enqueue_message(snac *snac, const xs_dict *msg); |
| 224 | void enqueue_close_question(snac *user, const char *id, int end_secs); | 236 | void enqueue_close_question(snac *user, const char *id, int end_secs); |
| 237 | void enqueue_object_request(snac *user, const char *id, int forward_secs); | ||
| 225 | void enqueue_verify_links(snac *user); | 238 | void enqueue_verify_links(snac *user); |
| 226 | void enqueue_actor_refresh(snac *user, const char *actor); | 239 | void enqueue_actor_refresh(snac *user, const char *actor, int forward_secs); |
| 227 | void enqueue_request_replies(snac *user, const char *id); | ||
| 228 | int was_question_voted(snac *user, const char *id); | 240 | int was_question_voted(snac *user, const char *id); |
| 229 | 241 | ||
| 230 | xs_list *user_queue(snac *snac); | 242 | xs_list *user_queue(snac *snac); |
| @@ -237,16 +249,16 @@ void purge_all(void); | |||
| 237 | 249 | ||
| 238 | xs_dict *http_signed_request_raw(const char *keyid, const char *seckey, | 250 | xs_dict *http_signed_request_raw(const char *keyid, const char *seckey, |
| 239 | const char *method, const char *url, | 251 | const char *method, const char *url, |
| 240 | xs_dict *headers, | 252 | const xs_dict *headers, |
| 241 | const char *body, int b_size, | 253 | const char *body, int b_size, |
| 242 | int *status, xs_str **payload, int *p_size, | 254 | int *status, xs_str **payload, int *p_size, |
| 243 | int timeout); | 255 | int timeout); |
| 244 | xs_dict *http_signed_request(snac *snac, const char *method, const char *url, | 256 | xs_dict *http_signed_request(snac *snac, const char *method, const char *url, |
| 245 | xs_dict *headers, | 257 | const xs_dict *headers, |
| 246 | const char *body, int b_size, | 258 | const char *body, int b_size, |
| 247 | int *status, xs_str **payload, int *p_size, | 259 | int *status, xs_str **payload, int *p_size, |
| 248 | int timeout); | 260 | int timeout); |
| 249 | int check_signature(xs_dict *req, xs_str **err); | 261 | int check_signature(const xs_dict *req, xs_str **err); |
| 250 | 262 | ||
| 251 | srv_state *srv_state_op(xs_str **fname, int op); | 263 | srv_state *srv_state_op(xs_str **fname, int op); |
| 252 | void httpd(void); | 264 | void httpd(void); |
| @@ -260,21 +272,21 @@ const char *default_avatar_base64(void); | |||
| 260 | 272 | ||
| 261 | xs_str *process_tags(snac *snac, const char *content, xs_list **tag); | 273 | xs_str *process_tags(snac *snac, const char *content, xs_list **tag); |
| 262 | 274 | ||
| 263 | char *get_atto(const xs_dict *msg); | 275 | const char *get_atto(const xs_dict *msg); |
| 264 | xs_list *get_attachments(const xs_dict *msg); | 276 | xs_list *get_attachments(const xs_dict *msg); |
| 265 | 277 | ||
| 266 | xs_dict *msg_admiration(snac *snac, char *object, char *type); | 278 | xs_dict *msg_admiration(snac *snac, const char *object, const char *type); |
| 267 | xs_dict *msg_repulsion(snac *user, char *id, char *type); | 279 | xs_dict *msg_repulsion(snac *user, const char *id, const char *type); |
| 268 | xs_dict *msg_create(snac *snac, const xs_dict *object); | 280 | xs_dict *msg_create(snac *snac, const xs_dict *object); |
| 269 | xs_dict *msg_follow(snac *snac, const char *actor); | 281 | xs_dict *msg_follow(snac *snac, const char *actor); |
| 270 | 282 | ||
| 271 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | 283 | xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, |
| 272 | xs_str *in_reply_to, xs_list *attach, int priv); | 284 | const xs_str *in_reply_to, const xs_list *attach, int priv); |
| 273 | 285 | ||
| 274 | xs_dict *msg_undo(snac *snac, char *object); | 286 | xs_dict *msg_undo(snac *snac, const xs_val *object); |
| 275 | xs_dict *msg_delete(snac *snac, char *id); | 287 | xs_dict *msg_delete(snac *snac, const char *id); |
| 276 | xs_dict *msg_actor(snac *snac); | 288 | xs_dict *msg_actor(snac *snac); |
| 277 | xs_dict *msg_update(snac *snac, xs_dict *object); | 289 | xs_dict *msg_update(snac *snac, const xs_dict *object); |
| 278 | xs_dict *msg_ping(snac *user, const char *rcpt); | 290 | xs_dict *msg_ping(snac *user, const char *rcpt); |
| 279 | xs_dict *msg_pong(snac *user, const char *rcpt, const char *object); | 291 | xs_dict *msg_pong(snac *user, const char *rcpt, const char *object); |
| 280 | xs_dict *msg_question(snac *user, const char *content, xs_list *attach, | 292 | xs_dict *msg_question(snac *user, const char *content, xs_list *attach, |
| @@ -282,7 +294,6 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach, | |||
| 282 | 294 | ||
| 283 | int activitypub_request(snac *snac, const char *url, xs_dict **data); | 295 | int activitypub_request(snac *snac, const char *url, xs_dict **data); |
| 284 | int actor_request(snac *user, const char *actor, xs_dict **data); | 296 | int actor_request(snac *user, const char *actor, xs_dict **data); |
| 285 | void timeline_request_replies(snac *user, const char *id); | ||
| 286 | int send_to_inbox_raw(const char *keyid, const char *seckey, | 297 | int send_to_inbox_raw(const char *keyid, const char *seckey, |
| 287 | const xs_str *inbox, const xs_dict *msg, | 298 | const xs_str *inbox, const xs_dict *msg, |
| 288 | xs_val **payload, int *p_size, int timeout); | 299 | xs_val **payload, int *p_size, int timeout); |
| @@ -312,13 +323,14 @@ xs_str *encode_html(const char *str); | |||
| 312 | 323 | ||
| 313 | xs_str *html_timeline(snac *user, const xs_list *list, int read_only, | 324 | xs_str *html_timeline(snac *user, const xs_list *list, int read_only, |
| 314 | int skip, int show, int show_more, | 325 | int skip, int show, int show_more, |
| 315 | char *tag, char *page, int utl); | 326 | char *title, char *page, int utl); |
| 316 | 327 | ||
| 317 | int html_get_handler(const xs_dict *req, const char *q_path, | 328 | int html_get_handler(const xs_dict *req, const char *q_path, |
| 318 | char **body, int *b_size, char **ctype, xs_str **etag); | 329 | char **body, int *b_size, char **ctype, xs_str **etag); |
| 319 | int html_post_handler(const xs_dict *req, const char *q_path, | 330 | int html_post_handler(const xs_dict *req, const char *q_path, |
| 320 | char *payload, int p_size, | 331 | char *payload, int p_size, |
| 321 | char **body, int *b_size, char **ctype); | 332 | char **body, int *b_size, char **ctype); |
| 333 | xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc); | ||
| 322 | 334 | ||
| 323 | int snac_init(const char *_basedir); | 335 | int snac_init(const char *_basedir); |
| 324 | int adduser(const char *uid); | 336 | int adduser(const char *uid); |
| @@ -337,11 +349,12 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, | |||
| 337 | char **body, int *b_size, char **ctype); | 349 | char **body, int *b_size, char **ctype); |
| 338 | int mastoapi_get_handler(const xs_dict *req, const char *q_path, | 350 | int mastoapi_get_handler(const xs_dict *req, const char *q_path, |
| 339 | char **body, int *b_size, char **ctype); | 351 | char **body, int *b_size, char **ctype); |
| 340 | int mastoapi_delete_handler(const xs_dict *req, const char *q_path, | ||
| 341 | char **body, int *b_size, char **ctype); | ||
| 342 | int mastoapi_post_handler(const xs_dict *req, const char *q_path, | 352 | int mastoapi_post_handler(const xs_dict *req, const char *q_path, |
| 343 | const char *payload, int p_size, | 353 | const char *payload, int p_size, |
| 344 | char **body, int *b_size, char **ctype); | 354 | char **body, int *b_size, char **ctype); |
| 355 | int mastoapi_delete_handler(const xs_dict *req, const char *q_path, | ||
| 356 | const char *payload, int p_size, | ||
| 357 | char **body, int *b_size, char **ctype); | ||
| 345 | int mastoapi_put_handler(const xs_dict *req, const char *q_path, | 358 | int mastoapi_put_handler(const xs_dict *req, const char *q_path, |
| 346 | const char *payload, int p_size, | 359 | const char *payload, int p_size, |
| 347 | char **body, int *b_size, char **ctype); | 360 | char **body, int *b_size, char **ctype); |