From 24105f6e9759b74c04522de1de12ddb77cfba568 Mon Sep 17 00:00:00 2001 From: postscriptum Date: Thu, 22 May 2025 03:34:48 +0300 Subject: use utf-8 lowercase function for tags #396 --- data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index e3fa52d..d5dc171 100644 --- a/data.c +++ b/data.c @@ -2200,7 +2200,7 @@ void tag_index(const char *id, const xs_dict *obj) if (*name == '\0') continue; - name = xs_tolower_i((xs_str *)name); + name = xs_utf8_to_lower((xs_str *)name); xs *md5_tag = xs_md5_hex(name, strlen(name)); xs *tag_dir = xs_fmt("%s/%c%c", g_tag_dir, md5_tag[0], md5_tag[1]); @@ -2230,7 +2230,7 @@ xs_str *tag_fn(const char *tag) if (*tag == '#') tag++; - xs *lw_tag = xs_tolower_i(xs_dup(tag)); + xs *lw_tag = xs_utf8_to_lower(xs_dup(tag)); xs *md5 = xs_md5_hex(lw_tag, strlen(lw_tag)); return xs_fmt("%s/tag/%c%c/%s.idx", srv_basedir, md5[0], md5[1], md5); -- cgit v1.2.3 From e567736640da21d37848567cd164cb84bbdab507 Mon Sep 17 00:00:00 2001 From: postscriptum Date: Thu, 22 May 2025 04:16:28 +0300 Subject: add missed replacement to the `content_match` function --- data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index d5dc171..8ca271d 100644 --- a/data.c +++ b/data.c @@ -2817,7 +2817,7 @@ int content_match(const char *file, const xs_dict *msg) /* massage content (strip HTML tags, etc.) */ xs *c = xs_regex_replace(v, "<[^>]+>", " "); c = xs_regex_replace_i(c, " {2,}", " "); - c = xs_tolower_i(c); + c = xs_utf8_to_lower(c); while (!r && !feof(f)) { xs *rx = xs_strip_i(xs_readline(f)); -- cgit v1.2.3 From 56816b305155fee2154c7991ba9be8c0e7671307 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 22 May 2025 11:18:48 +0200 Subject: Minor memory leak fixes. --- data.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 631a68b..5f890d3 100644 --- a/data.c +++ b/data.c @@ -2247,7 +2247,7 @@ xs_str *tag_fn(const char *tag) if (*tag == '#') tag++; - xs *lw_tag = xs_utf8_to_lower(xs_dup(tag)); + xs *lw_tag = xs_utf8_to_lower(tag); xs *md5 = xs_md5_hex(lw_tag, strlen(lw_tag)); return xs_fmt("%s/tag/%c%c/%s.idx", srv_basedir, md5[0], md5[1], md5); @@ -2832,9 +2832,9 @@ int content_match(const char *file, const xs_dict *msg) srv_debug(1, xs_fmt("content_match: loading regexes from %s", fn)); /* massage content (strip HTML tags, etc.) */ - xs *c = xs_regex_replace(v, "<[^>]+>", " "); - c = xs_regex_replace_i(c, " {2,}", " "); - c = xs_utf8_to_lower(c); + xs *c1 = xs_regex_replace(v, "<[^>]+>", " "); + c1 = xs_regex_replace_i(c1, " {2,}", " "); + xs *c = xs_utf8_to_lower(c1); while (!r && !feof(f)) { xs *rx = xs_strip_i(xs_readline(f)); -- cgit v1.2.3 From 11b4a46d54ce55545a8ac4958e5ff292c072d1d3 Mon Sep 17 00:00:00 2001 From: shtrophic Date: Sun, 25 May 2025 11:38:15 +0200 Subject: Increase verbosity for srv_debug() in tag_index() --- data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index 5f890d3..f45e346 100644 --- a/data.c +++ b/data.c @@ -2235,7 +2235,7 @@ void tag_index(const char *id, const xs_dict *obj) fclose(f); } - srv_debug(0, xs_fmt("tagged %s #%s (#%s)", id, name, md5_tag)); + srv_debug(1, xs_fmt("tagged %s #%s (#%s)", id, name, md5_tag)); } } } -- cgit v1.2.3 From 631e44a64a20741b5e4716bf75caf7fa743fef82 Mon Sep 17 00:00:00 2001 From: grunfink Date: Tue, 27 May 2025 21:08:57 +0200 Subject: Renamed timeline_here() to timeline_here_by_md5(), as it always should have been. --- data.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index f45e346..9eada38 100644 --- a/data.c +++ b/data.c @@ -1391,7 +1391,7 @@ xs_str *timeline_fn_by_md5(snac *snac, const char *md5) } -int timeline_here(snac *snac, const char *md5) +int timeline_here_by_md5(snac *snac, const char *md5) /* checks if an object is in the user cache */ { xs *fn = timeline_fn_by_md5(snac, md5); @@ -1515,7 +1515,7 @@ xs_list *timeline_top_level(snac *snac, const xs_list *list) break; /* well, there is a parent... but is it here? */ - if (!timeline_here(snac, line2)) + if (!timeline_here_by_md5(snac, line2)) break; /* it's here! try again with its own parent */ -- cgit v1.2.3 From 5bc451159420d5d51a507fda82a623069cfae92b Mon Sep 17 00:00:00 2001 From: grunfink Date: Tue, 27 May 2025 21:14:23 +0200 Subject: New function timeline_here(). --- data.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index 9eada38..224976b 100644 --- a/data.c +++ b/data.c @@ -1400,6 +1400,14 @@ int timeline_here_by_md5(snac *snac, const char *md5) } +int timeline_here(snac *user, const char *id) +{ + xs *md5 = xs_md5_hex(id, strlen(id)); + + return timeline_here_by_md5(user, md5); +} + + int timeline_get_by_md5(snac *snac, const char *md5, xs_dict **msg) /* gets a message from the timeline */ { -- cgit v1.2.3 From c8f6e1865dca9477d0cdfb95168bdca4a62852c3 Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 30 May 2025 11:30:37 +0200 Subject: New function enqueue_notify_webhook(). --- data.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index 224976b..ddfb443 100644 --- a/data.c +++ b/data.c @@ -3166,6 +3166,8 @@ void notify_add(snac *snac, const char *type, const char *utype, pthread_mutex_unlock(&data_mutex); } + + enqueue_notify_webhook(snac, noti, 0); } @@ -3521,6 +3523,23 @@ void enqueue_webmention(const xs_dict *msg) } +void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries) +/* enqueues a notification webhook */ +{ + const char *webhook = xs_dict_get(user->config, "notify_webhook"); + + if (xs_is_string(webhook)) { + xs *qmsg = _new_qmsg("notify_webhook", noti, retries); + const char *ntid = xs_dict_get(qmsg, "ntid"); + xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid); + + qmsg = _enqueue_put(fn, qmsg); + + snac_debug(user, 1, xs_fmt("notify_webhook")); + } +} + + int was_question_voted(snac *user, const char *id) /* returns true if the user voted in this poll */ { -- cgit v1.2.3 From 5a2aef8666a82a30dff329992bd41baa53d4e123 Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 30 May 2025 12:12:19 +0200 Subject: More notify_webhook work. --- data.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index ddfb443..10084f9 100644 --- a/data.c +++ b/data.c @@ -3529,7 +3529,16 @@ void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries) const char *webhook = xs_dict_get(user->config, "notify_webhook"); if (xs_is_string(webhook)) { - xs *qmsg = _new_qmsg("notify_webhook", noti, retries); + xs *msg = xs_dup(noti); + + /* add more data */ + msg = xs_dict_set(msg, "target", user->actor); + xs *actor_obj = NULL; + + if (valid_status(object_get(xs_dict_get(noti, "actor"), &actor_obj)) && actor_obj) + msg = xs_dict_set(msg, "account", actor_obj); + + xs *qmsg = _new_qmsg("notify_webhook", msg, retries); const char *ntid = xs_dict_get(qmsg, "ntid"); xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid); -- cgit v1.2.3 From f055c8b694a398868d14fd70df61d02429846dae Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 30 May 2025 19:34:11 +0200 Subject: Added a new server knob disable_notify_webhook. --- data.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index 10084f9..74bc112 100644 --- a/data.c +++ b/data.c @@ -3167,7 +3167,8 @@ void notify_add(snac *snac, const char *type, const char *utype, pthread_mutex_unlock(&data_mutex); } - enqueue_notify_webhook(snac, noti, 0); + if (!xs_is_true(xs_dict_get(srv_config, "disable_notify_webhook"))) + enqueue_notify_webhook(snac, noti, 0); } @@ -3528,7 +3529,7 @@ void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries) { const char *webhook = xs_dict_get(user->config, "notify_webhook"); - if (xs_is_string(webhook)) { + if (xs_is_string(webhook) && *webhook) { xs *msg = xs_dup(noti); /* add more data */ -- cgit v1.2.3 From 706816b4321337d56ff3121186567363b882d01d Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 30 May 2025 19:43:55 +0200 Subject: Added uid, basedir and baseurl to the notify webhook message. --- data.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index 74bc112..28f7cd9 100644 --- a/data.c +++ b/data.c @@ -3534,6 +3534,10 @@ void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries) /* add more data */ msg = xs_dict_set(msg, "target", user->actor); + msg = xs_dict_set(msg, "uid", user->uid); + msg = xs_dict_set(msg, "basedir", srv_basedir); + msg = xs_dict_set(msg, "baseurl", srv_baseurl); + xs *actor_obj = NULL; if (valid_status(object_get(xs_dict_get(noti, "actor"), &actor_obj)) && actor_obj) -- cgit v1.2.3 From c8848f6e9f8e9fd9d17290b1ef301d3bf7beccb4 Mon Sep 17 00:00:00 2001 From: grunfink Date: Fri, 30 May 2025 19:59:40 +0200 Subject: More webhook checks. --- data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index 28f7cd9..6c38631 100644 --- a/data.c +++ b/data.c @@ -3529,7 +3529,7 @@ void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries) { const char *webhook = xs_dict_get(user->config, "notify_webhook"); - if (xs_is_string(webhook) && *webhook) { + if (xs_is_string(webhook) && xs_match(webhook, "https://*|http://*")) { /** **/ xs *msg = xs_dup(noti); /* add more data */ -- cgit v1.2.3 From d87d294b7ddd93b16d0c89c324612aef5c6d648e Mon Sep 17 00:00:00 2001 From: grunfink Date: Mon, 16 Jun 2025 18:16:45 +0200 Subject: In enqueue_notify_webhook(), also add the inReplyTo object if there is one. --- data.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'data.c') diff --git a/data.c b/data.c index 6c38631..32b47d8 100644 --- a/data.c +++ b/data.c @@ -3543,6 +3543,16 @@ void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries) if (valid_status(object_get(xs_dict_get(noti, "actor"), &actor_obj)) && actor_obj) msg = xs_dict_set(msg, "account", actor_obj); + /* if this post is a reply, also add the inReplyTo object */ + const char *in_reply_to = xs_dict_get_path(msg, "msg.object.inReplyTo"); + + if (xs_is_string(in_reply_to)) { + xs *irt_obj = NULL; + + if (valid_status(object_get(in_reply_to, &irt_obj))) + msg = xs_dict_set(msg, "inReplyTo", irt_obj); + } + xs *qmsg = _new_qmsg("notify_webhook", msg, retries); const char *ntid = xs_dict_get(qmsg, "ntid"); xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid); -- cgit v1.2.3 From f580014c5031f78489257cbf152d38098a6f38ff Mon Sep 17 00:00:00 2001 From: grunfink Date: Mon, 16 Jun 2025 18:24:47 +0200 Subject: Renamed webhook 'inReplyTo' to 'reply'. --- data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index 32b47d8..e1cab52 100644 --- a/data.c +++ b/data.c @@ -3550,7 +3550,7 @@ void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries) xs *irt_obj = NULL; if (valid_status(object_get(in_reply_to, &irt_obj))) - msg = xs_dict_set(msg, "inReplyTo", irt_obj); + msg = xs_dict_set(msg, "reply", irt_obj); } xs *qmsg = _new_qmsg("notify_webhook", msg, retries); -- cgit v1.2.3 From 9b134e9076569b31eb5ec77ebda60eb9001485a8 Mon Sep 17 00:00:00 2001 From: grunfink Date: Wed, 18 Jun 2025 09:00:09 +0200 Subject: Added 'alias' and 'alias_raw' as forced update in user_persist(). --- data.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'data.c') diff --git a/data.c b/data.c index e1cab52..f26da49 100644 --- a/data.c +++ b/data.c @@ -333,6 +333,7 @@ int user_open_by_md5(snac *snac, const char *md5) return 0; } + int user_persist(snac *snac, int publish) /* store user */ { @@ -348,7 +349,7 @@ int user_persist(snac *snac, int publish) if (old != NULL) { int nw = 0; - const char *fields[] = { "header", "avatar", "name", "bio", + const char *fields[] = { "header", "avatar", "name", "bio", "alias", "alias_raw", "metadata", "latitude", "longitude", NULL }; for (int n = 0; fields[n]; n++) { -- cgit v1.2.3