diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 115 |
1 files changed, 87 insertions, 28 deletions
@@ -5,6 +5,7 @@ #include "xs_io.h" #include "xs_json.h" #include "xs_time.h" +#include "xs_openssl.h" #include "snac.h" @@ -17,30 +18,32 @@ int usage(void) 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} {actor} Queries about an actor (@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("actor {basedir} [{uid}] {url} Requests an actor\n"); - printf("note {basedir} {uid} {'text'} Sends a note to followers\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} {actor} Queries about an actor (@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("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("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\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} {actor} Queries about an actor (@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("actor {basedir} [{uid}] {url} Requests an actor\n"); + printf("note {basedir} {uid} {text} [files...] Sends a note with optional attachments\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} {actor} Queries about an actor (@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("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("verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"); return 1; } @@ -96,7 +99,7 @@ int main(int argc, char *argv[]) if (strcmp(cmd, "markdown") == 0) { /** **/ /* undocumented, for testing only */ xs *c = xs_readall(stdin); - xs *fc = not_really_markdown(c, NULL); + xs *fc = not_really_markdown(c, NULL, NULL); printf("<html>\n%s\n</html>\n", fc); return 0; @@ -279,7 +282,7 @@ int main(int argc, char *argv[]) return 0; } - if (strcmp(cmd, "announce") == 0) { /** **/ + if (strcmp(cmd, "boost") == 0 || strcmp(cmd, "announce") == 0) { /** **/ xs *msg = msg_admiration(&snac, url, "Announce"); if (msg != NULL) { @@ -293,6 +296,20 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(cmd, "unboost") == 0) { /** **/ + xs *msg = msg_repulsion(&snac, url, "Announce"); + + if (msg != NULL) { + enqueue_message(&snac, msg); + + if (dbglevel) { + xs_json_dump(msg, 4, stdout); + } + } + + return 0; + } + if (strcmp(cmd, "follow") == 0) { /** **/ xs *msg = msg_follow(&snac, url); @@ -360,6 +377,14 @@ int main(int argc, char *argv[]) if (strcmp(cmd, "ping") == 0) { /** **/ xs *actor_o = NULL; + if (!xs_startswith(url, "https:/")) { + /* try to resolve via webfinger */ + if (!valid_status(webfinger_request(url, &url, NULL))) { + srv_log(xs_fmt("cannot resolve %s via webfinger", url)); + return 1; + } + } + if (valid_status(actor_request(&snac, url, &actor_o))) { xs *msg = msg_ping(&snac, url); @@ -368,6 +393,8 @@ int main(int argc, char *argv[]) if (dbglevel) { xs_json_dump(msg, 4, stdout); } + + srv_log(xs_fmt("Ping sent to %s -- see log for Pong reply", url)); } else { srv_log(xs_fmt("Error getting actor %s", url)); @@ -450,7 +477,39 @@ int main(int argc, char *argv[]) xs *content = NULL; xs *msg = NULL; xs *c_msg = NULL; - char *in_reply_to = GET_ARGV(); + xs *attl = xs_list_new(); + char *fn = NULL; + + /* iterate possible attachments */ + while ((fn = GET_ARGV())) { + FILE *f; + + if ((f = fopen(fn, "rb")) != NULL) { + /* get the file size and content */ + fseek(f, 0, SEEK_END); + int sz = ftell(f); + fseek(f, 0, SEEK_SET); + xs *atc = xs_readall(f); + fclose(f); + + char *ext = strrchr(fn, '.'); + xs *hash = xs_md5_hex(fn, strlen(fn)); + xs *id = xs_fmt("%s%s", hash, ext); + xs *url = xs_fmt("%s/s/%s", snac.actor, id); + + /* store */ + static_put(&snac, id, atc, sz); + + xs *l = xs_list_new(); + + l = xs_list_append(l, url); + l = xs_list_append(l, ""); /* alt text */ + + attl = xs_list_append(attl, l); + } + else + fprintf(stderr, "Error opening '%s' as attachment\n", fn); + } if (strcmp(url, "-e") == 0) { /* get the content from an editor */ @@ -478,7 +537,7 @@ int main(int argc, char *argv[]) else content = xs_dup(url); - msg = msg_note(&snac, content, NULL, in_reply_to, NULL, 0); + msg = msg_note(&snac, content, NULL, NULL, attl, 0); c_msg = msg_create(&snac, msg); |