diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-03-26 16:51:21 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-03-26 20:55:10 +0000 |
commit | 533946781a68fc227d61bd6333ef0214e20c05ba (patch) | |
tree | 399752420c2e2e1b8b8c20e1d66fe07778a19d33 /src/libserver | |
parent | e7a58b8bfc5f8254e37afd08b2dd2380dd1353cb (diff) | |
download | rspamd-533946781a68fc227d61bd6333ef0214e20c05ba.tar.gz rspamd-533946781a68fc227d61bd6333ef0214e20c05ba.zip |
[Project] Css: Minor adjustments
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/css/css.cxx | 20 | ||||
-rw-r--r-- | src/libserver/css/css_selector.cxx | 4 | ||||
-rw-r--r-- | src/libserver/logger.h | 3 | ||||
-rw-r--r-- | src/libserver/logger/logger.c | 2 |
4 files changed, 24 insertions, 5 deletions
diff --git a/src/libserver/css/css.cxx b/src/libserver/css/css.cxx index bd26cee1e..17ec165fc 100644 --- a/src/libserver/css/css.cxx +++ b/src/libserver/css/css.cxx @@ -18,18 +18,34 @@ #include "css.hxx" #include "contrib/robin-hood/robin_hood.h" #include "css_parser.hxx" +/* Keep unit tests implementation here (it'll possibly be moved outside one day) */ #define DOCTEST_CONFIG_IMPLEMENTATION_IN_DLL #define DOCTEST_CONFIG_IMPLEMENT #include "doctest/doctest.h" +static void +rspamd_css_dtor(void *p) +{ + rspamd::css::css_style_sheet *style = + reinterpret_cast<rspamd::css::css_style_sheet *>(p); + + delete style; +} + rspamd_css -rspamd_css_parse_style (rspamd_mempool_t *pool, const guchar *begin, gsize len, +rspamd_css_parse_style(rspamd_mempool_t *pool, const guchar *begin, gsize len, GError **err) { auto parse_res = rspamd::css::parse_css(pool, {(const char* )begin, len}); if (parse_res.has_value()) { - return reinterpret_cast<rspamd_css>(parse_res.value().release()); + /* + * Detach style pointer from the unique_ptr as it will be managed by + * C memory pool + */ + auto *detached_style = reinterpret_cast<rspamd_css>(parse_res.value().release()); + rspamd_mempool_add_destructor(pool, rspamd_css_dtor, (void *)detached_style); + return detached_style; } else { g_set_error(err, g_quark_from_static_string("css"), diff --git a/src/libserver/css/css_selector.cxx b/src/libserver/css/css_selector.cxx index d4b578a08..b198b8553 100644 --- a/src/libserver/css/css_selector.cxx +++ b/src/libserver/css/css_selector.cxx @@ -87,7 +87,7 @@ auto process_selector_tokens(rspamd_mempool_t *pool, state = selector_process_state::selector_ident_consumed; break; default: - msg_debug_css("cannot consume more of a selector, invalid parser token: %*s; expected start", + msg_debug_css("cannot consume more of a selector, invalid parser token: %s; expected start", next_tok.token_type_str()); can_continue = false; break; @@ -103,7 +103,7 @@ auto process_selector_tokens(rspamd_mempool_t *pool, state = selector_process_state::selector_ident_consumed; } else { - msg_debug_css("cannot consume more of a selector, invalid parser token: %*s; expected ident", + msg_debug_css("cannot consume more of a selector, invalid parser token: %s; expected ident", next_tok.token_type_str()); can_continue = false; } diff --git a/src/libserver/logger.h b/src/libserver/logger.h index 9bf7015c0..c5e63c0fb 100644 --- a/src/libserver/logger.h +++ b/src/libserver/logger.h @@ -184,6 +184,9 @@ bool rspamd_conditional_debug_fast_num_id (rspamd_logger_t *logger, guint mod_id, const gchar *module, guint64 id, const gchar *function, const gchar *fmt, ...); +gboolean rspamd_logger_need_log (rspamd_logger_t *rspamd_log, + GLogLevelFlags log_level, + guint module_id); /** * Function with variable number of arguments support that uses static default logger diff --git a/src/libserver/logger/logger.c b/src/libserver/logger/logger.c index 21c92bbb9..0ab6c4789 100644 --- a/src/libserver/logger/logger.c +++ b/src/libserver/logger/logger.c @@ -300,7 +300,7 @@ rspamd_log_on_fork (GQuark ptype, struct rspamd_config *cfg, } } -static inline gboolean +inline gboolean rspamd_logger_need_log (rspamd_logger_t *rspamd_log, GLogLevelFlags log_level, guint module_id) { |