aboutsummaryrefslogtreecommitdiff
path: root/contrib/gen_http_headers_insert.sh
blob: d373045e17b54855fa3ca890c92cf8117c69903b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash

#
#   Generate header insert for HTTP headers
#

#   Copyright (c) 2015-2021 Karlson2k (Evgeny Grin) <k2k@yandex.ru>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved. This file is offered as-is, without any
#   warranty.

wget -nv https://www.iana.org/assignments/http-fields/field-names.csv -O perm-headers.csv || exit
echo Generating...
echo '/**
 * @defgroup headers HTTP headers
 * These are the standard headers found in HTTP requests and responses.
 * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml
 * Registry export date: '"$(date -u +%Y-%m-%d)"'
 * @{
 */

/* Main HTTP headers. */' > header_insert_headers.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
FNR > 1 {
    gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
    field_name = $1
    status = $3
    ref = $4
    comment = $5
    if ("RFC-ietf-httpbis" == substr(ref, 1, 16))
    {
      gsub(/\]\[/, "; ", ref)
      if (length(status) == 0)
      { status = "No category" }
      else
      { sub(/^./, toupper(substr(status, 1, 1)), status) }
      field_name = gensub(/\*/, "ASTERISK", "g", field_name)
      field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
      printf ("/* %-14.14s %s */\n", status ".", ref)
      printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
    }
}' perm-headers.csv >> header_insert_headers.h && \
echo '
/* Additional HTTP headers. */' >> header_insert_headers.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
FNR > 1 {
    gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
    field_name = $1
    status = $3
    ref = $4
    comment = $5
    if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && status == "permanent")
    {
      gsub(/\]\[/, "; ", ref)
      sub(/^./, toupper(substr(status, 1, 1)), status)
      field_name = gensub(/\*/, "ASTERISK", "g", field_name)
      field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
      printf ("/* %-14.14s %s */\n", status ".", ref)
      printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
    }
}' perm-headers.csv >> header_insert_headers.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
FNR > 1 {
    gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
    field_name = $1
    status = $3
    ref = $4
    comment = $5
    if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && status == "provisional")
    {
      gsub(/\]\[/, "; ", ref)
      sub(/^./, toupper(substr(status, 1, 1)), status)
      field_name = gensub(/\*/, "ASTERISK", "g", field_name)
      field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
      printf ("/* %-14.14s %s */\n", status ".", ref)
      printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
    }
}' perm-headers.csv >> header_insert_headers.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
FNR > 1 {
    gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
    field_name = $1
    status = $3
    ref = $4
    comment = $5
    if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && length(status) == 0)
    {
      gsub(/\]\[/, "; ", ref)
      status = "No category"
      field_name = gensub(/\*/, "ASTERISK", "g", field_name)
      field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
      printf ("/* %-14.14s %s */\n", status ".", ref)
      printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
    }
}' perm-headers.csv >> header_insert_headers.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
FNR > 1 {
    gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
    field_name = $1
    status = $3
    ref = $4
    comment = $5
    if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && status == "deprecated")
    {
      gsub(/\]\[/, "; ", ref)
      sub(/^./, toupper(substr(status, 1, 1)), status)
      field_name = gensub(/\*/, "ASTERISK", "g", field_name)
      field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
      printf ("/* %-14.14s %s */\n", status ".", ref)
      printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
    }
}' perm-headers.csv >> header_insert_headers.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
FNR > 1 {
    gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
    field_name = $1
    status = $3
    ref = $4
    comment = $5
    if ("RFC-ietf-httpbis" != substr(ref, 1, 16) && status == "obsoleted")
    {
      gsub(/\]\[/, "; ", ref)
      sub(/^./, toupper(substr(status, 1, 1)), status)
      field_name = gensub(/\*/, "ASTERISK", "g", field_name)
      field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
      printf ("/* %-14.14s %s */\n", status ".", ref)
      printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
    }
}' perm-headers.csv >> header_insert_headers.h && \
echo OK && \
rm perm-headers.csv || exit