summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar grunfink2025-10-13 13:07:06 +0200
committerGravatar grunfink2025-10-13 13:07:06 +0200
commit212284c792c86fca52e0172a4d097abc5bb45252 (patch)
tree4fe9ebc3859eec9edb46388a606cb6d54898c64a
parentUpdated RELEASE_NOTES. (diff)
downloadsnac2-212284c792c86fca52e0172a4d097abc5bb45252.tar.gz
snac2-212284c792c86fca52e0172a4d097abc5bb45252.tar.xz
snac2-212284c792c86fca52e0172a4d097abc5bb45252.zip
xs_http.h: new file.
-rw-r--r--Makefile37
-rw-r--r--Makefile.NetBSD37
-rw-r--r--activitypub.c3
-rw-r--r--data.c1
-rw-r--r--html.c1
-rw-r--r--http.c1
-rw-r--r--httpd.c3
-rw-r--r--main.c1
-rw-r--r--mastoapi.c1
-rw-r--r--rss.c1
-rw-r--r--snac.c21
-rw-r--r--snac.h10
-rw-r--r--utils.c1
-rw-r--r--webfinger.c1
-rw-r--r--xs_http.h42
-rw-r--r--xs_http_codes.h (renamed from http_codes.h)0
16 files changed, 94 insertions, 67 deletions
diff --git a/Makefile b/Makefile
index 5de2882..ffeac1a 100644
--- a/Makefile
+++ b/Makefile
@@ -48,35 +48,36 @@ update-po:
48 48
49activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \ 49activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \
50 xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \ 50 xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \
51 xs_webmention.h snac.h http_codes.h 51 xs_webmention.h xs_http.h xs_http_codes.h snac.h
52data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \ 52data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \
53 xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h \ 53 xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h \
54 xs_po.h snac.h http_codes.h 54 xs_po.h xs_http.h xs_http_codes.h snac.h
55format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \ 55format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \
56 xs_time.h xs_match.h xs_unicode.h snac.h http_codes.h 56 xs_time.h xs_match.h xs_unicode.h snac.h
57html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \ 57html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
58 xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h xs_url.h \ 58 xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h xs_url.h \
59 xs_random.h snac.h http_codes.h 59 xs_random.h xs_http.h xs_http_codes.h snac.h
60http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \ 60http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
61 snac.h http_codes.h 61 xs_http.h xs_http_codes.h snac.h
62httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \ 62httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \
63 xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h \ 63 xs_http.h xs_http_codes.h xs_httpd.h xs_mime.h xs_time.h xs_openssl.h \
64 xs_webmention.h snac.h http_codes.h 64 xs_fcgi.h xs_html.h xs_webmention.h snac.h
65main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \ 65main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \
66 xs_random.h snac.h http_codes.h 66 xs_random.h xs_http.h xs_http_codes.h snac.h
67mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ 67mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
68 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \ 68 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
69 xs_unicode.h snac.h http_codes.h 69 xs_unicode.h xs_http.h xs_http_codes.h snac.h
70rss.o: rss.c xs.h xs_html.h xs_regex.h xs_time.h xs_match.h xs_curl.h \ 70rss.o: rss.c xs.h xs_html.h xs_regex.h xs_time.h xs_match.h xs_curl.h \
71 xs_openssl.h xs_json.h snac.h http_codes.h 71 xs_openssl.h xs_json.h xs_http.h xs_http_codes.h snac.h
72sandbox.o: sandbox.c xs.h snac.h http_codes.h 72sandbox.o: sandbox.c xs.h snac.h
73snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \ 73snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \
74 xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \ 74 xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \
75 xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h xs_random.h \ 75 xs_http.h xs_http_codes.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h \
76 xs_match.h xs_fcgi.h xs_html.h xs_po.h xs_webmention.h snac.h \ 76 xs_time.h xs_glob.h xs_random.h xs_match.h xs_fcgi.h xs_html.h xs_po.h \
77 http_codes.h 77 xs_webmention.h snac.h
78upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h 78upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h
79utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ 79utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \
80 xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h 80 xs_random.h xs_glob.h xs_curl.h xs_regex.h xs_http.h xs_http_codes.h \
81webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h \ 81 snac.h
82 http_codes.h 82webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h xs_http.h \
83 xs_http_codes.h snac.h
diff --git a/Makefile.NetBSD b/Makefile.NetBSD
index ac5b052..b5005ee 100644
--- a/Makefile.NetBSD
+++ b/Makefile.NetBSD
@@ -37,35 +37,36 @@ uninstall:
37 37
38activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \ 38activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \
39 xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \ 39 xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \
40 xs_webmention.h snac.h http_codes.h 40 xs_webmention.h xs_http.h xs_http_codes.h snac.h
41data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \ 41data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \
42 xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h \ 42 xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h \
43 xs_po.h snac.h http_codes.h 43 xs_po.h xs_http.h xs_http_codes.h snac.h
44format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \ 44format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \
45 xs_time.h xs_match.h xs_unicode.h snac.h http_codes.h 45 xs_time.h xs_match.h xs_unicode.h snac.h
46html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \ 46html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
47 xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h xs_url.h \ 47 xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h xs_url.h \
48 xs_random.h snac.h http_codes.h 48 xs_random.h xs_http.h xs_http_codes.h snac.h
49http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \ 49http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
50 snac.h http_codes.h 50 xs_http.h xs_http_codes.h snac.h
51httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \ 51httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \
52 xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h \ 52 xs_http.h xs_http_codes.h xs_httpd.h xs_mime.h xs_time.h xs_openssl.h \
53 xs_webmention.h snac.h http_codes.h 53 xs_fcgi.h xs_html.h xs_webmention.h snac.h
54main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \ 54main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \
55 xs_random.h snac.h http_codes.h 55 xs_random.h xs_http.h xs_http_codes.h snac.h
56mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ 56mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \
57 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \ 57 xs_time.h xs_glob.h xs_set.h xs_random.h xs_url.h xs_mime.h xs_match.h \
58 xs_unicode.h snac.h http_codes.h 58 xs_unicode.h xs_http.h xs_http_codes.h snac.h
59rss.o: rss.c xs.h xs_html.h xs_regex.h xs_time.h xs_match.h xs_curl.h \ 59rss.o: rss.c xs.h xs_html.h xs_regex.h xs_time.h xs_match.h xs_curl.h \
60 xs_openssl.h xs_json.h snac.h http_codes.h 60 xs_openssl.h xs_json.h xs_http.h xs_http_codes.h snac.h
61sandbox.o: sandbox.c xs.h snac.h http_codes.h 61sandbox.o: sandbox.c xs.h snac.h
62snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \ 62snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \
63 xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \ 63 xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \
64 xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h xs_random.h \ 64 xs_http.h xs_http_codes.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h \
65 xs_match.h xs_fcgi.h xs_html.h xs_po.h xs_webmention.h snac.h \ 65 xs_time.h xs_glob.h xs_random.h xs_match.h xs_fcgi.h xs_html.h xs_po.h \
66 http_codes.h 66 xs_webmention.h snac.h
67upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h 67upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h
68utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ 68utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \
69 xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h 69 xs_random.h xs_glob.h xs_curl.h xs_regex.h xs_http.h xs_http_codes.h \
70webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h \ 70 snac.h
71 http_codes.h 71webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h xs_http.h \
72 xs_http_codes.h snac.h
diff --git a/activitypub.c b/activitypub.c
index c433788..f19c6fc 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -12,6 +12,7 @@
12#include "xs_match.h" 12#include "xs_match.h"
13#include "xs_unicode.h" 13#include "xs_unicode.h"
14#include "xs_webmention.h" 14#include "xs_webmention.h"
15#include "xs_http.h"
15 16
16#include "snac.h" 17#include "snac.h"
17 18
@@ -3210,7 +3211,7 @@ int process_user_queue(snac *snac)
3210 3211
3211xs_str *str_status(int status) 3212xs_str *str_status(int status)
3212{ 3213{
3213 return xs_fmt("%d %s", status, status < 0 ? xs_curl_strerr(status) : http_status_text(status)); 3214 return xs_fmt("%d %s", status, status < 0 ? xs_curl_strerr(status) : xs_http_status_text(status));
3214} 3215}
3215 3216
3216 3217
diff --git a/data.c b/data.c
index 53e9438..36f5101 100644
--- a/data.c
+++ b/data.c
@@ -14,6 +14,7 @@
14#include "xs_unicode.h" 14#include "xs_unicode.h"
15#include "xs_random.h" 15#include "xs_random.h"
16#include "xs_po.h" 16#include "xs_po.h"
17#include "xs_http.h"
17 18
18#include "snac.h" 19#include "snac.h"
19 20
diff --git a/html.c b/html.c
index 777875c..584059b 100644
--- a/html.c
+++ b/html.c
@@ -15,6 +15,7 @@
15#include "xs_unicode.h" 15#include "xs_unicode.h"
16#include "xs_url.h" 16#include "xs_url.h"
17#include "xs_random.h" 17#include "xs_random.h"
18#include "xs_http.h"
18 19
19#include "snac.h" 20#include "snac.h"
20 21
diff --git a/http.c b/http.c
index 611de4f..f0b1314 100644
--- a/http.c
+++ b/http.c
@@ -7,6 +7,7 @@
7#include "xs_curl.h" 7#include "xs_curl.h"
8#include "xs_time.h" 8#include "xs_time.h"
9#include "xs_json.h" 9#include "xs_json.h"
10#include "xs_http.h"
10 11
11#include "snac.h" 12#include "snac.h"
12 13
diff --git a/httpd.c b/httpd.c
index de76776..254d0e5 100644
--- a/httpd.c
+++ b/httpd.c
@@ -6,6 +6,7 @@
6#include "xs_json.h" 6#include "xs_json.h"
7#include "xs_socket.h" 7#include "xs_socket.h"
8#include "xs_unix_socket.h" 8#include "xs_unix_socket.h"
9#include "xs_http.h"
9#include "xs_httpd.h" 10#include "xs_httpd.h"
10#include "xs_mime.h" 11#include "xs_mime.h"
11#include "xs_time.h" 12#include "xs_time.h"
@@ -650,7 +651,7 @@ void httpd_connection(FILE *f)
650 if (p_state->use_fcgi) 651 if (p_state->use_fcgi)
651 xs_fcgi_response(f, status, headers, body, b_size, fcgi_id); 652 xs_fcgi_response(f, status, headers, body, b_size, fcgi_id);
652 else 653 else
653 xs_httpd_response(f, status, http_status_text(status), headers, body, b_size); 654 xs_httpd_response(f, status, xs_http_status_text(status), headers, body, b_size);
654 655
655 fclose(f); 656 fclose(f);
656 657
diff --git a/main.c b/main.c
index 46f88d2..6915bd0 100644
--- a/main.c
+++ b/main.c
@@ -8,6 +8,7 @@
8#include "xs_openssl.h" 8#include "xs_openssl.h"
9#include "xs_match.h" 9#include "xs_match.h"
10#include "xs_random.h" 10#include "xs_random.h"
11#include "xs_http.h"
11 12
12#include "snac.h" 13#include "snac.h"
13 14
diff --git a/mastoapi.c b/mastoapi.c
index c526307..2c111ca 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -16,6 +16,7 @@
16#include "xs_mime.h" 16#include "xs_mime.h"
17#include "xs_match.h" 17#include "xs_match.h"
18#include "xs_unicode.h" 18#include "xs_unicode.h"
19#include "xs_http.h"
19 20
20#include "snac.h" 21#include "snac.h"
21 22
diff --git a/rss.c b/rss.c
index bb7b043..6e77205 100644
--- a/rss.c
+++ b/rss.c
@@ -9,6 +9,7 @@
9#include "xs_curl.h" 9#include "xs_curl.h"
10#include "xs_openssl.h" 10#include "xs_openssl.h"
11#include "xs_json.h" 11#include "xs_json.h"
12#include "xs_http.h"
12 13
13#include "snac.h" 14#include "snac.h"
14 15
diff --git a/snac.c b/snac.c
index a35cd06..31f524f 100644
--- a/snac.c
+++ b/snac.c
@@ -14,6 +14,7 @@
14#include "xs_socket.h" 14#include "xs_socket.h"
15#include "xs_unix_socket.h" 15#include "xs_unix_socket.h"
16#include "xs_url.h" 16#include "xs_url.h"
17#include "xs_http.h"
17#include "xs_httpd.h" 18#include "xs_httpd.h"
18#include "xs_mime.h" 19#include "xs_mime.h"
19#include "xs_regex.h" 20#include "xs_regex.h"
@@ -58,13 +59,6 @@ int mkdirx(const char *pathname)
58} 59}
59 60
60 61
61int valid_status(int status)
62/* is this HTTP status valid? */
63{
64 return status >= 200 && status <= 299;
65}
66
67
68xs_str *tid(int offset) 62xs_str *tid(int offset)
69/* returns a time-based Id */ 63/* returns a time-based Id */
70{ 64{
@@ -176,16 +170,3 @@ int check_password(const char *uid, const char *passwd, const char *hash)
176 170
177 return ret; 171 return ret;
178} 172}
179
180
181const char *http_status_text(int status)
182/* translate status codes to canonical status texts */
183{
184 switch (status) {
185 case 599: return "Timeout";
186#define HTTP_STATUS(code, name, text) case HTTP_STATUS_ ## name: return #text;
187#include "http_codes.h"
188#undef HTTP_STATUS
189 default: return "Unknown";
190 }
191}
diff --git a/snac.h b/snac.h
index 245f477..038aa40 100644
--- a/snac.h
+++ b/snac.h
@@ -44,7 +44,7 @@ extern int dbglevel;
44 44
45int mkdirx(const char *pathname); 45int mkdirx(const char *pathname);
46 46
47int valid_status(int status); 47#define valid_status(status) xs_http_valid_status(status)
48xs_str *tid(int offset); 48xs_str *tid(int offset);
49double ftime(void); 49double ftime(void);
50 50
@@ -464,14 +464,6 @@ void import_list_csv(snac *user, const char *fn);
464void import_csv(snac *user); 464void import_csv(snac *user);
465int parse_port(const char *url, const char **errstr); 465int parse_port(const char *url, const char **errstr);
466 466
467typedef enum {
468#define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code,
469#include "http_codes.h"
470#undef HTTP_STATUS
471} http_status;
472
473const char *http_status_text(int status);
474
475typedef struct { 467typedef struct {
476 double timestamp; 468 double timestamp;
477 char *text; 469 char *text;
diff --git a/utils.c b/utils.c
index 38dcc06..de6db79 100644
--- a/utils.c
+++ b/utils.c
@@ -10,6 +10,7 @@
10#include "xs_glob.h" 10#include "xs_glob.h"
11#include "xs_curl.h" 11#include "xs_curl.h"
12#include "xs_regex.h" 12#include "xs_regex.h"
13#include "xs_http.h"
13 14
14#include "snac.h" 15#include "snac.h"
15 16
diff --git a/webfinger.c b/webfinger.c
index 46b7edb..12ec42c 100644
--- a/webfinger.c
+++ b/webfinger.c
@@ -5,6 +5,7 @@
5#include "xs_json.h" 5#include "xs_json.h"
6#include "xs_curl.h" 6#include "xs_curl.h"
7#include "xs_mime.h" 7#include "xs_mime.h"
8#include "xs_http.h"
8 9
9#include "snac.h" 10#include "snac.h"
10 11
diff --git a/xs_http.h b/xs_http.h
new file mode 100644
index 0000000..f2fd296
--- /dev/null
+++ b/xs_http.h
@@ -0,0 +1,42 @@
1/* copyright (c) 2022 - 2025 grunfink et al. / MIT license */
2
3#ifndef _XS_HTTP_H
4
5#define _XS_HTTP_H
6
7typedef enum {
8#define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code,
9#include "xs_http_codes.h"
10#undef HTTP_STATUS
11} http_status;
12
13
14int xs_http_valid_status(int status);
15const char *xs_http_status_text(int status);
16
17
18#ifdef XS_IMPLEMENTATION
19
20int xs_http_valid_status(int status)
21/* is this HTTP status valid? */
22{
23 return status >= 200 && status <= 299;
24}
25
26
27const char *xs_http_status_text(int status)
28/* translate status codes to canonical status texts */
29{
30 switch (status) {
31 case 599: return "Timeout";
32#define HTTP_STATUS(code, name, text) case HTTP_STATUS_ ## name: return #text;
33#include "xs_http_codes.h"
34#undef HTTP_STATUS
35 default: return "Unknown";
36 }
37}
38
39
40#endif /* XS_IMPLEMENTATION */
41
42#endif /* XS_HTTP_H */
diff --git a/http_codes.h b/xs_http_codes.h
index a1958f1..a1958f1 100644
--- a/http_codes.h
+++ b/xs_http_codes.h