You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lua_url.h 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*-
  2. * Copyright 2020 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef RSPAMD_LUA_URL_H
  17. #define RSPAMD_LUA_URL_H
  18. #include "lua_common.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. struct lua_tree_cb_data {
  23. lua_State *L;
  24. int i;
  25. int metatable_pos;
  26. unsigned int flags_mask;
  27. unsigned int flags_exclude_mask;
  28. unsigned int protocols_mask;
  29. enum {
  30. url_flags_mode_include_any,
  31. url_flags_mode_include_explicit,
  32. url_flags_mode_exclude_include,
  33. } flags_mode;
  34. gboolean sort;
  35. gsize max_urls;
  36. double skip_prob;
  37. uint64_t random_seed;
  38. };
  39. void lua_tree_url_callback(gpointer key, gpointer value, gpointer ud);
  40. /**
  41. * Fills a cbdata table based on the parameter at position pos
  42. * @param L
  43. * @param pos
  44. * @param cbd
  45. * @return
  46. */
  47. gboolean lua_url_cbdata_fill(lua_State *L, int pos,
  48. struct lua_tree_cb_data *cbd,
  49. unsigned int default_protocols,
  50. unsigned int default_flags,
  51. gsize max_urls);
  52. gboolean lua_url_cbdata_fill_exclude_include(lua_State *L, int pos,
  53. struct lua_tree_cb_data *cbd,
  54. unsigned int default_protocols,
  55. gsize max_urls);
  56. /**
  57. * Cleanup url cbdata
  58. * @param cbd
  59. */
  60. void lua_url_cbdata_dtor(struct lua_tree_cb_data *cbd);
  61. /**
  62. * Adjust probabilistic skip of the urls
  63. * @param timestamp
  64. * @param digest
  65. * @param cb
  66. * @param sz
  67. * @param max_urls
  68. * @return
  69. */
  70. gsize lua_url_adjust_skip_prob(float timestamp,
  71. unsigned char digest[16],
  72. struct lua_tree_cb_data *cb,
  73. gsize sz);
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif