gen_http_headers_insert.sh 4.7 KB

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