From: Vsevolod Stakhov Date: Thu, 5 Nov 2015 13:22:56 +0000 (+0300) Subject: Add routine to compare an ftok with C string X-Git-Tag: 1.1.0~638 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=58fc8c267ac9a619bc3c9cfce108c0d2a0d338fc;p=thirdparty%2Frspamd.git Add routine to compare an ftok with C string --- diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c index 3d5c59061a..d75b731fbb 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 d3b51821f3..79c96932ba 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 *