aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-13 13:46:33 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-13 13:46:33 +0100
commit79e437a712efba0d901c9b9d7c8c82e4d1283260 (patch)
tree59a9bbc6e20abe622e247989f4b6de75b7254f11 /src
parenta210cf354800ae92d94a5a28c24e1ac17d107c1e (diff)
downloadrspamd-79e437a712efba0d901c9b9d7c8c82e4d1283260.tar.gz
rspamd-79e437a712efba0d901c9b9d7c8c82e4d1283260.zip
[Feature] Add utility methods for multipattern
Diffstat (limited to 'src')
-rw-r--r--src/libutil/multipattern.c27
-rw-r--r--src/libutil/multipattern.h15
2 files changed, 42 insertions, 0 deletions
diff --git a/src/libutil/multipattern.c b/src/libutil/multipattern.c
index 8241d1d4e..229ef2a9b 100644
--- a/src/libutil/multipattern.c
+++ b/src/libutil/multipattern.c
@@ -611,3 +611,30 @@ rspamd_multipattern_destroy (struct rspamd_multipattern *mp)
g_slice_free1 (sizeof (*mp), mp);
}
}
+
+const gchar*
+rspamd_multipattern_get_pattern (struct rspamd_multipattern *mp,
+ guint index)
+{
+ g_assert (mp != NULL);
+ g_assert (index < mp->cnt);
+
+#ifdef WITH_HYPERSCAN
+ return g_array_index (mp->hs_pats, gchar *, index);
+#else
+
+ ac_trie_pat_t pat;
+
+ pat = g_array_index (mp->pats, ac_trie_pat_t, index);
+
+ return pat.ptr;
+#endif
+}
+
+guint
+rspamd_multipattern_get_npatterns (struct rspamd_multipattern *mp)
+{
+ g_assert (mp != NULL);
+
+ return mp->cnt;
+}
diff --git a/src/libutil/multipattern.h b/src/libutil/multipattern.h
index 45ade2743..c27977159 100644
--- a/src/libutil/multipattern.h
+++ b/src/libutil/multipattern.h
@@ -112,6 +112,21 @@ gboolean rspamd_multipattern_compile (struct rspamd_multipattern *mp,
gint rspamd_multipattern_lookup (struct rspamd_multipattern *mp,
const gchar *in, gsize len, rspamd_multipattern_cb_t cb,
gpointer ud, guint *pnfound);
+/**
+ * Get pattern string from multipattern identified by index
+ * @param mp
+ * @param index
+ * @return
+ */
+const gchar* rspamd_multipattern_get_pattern (struct rspamd_multipattern *mp,
+ guint index);
+
+/**
+ * Returns number of patterns in a multipattern matcher
+ * @param mp
+ * @return
+ */
+guint rspamd_multipattern_get_npatterns (struct rspamd_multipattern *mp);
/**
* Destroys multipattern structure