Browse Source

[Minor] Add routine to convert an ftok_t to a C string

tags/1.8.2
Vsevolod Stakhov 5 years ago
parent
commit
63ee3e00db
2 changed files with 23 additions and 4 deletions
  1. 16
    2
      src/libutil/fstring.c
  2. 7
    2
      src/libutil/fstring.h

+ 16
- 2
src/libutil/fstring.c View File

@@ -223,8 +223,6 @@ rspamd_fstring_erase (rspamd_fstring_t *str, gsize pos, gsize len)
}
}

char *rspamd_fstring_cstr (const rspamd_fstring_t *str);

/* Compat code */
static guint32
fstrhash_c (gchar c, guint32 hval)
@@ -418,6 +416,22 @@ rspamd_fstring_cstr (const rspamd_fstring_t *s)
return result;
}

char *
rspamd_ftok_cstr (const rspamd_ftok_t *s)
{
char *result;

if (s == NULL) {
return NULL;
}

result = g_malloc (s->len + 1);
memcpy (result, s->begin, s->len);
result[s->len] = '\0';

return result;
}

gboolean
rspamd_ftok_cstr_equal (const rspamd_ftok_t *s, const gchar *pat,
gboolean icase)

+ 7
- 2
src/libutil/fstring.h View File

@@ -87,12 +87,17 @@ void rspamd_fstring_erase (rspamd_fstring_t *str, gsize pos, gsize len);
#define rspamd_fstring_clear(s) rspamd_fstring_erase(s, 0, s->len)

/**
* Convert fixed string to a zero terminated string. This string should be
* Convert fixed string to a zero terminated string. This string must be
* freed by a caller
*/
char * rspamd_fstring_cstr (const rspamd_fstring_t *str)
G_GNUC_WARN_UNUSED_RESULT;

/**
* Convert fixed string usign ftok_t to a zero terminated string. This string must be
* freed by a caller
*/
char * rspamd_ftok_cstr (const rspamd_ftok_t *str)
G_GNUC_WARN_UNUSED_RESULT;
/*
* Return fast hash value for fixed string converted to lowercase
*/

Loading…
Cancel
Save