summaryrefslogtreecommitdiff
path: root/src/core/wee-hashtable.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2018-05-20 15:21:07 +0200
committerSébastien Helleu <flashcode@flashtux.org>2018-05-20 15:21:07 +0200
commitafb1d0305313edef297e2f1f6ced9058a4560556 (patch)
tree789625c55c21c377a2618c709bfef2b56ad90693 /src/core/wee-hashtable.c
parent0329a9c7cde1334d0de17440b6d2d304bdf2e6eb (diff)
parent0a348f0b9dd31fe8546e61d445f23b44a26d1abf (diff)
downloadweechat-afb1d0305313edef297e2f1f6ced9058a4560556.zip
Merge remote-tracking branch 'origin/pr/623' into irc-3.2-cap
Diffstat (limited to 'src/core/wee-hashtable.c')
-rw-r--r--src/core/wee-hashtable.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c
index 825691b6f..7e1572966 100644
--- a/src/core/wee-hashtable.c
+++ b/src/core/wee-hashtable.c
@@ -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)
@@ -1102,6 +1104,83 @@ hashtable_add_to_infolist (struct t_hashtable *hashtable,
}
/*
+ * 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.
*/