thttp_machine_utils.rl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2010-2015 Mamadou Diop.
  3. *
  4. * This file is part of Open Source Doubango Framework.
  5. *
  6. * DOUBANGO is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DOUBANGO is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DOUBANGO.
  18. *
  19. */
  20. /**@file thttp_machine_utils.rl
  21. * @brief Ragel file.
  22. *
  23. */
  24. %%{
  25. machine thttp_machine_utils;
  26. OCTET = "0x"[0-9A-Fa-f]+;
  27. CHAR = 0x01..0x7f;
  28. VCHAR = 0x21..0x7e;
  29. ALPHA = 0x41..0x5a | 0x61..0x7a;
  30. DIGIT = 0x30..0x39;
  31. CTL = 0x00..0x1f | 0x7f;
  32. HTAB = "\t";
  33. LF = "\n";
  34. CR = "\r";
  35. SP = " ";
  36. DQUOTE = "\"";
  37. BIT = "0" | "1";
  38. HEXDIG = DIGIT | "A"i | "B"i | "C"i | "D"i | "E"i | "F"i;
  39. CRLF = CR LF;
  40. WSP = SP | HTAB;
  41. LWSP = ( WSP | ( CRLF WSP ) )*;
  42. LWS = ( WSP* CRLF )? WSP+;
  43. SWS = LWS?;
  44. EQUAL = SWS "=" SWS;
  45. LHEX = DIGIT | 0x61..0x66;
  46. HCOLON = ( SP | HTAB )* ":" SWS;
  47. separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | DQUOTE | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HTAB;
  48. STAR = SWS "*" SWS;
  49. SLASH = SWS "/" SWS;
  50. LPAREN = SWS "(" SWS;
  51. RPAREN = SWS ")" SWS;
  52. COMMA = SWS "," SWS;
  53. SEMI = SWS ";" SWS;
  54. COLON = SWS ":" SWS;
  55. LAQUOT = SWS "<";
  56. LDQUOT = SWS DQUOTE;
  57. RAQUOT = ">" SWS;
  58. RDQUOT = DQUOTE SWS;
  59. UTF8_CONT = 0x80..0xbf;
  60. ##### FIXME: UTF8_NONASCII up to 2bytes will fail on Android
  61. UTF8_NONASCII = ( 0x80..0xff );
  62. #UTF8_NONASCII = ( 0xc0..0xdf UTF8_CONT ) | ( 0xe0..0xef UTF8_CONT{2} ) | ( 0xf0..0xf7 UTF8_CONT{3} ) | ( 0xf8..0xfb UTF8_CONT{4} ) | ( 0xfc..0xfd UTF8_CONT{5} );
  63. ctext = 0x21..0x27 | 0x2a..0x5b | 0x5d..0x7e | UTF8_NONASCII | LWS;
  64. qvalue = ( "0" ( "." DIGIT{,3} )? ) | ( "1" ( "." "0"{,3} )? );
  65. alphanum = ALPHA | DIGIT;
  66. scheme = ALPHA ( ALPHA | DIGIT | "+" | "-" | "." )*;
  67. token = ( alphanum | "-" | "." | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" )+;
  68. ietf_token = token;
  69. x_token = "x-"i token;
  70. iana_token = token;
  71. token_nodot = ( alphanum | "-" | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" )+;
  72. word = ( alphanum | "-" | "." | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" | "(" | ")" | "<" | ">" | ":" | "\\" | DQUOTE | "/" | "[" | "]" | "?" | "{" | "}" )+;
  73. domainlabel = alphanum | ( alphanum ( alphanum | "-" )* alphanum );
  74. toplabel = ALPHA | ( ALPHA ( alphanum | "-" )* alphanum );
  75. hostname = ( domainlabel "." )* toplabel "."?;
  76. IPv4address = DIGIT{1,3} "." DIGIT{1,3} "." DIGIT{1,3} "." DIGIT{1,3};
  77. hex4 = HEXDIG{1,4};
  78. hexseq = hex4 ( ":" hex4 )*;
  79. hexpart = hexseq | ( hexseq "::" hexseq? ) | ( "::" hexseq? );
  80. IPv6address = hexpart ( ":" IPv4address )?;
  81. IPv6reference = "[" IPv6address "]";
  82. host = hostname | IPv4address | IPv6reference;
  83. qdtext = LWS | "!" | 0x23..0x5b | 0x5d..0x7e | UTF8_NONASCII;
  84. quoted_pair = "\\" ( 0x00..0x09 | 0x0b..0x0c | 0x0e..0x7f );
  85. quoted_string = SWS DQUOTE ( qdtext | quoted_pair )* DQUOTE;
  86. gen_value = token | host | quoted_string;
  87. generic_param = token ( EQUAL gen_value )?;
  88. accept_param = ( "q"i EQUAL qvalue ) | generic_param;
  89. mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")";
  90. unreserved = alphanum | mark;
  91. escaped = "%" HEXDIG HEXDIG;
  92. user_unreserved = "&" | "=" | "+" | "$" | "," | ";" | "?" | "/";
  93. user = ( unreserved | escaped | user_unreserved )+;
  94. param_unreserved = "[" | "]" | "/" | ":" | "&" | "+" | "$";
  95. pct_encoded = "%" HEXDIG HEXDIG;
  96. paramchar = param_unreserved | unreserved | pct_encoded;
  97. pname = paramchar+;
  98. pvalue = paramchar+;
  99. parameter = ";" pname ( "=" pvalue )?;
  100. reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ",";
  101. urlc = reserved | unreserved | escaped;
  102. extension_code = DIGIT{3};
  103. Status_Code = "100" | "101" | "200" | "201" | "202" | "203" | "204" | "205" | "206" | "300" | "301" | "302" | "303" | "304" | "305" | "307" | "400" | "401" | "402" | "403" | "404" | "405" | "406" | "407" | "408" | "409" | "410" | "411" | "412" | "413" | "414" | "415" | "416" | "417" | "500" | "501" | "502" | "503" | "504" | "505" | extension_code;
  104. extension_method = token;
  105. Method = "OPTIONS"i | "GET"i | "HEAD"i | "POST"i | "PUT"i | "DELETE"i | "TRACE"i | "CONNECT"i | extension_method;
  106. }%%