summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-03-15 20:26:35 +0100
committerGravatar default2024-03-15 20:26:35 +0100
commit15ac48280b67701dd2d06cafbf6914dfa85865b0 (patch)
tree89de1676f0b1bff220b2495504c8cee184f6adb7
parentAlso hide Older... posts details if it's empty. (diff)
downloadpenes-snac2-15ac48280b67701dd2d06cafbf6914dfa85865b0.tar.gz
penes-snac2-15ac48280b67701dd2d06cafbf6914dfa85865b0.tar.xz
penes-snac2-15ac48280b67701dd2d06cafbf6914dfa85865b0.zip
The command-line 'note' also allows attachments.
-rw-r--r--Makefile2
-rw-r--r--Makefile.NetBSD2
-rw-r--r--main.c37
3 files changed, 37 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index cc320d0..93ddf40 100644
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@ http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
44 snac.h 44 snac.h
45httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \ 45httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \
46 xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h 46 xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h
47main.o: main.c xs.h xs_io.h xs_json.h xs_time.h snac.h 47main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h
48mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ 48mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
49 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \ 49 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
50 snac.h 50 snac.h
diff --git a/Makefile.NetBSD b/Makefile.NetBSD
index f4e6410..b249bca 100644
--- a/Makefile.NetBSD
+++ b/Makefile.NetBSD
@@ -46,7 +46,7 @@ http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
46 snac.h 46 snac.h
47httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \ 47httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \
48 xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h 48 xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h
49main.o: main.c xs.h xs_io.h xs_json.h xs_time.h snac.h 49main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h
50mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ 50mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
51 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \ 51 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
52 snac.h 52 snac.h
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