Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

lua_common.h 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. #ifndef RSPAMD_LUA_H
  2. #define RSPAMD_LUA_H
  3. #include "config.h"
  4. /* Lua headers do not have __cplusplus guards... */
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #include <lua.h>
  9. #include <lauxlib.h>
  10. #include <lualib.h>
  11. #ifdef WITH_LUAJIT
  12. #include <luajit.h>
  13. #endif
  14. #ifdef __cplusplus
  15. }
  16. #endif
  17. #include <stdbool.h>
  18. #include "rspamd.h"
  19. #include "ucl.h"
  20. #include "lua_ucl.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #ifndef lua_open
  25. #define lua_open() luaL_newstate ()
  26. #endif
  27. #ifndef luaL_reg
  28. #define luaL_reg luaL_Reg
  29. #endif
  30. #define LUA_ENUM(L, name, val) \
  31. lua_pushlstring (L, # name, sizeof(# name) - 1); \
  32. lua_pushinteger (L, val); \
  33. lua_settable (L, -3);
  34. #if LUA_VERSION_NUM > 501 && !defined LUA_COMPAT_MODULE
  35. static inline void
  36. luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods)
  37. {
  38. if (name != NULL) {
  39. lua_newtable (L);
  40. }
  41. luaL_setfuncs (L, methods, 0);
  42. if (name != NULL) {
  43. lua_pushvalue (L, -1);
  44. lua_setglobal (L, name);
  45. }
  46. }
  47. #endif
  48. #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501
  49. /* Special hack to work with moonjit of specific version */
  50. #if !defined(MOONJIT_VERSION) && (!defined(LUAJIT_VERSION_NUM) || LUAJIT_VERSION_NUM != 20200)
  51. static inline int lua_absindex (lua_State *L, int i) {
  52. if (i < 0 && i > LUA_REGISTRYINDEX)
  53. i += lua_gettop(L) + 1;
  54. return i;
  55. }
  56. #endif
  57. static inline int lua_rawgetp (lua_State *L, int i, const void *p) {
  58. int abs_i = lua_absindex(L, i);
  59. lua_pushlightuserdata(L, (void*)p);
  60. lua_rawget(L, abs_i);
  61. return lua_type(L, -1);
  62. }
  63. static inline void lua_rawsetp (lua_State *L, int i, const void *p) {
  64. int abs_i = lua_absindex(L, i);
  65. luaL_checkstack(L, 1, "not enough stack slots");
  66. lua_pushlightuserdata(L, (void*)p);
  67. lua_insert(L, -2);
  68. lua_rawset(L, abs_i);
  69. }
  70. #endif
  71. /* Interface definitions */
  72. #define LUA_FUNCTION_DEF(class, name) static int lua_##class##_##name (lua_State * L)
  73. #define LUA_PUBLIC_FUNCTION_DEF(class, name) int lua_##class##_##name (lua_State * L)
  74. #define LUA_INTERFACE_DEF(class, name) { #name, lua_##class##_##name }
  75. extern const luaL_reg null_reg[];
  76. #define RSPAMD_LUA_API_VERSION 12
  77. /* Locked lua state with mutex */
  78. struct lua_locked_state {
  79. lua_State *L;
  80. rspamd_mutex_t *m;
  81. };
  82. /**
  83. * Lua IP address structure
  84. */
  85. struct rspamd_lua_ip {
  86. rspamd_inet_addr_t *addr;
  87. };
  88. #define RSPAMD_TEXT_FLAG_OWN (1u << 0u)
  89. #define RSPAMD_TEXT_FLAG_MMAPED (1u << 1u)
  90. #define RSPAMD_TEXT_FLAG_WIPE (1u << 2u)
  91. #define RSPAMD_TEXT_FLAG_SYSMALLOC (1u << 3u)
  92. #define RSPAMD_TEXT_FLAG_FAKE (1u << 4u)
  93. struct rspamd_lua_text {
  94. const gchar *start;
  95. guint len;
  96. guint flags;
  97. };
  98. struct rspamd_lua_url {
  99. struct rspamd_url *url;
  100. };
  101. struct rspamd_lua_regexp {
  102. rspamd_regexp_t *re;
  103. gchar *module;
  104. gchar *re_pattern;
  105. gint re_flags;
  106. };
  107. struct rspamd_map;
  108. struct lua_map_callback_data;
  109. struct radix_tree_compressed;
  110. struct rspamd_mime_header;
  111. enum rspamd_lua_map_type {
  112. RSPAMD_LUA_MAP_RADIX = 0,
  113. RSPAMD_LUA_MAP_SET,
  114. RSPAMD_LUA_MAP_HASH,
  115. RSPAMD_LUA_MAP_REGEXP,
  116. RSPAMD_LUA_MAP_REGEXP_MULTIPLE,
  117. RSPAMD_LUA_MAP_CALLBACK,
  118. RSPAMD_LUA_MAP_CDB,
  119. RSPAMD_LUA_MAP_UNKNOWN,
  120. };
  121. struct rspamd_lua_map {
  122. struct rspamd_map *map;
  123. enum rspamd_lua_map_type type;
  124. guint flags;
  125. union {
  126. struct rspamd_radix_map_helper *radix;
  127. struct rspamd_hash_map_helper *hash;
  128. struct rspamd_regexp_map_helper *re_map;
  129. struct rspamd_cdb_map_helper *cdb_map;
  130. struct lua_map_callback_data *cbdata;
  131. } data;
  132. };
  133. struct rspamd_lua_cached_entry {
  134. gint ref;
  135. guint id;
  136. };
  137. /* Common utility functions */
  138. /**
  139. * Create and register new class
  140. */
  141. void rspamd_lua_new_class (lua_State *L,
  142. const gchar *classname,
  143. const struct luaL_reg *methods);
  144. /**
  145. * Set class name for object at @param objidx position
  146. */
  147. void rspamd_lua_setclass (lua_State *L, const gchar *classname, gint objidx);
  148. /**
  149. * Pushes the metatable for specific class on top of the stack
  150. * @param L
  151. * @param classname
  152. */
  153. void rspamd_lua_class_metatable (lua_State *L, const gchar *classname);
  154. /**
  155. * Adds a new field to the class (metatable) identified by `classname`
  156. * @param L
  157. * @param classname
  158. * @param meth
  159. */
  160. void rspamd_lua_add_metamethod (lua_State *L, const gchar *classname,
  161. luaL_Reg *meth);
  162. /**
  163. * Set index of table to value (like t['index'] = value)
  164. */
  165. void rspamd_lua_table_set (lua_State *L, const gchar *index, const gchar *value);
  166. /**
  167. * Get string value of index in a table (return t['index'])
  168. */
  169. const gchar *rspamd_lua_table_get (lua_State *L, const gchar *index);
  170. /**
  171. * Convert classname to string
  172. */
  173. gint rspamd_lua_class_tostring (lua_State *L);
  174. /**
  175. * Check whether the argument at specified index is of the specified class
  176. */
  177. gpointer rspamd_lua_check_class (lua_State *L, gint index, const gchar *name);
  178. /**
  179. * Initialize lua and bindings
  180. */
  181. lua_State *rspamd_lua_init (bool wipe_mem);
  182. void rspamd_lua_start_gc (struct rspamd_config *cfg);
  183. /**
  184. * Sets field in a global variable
  185. * @param L
  186. * @param global_name
  187. * @param field_name
  188. * @param new_elt
  189. */
  190. void
  191. rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name,
  192. const gchar *new_elt);
  193. /**
  194. * Load and initialize lua plugins
  195. */
  196. gboolean
  197. rspamd_init_lua_filters (struct rspamd_config *cfg, bool force_load, bool strict);
  198. /**
  199. * Initialize new locked lua_State structure
  200. */
  201. struct lua_locked_state *rspamd_init_lua_locked (struct rspamd_config *cfg);
  202. /**
  203. * Free locked state structure
  204. */
  205. void rspamd_free_lua_locked (struct lua_locked_state *st);
  206. /**
  207. * Push lua ip address
  208. */
  209. void rspamd_lua_ip_push (lua_State *L, rspamd_inet_addr_t *addr);
  210. /**
  211. * Push rspamd task structure to lua
  212. */
  213. void rspamd_lua_task_push (lua_State *L, struct rspamd_task *task);
  214. /**
  215. * Return lua ip structure at the specified address
  216. */
  217. struct rspamd_lua_ip *lua_check_ip (lua_State *L, gint pos);
  218. struct rspamd_lua_text *lua_check_text (lua_State *L, gint pos);
  219. /**
  220. * Checks for a text or a string. In case of string a pointer to static structure is returned.
  221. * So it should not be reused or placed to Lua stack anyhow!
  222. * However, you can use this function up to 4 times and have distinct static structures
  223. * @param L
  224. * @param pos
  225. * @return
  226. */
  227. struct rspamd_lua_text *lua_check_text_or_string (lua_State *L, gint pos);
  228. /* Creates and *pushes* new rspamd text, data is copied if RSPAMD_TEXT_FLAG_OWN is in flags*/
  229. struct rspamd_lua_text *lua_new_text (lua_State *L, const gchar *start,
  230. gsize len, gboolean own);
  231. struct rspamd_lua_regexp *lua_check_regexp (lua_State *L, gint pos);
  232. enum rspamd_lua_task_header_type {
  233. RSPAMD_TASK_HEADER_PUSH_SIMPLE = 0,
  234. RSPAMD_TASK_HEADER_PUSH_RAW,
  235. RSPAMD_TASK_HEADER_PUSH_FULL,
  236. RSPAMD_TASK_HEADER_PUSH_COUNT,
  237. RSPAMD_TASK_HEADER_PUSH_HAS,
  238. };
  239. gint rspamd_lua_push_header (lua_State *L,
  240. struct rspamd_mime_header *h,
  241. enum rspamd_lua_task_header_type how);
  242. /**
  243. * Push specific header to lua
  244. */
  245. gint rspamd_lua_push_header_array (lua_State *L,
  246. const gchar *name,
  247. struct rspamd_mime_header *rh,
  248. enum rspamd_lua_task_header_type how,
  249. gboolean strong);
  250. /**
  251. * Check for task at the specified position
  252. */
  253. struct rspamd_task *lua_check_task (lua_State *L, gint pos);
  254. struct rspamd_task *lua_check_task_maybe (lua_State *L, gint pos);
  255. struct rspamd_lua_map *lua_check_map (lua_State *L, gint pos);
  256. /**
  257. * Push ip address from a string (nil is pushed if a string cannot be converted)
  258. */
  259. void rspamd_lua_ip_push_fromstring (lua_State *L, const gchar *ip_str);
  260. /**
  261. * Create type error
  262. */
  263. int rspamd_lua_typerror (lua_State *L, int narg, const char *tname);
  264. /**
  265. * Open libraries functions
  266. */
  267. /**
  268. * Add preload function
  269. */
  270. void rspamd_lua_add_preload (lua_State *L, const gchar *name, lua_CFunction func);
  271. void luaopen_task (lua_State *L);
  272. void luaopen_config (lua_State *L);
  273. void luaopen_map (lua_State *L);
  274. void luaopen_trie (lua_State *L);
  275. void luaopen_textpart (lua_State *L);
  276. void luaopen_mimepart (lua_State *L);
  277. void luaopen_image (lua_State *L);
  278. void luaopen_url (lua_State *L);
  279. void luaopen_classifier (lua_State *L);
  280. void luaopen_statfile (lua_State *L);
  281. void luaopen_regexp (lua_State *L);
  282. void luaopen_cdb (lua_State *L);
  283. void luaopen_xmlrpc (lua_State *L);
  284. void luaopen_http (lua_State *L);
  285. void luaopen_redis (lua_State *L);
  286. void luaopen_upstream (lua_State *L);
  287. void luaopen_mempool (lua_State *L);
  288. void luaopen_dns_resolver (lua_State *L);
  289. void luaopen_rsa (lua_State *L);
  290. void luaopen_ip (lua_State *L);
  291. void luaopen_expression (lua_State *L);
  292. void luaopen_logger (lua_State *L);
  293. void luaopen_text (lua_State *L);
  294. void luaopen_util (lua_State *L);
  295. void luaopen_tcp (lua_State *L);
  296. void luaopen_html (lua_State *L);
  297. void luaopen_sqlite3 (lua_State *L);
  298. void luaopen_cryptobox (lua_State *L);
  299. void luaopen_dns (lua_State *L);
  300. void luaopen_udp (lua_State *L);
  301. void luaopen_worker (lua_State *L);
  302. void luaopen_kann (lua_State *L);
  303. void luaopen_spf (lua_State *L);
  304. void luaopen_tensor (lua_State *L);
  305. void luaopen_parsers (lua_State *L);
  306. void rspamd_lua_dostring (const gchar *line);
  307. double rspamd_lua_normalize (struct rspamd_config *cfg,
  308. long double score,
  309. void *params);
  310. /* Config file functions */
  311. void rspamd_lua_post_load_config (struct rspamd_config *cfg);
  312. gboolean rspamd_lua_handle_param (struct rspamd_task *task,
  313. gchar *mname,
  314. gchar *optname,
  315. enum lua_var_type expected_type,
  316. gpointer *res);
  317. gboolean rspamd_lua_check_condition (struct rspamd_config *cfg,
  318. const gchar *condition);
  319. void rspamd_lua_dumpstack (lua_State *L);
  320. /* Set lua path according to the configuration */
  321. void rspamd_lua_set_path (lua_State *L, const ucl_object_t *cfg_obj,
  322. GHashTable *vars);
  323. /* Set some lua globals */
  324. gboolean rspamd_lua_set_env (lua_State *L, GHashTable *vars, char **lua_env,
  325. GError **err);
  326. void rspamd_lua_set_globals (struct rspamd_config *cfg, lua_State *L);
  327. struct memory_pool_s *rspamd_lua_check_mempool (lua_State *L, gint pos);
  328. struct rspamd_config *lua_check_config (lua_State *L, gint pos);
  329. struct rspamd_async_session *lua_check_session (lua_State *L, gint pos);
  330. struct ev_loop *lua_check_ev_base (lua_State *L, gint pos);
  331. struct rspamd_dns_resolver *lua_check_dns_resolver (lua_State *L, gint pos);
  332. struct rspamd_lua_url *lua_check_url (lua_State * L, gint pos);
  333. enum rspamd_lua_parse_arguments_flags {
  334. RSPAMD_LUA_PARSE_ARGUMENTS_DEFAULT = 0,
  335. RSPAMD_LUA_PARSE_ARGUMENTS_IGNORE_MISSING,
  336. };
  337. /**
  338. * Extract an arguments from lua table according to format string. Supported arguments are:
  339. * [*]key=S|I|N|B|V|U{a-z};[key=...]
  340. * - S - const char *
  341. * - I - gint64_t
  342. * - i - int32_t
  343. * - N - double
  344. * - B - gboolean
  345. * - V - size_t + const char *
  346. * - U{classname} - userdata of the following class (stored in gpointer)
  347. * - F - function
  348. * - O - ucl_object_t *
  349. * - D - same as N but argument is set to NAN not to 0.0
  350. * - u{classname} - userdata of the following class (stored directly)
  351. *
  352. * If any of keys is prefixed with `*` then it is treated as required argument
  353. * @param L lua state
  354. * @param pos at which pos start extraction
  355. * @param err error pointer
  356. * @param how extraction type (IGNORE_MISSING means that default values will not be set)
  357. * @param extraction_pattern static pattern
  358. * @return TRUE if a table has been parsed
  359. */
  360. gboolean rspamd_lua_parse_table_arguments (lua_State *L, gint pos,
  361. GError **err,
  362. enum rspamd_lua_parse_arguments_flags how,
  363. const gchar *extraction_pattern, ...);
  364. gint rspamd_lua_traceback (lua_State *L);
  365. /**
  366. * Returns stack trace as a string. Caller should clear memory.
  367. * @param L
  368. * @return
  369. */
  370. void rspamd_lua_get_traceback_string (lua_State *L, luaL_Buffer *buf);
  371. /**
  372. * Returns size of table at position `tbl_pos`
  373. */
  374. guint rspamd_lua_table_size (lua_State *L, gint tbl_pos);
  375. void lua_push_emails_address_list (lua_State *L, GPtrArray *addrs, int flags);
  376. #define TRACE_POINTS 6
  377. struct lua_logger_trace {
  378. gint cur_level;
  379. gconstpointer traces[TRACE_POINTS];
  380. };
  381. enum lua_logger_escape_type {
  382. LUA_ESCAPE_NONE = (0u),
  383. LUA_ESCAPE_UNPRINTABLE = (1u << 0u),
  384. LUA_ESCAPE_NEWLINES = (1u << 1u),
  385. LUA_ESCAPE_8BIT = (1u << 2u),
  386. };
  387. #define LUA_ESCAPE_LOG (LUA_ESCAPE_UNPRINTABLE|LUA_ESCAPE_NEWLINES)
  388. #define LUA_ESCAPE_ALL (LUA_ESCAPE_UNPRINTABLE|LUA_ESCAPE_NEWLINES|LUA_ESCAPE_8BIT)
  389. /**
  390. * Log lua object to string
  391. * @param L
  392. * @param pos
  393. * @param outbuf
  394. * @param len
  395. * @return
  396. */
  397. gsize lua_logger_out_type (lua_State *L, gint pos, gchar *outbuf,
  398. gsize len, struct lua_logger_trace *trace,
  399. enum lua_logger_escape_type esc_type);
  400. /**
  401. * Safely checks userdata to match specified class
  402. * @param L
  403. * @param pos
  404. * @param classname
  405. */
  406. void *rspamd_lua_check_udata (lua_State *L, gint pos, const gchar *classname);
  407. #define RSPAMD_LUA_CHECK_UDATA_PTR_OR_RETURN(L, pos, classname, type, dest) do { \
  408. type **_maybe_ptr = (type **)rspamd_lua_check_udata((L), (pos), (classname)); \
  409. if (_maybe_ptr == NULL) { \
  410. return luaL_error (L, "%s: invalid arguments; pos = %d; expected = %s", G_STRFUNC, (pos), (classname)); \
  411. } \
  412. (dest) = *(_maybe_ptr); \
  413. } while(0)
  414. /**
  415. * Safely checks userdata to match specified class
  416. * @param L
  417. * @param pos
  418. * @param classname
  419. */
  420. void *rspamd_lua_check_udata_maybe (lua_State *L, gint pos, const gchar *classname);
  421. /**
  422. * Call finishing script with the specified task
  423. * @param sc
  424. * @param task
  425. */
  426. void lua_call_finish_script (struct rspamd_config_cfg_lua_script *sc,
  427. struct rspamd_task *task);
  428. /**
  429. * Run post-load operations
  430. * @param L
  431. * @param cfg
  432. * @param ev_base
  433. */
  434. void rspamd_lua_run_postloads (lua_State *L, struct rspamd_config *cfg,
  435. struct ev_loop *ev_base, struct rspamd_worker *w);
  436. void rspamd_lua_run_config_post_init (lua_State *L, struct rspamd_config *cfg);
  437. void rspamd_lua_run_config_unload (lua_State *L, struct rspamd_config *cfg);
  438. /**
  439. * Adds new destructor for a local function for specific pool
  440. * @param L
  441. * @param pool
  442. * @param ref
  443. */
  444. void rspamd_lua_add_ref_dtor (lua_State *L, rspamd_mempool_t *pool,
  445. gint ref);
  446. /**
  447. * Returns a lua reference from a function like string, e.g. `return function(...) end`
  448. * @param L
  449. * @param str
  450. * @return
  451. */
  452. gint rspamd_lua_function_ref_from_str (lua_State *L, const gchar *str, gsize slen,
  453. const gchar *modname, GError **err);
  454. /**
  455. * Tries to load some module using `require` and get some method from it
  456. * @param L
  457. * @param modname
  458. * @param funcname
  459. * @return TRUE if function exists in that module, the function is pushed in stack, otherwise stack is unchanged and FALSE is returned
  460. */
  461. gboolean rspamd_lua_require_function (lua_State *L, const gchar *modname,
  462. const gchar *funcname);
  463. /**
  464. * Tries to load redis server definition from ucl object specified
  465. * @param L
  466. * @param obj
  467. * @param cfg
  468. * @return
  469. */
  470. gboolean rspamd_lua_try_load_redis (lua_State *L, const ucl_object_t *obj,
  471. struct rspamd_config *cfg, gint *ref_id);
  472. struct rspamd_stat_token_s;
  473. /**
  474. * Pushes a single word into Lua
  475. * @param L
  476. * @param word
  477. */
  478. void rspamd_lua_push_full_word (lua_State *L, struct rspamd_stat_token_s *word);
  479. enum rspamd_lua_words_type {
  480. RSPAMD_LUA_WORDS_STEM = 0,
  481. RSPAMD_LUA_WORDS_NORM,
  482. RSPAMD_LUA_WORDS_RAW,
  483. RSPAMD_LUA_WORDS_FULL,
  484. RSPAMD_LUA_WORDS_MAX
  485. };
  486. /**
  487. * Pushes words (rspamd_stat_token_t) to Lua
  488. * @param L
  489. * @param words
  490. * @param how
  491. */
  492. gint rspamd_lua_push_words (lua_State *L, GArray *words,
  493. enum rspamd_lua_words_type how);
  494. /**
  495. * Returns newly allocated name for caller module name
  496. * @param L
  497. * @return
  498. */
  499. gchar *rspamd_lua_get_module_name (lua_State *L);
  500. /**
  501. * Call Lua function in a universal way. Arguments string:
  502. * - i - lua_integer, argument - gint64
  503. * - n - lua_number, argument - gdouble
  504. * - s - lua_string, argument - const gchar * (zero terminated)
  505. * - l - lua_lstring, argument - (size_t + const gchar *) pair
  506. * - u - lua_userdata, argument - (const char * + void *) - classname + pointer
  507. * - b - lua_boolean, argument - gboolean (not bool due to varargs promotion)
  508. * - f - lua_function, argument - int - position of the function on stack (not lua_registry)
  509. * - t - lua_text, argument - int - position of the lua_text on stack (not lua_registry)
  510. * @param L lua state
  511. * @param cbref LUA_REGISTRY reference
  512. * @param strloc where this function is called from
  513. * @param nret number of results (or LUA_MULTRET)
  514. * @param args arguments format string
  515. * @param err error to promote
  516. * @param ... arguments
  517. * @return true of pcall returned 0, false + err otherwise
  518. */
  519. bool rspamd_lua_universal_pcall (lua_State *L, gint cbref, const gchar* strloc,
  520. gint nret, const gchar *args, GError **err, ...);
  521. /**
  522. * Wrapper for lua_geti from lua 5.3
  523. * @param L
  524. * @param index
  525. * @param i
  526. * @return
  527. */
  528. #if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502
  529. gint rspamd_lua_geti (lua_State *L, int index, int i);
  530. #else
  531. #define rspamd_lua_geti lua_geti
  532. #endif
  533. /* Paths defs */
  534. #define RSPAMD_CONFDIR_INDEX "CONFDIR"
  535. #define RSPAMD_LOCAL_CONFDIR_INDEX "LOCAL_CONFDIR"
  536. #define RSPAMD_RUNDIR_INDEX "RUNDIR"
  537. #define RSPAMD_DBDIR_INDEX "DBDIR"
  538. #define RSPAMD_LOGDIR_INDEX "LOGDIR"
  539. #define RSPAMD_PLUGINSDIR_INDEX "PLUGINSDIR"
  540. #define RSPAMD_SHAREDIR_INDEX "SHAREDIR"
  541. #define RSPAMD_RULESDIR_INDEX "RULESDIR"
  542. #define RSPAMD_LUALIBDIR_INDEX "LUALIBDIR"
  543. #define RSPAMD_WWWDIR_INDEX "WWWDIR"
  544. #define RSPAMD_PREFIX_INDEX "PREFIX"
  545. #define RSPAMD_VERSION_INDEX "VERSION"
  546. #ifdef WITH_LUA_TRACE
  547. extern ucl_object_t *lua_traces;
  548. #define LUA_TRACE_POINT do { \
  549. ucl_object_t *func_obj; \
  550. if (lua_traces == NULL) { lua_traces = ucl_object_typed_new (UCL_OBJECT); } \
  551. func_obj = (ucl_object_t *)ucl_object_lookup (lua_traces, G_STRFUNC); \
  552. if (func_obj == NULL) { \
  553. func_obj = ucl_object_typed_new (UCL_INT); \
  554. ucl_object_insert_key (lua_traces, func_obj, G_STRFUNC, 0, false); \
  555. } \
  556. func_obj->value.iv ++; \
  557. } while(0)
  558. #else
  559. #define LUA_TRACE_POINT do {} while(0)
  560. #endif
  561. #ifdef __cplusplus
  562. }
  563. #endif
  564. #endif /* RSPAMD_LUA_H */