aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-02-07 12:34:22 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-02-07 12:34:22 +0000
commit3d7aef55713b576997aec976326c1143d14fe3f8 (patch)
tree7a811a565e83efd37d3123af31f71dafa45c32a0
parent11fafb3cde34c6ebbc0d4b1d694e2185aa27ae27 (diff)
downloadrspamd-3d7aef55713b576997aec976326c1143d14fe3f8.tar.gz
rspamd-3d7aef55713b576997aec976326c1143d14fe3f8.zip
[Minor] Add starts_with function for rspamd_ftok_t
-rw-r--r--src/libutil/fstring.c13
-rw-r--r--src/libutil/fstring.h9
2 files changed, 22 insertions, 0 deletions
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c
index 2cfbd7bf8..967de9e98 100644
--- a/src/libutil/fstring.c
+++ b/src/libutil/fstring.c
@@ -375,6 +375,19 @@ rspamd_ftok_cmp (const rspamd_ftok_t *s1,
return s1->len - s2->len;
}
+gboolean
+rspamd_ftok_starts_with (const rspamd_ftok_t *s1,
+ const rspamd_ftok_t *s2)
+{
+ g_assert (s1 != NULL && s2 != NULL);
+
+ if (s1->len >= s2->len) {
+ return !!(memcmp (s1->begin, s2->begin, s1->len) == 0);
+ }
+
+ return FALSE;
+}
+
void
rspamd_fstring_mapped_ftok_free (gpointer p)
{
diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h
index 96749052c..1a4d25eb9 100644
--- a/src/libutil/fstring.h
+++ b/src/libutil/fstring.h
@@ -140,6 +140,15 @@ gint rspamd_ftok_cmp (const rspamd_ftok_t *s1,
const rspamd_ftok_t *s2);
/**
+ * Returns true if `s1` starts with `s2`
+ * @param s1
+ * @param s2
+ * @return
+ */
+gboolean rspamd_ftok_starts_with (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,