aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-09 08:31:26 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-09 08:31:26 +0000
commit63ee3e00db2982e8053e2e7450cf05b268b92506 (patch)
tree86df076eddfd06f53f9e56a358086490bb254a34 /src
parent6d87018738712b7d01120ad3584b5db225255ce8 (diff)
downloadrspamd-63ee3e00db2982e8053e2e7450cf05b268b92506.tar.gz
rspamd-63ee3e00db2982e8053e2e7450cf05b268b92506.zip
[Minor] Add routine to convert an ftok_t to a C string
Diffstat (limited to 'src')
-rw-r--r--src/libutil/fstring.c18
-rw-r--r--src/libutil/fstring.h9
2 files changed, 23 insertions, 4 deletions
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c
index fac3b364b..2cfbd7bf8 100644
--- a/src/libutil/fstring.c
+++ b/src/libutil/fstring.c
@@ -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)
diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h
index e5d34e022..1f194827c 100644
--- a/src/libutil/fstring.h
+++ b/src/libutil/fstring.h
@@ -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
*/