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.

learn_cache.h 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*-
  2. * Copyright 2016 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 LEARN_CACHE_H_
  17. #define LEARN_CACHE_H_
  18. #include "config.h"
  19. #include "ucl.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define RSPAMD_DEFAULT_CACHE "sqlite3"
  24. struct rspamd_task;
  25. struct rspamd_stat_ctx;
  26. struct rspamd_config;
  27. struct rspamd_statfile;
  28. struct rspamd_stat_cache {
  29. const char *name;
  30. gpointer (*init)(struct rspamd_stat_ctx *ctx,
  31. struct rspamd_config *cfg,
  32. struct rspamd_statfile *st,
  33. const ucl_object_t *cf);
  34. gpointer (*runtime)(struct rspamd_task *task,
  35. gpointer ctx, gboolean learn);
  36. int (*check)(struct rspamd_task *task,
  37. gboolean is_spam,
  38. gpointer runtime);
  39. int (*learn)(struct rspamd_task *task,
  40. gboolean is_spam,
  41. gpointer runtime);
  42. void (*close)(gpointer ctx);
  43. gpointer ctx;
  44. };
  45. #define RSPAMD_STAT_CACHE_DEF(name) \
  46. gpointer rspamd_stat_cache_##name##_init(struct rspamd_stat_ctx *ctx, \
  47. struct rspamd_config *cfg, \
  48. struct rspamd_statfile *st, \
  49. const ucl_object_t *cf); \
  50. gpointer rspamd_stat_cache_##name##_runtime(struct rspamd_task *task, \
  51. gpointer ctx, gboolean learn); \
  52. int rspamd_stat_cache_##name##_check(struct rspamd_task *task, \
  53. gboolean is_spam, \
  54. gpointer runtime); \
  55. int rspamd_stat_cache_##name##_learn(struct rspamd_task *task, \
  56. gboolean is_spam, \
  57. gpointer runtime); \
  58. void rspamd_stat_cache_##name##_close(gpointer ctx)
  59. RSPAMD_STAT_CACHE_DEF(sqlite3);
  60. RSPAMD_STAT_CACHE_DEF(redis);
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* LEARN_CACHE_H_ */