commit 15ac482

default  ·  2024-03-15 19:26:35 +0000 UTC
parent c12acc0
The command-line 'note' also allows attachments.
3 files changed,  +37, -4
M main.c
+1, -1
1@@ -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 \
2  snac.h
3 httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \
4  xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h
5-main.o: main.c xs.h xs_io.h xs_json.h xs_time.h snac.h
6+main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h
7 mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
8  xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
9  snac.h
+1, -1
1@@ -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 \
2  snac.h
3 httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_httpd.h xs_mime.h \
4  xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h
5-main.o: main.c xs.h xs_io.h xs_json.h xs_time.h snac.h
6+main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h snac.h
7 mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
8  xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
9  snac.h
M main.c
+35, -2
 1@@ -5,6 +5,7 @@
 2 #include "xs_io.h"
 3 #include "xs_json.h"
 4 #include "xs_time.h"
 5+#include "xs_openssl.h"
 6 
 7 #include "snac.h"
 8 
 9@@ -450,7 +451,39 @@ int main(int argc, char *argv[])
10         xs *content = NULL;
11         xs *msg = NULL;
12         xs *c_msg = NULL;
13-        char *in_reply_to = GET_ARGV();
14+        xs *attl = xs_list_new();
15+        char *fn = NULL;
16+
17+        /* iterate possible attachments */
18+        while ((fn = GET_ARGV())) {
19+            FILE *f;
20+
21+            if ((f = fopen(fn, "rb")) != NULL) {
22+                /* get the file size and content */
23+                fseek(f, 0, SEEK_END);
24+                int sz = ftell(f);
25+                fseek(f, 0, SEEK_SET);
26+                xs *atc = xs_readall(f);
27+                fclose(f);
28+
29+                char *ext = strrchr(fn, '.');
30+                xs *hash  = xs_md5_hex(fn, strlen(fn));
31+                xs *id    = xs_fmt("%s%s", hash, ext);
32+                xs *url   = xs_fmt("%s/s/%s", snac.actor, id);
33+
34+                /* store */
35+                static_put(&snac, id, atc, sz);
36+
37+                xs *l = xs_list_new();
38+
39+                l = xs_list_append(l, url);
40+                l = xs_list_append(l, ""); /* alt text */
41+
42+                attl = xs_list_append(attl, l);
43+            }
44+            else
45+                fprintf(stderr, "Error opening '%s' as attachment\n", fn);
46+        }
47 
48         if (strcmp(url, "-e") == 0) {
49             /* get the content from an editor */
50@@ -478,7 +511,7 @@ int main(int argc, char *argv[])
51         else
52             content = xs_dup(url);
53 
54-        msg = msg_note(&snac, content, NULL, in_reply_to, NULL, 0);
55+        msg = msg_note(&snac, content, NULL, NULL, attl, 0);
56 
57         c_msg = msg_create(&snac, msg);
58