From 511f5062b7df26c47409c88649f24d68bbd43ccb Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 09:19:26 +0200 Subject: Deleted real unused parameters. --- activitypub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activitypub.c') diff --git a/activitypub.c b/activitypub.c index b20ae0f..13b1ce2 100644 --- a/activitypub.c +++ b/activitypub.c @@ -109,7 +109,7 @@ int actor_request(snac *snac, const char *actor, xs_dict **data) if (valid_status(status2)) { /* renew data */ - status = actor_add(snac, actor, payload); + status = actor_add(actor, payload); if (data != NULL) { *data = payload; @@ -1121,7 +1121,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) else if (strcmp(type, "Update") == 0) { if (strcmp(utype, "Person") == 0) { - actor_add(snac, actor, xs_dict_get(msg, "object")); + actor_add(actor, xs_dict_get(msg, "object")); snac_log(snac, xs_fmt("updated actor %s", actor)); } -- cgit v1.2.3 From 753eadfd1775545c5bfb4110ad2ba7cb61df9588 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 09:25:09 +0200 Subject: Added some const here and there. --- activitypub.c | 6 +++--- data.c | 2 +- html.c | 6 ++++-- httpd.c | 2 +- snac.h | 14 ++++++++------ 5 files changed, 17 insertions(+), 13 deletions(-) (limited to 'activitypub.c') diff --git a/activitypub.c b/activitypub.c index 13b1ce2..86d33df 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1426,7 +1426,7 @@ int process_queue(void) /** HTTP handlers */ -int activitypub_get_handler(d_char *req, char *q_path, +int activitypub_get_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype) { int status = 200; @@ -1519,8 +1519,8 @@ int activitypub_get_handler(d_char *req, char *q_path, } -int activitypub_post_handler(d_char *req, char *q_path, - d_char *payload, int p_size, +int activitypub_post_handler(const xs_dict *req, const char *q_path, + char *payload, int p_size, char **body, int *b_size, char **ctype) /* processes an input message */ { diff --git a/data.c b/data.c index f03fd71..72b63f8 100644 --- a/data.c +++ b/data.c @@ -1814,7 +1814,7 @@ static xs_dict *_new_qmsg(const char *type, const xs_val *msg, int retries) } -void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries) +void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries) /* enqueues an input message */ { xs *qmsg = _new_qmsg("input", msg, retries); diff --git a/html.c b/html.c index 2aa6514..3ba7930 100644 --- a/html.c +++ b/html.c @@ -1289,7 +1289,8 @@ xs_str *html_notifications(snac *snac) } -int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) +int html_get_handler(const xs_dict *req, const char *q_path, + char **body, int *b_size, char **ctype) { char *accept = xs_dict_get(req, "accept"); int status = 404; @@ -1546,7 +1547,8 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char * } -int html_post_handler(d_char *req, char *q_path, d_char *payload, int p_size, +int html_post_handler(const xs_dict *req, const char *q_path, + char *payload, int p_size, char **body, int *b_size, char **ctype) { int status = 0; diff --git a/httpd.c b/httpd.c index 70083a1..5520457 100644 --- a/httpd.c +++ b/httpd.c @@ -43,7 +43,7 @@ d_char *nodeinfo_2_0(void) } -int server_get_handler(d_char *req, char *q_path, +int server_get_handler(xs_dict *req, char *q_path, char **body, int *b_size, char **ctype) /* basic server services */ { diff --git a/snac.h b/snac.h index 54c8e51..5279453 100644 --- a/snac.h +++ b/snac.h @@ -155,7 +155,7 @@ void inbox_add(const char *inbox); void inbox_add_by_actor(const xs_dict *actor); xs_list *inbox_list(void); -void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries); +void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); void enqueue_output_raw(const char *keyid, const char *seckey, xs_dict *msg, xs_str *inbox, int retries); void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries); @@ -187,7 +187,7 @@ int check_signature(snac *snac, xs_dict *req, xs_str **err); void httpd(void); int webfinger_request(const char *qs, char **actor, char **user); -int webfinger_get_handler(d_char *req, char *q_path, +int webfinger_get_handler(xs_dict *req, char *q_path, char **body, int *b_size, char **ctype); const char *default_avatar_base64(void); @@ -220,17 +220,19 @@ int process_user_queue(snac *snac); void process_queue_item(xs_dict *q_item); int process_queue(void); -int activitypub_get_handler(d_char *req, char *q_path, +int activitypub_get_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype); -int activitypub_post_handler(d_char *req, char *q_path, +int activitypub_post_handler(const xs_dict *req, const char *q_path, char *payload, int p_size, char **body, int *b_size, char **ctype); d_char *not_really_markdown(const char *content); d_char *sanitize(const char *str); -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, +int html_get_handler(const xs_dict *req, const char *q_path, + char **body, int *b_size, char **ctype); +int html_post_handler(const xs_dict *req, const char *q_path, + char *payload, int p_size, char **body, int *b_size, char **ctype); int snac_init(const char *_basedir); -- cgit v1.2.3 From 185aac23876f9ae5d9b613f8b9abd517c3ab3b4d Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 09:28:36 +0200 Subject: Added -Wextra to C flags. --- Makefile | 2 +- activitypub.c | 2 ++ html.c | 3 +++ httpd.c | 6 ++++++ mastoapi.c | 13 +++++++++++++ webfinger.c | 2 ++ 6 files changed, 27 insertions(+), 1 deletion(-) (limited to 'activitypub.c') diff --git a/Makefile b/Makefile index 710d61f..7dbd9e7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PREFIX=/usr/local PREFIX_MAN=$(PREFIX)/man -CFLAGS?=-g -Wall +CFLAGS?=-g -Wall -Wextra all: snac diff --git a/activitypub.c b/activitypub.c index 86d33df..c25b733 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1524,6 +1524,8 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype) /* processes an input message */ { + (void)b_size; + int status = 202; /* accepted */ char *i_ctype = xs_dict_get(req, "content-type"); snac snac; diff --git a/html.c b/html.c index 3ba7930..3ebe70d 100644 --- a/html.c +++ b/html.c @@ -1551,6 +1551,9 @@ int html_post_handler(const xs_dict *req, const char *q_path, char *payload, int p_size, char **body, int *b_size, char **ctype) { + (void)p_size; + (void)ctype; + int status = 0; snac snac; char *uid, *p_path; diff --git a/httpd.c b/httpd.c index 5520457..fe93727 100644 --- a/httpd.c +++ b/httpd.c @@ -49,6 +49,8 @@ int server_get_handler(xs_dict *req, char *q_path, { int status = 0; + (void)req; + /* is it the server root? */ if (*q_path == '\0') { /* try to open greeting.html */ @@ -285,6 +287,8 @@ static jmp_buf on_break; void term_handler(int s) { + (void)s; + longjmp(on_break, 1); } @@ -401,6 +405,8 @@ static void *background_thread(void *arg) { time_t purge_time; + (void)arg; + /* first purge time */ purge_time = time(NULL) + 10 * 60; diff --git a/mastoapi.c b/mastoapi.c index c51c933..2413edb 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -175,6 +175,8 @@ const char *login_page = "" int oauth_get_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype) { + (void)b_size; + if (!xs_startswith(q_path, "/oauth/")) return 0; @@ -227,6 +229,9 @@ int oauth_post_handler(const xs_dict *req, const char *q_path, const char *payload, int p_size, char **body, int *b_size, char **ctype) { + (void)p_size; + (void)b_size; + if (!xs_startswith(q_path, "/oauth/")) return 0; @@ -815,6 +820,8 @@ int process_auth_token(snac *snac, const xs_dict *req) int mastoapi_get_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype) { + (void)b_size; + if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; @@ -1474,6 +1481,9 @@ 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) { + (void)p_size; + (void)b_size; + if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; @@ -1898,6 +1908,9 @@ int mastoapi_put_handler(const xs_dict *req, const char *q_path, const char *payload, int p_size, char **body, int *b_size, char **ctype) { + (void)p_size; + (void)b_size; + if (!xs_startswith(q_path, "/api/v1/") && !xs_startswith(q_path, "/api/v2/")) return 0; diff --git a/webfinger.c b/webfinger.c index f56b6f2..765c469 100644 --- a/webfinger.c +++ b/webfinger.c @@ -104,6 +104,8 @@ int webfinger_get_handler(d_char *req, char *q_path, { int status; + (void)b_size; + if (strcmp(q_path, "/.well-known/webfinger") != 0) return 0; -- cgit v1.2.3 From 980a8d524fae11d17366e7aea56206d13f278e31 Mon Sep 17 00:00:00 2001 From: default Date: Thu, 4 May 2023 09:34:33 +0200 Subject: Fixed more warnings. --- activitypub.c | 3 ++- html.c | 1 + mastoapi.c | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'activitypub.c') diff --git a/activitypub.c b/activitypub.c index c25b733..0d5439d 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1384,8 +1384,9 @@ void process_queue_item(xs_dict *q_item) xs *headers = xs_dict_new(); headers = xs_dict_append(headers, "content-type", "application/json"); - xs *rsp = xs_http_request("POST", url, headers, + xs *rsp = xs_http_request("POST", url, headers, body, strlen(body), &status, NULL, NULL, 0); + rsp = xs_free(rsp); srv_debug(0, xs_fmt("telegram post %d", status)); } diff --git a/html.c b/html.c index 3ebe70d..8d4203d 100644 --- a/html.c +++ b/html.c @@ -1282,6 +1282,7 @@ xs_str *html_notifications(snac *snac) /* set the check time to now */ xs *dummy = notify_check_time(snac, 1); + dummy = xs_free(dummy); timeline_touch(snac); diff --git a/mastoapi.c b/mastoapi.c index 2413edb..c333573 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -542,7 +542,6 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) xs *f = xs_val_new(XSTYPE_FALSE); xs *t = xs_val_new(XSTYPE_TRUE); xs *n = xs_val_new(XSTYPE_NULL); - xs *el = xs_list_new(); xs *idx = NULL; xs *ixc = NULL; -- cgit v1.2.3 From d3a36218a6ebfc951ff38c410ac1c29ec15c3c7f Mon Sep 17 00:00:00 2001 From: default Date: Fri, 5 May 2023 09:54:41 +0200 Subject: Implemented 'Ping' and 'Pong' activities. According to https://humungus.tedunangst.com/r/honk/v/tip/f/docs/ping.txt --- activitypub.c | 41 ++++++++++++++++++++++++++++++++++++++--- main.c | 14 ++++++++++++++ snac.h | 2 ++ 3 files changed, 54 insertions(+), 3 deletions(-) (limited to 'activitypub.c') diff --git a/activitypub.c b/activitypub.c index 0d5439d..6127dab 100644 --- a/activitypub.c +++ b/activitypub.c @@ -437,7 +437,8 @@ void process_tags(snac *snac, const char *content, d_char **n_content, d_char ** /** messages **/ -d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char *object) +xs_dict *msg_base(snac *snac, const char *type, const char *id, + const char *actor, const char *date, const char *object) /* creates a base ActivityPub message */ { xs *did = NULL; @@ -467,7 +468,7 @@ d_char *msg_base(snac *snac, char *type, char *id, char *actor, char *date, char } } - d_char *msg = xs_dict_new(); + xs_dict *msg = xs_dict_new(); msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams"); msg = xs_dict_append(msg, "type", type); @@ -845,6 +846,28 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, } +xs_dict *msg_ping(snac *user, const char *rcpt) +/* creates a Ping message (https://humungus.tedunangst.com/r/honk/v/tip/f/docs/ping.txt) */ +{ + xs_dict *msg = msg_base(user, "Ping", "@dummy", user->actor, NULL, NULL); + + msg = xs_dict_append(msg, "to", rcpt); + + return msg; +} + + +xs_dict *msg_pong(snac *user, const char *rcpt, const char *object) +/* creates a Pong message (https://humungus.tedunangst.com/r/honk/v/tip/f/docs/ping.txt) */ +{ + xs_dict *msg = msg_base(user, "Pong", "@dummy", user->actor, NULL, object); + + msg = xs_dict_append(msg, "to", rcpt); + + return msg; +} + + void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg) /* notifies the user of relevant events */ { @@ -1147,7 +1170,19 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) snac_debug(snac, 1, xs_fmt("ignored 'Delete' for unknown object %s", object)); } else - snac_debug(snac, 1, xs_fmt("process_message type '%s' ignored", type)); + if (strcmp(type, "Pong") == 0) { + snac_log(snac, xs_fmt("'Pong' received from %s", actor)); + } + else + if (strcmp(type, "Ping") == 0) { + snac_log(snac, xs_fmt("'Ping' requested from %s", actor)); + + xs *rsp = msg_pong(snac, actor, xs_dict_get(msg, "id")); + + enqueue_output_by_actor(snac, rsp, actor, 0); + } + else + snac_debug(snac, 1, xs_fmt("process_input_message type '%s' ignored", type)); if (do_notify) { notify(snac, type, utype, actor, msg); diff --git a/main.c b/main.c index 6a0bb74..b8fc97b 100644 --- a/main.c +++ b/main.c @@ -30,6 +30,7 @@ int usage(void) printf("actor {basedir} {uid} {url} Requests an actor\n"); printf("note {basedir} {uid} {'text'} Sends a note to followers\n"); printf("resetpwd {basedir} {uid} Resets the password of a user\n"); + printf("ping {basedir} {uid} {actor} Pings an actor\n"); return 1; } @@ -228,6 +229,19 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(cmd, "ping") == 0) { + xs *msg = msg_ping(&snac, url); + + enqueue_output_by_actor(&snac, msg, url, 0); + + if (dbglevel) { + xs *j = xs_json_dumps_pp(msg, 4); + printf("%s\n", msg); + } + + return 0; + } + if (strcmp(cmd, "request") == 0) { int status; xs *data = NULL; diff --git a/snac.h b/snac.h index 5279453..7d4b8f4 100644 --- a/snac.h +++ b/snac.h @@ -203,6 +203,8 @@ d_char *msg_undo(snac *snac, char *object); d_char *msg_delete(snac *snac, char *id); d_char *msg_actor(snac *snac); xs_dict *msg_update(snac *snac, xs_dict *object); +xs_dict *msg_ping(snac *user, const char *rcpt); +xs_dict *msg_pong(snac *user, const char *rcpt, const char *object); int activitypub_request(snac *snac, const char *url, xs_dict **data); int actor_request(snac *snac, const char *actor, xs_dict **data); -- cgit v1.2.3