From 58fc8c267ac9a619bc3c9cfce108c0d2a0d338fc Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 5 Nov 2015 16:22:56 +0300 Subject: [PATCH] Add routine to compare an ftok with C string --- src/libutil/fstring.c | 21 +++++++++++++++++++++ src/libutil/fstring.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c index 3d5c59061..d75b731fb 100644 --- a/src/libutil/fstring.c +++ b/src/libutil/fstring.c @@ -376,3 +376,24 @@ rspamd_fstring_cstr (const rspamd_fstring_t *s) return result; } + +gboolean +rspamd_ftok_cstr_equal (const rspamd_ftok_t *s, const gchar *pat, + gboolean icase) +{ + gsize slen; + rspamd_ftok_t srch; + + g_assert (s != NULL); + g_assert (pat != NULL); + + slen = strlen (pat); + srch.begin = pat; + srch.len = slen; + + if (icase) { + return (rspamd_ftok_casecmp (s, &srch) == 0); + } + + return (rspamd_ftok_cmp (s, &srch) == 0); +} diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h index d3b51821f..79c96932b 100644 --- a/src/libutil/fstring.h +++ b/src/libutil/fstring.h @@ -133,6 +133,12 @@ gint rspamd_ftok_casecmp (const rspamd_ftok_t *s1, gint rspamd_ftok_cmp (const rspamd_ftok_t *s1, const rspamd_ftok_t *s2); +/** + * Return TRUE if ftok is equal to specified C string + */ +gboolean rspamd_ftok_cstr_equal (const rspamd_ftok_t *s, + const gchar *pat, gboolean icase); + /** * Free fstring_t that is mapped to ftok_t * -- 2.39.5