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.

stat_internal.h 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 STAT_INTERNAL_H_
  17. #define STAT_INTERNAL_H_
  18. #include "config.h"
  19. #include "task.h"
  20. #include "ref.h"
  21. #include "classifiers/classifiers.h"
  22. #include "tokenizers/tokenizers.h"
  23. #include "backends/backends.h"
  24. #include "learn_cache/learn_cache.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. struct rspamd_statfile_runtime {
  29. struct rspamd_statfile_config *st;
  30. gpointer backend_runtime;
  31. uint64_t hits;
  32. uint64_t total_hits;
  33. };
  34. /* Common classifier structure */
  35. struct rspamd_classifier {
  36. struct rspamd_stat_ctx *ctx;
  37. GArray *statfiles_ids; /* int */
  38. struct rspamd_stat_cache *cache;
  39. gpointer cachecf;
  40. gulong spam_learns;
  41. gulong ham_learns;
  42. gint autolearn_cbref;
  43. struct rspamd_classifier_config *cfg;
  44. struct rspamd_stat_classifier *subrs;
  45. gpointer specific;
  46. };
  47. struct rspamd_statfile {
  48. gint id;
  49. struct rspamd_statfile_config *stcf;
  50. struct rspamd_classifier *classifier;
  51. struct rspamd_stat_backend *backend;
  52. gpointer bkcf;
  53. };
  54. struct rspamd_stat_async_elt;
  55. typedef void (*rspamd_stat_async_handler)(struct rspamd_stat_async_elt *elt,
  56. gpointer ud);
  57. typedef void (*rspamd_stat_async_cleanup)(struct rspamd_stat_async_elt *elt,
  58. gpointer ud);
  59. struct rspamd_stat_async_elt {
  60. rspamd_stat_async_handler handler;
  61. rspamd_stat_async_cleanup cleanup;
  62. struct ev_loop *event_loop;
  63. ev_timer timer_ev;
  64. gdouble timeout;
  65. gboolean enabled;
  66. gpointer ud;
  67. ref_entry_t ref;
  68. };
  69. struct rspamd_stat_ctx {
  70. /* Subroutines for all objects */
  71. struct rspamd_stat_classifier *classifiers_subrs;
  72. guint classifiers_count;
  73. struct rspamd_stat_tokenizer *tokenizers_subrs;
  74. guint tokenizers_count;
  75. struct rspamd_stat_backend *backends_subrs;
  76. guint backends_count;
  77. struct rspamd_stat_cache *caches_subrs;
  78. guint caches_count;
  79. /* Runtime configuration */
  80. GPtrArray *statfiles; /* struct rspamd_statfile */
  81. GPtrArray *classifiers; /* struct rspamd_classifier */
  82. GQueue *async_elts; /* struct rspamd_stat_async_elt */
  83. struct rspamd_config *cfg;
  84. gint lua_stat_tokens_ref;
  85. /* Global tokenizer */
  86. struct rspamd_stat_tokenizer *tokenizer;
  87. gpointer tkcf;
  88. struct ev_loop *event_loop;
  89. };
  90. typedef enum rspamd_learn_cache_result {
  91. RSPAMD_LEARN_OK = 0,
  92. RSPAMD_LEARN_UNLEARN,
  93. RSPAMD_LEARN_IGNORE
  94. } rspamd_learn_t;
  95. struct rspamd_stat_ctx *rspamd_stat_get_ctx(void);
  96. struct rspamd_stat_classifier *rspamd_stat_get_classifier(const gchar *name);
  97. struct rspamd_stat_backend *rspamd_stat_get_backend(const gchar *name);
  98. struct rspamd_stat_tokenizer *rspamd_stat_get_tokenizer(const gchar *name);
  99. struct rspamd_stat_cache *rspamd_stat_get_cache(const gchar *name);
  100. struct rspamd_stat_async_elt *rspamd_stat_ctx_register_async(
  101. rspamd_stat_async_handler handler, rspamd_stat_async_cleanup cleanup,
  102. gpointer d, gdouble timeout);
  103. static GQuark rspamd_stat_quark(void)
  104. {
  105. return g_quark_from_static_string("rspamd-statistics");
  106. }
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif /* STAT_INTERNAL_H_ */