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_sqlite.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2024 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 FUZZY_BACKEND_H_
  17. #define FUZZY_BACKEND_H_
  18. #include "config.h"
  19. #include "fuzzy_wire.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. struct rspamd_fuzzy_backend_sqlite;
  24. /**
  25. * Open fuzzy backend
  26. * @param path file to open (legacy file will be converted automatically)
  27. * @param err error pointer
  28. * @return backend structure or NULL
  29. */
  30. struct rspamd_fuzzy_backend_sqlite *rspamd_fuzzy_backend_sqlite_open(const char *path,
  31. gboolean vacuum,
  32. GError **err);
  33. /**
  34. * Check specified fuzzy in the backend
  35. * @param backend
  36. * @param cmd
  37. * @return reply with probability and weight
  38. */
  39. struct rspamd_fuzzy_reply rspamd_fuzzy_backend_sqlite_check(
  40. struct rspamd_fuzzy_backend_sqlite *backend,
  41. const struct rspamd_fuzzy_cmd *cmd,
  42. int64_t expire);
  43. /**
  44. * Prepare storage for updates (by starting transaction)
  45. */
  46. gboolean rspamd_fuzzy_backend_sqlite_prepare_update(struct rspamd_fuzzy_backend_sqlite *backend,
  47. const char *source);
  48. /**
  49. * Add digest to the database
  50. * @param backend
  51. * @param cmd
  52. * @return
  53. */
  54. gboolean rspamd_fuzzy_backend_sqlite_add(struct rspamd_fuzzy_backend_sqlite *backend,
  55. const struct rspamd_fuzzy_cmd *cmd);
  56. /**
  57. * Delete digest from the database
  58. * @param backend
  59. * @param cmd
  60. * @return
  61. */
  62. gboolean rspamd_fuzzy_backend_sqlite_del(
  63. struct rspamd_fuzzy_backend_sqlite *backend,
  64. const struct rspamd_fuzzy_cmd *cmd);
  65. /**
  66. * Commit updates to storage
  67. */
  68. gboolean rspamd_fuzzy_backend_sqlite_finish_update(struct rspamd_fuzzy_backend_sqlite *backend,
  69. const char *source, gboolean version_bump);
  70. /**
  71. * Sync storage
  72. * @param backend
  73. * @return
  74. */
  75. gboolean rspamd_fuzzy_backend_sqlite_sync(struct rspamd_fuzzy_backend_sqlite *backend,
  76. int64_t expire,
  77. gboolean clean_orphaned);
  78. /**
  79. * Close storage
  80. * @param backend
  81. */
  82. void rspamd_fuzzy_backend_sqlite_close(struct rspamd_fuzzy_backend_sqlite *backend);
  83. gsize rspamd_fuzzy_backend_sqlite_count(struct rspamd_fuzzy_backend_sqlite *backend);
  84. int rspamd_fuzzy_backend_sqlite_version(struct rspamd_fuzzy_backend_sqlite *backend, const char *source);
  85. gsize rspamd_fuzzy_backend_sqlite_expired(struct rspamd_fuzzy_backend_sqlite *backend);
  86. const char *rspamd_fuzzy_sqlite_backend_id(struct rspamd_fuzzy_backend_sqlite *backend);
  87. #ifdef __cplusplus
  88. }
  89. #endif
  90. #endif /* FUZZY_BACKEND_H_ */