diff options
| -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: | |||
| 48 | 48 | ||
| 49 | activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \ | 49 | activitypub.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 |
| 52 | data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \ | 52 | data.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 |
| 55 | format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \ | 55 | format.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 |
| 57 | html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \ | 57 | html.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 |
| 60 | http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \ | 60 | http.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 |
| 62 | httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \ | 62 | httpd.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 |
| 65 | main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \ | 65 | main.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 |
| 67 | mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ | 67 | mastoapi.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 |
| 70 | rss.o: rss.c xs.h xs_html.h xs_regex.h xs_time.h xs_match.h xs_curl.h \ | 70 | rss.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 |
| 72 | sandbox.o: sandbox.c xs.h snac.h http_codes.h | 72 | sandbox.o: sandbox.c xs.h snac.h |
| 73 | snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \ | 73 | snac.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 |
| 78 | upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h | 78 | upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h |
| 79 | utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ | 79 | utils.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 \ |
| 81 | webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h \ | 81 | snac.h |
| 82 | http_codes.h | 82 | webfinger.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 | ||
| 38 | activitypub.o: activitypub.c xs.h xs_json.h xs_curl.h xs_mime.h \ | 38 | activitypub.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 |
| 41 | data.o: data.c xs.h xs_hex.h xs_io.h xs_json.h xs_openssl.h xs_glob.h \ | 41 | data.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 |
| 44 | format.o: format.c xs.h xs_regex.h xs_mime.h xs_html.h xs_json.h \ | 44 | format.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 |
| 46 | html.o: html.c xs.h xs_io.h xs_json.h xs_regex.h xs_set.h xs_openssl.h \ | 46 | html.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 |
| 49 | http.o: http.c xs.h xs_io.h xs_openssl.h xs_curl.h xs_time.h xs_json.h \ | 49 | http.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 |
| 51 | httpd.o: httpd.c xs.h xs_io.h xs_json.h xs_socket.h xs_unix_socket.h \ | 51 | httpd.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 |
| 54 | main.o: main.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h xs_match.h \ | 54 | main.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 |
| 56 | mastoapi.o: mastoapi.c xs.h xs_hex.h xs_openssl.h xs_json.h xs_io.h \ | 56 | mastoapi.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 |
| 59 | rss.o: rss.c xs.h xs_html.h xs_regex.h xs_time.h xs_match.h xs_curl.h \ | 59 | rss.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 |
| 61 | sandbox.o: sandbox.c xs.h snac.h http_codes.h | 61 | sandbox.o: sandbox.c xs.h snac.h |
| 62 | snac.o: snac.c xs.h xs_hex.h xs_io.h xs_unicode_tbl.h xs_unicode.h \ | 62 | snac.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 |
| 67 | upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h http_codes.h | 67 | upgrade.o: upgrade.c xs.h xs_io.h xs_json.h xs_glob.h snac.h |
| 68 | utils.o: utils.c xs.h xs_io.h xs_json.h xs_time.h xs_openssl.h \ | 68 | utils.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 \ |
| 70 | webfinger.o: webfinger.c xs.h xs_json.h xs_curl.h xs_mime.h snac.h \ | 70 | snac.h |
| 71 | http_codes.h | 71 | webfinger.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 | ||
| 3211 | xs_str *str_status(int status) | 3212 | xs_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 | ||
| @@ -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 | ||
| @@ -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 | ||
| @@ -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 | ||
| @@ -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 | ||
| @@ -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 | ||
| @@ -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 | ||
| @@ -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 | ||
| @@ -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 | ||
| 61 | int valid_status(int status) | ||
| 62 | /* is this HTTP status valid? */ | ||
| 63 | { | ||
| 64 | return status >= 200 && status <= 299; | ||
| 65 | } | ||
| 66 | |||
| 67 | |||
| 68 | xs_str *tid(int offset) | 62 | xs_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 | |||
| 181 | const 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 | } | ||
| @@ -44,7 +44,7 @@ extern int dbglevel; | |||
| 44 | 44 | ||
| 45 | int mkdirx(const char *pathname); | 45 | int mkdirx(const char *pathname); |
| 46 | 46 | ||
| 47 | int valid_status(int status); | 47 | #define valid_status(status) xs_http_valid_status(status) |
| 48 | xs_str *tid(int offset); | 48 | xs_str *tid(int offset); |
| 49 | double ftime(void); | 49 | double ftime(void); |
| 50 | 50 | ||
| @@ -464,14 +464,6 @@ void import_list_csv(snac *user, const char *fn); | |||
| 464 | void import_csv(snac *user); | 464 | void import_csv(snac *user); |
| 465 | int parse_port(const char *url, const char **errstr); | 465 | int parse_port(const char *url, const char **errstr); |
| 466 | 466 | ||
| 467 | typedef 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 | |||
| 473 | const char *http_status_text(int status); | ||
| 474 | |||
| 475 | typedef struct { | 467 | typedef struct { |
| 476 | double timestamp; | 468 | double timestamp; |
| 477 | char *text; | 469 | char *text; |
| @@ -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 | |||
| 7 | typedef 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 | |||
| 14 | int xs_http_valid_status(int status); | ||
| 15 | const char *xs_http_status_text(int status); | ||
| 16 | |||
| 17 | |||
| 18 | #ifdef XS_IMPLEMENTATION | ||
| 19 | |||
| 20 | int xs_http_valid_status(int status) | ||
| 21 | /* is this HTTP status valid? */ | ||
| 22 | { | ||
| 23 | return status >= 200 && status <= 299; | ||
| 24 | } | ||
| 25 | |||
| 26 | |||
| 27 | const 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 | |||