]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add starts_with function for rspamd_ftok_t
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Feb 2019 12:34:22 +0000 (12:34 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Feb 2019 12:34:22 +0000 (12:34 +0000)
src/libutil/fstring.c
src/libutil/fstring.h

index 2cfbd7bf82a6bee4cdd67a78992eccbeb6d7b865..967de9e98d2f42ca1cb8ea35cffa207350553de5 100644 (file)
@@ -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)
 {
index 96749052ceca4d0057293b6826f27da918af6ed8..1a4d25eb96fced60f0b6db7b03063a41ca6d7660 100644 (file)
@@ -139,6 +139,15 @@ gint rspamd_ftok_casecmp (const rspamd_ftok_t *s1,
 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
  */