libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

gen_http_headers_insert.sh (4751B)


      1 #!/bin/bash
      2 
      3 #
      4 #   Generate header insert for HTTP headers
      5 #
      6 
      7 #   Copyright (c) 2015-2021 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 
     14 wget -nv https://www.iana.org/assignments/http-fields/field-names.csv -O perm-headers.csv || exit
     15 echo Generating...
     16 echo '/**
     17  * @defgroup headers HTTP headers
     18  * The standard headers found in HTTP requests and responses.
     19  * See: https://www.iana.org/assignments/http-fields/http-fields.xhtml
     20  * Registry export date: '"$(date -u +%Y-%m-%d)"'
     21  * @{
     22  */
     23 
     24 /* Main HTTP headers. */' > header_insert_headers.h && \
     25 gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
     26 FNR > 1 {
     27     gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
     28     field_name = $1
     29     status = $3
     30     ref = $4
     31     comment = $5
     32     if(ref ~ /^RFC911[0-2]/ && status != "obsoleted")
     33     {
     34       gsub(/\]\[/, "; ", ref)
     35       if(length(status) == 0)
     36       { status = "No category" }
     37       else
     38       { sub(/^./, toupper(substr(status, 1, 1)), status) }
     39       field_name = gensub(/\*/, "ASTERISK", "g", field_name)
     40       field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
     41       printf("/* %-14.14s %s */\n", status ".", ref)
     42       printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
     43     }
     44 }' perm-headers.csv >> header_insert_headers.h && \
     45 echo '
     46 /* Additional HTTP headers. */' >> header_insert_headers.h && \
     47 gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
     48 FNR > 1 {
     49     gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
     50     field_name = $1
     51     status = $3
     52     ref = $4
     53     comment = $5
     54     if(ref !~ /^RFC911[0-2]/ && status == "permanent")
     55     {
     56       gsub(/\]\[/, "; ", ref)
     57       sub(/^./, toupper(substr(status, 1, 1)), status)
     58       field_name = gensub(/\*/, "ASTERISK", "g", field_name)
     59       field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
     60       printf("/* %-14.14s %s */\n", status ".", ref)
     61       printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
     62     }
     63 }' perm-headers.csv >> header_insert_headers.h && \
     64 gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
     65 FNR > 1 {
     66     gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
     67     field_name = $1
     68     status = $3
     69     ref = $4
     70     comment = $5
     71     if(ref !~ /^RFC911[0-2]/ && status == "provisional")
     72     {
     73       gsub(/\]\[/, "; ", ref)
     74       sub(/^./, toupper(substr(status, 1, 1)), status)
     75       field_name = gensub(/\*/, "ASTERISK", "g", field_name)
     76       field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
     77       printf ("/* %-14.14s %s */\n", status ".", ref)
     78       printf ("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
     79     }
     80 }' perm-headers.csv >> header_insert_headers.h && \
     81 gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
     82 FNR > 1 {
     83     gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
     84     field_name = $1
     85     status = $3
     86     ref = $4
     87     comment = $5
     88     if(ref !~ /^RFC911[0-2]/ && status != "obsoleted" && status != "permanent" && status != "provisional" && status != "deprecated")
     89     {
     90       gsub(/\]\[/, "; ", ref)
     91       status = "No category"
     92       field_name = gensub(/\*/, "ASTERISK", "g", field_name)
     93       field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
     94       printf("/* %-14.14s %s */\n", status ".", ref)
     95       printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
     96     }
     97 }' perm-headers.csv >> header_insert_headers.h && \
     98 gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
     99 FNR > 1 {
    100     gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
    101     field_name = $1
    102     status = $3
    103     ref = $4
    104     comment = $5
    105     if(ref !~ /^RFC911[0-2]/ && status == "deprecated")
    106     {
    107       gsub(/\]\[/, "; ", ref)
    108       sub(/^./, toupper(substr(status, 1, 1)), status)
    109       field_name = gensub(/\*/, "ASTERISK", "g", field_name)
    110       field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
    111       printf("/* %-14.14s %s */\n", status ".", ref)
    112       printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
    113     }
    114 }' perm-headers.csv >> header_insert_headers.h && \
    115 gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
    116 FNR > 1 {
    117     gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
    118     field_name = $1
    119     status = $3
    120     ref = $4
    121     comment = $5
    122     if (status == "obsoleted")
    123     {
    124       gsub(/\]\[/, "; ", ref)
    125       sub(/^./, toupper(substr(status, 1, 1)), status)
    126       field_name = gensub(/\*/, "ASTERISK", "g", field_name)
    127       field_name = gensub(/[^a-zA-Z0-9_]/, "_", "g", field_name)
    128       printf("/* %-14.14s %s */\n", status ".", ref)
    129       printf("#define MHD_HTTP_HEADER_%-12s \"%s\"\n", toupper(field_name), $1)
    130     }
    131 }' perm-headers.csv >> header_insert_headers.h && \
    132 echo OK && \
    133 rm perm-headers.csv || exit