immunio 1.2.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -5
  3. data/ext/immunio/Rakefile +14 -6
  4. data/lib/immunio/context.rb +2 -0
  5. data/lib/immunio/plugins/action_view.rb +7 -668
  6. data/lib/immunio/plugins/action_view/action_view.rb +22 -0
  7. data/lib/immunio/plugins/action_view/active_support_hash.rb +29 -0
  8. data/lib/immunio/plugins/action_view/cache_store.rb +24 -0
  9. data/lib/immunio/plugins/action_view/erubi.rb +38 -0
  10. data/lib/immunio/plugins/action_view/erubis.rb +39 -0
  11. data/lib/immunio/plugins/action_view/fragment_caching.rb +29 -0
  12. data/lib/immunio/plugins/action_view/haml.rb +46 -0
  13. data/lib/immunio/plugins/action_view/slim.rb +42 -0
  14. data/lib/immunio/plugins/action_view/template.rb +431 -0
  15. data/lib/immunio/plugins/action_view/template_rendering.rb +45 -0
  16. data/lib/immunio/plugins/http_tracker.rb +2 -0
  17. data/lib/immunio/plugins/io.rb +34 -0
  18. data/lib/immunio/version.rb +1 -1
  19. data/lua-hooks/Makefile +36 -9
  20. data/lua-hooks/ext/luajit/COPYRIGHT +1 -1
  21. data/lua-hooks/ext/luajit/Makefile +22 -15
  22. data/lua-hooks/ext/luajit/README +2 -2
  23. data/lua-hooks/ext/luajit/doc/bluequad-print.css +1 -1
  24. data/lua-hooks/ext/luajit/doc/bluequad.css +1 -1
  25. data/lua-hooks/ext/luajit/doc/changes.html +69 -3
  26. data/lua-hooks/ext/luajit/doc/contact.html +10 -3
  27. data/lua-hooks/ext/luajit/doc/ext_c_api.html +2 -2
  28. data/lua-hooks/ext/luajit/doc/ext_ffi.html +2 -2
  29. data/lua-hooks/ext/luajit/doc/ext_ffi_api.html +2 -2
  30. data/lua-hooks/ext/luajit/doc/ext_ffi_semantics.html +3 -4
  31. data/lua-hooks/ext/luajit/doc/ext_ffi_tutorial.html +2 -2
  32. data/lua-hooks/ext/luajit/doc/ext_jit.html +3 -3
  33. data/lua-hooks/ext/luajit/doc/ext_profiler.html +2 -2
  34. data/lua-hooks/ext/luajit/doc/extensions.html +47 -20
  35. data/lua-hooks/ext/luajit/doc/faq.html +2 -2
  36. data/lua-hooks/ext/luajit/doc/install.html +74 -45
  37. data/lua-hooks/ext/luajit/doc/luajit.html +5 -5
  38. data/lua-hooks/ext/luajit/doc/running.html +3 -3
  39. data/lua-hooks/ext/luajit/doc/status.html +13 -8
  40. data/lua-hooks/ext/luajit/dynasm/dasm_arm.h +1 -1
  41. data/lua-hooks/ext/luajit/dynasm/dasm_arm.lua +1 -1
  42. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.h +1 -1
  43. data/lua-hooks/ext/luajit/dynasm/dasm_arm64.lua +1 -1
  44. data/lua-hooks/ext/luajit/dynasm/dasm_mips.h +8 -5
  45. data/lua-hooks/ext/luajit/dynasm/dasm_mips.lua +66 -11
  46. data/lua-hooks/ext/luajit/dynasm/dasm_mips64.lua +12 -0
  47. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.h +1 -1
  48. data/lua-hooks/ext/luajit/dynasm/dasm_ppc.lua +1 -1
  49. data/lua-hooks/ext/luajit/dynasm/dasm_proto.h +1 -1
  50. data/lua-hooks/ext/luajit/dynasm/dasm_x64.lua +1 -1
  51. data/lua-hooks/ext/luajit/dynasm/dasm_x86.h +1 -1
  52. data/lua-hooks/ext/luajit/dynasm/dasm_x86.lua +5 -1
  53. data/lua-hooks/ext/luajit/dynasm/dynasm.lua +2 -2
  54. data/lua-hooks/ext/luajit/etc/luajit.1 +1 -1
  55. data/lua-hooks/ext/luajit/etc/luajit.pc +1 -1
  56. data/lua-hooks/ext/luajit/src/Makefile +15 -11
  57. data/lua-hooks/ext/luajit/src/Makefile.dep +16 -16
  58. data/lua-hooks/ext/luajit/src/host/buildvm.c +2 -2
  59. data/lua-hooks/ext/luajit/src/host/buildvm.h +1 -1
  60. data/lua-hooks/ext/luajit/src/host/buildvm_asm.c +9 -4
  61. data/lua-hooks/ext/luajit/src/host/buildvm_fold.c +2 -2
  62. data/lua-hooks/ext/luajit/src/host/buildvm_lib.c +1 -1
  63. data/lua-hooks/ext/luajit/src/host/buildvm_libbc.h +14 -3
  64. data/lua-hooks/ext/luajit/src/host/buildvm_peobj.c +27 -3
  65. data/lua-hooks/ext/luajit/src/host/genlibbc.lua +1 -1
  66. data/lua-hooks/ext/luajit/src/host/genminilua.lua +6 -5
  67. data/lua-hooks/ext/luajit/src/host/minilua.c +1 -1
  68. data/lua-hooks/ext/luajit/src/jit/bc.lua +1 -1
  69. data/lua-hooks/ext/luajit/src/jit/bcsave.lua +8 -8
  70. data/lua-hooks/ext/luajit/src/jit/dis_arm.lua +2 -2
  71. data/lua-hooks/ext/luajit/src/jit/dis_arm64.lua +1216 -0
  72. data/lua-hooks/ext/luajit/src/jit/dis_arm64be.lua +12 -0
  73. data/lua-hooks/ext/luajit/src/jit/dis_mips.lua +35 -20
  74. data/lua-hooks/ext/luajit/src/jit/dis_mips64.lua +17 -0
  75. data/lua-hooks/ext/luajit/src/jit/dis_mips64el.lua +17 -0
  76. data/lua-hooks/ext/luajit/src/jit/dis_mipsel.lua +1 -1
  77. data/lua-hooks/ext/luajit/src/jit/dis_ppc.lua +2 -2
  78. data/lua-hooks/ext/luajit/src/jit/dis_x64.lua +1 -1
  79. data/lua-hooks/ext/luajit/src/jit/dis_x86.lua +7 -4
  80. data/lua-hooks/ext/luajit/src/jit/dump.lua +17 -12
  81. data/lua-hooks/ext/luajit/src/jit/p.lua +3 -2
  82. data/lua-hooks/ext/luajit/src/jit/v.lua +2 -2
  83. data/lua-hooks/ext/luajit/src/jit/zone.lua +1 -1
  84. data/lua-hooks/ext/luajit/src/lauxlib.h +14 -20
  85. data/lua-hooks/ext/luajit/src/lib_aux.c +38 -27
  86. data/lua-hooks/ext/luajit/src/lib_base.c +12 -5
  87. data/lua-hooks/ext/luajit/src/lib_bit.c +1 -1
  88. data/lua-hooks/ext/luajit/src/lib_debug.c +5 -5
  89. data/lua-hooks/ext/luajit/src/lib_ffi.c +2 -2
  90. data/lua-hooks/ext/luajit/src/lib_init.c +16 -16
  91. data/lua-hooks/ext/luajit/src/lib_io.c +6 -7
  92. data/lua-hooks/ext/luajit/src/lib_jit.c +14 -4
  93. data/lua-hooks/ext/luajit/src/lib_math.c +1 -5
  94. data/lua-hooks/ext/luajit/src/lib_os.c +1 -1
  95. data/lua-hooks/ext/luajit/src/lib_package.c +14 -23
  96. data/lua-hooks/ext/luajit/src/lib_string.c +1 -5
  97. data/lua-hooks/ext/luajit/src/lib_table.c +21 -1
  98. data/lua-hooks/ext/luajit/src/lj.supp +3 -3
  99. data/lua-hooks/ext/luajit/src/lj_alloc.c +174 -83
  100. data/lua-hooks/ext/luajit/src/lj_api.c +97 -18
  101. data/lua-hooks/ext/luajit/src/lj_arch.h +54 -22
  102. data/lua-hooks/ext/luajit/src/lj_asm.c +172 -53
  103. data/lua-hooks/ext/luajit/src/lj_asm.h +1 -1
  104. data/lua-hooks/ext/luajit/src/lj_asm_arm.h +19 -16
  105. data/lua-hooks/ext/luajit/src/lj_asm_arm64.h +2022 -0
  106. data/lua-hooks/ext/luajit/src/lj_asm_mips.h +564 -158
  107. data/lua-hooks/ext/luajit/src/lj_asm_ppc.h +19 -18
  108. data/lua-hooks/ext/luajit/src/lj_asm_x86.h +578 -92
  109. data/lua-hooks/ext/luajit/src/lj_bc.c +1 -1
  110. data/lua-hooks/ext/luajit/src/lj_bc.h +1 -1
  111. data/lua-hooks/ext/luajit/src/lj_bcdump.h +1 -1
  112. data/lua-hooks/ext/luajit/src/lj_bcread.c +1 -1
  113. data/lua-hooks/ext/luajit/src/lj_bcwrite.c +1 -1
  114. data/lua-hooks/ext/luajit/src/lj_buf.c +1 -1
  115. data/lua-hooks/ext/luajit/src/lj_buf.h +1 -1
  116. data/lua-hooks/ext/luajit/src/lj_carith.c +1 -1
  117. data/lua-hooks/ext/luajit/src/lj_carith.h +1 -1
  118. data/lua-hooks/ext/luajit/src/lj_ccall.c +172 -7
  119. data/lua-hooks/ext/luajit/src/lj_ccall.h +21 -5
  120. data/lua-hooks/ext/luajit/src/lj_ccallback.c +71 -17
  121. data/lua-hooks/ext/luajit/src/lj_ccallback.h +1 -1
  122. data/lua-hooks/ext/luajit/src/lj_cconv.c +4 -2
  123. data/lua-hooks/ext/luajit/src/lj_cconv.h +1 -1
  124. data/lua-hooks/ext/luajit/src/lj_cdata.c +7 -5
  125. data/lua-hooks/ext/luajit/src/lj_cdata.h +1 -1
  126. data/lua-hooks/ext/luajit/src/lj_clib.c +5 -5
  127. data/lua-hooks/ext/luajit/src/lj_clib.h +1 -1
  128. data/lua-hooks/ext/luajit/src/lj_cparse.c +11 -6
  129. data/lua-hooks/ext/luajit/src/lj_cparse.h +1 -1
  130. data/lua-hooks/ext/luajit/src/lj_crecord.c +70 -14
  131. data/lua-hooks/ext/luajit/src/lj_crecord.h +1 -1
  132. data/lua-hooks/ext/luajit/src/lj_ctype.c +1 -1
  133. data/lua-hooks/ext/luajit/src/lj_ctype.h +8 -8
  134. data/lua-hooks/ext/luajit/src/lj_debug.c +1 -1
  135. data/lua-hooks/ext/luajit/src/lj_debug.h +1 -1
  136. data/lua-hooks/ext/luajit/src/lj_def.h +6 -9
  137. data/lua-hooks/ext/luajit/src/lj_dispatch.c +3 -3
  138. data/lua-hooks/ext/luajit/src/lj_dispatch.h +2 -1
  139. data/lua-hooks/ext/luajit/src/lj_emit_arm.h +5 -4
  140. data/lua-hooks/ext/luajit/src/lj_emit_arm64.h +419 -0
  141. data/lua-hooks/ext/luajit/src/lj_emit_mips.h +100 -20
  142. data/lua-hooks/ext/luajit/src/lj_emit_ppc.h +4 -4
  143. data/lua-hooks/ext/luajit/src/lj_emit_x86.h +116 -25
  144. data/lua-hooks/ext/luajit/src/lj_err.c +34 -13
  145. data/lua-hooks/ext/luajit/src/lj_err.h +1 -1
  146. data/lua-hooks/ext/luajit/src/lj_errmsg.h +1 -1
  147. data/lua-hooks/ext/luajit/src/lj_ff.h +1 -1
  148. data/lua-hooks/ext/luajit/src/lj_ffrecord.c +58 -49
  149. data/lua-hooks/ext/luajit/src/lj_ffrecord.h +1 -1
  150. data/lua-hooks/ext/luajit/src/lj_frame.h +33 -6
  151. data/lua-hooks/ext/luajit/src/lj_func.c +4 -2
  152. data/lua-hooks/ext/luajit/src/lj_func.h +1 -1
  153. data/lua-hooks/ext/luajit/src/lj_gc.c +16 -7
  154. data/lua-hooks/ext/luajit/src/lj_gc.h +1 -1
  155. data/lua-hooks/ext/luajit/src/lj_gdbjit.c +31 -1
  156. data/lua-hooks/ext/luajit/src/lj_gdbjit.h +1 -1
  157. data/lua-hooks/ext/luajit/src/lj_ir.c +69 -96
  158. data/lua-hooks/ext/luajit/src/lj_ir.h +29 -18
  159. data/lua-hooks/ext/luajit/src/lj_ircall.h +24 -30
  160. data/lua-hooks/ext/luajit/src/lj_iropt.h +9 -9
  161. data/lua-hooks/ext/luajit/src/lj_jit.h +67 -9
  162. data/lua-hooks/ext/luajit/src/lj_lex.c +1 -1
  163. data/lua-hooks/ext/luajit/src/lj_lex.h +1 -1
  164. data/lua-hooks/ext/luajit/src/lj_lib.c +1 -1
  165. data/lua-hooks/ext/luajit/src/lj_lib.h +1 -1
  166. data/lua-hooks/ext/luajit/src/lj_load.c +1 -1
  167. data/lua-hooks/ext/luajit/src/lj_mcode.c +11 -10
  168. data/lua-hooks/ext/luajit/src/lj_mcode.h +1 -1
  169. data/lua-hooks/ext/luajit/src/lj_meta.c +1 -1
  170. data/lua-hooks/ext/luajit/src/lj_meta.h +1 -1
  171. data/lua-hooks/ext/luajit/src/lj_obj.c +1 -1
  172. data/lua-hooks/ext/luajit/src/lj_obj.h +7 -3
  173. data/lua-hooks/ext/luajit/src/lj_opt_dce.c +1 -1
  174. data/lua-hooks/ext/luajit/src/lj_opt_fold.c +84 -17
  175. data/lua-hooks/ext/luajit/src/lj_opt_loop.c +1 -1
  176. data/lua-hooks/ext/luajit/src/lj_opt_mem.c +3 -3
  177. data/lua-hooks/ext/luajit/src/lj_opt_narrow.c +24 -22
  178. data/lua-hooks/ext/luajit/src/lj_opt_sink.c +11 -6
  179. data/lua-hooks/ext/luajit/src/lj_opt_split.c +11 -2
  180. data/lua-hooks/ext/luajit/src/lj_parse.c +9 -7
  181. data/lua-hooks/ext/luajit/src/lj_parse.h +1 -1
  182. data/lua-hooks/ext/luajit/src/lj_profile.c +1 -1
  183. data/lua-hooks/ext/luajit/src/lj_profile.h +1 -1
  184. data/lua-hooks/ext/luajit/src/lj_record.c +201 -117
  185. data/lua-hooks/ext/luajit/src/lj_record.h +1 -1
  186. data/lua-hooks/ext/luajit/src/lj_snap.c +72 -26
  187. data/lua-hooks/ext/luajit/src/lj_snap.h +1 -1
  188. data/lua-hooks/ext/luajit/src/lj_state.c +6 -6
  189. data/lua-hooks/ext/luajit/src/lj_state.h +2 -2
  190. data/lua-hooks/ext/luajit/src/lj_str.c +1 -1
  191. data/lua-hooks/ext/luajit/src/lj_str.h +1 -1
  192. data/lua-hooks/ext/luajit/src/lj_strfmt.c +7 -3
  193. data/lua-hooks/ext/luajit/src/lj_strfmt.h +1 -1
  194. data/lua-hooks/ext/luajit/src/lj_strfmt_num.c +4 -3
  195. data/lua-hooks/ext/luajit/src/lj_strscan.c +1 -1
  196. data/lua-hooks/ext/luajit/src/lj_strscan.h +1 -1
  197. data/lua-hooks/ext/luajit/src/lj_tab.c +1 -2
  198. data/lua-hooks/ext/luajit/src/lj_tab.h +1 -1
  199. data/lua-hooks/ext/luajit/src/lj_target.h +3 -3
  200. data/lua-hooks/ext/luajit/src/lj_target_arm.h +1 -1
  201. data/lua-hooks/ext/luajit/src/lj_target_arm64.h +239 -7
  202. data/lua-hooks/ext/luajit/src/lj_target_mips.h +111 -22
  203. data/lua-hooks/ext/luajit/src/lj_target_ppc.h +1 -1
  204. data/lua-hooks/ext/luajit/src/lj_target_x86.h +21 -4
  205. data/lua-hooks/ext/luajit/src/lj_trace.c +63 -18
  206. data/lua-hooks/ext/luajit/src/lj_trace.h +2 -1
  207. data/lua-hooks/ext/luajit/src/lj_traceerr.h +1 -1
  208. data/lua-hooks/ext/luajit/src/lj_udata.c +1 -1
  209. data/lua-hooks/ext/luajit/src/lj_udata.h +1 -1
  210. data/lua-hooks/ext/luajit/src/lj_vm.h +5 -1
  211. data/lua-hooks/ext/luajit/src/lj_vmevent.c +1 -1
  212. data/lua-hooks/ext/luajit/src/lj_vmevent.h +1 -1
  213. data/lua-hooks/ext/luajit/src/lj_vmmath.c +1 -1
  214. data/lua-hooks/ext/luajit/src/ljamalg.c +1 -1
  215. data/lua-hooks/ext/luajit/src/lua.h +9 -1
  216. data/lua-hooks/ext/luajit/src/luaconf.h +3 -7
  217. data/lua-hooks/ext/luajit/src/luajit.c +69 -54
  218. data/lua-hooks/ext/luajit/src/luajit.h +4 -4
  219. data/lua-hooks/ext/luajit/src/lualib.h +1 -1
  220. data/lua-hooks/ext/luajit/src/msvcbuild.bat +12 -4
  221. data/lua-hooks/ext/luajit/src/vm_arm.dasc +1 -1
  222. data/lua-hooks/ext/luajit/src/vm_arm64.dasc +255 -32
  223. data/lua-hooks/ext/luajit/src/vm_mips.dasc +26 -23
  224. data/lua-hooks/ext/luajit/src/vm_mips64.dasc +5062 -0
  225. data/lua-hooks/ext/luajit/src/vm_ppc.dasc +1 -1
  226. data/lua-hooks/ext/luajit/src/vm_x64.dasc +24 -25
  227. data/lua-hooks/ext/luajit/src/vm_x86.dasc +77 -4
  228. data/lua-hooks/libluahooks.darwin.a +0 -0
  229. data/lua-hooks/libluahooks.linux.a +0 -0
  230. data/lua-hooks/options.mk +1 -1
  231. metadata +37 -77
  232. data/lua-hooks/ext/all.c +0 -69
  233. data/lua-hooks/ext/libinjection/COPYING +0 -37
  234. data/lua-hooks/ext/libinjection/libinjection.h +0 -65
  235. data/lua-hooks/ext/libinjection/libinjection_html5.c +0 -847
  236. data/lua-hooks/ext/libinjection/libinjection_html5.h +0 -54
  237. data/lua-hooks/ext/libinjection/libinjection_sqli.c +0 -2301
  238. data/lua-hooks/ext/libinjection/libinjection_sqli.h +0 -295
  239. data/lua-hooks/ext/libinjection/libinjection_sqli_data.h +0 -9349
  240. data/lua-hooks/ext/libinjection/libinjection_xss.c +0 -531
  241. data/lua-hooks/ext/libinjection/libinjection_xss.h +0 -21
  242. data/lua-hooks/ext/libinjection/lualib.c +0 -145
  243. data/lua-hooks/ext/libinjection/module.mk +0 -5
  244. data/lua-hooks/ext/lpeg/HISTORY +0 -96
  245. data/lua-hooks/ext/lpeg/lpcap.c +0 -537
  246. data/lua-hooks/ext/lpeg/lpcap.h +0 -56
  247. data/lua-hooks/ext/lpeg/lpcode.c +0 -1014
  248. data/lua-hooks/ext/lpeg/lpcode.h +0 -40
  249. data/lua-hooks/ext/lpeg/lpeg-128.gif +0 -0
  250. data/lua-hooks/ext/lpeg/lpeg.html +0 -1445
  251. data/lua-hooks/ext/lpeg/lpprint.c +0 -244
  252. data/lua-hooks/ext/lpeg/lpprint.h +0 -36
  253. data/lua-hooks/ext/lpeg/lptree.c +0 -1303
  254. data/lua-hooks/ext/lpeg/lptree.h +0 -82
  255. data/lua-hooks/ext/lpeg/lptypes.h +0 -149
  256. data/lua-hooks/ext/lpeg/lpvm.c +0 -364
  257. data/lua-hooks/ext/lpeg/lpvm.h +0 -58
  258. data/lua-hooks/ext/lpeg/makefile +0 -55
  259. data/lua-hooks/ext/lpeg/module.mk +0 -6
  260. data/lua-hooks/ext/lpeg/re.html +0 -498
  261. data/lua-hooks/ext/lua-cmsgpack/.gitignore +0 -13
  262. data/lua-hooks/ext/lua-cmsgpack/CMakeLists.txt +0 -45
  263. data/lua-hooks/ext/lua-cmsgpack/README.md +0 -115
  264. data/lua-hooks/ext/lua-cmsgpack/lua_cmsgpack.c +0 -970
  265. data/lua-hooks/ext/lua-cmsgpack/module.mk +0 -2
  266. data/lua-hooks/ext/lua-cmsgpack/test.lua +0 -570
  267. data/lua-hooks/ext/lua-snapshot/LICENSE +0 -7
  268. data/lua-hooks/ext/lua-snapshot/Makefile +0 -12
  269. data/lua-hooks/ext/lua-snapshot/README.md +0 -18
  270. data/lua-hooks/ext/lua-snapshot/dump.lua +0 -15
  271. data/lua-hooks/ext/lua-snapshot/module.mk +0 -2
  272. data/lua-hooks/ext/lua-snapshot/snapshot.c +0 -462
  273. data/lua-hooks/ext/luautf8/README.md +0 -152
  274. data/lua-hooks/ext/luautf8/lutf8lib.c +0 -1274
  275. data/lua-hooks/ext/luautf8/module.mk +0 -2
  276. data/lua-hooks/ext/luautf8/unidata.h +0 -3064
  277. data/lua-hooks/ext/module.mk +0 -15
  278. data/lua-hooks/ext/modules.h +0 -17
  279. data/lua-hooks/ext/perf/luacpu.c +0 -114
  280. data/lua-hooks/ext/perf/lualoadavg.c +0 -40
  281. data/lua-hooks/ext/perf/luameminfo.c +0 -38
  282. data/lua-hooks/ext/perf/luaoslib.c +0 -203
  283. data/lua-hooks/ext/perf/module.mk +0 -5
  284. data/lua-hooks/ext/sha1/luasha1.c +0 -74
  285. data/lua-hooks/ext/sha1/module.mk +0 -5
  286. data/lua-hooks/ext/sha1/sha1.c +0 -145
  287. data/lua-hooks/ext/sha2/luasha256.c +0 -77
  288. data/lua-hooks/ext/sha2/module.mk +0 -5
  289. data/lua-hooks/ext/sha2/sha256.c +0 -196
  290. data/lua-hooks/ext/sysutils/lua_utils.c +0 -56
  291. data/lua-hooks/ext/sysutils/module.mk +0 -2
