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.0KB

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