aboutsummaryrefslogtreecommitdiff
path: root/contrib/gen_http_methods_insert.sh
blob: 6507608164bc215a55885df6e6e6391791056b92 (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
#!/bin/bash

#
#   Generate header insert for HTTP methods
#

#   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 http://www.iana.org/assignments/http-methods/methods.csv -O methods.csv || exit
echo Generating...
echo '/**
 * @defgroup methods HTTP methods
 * HTTP methods (as strings).
 * See: http://www.iana.org/assignments/http-methods/http-methods.xml
 * Registry export date: '"$(date -u +%Y-%m-%d)"'
 * @{
 */

/* Main HTTP methods. */' > header_insert_methods.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
FNR > 1 {
  gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
  gsub(/\]\[/, "; ", $4)
  if (substr($4, 1, 26) == "RFC-ietf-httpbis-semantics") {
    if ($2 == "yes")
    { safe_m = "Safe.    " }
    else
    { safe_m = "Not safe." }
    if ($3 == "yes")
    { indem_m = "Idempotent.    " }
    else
    { indem_m = "Not idempotent." }
    print "/* " safe_m " " indem_m " " $4 ". */"
    mthd = gensub(/\*/, "ASTERISK", "g", $1)
    mthd = gensub(/[^a-zA-Z0-9_]/, "_", "g", mthd)
    printf ("%-32s \"%s\"\n", "#define MHD_HTTP_METHOD_" toupper(mthd), $1)
  }
}' methods.csv >> header_insert_methods.h && \
echo '
/* Additional HTTP methods. */' >> header_insert_methods.h && \
gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
FNR > 1 {
  gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
  gsub(/\]\[/, "; ", $4)
  if (substr($4, 1, 26) != "RFC-ietf-httpbis-semantics") {
    if ($2 == "yes")
    { safe_m = "Safe.    " }
    else
    { safe_m = "Not safe." }
    if ($3 == "yes")
    { indem_m = "Idempotent.    " }
    else
    { indem_m = "Not idempotent." }
    print "/* " safe_m " " indem_m " " $4 ". */"
    mthd = gensub(/\*/, "ASTERISK", "g", $1)
    mthd = gensub(/[^a-zA-Z0-9_]/, "_", "g", mthd)
    printf ("%-38s \"%s\"\n", "#define MHD_HTTP_METHOD_" toupper(mthd), $1)
  }
}' methods.csv >> header_insert_methods.h && \
echo OK && \
rm methods.csv || exit