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.1KB

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