aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-06-09 11:43:53 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-06-09 12:14:30 +0300
commite5f188a4cb924508d49419a1fb7ca98b5740f423 (patch)
treec31fe8de1d8eb286a7401f50a1e9267d5bfe5b5a /contrib
parentbadb814e445fa6cb7060dbfb3591095797e05c83 (diff)
downloadlibmicrohttpd-e5f188a4cb924508d49419a1fb7ca98b5740f423.tar.gz
libmicrohttpd-e5f188a4cb924508d49419a1fb7ca98b5740f423.zip
contrib: implemented script for importing HTTP status codes
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/gen_http_statuses_inserts.sh85
1 files changed, 85 insertions, 0 deletions
diff --git a/contrib/gen_http_statuses_inserts.sh b/contrib/gen_http_statuses_inserts.sh
new file mode 100755
index 00000000..07c2075f
--- /dev/null
+++ b/contrib/gen_http_statuses_inserts.sh
@@ -0,0 +1,85 @@
1#!/bin/bash
2
3#
4# Generate code and header inserts for HTTP statues
5#
6
7# Copyright (c) 2019 Karlson2k (Evgeny Grin) <k2k@yandex.ru>
8#
9# Copying and distribution of this file, with or without modification, are
10# permitted in any medium without royalty provided the copyright notice
11# and this notice are preserved. This file is offered as-is, without any
12# warranty.
13
14wget -nv https://www.iana.org/assignments/http-status-codes/http-status-codes-1.csv -O http-status-codes-1.csv || exit
15echo Generating...
16echo "/**
17 * @defgroup httpcode HTTP response codes.
18 * These are the status codes defined for HTTP responses.
19 * See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
20 * Registry export date: $(date -u +%Y-%m-%d)
21 * @{
22 */
23" > header_insert_statuses.h && \
24gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
25FNR > 1 {
26 gsub(/^\[|^"\[|\]"$|\]$/, "", $3)
27 gsub(/\]\[/, "; ", $3)
28 if ($1 == 306) {
29 $2 = "Switch Proxy"
30 $3 = "Not used! " $3
31 }
32 if ($2 != "Unassigned") {
33 print "/* " $1 sprintf("%-24s", " \"" $2 "\". ") $3 ". */"
34 print "#define MHD_HTTP_" toupper(gensub(/[^A-Za-z0-0]/, "_", "g", $2)) " "$1""
35 } else {
36 print ""
37 }
38}' http-status-codes-1.csv >> header_insert_statuses.h && \
39echo '
40/* Not registered non-standard codes */
41/* 449 "Reply With". MS IIS extension. */
42#define MHD_HTTP_RETRY_WITH 449
43
44/* 450 "Blocked by Windows Parental Controls". MS extension. */
45#define MHD_HTTP_BLOCKED_BY_WINDOWS_PARENTAL_CONTROLS 450
46
47/* 509 "Bandwidth Limit Exceeded". Apache extension. */
48#define MHD_HTTP_BANDWIDTH_LIMIT_EXCEEDED 509
49' >> header_insert_statuses.h && \
50gawk -e 'BEGIN {
51 FPAT = "([^,]*)|(\"[^\"]+\")"
52 hundreds[1]="one"
53 hundreds[2]="two"
54 hundreds[3]="three"
55 hundreds[4]="four"
56 hundreds[5]="five"
57 hundreds[6]="six"
58 prev_num=0
59}
60FNR > 1 {
61 gsub(/^\[|^"\[|\]"$|\]$/, "", $3)
62 gsub(/\]\[/, "; ", $3)
63 if ($1 % 100 == 0) {
64 if ($1 != 100) { printf("\n};\n\n") }
65 prev_num=$1 - 1;
66 print "static const char *const " hundreds[$1/100] "_hundred[] = {"
67 }
68 if ($1 == 306) {
69 $2 = "Switch Proxy"
70 $3 = "Not used! " $3
71 }
72 if ($2 == "Unassigned") next
73 while(++prev_num != $1) {
74 if (prev_num == 449) {reason="Reply With"; desc="MS IIS extension";}
75 else if (prev_num == 450) {reason="Blocked by Windows Parental Controls"; desc="MS extension";}
76 else if (prev_num == 509) {reason="Bandwidth Limit Exceeded"; desc="Apache extension";}
77 else {reason="Unknown"; desc="Not used";}
78 printf (",\n /* %s */ %-24s /* %s */", prev_num, "\"" reason "\"", desc)
79 }
80 if ($1 % 100 != 0) { print "," }
81 printf (" /* %s */ %-24s /* %s */", $1, "\""$2"\"", $3)
82}
83END {printf("\n};\n")}' http-status-codes-1.csv >> code_insert_statuses.c && \
84echo OK && \
85rm http-status-codes-1.csv || exit