gen_http_methods_insert.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. #
  3. # Generate header insert for HTTP methods
  4. #
  5. # Copyright (c) 2015-2021 Karlson2k (Evgeny Grin) <[email protected]>
  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 http://www.iana.org/assignments/http-methods/methods.csv -O methods.csv || exit
  12. echo Generating...
  13. echo '/**
  14. * @defgroup methods HTTP methods
  15. * HTTP methods (as strings).
  16. * See: http://www.iana.org/assignments/http-methods/http-methods.xml
  17. * Registry export date: '"$(date -u +%Y-%m-%d)"'
  18. * @{
  19. */
  20. /* Main HTTP methods. */' > header_insert_methods.h && \
  21. gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
  22. FNR > 1 {
  23. gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
  24. gsub(/\]\[/, "; ", $4)
  25. if (substr($4, 1, 26) == "RFC-ietf-httpbis-semantics") {
  26. if ($2 == "yes")
  27. { safe_m = "Safe. " }
  28. else
  29. { safe_m = "Not safe." }
  30. if ($3 == "yes")
  31. { indem_m = "Idempotent. " }
  32. else
  33. { indem_m = "Not idempotent." }
  34. print "/* " safe_m " " indem_m " " $4 ". */"
  35. mthd = gensub(/\*/, "ASTERISK", "g", $1)
  36. mthd = gensub(/[^a-zA-Z0-9_]/, "_", "g", mthd)
  37. printf ("%-32s \"%s\"\n", "#define MHD_HTTP_METHOD_" toupper(mthd), $1)
  38. }
  39. }' methods.csv >> header_insert_methods.h && \
  40. echo '
  41. /* Additional HTTP methods. */' >> header_insert_methods.h && \
  42. gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
  43. FNR > 1 {
  44. gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
  45. gsub(/\]\[/, "; ", $4)
  46. if (substr($4, 1, 26) != "RFC-ietf-httpbis-semantics") {
  47. if ($2 == "yes")
  48. { safe_m = "Safe. " }
  49. else
  50. { safe_m = "Not safe." }
  51. if ($3 == "yes")
  52. { indem_m = "Idempotent. " }
  53. else
  54. { indem_m = "Not idempotent." }
  55. print "/* " safe_m " " indem_m " " $4 ". */"
  56. mthd = gensub(/\*/, "ASTERISK", "g", $1)
  57. mthd = gensub(/[^a-zA-Z0-9_]/, "_", "g", mthd)
  58. printf ("%-38s \"%s\"\n", "#define MHD_HTTP_METHOD_" toupper(mthd), $1)
  59. }
  60. }' methods.csv >> header_insert_methods.h && \
  61. echo OK && \
  62. rm methods.csv || exit