mirror of
https://github.com/weechat/weechat.git
synced 2026-07-07 18:23:13 +02:00
Merge remote-tracking branch 'origin/pr/623' into irc-3.2-cap
This commit is contained in:
@@ -1062,6 +1062,8 @@ hashtable_add_to_infolist (struct t_hashtable *hashtable,
|
||||
hashtable_to_string (hashtable->type_keys,
|
||||
ptr_item->key)))
|
||||
return 0;
|
||||
/* TODO: implement other key types */
|
||||
|
||||
snprintf (option_name, sizeof (option_name),
|
||||
"%s_value_%05d", prefix, item_number);
|
||||
switch (hashtable->type_values)
|
||||
@@ -1101,6 +1103,83 @@ hashtable_add_to_infolist (struct t_hashtable *hashtable,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds hashtable keys and values from an infolist.
|
||||
*
|
||||
* Returns:
|
||||
* 1: OK
|
||||
* 0: error
|
||||
*/
|
||||
|
||||
int
|
||||
hashtable_add_from_infolist (struct t_hashtable *hashtable,
|
||||
struct t_infolist *infolist,
|
||||
const char *prefix)
|
||||
{
|
||||
struct t_infolist_var *ptr_name, *ptr_value;
|
||||
char prefix_name[128], option_value[128];
|
||||
int prefix_length;
|
||||
|
||||
if (!hashtable || !infolist || !prefix)
|
||||
return 0;
|
||||
|
||||
if (hashtable->type_keys != HASHTABLE_STRING)
|
||||
return 0;
|
||||
/* TODO: implement other key types */
|
||||
|
||||
snprintf (prefix_name, sizeof (prefix_name),
|
||||
"%s_name_", prefix);
|
||||
prefix_length = strlen (prefix_name);
|
||||
|
||||
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);
|
||||
|
||||
ptr_value = infolist_search_var (infolist, option_value);
|
||||
if (ptr_value)
|
||||
{
|
||||
switch (hashtable->type_values)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes an item from hashtable.
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
struct t_hashtable;
|
||||
struct t_infolist_item;
|
||||
struct t_infolist;
|
||||
|
||||
typedef unsigned long long (t_hashtable_hash_key)(struct t_hashtable *hashtable,
|
||||
const void *key);
|
||||
@@ -149,6 +150,9 @@ extern void hashtable_set_pointer (struct t_hashtable *hashtable,
|
||||
extern int hashtable_add_to_infolist (struct t_hashtable *hashtable,
|
||||
struct t_infolist_item *infolist_item,
|
||||
const char *prefix);
|
||||
extern int hashtable_add_from_infolist (struct t_hashtable *hashtable,
|
||||
struct t_infolist *infolist,
|
||||
const char *prefix);
|
||||
extern void hashtable_remove (struct t_hashtable *hashtable, const void *key);
|
||||
extern void hashtable_remove_all (struct t_hashtable *hashtable);
|
||||
extern void hashtable_free (struct t_hashtable *hashtable);
|
||||
|
||||
Reference in New Issue
Block a user