Browse Source

[Minor] Add starts_with function for rspamd_ftok_t

tags/1.9.0
Vsevolod Stakhov 5 years ago
parent
commit
3d7aef5571
2 changed files with 22 additions and 0 deletions
  1. 13
    0
      src/libutil/fstring.c
  2. 9
    0
      src/libutil/fstring.h

+ 13
- 0
src/libutil/fstring.c View 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)
{

+ 9
- 0
src/libutil/fstring.h View 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
*/

Loading…
Cancel
Save