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.

fuzzy_backend.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 SRC_LIBSERVER_FUZZY_BACKEND_H_
  17. #define SRC_LIBSERVER_FUZZY_BACKEND_H_
  18. #include "config.h"
  19. #include "contrib/libev/ev.h"
  20. #include "fuzzy_wire.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. struct rspamd_fuzzy_backend;
  25. struct rspamd_config;
  26. /*
  27. * Callbacks for fuzzy methods
  28. */
  29. typedef void (*rspamd_fuzzy_check_cb)(struct rspamd_fuzzy_reply *rep, void *ud);
  30. typedef void (*rspamd_fuzzy_update_cb)(gboolean success,
  31. unsigned int nadded,
  32. unsigned int ndeleted,
  33. unsigned int nextended,
  34. unsigned int nignored,
  35. void *ud);
  36. typedef void (*rspamd_fuzzy_version_cb)(uint64_t rev, void *ud);
  37. typedef void (*rspamd_fuzzy_count_cb)(uint64_t count, void *ud);
  38. typedef gboolean (*rspamd_fuzzy_periodic_cb)(void *ud);
  39. /**
  40. * Open fuzzy backend
  41. * @param ev_base
  42. * @param config
  43. * @param err
  44. * @return
  45. */
  46. struct rspamd_fuzzy_backend *rspamd_fuzzy_backend_create(struct ev_loop *ev_base,
  47. const ucl_object_t *config,
  48. struct rspamd_config *cfg,
  49. GError **err);
  50. /**
  51. * Check a specific hash in storage
  52. * @param cmd
  53. * @param cb
  54. * @param ud
  55. */
  56. void rspamd_fuzzy_backend_check(struct rspamd_fuzzy_backend *bk,
  57. const struct rspamd_fuzzy_cmd *cmd,
  58. rspamd_fuzzy_check_cb cb, void *ud);
  59. /**
  60. * Process updates for a specific queue
  61. * @param bk
  62. * @param updates queue of struct fuzzy_peer_cmd
  63. * @param src
  64. */
  65. void rspamd_fuzzy_backend_process_updates(struct rspamd_fuzzy_backend *bk,
  66. GArray *updates, const char *src, rspamd_fuzzy_update_cb cb,
  67. void *ud);
  68. /**
  69. * Gets number of hashes from the backend
  70. * @param bk
  71. * @param cb
  72. * @param ud
  73. */
  74. void rspamd_fuzzy_backend_count(struct rspamd_fuzzy_backend *bk,
  75. rspamd_fuzzy_count_cb cb, void *ud);
  76. /**
  77. * Returns number of revision for a specific source
  78. * @param bk
  79. * @param src
  80. * @param cb
  81. * @param ud
  82. */
  83. void rspamd_fuzzy_backend_version(struct rspamd_fuzzy_backend *bk,
  84. const char *src,
  85. rspamd_fuzzy_version_cb cb, void *ud);
  86. /**
  87. * Returns unique id for backend
  88. * @param backend
  89. * @return
  90. */
  91. const char *rspamd_fuzzy_backend_id(struct rspamd_fuzzy_backend *backend);
  92. /**
  93. * Starts expire process for the backend
  94. * @param backend
  95. */
  96. void rspamd_fuzzy_backend_start_update(struct rspamd_fuzzy_backend *backend,
  97. double timeout,
  98. rspamd_fuzzy_periodic_cb cb,
  99. void *ud);
  100. struct ev_loop *rspamd_fuzzy_backend_event_base(struct rspamd_fuzzy_backend *backend);
  101. double rspamd_fuzzy_backend_get_expire(struct rspamd_fuzzy_backend *backend);
  102. /**
  103. * Closes backend
  104. * @param backend
  105. */
  106. void rspamd_fuzzy_backend_close(struct rspamd_fuzzy_backend *backend);
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif /* SRC_LIBSERVER_FUZZY_BACKEND_H_ */