summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-08-27 15:59:06 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-08-27 15:59:06 +0200
commit712623547f7e6fffc1bda625399ac54de87b6e2d (patch)
tree7353e6aec83c944eaa7b8af24694015b13f7715f /src/core
parentbb42984f5d6101ddc750700768ed3faf27f31021 (diff)
downloadweechat-712623547f7e6fffc1bda625399ac54de87b6e2d.zip
Add new functions in plugin API (hashtable_get_string, hook_info_hashtable, info_get_hashtable), add IRC info_hashtable "irc_parse_message"
Note: tcl >= 8.5 is now required (for tcl plugin).
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-hashtable.c22
-rw-r--r--src/core/wee-hashtable.h2
-rw-r--r--src/core/wee-hook.c152
-rw-r--r--src/core/wee-hook.h28
-rw-r--r--src/core/wee-string.c2
5 files changed, 202 insertions, 4 deletions
diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c
index bc44f1c13..0f4d91601 100644
--- a/src/core/wee-hashtable.c
+++ b/src/core/wee-hashtable.c
@@ -38,7 +38,9 @@
char *hashtable_type_string[HASHTABLE_NUM_TYPES] =
-{ "integer", "string", "pointer", "buffer", "time" };
+{ WEECHAT_HASHTABLE_INTEGER, WEECHAT_HASHTABLE_STRING,
+ WEECHAT_HASHTABLE_POINTER, WEECHAT_HASHTABLE_BUFFER,
+ WEECHAT_HASHTABLE_TIME };
/*
@@ -403,6 +405,24 @@ hashtable_get_integer (struct t_hashtable *hashtable, const char *property)
}
/*
+ * hashtable_get_string: get a hashtable property as string
+ */
+
+const char *
+hashtable_get_string (struct t_hashtable *hashtable, const char *property)
+{
+ if (hashtable && property)
+ {
+ if (string_strcasecmp (property, "type_keys") == 0)
+ return hashtable_type_string[hashtable->type_keys];
+ else if (string_strcasecmp (property, "type_values") == 0)
+ return hashtable_type_string[hashtable->type_values];
+ }
+
+ return NULL;
+}
+
+/*
* hashtable_add_to_infolist: add hashtable keys and values to infolist
* return 1 if ok, 0 if error
*/
diff --git a/src/core/wee-hashtable.h b/src/core/wee-hashtable.h
index 33dc7c11c..ab901528b 100644
--- a/src/core/wee-hashtable.h
+++ b/src/core/wee-hashtable.h
@@ -115,6 +115,8 @@ extern void hashtable_map (struct t_hashtable *hashtable,
void *callback_map_data);
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 int hashtable_add_to_infolist (struct t_hashtable *hashtable,
struct t_infolist_item *infolist_item,
const char *prefix);
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c
index d5e26b6fb..d49732ff4 100644
--- a/src/core/wee-hook.c
+++ b/src/core/wee-hook.c
@@ -36,6 +36,7 @@
#include "weechat.h"
#include "wee-hook.h"
+#include "wee-hashtable.h"
#include "wee-infolist.h"
#include "wee-list.h"
#include "wee-log.h"
@@ -52,7 +53,8 @@
char *hook_type_string[HOOK_NUM_TYPES] =
{ "command", "command_run", "timer", "fd", "process", "connect", "print",
- "signal", "config", "completion", "modifier", "info", "infolist" };
+ "signal", "config", "completion", "modifier", "info", "info_hashtable",
+ "infolist" };
struct t_hook *weechat_hooks[HOOK_NUM_TYPES]; /* list of hooks */
struct t_hook *last_weechat_hook[HOOK_NUM_TYPES]; /* last hook */
int hook_exec_recursion = 0; /* 1 when a hook is executed */
@@ -2188,7 +2190,7 @@ hook_info (struct t_weechat_plugin *plugin, const char *info_name,
}
/*
- * hook_info_get: get info via info hook
+ * hook_info_get: get info (as string) via info hook
*/
const char *
@@ -2235,6 +2237,101 @@ hook_info_get (struct t_weechat_plugin *plugin, const char *info_name,
}
/*
+ * hook_info_hashtable: hook an info using hashtable
+ */
+
+struct t_hook *
+hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
+ const char *description, const char *args_description,
+ const char *output_description,
+ t_hook_callback_info_hashtable *callback,
+ void *callback_data)
+{
+ struct t_hook *new_hook;
+ struct t_hook_info_hashtable *new_hook_info_hashtable;
+ int priority;
+ const char *ptr_info_name;
+
+ if (!info_name || !info_name[0] || !callback)
+ return NULL;
+
+ new_hook = malloc (sizeof (*new_hook));
+ if (!new_hook)
+ return NULL;
+ new_hook_info_hashtable = malloc (sizeof (*new_hook_info_hashtable));
+ if (!new_hook_info_hashtable)
+ {
+ free (new_hook);
+ return NULL;
+ }
+
+ hook_get_priority_and_name (info_name, &priority, &ptr_info_name);
+ hook_init_data (new_hook, plugin, HOOK_TYPE_INFO_HASHTABLE, priority,
+ callback_data);
+
+ new_hook->hook_data = new_hook_info_hashtable;
+ new_hook_info_hashtable->callback = callback;
+ new_hook_info_hashtable->info_name = strdup ((ptr_info_name) ?
+ ptr_info_name : info_name);
+ new_hook_info_hashtable->description = strdup ((description) ? description : "");
+ new_hook_info_hashtable->args_description = strdup ((args_description) ?
+ args_description : "");
+ new_hook_info_hashtable->output_description = strdup ((output_description) ?
+ output_description : "");
+
+ hook_add_to_list (new_hook);
+
+ return new_hook;
+}
+
+/*
+ * hook_info_get_hashtable: get info (as hashtable) via info hook
+ */
+
+struct t_hashtable *
+hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name,
+ struct t_hashtable *hashtable)
+{
+ struct t_hook *ptr_hook, *next_hook;
+ struct t_hashtable *value;
+
+ /* make C compiler happy */
+ (void) plugin;
+
+ if (!info_name || !info_name[0])
+ return NULL;
+
+ hook_exec_start ();
+
+ ptr_hook = weechat_hooks[HOOK_TYPE_INFO_HASHTABLE];
+ while (ptr_hook)
+ {
+ next_hook = ptr_hook->next_hook;
+
+ if (!ptr_hook->deleted
+ && !ptr_hook->running
+ && (string_strcasecmp (HOOK_INFO_HASHTABLE(ptr_hook, info_name),
+ info_name) == 0))
+ {
+ ptr_hook->running = 1;
+ value = (HOOK_INFO_HASHTABLE(ptr_hook, callback))
+ (ptr_hook->callback_data, info_name, hashtable);
+ ptr_hook->running = 0;
+
+ hook_exec_end ();
+ return value;
+ }
+
+ ptr_hook = next_hook;
+ }
+
+ hook_exec_end ();
+
+ /* info not found */
+ return NULL;
+}
+
+/*
* hook_infolist: hook an infolist
*/
@@ -2478,6 +2575,16 @@ unhook (struct t_hook *hook)
if (HOOK_INFO(hook, args_description))
free (HOOK_INFO(hook, args_description));
break;
+ case HOOK_TYPE_INFO_HASHTABLE:
+ if (HOOK_INFO_HASHTABLE(hook, info_name))
+ free (HOOK_INFO_HASHTABLE(hook, info_name));
+ if (HOOK_INFO_HASHTABLE(hook, description))
+ free (HOOK_INFO_HASHTABLE(hook, description));
+ if (HOOK_INFO_HASHTABLE(hook, args_description))
+ free (HOOK_INFO_HASHTABLE(hook, args_description));
+ if (HOOK_INFO_HASHTABLE(hook, output_description))
+ free (HOOK_INFO_HASHTABLE(hook, output_description));
+ break;
case HOOK_TYPE_INFOLIST:
if (HOOK_INFOLIST(hook, infolist_name))
free (HOOK_INFOLIST(hook, infolist_name));
@@ -2815,6 +2922,36 @@ hook_add_to_infolist_type (struct t_infolist *infolist,
return 0;
}
break;
+ case HOOK_TYPE_INFO_HASHTABLE:
+ if (!ptr_hook->deleted)
+ {
+ if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_INFO_HASHTABLE(ptr_hook, callback)))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "info_name", HOOK_INFO_HASHTABLE(ptr_hook, info_name)))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "description", HOOK_INFO_HASHTABLE(ptr_hook, description)))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "description_nls",
+ (HOOK_INFO_HASHTABLE(ptr_hook, description)
+ && HOOK_INFO_HASHTABLE(ptr_hook, description)[0]) ?
+ _(HOOK_INFO_HASHTABLE(ptr_hook, description)) : ""))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "args_description", HOOK_INFO_HASHTABLE(ptr_hook, args_description)))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "args_description_nls",
+ (HOOK_INFO_HASHTABLE(ptr_hook, args_description)
+ && HOOK_INFO_HASHTABLE(ptr_hook, args_description)[0]) ?
+ _(HOOK_INFO_HASHTABLE(ptr_hook, args_description)) : ""))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "output_description", HOOK_INFO_HASHTABLE(ptr_hook, output_description)))
+ return 0;
+ if (!infolist_new_var_string (ptr_item, "output_description_nls",
+ (HOOK_INFO_HASHTABLE(ptr_hook, output_description)
+ && HOOK_INFO_HASHTABLE(ptr_hook, output_description)[0]) ?
+ _(HOOK_INFO_HASHTABLE(ptr_hook, output_description)) : ""))
+ return 0;
+ }
+ break;
case HOOK_TYPE_INFOLIST:
if (!ptr_hook->deleted)
{
@@ -3079,6 +3216,17 @@ hook_print_log ()
log_printf (" args_description. . . : '%s'", HOOK_INFO(ptr_hook, args_description));
}
break;
+ case HOOK_TYPE_INFO_HASHTABLE:
+ if (!ptr_hook->deleted)
+ {
+ log_printf (" info_hashtable data:");
+ log_printf (" callback. . . . . . . : 0x%lx", HOOK_INFO_HASHTABLE(ptr_hook, callback));
+ log_printf (" info_name . . . . . . : '%s'", HOOK_INFO_HASHTABLE(ptr_hook, info_name));
+ log_printf (" description . . . . . : '%s'", HOOK_INFO_HASHTABLE(ptr_hook, description));
+ log_printf (" args_description. . . : '%s'", HOOK_INFO_HASHTABLE(ptr_hook, args_description));
+ log_printf (" output_description. . : '%s'", HOOK_INFO_HASHTABLE(ptr_hook, output_description));
+ }
+ break;
case HOOK_TYPE_INFOLIST:
if (!ptr_hook->deleted)
{
diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h
index 7a10b8ad3..2e2b735d6 100644
--- a/src/core/wee-hook.h
+++ b/src/core/wee-hook.h
@@ -28,6 +28,7 @@ struct t_gui_buffer;
struct t_gui_line;
struct t_gui_completion;
struct t_weelist;
+struct t_hashtable;
struct t_infolist;
/* hook types */
@@ -46,6 +47,7 @@ enum t_hook_type
HOOK_TYPE_COMPLETION, /* custom completions */
HOOK_TYPE_MODIFIER, /* string modifier */
HOOK_TYPE_INFO, /* get some info as string */
+ HOOK_TYPE_INFO_HASHTABLE, /* get some info as hashtable */
HOOK_TYPE_INFOLIST, /* get some info as infolist */
/* number of hook types */
HOOK_NUM_TYPES,
@@ -78,6 +80,7 @@ enum t_hook_type
#define HOOK_COMPLETION(hook, var) (((struct t_hook_completion *)hook->hook_data)->var)
#define HOOK_MODIFIER(hook, var) (((struct t_hook_modifier *)hook->hook_data)->var)
#define HOOK_INFO(hook, var) (((struct t_hook_info *)hook->hook_data)->var)
+#define HOOK_INFO_HASHTABLE(hook, var) (((struct t_hook_info_hashtable *)hook->hook_data)->var)
#define HOOK_INFOLIST(hook, var) (((struct t_hook_infolist *)hook->hook_data)->var)
struct t_hook
@@ -300,6 +303,21 @@ struct t_hook_info
char *args_description; /* description of arguments */
};
+/* hook info (hashtable) */
+
+typedef struct t_hashtable *(t_hook_callback_info_hashtable)(void *data,
+ const char *info_name,
+ struct t_hashtable *hashtable);
+
+struct t_hook_info_hashtable
+{
+ t_hook_callback_info_hashtable *callback; /* info_hashtable callback */
+ char *info_name; /* name of info returned */
+ char *description; /* description */
+ char *args_description; /* description of arguments */
+ char *output_description; /* description of output (hashtable) */
+};
+
/* hook infolist */
typedef struct t_infolist *(t_hook_callback_infolist)(void *data,
@@ -425,6 +443,16 @@ extern struct t_hook *hook_info (struct t_weechat_plugin *plugin,
extern const char *hook_info_get (struct t_weechat_plugin *plugin,
const char *info_name,
const char *arguments);
+extern struct t_hook *hook_info_hashtable (struct t_weechat_plugin *plugin,
+ const char *info_name,
+ const char *description,
+ const char *args_description,
+ const char *output_description,
+ t_hook_callback_info_hashtable *callback,
+ void *callback_data);
+extern struct t_hashtable *hook_info_get_hashtable (struct t_weechat_plugin *plugin,
+ const char *info_name,
+ struct t_hashtable *hashtable);
extern struct t_hook *hook_infolist (struct t_weechat_plugin *plugin,
const char *infolist_name,
const char *description,
diff --git a/src/core/wee-string.c b/src/core/wee-string.c
index 8e3fdb66b..da30195f4 100644
--- a/src/core/wee-string.c
+++ b/src/core/wee-string.c
@@ -377,7 +377,7 @@ string_replace (const char *string, const char *search, const char *replace)
if (!new_string)
return strdup (string);
- /* replace all occurences */
+ /* replace all occurrences */
new_string[0] = '\0';
while (string && string[0])
{