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.

hyperscan_tools.h 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2023 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. #include "config.h"
  17. #ifndef RSPAMD_HYPERSCAN_TOOLS_H
  18. #define RSPAMD_HYPERSCAN_TOOLS_H
  19. #ifdef WITH_HYPERSCAN
  20. #include "hs.h"
  21. G_BEGIN_DECLS
  22. /**
  23. * Opaque structure that represents hyperscan (maybe shared/cached database)
  24. */
  25. typedef struct rspamd_hyperscan_s rspamd_hyperscan_t;
  26. /**
  27. * Maybe load or mmap shared a hyperscan from a file
  28. * @param filename
  29. * @return cached database if available
  30. */
  31. rspamd_hyperscan_t *rspamd_hyperscan_maybe_load(const char *filename, goffset offset);
  32. /**
  33. * Creates a wrapper for a raw hs db. Ownership is transferred to the enclosing object returned
  34. * @param filename
  35. * @return
  36. */
  37. rspamd_hyperscan_t *rspamd_hyperscan_from_raw_db(hs_database_t *db, const char *fname);
  38. /**
  39. * Get the internal database
  40. * @param db
  41. * @return
  42. */
  43. hs_database_t *rspamd_hyperscan_get_database(rspamd_hyperscan_t *db);
  44. /**
  45. * Free the database
  46. * @param db
  47. */
  48. void rspamd_hyperscan_free(rspamd_hyperscan_t *db, bool invalid);
  49. /**
  50. * Notice a known hyperscan file (e.g. externally serialized)
  51. * @param fname
  52. */
  53. void rspamd_hyperscan_notice_known(const char *fname);
  54. /**
  55. * Notice that hyperscan files are all loaded (e.g. in the main process), so we can cleanup old files on termination
  56. */
  57. void rspamd_hyperscan_notice_loaded(void);
  58. /**
  59. * Cleans up old files. This method should be called on config free (in the main process)
  60. */
  61. void rspamd_hyperscan_cleanup_maybe(void);
  62. G_END_DECLS
  63. #endif
  64. #endif