static const guchar rspamd_symbols_cache_magic[8] = {'r', 's', 'c', 1, 0, 0, 0, 0 };
+static gint rspamd_symbols_cache_find_symbol_parent (struct symbols_cache *cache,
+ const gchar *name);
+
struct rspamd_symbols_cache_header {
guchar magic[8];
guint nitems;
while (cur) {
ddep = cur->data;
- id = rspamd_symbols_cache_find_symbol (cache, ddep->from);
+ id = rspamd_symbols_cache_find_symbol_parent (cache, ddep->from);
if (id != -1) {
it = g_ptr_array_index (cache->items_by_id, id);
}
while (cur) {
dcond = cur->data;
- id = rspamd_symbols_cache_find_symbol (cache, dcond->sym);
+ id = rspamd_symbols_cache_find_symbol_parent (cache, dcond->sym);
if (id != -1) {
it = g_ptr_array_index (cache->items_by_id, id);
}
g_assert (cache != NULL);
g_assert (sym != NULL);
- id = rspamd_symbols_cache_find_symbol (cache, sym);
+ id = rspamd_symbols_cache_find_symbol_parent (cache, sym);
if (id != -1) {
/* We already know id, so just register a direct condition */
item = g_hash_table_lookup (cache->items_by_symbol, name);
+ if (item != NULL) {
+ return item->id;
+ }
+
+ return -1;
+}
+
+static gint
+rspamd_symbols_cache_find_symbol_parent (struct symbols_cache *cache,
+ const gchar *name)
+{
+ struct cache_item *item;
+
+ g_assert (cache != NULL);
+
+ if (name == NULL) {
+ return -1;
+ }
+
+ item = g_hash_table_lookup (cache->items_by_symbol, name);
+
if (item != NULL) {
while (item != NULL && item->parent != -1) {
return -1;
}
+const gchar *
+rspamd_symbols_cache_symbol_by_id (struct symbols_cache *cache,
+ gint id)
+{
+ struct cache_item *item;
+
+ g_assert (cache != NULL);
+
+ if (id < 0 || id >= (gint)cache->items_by_id->len) {
+ return NULL;
+ }
+
+ item = g_ptr_array_index (cache->items_by_id, id);
+
+ return item->symbol;
+}
+
void
rspamd_symbols_cache_disable_symbol (struct rspamd_task *task,
struct symbols_cache *cache, const gchar *symbol)
* @param name
* @return id of symbol or (-1) if a symbol has not been found
*/
-gint rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, const gchar *name);
+gint rspamd_symbols_cache_find_symbol (struct symbols_cache *cache,
+ const gchar *name);
+
+/**
+ * Find symbol in cache by its id
+ * @param cache
+ * @param id
+ * @return symbol's name or NULL
+ */
+const gchar * rspamd_symbols_cache_symbol_by_id (struct symbols_cache *cache,
+ gint id);
/**
* Call function for cached symbol using saved callback