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.

roll_history.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 ROLL_HISTORY_H_
  17. #define ROLL_HISTORY_H_
  18. #include "config.h"
  19. #include "mem_pool.h"
  20. /*
  21. * Roll history is a special cycled buffer for checked messages, it is designed for writing history messages
  22. * and displaying them in webui
  23. */
  24. #define HISTORY_MAX_ID 256
  25. #define HISTORY_MAX_SYMBOLS 256
  26. #define HISTORY_MAX_USER 32
  27. #define HISTORY_MAX_ADDR 32
  28. struct rspamd_task;
  29. struct rspamd_config;
  30. struct roll_history_row {
  31. struct timeval tv;
  32. gchar message_id[HISTORY_MAX_ID];
  33. gchar symbols[HISTORY_MAX_SYMBOLS];
  34. gchar user[HISTORY_MAX_USER];
  35. gchar from_addr[HISTORY_MAX_ADDR];
  36. gsize len;
  37. gdouble scan_time;
  38. gdouble score;
  39. gdouble required_score;
  40. gint action;
  41. guint completed;
  42. };
  43. struct roll_history {
  44. struct roll_history_row *rows;
  45. gboolean disabled;
  46. guint nrows;
  47. guint cur_row;
  48. };
  49. /**
  50. * Returns new roll history
  51. * @param pool pool for shared memory
  52. * @return new structure
  53. */
  54. struct roll_history * rspamd_roll_history_new (rspamd_mempool_t *pool,
  55. guint max_rows, struct rspamd_config *cfg);
  56. /**
  57. * Update roll history with data from task
  58. * @param history roll history object
  59. * @param task task object
  60. */
  61. void rspamd_roll_history_update (struct roll_history *history,
  62. struct rspamd_task *task);
  63. /**
  64. * Load previously saved history from file
  65. * @param history roll history object
  66. * @param filename filename to load from
  67. * @return TRUE if history has been loaded
  68. */
  69. gboolean rspamd_roll_history_load (struct roll_history *history,
  70. const gchar *filename);
  71. /**
  72. * Save history to file
  73. * @param history roll history object
  74. * @param filename filename to load from
  75. * @return TRUE if history has been saved
  76. */
  77. gboolean rspamd_roll_history_save (struct roll_history *history,
  78. const gchar *filename);
  79. #endif /* ROLL_HISTORY_H_ */