diff options
author | default <nobody@localhost> | 2024-03-15 20:26:35 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2024-03-15 20:26:35 +0100 |
commit | 15ac48280b67701dd2d06cafbf6914dfa85865b0 (patch) | |
tree | 89de1676f0b1bff220b2495504c8cee184f6adb7 | |
parent | c12acc0cc9a5037570207a84f5eaa5e6c849764c (diff) |
The command-line 'note' also allows attachments.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | Makefile.NetBSD | 2 | ||||
-rw-r--r-- | main.c | 37 |
3 files changed, 37 insertions, 4 deletions
@@ -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 \ snac.h httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \ xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h -main.o: main.c xs.h xs_io.h xs_json.h xs_time.h snac.h +main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \ 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 \ snac.h httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \ xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h -main.o: main.c xs.h xs_io.h xs_json.h xs_time.h snac.h +main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \ snac.h @@ -5,6 +5,7 @@ #include "xs_io.h" #include "xs_json.h" #include "xs_time.h" +#include "xs_openssl.h" #include "snac.h" @@ -450,7 +451,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 +511,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); |