summaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-06 15:41:16 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-06 15:41:16 +0100
commitaac916db77b6ae58b7c0186d764e97a25482017c (patch)
tree52d58a063d790c699913116ee790b2a3019a6615 /src/libutil
parentc7f92da47dcb17393132b713f75a4dbd41629819 (diff)
downloadrspamd-aac916db77b6ae58b7c0186d764e97a25482017c.tar.gz
rspamd-aac916db77b6ae58b7c0186d764e97a25482017c.zip
Start miration to the new strings.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/fstring.c16
-rw-r--r--src/libutil/fstring.h5
-rw-r--r--src/libutil/mem_pool.c2
-rw-r--r--src/libutil/printf.c2
-rw-r--r--src/libutil/shingles.c4
5 files changed, 24 insertions, 5 deletions
diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c
index 9e96aac3c..ba580cd8b 100644
--- a/src/libutil/fstring.c
+++ b/src/libutil/fstring.c
@@ -48,7 +48,7 @@ rspamd_fstring_t *
rspamd_fstring_sized_new (gsize initial_size)
{
rspamd_fstring_t *s;
- gsize real_size = MAX(default_initial_size, initial_size);
+ gsize real_size = MAX (default_initial_size, initial_size);
g_assert (posix_memalign ((void **)&s, 16, real_size + sizeof (*s)) == 0);
s->len = 0;
@@ -57,6 +57,20 @@ rspamd_fstring_sized_new (gsize initial_size)
return s;
}
+rspamd_fstring_t *
+rspamd_fstring_new_init (const gchar *init, gsize len)
+{
+ rspamd_fstring_t *s;
+ gsize real_size = MAX (default_initial_size, len);
+
+ g_assert (posix_memalign ((void **) &s, 16, real_size + sizeof (*s)) == 0);
+ s->len = len;
+ s->allocated = real_size;
+ memcpy (s->str, init, len);
+
+ return s;
+}
+
void
rspamd_fstring_free (rspamd_fstring_t *str)
{
diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h
index 9fdf47211..0d257633b 100644
--- a/src/libutil/fstring.h
+++ b/src/libutil/fstring.h
@@ -56,6 +56,11 @@ rspamd_fstring_t* rspamd_fstring_new (void);
rspamd_fstring_t *rspamd_fstring_sized_new (gsize initial_size);
/**
+ * Create new fixed length string and initialize it with the initial data
+ */
+rspamd_fstring_t *rspamd_fstring_new_init (const gchar *init, gsize len);
+
+/**
* Free fixed length string
*/
void rspamd_fstring_free (rspamd_fstring_t *str);
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c
index ea5fa0bd8..6d8c37223 100644
--- a/src/libutil/mem_pool.c
+++ b/src/libutil/mem_pool.c
@@ -424,7 +424,7 @@ rspamd_mempool_fstrdup (rspamd_mempool_t * pool, const struct f_str_s *src)
}
newstr = rspamd_mempool_alloc (pool, src->len + 1);
- memcpy (newstr, src->begin, src->len);
+ memcpy (newstr, src->str, src->len);
newstr[src->len] = '\0';
return newstr;
}
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 328173bd0..7fe7a9c26 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -453,7 +453,7 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
case 'V':
v = va_arg (args, rspamd_fstring_t *);
- RSPAMD_PRINTF_APPEND (v->begin, v->len);
+ RSPAMD_PRINTF_APPEND (v->str, v->len);
continue;
diff --git a/src/libutil/shingles.c b/src/libutil/shingles.c
index 776ecfa96..e3bcc0f10 100644
--- a/src/libutil/shingles.c
+++ b/src/libutil/shingles.c
@@ -41,7 +41,7 @@ rspamd_shingles_generate (GArray *input,
guchar shabuf[BLAKE2B_OUTBYTES], *out_key;
const guchar *cur_key;
GString *row;
- rspamd_fstring_t *word;
+ rspamd_ftok_t *word;
blake2b_state bs;
guint64 val;
gint i, j, beg = 0;
@@ -84,7 +84,7 @@ rspamd_shingles_generate (GArray *input,
for (i = 0; i <= (gint)input->len; i ++) {
if (i - beg >= SHINGLES_WINDOW || i == (gint)input->len) {
for (j = beg; j < i; j ++) {
- word = &g_array_index (input, rspamd_fstring_t, j);
+ word = &g_array_index (input, rspamd_ftok_t, j);
g_string_append_len (row, word->begin, word->len);
}
beg++;