summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c74
1 files changed, 46 insertions, 28 deletions
diff --git a/main.c b/main.c
index 7d23c84..a57adb5 100644
--- a/main.c
+++ b/main.c
@@ -1,11 +1,12 @@
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 - 2025 grunfink et al. / MIT license */
3 3
4#include "xs.h" 4#include "xs.h"
5#include "xs_io.h" 5#include "xs_io.h"
6#include "xs_json.h" 6#include "xs_json.h"
7#include "xs_time.h" 7#include "xs_time.h"
8#include "xs_openssl.h" 8#include "xs_openssl.h"
9#include "xs_match.h"
9 10
10#include "snac.h" 11#include "snac.h"
11 12
@@ -14,7 +15,7 @@
14int usage(void) 15int usage(void)
15{ 16{
16 printf("snac " VERSION " - A simple, minimalistic ActivityPub instance\n"); 17 printf("snac " VERSION " - A simple, minimalistic ActivityPub instance\n");
17 printf("Copyright (c) 2022 - 2024 grunfink et al. / MIT license\n"); 18 printf("Copyright (c) 2022 - 2025 grunfink et al. / MIT license\n");
18 printf("\n"); 19 printf("\n");
19 printf("Commands:\n"); 20 printf("Commands:\n");
20 printf("\n"); 21 printf("\n");
@@ -34,6 +35,7 @@ int usage(void)
34 printf("actor {basedir} [{uid}] {url} Requests an actor\n"); 35 printf("actor {basedir} [{uid}] {url} Requests an actor\n");
35 printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n"); 36 printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n");
36 printf("note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n"); 37 printf("note_unlisted {basedir} {uid} {text} [files...] Sends an unlisted note with optional attachments\n");
38 printf("note_mention {basedir} {uid} {text} [files...] Sends a note only to mentioned accounts\n");
37 printf("boost|announce {basedir} {uid} {url} Boosts (announces) a post\n"); 39 printf("boost|announce {basedir} {uid} {url} Boosts (announces) a post\n");
38 printf("unboost {basedir} {uid} {url} Unboosts a post\n"); 40 printf("unboost {basedir} {uid} {url} Unboosts a post\n");
39 printf("resetpwd {basedir} {uid} Resets the password of a user\n"); 41 printf("resetpwd {basedir} {uid} Resets the password of a user\n");
@@ -49,10 +51,10 @@ int usage(void)
49 printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n"); 51 printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n");
50 printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); 52 printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n");
51 printf("search {basedir} {uid} {regex} Searches posts by content\n"); 53 printf("search {basedir} {uid} {regex} Searches posts by content\n");
52 printf("export_csv {basedir} {uid} Exports data as CSV files into current directory\n"); 54 printf("export_csv {basedir} {uid} Exports data as CSV files\n");
53 printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n"); 55 printf("alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n");
54 printf("migrate {basedir} {uid} Migrates to the account defined as the alias\n"); 56 printf("migrate {basedir} {uid} Migrates to the account defined as the alias\n");
55 printf("import_csv {basedir} {uid} Imports data from CSV files in the current directory\n"); 57 printf("import_csv {basedir} {uid} Imports data from CSV files\n");
56 printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n"); 58 printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n");
57 printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n"); 59 printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n");
58 60
@@ -94,19 +96,6 @@ int main(int argc, char *argv[])
94 return snac_init(basedir); 96 return snac_init(basedir);
95 } 97 }
96 98
97 if (strcmp(cmd, "upgrade") == 0) { /** **/
98 int ret;
99
100 /* upgrade */
101 if ((basedir = GET_ARGV()) == NULL)
102 return usage();
103
104 if ((ret = srv_open(basedir, 1)) == 1)
105 srv_log(xs_dup("OK"));
106
107 return ret;
108 }
109
110 if (strcmp(cmd, "markdown") == 0) { /** **/ 99 if (strcmp(cmd, "markdown") == 0) { /** **/
111 /* undocumented, for testing only */ 100 /* undocumented, for testing only */
112 xs *c = xs_readall(stdin); 101 xs *c = xs_readall(stdin);
@@ -116,8 +105,20 @@ int main(int argc, char *argv[])
116 return 0; 105 return 0;
117 } 106 }
118 107
119 if ((basedir = GET_ARGV()) == NULL) 108 if ((basedir = getenv("SNAC_BASEDIR")) == NULL) {
120 return usage(); 109 if ((basedir = GET_ARGV()) == NULL)
110 return usage();
111 }
112
113 if (strcmp(cmd, "upgrade") == 0) { /** **/
114 int ret;
115
116 /* upgrade */
117 if ((ret = srv_open(basedir, 1)) == 1)
118 srv_log(xs_dup("OK"));
119
120 return ret;
121 }
121 122
122 if (!srv_open(basedir, 0)) { 123 if (!srv_open(basedir, 0)) {
123 srv_log(xs_fmt("error opening data storage at %s", basedir)); 124 srv_log(xs_fmt("error opening data storage at %s", basedir));
@@ -351,6 +352,22 @@ int main(int argc, char *argv[])
351 return 0; 352 return 0;
352 } 353 }
353 354
355
356 if (strcmp(cmd, "assist") == 0) { /** **/
357 /* undocumented: experimental (do not use) */
358 xs *msg = msg_admiration(&snac, url, "Accept");
359
360 if (msg != NULL) {
361 enqueue_message(&snac, msg);
362
363 if (dbglevel) {
364 xs_json_dump(msg, 4, stdout);
365 }
366 }
367
368 return 0;
369 }
370
354 if (strcmp(cmd, "unboost") == 0) { /** **/ 371 if (strcmp(cmd, "unboost") == 0) { /** **/
355 xs *msg = msg_repulsion(&snac, url, "Announce"); 372 xs *msg = msg_repulsion(&snac, url, "Announce");
356 373
@@ -604,7 +621,9 @@ int main(int argc, char *argv[])
604 return 0; 621 return 0;
605 } 622 }
606 623
607 if (strcmp(cmd, "note") == 0 || strcmp(cmd, "note_unlisted") == 0) { /** **/ 624 if (strcmp(cmd, "note") == 0 || /** **/
625 strcmp(cmd, "note_unlisted") == 0 || /** **/
626 strcmp(cmd, "note_mention") == 0) { /** **/
608 xs *content = NULL; 627 xs *content = NULL;
609 xs *msg = NULL; 628 xs *msg = NULL;
610 xs *c_msg = NULL; 629 xs *c_msg = NULL;
@@ -668,15 +687,14 @@ int main(int argc, char *argv[])
668 else 687 else
669 content = xs_dup(url); 688 content = xs_dup(url);
670 689
671 msg = msg_note(&snac, content, NULL, NULL, attl, 0, getenv("LANG")); 690 int scope = 0;
691 if (strcmp(cmd, "note_mention") == 0)
692 scope = 1;
693 else
694 if (strcmp(cmd, "note_unlisted") == 0)
695 scope = 2;
672 696
673 if (strcmp(cmd, "note_unlisted") == 0) { 697 msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"));
674 /* according to Mastodon, "unlisted" posts (now called "quiet public")
675 has the public address as a cc instead of to, so toggle it */
676 xs *to = xs_dup(xs_dict_get(msg, "to"));
677 msg = xs_dict_set(msg, "cc", to);
678 msg = xs_dict_set(msg, "to", xs_stock(XSTYPE_LIST));
679 }
680 698
681 c_msg = msg_create(&snac, msg); 699 c_msg = msg_create(&snac, msg);
682 700