aboutsummaryrefslogtreecommitdiff
path: root/contrib/gen_http_headers_insert.sh
blob: 6fce2809a8a01e8e308103b460e256b3ce9f2378 (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
#!/bin/bash

#
#   Generate header insert for HTTP headers
#

#   Copyright (c) 2015-2019 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 http://www.iana.org/assignments/message-headers/perm-headers.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: http://www.iana.org/assignments/message-headers/message-headers.xml
 * Registry export date: '$(date -u +%Y-%m-%d)'
 * @{
 */

/* Main HTTP headers. */' > header_insert_headers.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
{
  if ($3 == "http") {
    gsub(/^\[|^"\[|\]"$|\]$/, "", $5)
    rfc_num = substr($5, 4, 4)
    if (rfc_num >= 7230 && rfc_num <= 7235)
    {
      gsub(/\]\[/, "; ", $5)
      if (length($4) == 0) 
      { $4 = "No category" }
      else
      { sub(/^./, toupper(substr($4, 1, 1)), $4) }
      print "/* " sprintf("%-14.14s", $4 ".") " " $5 " */"
      print "#define MHD_HTTP_HEADER_" toupper(gensub(/-/, "_", "g", $1)) " \""$1"\""
    }
  }
}' perm-headers.csv >> header_insert_headers.h && \
echo '
/* Additional HTTP headers. */' >> header_insert_headers.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
{
  if ($3 == "http") {
    gsub(/^\[|^"\[|\]"$|\]$/, "", $5)
    rfc_num = substr($5, 4, 4)
    if (!(rfc_num >= 7230 && rfc_num <= 7235))
    {
      gsub(/\]\[/, "; ", $5)
      if (length($4) == 0) 
      { $4 = "No category" }
      else
      { sub(/^./, toupper(substr($4, 1, 1)), $4) }
      print "/* " sprintf("%-14.14s", $4 ".") " " $5 " */"
      print "#define MHD_HTTP_HEADER_" toupper(gensub(/-/, "_", "g", $1)) " \""$1"\""
    }
  }
}' perm-headers.csv >> header_insert_headers.h && \
echo OK && \
rm perm-headers.csv || exit