diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 115 |
1 files changed, 87 insertions, 28 deletions
| @@ -5,6 +5,7 @@ | |||
| 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 | 9 | ||
| 9 | #include "snac.h" | 10 | #include "snac.h" |
| 10 | 11 | ||
| @@ -17,30 +18,32 @@ int usage(void) | |||
| 17 | printf("\n"); | 18 | printf("\n"); |
| 18 | printf("Commands:\n"); | 19 | printf("Commands:\n"); |
| 19 | printf("\n"); | 20 | printf("\n"); |
| 20 | printf("init [{basedir}] Initializes the data storage\n"); | 21 | printf("init [{basedir}] Initializes the data storage\n"); |
| 21 | printf("upgrade {basedir} Upgrade to a new version\n"); | 22 | printf("upgrade {basedir} Upgrade to a new version\n"); |
| 22 | printf("adduser {basedir} [{uid}] Adds a new user\n"); | 23 | printf("adduser {basedir} [{uid}] Adds a new user\n"); |
| 23 | printf("deluser {basedir} {uid} Deletes a user\n"); | 24 | printf("deluser {basedir} {uid} Deletes a user\n"); |
| 24 | printf("httpd {basedir} Starts the HTTPD daemon\n"); | 25 | printf("httpd {basedir} Starts the HTTPD daemon\n"); |
| 25 | printf("purge {basedir} Purges old data\n"); | 26 | printf("purge {basedir} Purges old data\n"); |
| 26 | printf("state {basedir} Prints server state\n"); | 27 | printf("state {basedir} Prints server state\n"); |
| 27 | printf("webfinger {basedir} {actor} Queries about an actor (@user@host or actor url)\n"); | 28 | printf("webfinger {basedir} {actor} Queries about an actor (@user@host or actor url)\n"); |
| 28 | printf("queue {basedir} {uid} Processes a user queue\n"); | 29 | printf("queue {basedir} {uid} Processes a user queue\n"); |
| 29 | printf("follow {basedir} {uid} {actor} Follows an actor\n"); | 30 | printf("follow {basedir} {uid} {actor} Follows an actor\n"); |
| 30 | printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); | 31 | printf("unfollow {basedir} {uid} {actor} Unfollows an actor\n"); |
| 31 | printf("request {basedir} {uid} {url} Requests an object\n"); | 32 | printf("request {basedir} {uid} {url} Requests an object\n"); |
| 32 | printf("actor {basedir} [{uid}] {url} Requests an actor\n"); | 33 | printf("actor {basedir} [{uid}] {url} Requests an actor\n"); |
| 33 | printf("note {basedir} {uid} {'text'} Sends a note to followers\n"); | 34 | printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\n"); |
| 34 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); | 35 | printf("boost|announce {basedir} {uid} {url} Boosts (announces) a post\n"); |
| 35 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); | 36 | printf("unboost {basedir} {uid} {url} Unboosts a post\n"); |
| 36 | printf("webfinger_s {basedir} {uid} {actor} Queries about an actor (@user@host or actor url)\n"); | 37 | printf("resetpwd {basedir} {uid} Resets the password of a user\n"); |
| 37 | printf("pin {basedir} {uid} {msg_url} Pins a message\n"); | 38 | printf("ping {basedir} {uid} {actor} Pings an actor\n"); |
| 38 | printf("unpin {basedir} {uid} {msg_url} Unpins a message\n"); | 39 | printf("webfinger_s {basedir} {uid} {actor} Queries about an actor (@user@host or actor url)\n"); |
| 39 | printf("block {basedir} {instance_url} Blocks a full instance\n"); | 40 | printf("pin {basedir} {uid} {msg_url} Pins a message\n"); |
| 40 | printf("unblock {basedir} {instance_url} Unblocks a full instance\n"); | 41 | printf("unpin {basedir} {uid} {msg_url} Unpins a message\n"); |
| 41 | printf("limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n"); | 42 | printf("block {basedir} {instance_url} Blocks a full instance\n"); |
| 42 | printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n"); | 43 | printf("unblock {basedir} {instance_url} Unblocks a full instance\n"); |
| 43 | printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); | 44 | printf("limit {basedir} {uid} {actor} Limits an actor (drops their announces)\n"); |
| 45 | printf("unlimit {basedir} {uid} {actor} Unlimits an actor\n"); | ||
| 46 | printf("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); | ||
| 44 | 47 | ||
| 45 | return 1; | 48 | return 1; |
| 46 | } | 49 | } |
| @@ -96,7 +99,7 @@ int main(int argc, char *argv[]) | |||
| 96 | if (strcmp(cmd, "markdown") == 0) { /** **/ | 99 | if (strcmp(cmd, "markdown") == 0) { /** **/ |
| 97 | /* undocumented, for testing only */ | 100 | /* undocumented, for testing only */ |
| 98 | xs *c = xs_readall(stdin); | 101 | xs *c = xs_readall(stdin); |
| 99 | xs *fc = not_really_markdown(c, NULL); | 102 | xs *fc = not_really_markdown(c, NULL, NULL); |
| 100 | 103 | ||
| 101 | printf("<html>\n%s\n</html>\n", fc); | 104 | printf("<html>\n%s\n</html>\n", fc); |
| 102 | return 0; | 105 | return 0; |
| @@ -279,7 +282,7 @@ int main(int argc, char *argv[]) | |||
| 279 | return 0; | 282 | return 0; |
| 280 | } | 283 | } |
| 281 | 284 | ||
| 282 | if (strcmp(cmd, "announce") == 0) { /** **/ | 285 | if (strcmp(cmd, "boost") == 0 || strcmp(cmd, "announce") == 0) { /** **/ |
| 283 | xs *msg = msg_admiration(&snac, url, "Announce"); | 286 | xs *msg = msg_admiration(&snac, url, "Announce"); |
| 284 | 287 | ||
| 285 | if (msg != NULL) { | 288 | if (msg != NULL) { |
| @@ -293,6 +296,20 @@ int main(int argc, char *argv[]) | |||
| 293 | return 0; | 296 | return 0; |
| 294 | } | 297 | } |
| 295 | 298 | ||
| 299 | if (strcmp(cmd, "unboost") == 0) { /** **/ | ||
| 300 | xs *msg = msg_repulsion(&snac, url, "Announce"); | ||
| 301 | |||
| 302 | if (msg != NULL) { | ||
| 303 | enqueue_message(&snac, msg); | ||
| 304 | |||
| 305 | if (dbglevel) { | ||
| 306 | xs_json_dump(msg, 4, stdout); | ||
| 307 | } | ||
| 308 | } | ||
| 309 | |||
| 310 | return 0; | ||
| 311 | } | ||
| 312 | |||
| 296 | if (strcmp(cmd, "follow") == 0) { /** **/ | 313 | if (strcmp(cmd, "follow") == 0) { /** **/ |
| 297 | xs *msg = msg_follow(&snac, url); | 314 | xs *msg = msg_follow(&snac, url); |
| 298 | 315 | ||
| @@ -360,6 +377,14 @@ int main(int argc, char *argv[]) | |||
| 360 | if (strcmp(cmd, "ping") == 0) { /** **/ | 377 | if (strcmp(cmd, "ping") == 0) { /** **/ |
| 361 | xs *actor_o = NULL; | 378 | xs *actor_o = NULL; |
| 362 | 379 | ||
| 380 | if (!xs_startswith(url, "https:/")) { | ||
| 381 | /* try to resolve via webfinger */ | ||
| 382 | if (!valid_status(webfinger_request(url, &url, NULL))) { | ||
| 383 | srv_log(xs_fmt("cannot resolve %s via webfinger", url)); | ||
| 384 | return 1; | ||
| 385 | } | ||
| 386 | } | ||
| 387 | |||
| 363 | if (valid_status(actor_request(&snac, url, &actor_o))) { | 388 | if (valid_status(actor_request(&snac, url, &actor_o))) { |
| 364 | xs *msg = msg_ping(&snac, url); | 389 | xs *msg = msg_ping(&snac, url); |
| 365 | 390 | ||
| @@ -368,6 +393,8 @@ int main(int argc, char *argv[]) | |||
| 368 | if (dbglevel) { | 393 | if (dbglevel) { |
| 369 | xs_json_dump(msg, 4, stdout); | 394 | xs_json_dump(msg, 4, stdout); |
| 370 | } | 395 | } |
| 396 | |||
| 397 | srv_log(xs_fmt("Ping sent to %s -- see log for Pong reply", url)); | ||
| 371 | } | 398 | } |
| 372 | else { | 399 | else { |
| 373 | srv_log(xs_fmt("Error getting actor %s", url)); | 400 | srv_log(xs_fmt("Error getting actor %s", url)); |
| @@ -450,7 +477,39 @@ int main(int argc, char *argv[]) | |||
| 450 | xs *content = NULL; | 477 | xs *content = NULL; |
| 451 | xs *msg = NULL; | 478 | xs *msg = NULL; |
| 452 | xs *c_msg = NULL; | 479 | xs *c_msg = NULL; |
| 453 | char *in_reply_to = GET_ARGV(); | 480 | xs *attl = xs_list_new(); |
| 481 | char *fn = NULL; | ||
| 482 | |||
| 483 | /* iterate possible attachments */ | ||
| 484 | while ((fn = GET_ARGV())) { | ||
| 485 | FILE *f; | ||
| 486 | |||
| 487 | if ((f = fopen(fn, "rb")) != NULL) { | ||
| 488 | /* get the file size and content */ | ||
| 489 | fseek(f, 0, SEEK_END); | ||
| 490 | int sz = ftell(f); | ||
| 491 | fseek(f, 0, SEEK_SET); | ||
| 492 | xs *atc = xs_readall(f); | ||
| 493 | fclose(f); | ||
| 494 | |||
| 495 | char *ext = strrchr(fn, '.'); | ||
| 496 | xs *hash = xs_md5_hex(fn, strlen(fn)); | ||
| 497 | xs *id = xs_fmt("%s%s", hash, ext); | ||
| 498 | xs *url = xs_fmt("%s/s/%s", snac.actor, id); | ||
| 499 | |||
| 500 | /* store */ | ||
| 501 | static_put(&snac, id, atc, sz); | ||
| 502 | |||
| 503 | xs *l = xs_list_new(); | ||
| 504 | |||
| 505 | l = xs_list_append(l, url); | ||
| 506 | l = xs_list_append(l, ""); /* alt text */ | ||
| 507 | |||
| 508 | attl = xs_list_append(attl, l); | ||
| 509 | } | ||
| 510 | else | ||
| 511 | fprintf(stderr, "Error opening '%s' as attachment\n", fn); | ||
| 512 | } | ||
| 454 | 513 | ||
| 455 | if (strcmp(url, "-e") == 0) { | 514 | if (strcmp(url, "-e") == 0) { |
| 456 | /* get the content from an editor */ | 515 | /* get the content from an editor */ |
| @@ -478,7 +537,7 @@ int main(int argc, char *argv[]) | |||
| 478 | else | 537 | else |
| 479 | content = xs_dup(url); | 538 | content = xs_dup(url); |
| 480 | 539 | ||
| 481 | msg = msg_note(&snac, content, NULL, in_reply_to, NULL, 0); | 540 | msg = msg_note(&snac, content, NULL, NULL, attl, 0); |
| 482 | 541 | ||
| 483 | c_msg = msg_create(&snac, msg); | 542 | c_msg = msg_create(&snac, msg); |
| 484 | 543 | ||