diff options
| author | grunfink <grunfink@comam.es> | 2025-10-13 13:07:06 +0200 |
|---|---|---|
| committer | grunfink <grunfink@comam.es> | 2025-10-13 13:07:06 +0200 |
| commit | 212284c792c86fca52e0172a4d097abc5bb45252 (patch) | |
| tree | 4fe9ebc3859eec9edb46388a606cb6d54898c64a | |
| parent | 4f0b97ecf6ee157c56aa4fba781a8b6b5ea36174 (diff) | |
xs_http.h: new file.
| -rw-r--r-- | Makefile | 37 | ||||
| -rw-r--r-- | Makefile.NetBSD | 37 | ||||
| -rw-r--r-- | activitypub.c | 3 | ||||
| -rw-r--r-- | data.c | 1 | ||||
| -rw-r--r-- | html.c | 1 | ||||
| -rw-r--r-- | http.c | 1 | ||||
| -rw-r--r-- | httpd.c | 3 | ||||
| -rw-r--r-- | main.c | 1 | ||||
| -rw-r--r-- | mastoapi.c | 1 | ||||
| -rw-r--r-- | rss.c | 1 | ||||
| -rw-r--r-- | snac.c | 21 | ||||
| -rw-r--r-- | snac.h | 10 | ||||
| -rw-r--r-- | utils.c | 1 | ||||
| -rw-r--r-- | webfinger.c | 1 | ||||
| -rw-r--r-- | xs_http.h | 42 | ||||
| -rw-r--r-- | xs_http_codes.h (renamed from http_codes.h) | 0 |
16 files changed, 94 insertions, 67 deletions
@@ -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)); } @@ -14,6 +14,7 @@ #include "xs_unicode.h" #include "xs_random.h" #include "xs_po.h" +#include "xs_http.h" #include "snac.h" @@ -15,6 +15,7 @@ #include "xs_unicode.h" #include "xs_url.h" #include "xs_random.h" +#include "xs_http.h" #include "snac.h" @@ -7,6 +7,7 @@ #include "xs_curl.h" #include "xs_time.h" #include "xs_json.h" +#include "xs_http.h" #include "snac.h" @@ -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); @@ -8,6 +8,7 @@ #include "xs_openssl.h" #include "xs_match.h" #include "xs_random.h" +#include "xs_http.h" #include "snac.h" @@ -16,6 +16,7 @@ #include "xs_mime.h" #include "xs_match.h" #include "xs_unicode.h" +#include "xs_http.h" #include "snac.h" @@ -9,6 +9,7 @@ #include "xs_curl.h" #include "xs_openssl.h" #include "xs_json.h" +#include "xs_http.h" #include "snac.h" @@ -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"; - } -} @@ -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; @@ -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 |