return rspamd_controller_handle_stat_common (conn_ent, msg, TRUE);
}
-#if 0
-/* XXX: restore counters */
-static ucl_object_t *
-rspamd_controller_cache_item_to_ucl (struct cache_item *item)
-{
- ucl_object_t *obj;
-
- obj = ucl_object_typed_new (UCL_OBJECT);
- ucl_object_insert_key (obj, ucl_object_fromstring (item->s->symbol),
- "symbol", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromdouble (item->s->weight),
- "weight", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromint (item->s->frequency),
- "frequency", 0, false);
- ucl_object_insert_key (obj, ucl_object_fromdouble (item->s->avg_time),
- "time", 0, false);
-
- return obj;
-}
-#endif
/*
* Counters command handler:
}
cache = session->ctx->cfg->cache;
- top = ucl_object_typed_new (UCL_ARRAY);
+
if (cache != NULL) {
-#if 0
-/* XXX: restore counters */
- cur = cache->negative_items;
- while (cur) {
- item = cur->data;
- if (!item->is_callback) {
- ucl_array_append (top, rspamd_controller_cache_item_to_ucl (
- item));
- }
- cur = g_list_next (cur);
- }
- cur = cache->static_items;
- while (cur) {
- item = cur->data;
- if (!item->is_callback) {
- ucl_array_append (top, rspamd_controller_cache_item_to_ucl (
- item));
- }
- cur = g_list_next (cur);
- }
-#endif
+ top = rspamd_symbols_cache_counters (cache);
+ rspamd_controller_send_ucl (conn_ent, top);
+ ucl_object_unref (top);
+ }
+ else {
+ rspamd_controller_send_error (conn_ent, 500, "Invalid cache");
}
- rspamd_controller_send_ucl (conn_ent, top);
- ucl_object_unref (top);
return 0;
}
*save = GUINT_TO_POINTER (idx);
return TRUE;
+}
+
+static void
+rspamd_symbols_cache_counters_cb (gpointer k, gpointer v, gpointer ud)
+{
+ ucl_object_t *obj, *top = ud;
+ struct cache_item *item = v;
+
+ if (item->type != SYMBOL_TYPE_CALLBACK) {
+ obj = ucl_object_typed_new (UCL_OBJECT);
+ ucl_object_insert_key (obj, ucl_object_fromstring (item->symbol),
+ "symbol", 0, false);
+ ucl_object_insert_key (obj, ucl_object_fromdouble (item->weight),
+ "weight", 0, false);
+ ucl_object_insert_key (obj, ucl_object_fromint (item->frequency),
+ "frequency", 0, false);
+ ucl_object_insert_key (obj, ucl_object_fromdouble (item->avg_time),
+ "time", 0, false);
+
+ ucl_array_append (top, obj);
+ }
+}
+
+ucl_object_t *
+rspamd_symbols_cache_counters (struct symbols_cache * cache)
+{
+ ucl_object_t *top;
+
+ g_assert (cache != NULL);
+ top = ucl_object_typed_new (UCL_ARRAY);
+ g_hash_table_foreach (cache->items_by_symbol,
+ rspamd_symbols_cache_counters_cb, top);
+ return top;
}