summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar default2024-03-15 20:26:35 +0100
committerGravatar default2024-03-15 20:26:35 +0100
commit15ac48280b67701dd2d06cafbf6914dfa85865b0 (patch)
tree89de1676f0b1bff220b2495504c8cee184f6adb7 /main.c
parentAlso hide Older... posts details if it's empty. (diff)
downloadsnac2-15ac48280b67701dd2d06cafbf6914dfa85865b0.tar.gz
snac2-15ac48280b67701dd2d06cafbf6914dfa85865b0.tar.xz
snac2-15ac48280b67701dd2d06cafbf6914dfa85865b0.zip
The command-line 'note' also allows attachments.
Diffstat (limited to 'main.c')
-rw-r--r--main.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/main.c b/main.c
index cbd9921..9d09ba3 100644
--- a/main.c
+++ b/main.c
@@ -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
@@ -450,7 +451,39 @@ int main(int argc, char *argv[])
450 xs *content = NULL; 451 xs *content = NULL;
451 xs *msg = NULL; 452 xs *msg = NULL;
452 xs *c_msg = NULL; 453 xs *c_msg = NULL;
453 char *in_reply_to = GET_ARGV(); 454 xs *attl = xs_list_new();
455 char *fn = NULL;
456
457 /* iterate possible attachments */
458 while ((fn = GET_ARGV())) {
459 FILE *f;
460
461 if ((f = fopen(fn, "rb")) != NULL) {
462 /* get the file size and content */
463 fseek(f, 0, SEEK_END);
464 int sz = ftell(f);
465 fseek(f, 0, SEEK_SET);
466 xs *atc = xs_readall(f);
467 fclose(f);
468
469 char *ext = strrchr(fn, '.');
470 xs *hash = xs_md5_hex(fn, strlen(fn));
471 xs *id = xs_fmt("%s%s", hash, ext);
472 xs *url = xs_fmt("%s/s/%s", snac.actor, id);
473
474 /* store */
475 static_put(&snac, id, atc, sz);
476
477 xs *l = xs_list_new();
478
479 l = xs_list_append(l, url);
480 l = xs_list_append(l, ""); /* alt text */
481
482 attl = xs_list_append(attl, l);
483 }
484 else
485 fprintf(stderr, "Error opening '%s' as attachment\n", fn);
486 }
454 487
455 if (strcmp(url, "-e") == 0) { 488 if (strcmp(url, "-e") == 0) {
456 /* get the content from an editor */ 489 /* get the content from an editor */
@@ -478,7 +511,7 @@ int main(int argc, char *argv[])
478 else 511 else
479 content = xs_dup(url); 512 content = xs_dup(url);
480 513
481 msg = msg_note(&snac, content, NULL, in_reply_to, NULL, 0); 514 msg = msg_note(&snac, content, NULL, NULL, attl, 0);
482 515
483 c_msg = msg_create(&snac, msg); 516 c_msg = msg_create(&snac, msg);
484 517