summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSimmo Saan <simmo.saan@gmail.com>2015-12-13 19:44:06 +0200
committerSimmo Saan <simmo.saan@gmail.com>2017-06-17 20:10:45 +0300
commit1af75739b5e4fa6aeb4cf0d4c674b057fc98024d (patch)
tree20df6380a8e2b066445812c8566c8927e3fc82ff /src/core
parent08da7c658649b8564e9017cb64bfa7de92383c5b (diff)
downloadweechat-1af75739b5e4fa6aeb4cf0d4c674b057fc98024d.zip
core: implement buffer type in hashtable_add_from_infolist
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-hashtable.c79
1 files changed, 33 insertions, 46 deletions
diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c
index d9f480c42..508c30892 100644
--- a/src/core/wee-hashtable.c
+++ b/src/core/wee-hashtable.c
@@ -1116,19 +1116,13 @@ hashtable_add_from_infolist (struct t_hashtable *hashtable,
struct t_infolist *infolist,
const char *prefix)
{
- struct t_infolist_item *infolist_item;
struct t_infolist_var *ptr_name, *ptr_value;
- void *value;
char prefix_name[128], option_value[128];
int prefix_length;
if (!hashtable || !infolist || !prefix)
return 0;
- infolist_item = infolist->ptr_item;
- if (!infolist_item)
- return 0;
-
if (hashtable->type_keys != HASHTABLE_STRING)
return 0;
/* TODO: implement other key types */
@@ -1137,55 +1131,48 @@ hashtable_add_from_infolist (struct t_hashtable *hashtable,
"%s_name_", prefix);
prefix_length = strlen (prefix_name);
- for (ptr_name = infolist_item->vars; ptr_name; ptr_name = ptr_name->next_var)
+ for (ptr_name = infolist->ptr_item->vars; ptr_name; ptr_name = ptr_name->next_var)
{
if (string_strncasecmp (ptr_name->name, prefix_name, prefix_length) == 0)
{
snprintf (option_value, sizeof (option_value),
"%s_value_%s", prefix, ptr_name->name + prefix_length);
- for (ptr_value = infolist_item->vars; ptr_value; ptr_value = ptr_value->next_var)
+ ptr_value = infolist_search_var (infolist, option_value);
+ if (ptr_value)
{
- if (string_strcasecmp (ptr_value->name, option_value) == 0)
+ switch (hashtable->type_values)
{
- switch (hashtable->type_values)
- {
- case HASHTABLE_INTEGER:
- if (ptr_value->type != INFOLIST_INTEGER)
- return 0;
-
- value = ptr_value->value;
- break;
- case HASHTABLE_STRING:
- if (ptr_value->type != INFOLIST_STRING)
- return 0;
-
- value = ptr_value->value;
- break;
- case HASHTABLE_POINTER:
- if (ptr_value->type != INFOLIST_POINTER)
- return 0;
-
- value = ptr_value->value;
- break;
- case HASHTABLE_BUFFER:
- if (ptr_value->type != INFOLIST_BUFFER)
- return 0;
-
- value = ptr_value->value; /* TODO: implement size */
- break;
- case HASHTABLE_TIME:
- if (ptr_value->type != INFOLIST_TIME)
- return 0;
-
- value = ptr_value->value;
- break;
- case HASHTABLE_NUM_TYPES:
- break;
- }
- hashtable_set (hashtable, ptr_name->value, value);
- break;
+ case HASHTABLE_INTEGER:
+ if (ptr_value->type != INFOLIST_INTEGER)
+ return 0;
+ break;
+ case HASHTABLE_STRING:
+ if (ptr_value->type != INFOLIST_STRING)
+ return 0;
+ break;
+ case HASHTABLE_POINTER:
+ if (ptr_value->type != INFOLIST_POINTER)
+ return 0;
+ break;
+ case HASHTABLE_BUFFER:
+ if (ptr_value->type != INFOLIST_BUFFER)
+ return 0;
+ break;
+ case HASHTABLE_TIME:
+ if (ptr_value->type != INFOLIST_TIME)
+ return 0;
+ break;
+ case HASHTABLE_NUM_TYPES:
+ break;
}
+ if (hashtable->type_values == HASHTABLE_BUFFER)
+ {
+ hashtable_set_with_size (hashtable, ptr_name->value, 0,
+ ptr_value->value, ptr_value->size);
+ }
+ else
+ hashtable_set (hashtable, ptr_name->value, ptr_value->value);
}
}
}