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_api.h 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_API_H_
  17. #define STAT_API_H_
  18. #include "config.h"
  19. #include "task.h"
  20. #include <lua.h>
  21. #include <event.h>
  22. /**
  23. * @file stat_api.h
  24. * High level statistics API
  25. */
  26. /**
  27. * The results of statistics processing:
  28. * - error
  29. * - need to do additional job for processing
  30. * - all processed
  31. */
  32. typedef enum rspamd_stat_result_e {
  33. RSPAMD_STAT_PROCESS_ERROR = 0,
  34. RSPAMD_STAT_PROCESS_DELAYED = 1,
  35. RSPAMD_STAT_PROCESS_OK
  36. } rspamd_stat_result_t;
  37. /**
  38. * Initialise statistics modules
  39. * @param cfg
  40. */
  41. void rspamd_stat_init (struct rspamd_config *cfg, struct event_base *ev_base);
  42. /**
  43. * Finalize statistics
  44. */
  45. void rspamd_stat_close (void);
  46. /**
  47. * Classify the task specified and insert symbols if needed
  48. * @param task
  49. * @param L lua state
  50. * @param err error returned
  51. * @return TRUE if task has been classified
  52. */
  53. rspamd_stat_result_t rspamd_stat_classify (struct rspamd_task *task,
  54. lua_State *L, guint stage, GError **err);
  55. /**
  56. * Check if a task should be learned and set the appropriate flags for it
  57. * @param task
  58. * @return
  59. */
  60. gboolean rspamd_stat_check_autolearn (struct rspamd_task *task);
  61. /**
  62. * Learn task as spam or ham, task must be processed prior to this call
  63. * @param task task to learn
  64. * @param spam if TRUE learn spam, otherwise learn ham
  65. * @param L lua state
  66. * @param classifier NULL to learn all classifiers, name to learn a specific one
  67. * @param err error returned
  68. * @return TRUE if task has been learned
  69. */
  70. rspamd_stat_result_t rspamd_stat_learn (struct rspamd_task *task,
  71. gboolean spam, lua_State *L, const gchar *classifier,
  72. guint stage,
  73. GError **err);
  74. /**
  75. * Get the overall statistics for all statfile backends
  76. * @param cfg configuration
  77. * @param total_learns the total number of learns is stored here
  78. * @return array of statistical information
  79. */
  80. rspamd_stat_result_t rspamd_stat_statistics (struct rspamd_task *task,
  81. struct rspamd_config *cfg,
  82. guint64 *total_learns,
  83. ucl_object_t **res);
  84. void rspamd_stat_unload (void);
  85. #endif /* STAT_API_H_ */