summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--doc/en/weechat_plugin_api.en.txt37
-rw-r--r--doc/fr/weechat_plugin_api.fr.txt38
-rw-r--r--doc/it/weechat_plugin_api.it.txt39
-rw-r--r--src/core/wee-hashtable.c64
-rw-r--r--src/core/wee-hashtable.h12
-rw-r--r--src/plugins/plugin.c1
-rw-r--r--src/plugins/weechat-plugin.h9
8 files changed, 193 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 44ce8fe37..d33b91221 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
Sébastien Helleu <flashcode@flashtux.org>
-v0.3.4-rc2, 2011-01-01
+v0.3.4-rc2, 2011-01-02
Version 0.3.4 (under dev!)
@@ -42,8 +42,9 @@ Version 0.3.4 (under dev!)
(bug #30759)
* api: add priority for hooks (task #10550)
* api: add new functions: list_search_pos, list_casesearch_pos,
- hashtable_get_string, hook_info_hashtable, info_get_hashtable, hook_hsignal,
- hook_hsignal_send, hook_completion_get_string, nicklist_group_get_integer,
+ hashtable_get_string, hashtable_set_pointer, hook_info_hashtable,
+ info_get_hashtable, hook_hsignal, hook_hsignal_send,
+ hook_completion_get_string, nicklist_group_get_integer,
nicklist_group_get_string, nicklist_group_get_pointer, nicklist_group_set,
nicklist_nick_get_integer, nicklist_nick_get_string, nicklist_nick_get_pointer,
nicklist_nick_set
diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt
index bc4e754f0..aa9efc917 100644
--- a/doc/en/weechat_plugin_api.en.txt
+++ b/doc/en/weechat_plugin_api.en.txt
@@ -3278,6 +3278,43 @@ weechat_printf (NULL, "list of keys: %s",
[NOTE]
This function is not available in scripting API.
+weechat_hashtable_set_pointer
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+_New in version 0.3.4._
+
+Set pointer value of a hashtable property.
+
+Prototype:
+
+[source,C]
+----------------------------------------
+void weechat_hashtable_set_pointer (struct t_hashtable *hashtable,
+ const char *property, void *pointer);
+----------------------------------------
+
+Arguments:
+
+* 'hashtable': hashtable pointer
+* 'property' and 'value': property name, with its value:
+** 'callback_free_value': set callback function used to free values in hashtable
+
+C example:
+
+[source,C]
+----------------------------------------
+void
+my_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value)
+{
+ /* ... */
+}
+
+weechat_hashtable_set_pointer (hashtable, "callback_free_value", &my_free_value_cb);
+----------------------------------------
+
+[NOTE]
+This function is not available in scripting API.
+
weechat_hashtable_add_to_infolist
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt
index 817ae52d2..f94931599 100644
--- a/doc/fr/weechat_plugin_api.fr.txt
+++ b/doc/fr/weechat_plugin_api.fr.txt
@@ -3310,6 +3310,44 @@ weechat_printf (NULL, "liste des clés: %s",
[NOTE]
Cette fonction n'est pas disponible dans l'API script.
+weechat_hashtable_set_pointer
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+_Nouveau dans la version 0.3.4._
+
+Affecte un pointeur à une propriété d'une hashtable.
+
+Prototype :
+
+[source,C]
+----------------------------------------
+void weechat_hashtable_set_pointer (struct t_hashtable *hashtable,
+ const char *property, void *pointer);
+----------------------------------------
+
+Paramètres :
+
+* 'hashtable' : pointeur vers la hashtable
+* 'property' et 'value' : nom de la propriété, avec sa valeur :
+** 'callback_free_value' : définit la fonction "callback" pour libérer les
+ valeurs de la hashtable
+
+Exemple en C :
+
+[source,C]
+----------------------------------------
+void
+my_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value)
+{
+ /* ... */
+}
+
+weechat_hashtable_set_pointer (hashtable, "callback_free_value", &my_free_value_cb);
+----------------------------------------
+
+[NOTE]
+Cette fonction n'est pas disponible dans l'API script.
+
weechat_hashtable_add_to_infolist
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt
index d7a2ccdde..729061326 100644
--- a/doc/it/weechat_plugin_api.it.txt
+++ b/doc/it/weechat_plugin_api.it.txt
@@ -3268,6 +3268,45 @@ weechat_printf (NULL, "list of keys: %s",
[NOTE]
Questa funzione non è disponibile nelle API per lo scripting.
+weechat_hashtable_set_pointer
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+_Novità nella versione 0.3.4._
+
+// TRANSLATION MISSING
+Set pointer value of a hashtable property.
+
+Prototipo:
+
+[source,C]
+----------------------------------------
+void weechat_hashtable_set_pointer (struct t_hashtable *hashtable,
+ const char *property, void *pointer);
+----------------------------------------
+
+Argomenti:
+
+* 'hashtable': puntatore alla tabella hash
+* 'property' e 'value': nome della proprietà, con il proprio valore:
+// TRANSLATION MISSING
+** 'callback_free_value': set callback function used to free values in hashtable
+
+Esempio in C:
+
+[source,C]
+----------------------------------------
+void
+my_free_value_cb (struct t_hashtable *hashtable, const void *key, void *value)
+{
+ /* ... */
+}
+
+weechat_hashtable_set_pointer (hashtable, "callback_free_value", &my_free_value_cb);
+----------------------------------------
+
+[NOTE]
+Questa funzione non è disponibile nelle API per lo scripting.
+
weechat_hashtable_add_to_infolist
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c
index 2080426d3..99210cbc7 100644
--- a/src/core/wee-hashtable.c
+++ b/src/core/wee-hashtable.c
@@ -149,6 +149,8 @@ hashtable_new (int size,
new_hashtable->callback_keycmp = &hashtable_keycmp_string_cb;
else
new_hashtable->callback_keycmp = callback_keycmp;
+
+ new_hashtable->callback_free_value = NULL;
}
return new_hashtable;
}
@@ -211,19 +213,20 @@ hashtable_alloc_type (enum t_hashtable_type type,
}
/*
- * hashtable_free_type: free space used by a key or value
+ * hashtable_free_key: free space used by a key
*/
void
-hashtable_free_type (enum t_hashtable_type type, void *value)
+hashtable_free_key (struct t_hashtable *hashtable,
+ struct t_hashtable_item *item)
{
- switch (type)
+ switch (hashtable->type_keys)
{
case HASHTABLE_INTEGER:
case HASHTABLE_STRING:
case HASHTABLE_BUFFER:
case HASHTABLE_TIME:
- free (value);
+ free (item->key);
break;
case HASHTABLE_POINTER:
break;
@@ -233,6 +236,38 @@ hashtable_free_type (enum t_hashtable_type type, void *value)
}
/*
+ * hashtable_free_value: free space used by a value
+ */
+
+void
+hashtable_free_value (struct t_hashtable *hashtable,
+ struct t_hashtable_item *item)
+{
+ if (hashtable->callback_free_value)
+ {
+ (void) (hashtable->callback_free_value) (hashtable,
+ item->key,
+ item->value);
+ }
+ else
+ {
+ switch (hashtable->type_values)
+ {
+ case HASHTABLE_INTEGER:
+ case HASHTABLE_STRING:
+ case HASHTABLE_BUFFER:
+ case HASHTABLE_TIME:
+ free (item->value);
+ break;
+ case HASHTABLE_POINTER:
+ break;
+ case HASHTABLE_NUM_TYPES:
+ break;
+ }
+ }
+}
+
+/*
* hashtable_set_with_size: set value for item in hash table
* argument size is used only for type "buffer"
* return 1 if ok, 0 if error
@@ -267,7 +302,7 @@ hashtable_set_with_size (struct t_hashtable *hashtable,
/* replace value if item is already in hash table */
if (ptr_item && (hashtable->callback_keycmp (hashtable, key, ptr_item->key) == 0))
{
- hashtable_free_type (hashtable->type_values, ptr_item->value);
+ hashtable_free_value (hashtable, ptr_item);
hashtable_alloc_type (hashtable->type_values,
value, value_size,
&ptr_item->value, &ptr_item->value_size);
@@ -733,6 +768,21 @@ hashtable_get_string (struct t_hashtable *hashtable, const char *property)
}
/*
+ * hashtable_set_pointer: set a hashtable property (pointer)
+ */
+
+void
+hashtable_set_pointer (struct t_hashtable *hashtable, const char *property,
+ void *pointer)
+{
+ if (hashtable && property)
+ {
+ if (string_strcasecmp (property, "callback_free_value") == 0)
+ hashtable->callback_free_value = pointer;
+ }
+}
+
+/*
* hashtable_add_to_infolist: add hashtable keys and values to infolist
* return 1 if ok, 0 if error
*/
@@ -813,8 +863,8 @@ hashtable_remove_item (struct t_hashtable *hashtable,
return;
/* free key and value */
- hashtable_free_type (hashtable->type_keys, item->key);
- hashtable_free_type (hashtable->type_values, item->value);
+ hashtable_free_value (hashtable, item);
+ hashtable_free_key (hashtable, item);
/* remove item from list */
if (item->prev_item)
diff --git a/src/core/wee-hashtable.h b/src/core/wee-hashtable.h
index 4a76c6f21..b11a83429 100644
--- a/src/core/wee-hashtable.h
+++ b/src/core/wee-hashtable.h
@@ -27,6 +27,8 @@ typedef unsigned int (t_hashtable_hash_key)(struct t_hashtable *hashtable,
const void *key);
typedef int (t_hashtable_keycmp)(struct t_hashtable *hashtable,
const void *key1, const void *key2);
+typedef void (t_hashtable_free_value)(struct t_hashtable *hashtable,
+ const void *key, void *value);
typedef void (t_hashtable_map)(void *data,
struct t_hashtable *hashtable,
const void *key, const void *value);
@@ -95,9 +97,10 @@ struct t_hashtable
enum t_hashtable_type type_values; /* type for values: int/str/pointer */
/* callbacks */
- t_hashtable_hash_key *callback_hash_key; /* hash key to integer value */
- t_hashtable_keycmp *callback_keycmp; /* compare two keys */
-
+ t_hashtable_hash_key *callback_hash_key; /* hash key to int value */
+ t_hashtable_keycmp *callback_keycmp; /* compare two keys */
+ t_hashtable_free_value *callback_free_value; /* callback to free value */
+
/* keys/values as string */
char *keys_values; /* keys/values as string (NULL if */
/* never asked) */
@@ -122,6 +125,9 @@ extern int hashtable_get_integer (struct t_hashtable *hashtable,
const char *property);
extern const char *hashtable_get_string (struct t_hashtable *hashtable,
const char *property);
+extern void hashtable_set_pointer (struct t_hashtable *hashtable,
+ const char *property,
+ void *pointer);
extern int hashtable_add_to_infolist (struct t_hashtable *hashtable,
struct t_infolist_item *infolist_item,
const char *prefix);
diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c
index 7029154bb..771872023 100644
--- a/src/plugins/plugin.c
+++ b/src/plugins/plugin.c
@@ -532,6 +532,7 @@ plugin_load (const char *filename)
new_plugin->hashtable_map = &hashtable_map;
new_plugin->hashtable_get_integer = &hashtable_get_integer;
new_plugin->hashtable_get_string = &hashtable_get_string;
+ new_plugin->hashtable_set_pointer = &hashtable_set_pointer;
new_plugin->hashtable_add_to_infolist = &hashtable_add_to_infolist;
new_plugin->hashtable_remove = &hashtable_remove;
new_plugin->hashtable_remove_all = &hashtable_remove_all;
diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h
index 565e9cd1d..8f4550492 100644
--- a/src/plugins/weechat-plugin.h
+++ b/src/plugins/weechat-plugin.h
@@ -45,7 +45,7 @@ struct timeval;
*/
/* API version (used to check that plugin has same API and can be loaded) */
-#define WEECHAT_PLUGIN_API_VERSION "20101220-01"
+#define WEECHAT_PLUGIN_API_VERSION "20110102-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -281,6 +281,9 @@ struct t_weechat_plugin
const char *property);
const char *(*hashtable_get_string) (struct t_hashtable *hashtable,
const char *property);
+ void (*hashtable_set_pointer) (struct t_hashtable *hashtable,
+ const char *property,
+ void *pointer);
int (*hashtable_add_to_infolist) (struct t_hashtable *hashtable,
struct t_infolist_item *infolist_item,
const char *prefix);
@@ -950,6 +953,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
weechat_plugin->hashtable_get_integer(__hashtable, __property)
#define weechat_hashtable_get_string(__hashtable, __property) \
weechat_plugin->hashtable_get_string(__hashtable, __property)
+#define weechat_hashtable_set_pointer(__hashtable, __property, \
+ __pointer) \
+ weechat_plugin->hashtable_set_pointer(__hashtable, __property, \
+ __pointer)
#define weechat_hashtable_add_to_infolist(__hashtable, __infolist_item, \
__prefix) \
weechat_plugin->hashtable_add_to_infolist(__hashtable, \