1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-27 13:26:38 +02:00

core: implement buffer type in hashtable_add_from_infolist

This commit is contained in:
Simmo Saan
2015-12-13 19:44:06 +02:00
parent 08da7c6586
commit 1af75739b5
+33 -46
View File
@@ -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);
}
}
}