summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar default2022-09-25 09:07:43 +0200
committerGravatar default2022-09-25 09:07:43 +0200
commit4f328eec1f428d4e87adeb4c4eaf1e81afe26913 (patch)
treea3636038d0347efb593f1bf580fbe67d3ab0bed1 /main.c
parentProcess 'Create' messages (untested). (diff)
downloadpenes-snac2-4f328eec1f428d4e87adeb4c4eaf1e81afe26913.tar.gz
penes-snac2-4f328eec1f428d4e87adeb4c4eaf1e81afe26913.tar.xz
penes-snac2-4f328eec1f428d4e87adeb4c4eaf1e81afe26913.zip
Some fixes to timeline_add().
Diffstat (limited to 'main.c')
-rw-r--r--main.c68
1 files changed, 52 insertions, 16 deletions
diff --git a/main.c b/main.c
index 90fd5f9..d7d408f 100644
--- a/main.c
+++ b/main.c
@@ -9,11 +9,47 @@
9 9
10int usage(void) 10int usage(void)
11{ 11{
12 printf("usage:\n"); 12 printf("snac - A simple, minimalistic ActivityPub instance\n");
13 printf("Copyright (c) 2022 grunfink - MIT license\n");
14 printf("\n");
15 printf("Commands:\n");
16 printf("\n");
17 printf("init [{basedir}] Initializes the database\n");
18 printf("httpd {basedir} Starts the HTTPD daemon\n");
19 printf("webfinger {basedir} {user} Queries about a @user@host or actor\n");
20 printf("queue {basedir} {uid} Processes a user queue\n");
21// printf("check {basedir} [{uid}] Checks the database\n");
22// printf("purge {basedir} [{uid}] Purges old data\n");
23// printf("adduser {basedir} [{uid}] Adds a new user\n");
24
25// printf("update {basedir} {uid} Sends a user update to followers\n");
26// printf("passwd {basedir} {uid} Sets the password for {uid}\n");
27// printf("follow {basedir} {uid} {actor} Follows an actor\n");
28// printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n");
29// printf("mute {basedir} {uid} {actor} Mutes an actor\n");
30// printf("unmute {basedir} {uid} {actor} Unmutes an actor\n");
31// printf("like {basedir} {uid} {url} Likes an url\n");
32// printf("announce {basedir} {uid} {url} Announces (boosts) an url\n");
33// printf("note {basedir} {uid} {'text'} Sends a note to followers\n");
34
35 printf("request {basedir} {uid} {url} Requests an object\n");
36 printf("actor {basedir} {uid} {url} Requests an actor\n");
37
13 return 1; 38 return 1;
14} 39}
15 40
16 41
42char *get_argv(int *argi, int argc, char *argv[])
43{
44 if (*argi < argc)
45 return argv[(*argi)++];
46 else
47 return NULL;
48}
49
50
51#define GET_ARGV() get_argv(&argi, argc, argv)
52
17int main(int argc, char *argv[]) 53int main(int argc, char *argv[])
18{ 54{
19 char *cmd; 55 char *cmd;
@@ -23,21 +59,20 @@ int main(int argc, char *argv[])
23 int argi = 1; 59 int argi = 1;
24 snac snac; 60 snac snac;
25 61
26 argc--; 62 if ((cmd = GET_ARGV()) == NULL)
27 if (argc < argi)
28 return usage(); 63 return usage();
29 64
30 cmd = argv[argi++];
31
32 if (strcmp(cmd, "init") == 0) { 65 if (strcmp(cmd, "init") == 0) {
66 /* initialize the database */
67 /* ... */
68 basedir = GET_ARGV();
69
33 return 0; 70 return 0;
34 } 71 }
35 72
36 if (argc < argi) 73 if ((basedir = GET_ARGV()) == NULL)
37 return usage(); 74 return usage();
38 75
39 basedir = argv[argi++];
40
41 if (!srv_open(basedir)) { 76 if (!srv_open(basedir)) {
42 srv_log(xs_fmt("error opening database at %s", basedir)); 77 srv_log(xs_fmt("error opening database at %s", basedir));
43 return 1; 78 return 1;
@@ -48,11 +83,9 @@ int main(int argc, char *argv[])
48 return 0; 83 return 0;
49 } 84 }
50 85
51 if (argc < argi) 86 if ((user = GET_ARGV()) == NULL)
52 return usage(); 87 return usage();
53 88
54 user = argv[argi++];
55
56 if (strcmp(cmd, "webfinger") == 0) { 89 if (strcmp(cmd, "webfinger") == 0) {
57 xs *actor = NULL; 90 xs *actor = NULL;
58 xs *uid = NULL; 91 xs *uid = NULL;
@@ -69,16 +102,19 @@ int main(int argc, char *argv[])
69 return 0; 102 return 0;
70 } 103 }
71 104
72 if (argc < argi)
73 return usage();
74
75 url = argv[argi++];
76
77 if (!user_open(&snac, user)) { 105 if (!user_open(&snac, user)) {
78 printf("error in user '%s'\n", user); 106 printf("error in user '%s'\n", user);
79 return 1; 107 return 1;
80 } 108 }
81 109
110 if (strcmp(cmd, "queue") == 0) {
111 process_queue(&snac);
112 return 0;
113 }
114
115 if ((url = GET_ARGV()) == NULL)
116 return usage();
117
82 if (strcmp(cmd, "request") == 0) { 118 if (strcmp(cmd, "request") == 0) {
83 int status; 119 int status;
84 xs *data = NULL; 120 xs *data = NULL;