diff options
| author | 2023-05-24 11:49:16 +0200 | |
|---|---|---|
| committer | 2023-05-24 11:49:16 +0200 | |
| commit | 0d8a040d9086cd7a9e13a7b070e425df9201f7e5 (patch) | |
| tree | c9832687eaaa9a0dfd954a9bbc835557e14dc579 /main.c | |
| parent | New function msg_question() (unused). (diff) | |
| download | penes-snac2-0d8a040d9086cd7a9e13a7b070e425df9201f7e5.tar.gz penes-snac2-0d8a040d9086cd7a9e13a7b070e425df9201f7e5.tar.xz penes-snac2-0d8a040d9086cd7a9e13a7b070e425df9201f7e5.zip | |
Added some experimental 'Question' posting code.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 53 |
1 files changed, 36 insertions, 17 deletions
| @@ -30,6 +30,7 @@ int usage(void) | |||
| 30 | printf("note {basedir} {uid} {'text'} Sends a note to followers\n"); | 30 | printf("note {basedir} {uid} {'text'} Sends a note to followers\n"); |
| 31 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); | 31 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); |
| 32 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); | 32 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); |
| 33 | /* printf("question {basedir} {uid} 'opts' Generates a poll (;-separated opts)\n");*/ | ||
| 33 | 34 | ||
| 34 | return 1; | 35 | return 1; |
| 35 | } | 36 | } |
| @@ -63,7 +64,7 @@ int main(int argc, char *argv[]) | |||
| 63 | if ((cmd = GET_ARGV()) == NULL) | 64 | if ((cmd = GET_ARGV()) == NULL) |
| 64 | return usage(); | 65 | return usage(); |
| 65 | 66 | ||
| 66 | if (strcmp(cmd, "init") == 0) { | 67 | if (strcmp(cmd, "init") == 0) { /** **/ |
| 67 | /* initialize the data storage */ | 68 | /* initialize the data storage */ |
| 68 | /* ... */ | 69 | /* ... */ |
| 69 | basedir = GET_ARGV(); | 70 | basedir = GET_ARGV(); |
| @@ -71,7 +72,7 @@ int main(int argc, char *argv[]) | |||
| 71 | return snac_init(basedir); | 72 | return snac_init(basedir); |
| 72 | } | 73 | } |
| 73 | 74 | ||
| 74 | if (strcmp(cmd, "upgrade") == 0) { | 75 | if (strcmp(cmd, "upgrade") == 0) { /** **/ |
| 75 | int ret; | 76 | int ret; |
| 76 | 77 | ||
| 77 | /* upgrade */ | 78 | /* upgrade */ |
| @@ -84,7 +85,7 @@ int main(int argc, char *argv[]) | |||
| 84 | return ret; | 85 | return ret; |
| 85 | } | 86 | } |
| 86 | 87 | ||
| 87 | if (strcmp(cmd, "markdown") == 0) { | 88 | if (strcmp(cmd, "markdown") == 0) { /** **/ |
| 88 | /* undocumented, for testing only */ | 89 | /* undocumented, for testing only */ |
| 89 | xs *c = xs_readall(stdin); | 90 | xs *c = xs_readall(stdin); |
| 90 | xs *fc = not_really_markdown(c, NULL); | 91 | xs *fc = not_really_markdown(c, NULL); |
| @@ -101,7 +102,7 @@ int main(int argc, char *argv[]) | |||
| 101 | return 1; | 102 | return 1; |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | if (strcmp(cmd, "adduser") == 0) { | 105 | if (strcmp(cmd, "adduser") == 0) { /** **/ |
| 105 | user = GET_ARGV(); | 106 | user = GET_ARGV(); |
| 106 | 107 | ||
| 107 | return adduser(user); | 108 | return adduser(user); |
| @@ -109,13 +110,13 @@ int main(int argc, char *argv[]) | |||
| 109 | return 0; | 110 | return 0; |
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | if (strcmp(cmd, "httpd") == 0) { | 113 | if (strcmp(cmd, "httpd") == 0) { /** **/ |
| 113 | httpd(); | 114 | httpd(); |
| 114 | srv_free(); | 115 | srv_free(); |
| 115 | return 0; | 116 | return 0; |
| 116 | } | 117 | } |
| 117 | 118 | ||
| 118 | if (strcmp(cmd, "purge") == 0) { | 119 | if (strcmp(cmd, "purge") == 0) { /** **/ |
| 119 | purge_all(); | 120 | purge_all(); |
| 120 | return 0; | 121 | return 0; |
| 121 | } | 122 | } |
| @@ -123,7 +124,7 @@ int main(int argc, char *argv[]) | |||
| 123 | if ((user = GET_ARGV()) == NULL) | 124 | if ((user = GET_ARGV()) == NULL) |
| 124 | return usage(); | 125 | return usage(); |
| 125 | 126 | ||
| 126 | if (strcmp(cmd, "webfinger") == 0) { | 127 | if (strcmp(cmd, "webfinger") == 0) { /** **/ |
| 127 | xs *actor = NULL; | 128 | xs *actor = NULL; |
| 128 | xs *uid = NULL; | 129 | xs *uid = NULL; |
| 129 | int status; | 130 | int status; |
| @@ -146,16 +147,16 @@ int main(int argc, char *argv[]) | |||
| 146 | 147 | ||
| 147 | lastlog_write(&snac, "cmdline"); | 148 | lastlog_write(&snac, "cmdline"); |
| 148 | 149 | ||
| 149 | if (strcmp(cmd, "resetpwd") == 0) { | 150 | if (strcmp(cmd, "resetpwd") == 0) { /** **/ |
| 150 | return resetpwd(&snac); | 151 | return resetpwd(&snac); |
| 151 | } | 152 | } |
| 152 | 153 | ||
| 153 | if (strcmp(cmd, "queue") == 0) { | 154 | if (strcmp(cmd, "queue") == 0) { /** **/ |
| 154 | process_user_queue(&snac); | 155 | process_user_queue(&snac); |
| 155 | return 0; | 156 | return 0; |
| 156 | } | 157 | } |
| 157 | 158 | ||
| 158 | if (strcmp(cmd, "timeline") == 0) { | 159 | if (strcmp(cmd, "timeline") == 0) { /** **/ |
| 159 | #if 0 | 160 | #if 0 |
| 160 | xs *list = local_list(&snac, XS_ALL); | 161 | xs *list = local_list(&snac, XS_ALL); |
| 161 | xs *body = html_timeline(&snac, list, 1); | 162 | xs *body = html_timeline(&snac, list, 1); |
| @@ -178,7 +179,7 @@ int main(int argc, char *argv[]) | |||
| 178 | if ((url = GET_ARGV()) == NULL) | 179 | if ((url = GET_ARGV()) == NULL) |
| 179 | return usage(); | 180 | return usage(); |
| 180 | 181 | ||
| 181 | if (strcmp(cmd, "announce") == 0) { | 182 | if (strcmp(cmd, "announce") == 0) { /** **/ |
| 182 | xs *msg = msg_admiration(&snac, url, "Announce"); | 183 | xs *msg = msg_admiration(&snac, url, "Announce"); |
| 183 | 184 | ||
| 184 | if (msg != NULL) { | 185 | if (msg != NULL) { |
| @@ -193,7 +194,7 @@ int main(int argc, char *argv[]) | |||
| 193 | return 0; | 194 | return 0; |
| 194 | } | 195 | } |
| 195 | 196 | ||
| 196 | if (strcmp(cmd, "follow") == 0) { | 197 | if (strcmp(cmd, "follow") == 0) { /** **/ |
| 197 | xs *msg = msg_follow(&snac, url); | 198 | xs *msg = msg_follow(&snac, url); |
| 198 | 199 | ||
| 199 | if (msg != NULL) { | 200 | if (msg != NULL) { |
| @@ -212,7 +213,7 @@ int main(int argc, char *argv[]) | |||
| 212 | return 0; | 213 | return 0; |
| 213 | } | 214 | } |
| 214 | 215 | ||
| 215 | if (strcmp(cmd, "unfollow") == 0) { | 216 | if (strcmp(cmd, "unfollow") == 0) { /** **/ |
| 216 | xs *object = NULL; | 217 | xs *object = NULL; |
| 217 | 218 | ||
| 218 | if (valid_status(following_get(&snac, url, &object))) { | 219 | if (valid_status(following_get(&snac, url, &object))) { |
| @@ -230,7 +231,7 @@ int main(int argc, char *argv[]) | |||
| 230 | return 0; | 231 | return 0; |
| 231 | } | 232 | } |
| 232 | 233 | ||
| 233 | if (strcmp(cmd, "ping") == 0) { | 234 | if (strcmp(cmd, "ping") == 0) { /** **/ |
| 234 | xs *actor_o = NULL; | 235 | xs *actor_o = NULL; |
| 235 | 236 | ||
| 236 | if (valid_status(actor_request(&snac, url, &actor_o))) { | 237 | if (valid_status(actor_request(&snac, url, &actor_o))) { |
| @@ -251,7 +252,25 @@ int main(int argc, char *argv[]) | |||
| 251 | return 0; | 252 | return 0; |
| 252 | } | 253 | } |
| 253 | 254 | ||
| 254 | if (strcmp(cmd, "request") == 0) { | 255 | if (strcmp(cmd, "question") == 0) { /** **/ |
| 256 | xs *opts = xs_split(url, ";"); | ||
| 257 | |||
| 258 | xs *msg = msg_question(&snac, "Poll", opts, 0, 5 * 60); | ||
| 259 | xs *c_msg = msg_create(&snac, msg); | ||
| 260 | |||
| 261 | if (dbglevel) { | ||
| 262 | xs *j = xs_json_dumps_pp(c_msg, 4); | ||
| 263 | printf("%s\n", j); | ||
| 264 | } | ||
| 265 | |||
| 266 | enqueue_message(&snac, c_msg); | ||
| 267 | |||
| 268 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | ||
| 269 | |||
| 270 | return 0; | ||
| 271 | } | ||
| 272 | |||
| 273 | if (strcmp(cmd, "request") == 0) { /** **/ | ||
| 255 | int status; | 274 | int status; |
| 256 | xs *data = NULL; | 275 | xs *data = NULL; |
| 257 | 276 | ||
| @@ -267,7 +286,7 @@ int main(int argc, char *argv[]) | |||
| 267 | return 0; | 286 | return 0; |
| 268 | } | 287 | } |
| 269 | 288 | ||
| 270 | if (strcmp(cmd, "actor") == 0) { | 289 | if (strcmp(cmd, "actor") == 0) { /** **/ |
| 271 | int status; | 290 | int status; |
| 272 | xs *data = NULL; | 291 | xs *data = NULL; |
| 273 | 292 | ||
| @@ -283,7 +302,7 @@ int main(int argc, char *argv[]) | |||
| 283 | return 0; | 302 | return 0; |
| 284 | } | 303 | } |
| 285 | 304 | ||
| 286 | if (strcmp(cmd, "note") == 0) { | 305 | if (strcmp(cmd, "note") == 0) { /** **/ |
| 287 | xs *content = NULL; | 306 | xs *content = NULL; |
| 288 | xs *msg = NULL; | 307 | xs *msg = NULL; |
| 289 | xs *c_msg = NULL; | 308 | xs *c_msg = NULL; |