commit c976b9a

grunfink  ·  2025-06-26 08:39:47 +0000 UTC
parent 5d680a5
Sending notes from the cmdline allows setting an inReplyTo field.
3 files changed,  +25, -10
M main.c
+3, -3
 1@@ -60,10 +60,10 @@ html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
 2 http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
 3  snac.h http_codes.h
 4 httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \
 5- xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h \
 6- http_codes.h
 7+ xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h \
 8+ xs_webmention.h snac.h http_codes.h
 9 main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \
10- snac.h http_codes.h
11+ xs_random.h snac.h http_codes.h
12 mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
13  xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
14  xs_unicode.h snac.h http_codes.h
+3, -3
 1@@ -49,10 +49,10 @@ html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
 2 http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
 3  snac.h http_codes.h
 4 httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \
 5- xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h snac.h \
 6- http_codes.h
 7+ xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h \
 8+ xs_webmention.h snac.h http_codes.h
 9 main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \
10- snac.h http_codes.h
11+ xs_random.h snac.h http_codes.h
12 mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
13  xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
14  xs_unicode.h snac.h http_codes.h
M main.c
+19, -4
 1@@ -7,6 +7,7 @@
 2 #include "xs_time.h"
 3 #include "xs_openssl.h"
 4 #include "xs_match.h"
 5+#include "xs_random.h"
 6 
 7 #include "snac.h"
 8 
 9@@ -779,12 +780,24 @@ int main(int argc, char *argv[])
10         xs *msg = NULL;
11         xs *c_msg = NULL;
12         xs *attl = xs_list_new();
13-        char *fn = NULL;
14+        const char *fn = NULL;
15+        const char *in_reply_to = NULL;
16+        const char **next = NULL;
17 
18         /* iterate possible attachments */
19         while ((fn = GET_ARGV())) {
20             FILE *f;
21 
22+            if (next) {
23+                *next = fn;
24+                next = NULL;
25+            }
26+            else
27+            if (strcmp(fn, "-r") == 0) {
28+                /* next argument is an inReplyTo */
29+                next = &in_reply_to;
30+            }
31+            else
32             if ((f = fopen(fn, "rb")) != NULL) {
33                 /* get the file size and content */
34                 fseek(f, 0, SEEK_END);
35@@ -794,8 +807,10 @@ int main(int argc, char *argv[])
36                 fclose(f);
37 
38                 char *ext = strrchr(fn, '.');
39-                xs *hash  = xs_md5_hex(fn, strlen(fn));
40-                xs *id    = xs_fmt("%s%s", hash, ext);
41+                char rnd[32];
42+                xs_rnd_buf(rnd, sizeof(rnd));
43+                xs *hash  = xs_md5_hex(rnd, sizeof(rnd));
44+                xs *id    = xs_fmt("post-%s%s", hash, ext ? ext : "");
45                 xs *url   = xs_fmt("%s/s/%s", snac.actor, id);
46 
47                 /* store */
48@@ -856,7 +871,7 @@ int main(int argc, char *argv[])
49         if (strcmp(cmd, "note_unlisted") == 0)
50             scope = 2;
51 
52-        msg = msg_note(&snac, content, NULL, NULL, attl, scope, getenv("LANG"), NULL);
53+        msg = msg_note(&snac, content, NULL, in_reply_to, attl, scope, getenv("LANG"), NULL);
54 
55         c_msg = msg_create(&snac, msg);
56