tsip_machine_utils.rl 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file tsip_machine_utils.rl
  23. * @brief Ragel file.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. %%{
  29. machine tsip_machine_utils;
  30. #OCTET = 0x00..0xff;
  31. OCTET = "0x"[0-9A-Fa-f]+;
  32. CHAR = 0x01..0x7f;
  33. VCHAR = 0x21..0x7e;
  34. ALPHA = 0x41..0x5a | 0x61..0x7a;
  35. DIGIT = 0x30..0x39;
  36. CTL = 0x00..0x1f | 0x7f;
  37. HTAB = "\t";
  38. LF = "\n";
  39. CR = "\r";
  40. SP = " ";
  41. DQUOTE = "\"";
  42. BIT = "0" | "1";
  43. HEXDIG = DIGIT | "A"i | "B"i | "C"i | "D"i | "E"i | "F"i;
  44. CRLF = CR LF;
  45. WSP = SP | HTAB;
  46. LWSP = ( WSP | ( CRLF WSP ) )*;
  47. LWS = ( WSP* CRLF )? WSP+;
  48. SWS = LWS?;
  49. EQUAL = SWS "=" SWS;
  50. LHEX = DIGIT | 0x61..0x66;
  51. HCOLON = ( SP | HTAB )* ":" SWS;
  52. separators = "(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | DQUOTE | "/" | "[" | "]" | "?" | "=" | "{" | "}" | SP | HTAB;
  53. STAR = SWS "*" SWS;
  54. SLASH = SWS "/" SWS;
  55. LPAREN = SWS "(" SWS;
  56. RPAREN = SWS ")" SWS;
  57. COMMA = SWS "," SWS;
  58. SEMI = SWS ";" SWS;
  59. COLON = SWS ":" SWS;
  60. LAQUOT = SWS "<";
  61. LDQUOT = SWS DQUOTE;
  62. RAQUOT = ">" SWS;
  63. RDQUOT = DQUOTE SWS;
  64. UTF8_CONT = 0x80..0xbf;
  65. ##### FIXME: UTF8_NONASCII up to 2bytes will fail on Android
  66. UTF8_NONASCII = ( 0x80..0xff );
  67. #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} ); ctext = 0x21..0x27 | 0x2a..0x5b | 0x5d..0x7e | UTF8_NONASCII | LWS;
  68. qvalue = ( "0" ( "." DIGIT{,3} )? ) | ( "1" ( "." "0"{,3} )? );
  69. alphanum = ALPHA | DIGIT;
  70. token = ( alphanum | "-" | "." | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" )+;
  71. ietf_token = token;
  72. x_token = "x-"i token;
  73. iana_token = token;
  74. token_nodot = ( alphanum | "-" | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" )+;
  75. word = ( alphanum | "-" | "." | "!" | "%" | "*" | "_" | "+" | "`" | "'" | "~" | "(" | ")" | "<" | ">" | ":" | "\\" | DQUOTE | "/" | "[" | "]" | "?" | "{" | "}" )+;
  76. domainlabel = alphanum | ( alphanum ( alphanum | "-" )* alphanum );
  77. toplabel = ALPHA | ( ALPHA ( alphanum | "-" )* alphanum );
  78. hostname = ( domainlabel "." )* toplabel "."?;
  79. IPv4address = DIGIT{1,3} "." DIGIT{1,3} "." DIGIT{1,3} "." DIGIT{1,3};
  80. hex4 = HEXDIG{1,4};
  81. hexseq = hex4 ( ":" hex4 )*;
  82. hexpart = hexseq | ( hexseq "::" hexseq? ) | ( "::" hexseq? );
  83. IPv6address = hexpart ( ":" IPv4address )?;
  84. IPv6reference = "[" IPv6address "]";
  85. host = hostname | IPv4address | IPv6reference;
  86. qdtext = LWS | "!" | 0x23..0x5b | 0x5d..0x7e | UTF8_NONASCII;
  87. quoted_pair = "\\" ( 0x00..0x09 | 0x0b..0x0c | 0x0e..0x7f );
  88. quoted_string = SWS DQUOTE ( qdtext | quoted_pair )* DQUOTE;
  89. gen_value = token | host | quoted_string;
  90. generic_param = token ( EQUAL gen_value )?;
  91. accept_param = ( "q"i EQUAL qvalue ) | generic_param;
  92. mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")";
  93. unreserved = alphanum | mark;
  94. escaped = "%" HEXDIG HEXDIG;
  95. user_unreserved = "&" | "=" | "+" | "$" | "," | ";" | "?" | "/";
  96. user = ( unreserved | escaped | user_unreserved )+;
  97. visual_separator = "-" | "." | "(" | ")";
  98. phonedigit = DIGIT | visual_separator?;
  99. global_number_digits = "+" phonedigit* DIGIT phonedigit*;
  100. param_unreserved = "[" | "]" | "/" | ":" | "&" | "+" | "$";
  101. pct_encoded = "%" HEXDIG HEXDIG;
  102. paramchar = param_unreserved | unreserved | pct_encoded;
  103. pname = paramchar+;
  104. pvalue = paramchar+;
  105. parameter = ";" pname ( "=" pvalue )?;
  106. extension = ";ext="i phonedigit+;
  107. reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | ",";
  108. uric = reserved | unreserved | escaped;
  109. isdn_subaddress = ";isub="i uric+;
  110. not_defined = token;
  111. global_rn = not_defined;
  112. hex_phonedigit = HEXDIG | visual_separator;
  113. domainname = ( domainlabel "." )* toplabel "."?;
  114. phonedigit_hex = HEXDIG | "*" | "#" | visual_separator?;
  115. global_hex_digits = "+" phonedigit{1,3} phonedigit_hex*;
  116. rn_descriptor = domainname | global_hex_digits;
  117. rn_context = ";rn-context="i rn_descriptor;
  118. local_rn = hex_phonedigit+ rn_context;
  119. rn = ";rn="i ( global_rn | local_rn );
  120. global_cic = global_hex_digits;
  121. cic_context = ";cic-context="i rn_descriptor;
  122. local_cic = hex_phonedigit+ cic_context;
  123. cic = ";cic="i ( global_cic | local_cic );
  124. npdi = ";npdi"i;
  125. enum_dip_indicator = ";enumdi"i;
  126. trunk_group_unreserved = "/" | "&" | "+" | "$";
  127. trunk_group_label = ( unreserved | escaped | trunk_group_unreserved )+;
  128. trunk_group = ";tgrp="i trunk_group_label;
  129. descriptor = domainname | global_number_digits;
  130. trunk_context = ";trunk-context="i descriptor;
  131. par = parameter | extension | isdn_subaddress | rn | cic | npdi | enum_dip_indicator | trunk_group | trunk_context;
  132. global_number = global_number_digits par*;
  133. local_number_digits = phonedigit_hex* ( HEXDIG | "*" | "#" ) phonedigit_hex*;
  134. context = ";phone-context="i descriptor;
  135. local_number = local_number_digits par* context par*;
  136. telephone_subscriber = global_number | local_number;
  137. password = ( unreserved | escaped | "&" | "=" | "+" | "$" | "," )*;
  138. userinfo = ( user | telephone_subscriber ) ( ":" password )? "@";
  139. port = DIGIT+;
  140. hostport = host ( ":" port )?;
  141. other_transport = token;
  142. transport_param = "transport="i ( "udp"i | "tcp"i | "sctp"i | "tls"i | "tls-sctp"i | other_transport );
  143. other_user = token;
  144. user_param = "user="i ( "phone"i | "ip"i | "dialstring"i | other_user );
  145. ttl = DIGIT{1,3};
  146. ttl_param = "ttl="i ttl;
  147. maddr_param = "maddr="i host;
  148. lr_param = "lr"i;
  149. option_tag = token;
  150. other_compression = token;
  151. compression_param = "comp="i ( "sigcomp"i | other_compression );
  152. target_param = "target"i EQUAL pvalue;
  153. orig = "orig"i;
  154. gr_param = "gr"i ( "=" pvalue )?;
  155. other_param = pname ( "=" pvalue )?;
  156. tag_param = "tag"i EQUAL token;
  157. scheme = ALPHA ( ALPHA | DIGIT | "+" | "-" | "." )*;
  158. hnv_unreserved = "[" | "]" | "/" | "?" | ":" | "+" | "$";
  159. hname = ( hnv_unreserved | unreserved | escaped )+;
  160. hvalue = ( hnv_unreserved | unreserved | escaped )*;
  161. header = hname ( "=" hvalue )?;
  162. headers = "?" header ( "&" header )*;
  163. Informational = "100" | "180" | "181" | "182" | "183";
  164. Success = "200" | "202";
  165. Redirection = "250" | "301" | "302" | "305" | "380";
  166. Client_Error = "400" | "401" | "402" | "403" | "404" | "405" | "406" | "407" | "408" | "410" | "412" | "413" | "414" | "415" | "416" | "417" | "420" | "421" | "422" | "423" | "428" | "429" | "433" | "436" | "440" | "437" | "438" | "470" | "480" | "481" | "482" | "483" | "484" | "485" | "486" | "487" | "488" | "489" | "491" | "493" | "494";
  167. Server_Error = "500" | "501" | "502" | "503" | "504" | "505" | "513" | "580";
  168. Global_Failure = "600" | "603" | "604" | "606";
  169. extension_code = DIGIT{3};
  170. delta_seconds = DIGIT+;
  171. Status_Code = Informational | Success | Redirection | Client_Error | Server_Error | Global_Failure | extension_code;
  172. cause_param = "cause"i EQUAL Status_Code;
  173. INVITEm = 0x49.0x4e.0x56.0x49.0x54.0x45;
  174. ACKm = 0x41.0x43.0x4b;
  175. OPTIONSm = 0x4f.0x50.0x54.0x49.0x4f.0x4e.0x53;
  176. BYEm = 0x42.0x59.0x45;
  177. CANCELm = 0x43.0x41.0x4e.0x43.0x45.0x4c;
  178. REGISTERm = 0x52.0x45.0x47.0x49.0x53.0x54.0x45.0x52;
  179. INFOm = 0x49.0x4e.0x46.0x4f;
  180. PRACKm = 0x50.0x52.0x41.0x43.0x4b;
  181. SUBSCRIBEm = 0x53.0x55.0x42.0x53.0x43.0x52.0x49.0x42.0x45;
  182. NOTIFYm = 0x4e.0x4f.0x54.0x49.0x46.0x59;
  183. UPDATEm = 0x55.0x50.0x44.0x41.0x54.0x45;
  184. MESSAGEm = 0x4d.0x45.0x53.0x53.0x41.0x47.0x45;
  185. REFERm = 0x52.0x45.0x46.0x45.0x52;
  186. PUBLISHm = 0x50.0x55.0x42.0x4c.0x49.0x53.0x48;
  187. extension_method = token;
  188. Method = INVITEm | ACKm | OPTIONSm | BYEm | CANCELm | REGISTERm | INFOm | PRACKm | SUBSCRIBEm | NOTIFYm | UPDATEm | MESSAGEm | REFERm | PUBLISHm | extension_method;
  189. method_param = "method="i Method;
  190. }%%