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.

backends.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 BACKENDS_H_
  17. #define BACKENDS_H_
  18. #include "config.h"
  19. #include "ucl.h"
  20. #define RSPAMD_DEFAULT_BACKEND "mmap"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Forwarded declarations */
  25. struct rspamd_classifier_config;
  26. struct rspamd_statfile_config;
  27. struct rspamd_config;
  28. struct rspamd_stat_ctx;
  29. struct rspamd_token_result;
  30. struct rspamd_statfile;
  31. struct rspamd_task;
  32. struct rspamd_stat_backend {
  33. const char *name;
  34. bool read_only;
  35. gpointer (*init)(struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg,
  36. struct rspamd_statfile *st);
  37. gpointer (*runtime)(struct rspamd_task *task,
  38. struct rspamd_statfile_config *stcf,
  39. gboolean learn, gpointer ctx,
  40. int id);
  41. gboolean (*process_tokens)(struct rspamd_task *task, GPtrArray *tokens,
  42. int id,
  43. gpointer ctx);
  44. gboolean (*finalize_process)(struct rspamd_task *task,
  45. gpointer runtime, gpointer ctx);
  46. gboolean (*learn_tokens)(struct rspamd_task *task, GPtrArray *tokens,
  47. int id,
  48. gpointer ctx);
  49. gulong (*total_learns)(struct rspamd_task *task,
  50. gpointer runtime, gpointer ctx);
  51. gboolean (*finalize_learn)(struct rspamd_task *task,
  52. gpointer runtime, gpointer ctx, GError **err);
  53. gulong (*inc_learns)(struct rspamd_task *task,
  54. gpointer runtime, gpointer ctx);
  55. gulong (*dec_learns)(struct rspamd_task *task,
  56. gpointer runtime, gpointer ctx);
  57. ucl_object_t *(*get_stat)(gpointer runtime, gpointer ctx);
  58. void (*close)(gpointer ctx);
  59. gpointer (*load_tokenizer_config)(gpointer runtime, gsize *sz);
  60. gpointer ctx;
  61. };
  62. #define RSPAMD_STAT_BACKEND_DEF(name) \
  63. gpointer rspamd_##name##_init(struct rspamd_stat_ctx *ctx, \
  64. struct rspamd_config *cfg, struct rspamd_statfile *st); \
  65. gpointer rspamd_##name##_runtime(struct rspamd_task *task, \
  66. struct rspamd_statfile_config *stcf, \
  67. gboolean learn, gpointer ctx, int id); \
  68. gboolean rspamd_##name##_process_tokens(struct rspamd_task *task, \
  69. GPtrArray *tokens, int id, \
  70. gpointer runtime); \
  71. gboolean rspamd_##name##_finalize_process(struct rspamd_task *task, \
  72. gpointer runtime, \
  73. gpointer ctx); \
  74. gboolean rspamd_##name##_learn_tokens(struct rspamd_task *task, \
  75. GPtrArray *tokens, int id, \
  76. gpointer runtime); \
  77. gboolean rspamd_##name##_finalize_learn(struct rspamd_task *task, \
  78. gpointer runtime, \
  79. gpointer ctx, GError **err); \
  80. gulong rspamd_##name##_total_learns(struct rspamd_task *task, \
  81. gpointer runtime, \
  82. gpointer ctx); \
  83. gulong rspamd_##name##_inc_learns(struct rspamd_task *task, \
  84. gpointer runtime, \
  85. gpointer ctx); \
  86. gulong rspamd_##name##_dec_learns(struct rspamd_task *task, \
  87. gpointer runtime, \
  88. gpointer ctx); \
  89. gulong rspamd_##name##_learns(struct rspamd_task *task, \
  90. gpointer runtime, \
  91. gpointer ctx); \
  92. ucl_object_t *rspamd_##name##_get_stat(gpointer runtime, \
  93. gpointer ctx); \
  94. gpointer rspamd_##name##_load_tokenizer_config(gpointer runtime, \
  95. gsize *len); \
  96. void rspamd_##name##_close(gpointer ctx)
  97. RSPAMD_STAT_BACKEND_DEF(mmaped_file);
  98. RSPAMD_STAT_BACKEND_DEF(sqlite3);
  99. RSPAMD_STAT_BACKEND_DEF(cdb);
  100. RSPAMD_STAT_BACKEND_DEF(redis);
  101. RSPAMD_STAT_BACKEND_DEF(http);
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif /* BACKENDS_H_ */