gen_http_methods_insert.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. #
  3. # Generate header insert for HTTP methods
  4. #
  5. # Copyright (c) 2015-2019 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 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, 7) == "RFC7231") {
  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. print "#define MHD_HTTP_METHOD_" toupper(gensub(/-/, "_", "g", $1)) " \""$1"\""
  36. }
  37. }' methods.csv >> header_insert_methods.h && \
  38. echo '
  39. /* Additional HTTP methods. */' >> header_insert_methods.h && \
  40. gawk -e 'BEGIN {FPAT = "([^,]*)|(\"[^\"]+\")"}
  41. FNR > 1 {
  42. gsub(/^\[|^"\[|\]"$|\]$/, "", $4)
  43. gsub(/\]\[/, "; ", $4)
  44. if (substr($4, 1, 7) != "RFC7231") {
  45. if ($2 == "yes")
  46. { safe_m = "Safe. " }
  47. else
  48. { safe_m = "Not safe." }
  49. if ($3 == "yes")
  50. { indem_m = "Idempotent. " }
  51. else
  52. { indem_m = "Not idempotent." }
  53. print "/* " safe_m " " indem_m " " $4 ". */"
  54. print "#define MHD_HTTP_METHOD_" toupper(gensub(/-/, "_", "g", $1)) " \""$1"\""
  55. }
  56. }' methods.csv >> header_insert_methods.h && \
  57. echo OK && \
  58. rm methods.csv || exit