aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrunfink <grunfink@comam.es>2025-10-13 13:07:06 +0200
committergrunfink <grunfink@comam.es>2025-10-13 13:07:06 +0200
commit212284c792c86fca52e0172a4d097abc5bb45252 (patch)
tree4fe9ebc3859eec9edb46388a606cb6d54898c64a
parent4f0b97ecf6ee157c56aa4fba781a8b6b5ea36174 (diff)
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:
activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \
xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \
- xs_webmention.h snac.h http_codes.h
+ xs_webmention.h xs_http.h xs_http_codes.h snac.h
data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \
xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h \
- xs_po.h snac.h http_codes.h
+ xs_po.h xs_http.h xs_http_codes.h snac.h
format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \
- xs_time.h xs_match.h xs_unicode.h snac.h http_codes.h
+ xs_time.h xs_match.h xs_unicode.h snac.h
html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h xs_url.h \
- xs_random.h snac.h http_codes.h
+ xs_random.h xs_http.h xs_http_codes.h snac.h
http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
- snac.h http_codes.h
+ xs_http.h xs_http_codes.h snac.h
httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \
- xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h \
- xs_webmention.h snac.h http_codes.h
+ xs_http.h xs_http_codes.h xs_httpd.h xs_mime.h xs_time.h xs_openssl.h \
+ xs_fcgi.h xs_html.h xs_webmention.h snac.h
main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \
- xs_random.h snac.h http_codes.h
+ xs_random.h xs_http.h xs_http_codes.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 \
- xs_unicode.h snac.h http_codes.h
+ xs_unicode.h xs_http.h xs_http_codes.h snac.h
rss.o: rss.c xs.h xs_html.h xs_regex.h xs_time.h xs_match.h xs_curl.h \
- xs_openssl.h xs_json.h snac.h http_codes.h
-sandbox.o: sandbox.c xs.h snac.h http_codes.h
+ xs_openssl.h xs_json.h xs_http.h xs_http_codes.h snac.h
+sandbox.o: sandbox.c xs.h snac.h
snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \
xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \
- xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h xs_random.h \
- xs_match.h xs_fcgi.h xs_html.h xs_po.h xs_webmention.h snac.h \
- http_codes.h
-upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h
+ xs_http.h xs_http_codes.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h \
+ xs_time.h xs_glob.h xs_random.h xs_match.h xs_fcgi.h xs_html.h xs_po.h \
+ xs_webmention.h snac.h
+upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h
utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \
- xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h
-webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h \
- http_codes.h
+ xs_random.h xs_glob.h xs_curl.h xs_regex.h xs_http.h xs_http_codes.h \
+ snac.h
+webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h xs_http.h \
+ 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:
activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \
xs_openssl.h xs_regex.h xs_time.h xs_set.h xs_match.h xs_unicode.h \
- xs_webmention.h snac.h http_codes.h
+ xs_webmention.h xs_http.h xs_http_codes.h snac.h
data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \
xs_set.h xs_time.h xs_regex.h xs_match.h xs_unicode.h xs_random.h \
- xs_po.h snac.h http_codes.h
+ xs_po.h xs_http.h xs_http_codes.h snac.h
format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \
- xs_time.h xs_match.h xs_unicode.h snac.h http_codes.h
+ xs_time.h xs_match.h xs_unicode.h snac.h
html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \
xs_time.h xs_mime.h xs_match.h xs_html.h xs_curl.h xs_unicode.h xs_url.h \
- xs_random.h snac.h http_codes.h
+ xs_random.h xs_http.h xs_http_codes.h snac.h
http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \
- snac.h http_codes.h
+ xs_http.h xs_http_codes.h snac.h
httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \
- xs_httpd.h xs_mime.h xs_time.h xs_openssl.h xs_fcgi.h xs_html.h \
- xs_webmention.h snac.h http_codes.h
+ xs_http.h xs_http_codes.h xs_httpd.h xs_mime.h xs_time.h xs_openssl.h \
+ xs_fcgi.h xs_html.h xs_webmention.h snac.h
main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \
- xs_random.h snac.h http_codes.h
+ xs_random.h xs_http.h xs_http_codes.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 \
- xs_unicode.h snac.h http_codes.h
+ xs_unicode.h xs_http.h xs_http_codes.h snac.h
rss.o: rss.c xs.h xs_html.h xs_regex.h xs_time.h xs_match.h xs_curl.h \
- xs_openssl.h xs_json.h snac.h http_codes.h
-sandbox.o: sandbox.c xs.h snac.h http_codes.h
+ xs_openssl.h xs_json.h xs_http.h xs_http_codes.h snac.h
+sandbox.o: sandbox.c xs.h snac.h
snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \
xs_json.h xs_curl.h xs_openssl.h xs_socket.h xs_unix_socket.h xs_url.h \
- xs_httpd.h xs_mime.h xs_regex.h xs_set.h xs_time.h xs_glob.h xs_random.h \
- xs_match.h xs_fcgi.h xs_html.h xs_po.h xs_webmention.h snac.h \
- http_codes.h
-upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h
+ xs_http.h xs_http_codes.h xs_httpd.h xs_mime.h xs_regex.h xs_set.h \
+ xs_time.h xs_glob.h xs_random.h xs_match.h xs_fcgi.h xs_html.h xs_po.h \
+ xs_webmention.h snac.h
+upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h
utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \
- xs_random.h xs_glob.h xs_curl.h xs_regex.h snac.h http_codes.h
-webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h \
- http_codes.h
+ xs_random.h xs_glob.h xs_curl.h xs_regex.h xs_http.h xs_http_codes.h \
+ snac.h
+webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h xs_http.h \
+ 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 @@
#include "xs_match.h"
#include "xs_unicode.h"
#include "xs_webmention.h"
+#include "xs_http.h"
#include "snac.h"
@@ -3210,7 +3211,7 @@ int process_user_queue(snac *snac)
xs_str *str_status(int status)
{
- return xs_fmt("%d %s", status, status < 0 ? xs_curl_strerr(status) : http_status_text(status));
+ return xs_fmt("%d %s", status, status < 0 ? xs_curl_strerr(status) : xs_http_status_text(status));
}
diff --git a/data.c b/data.c
index 53e9438..36f5101 100644
--- a/data.c
+++ b/data.c
@@ -14,6 +14,7 @@
#include "xs_unicode.h"
#include "xs_random.h"
#include "xs_po.h"
+#include "xs_http.h"
#include "snac.h"
diff --git a/html.c b/html.c
index 777875c..584059b 100644
--- a/html.c
+++ b/html.c
@@ -15,6 +15,7 @@
#include "xs_unicode.h"
#include "xs_url.h"
#include "xs_random.h"
+#include "xs_http.h"
#include "snac.h"
diff --git a/http.c b/http.c
index 611de4f..f0b1314 100644
--- a/http.c
+++ b/http.c
@@ -7,6 +7,7 @@
#include "xs_curl.h"
#include "xs_time.h"
#include "xs_json.h"
+#include "xs_http.h"
#include "snac.h"
diff --git a/httpd.c b/httpd.c
index de76776..254d0e5 100644
--- a/httpd.c
+++ b/httpd.c
@@ -6,6 +6,7 @@
#include "xs_json.h"
#include "xs_socket.h"
#include "xs_unix_socket.h"
+#include "xs_http.h"
#include "xs_httpd.h"
#include "xs_mime.h"
#include "xs_time.h"
@@ -650,7 +651,7 @@ void httpd_connection(FILE *f)
if (p_state->use_fcgi)
xs_fcgi_response(f, status, headers, body, b_size, fcgi_id);
else
- xs_httpd_response(f, status, http_status_text(status), headers, body, b_size);
+ xs_httpd_response(f, status, xs_http_status_text(status), headers, body, b_size);
fclose(f);
diff --git a/main.c b/main.c
index 46f88d2..6915bd0 100644
--- a/main.c
+++ b/main.c
@@ -8,6 +8,7 @@
#include "xs_openssl.h"
#include "xs_match.h"
#include "xs_random.h"
+#include "xs_http.h"
#include "snac.h"
diff --git a/mastoapi.c b/mastoapi.c
index c526307..2c111ca 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -16,6 +16,7 @@
#include "xs_mime.h"
#include "xs_match.h"
#include "xs_unicode.h"
+#include "xs_http.h"
#include "snac.h"
diff --git a/rss.c b/rss.c
index bb7b043..6e77205 100644
--- a/rss.c
+++ b/rss.c
@@ -9,6 +9,7 @@
#include "xs_curl.h"
#include "xs_openssl.h"
#include "xs_json.h"
+#include "xs_http.h"
#include "snac.h"
diff --git a/snac.c b/snac.c
index a35cd06..31f524f 100644
--- a/snac.c
+++ b/snac.c
@@ -14,6 +14,7 @@
#include "xs_socket.h"
#include "xs_unix_socket.h"
#include "xs_url.h"
+#include "xs_http.h"
#include "xs_httpd.h"
#include "xs_mime.h"
#include "xs_regex.h"
@@ -58,13 +59,6 @@ int mkdirx(const char *pathname)
}
-int valid_status(int status)
-/* is this HTTP status valid? */
-{
- return status >= 200 && status <= 299;
-}
-
-
xs_str *tid(int offset)
/* returns a time-based Id */
{
@@ -176,16 +170,3 @@ int check_password(const char *uid, const char *passwd, const char *hash)
return ret;
}
-
-
-const char *http_status_text(int status)
-/* translate status codes to canonical status texts */
-{
- switch (status) {
- case 599: return "Timeout";
-#define HTTP_STATUS(code, name, text) case HTTP_STATUS_ ## name: return #text;
-#include "http_codes.h"
-#undef HTTP_STATUS
- default: return "Unknown";
- }
-}
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;
int mkdirx(const char *pathname);
-int valid_status(int status);
+#define valid_status(status) xs_http_valid_status(status)
xs_str *tid(int offset);
double ftime(void);
@@ -464,14 +464,6 @@ void import_list_csv(snac *user, const char *fn);
void import_csv(snac *user);
int parse_port(const char *url, const char **errstr);
-typedef enum {
-#define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code,
-#include "http_codes.h"
-#undef HTTP_STATUS
-} http_status;
-
-const char *http_status_text(int status);
-
typedef struct {
double timestamp;
char *text;
diff --git a/utils.c b/utils.c
index 38dcc06..de6db79 100644
--- a/utils.c
+++ b/utils.c
@@ -10,6 +10,7 @@
#include "xs_glob.h"
#include "xs_curl.h"
#include "xs_regex.h"
+#include "xs_http.h"
#include "snac.h"
diff --git a/webfinger.c b/webfinger.c
index 46b7edb..12ec42c 100644
--- a/webfinger.c
+++ b/webfinger.c
@@ -5,6 +5,7 @@
#include "xs_json.h"
#include "xs_curl.h"
#include "xs_mime.h"
+#include "xs_http.h"
#include "snac.h"
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 @@
+/* copyright (c) 2022 - 2025 grunfink et al. / MIT license */
+
+#ifndef _XS_HTTP_H
+
+#define _XS_HTTP_H
+
+typedef enum {
+#define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code,
+#include "xs_http_codes.h"
+#undef HTTP_STATUS
+} http_status;
+
+
+int xs_http_valid_status(int status);
+const char *xs_http_status_text(int status);
+
+
+#ifdef XS_IMPLEMENTATION
+
+int xs_http_valid_status(int status)
+/* is this HTTP status valid? */
+{
+ return status >= 200 && status <= 299;
+}
+
+
+const char *xs_http_status_text(int status)
+/* translate status codes to canonical status texts */
+{
+ switch (status) {
+ case 599: return "Timeout";
+#define HTTP_STATUS(code, name, text) case HTTP_STATUS_ ## name: return #text;
+#include "xs_http_codes.h"
+#undef HTTP_STATUS
+ default: return "Unknown";
+ }
+}
+
+
+#endif /* XS_IMPLEMENTATION */
+
+#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