((dyn_item)->started)
#define SET_START_BIT(checkpoint, dyn_item) \
(dyn_item)->started = 1
+#define CLR_START_BIT(checkpoint, dyn_item) \
+ (dyn_item)->started = 0
#define CHECK_FINISH_BIT(checkpoint, dyn_item) \
((dyn_item)->finished)
#define SET_FINISH_BIT(checkpoint, dyn_item) \
(dyn_item)->finished = 1
+#define CLR_FINISH_BIT(checkpoint, dyn_item) \
+ (dyn_item)->finished = 0
static const guchar rspamd_symcache_magic[8] = {'r', 's', 'c', 2, 0, 0, 0, 0 };
}
void
-rspamd_symcache_disable_symbol (struct rspamd_symcache *cache,
- const gchar *symbol)
+rspamd_symcache_disable_symbol_perm (struct rspamd_symcache *cache,
+ const gchar *symbol)
{
struct rspamd_symcache_item *item;
}
void
-rspamd_symcache_enable_symbol (struct rspamd_symcache *cache,
- const gchar *symbol)
+rspamd_symcache_enable_symbol_perm (struct rspamd_symcache *cache,
+ const gchar *symbol)
{
struct rspamd_symcache_item *item;
return ret;
}
+
+gboolean
+rspamd_symcache_enable_symbol (struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ const gchar *symbol)
+{
+ struct cache_savepoint *checkpoint;
+ struct rspamd_symcache_item *item;
+ struct rspamd_symcache_dynamic_item *dyn_item;
+ gboolean ret = FALSE;
+
+ g_assert (cache != NULL);
+ g_assert (symbol != NULL);
+
+ checkpoint = task->checkpoint;
+
+ if (checkpoint) {
+ item = rspamd_symcache_find_filter (cache, symbol);
+
+ if (item) {
+ dyn_item = rspamd_symcache_get_dynamic (checkpoint, item);
+
+ if (CHECK_FINISH_BIT (checkpoint, dyn_item)) {
+ ret = TRUE;
+ CLR_START_BIT (checkpoint, dyn_item);
+ CLR_FINISH_BIT (checkpoint, dyn_item);
+ }
+ else {
+ msg_debug_task ("cannot enable symbol %s: already started", symbol);
+ }
+ }
+ }
+
+ return ret;
+}
+
+
+gboolean
+rspamd_symcache_disable_symbol (struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ const gchar *symbol)
+{
+ struct cache_savepoint *checkpoint;
+ struct rspamd_symcache_item *item;
+ struct rspamd_symcache_dynamic_item *dyn_item;
+ gboolean ret = FALSE;
+
+ g_assert (cache != NULL);
+ g_assert (symbol != NULL);
+
+ checkpoint = task->checkpoint;
+
+ if (checkpoint) {
+ item = rspamd_symcache_find_filter (cache, symbol);
+
+ if (item) {
+ dyn_item = rspamd_symcache_get_dynamic (checkpoint, item);
+
+ if (CHECK_START_BIT (checkpoint, dyn_item)) {
+ ret = TRUE;
+ SET_START_BIT (checkpoint, dyn_item);
+ SET_FINISH_BIT (checkpoint, dyn_item);
+ }
+ else {
+ msg_warn_task ("cannot disable symbol %s: already started", symbol);
+ }
+ }
+ }
+
+ return ret;
+}
+
void
rspamd_symcache_foreach (struct rspamd_symcache *cache,
void (*func) (gint, const gchar *, gint, gpointer),
* @param cache
* @param symbol
*/
-void rspamd_symcache_disable_symbol (struct rspamd_symcache *cache,
- const gchar *symbol);
+void rspamd_symcache_disable_symbol_perm (struct rspamd_symcache *cache,
+ const gchar *symbol);
/**
* Enable specific symbol in the cache
* @param cache
* @param symbol
*/
-void rspamd_symcache_enable_symbol (struct rspamd_symcache *cache,
- const gchar *symbol);
+void rspamd_symcache_enable_symbol_perm (struct rspamd_symcache *cache,
+ const gchar *symbol);
/**
* Get abstract callback data for a symbol (or its parent symbol)
* @param cache cache object
gboolean rspamd_symcache_is_symbol_enabled (struct rspamd_task *task,
struct rspamd_symcache *cache,
const gchar *symbol);
+
+/**
+ * Enable this symbol for task
+ * @param task
+ * @param cache
+ * @param symbol
+ * @return TRUE if a symbol has been enabled (not executed before)
+ */
+gboolean rspamd_symcache_enable_symbol (struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ const gchar *symbol);
+
+/**
+ * Enable this symbol for task
+ * @param task
+ * @param cache
+ * @param symbol
+ * @return TRUE if a symbol has been disabled (not executed before)
+ */
+gboolean rspamd_symcache_disable_symbol (struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ const gchar *symbol);
/**
* Process specific function for each cache element (in order they are added)
* @param cache
const gchar *sym = luaL_checkstring (L, 2);
if (cfg && sym) {
- rspamd_symcache_enable_symbol (cfg->cache, sym);
+ rspamd_symcache_enable_symbol_perm (cfg->cache, sym);
}
else {
return luaL_error (L, "invalid arguments");
const gchar *sym = luaL_checkstring (L, 2);
if (cfg && sym) {
- rspamd_symcache_disable_symbol (cfg->cache, sym);
+ rspamd_symcache_disable_symbol_perm (cfg->cache, sym);
}
else {
return luaL_error (L, "invalid arguments");