From: Vsevolod Stakhov Date: Wed, 20 May 2015 16:34:15 +0000 (+0100) Subject: Use caseless hash and equal functions for request headers. X-Git-Tag: 0.9.4~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fc91dd7a8186ef9d4d9f2e861f5d6e482033e748;p=rspamd.git Use caseless hash and equal functions for request headers. --- 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