diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2023-10-02 16:30:25 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2023-10-02 18:10:11 +0300 |
commit | 1ba86164a201e2138fef78130688dabce8b6ceaf (patch) | |
tree | f6eb3aed1471daa08f627a432d75df3e0c9e8523 /contrib | |
parent | f5c2724a9f580a664299d8519bb5f615f980ac53 (diff) | |
download | libmicrohttpd-1ba86164a201e2138fef78130688dabce8b6ceaf.tar.gz libmicrohttpd-1ba86164a201e2138fef78130688dabce8b6ceaf.zip |
Updated helper scripts
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/gen_http_headers_insert.sh | 36 | ||||
-rwxr-xr-x | contrib/gen_http_methods_insert.sh | 85 | ||||
-rwxr-xr-x | contrib/gen_http_statuses_inserts.sh | 8 |
3 files changed, 100 insertions, 29 deletions
diff --git a/contrib/gen_http_headers_insert.sh b/contrib/gen_http_headers_insert.sh index d373045e..26e0bcde 100755 --- a/contrib/gen_http_headers_insert.sh +++ b/contrib/gen_http_headers_insert.sh | |||
@@ -15,7 +15,7 @@ wget -nv https://www.iana.org/assignments/http-fields/field-names.csv -O perm-he | |||
15 | echo Generating... | 15 | echo Generating... |
16 | echo '/** | 16 | echo '/** |
17 | * @defgroup headers HTTP headers | 17 | * @defgroup headers HTTP headers |
18 | * These are the standard headers found in HTTP requests and responses. | 18 | * The standard headers found in HTTP requests and responses. |
19 | * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml | 19 | * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml |
20 | * Registry export date: '"$(date -u +%Y-%m-%d)"' | 20 | * Registry export date: '"$(date -u +%Y-%m-%d)"' |
21 | * @{ | 21 | * @{ |
@@ -29,17 +29,17 @@ FNR > 1 { | |||
29 | status = $3 | 29 | status = $3 |
30 | ref = $4 | 30 | ref = $4 |
31 | comment = $5 | 31 | comment = $5 |
32 | if ("RFC-ietf-httpbis" == substr(ref, 1, 16)) | 32 | if(ref ~ /^RFC911[0-2]/ && status != "obsoleted") |
33 | { | 33 | { |
34 | gsub(/\]\[/, "; ", ref) | 34 | gsub(/\]\[/, "; ", ref) |
35 | if (length(status) == 0) | 35 | if(length(status) == 0) |
36 | { status = "No category" } | 36 | { status = "No category" } |
37 | else | 37 | else |
38 | { sub(/^./, toupper(substr(status, 1, 1)), status) } | 38 | { sub(/^./, toupper(substr(status, 1, 1)), status) } |
39 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) | 39 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) |
40 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) | 40 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) |
41 | printf ("/* %-14.14s %s */\n", status ".", ref) | 41 | printf("/* %-14.14s %s */\n", status ".", ref) |
42 | printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) | 42 | printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) |
43 | } | 43 | } |
44 | }' perm-headers.csv >> header_insert_headers.h && \ | 44 | }' perm-headers.csv >> header_insert_headers.h && \ |
45 | echo ' | 45 | echo ' |
@@ -51,14 +51,14 @@ FNR > 1 { | |||
51 | status = $3 | 51 | status = $3 |
52 | ref = $4 | 52 | ref = $4 |
53 | comment = $5 | 53 | comment = $5 |
54 | if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && status == "permanent") | 54 | if(ref !~ /^RFC911[0-2]/ && status == "permanent") |
55 | { | 55 | { |
56 | gsub(/\]\[/, "; ", ref) | 56 | gsub(/\]\[/, "; ", ref) |
57 | sub(/^./, toupper(substr(status, 1, 1)), status) | 57 | sub(/^./, toupper(substr(status, 1, 1)), status) |
58 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) | 58 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) |
59 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) | 59 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) |
60 | printf ("/* %-14.14s %s */\n", status ".", ref) | 60 | printf("/* %-14.14s %s */\n", status ".", ref) |
61 | printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) | 61 | printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) |
62 | } | 62 | } |
63 | }' perm-headers.csv >> header_insert_headers.h && \ | 63 | }' perm-headers.csv >> header_insert_headers.h && \ |
64 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} | 64 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} |
@@ -68,7 +68,7 @@ FNR > 1 { | |||
68 | status = $3 | 68 | status = $3 |
69 | ref = $4 | 69 | ref = $4 |
70 | comment = $5 | 70 | comment = $5 |
71 | if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && status == "provisional") | 71 | if(ref !~ /^RFC911[0-2]/ && status == "provisional") |
72 | { | 72 | { |
73 | gsub(/\]\[/, "; ", ref) | 73 | gsub(/\]\[/, "; ", ref) |
74 | sub(/^./, toupper(substr(status, 1, 1)), status) | 74 | sub(/^./, toupper(substr(status, 1, 1)), status) |
@@ -85,14 +85,14 @@ FNR > 1 { | |||
85 | status = $3 | 85 | status = $3 |
86 | ref = $4 | 86 | ref = $4 |
87 | comment = $5 | 87 | comment = $5 |
88 | if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && length(status) == 0) | 88 | if(ref !~ /^RFC911[0-2]/ && status != "obsoleted" && status != "permanent" && status != "provisional" && status != "deprecated") |
89 | { | 89 | { |
90 | gsub(/\]\[/, "; ", ref) | 90 | gsub(/\]\[/, "; ", ref) |
91 | status = "No category" | 91 | status = "No category" |
92 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) | 92 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) |
93 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) | 93 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) |
94 | printf ("/* %-14.14s %s */\n", status ".", ref) | 94 | printf("/* %-14.14s %s */\n", status ".", ref) |
95 | printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) | 95 | printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) |
96 | } | 96 | } |
97 | }' perm-headers.csv >> header_insert_headers.h && \ | 97 | }' perm-headers.csv >> header_insert_headers.h && \ |
98 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} | 98 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} |
@@ -102,14 +102,14 @@ FNR > 1 { | |||
102 | status = $3 | 102 | status = $3 |
103 | ref = $4 | 103 | ref = $4 |
104 | comment = $5 | 104 | comment = $5 |
105 | if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && status == "deprecated") | 105 | if(ref !~ /^RFC911[0-2]/ && status == "deprecated") |
106 | { | 106 | { |
107 | gsub(/\]\[/, "; ", ref) | 107 | gsub(/\]\[/, "; ", ref) |
108 | sub(/^./, toupper(substr(status, 1, 1)), status) | 108 | sub(/^./, toupper(substr(status, 1, 1)), status) |
109 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) | 109 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) |
110 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) | 110 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) |
111 | printf ("/* %-14.14s %s */\n", status ".", ref) | 111 | printf("/* %-14.14s %s */\n", status ".", ref) |
112 | printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) | 112 | printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) |
113 | } | 113 | } |
114 | }' perm-headers.csv >> header_insert_headers.h && \ | 114 | }' perm-headers.csv >> header_insert_headers.h && \ |
115 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} | 115 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} |
@@ -119,14 +119,14 @@ FNR > 1 { | |||
119 | status = $3 | 119 | status = $3 |
120 | ref = $4 | 120 | ref = $4 |
121 | comment = $5 | 121 | comment = $5 |
122 | if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && status == "obsoleted") | 122 | if (status == "obsoleted") |
123 | { | 123 | { |
124 | gsub(/\]\[/, "; ", ref) | 124 | gsub(/\]\[/, "; ", ref) |
125 | sub(/^./, toupper(substr(status, 1, 1)), status) | 125 | sub(/^./, toupper(substr(status, 1, 1)), status) |
126 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) | 126 | field_name = gensub(/\*/, "ASTERISK", "g", field_name) |
127 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) | 127 | field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name) |
128 | printf ("/* %-14.14s %s */\n", status ".", ref) | 128 | printf("/* %-14.14s %s */\n", status ".", ref) |
129 | printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) | 129 | printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1) |
130 | } | 130 | } |
131 | }' perm-headers.csv >> header_insert_headers.h && \ | 131 | }' perm-headers.csv >> header_insert_headers.h && \ |
132 | echo OK && \ | 132 | echo OK && \ |
diff --git a/contrib/gen_http_methods_insert.sh b/contrib/gen_http_methods_insert.sh index 65076081..49e25fef 100755 --- a/contrib/gen_http_methods_insert.sh +++ b/contrib/gen_http_methods_insert.sh | |||
@@ -16,17 +16,71 @@ echo Generating... | |||
16 | echo '/** | 16 | echo '/** |
17 | * @defgroup methods HTTP methods | 17 | * @defgroup methods HTTP methods |
18 | * HTTP methods (as strings). | 18 | * HTTP methods (as strings). |
19 | * See: http://www.iana.org/assignments/http-methods/http-methods.xml | 19 | * See: https://www.iana.org/assignments/http-methods/http-methods.xml |
20 | * Registry export date: '"$(date -u +%Y-%m-%d)"' | 20 | * Registry export date: '"$(date -u +%Y-%m-%d)"' |
21 | * @{ | 21 | * @{ |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* Main HTTP methods. */' > header_insert_methods.h && \ | 24 | /* Main HTTP methods. */' > header_insert_methods.h && \ |
25 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} | 25 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} |
26 | function strnumcmp(s1, s2, n1, n2, a1, a2) | ||
27 | { | ||
28 | n1 = length(s1) | ||
29 | n2 = length(s2) | ||
30 | if (0 == n1 && 0 == n2) | ||
31 | return 0 | ||
32 | if (0 == n1 && 0 < n2) | ||
33 | return -1 | ||
34 | if (0 < n1 && 0 == n2) | ||
35 | return 1 | ||
36 | n1 = match(s1, /^[^0-9]+/, a1) | ||
37 | n2 = match(s2, /^[^0-9]+/, a2) | ||
38 | if (0 != n1) | ||
39 | { | ||
40 | if (0 == n2) | ||
41 | return 1 | ||
42 | if ((a1[0] "") < (a2[0] "")) | ||
43 | return -1 | ||
44 | if ((a1[0] "") > (a2[0] "")) | ||
45 | return 1 | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | if (0 != n2) | ||
50 | return -1 | ||
51 | } | ||
52 | s1 = substr(s1, length(a1[0]) + 1) | ||
53 | s2 = substr(s2, length(a2[0]) + 1) | ||
54 | n1 = match(s1, /^[0-9]+/, a1) | ||
55 | n2 = match(s2, /^[0-9]+/, a2) | ||
56 | if (0 != n1) | ||
57 | { | ||
58 | if (0 == n2) | ||
59 | return 1 | ||
60 | if ((a1[0] + 0) < (a2[0] + 0)) | ||
61 | return -1 | ||
62 | if ((a1[0] + 0) > (a2[0] + 0)) | ||
63 | return 1 | ||
64 | } | ||
65 | else | ||
66 | { | ||
67 | if (0 != n2) | ||
68 | return -1 | ||
69 | } | ||
70 | return strnumcmp(substr(s1, length(a1[0]) + 1), substr(s2, length(a2[0]) + 1)) | ||
71 | } | ||
72 | |||
73 | function sort_indices(i1, v1, i2, v2) | ||
74 | { | ||
75 | return strnumcmp(gensub(/[^0-9A-Za-z]+/, " ", "g", i1), gensub(/[^0-9A-Za-z]+/, " ", "g", i2)) | ||
76 | } | ||
77 | |||
26 | FNR > 1 { | 78 | FNR > 1 { |
27 | gsub(/^\[|^"\[|\]"$|\]$/, "", $4) | 79 | mthd_m = $1 |
28 | gsub(/\]\[/, "; ", $4) | 80 | reference_m = $4 |
29 | if (substr($4, 1, 26) == "RFC-ietf-httpbis-semantics") { | 81 | gsub(/^\[|^"\[|\]"$|\]$/, "", reference_m) |
82 | gsub(/\]\[/, "; ", reference_m) | ||
83 | if (reference_m ~ /^RFC911[0-2]/ && mthd_m != "*") { | ||
30 | if ($2 == "yes") | 84 | if ($2 == "yes") |
31 | { safe_m = "Safe. " } | 85 | { safe_m = "Safe. " } |
32 | else | 86 | else |
@@ -35,19 +89,27 @@ FNR > 1 { | |||
35 | { indem_m = "Idempotent. " } | 89 | { indem_m = "Idempotent. " } |
36 | else | 90 | else |
37 | { indem_m = "Not idempotent." } | 91 | { indem_m = "Not idempotent." } |
38 | print "/* " safe_m " " indem_m " " $4 ". */" | 92 | idx_str = gensub(/[^0-9A-Za-z]+/, " ", "g", reference_m) |
39 | mthd = gensub(/\*/, "ASTERISK", "g", $1) | 93 | main_methods[idx_str] = sprintf ("%s\n", "/* " safe_m " " indem_m " " reference_m ". */") |
40 | mthd = gensub(/[^a-zA-Z0-9_]/, "_", "g", mthd) | 94 | mthd_tkn = gensub(/\*/, "ASTERISK", "g", mthd_m) |
41 | printf ("%-32s \"%s\"\n", "#define MHD_HTTP_METHOD_" toupper(mthd), $1) | 95 | gsub(/[^a-zA-Z0-9_]/, "_", mthd_tkn) |
96 | main_methods[idx_str] = (main_methods[idx_str] sprintf ("%-32s \"%s\"\n", "#define MHD_HTTP_METHOD_" toupper(mthd_tkn), mthd_m)) | ||
42 | } | 97 | } |
43 | }' methods.csv >> header_insert_methods.h && \ | 98 | } |
99 | |||
100 | END { | ||
101 | n = asort(main_methods, main_methods, "sort_indices") | ||
102 | for (i = 1; i <= n; i++) | ||
103 | printf("%s", main_methods[i]) | ||
104 | } | ||
105 | ' methods.csv >> header_insert_methods.h && \ | ||
44 | echo ' | 106 | echo ' |
45 | /* Additional HTTP methods. */' >> header_insert_methods.h && \ | 107 | /* Additional HTTP methods. */' >> header_insert_methods.h && \ |
46 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} | 108 | gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} |
47 | FNR > 1 { | 109 | FNR > 1 { |
48 | gsub(/^\[|^"\[|\]"$|\]$/, "", $4) | 110 | gsub(/^\[|^"\[|\]"$|\]$/, "", $4) |
49 | gsub(/\]\[/, "; ", $4) | 111 | gsub(/\]\[/, "; ", $4) |
50 | if (substr($4, 1, 26) != "RFC-ietf-httpbis-semantics") { | 112 | if ($4 !~ /^RFC911[0-2]/ || $1 == "*") { |
51 | if ($2 == "yes") | 113 | if ($2 == "yes") |
52 | { safe_m = "Safe. " } | 114 | { safe_m = "Safe. " } |
53 | else | 115 | else |
@@ -62,5 +124,8 @@ FNR > 1 { | |||
62 | printf ("%-38s \"%s\"\n", "#define MHD_HTTP_METHOD_" toupper(mthd), $1) | 124 | printf ("%-38s \"%s\"\n", "#define MHD_HTTP_METHOD_" toupper(mthd), $1) |
63 | } | 125 | } |
64 | }' methods.csv >> header_insert_methods.h && \ | 126 | }' methods.csv >> header_insert_methods.h && \ |
127 | echo ' | ||
128 | /** @} */ /* end of group methods */ | ||
129 | ' >> header_insert_methods.h && | ||
65 | echo OK && \ | 130 | echo OK && \ |
66 | rm methods.csv || exit | 131 | rm methods.csv || exit |
diff --git a/contrib/gen_http_statuses_inserts.sh b/contrib/gen_http_statuses_inserts.sh index a4f2bb01..9b10e810 100755 --- a/contrib/gen_http_statuses_inserts.sh +++ b/contrib/gen_http_statuses_inserts.sh | |||
@@ -25,6 +25,9 @@ gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"} | |||
25 | FNR > 1 { | 25 | FNR > 1 { |
26 | gsub(/^\[|^"\[|\]"$|\]$/, "", $3) | 26 | gsub(/^\[|^"\[|\]"$|\]$/, "", $3) |
27 | gsub(/\]\[/, "; ", $3) | 27 | gsub(/\]\[/, "; ", $3) |
28 | if (sub(/ *\(OBSOLETED\)/, "", $2)) { | ||
29 | $3 = "(OBSOLETED) " $3 | ||
30 | } | ||
28 | if ($1 == 306) { | 31 | if ($1 == 306) { |
29 | $2 = "Switch Proxy" | 32 | $2 = "Switch Proxy" |
30 | $3 = "Not used! " $3 | 33 | $3 = "Not used! " $3 |
@@ -68,12 +71,15 @@ FNR > 1 { | |||
68 | num = $1 | 71 | num = $1 |
69 | reason = $2 | 72 | reason = $2 |
70 | desc = $3 | 73 | desc = $3 |
74 | if (sub(/ *\(OBSOLETED\)/, "", reason)) { | ||
75 | desc = "(OBSOLETED) " desc | ||
76 | } | ||
71 | if (num % 100 == 0) { | 77 | if (num % 100 == 0) { |
72 | if (num != 100) { | 78 | if (num != 100) { |
73 | printf (" /* %s */ %-36s /* %s */\n};\n\n", prev_num, "_MHD_S_STR_W_LEN (\""prev_reason"\")", prev_desc) | 79 | printf (" /* %s */ %-36s /* %s */\n};\n\n", prev_num, "_MHD_S_STR_W_LEN (\""prev_reason"\")", prev_desc) |
74 | } | 80 | } |
75 | prev_num = num; | 81 | prev_num = num; |
76 | print "static const struct _MHD_str_w_len " hundreds[$1/100] "_hundred[] = {" | 82 | print "static const struct _MHD_cstr_w_len " hundreds[$1/100] "_hundred[] = {" |
77 | } | 83 | } |
78 | if (num == 306) { | 84 | if (num == 306) { |
79 | reason = "Switch Proxy" | 85 | reason = "Switch Proxy" |