aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-20 17:34:15 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-05-20 17:34:15 +0100
commitfc91dd7a8186ef9d4d9f2e861f5d6e482033e748 (patch)
treea49d39e4d6d9b5e524197615e0a00aeff8682244
parent7e785d608880eae1ed9698ded30b83de944c1095 (diff)
downloadrspamd-fc91dd7a8186ef9d4d9f2e861f5d6e482033e748.tar.gz
rspamd-fc91dd7a8186ef9d4d9f2e861f5d6e482033e748.zip
Use caseless hash and equal functions for request headers.
-rw-r--r--src/libserver/task.c8
-rw-r--r--src/libutil/util.c21
-rw-r--r--src/libutil/util.h2
3 files changed, 27 insertions, 4 deletions
diff --git a/src/libserver/task.c b/src/libserver/task.c
index 26de6a69f..1874847de 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -71,13 +71,13 @@ rspamd_task_new (struct rspamd_worker *worker)
new_task->re_cache);
new_task->raw_headers = g_hash_table_new (rspamd_strcase_hash,
rspamd_strcase_equal);
- new_task->request_headers = g_hash_table_new_full ((GHashFunc)g_string_hash,
- (GEqualFunc)g_string_equal, gstring_destruct, gstring_destruct);
+ new_task->request_headers = g_hash_table_new_full (rspamd_gstring_icase_hash,
+ rspamd_gstring_icase_equal, gstring_destruct, gstring_destruct);
rspamd_mempool_add_destructor (new_task->task_pool,
(rspamd_mempool_destruct_t) g_hash_table_unref,
new_task->request_headers);
- new_task->reply_headers = g_hash_table_new_full ((GHashFunc)g_string_hash,
- (GEqualFunc)g_string_equal, gstring_destruct, gstring_destruct);
+ new_task->reply_headers = g_hash_table_new_full (rspamd_gstring_icase_hash,
+ rspamd_gstring_icase_equal, gstring_destruct, gstring_destruct);
rspamd_mempool_add_destructor (new_task->task_pool,
(rspamd_mempool_destruct_t) g_hash_table_unref,
new_task->reply_headers);
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 90352f28e..5e3e9c4e1 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -1316,6 +1316,27 @@ rspamd_fstring_icase_hash (gconstpointer key)
return rspamd_icase_hash (f->begin, f->len);
}
+gboolean
+rspamd_gstring_icase_equal (gconstpointer v, gconstpointer v2)
+{
+ const GString *f1 = v, *f2 = v2;
+ if (f1->len == f2->len &&
+ g_ascii_strncasecmp (f1->str, f2->str, f1->len) == 0) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+guint
+rspamd_gstring_icase_hash (gconstpointer key)
+{
+ const GString *f = key;
+
+ return rspamd_icase_hash (f->str, f->len);
+}
+
void
gperf_profiler_init (struct rspamd_config *cfg, const gchar *descr)
{
diff --git a/src/libutil/util.h b/src/libutil/util.h
index c4170881c..80896083c 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -185,6 +185,8 @@ gboolean rspamd_str_equal (gconstpointer v, gconstpointer v2);
*/
guint rspamd_fstring_icase_hash (gconstpointer key);
gboolean rspamd_fstring_icase_equal (gconstpointer v, gconstpointer v2);
+guint rspamd_gstring_icase_hash (gconstpointer key);
+gboolean rspamd_gstring_icase_equal (gconstpointer v, gconstpointer v2);
/*
* Google perf-tools initialization function