@@ -1,82 +0,0 @@
1
- /*
2
- ** $Id: lptree.h,v 1.3 2016/09/13 18:07:51 roberto Exp $
3
- */
4
-
5
- #if !defined(lptree_h)
6
- #define lptree_h
7
-
8
-
9
- #include "lptypes.h"
10
-
11
-
12
- /*
13
- ** types of trees
14
- */
15
- typedef enum TTag {
16
- TChar = 0, /* 'n' = char */
17
- TSet, /* the set is stored in next CHARSETSIZE bytes */
18
- TAny,
19
- TTrue,
20
- TFalse,
21
- TRep, /* 'sib1'* */
22
- TSeq, /* 'sib1' 'sib2' */
23
- TChoice, /* 'sib1' / 'sib2' */
24
- TNot, /* !'sib1' */
25
- TAnd, /* &'sib1' */
26
- TCall, /* ktable[key] is rule's key; 'sib2' is rule being called */
27
- TOpenCall, /* ktable[key] is rule's key */
28
- TRule, /* ktable[key] is rule's key (but key == 0 for unused rules);
29
- 'sib1' is rule's pattern;
30
- 'sib2' is next rule; 'cap' is rule's sequential number */
31
- TGrammar, /* 'sib1' is initial (and first) rule */
32
- TBehind, /* 'sib1' is pattern, 'n' is how much to go back */
33
- TCapture, /* captures: 'cap' is kind of capture (enum 'CapKind');
34
- ktable[key] is Lua value associated with capture;
35
- 'sib1' is capture body */
36
- TRunTime /* run-time capture: 'key' is Lua function;
37
- 'sib1' is capture body */
38
- } TTag;
39
-
40
-
41
- /*
42
- ** Tree trees
43
- ** The first child of a tree (if there is one) is immediately after
44
- ** the tree. A reference to a second child (ps) is its position
45
- ** relative to the position of the tree itself.
46
- */
47
- typedef struct TTree {
48
- byte tag;
49
- byte cap; /* kind of capture (if it is a capture) */
50
- unsigned short key; /* key in ktable for Lua data (0 if no key) */
51
- union {
52
- int ps; /* occasional second child */
53
- int n; /* occasional counter */
54
- } u;
55
- } TTree;
56
-
57
-
58
- /*
59
- ** A complete pattern has its tree plus, if already compiled,
60
- ** its corresponding code
61
- */
62
- typedef struct Pattern {
63
- union Instruction *code;
64
- int codesize;
65
- TTree tree[1];
66
- } Pattern;
67
-
68
-
69
- /* number of children for each tree */
70
- extern const byte numsiblings[];
71
-
72
- /* access to children */
73
- #define sib1(t) ((t) + 1)
74
- #define sib2(t) ((t) + (t)->u.ps)
75
-
76
-
77
-
78
-
79
-
80
-
81
- #endif
82
-
@@ -1,149 +0,0 @@
1
- /*
2
- ** $Id: lptypes.h,v 1.16 2017/01/13 13:33:17 roberto Exp $
3
- ** LPeg - PEG pattern matching for Lua
4
- ** Copyright 2007-2017, Lua.org & PUC-Rio (see 'lpeg.html' for license)
5
- ** written by Roberto Ierusalimschy
6
- */
7
-
8
- #if !defined(lptypes_h)
9
- #define lptypes_h
10
-
11
-
12
- #if !defined(LPEG_DEBUG)
13
- #define NDEBUG
14
- #endif
15
-
16
- #include <assert.h>
17
- #include <limits.h>
18
-
19
- #include "lua.h"
20
-
21
-
22
- #define VERSION "1.0.1"
23
-
24
-
25
- #define PATTERN_T "lpeg-pattern"
26
- #define MAXSTACKIDX "lpeg-maxstack"
27
-
28
-
29
- /*
30
- ** compatibility with Lua 5.1
31
- */
32
- #if (LUA_VERSION_NUM == 501)
33
-
34
- #define lp_equal lua_equal
35
-
36
- #define lua_getuservalue lua_getfenv
37
- #define lua_setuservalue lua_setfenv
38
-
39
- #define lua_rawlen lua_objlen
40
-
41
- #define luaL_setfuncs(L,f,n) luaL_register(L,NULL,f)
42
- #define luaL_newlib(L,f) luaL_register(L,"lpeg",f)
43
-
44
- #endif
45
-
46
-
47
- #if !defined(lp_equal)
48
- #define lp_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
49
- #endif
50
-
51
-
52
- /* default maximum size for call/backtrack stack */
53
- #if !defined(MAXBACK)
54
- #define MAXBACK 400
55
- #endif
56
-
57
-
58
- /* maximum number of rules in a grammar (limited by 'unsigned char') */
59
- #if !defined(MAXRULES)
60
- #define MAXRULES 250
61
- #endif
62
-
63
-
64
-
65
- /* initial size for capture's list */
66
- #define INITCAPSIZE 32
67
-
68
-
69
- /* index, on Lua stack, for subject */
70
- #define SUBJIDX 2
71
-
72
- /* number of fixed arguments to 'match' (before capture arguments) */
73
- #define FIXEDARGS 3
74
-
75
- /* index, on Lua stack, for capture list */
76
- #define caplistidx(ptop) ((ptop) + 2)
77
-
78
- /* index, on Lua stack, for pattern's ktable */
79
- #define ktableidx(ptop) ((ptop) + 3)
80
-
81
- /* index, on Lua stack, for backtracking stack */
82
- #define stackidx(ptop) ((ptop) + 4)
83
-
84
-
85
-
86
- typedef unsigned char byte;
87
-
88
-
89
- #define BITSPERCHAR 8
90
-
91
- #define CHARSETSIZE ((UCHAR_MAX/BITSPERCHAR) + 1)
92
-
93
-
94
-
95
- typedef struct Charset {
96
- byte cs[CHARSETSIZE];
97
- } Charset;
98
-
99
-
100
-
101
- #define loopset(v,b) { int v; for (v = 0; v < CHARSETSIZE; v++) {b;} }
102
-
103
- /* access to charset */
104
- #define treebuffer(t) ((byte *)((t) + 1))
105
-
106
- /* number of slots needed for 'n' bytes */
107
- #define bytes2slots(n) (((n) - 1) / sizeof(TTree) + 1)
108
-
109
- /* set 'b' bit in charset 'cs' */
110
- #define setchar(cs,b) ((cs)[(b) >> 3] |= (1 << ((b) & 7)))
111
-
112
-
113
- /*
114
- ** in capture instructions, 'kind' of capture and its offset are
115
- ** packed in field 'aux', 4 bits for each
116
- */
117
- #define getkind(op) ((op)->i.aux & 0xF)
118
- #define getoff(op) (((op)->i.aux >> 4) & 0xF)
119
- #define joinkindoff(k,o) ((k) | ((o) << 4))
120
-
121
- #define MAXOFF 0xF
122
- #define MAXAUX 0xFF
123
-
124
-
125
- /* maximum number of bytes to look behind */
126
- #define MAXBEHIND MAXAUX
127
-
128
-
129
- /* maximum size (in elements) for a pattern */
130
- #define MAXPATTSIZE (SHRT_MAX - 10)
131
-
132
-
133
- /* size (in elements) for an instruction plus extra l bytes */
134
- #define instsize(l) (((l) + sizeof(Instruction) - 1)/sizeof(Instruction) + 1)
135
-
136
-
137
- /* size (in elements) for a ISet instruction */
138
- #define CHARSETINSTSIZE instsize(CHARSETSIZE)
139
-
140
- /* size (in elements) for a IFunc instruction */
141
- #define funcinstsize(p) ((p)->i.aux + 2)
142
-
143
-
144
-
145
- #define testchar(st,c) (((int)(st)[((c) >> 3)] & (1 << ((c) & 7))))
146
-
147
-
148
- #endif
149
-
@@ -1,364 +0,0 @@
1
- /*
2
- ** $Id: lpvm.c,v 1.9 2016/06/03 20:11:18 roberto Exp $
3
- ** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license)
4
- */
5
-
6
- #include <limits.h>
7
- #include <string.h>
8
-
9
-
10
- #include "lua.h"
11
- #include "lauxlib.h"
12
-
13
- #include "lpcap.h"
14
- #include "lptypes.h"
15
- #include "lpvm.h"
16
- #include "lpprint.h"
17
-
18
-
19
- /* initial size for call/backtrack stack */
20
- #if !defined(INITBACK)
21
- #define INITBACK MAXBACK
22
- #endif
23
-
24
-
25
- #define getoffset(p) (((p) + 1)->offset)
26
-
27
- static const Instruction giveup = {{IGiveup, 0, 0}};
28
-
29
-
30
- /*
31
- ** {======================================================
32
- ** Virtual Machine
33
- ** =======================================================
34
- */
35
-
36
-
37
- typedef struct Stack {
38
- const char *s; /* saved position (or NULL for calls) */
39
- const Instruction *p; /* next instruction */
40
- int caplevel;
41
- } Stack;
42
-
43
-
44
- #define getstackbase(L, ptop) ((Stack *)lua_touserdata(L, stackidx(ptop)))
45
-
46
-
47
- /*
48
- ** Make the size of the array of captures 'cap' twice as large as needed
49
- ** (which is 'captop'). ('n' is the number of new elements.)
50
- */
51
- static Capture *doublecap (lua_State *L, Capture *cap, int captop,
52
- int n, int ptop) {
53
- Capture *newc;
54
- if (captop >= INT_MAX/((int)sizeof(Capture) * 2))
55
- luaL_error(L, "too many captures");
56
- newc = (Capture *)lua_newuserdata(L, captop * 2 * sizeof(Capture));
57
- memcpy(newc, cap, (captop - n) * sizeof(Capture));
58
- lua_replace(L, caplistidx(ptop));
59
- return newc;
60
- }
61
-
62
-
63
- /*
64
- ** Double the size of the stack
65
- */
66
- static Stack *doublestack (lua_State *L, Stack **stacklimit, int ptop) {
67
- Stack *stack = getstackbase(L, ptop);
68
- Stack *newstack;
69
- int n = *stacklimit - stack; /* current stack size */
70
- int max, newn;
71
- lua_getfield(L, LUA_REGISTRYINDEX, MAXSTACKIDX);
72
- max = lua_tointeger(L, -1); /* maximum allowed size */
73
- lua_pop(L, 1);
74
- if (n >= max) /* already at maximum size? */
75
- luaL_error(L, "backtrack stack overflow (current limit is %d)", max);
76
- newn = 2 * n; /* new size */
77
- if (newn > max) newn = max;
78
- newstack = (Stack *)lua_newuserdata(L, newn * sizeof(Stack));
79
- memcpy(newstack, stack, n * sizeof(Stack));
80
- lua_replace(L, stackidx(ptop));
81
- *stacklimit = newstack + newn;
82
- return newstack + n; /* return next position */
83
- }
84
-
85
-
86
- /*
87
- ** Interpret the result of a dynamic capture: false -> fail;
88
- ** true -> keep current position; number -> next position.
89
- ** Return new subject position. 'fr' is stack index where
90
- ** is the result; 'curr' is current subject position; 'limit'
91
- ** is subject's size.
92
- */
93
- static int resdyncaptures (lua_State *L, int fr, int curr, int limit) {
94
- lua_Integer res;
95
- if (!lua_toboolean(L, fr)) { /* false value? */
96
- lua_settop(L, fr - 1); /* remove results */
97
- return -1; /* and fail */
98
- }
99
- else if (lua_isboolean(L, fr)) /* true? */
100
- res = curr; /* keep current position */
101
- else {
102
- res = lua_tointeger(L, fr) - 1; /* new position */
103
- if (res < curr || res > limit)
104
- luaL_error(L, "invalid position returned by match-time capture");
105
- }
106
- lua_remove(L, fr); /* remove first result (offset) */
107
- return res;
108
- }
109
-
110
-
111
- /*
112
- ** Add capture values returned by a dynamic capture to the capture list
113
- ** 'base', nested inside a group capture. 'fd' indexes the first capture
114
- ** value, 'n' is the number of values (at least 1).
115
- */
116
- static void adddyncaptures (const char *s, Capture *base, int n, int fd) {
117
- int i;
118
- base[0].kind = Cgroup; /* create group capture */
119
- base[0].siz = 0;
120
- base[0].idx = 0; /* make it an anonymous group */
121
- for (i = 1; i <= n; i++) { /* add runtime captures */
122
- base[i].kind = Cruntime;
123
- base[i].siz = 1; /* mark it as closed */
124
- base[i].idx = fd + i - 1; /* stack index of capture value */
125
- base[i].s = s;
126
- }
127
- base[i].kind = Cclose; /* close group */
128
- base[i].siz = 1;
129
- base[i].s = s;
130
- }
131
-
132
-
133
- /*
134
- ** Remove dynamic captures from the Lua stack (called in case of failure)
135
- */
136
- static int removedyncap (lua_State *L, Capture *capture,
137
- int level, int last) {
138
- int id = finddyncap(capture + level, capture + last); /* index of 1st cap. */
139
- int top = lua_gettop(L);
140
- if (id == 0) return 0; /* no dynamic captures? */
141
- lua_settop(L, id - 1); /* remove captures */
142
- return top - id + 1; /* number of values removed */
143
- }
144
-
145
-
146
- /*
147
- ** Opcode interpreter
148
- */
149
- const char *match (lua_State *L, const char *o, const char *s, const char *e,
150
- Instruction *op, Capture *capture, int ptop) {
151
- Stack stackbase[INITBACK];
152
- Stack *stacklimit = stackbase + INITBACK;
153
- Stack *stack = stackbase; /* point to first empty slot in stack */
154
- int capsize = INITCAPSIZE;
155
- int captop = 0; /* point to first empty slot in captures */
156
- int ndyncap = 0; /* number of dynamic captures (in Lua stack) */
157
- const Instruction *p = op; /* current instruction */
158
- stack->p = &giveup; stack->s = s; stack->caplevel = 0; stack++;
159
- lua_pushlightuserdata(L, stackbase);
160
- for (;;) {
161
- #if defined(DEBUG)
162
- printf("-------------------------------------\n");
163
- printcaplist(capture, capture + captop);
164
- printf("s: |%s| stck:%d, dyncaps:%d, caps:%d ",
165
- s, (int)(stack - getstackbase(L, ptop)), ndyncap, captop);
166
- printinst(op, p);
167
- #endif
168
- assert(stackidx(ptop) + ndyncap == lua_gettop(L) && ndyncap <= captop);
169
- switch ((Opcode)p->i.code) {
170
- case IEnd: {
171
- assert(stack == getstackbase(L, ptop) + 1);
172
- capture[captop].kind = Cclose;
173
- capture[captop].s = NULL;
174
- return s;
175
- }
176
- case IGiveup: {
177
- assert(stack == getstackbase(L, ptop));
178
- return NULL;
179
- }
180
- case IRet: {
181
- assert(stack > getstackbase(L, ptop) && (stack - 1)->s == NULL);
182
- p = (--stack)->p;
183
- continue;
184
- }
185
- case IAny: {
186
- if (s < e) { p++; s++; }
187
- else goto fail;
188
- continue;
189
- }
190
- case ITestAny: {
191
- if (s < e) p += 2;
192
- else p += getoffset(p);
193
- continue;
194
- }
195
- case IChar: {
196
- if ((byte)*s == p->i.aux && s < e) { p++; s++; }
197
- else goto fail;
198
- continue;
199
- }
200
- case ITestChar: {
201
- if ((byte)*s == p->i.aux && s < e) p += 2;
202
- else p += getoffset(p);
203
- continue;
204
- }
205
- case ISet: {
206
- int c = (byte)*s;
207
- if (testchar((p+1)->buff, c) && s < e)
208
- { p += CHARSETINSTSIZE; s++; }
209
- else goto fail;
210
- continue;
211
- }
212
- case ITestSet: {
213
- int c = (byte)*s;
214
- if (testchar((p + 2)->buff, c) && s < e)
215
- p += 1 + CHARSETINSTSIZE;
216
- else p += getoffset(p);
217
- continue;
218
- }
219
- case IBehind: {
220
- int n = p->i.aux;
221
- if (n > s - o) goto fail;
222
- s -= n; p++;
223
- continue;
224
- }
225
- case ISpan: {
226
- for (; s < e; s++) {
227
- int c = (byte)*s;
228
- if (!testchar((p+1)->buff, c)) break;
229
- }
230
- p += CHARSETINSTSIZE;
231
- continue;
232
- }
233
- case IJmp: {
234
- p += getoffset(p);
235
- continue;
236
- }
237
- case IChoice: {
238
- if (stack == stacklimit)
239
- stack = doublestack(L, &stacklimit, ptop);
240
- stack->p = p + getoffset(p);
241
- stack->s = s;
242
- stack->caplevel = captop;
243
- stack++;
244
- p += 2;
245
- continue;
246
- }
247
- case ICall: {
248
- if (stack == stacklimit)
249
- stack = doublestack(L, &stacklimit, ptop);
250
- stack->s = NULL;
251
- stack->p = p + 2; /* save return address */
252
- stack++;
253
- p += getoffset(p);
254
- continue;
255
- }
256
- case ICommit: {
257
- assert(stack > getstackbase(L, ptop) && (stack - 1)->s != NULL);
258
- stack--;
259
- p += getoffset(p);
260
- continue;
261
- }
262
- case IPartialCommit: {
263
- assert(stack > getstackbase(L, ptop) && (stack - 1)->s != NULL);
264
- (stack - 1)->s = s;
265
- (stack - 1)->caplevel = captop;
266
- p += getoffset(p);
267
- continue;
268
- }
269
- case IBackCommit: {
270
- assert(stack > getstackbase(L, ptop) && (stack - 1)->s != NULL);
271
- s = (--stack)->s;
272
- captop = stack->caplevel;
273
- p += getoffset(p);
274
- continue;
275
- }
276
- case IFailTwice:
277
- assert(stack > getstackbase(L, ptop));
278
- stack--;
279
- /* go through */
280
- case IFail:
281
- fail: { /* pattern failed: try to backtrack */
282
- do { /* remove pending calls */
283
- assert(stack > getstackbase(L, ptop));
284
- s = (--stack)->s;
285
- } while (s == NULL);
286
- if (ndyncap > 0) /* is there matchtime captures? */
287
- ndyncap -= removedyncap(L, capture, stack->caplevel, captop);
288
- captop = stack->caplevel;
289
- p = stack->p;
290
- #if defined(DEBUG)
291
- printf("**FAIL**\n");
292
- #endif
293
- continue;
294
- }
295
- case ICloseRunTime: {
296
- CapState cs;
297
- int rem, res, n;
298
- int fr = lua_gettop(L) + 1; /* stack index of first result */
299
- cs.s = o; cs.L = L; cs.ocap = capture; cs.ptop = ptop;
300
- n = runtimecap(&cs, capture + captop, s, &rem); /* call function */
301
- captop -= n; /* remove nested captures */
302
- ndyncap -= rem; /* update number of dynamic captures */
303
- fr -= rem; /* 'rem' items were popped from Lua stack */
304
- res = resdyncaptures(L, fr, s - o, e - o); /* get result */
305
- if (res == -1) /* fail? */
306
- goto fail;
307
- s = o + res; /* else update current position */
308
- n = lua_gettop(L) - fr + 1; /* number of new captures */
309
- ndyncap += n; /* update number of dynamic captures */
310
- if (n > 0) { /* any new capture? */
311
- if (fr + n >= SHRT_MAX)
312
- luaL_error(L, "too many results in match-time capture");
313
- if ((captop += n + 2) >= capsize) {
314
- capture = doublecap(L, capture, captop, n + 2, ptop);
315
- capsize = 2 * captop;
316
- }
317
- /* add new captures to 'capture' list */
318
- adddyncaptures(s, capture + captop - n - 2, n, fr);
319
- }
320
- p++;
321
- continue;
322
- }
323
- case ICloseCapture: {
324
- const char *s1 = s;
325
- assert(captop > 0);
326
- /* if possible, turn capture into a full capture */
327
- if (capture[captop - 1].siz == 0 &&
328
- s1 - capture[captop - 1].s < UCHAR_MAX) {
329
- capture[captop - 1].siz = s1 - capture[captop - 1].s + 1;
330
- p++;
331
- continue;
332
- }
333
- else {
334
- capture[captop].siz = 1; /* mark entry as closed */
335
- capture[captop].s = s;
336
- goto pushcapture;
337
- }
338
- }
339
- case IOpenCapture:
340
- capture[captop].siz = 0; /* mark entry as open */
341
- capture[captop].s = s;
342
- goto pushcapture;
343
- case IFullCapture:
344
- capture[captop].siz = getoff(p) + 1; /* save capture size */
345
- capture[captop].s = s - getoff(p);
346
- /* goto pushcapture; */
347
- pushcapture: {
348
- capture[captop].idx = p->i.key;
349
- capture[captop].kind = getkind(p);
350
- if (++captop >= capsize) {
351
- capture = doublecap(L, capture, captop, 0, ptop);
352
- capsize = 2 * captop;
353
- }
354
- p++;
355
- continue;
356
- }
357
- default: assert(0); return NULL;
358
- }
359
- }
360
- }
361
-
362
- /* }====================================================== */
363
-
364
-