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. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 80df2d0..9cfbb0d 100644 --- a/main.c +++ b/main.c @@ -695,7 +695,7 @@ int main(int argc, char *argv[]) xs_json_dump(data, 4, stdout); enqueue_actor_refresh(&snac, xs_dict_get(data, "attributedTo"), 0); - if (!timeline_here(&snac, url)) + if (!timeline_here_by_md5(&snac, url)) timeline_add(&snac, url, data); else printf("Post %s already here\n", url); -- 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(). --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 9cfbb0d..80df2d0 100644 --- a/main.c +++ b/main.c @@ -695,7 +695,7 @@ int main(int argc, char *argv[]) xs_json_dump(data, 4, stdout); enqueue_actor_refresh(&snac, xs_dict_get(data, "attributedTo"), 0); - if (!timeline_here_by_md5(&snac, url)) + if (!timeline_here(&snac, url)) timeline_add(&snac, url, data); else printf("Post %s already here\n", url); -- cgit v1.2.3 From 5ec55544e4d83503776f517d62262ae176ca15c6 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 29 May 2025 22:52:20 +0200 Subject: New command-line option 'poll_hashtag_rss'. --- main.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 80df2d0..c948b57 100644 --- a/main.c +++ b/main.c @@ -143,6 +143,11 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(cmd, "poll_hashtag_rss") == 0) { /** **/ + rss_poll_hashtags(); + return 0; + } + if (strcmp(cmd, "state") == 0) { /** **/ xs *shm_name = NULL; srv_state *p_state = srv_state_op(&shm_name, 1); -- cgit v1.2.3 From 1ca5b346a556f2418c110b480ce1859ce7d5b36c Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 12 Jun 2025 12:11:34 +0200 Subject: The usage "screen" shows info only about the entered command. If there is no command or no command starts with that string, the full list is shown as before. --- main.c | 128 ++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 76 insertions(+), 52 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index c948b57..2995e3f 100644 --- a/main.c +++ b/main.c @@ -13,58 +13,82 @@ #include #include -int usage(void) +int usage(const char *cmd) { printf("snac " VERSION " - A simple, minimalistic ActivityPub instance\n"); printf("Copyright (c) 2022 - 2025 grunfink et al. / MIT license\n"); printf("\n"); - printf("Commands:\n"); - printf("\n"); - printf("init [{basedir}] Initializes the data storage\n"); - printf("upgrade {basedir} Upgrade to a new version\n"); - printf("adduser {basedir} [{uid}] Adds a new user\n"); - printf("deluser {basedir} {uid} Deletes a user\n"); - printf("httpd {basedir} Starts the HTTPD daemon\n"); - printf("purge {basedir} Purges old data\n"); - printf("state {basedir} Prints server state\n"); - printf("webfinger {basedir} {account} Queries about an account (@user@host or actor url)\n"); - printf("queue {basedir} {uid} Processes a user queue\n"); - printf("follow {basedir} {uid} {actor} Follows an actor\n"); - printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); - printf("request {basedir} {uid} {url} Requests an object\n"); - printf("insert {basedir} {uid} {url} Requests an object and inserts it into the timeline\n"); - printf("actor {basedir} [{uid}] {url} Requests an actor\n"); - printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n"); - printf("note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n"); - printf("note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n"); - printf("boost|announce {basedir} {uid} {url} Boosts (announces) a post\n"); - printf("unboost {basedir} {uid} {url} Unboosts a post\n"); - printf("resetpwd {basedir} {uid} Resets the password of a user\n"); - printf("ping {basedir} {uid} {actor} Pings an actor\n"); - printf("webfinger_s {basedir} {uid} {account} Queries about an account (@user@host or actor url)\n"); - printf("pin {basedir} {uid} {msg_url} Pins a message\n"); - printf("unpin {basedir} {uid} {msg_url} Unpins a message\n"); - printf("bookmark {basedir} {uid} {msg_url} Bookmarks a message\n"); - printf("unbookmark {basedir} {uid} {msg_url} Unbookmarks a message\n"); - printf("block {basedir} {instance_url} Blocks a full instance\n"); - printf("unblock {basedir} {instance_url} Unblocks a full instance\n"); - printf("limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n"); - printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n"); - printf("unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n"); - printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); - printf("search {basedir} {uid} {regex} Searches posts by content\n"); - printf("export_csv {basedir} {uid} Exports data as CSV files\n"); - printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n"); - printf("migrate {basedir} {uid} Migrates to the account defined as the alias\n"); - printf("import_csv {basedir} {uid} Imports data from CSV files\n"); - printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n"); - printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n"); - printf("lists {basedir} {uid} Returns the names of the lists created by the user\n"); - printf("list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n"); - printf("create_list {basedir} {uid} {name} Creates a new list\n"); - printf("delete_list {basedir} {uid} {name} Deletes an existing list\n"); - printf("list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n"); - printf("list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n"); + + if (cmd == NULL) { + printf("Commands:\n"); + printf("\n"); + } + + const char *cmds = + "init [{basedir}] Initializes the data storage\n" + "upgrade {basedir} Upgrade to a new version\n" + "adduser {basedir} [{uid}] Adds a new user\n" + "deluser {basedir} {uid} Deletes a user\n" + "httpd {basedir} Starts the HTTPD daemon\n" + "purge {basedir} Purges old data\n" + "state {basedir} Prints server state\n" + "webfinger {basedir} {account} Queries about an account (@user@host or actor url)\n" + "queue {basedir} {uid} Processes a user queue\n" + "follow {basedir} {uid} {actor} Follows an actor\n" + "unfollow {basedir} {uid} {actor} Unfollows an actor\n" + "request {basedir} {uid} {url} Requests an object\n" + "insert {basedir} {uid} {url} Requests an object and inserts it into the timeline\n" + "actor {basedir} [{uid}] {url} Requests an actor\n" + "note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n" + "note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n" + "note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n" + "boost|announce {basedir} {uid} {url} Boosts (announces) a post\n" + "unboost {basedir} {uid} {url} Unboosts a post\n" + "resetpwd {basedir} {uid} Resets the password of a user\n" + "ping {basedir} {uid} {actor} Pings an actor\n" + "webfinger_s {basedir} {uid} {account} Queries about an account (@user@host or actor url)\n" + "pin {basedir} {uid} {msg_url} Pins a message\n" + "unpin {basedir} {uid} {msg_url} Unpins a message\n" + "bookmark {basedir} {uid} {msg_url} Bookmarks a message\n" + "unbookmark {basedir} {uid} {msg_url} Unbookmarks a message\n" + "block {basedir} {instance_url} Blocks a full instance\n" + "unblock {basedir} {instance_url} Unblocks a full instance\n" + "limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n" + "unlimit {basedir} {uid} {actor} Unlimits an actor\n" + "unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n" + "verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n" + "search {basedir} {uid} {regex} Searches posts by content\n" + "export_csv {basedir} {uid} Exports data as CSV files\n" + "alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n" + "migrate {basedir} {uid} Migrates to the account defined as the alias\n" + "import_csv {basedir} {uid} Imports data from CSV files\n" + "import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n" + "import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n" + "lists {basedir} {uid} Returns the names of the lists created by the user\n" + "list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n" + "create_list {basedir} {uid} {name} Creates a new list\n" + "delete_list {basedir} {uid} {name} Deletes an existing list\n" + "list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n" + "list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n"; + + if (cmd == NULL) + printf("%s", cmds); + else { + /* only show help for the entered command */ + xs *l = xs_split(cmds, "\n"); + const char *v; + int cnt = 0; + + xs_list_foreach(l, v) { + if (xs_startswith(v, cmd)) { + printf("%s\n", v); + cnt++; + } + } + + if (cnt == 0) + printf("%s", cmds); + } return 1; } @@ -94,7 +118,7 @@ int main(int argc, char *argv[]) umask(0007); if ((cmd = GET_ARGV()) == NULL) - return usage(); + return usage(cmd); if (strcmp(cmd, "init") == 0) { /** **/ /* initialize the data storage */ @@ -106,7 +130,7 @@ int main(int argc, char *argv[]) if ((basedir = getenv("SNAC_BASEDIR")) == NULL) { if ((basedir = GET_ARGV()) == NULL) - return usage(); + return usage(cmd); } if (strcmp(cmd, "upgrade") == 0) { /** **/ @@ -172,7 +196,7 @@ int main(int argc, char *argv[]) } if ((user = GET_ARGV()) == NULL) - return usage(); + return usage(cmd); if (strcmp(cmd, "block") == 0) { /** **/ int ret = instance_block(user); @@ -305,7 +329,7 @@ int main(int argc, char *argv[]) } if ((url = GET_ARGV()) == NULL) - return usage(); + return usage(cmd); if (strcmp(cmd, "list_members") == 0) { /** **/ xs *lid = list_maint(&snac, url, 4); -- cgit v1.2.3 From 7eecd4bb95116caef35d98f97e6e56f5dc910bd5 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 12 Jun 2025 12:14:18 +0200 Subject: Improved usage screen. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 2995e3f..85576b6 100644 --- a/main.c +++ b/main.c @@ -80,7 +80,7 @@ int usage(const char *cmd) int cnt = 0; xs_list_foreach(l, v) { - if (xs_startswith(v, cmd)) { + if (xs_str_in(v, cmd) != -1) { printf("%s\n", v); cnt++; } -- cgit v1.2.3 From e1fb414ffd4c46f51903f48ade7b399c0f5de9bb Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 15 Jun 2025 09:43:42 +0200 Subject: Renamed some list command line options. create_list to list_create delete_list to list_delete. --- main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 85576b6..758e692 100644 --- a/main.c +++ b/main.c @@ -66,8 +66,8 @@ int usage(const char *cmd) "import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n" "lists {basedir} {uid} Returns the names of the lists created by the user\n" "list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n" - "create_list {basedir} {uid} {name} Creates a new list\n" - "delete_list {basedir} {uid} {name} Deletes an existing list\n" + "list_create {basedir} {uid} {name} Creates a new list\n" + "list_delete {basedir} {uid} {name} Deletes an existing list\n" "list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n" "list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n"; @@ -352,7 +352,7 @@ int main(int argc, char *argv[]) return 0; } - if (strcmp(cmd, "create_list") == 0) { /** **/ + if (strcmp(cmd, "list_create") == 0) { /** **/ xs *lid = list_maint(&snac, url, 4); if (lid == NULL) { @@ -365,7 +365,7 @@ int main(int argc, char *argv[]) return 0; } - if (strcmp(cmd, "delete_list") == 0) { /** **/ + if (strcmp(cmd, "list_delete") == 0) { /** **/ xs *lid = list_maint(&snac, url, 4); if (lid != NULL) { -- cgit v1.2.3 From deb90ed0ac6dd5ccea4516b3988e16d95f9687b2 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 15 Jun 2025 09:44:56 +0200 Subject: Renamed cmd list_delete to list_remove. --- main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 758e692..5af3695 100644 --- a/main.c +++ b/main.c @@ -67,7 +67,7 @@ int usage(const char *cmd) "lists {basedir} {uid} Returns the names of the lists created by the user\n" "list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n" "list_create {basedir} {uid} {name} Creates a new list\n" - "list_delete {basedir} {uid} {name} Deletes an existing list\n" + "list_remove {basedir} {uid} {name} Removes an existing list\n" "list_add {basedir} {uid} {name} {acct} Adds an account (@user@host or actor url) to a list\n" "list_del {basedir} {uid} {name} {actor} Deletes an actor URL from a list\n"; @@ -365,7 +365,7 @@ int main(int argc, char *argv[]) return 0; } - if (strcmp(cmd, "list_delete") == 0) { /** **/ + if (strcmp(cmd, "list_remove") == 0) { /** **/ xs *lid = list_maint(&snac, url, 4); if (lid != NULL) { -- cgit v1.2.3 From 8c9eb18099370f34a577859d7fddea1d5f412612 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 19 Jun 2025 18:41:59 +0200 Subject: Minor tweak to usage screen. --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 5af3695..ddb02a8 100644 --- a/main.c +++ b/main.c @@ -58,7 +58,7 @@ int usage(const char *cmd) "unmute {basedir} {uid} {actor} Unmutes a previously muted actor\n" "verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n" "search {basedir} {uid} {regex} Searches posts by content\n" - "export_csv {basedir} {uid} Exports data as CSV files\n" + "export_csv {basedir} {uid} Exports followers, lists, MUTEd and bookmarks to CSV\n" "alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n" "migrate {basedir} {uid} Migrates to the account defined as the alias\n" "import_csv {basedir} {uid} Imports data from CSV files\n" -- cgit v1.2.3 From a07458f408c304ae9d037c95bee77dbf4522f3f0 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 19 Jun 2025 19:19:08 +0200 Subject: New command-line option export_posts. --- main.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index ddb02a8..f271abc 100644 --- a/main.c +++ b/main.c @@ -59,6 +59,7 @@ int usage(const char *cmd) "verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n" "search {basedir} {uid} {regex} Searches posts by content\n" "export_csv {basedir} {uid} Exports followers, lists, MUTEd and bookmarks to CSV\n" + "export_posts {basedir} {iod} Exports all posts to outbox.json\n" "alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n" "migrate {basedir} {uid} Migrates to the account defined as the alias\n" "import_csv {basedir} {uid} Imports data from CSV files\n" @@ -308,6 +309,11 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(cmd, "export_posts") == 0) { /** **/ + export_posts(&snac); + return 0; + } + if (strcmp(cmd, "import_csv") == 0) { /** **/ import_csv(&snac); return 0; -- cgit v1.2.3 From c976b9a334872e14aadc1f454680599468652231 Mon Sep 17 00:00:00 2001 From: grunfink Date: Thu, 26 Jun 2025 10:39:47 +0200 Subject: Sending notes from the cmdline allows setting an inReplyTo field. --- main.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index f271abc..ce4e7ce 100644 --- a/main.c +++ b/main.c @@ -7,6 +7,7 @@ #include "xs_time.h" #include "xs_openssl.h" #include "xs_match.h" +#include "xs_random.h" #include "snac.h" @@ -779,12 +780,24 @@ int main(int argc, char *argv[]) xs *msg = NULL; xs *c_msg = NULL; xs *attl = xs_list_new(); - char *fn = NULL; + const char *fn = NULL; + const char *in_reply_to = NULL; + const char **next = NULL; /* iterate possible attachments */ while ((fn = GET_ARGV())) { FILE *f; + if (next) { + *next = fn; + next = NULL; + } + else + if (strcmp(fn, "-r") == 0) { + /* next argument is an inReplyTo */ + next = &in_reply_to; + } + else if ((f = fopen(fn, "rb")) != NULL) { /* get the file size and content */ fseek(f, 0, SEEK_END); @@ -794,8 +807,10 @@ int main(int argc, char *argv[]) fclose(f); char *ext = strrchr(fn, '.'); - xs *hash = xs_md5_hex(fn, strlen(fn)); - xs *id = xs_fmt("%s%s", hash, ext); + char rnd[32]; + xs_rnd_buf(rnd, sizeof(rnd)); + xs *hash = xs_md5_hex(rnd, sizeof(rnd)); + xs *id = xs_fmt("post-%s%s", hash, ext ? ext : ""); xs *url = xs_fmt("%s/s/%s", snac.actor, id); /* store */ @@ -856,7 +871,7 @@ int main(int argc, char *argv[]) if (strcmp(cmd, "note_unlisted") == 0) scope = 2; - msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"), NULL); + msg = msg_note(&snac, content, NULL, in_reply_to, attl, scope, getenv("LANG"), NULL); c_msg = msg_create(&snac, msg); -- cgit v1.2.3