1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 17:23:15 +02:00

core: add "hdata" (direct access to WeeChat/plugin data)

This commit is contained in:
Sebastien Helleu
2011-06-13 12:32:27 +02:00
parent 756252b95c
commit c8b2a6a084
77 changed files with 12088 additions and 275 deletions
+1
View File
@@ -28,6 +28,7 @@ wee-config.c wee-config.h
wee-config-file.c wee-config-file.h
wee-debug.c wee-debug.h
wee-hashtable.c wee-hashtable.h
wee-hdata.c wee-hdata.h
wee-hook.c wee-hook.h
wee-infolist.c wee-infolist.h
wee-input.c wee-input.h
+2
View File
@@ -37,6 +37,8 @@ lib_weechat_core_a_SOURCES = weechat.c \
wee-debug.h \
wee-hashtable.c \
wee-hashtable.h \
wee-hdata.c \
wee-hdata.h \
wee-hook.c \
wee-hook.h \
wee-infolist.c \
+7 -1
View File
@@ -1152,6 +1152,10 @@ COMMAND_CALLBACK(debug)
{
gui_color_dump (buffer);
}
else if (string_strcasecmp (argv[1], "hdata") == 0)
{
debug_hdata ();
}
else if (string_strcasecmp (argv[1], "infolists") == 0)
{
debug_infolists ();
@@ -4837,7 +4841,7 @@ command_init ()
N_("list"
" || set <plugin> <level>"
" || dump [<plugin>]"
" || buffer|color|infolists|memory|term|windows"),
" || buffer|color|hdata|infolists|memory|term|windows"),
N_(" list: list plugins with debug levels\n"
" set: set debug level for plugin\n"
" plugin: name of plugin (\"core\" for WeeChat core)\n"
@@ -4847,6 +4851,7 @@ command_init ()
" buffer: dump buffer content with hexadecimal values "
"in log file\n"
" color: display infos about current color pairs\n"
" hdata: display infos about hdata\n"
"infolists: display infos about infolists\n"
" memory: display infos about memory usage\n"
" term: display infos about terminal\n"
@@ -4856,6 +4861,7 @@ command_init ()
" || dump %(plugins_names)|core"
" || buffer"
" || color"
" || hdata"
" || infolists"
" || memory"
" || term"
+125
View File
@@ -27,6 +27,7 @@
#endif
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h>
@@ -34,6 +35,7 @@
#include "weechat.h"
#include "wee-config-file.h"
#include "wee-hdata.h"
#include "wee-hook.h"
#include "wee-infolist.h"
#include "wee-log.h"
@@ -51,6 +53,10 @@ char *config_option_type_string[CONFIG_NUM_OPTION_TYPES] =
char *config_boolean_true[] = { "on", "yes", "y", "true", "t", "1", NULL };
char *config_boolean_false[] = { "off", "no", "n", "false", "f", "0", NULL };
struct t_hdata *config_file_hdata_config_file = NULL;
struct t_hdata *config_file_hdata_config_section = NULL;
struct t_hdata *config_file_hdata_config_option = NULL;
void config_file_option_free_data (struct t_config_option *option);
@@ -2543,6 +2549,125 @@ config_file_free_all_plugin (struct t_weechat_plugin *plugin)
}
}
/*
* config_file_hdata_config_file_cb: return hdata for config_file
*/
struct t_hdata *
config_file_hdata_config_file_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (config_file_hdata_config_file)
return config_file_hdata_config_file;
hdata = hdata_new (hdata_name, "prev_config", "next_config");
if (hdata)
{
config_file_hdata_config_file = hdata;
HDATA_VAR(struct t_config_file, plugin, POINTER);
HDATA_VAR(struct t_config_file, name, STRING);
HDATA_VAR(struct t_config_file, filename, STRING);
HDATA_VAR(struct t_config_file, file, POINTER);
HDATA_VAR(struct t_config_file, callback_reload, POINTER);
HDATA_VAR(struct t_config_file, callback_reload_data, POINTER);
HDATA_VAR(struct t_config_file, sections, POINTER);
HDATA_VAR(struct t_config_file, last_section, POINTER);
HDATA_VAR(struct t_config_file, prev_config, POINTER);
HDATA_VAR(struct t_config_file, next_config, POINTER);
HDATA_LIST(config_files);
HDATA_LIST(last_config_file);
}
return config_file_hdata_config_file;
}
/*
* config_file_hdata_config_section_cb: return hdata for config_section
*/
struct t_hdata *
config_file_hdata_config_section_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (config_file_hdata_config_section)
return config_file_hdata_config_section;
hdata = hdata_new (hdata_name, "prev_section", "next_section");
if (hdata)
{
config_file_hdata_config_section = hdata;
HDATA_VAR(struct t_config_section, config_file, POINTER);
HDATA_VAR(struct t_config_section, name, STRING);
HDATA_VAR(struct t_config_section, user_can_add_options, INTEGER);
HDATA_VAR(struct t_config_section, user_can_delete_options, INTEGER);
HDATA_VAR(struct t_config_section, callback_read, POINTER);
HDATA_VAR(struct t_config_section, callback_read_data, POINTER);
HDATA_VAR(struct t_config_section, callback_write, POINTER);
HDATA_VAR(struct t_config_section, callback_write_data, POINTER);
HDATA_VAR(struct t_config_section, callback_write_default, POINTER);
HDATA_VAR(struct t_config_section, callback_write_default_data, POINTER);
HDATA_VAR(struct t_config_section, callback_create_option, POINTER);
HDATA_VAR(struct t_config_section, callback_create_option_data, POINTER);
HDATA_VAR(struct t_config_section, callback_delete_option, POINTER);
HDATA_VAR(struct t_config_section, callback_delete_option_data, POINTER);
HDATA_VAR(struct t_config_section, options, POINTER);
HDATA_VAR(struct t_config_section, last_option, POINTER);
HDATA_VAR(struct t_config_section, prev_section, POINTER);
HDATA_VAR(struct t_config_section, next_section, POINTER);
}
return config_file_hdata_config_section;
}
/*
* config_file_hdata_config_option_cb: return hdata for config_option
*/
struct t_hdata *
config_file_hdata_config_option_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (config_file_hdata_config_option)
return config_file_hdata_config_option;
hdata = hdata_new (hdata_name, "prev_option", "next_option");
if (hdata)
{
config_file_hdata_config_option = hdata;
HDATA_VAR(struct t_config_option, config_file, POINTER);
HDATA_VAR(struct t_config_option, section, POINTER);
HDATA_VAR(struct t_config_option, name, STRING);
HDATA_VAR(struct t_config_option, type, INTEGER);
HDATA_VAR(struct t_config_option, description, STRING);
HDATA_VAR(struct t_config_option, string_values, POINTER);
HDATA_VAR(struct t_config_option, min, INTEGER);
HDATA_VAR(struct t_config_option, max, INTEGER);
HDATA_VAR(struct t_config_option, default_value, POINTER);
HDATA_VAR(struct t_config_option, value, POINTER);
HDATA_VAR(struct t_config_option, null_value_allowed, INTEGER);
HDATA_VAR(struct t_config_option, callback_check_value, POINTER);
HDATA_VAR(struct t_config_option, callback_check_value_data, POINTER);
HDATA_VAR(struct t_config_option, callback_change, POINTER);
HDATA_VAR(struct t_config_option, callback_change_data, POINTER);
HDATA_VAR(struct t_config_option, callback_delete, POINTER);
HDATA_VAR(struct t_config_option, callback_delete_data, POINTER);
HDATA_VAR(struct t_config_option, loaded, INTEGER);
HDATA_VAR(struct t_config_option, prev_option, POINTER);
HDATA_VAR(struct t_config_option, next_option, POINTER);
}
return config_file_hdata_config_option;
}
/*
* config_file_add_to_infolist: add configuration options in an infolist
* return 1 if ok, 0 if error
+6
View File
@@ -248,6 +248,12 @@ extern void config_file_section_free (struct t_config_section *section);
extern void config_file_free (struct t_config_file *config_file);
extern void config_file_free_all ();
extern void config_file_free_all_plugin (struct t_weechat_plugin *plugin);
extern struct t_hdata *config_file_hdata_config_file_cb (void *data,
const char *hdata_name);
extern struct t_hdata *config_file_hdata_config_section_cb (void *data,
const char *hdata_name);
extern struct t_hdata *config_file_hdata_config_option_cb (void *data,
const char *hdata_name);
extern int config_file_add_to_infolist (struct t_infolist *infolist,
const char *option_name);
extern void config_file_print_log ();
+109 -2
View File
@@ -35,7 +35,10 @@
#include "weechat.h"
#include "wee-backtrace.h"
#include "wee-config-file.h"
#include "wee-hashtable.h"
#include "wee-hdata.h"
#include "wee-infolist.h"
#include "wee-list.h"
#include "wee-log.h"
#include "wee-hook.h"
#include "wee-proxy.h"
@@ -95,6 +98,8 @@ debug_dump (int crash)
gui_bar_item_print_log ();
gui_hotlist_print_log ();
hdata_print_log ();
infolist_print_log ();
hook_print_log ();
@@ -294,6 +299,108 @@ debug_memory ()
#endif
}
/*
* debug_hdata_hash_var_map_cb: function called for each variable in hdata
*/
void
debug_hdata_hash_var_map_cb (void *data,
struct t_hashtable *hashtable,
const void *key, const void *value)
{
struct t_weelist *list;
char str_offset[16];
/* make C compiler happy */
(void) hashtable;
list = (struct t_weelist *)data;
snprintf (str_offset, sizeof (str_offset),
"%12d", (*((int *)value)) & 0xFFFF);
weelist_add (list, str_offset, WEECHAT_LIST_POS_SORT, (void *)key);
}
/*
* debug_hdata_hash_list_map_cb: function called for each list in hdata
*/
void
debug_hdata_hash_list_map_cb (void *data,
struct t_hashtable *hashtable,
const void *key, const void *value)
{
/* make C compiler happy */
(void) data;
(void) hashtable;
gui_chat_printf (NULL,
" list: %s -> 0x%lx",
(char *)key,
*((void **)value));
}
/*
* debug_hdata: display list of hdata in memory
*/
void
debug_hdata ()
{
struct t_hdata *ptr_hdata;
int i, count;
struct t_weelist *list;
struct t_weelist_item *ptr_item;
void *value;
count = 0;
for (ptr_hdata = weechat_hdata; ptr_hdata;
ptr_hdata = ptr_hdata->next_hdata)
{
count++;
}
gui_chat_printf (NULL, "");
gui_chat_printf (NULL, "%d hdata in memory", count);
if (count > 0)
{
i = 0;
for (ptr_hdata = weechat_hdata; ptr_hdata;
ptr_hdata = ptr_hdata->next_hdata)
{
gui_chat_printf (NULL,
"%4d: hdata 0x%lx: \"%s\", %d vars, %d lists:",
i + 1, ptr_hdata,
ptr_hdata->name,
hashtable_get_integer (ptr_hdata->hash_var,
"items_count"),
hashtable_get_integer (ptr_hdata->hash_list,
"items_count"));
list = weelist_new ();
hashtable_map (ptr_hdata->hash_var,
&debug_hdata_hash_var_map_cb, list);
for (ptr_item = list->items; ptr_item;
ptr_item = ptr_item->next_item)
{
value = hashtable_get (ptr_hdata->hash_var, ptr_item->user_data);
if (value)
{
gui_chat_printf (NULL,
" %04d -> %s (%s)",
(*((int *)value)) & 0xFFFF,
(char *)ptr_item->user_data,
hdata_type_string[(*((int *)value)) >> 16]);
}
}
weelist_free (list);
hashtable_map (ptr_hdata->hash_list,
&debug_hdata_hash_list_map_cb, NULL);
i++;
}
}
}
/*
* debug_infolists: display list of infolists in memory
*/
@@ -370,7 +477,7 @@ debug_infolists ()
}
}
gui_chat_printf (NULL,
" %d: infolist 0x%lx: %d items, %d vars - "
"%4d: infolist 0x%lx: %d items, %d vars - "
"structs: %d, data: %d (total: %d bytes)",
i + 1, ptr_infolist, count_items, count_vars,
size_structs, size_data, size_structs + size_data);
@@ -378,7 +485,7 @@ debug_infolists ()
i++;
}
gui_chat_printf (NULL,
" Total: %d items, %d vars - %d bytes",
"Total: %d items, %d vars - %d bytes",
total_items, total_vars, total_size);
}
}
+1
View File
@@ -25,6 +25,7 @@ struct t_gui_window_tree;
extern void debug_sigsegv ();
extern void debug_windows_tree ();
extern void debug_memory ();
extern void debug_hdata ();
extern void debug_infolists ();
extern void debug_init ();
+400
View File
@@ -0,0 +1,400 @@
/*
* Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* WeeChat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* wee-hdata.c: direct access to WeeChat data using hashtables (for C plugins)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include "weechat.h"
#include "wee-hdata.h"
#include "wee-hashtable.h"
#include "wee-log.h"
#include "wee-string.h"
#include "../plugins/plugin.h"
struct t_hdata *weechat_hdata = NULL;
struct t_hdata *last_weechat_hdata = NULL;
char *hdata_type_string[6] =
{ "other", "integer", "long", "string", "pointer", "time" };
/*
* hdata_new: create a new hdata
*/
struct t_hdata *
hdata_new (const char *hdata_name, const char *var_prev, const char *var_next)
{
struct t_hdata *new_hdata;
if (!hdata_name || !hdata_name[0])
return NULL;
new_hdata = malloc (sizeof (*new_hdata));
if (new_hdata)
{
new_hdata->name = strdup (hdata_name);
new_hdata->hash_var = hashtable_new (8,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_INTEGER,
NULL,
NULL);
new_hdata->var_prev = (var_prev) ? strdup (var_prev) : NULL;
new_hdata->var_next = (var_next) ? strdup (var_next) : NULL;
new_hdata->hash_list = hashtable_new (8,
WEECHAT_HASHTABLE_STRING,
WEECHAT_HASHTABLE_POINTER,
NULL,
NULL);
new_hdata->prev_hdata = last_weechat_hdata;
new_hdata->next_hdata = NULL;
if (weechat_hdata)
last_weechat_hdata->next_hdata = new_hdata;
else
weechat_hdata = new_hdata;
last_weechat_hdata = new_hdata;
}
return new_hdata;
}
/*
* hdata_new_var: add a new variable (offset/type) in a hdata
*/
void
hdata_new_var (struct t_hdata *hdata, const char *name, int offset, int type)
{
int value;
if (hdata && name)
{
value = (type << 16) | (offset & 0xFFFF);
hashtable_set (hdata->hash_var, name, &value);
}
}
/*
* hdata_new_list: add a new list pointer in a hdata
*/
void
hdata_new_list (struct t_hdata *hdata, const char *name, void *pointer)
{
if (hdata && name)
hashtable_set (hdata->hash_list, name, pointer);
}
/*
* hdata_get_var_offset: get offset of variable
*/
int
hdata_get_var_offset (struct t_hdata *hdata, const char *name)
{
int *ptr_value;
if (hdata && name)
{
ptr_value = hashtable_get (hdata->hash_var, name);
if (ptr_value)
return (*ptr_value) & 0xFFFF;
}
return -1;
}
/*
* hdata_get_var_type: get type of variable (as integer)
*/
int
hdata_get_var_type (struct t_hdata *hdata, const char *name)
{
int *ptr_value;
if (hdata && name)
{
ptr_value = hashtable_get (hdata->hash_var, name);
if (ptr_value)
return (*ptr_value) >> 16;
}
return -1;
}
/*
* hdata_get_var_type_string: get type of variable (as string)
*/
const char *
hdata_get_var_type_string (struct t_hdata *hdata, const char *name)
{
int *ptr_value;
if (hdata && name)
{
ptr_value = hashtable_get (hdata->hash_var, name);
if (ptr_value)
return hdata_type_string[(*ptr_value) >> 16];
}
return NULL;
}
/*
* hdata_get_var: get pointer to content of variable using hdata var name
*/
void *
hdata_get_var (struct t_hdata *hdata, void *pointer, const char *name)
{
int offset;
if (hdata && pointer)
{
offset = hdata_get_var_offset (hdata, name);
if (offset >= 0)
return pointer + offset;
}
return NULL;
}
/*
* hdata_get_var_at_offset: get pointer to content of variable using hdata var
* offset
*/
void *
hdata_get_var_at_offset (struct t_hdata *hdata, void *pointer, int offset)
{
if (hdata && pointer)
return pointer + offset;
return NULL;
}
/*
* hdata_get_list: get a list pointer
*/
void *
hdata_get_list (struct t_hdata *hdata, const char *name)
{
void *ptr_value;
if (hdata && name)
{
ptr_value = hashtable_get (hdata->hash_list, name);
if (ptr_value)
return *((void **)ptr_value);
}
return NULL;
}
/*
* hdata_move: move pointer to another element in list
*/
void *
hdata_move (struct t_hdata *hdata, void *pointer, int count)
{
char *ptr_var;
int i, abs_count;
if (hdata && pointer && (count != 0))
{
ptr_var = (count < 0) ? hdata->var_prev : hdata->var_next;
abs_count = abs(count);
for (i = 0; i < abs_count; i++)
{
pointer = hdata_pointer (hdata, pointer, ptr_var);
if (pointer)
return pointer;
}
}
return NULL;
}
/*
* hdata_integer: get integer value of a variable in structure using hdata
*/
int
hdata_integer (struct t_hdata *hdata, void *pointer, const char *name)
{
int offset;
if (hdata && pointer)
{
offset = hdata_get_var_offset (hdata, name);
if (offset >= 0)
return *((int *)(pointer + offset));
}
return 0;
}
/*
* hdata_long: get long value of a variable in structure using hdata
*/
long
hdata_long (struct t_hdata *hdata, void *pointer, const char *name)
{
int offset;
if (hdata && pointer)
{
offset = hdata_get_var_offset (hdata, name);
if (offset >= 0)
return *((long *)(pointer + offset));
}
return 0;
}
/*
* hdata_string: get string value of a variable in structure using hdata
*/
const char *
hdata_string (struct t_hdata *hdata, void *pointer, const char *name)
{
int offset;
if (hdata && pointer)
{
offset = hdata_get_var_offset (hdata, name);
if (offset >= 0)
return *((char **)(pointer + offset));
}
return NULL;
}
/*
* hdata_pointer: get pointer value of a variable in structure using hdata
*/
void *
hdata_pointer (struct t_hdata *hdata, void *pointer, const char *name)
{
int offset;
if (hdata && pointer)
{
offset = hdata_get_var_offset (hdata, name);
if (offset >= 0)
return *((void **)(pointer + offset));
}
return NULL;
}
/*
* hdata_time: get time value of a variable in structure using hdata
*/
time_t
hdata_time (struct t_hdata *hdata, void *pointer, const char *name)
{
int offset;
if (hdata && pointer)
{
offset = hdata_get_var_offset (hdata, name);
if (offset >= 0)
return *((time_t *)(pointer + offset));
}
return 0;
}
/*
* hdata_get_string: get a hdata property as string
*/
const char *
hdata_get_string (struct t_hdata *hdata, const char *property)
{
if (hdata && property)
{
if (string_strcasecmp (property, "var_keys") == 0)
return hashtable_get_string (hdata->hash_var, "keys");
else if (string_strcasecmp (property, "var_values") == 0)
return hashtable_get_string (hdata->hash_var, "values");
else if (string_strcasecmp (property, "var_keys_values") == 0)
return hashtable_get_string (hdata->hash_var, "keys_values");
else if (string_strcasecmp (property, "var_prev") == 0)
return hdata->var_prev;
else if (string_strcasecmp (property, "var_next") == 0)
return hdata->var_next;
else if (string_strcasecmp (property, "list_keys") == 0)
return hashtable_get_string (hdata->hash_list, "keys");
else if (string_strcasecmp (property, "list_values") == 0)
return hashtable_get_string (hdata->hash_list, "values");
else if (string_strcasecmp (property, "list_keys_values") == 0)
return hashtable_get_string (hdata->hash_list, "keys_values");
}
return NULL;
}
/*
* hdata_print_log: print hdata in log (usually for crash dump)
*/
void
hdata_print_log ()
{
struct t_hdata *ptr_hdata;
for (ptr_hdata = weechat_hdata; ptr_hdata;
ptr_hdata = ptr_hdata->next_hdata)
{
log_printf ("");
log_printf ("[hdata (addr:0x%lx)]", ptr_hdata);
log_printf (" name . . . . . . . . . : '%s'", ptr_hdata->name);
log_printf (" hash_var . . . . . . . : 0x%lx (hashtable: '%s')",
ptr_hdata->hash_var,
hashtable_get_string (ptr_hdata->hash_var, "keys_values"));
log_printf (" var_prev . . . . . . . : '%s'", ptr_hdata->var_prev);
log_printf (" var_next . . . . . . . : '%s'", ptr_hdata->var_next);
log_printf (" hash_list. . . . . . . : 0x%lx (hashtable: '%s')",
ptr_hdata->hash_list,
hashtable_get_string (ptr_hdata->hash_list, "keys_values"));
log_printf (" prev_hdata . . . . . . : 0x%lx", ptr_hdata->prev_hdata);
log_printf (" next_hdata . . . . . . : 0x%lx", ptr_hdata->next_hdata);
}
}
+77
View File
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2011 Sebastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* WeeChat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __WEECHAT_HDATA_H
#define __WEECHAT_HDATA_H 1
#define HDATA_VAR(__struct, __name, __type) \
hdata_new_var (hdata, #__name, offsetof (__struct, __name), \
WEECHAT_HDATA_##__type);
#define HDATA_LIST(__name) hdata_new_list (hdata, #__name, &(__name));
struct t_hdata
{
char *name; /* name of hdata */
struct t_hashtable *hash_var; /* hashtable with offset of vars */
char *var_prev; /* name of var with pointer to */
/* previous element in list */
char *var_next; /* name of var with pointer to */
/* next element in list */
struct t_hashtable *hash_list; /* hashtable with pointers on lists */
/* (used to search objects) */
struct t_hdata *prev_hdata; /* link to previous hdata */
struct t_hdata *next_hdata; /* link to next hdata */
};
extern struct t_hdata *weechat_hdata;
extern struct t_hdata *last_weechat_hdata;
extern char *hdata_type_string[];
extern struct t_hdata *hdata_new (const char *hdata_name, const char *var_prev,
const char *var_next);
extern void hdata_new_var (struct t_hdata *hdata, const char *name, int offset,
int type);
extern void hdata_new_list (struct t_hdata *hdata, const char *name,
void *pointer);
extern int hdata_get_var_offset (struct t_hdata *hdata, const char *name);
extern int hdata_get_var_type (struct t_hdata *hdata, const char *name);
extern const char *hdata_get_var_type_string (struct t_hdata *hdata,
const char *name);
extern void *hdata_get_var (struct t_hdata *hdata, void *pointer,
const char *name);
extern void *hdata_get_var_at_offset (struct t_hdata *hdata, void *pointer,
int offset);
extern void *hdata_get_list (struct t_hdata *hdata, const char *name);
extern void *hdata_move (struct t_hdata *hdata, void *pointer, int count);
extern int hdata_integer (struct t_hdata *hdata, void *pointer,
const char *name);
extern long hdata_long (struct t_hdata *hdata, void *pointer,
const char *name);
extern const char *hdata_string (struct t_hdata *hdata, void *pointer,
const char *name);
extern void *hdata_pointer (struct t_hdata *hdata, void *pointer,
const char *name);
extern time_t hdata_time (struct t_hdata *hdata, void *pointer,
const char *name);
extern const char *hdata_get_string (struct t_hdata *hdata,
const char *property);
extern void hdata_print_log ();
#endif /* __WEECHAT_HDATA_H */
+666 -3
View File
@@ -25,8 +25,9 @@
#include "config.h"
#endif
#include <unistd.h>
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <time.h>
@@ -37,6 +38,7 @@
#include "weechat.h"
#include "wee-hook.h"
#include "wee-hashtable.h"
#include "wee-hdata.h"
#include "wee-infolist.h"
#include "wee-list.h"
#include "wee-log.h"
@@ -54,13 +56,31 @@
char *hook_type_string[HOOK_NUM_TYPES] =
{ "command", "command_run", "timer", "fd", "process", "connect", "print",
"signal", "hsignal", "config", "completion", "modifier",
"info", "info_hashtable", "infolist" };
"info", "info_hashtable", "infolist", "hdata" };
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 */
time_t hook_last_system_time = 0; /* used to detect system clock skew */
int real_delete_pending = 0; /* 1 if some hooks must be deleted */
struct t_hdata *hook_hdata_hook = NULL;
struct t_hdata *hook_hdata_hook_command = NULL;
struct t_hdata *hook_hdata_hook_command_run = NULL;
struct t_hdata *hook_hdata_hook_timer = NULL;
struct t_hdata *hook_hdata_hook_fd = NULL;
struct t_hdata *hook_hdata_hook_process = NULL;
struct t_hdata *hook_hdata_hook_connect = NULL;
struct t_hdata *hook_hdata_hook_print = NULL;
struct t_hdata *hook_hdata_hook_signal = NULL;
struct t_hdata *hook_hdata_hook_hsignal = NULL;
struct t_hdata *hook_hdata_hook_config = NULL;
struct t_hdata *hook_hdata_hook_completion = NULL;
struct t_hdata *hook_hdata_hook_modifier = NULL;
struct t_hdata *hook_hdata_hook_info = NULL;
struct t_hdata *hook_hdata_hook_info_hashtable = NULL;
struct t_hdata *hook_hdata_hook_infolist = NULL;
struct t_hdata *hook_hdata_hook_hdata = NULL;
void hook_process_run (struct t_hook *hook_process);
@@ -2580,7 +2600,7 @@ hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name,
}
/*
* hook_infolist_get: get info via info hook
* hook_infolist_get: get infolist via infolist hook
*/
struct t_infolist *
@@ -2626,6 +2646,95 @@ hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name,
return NULL;
}
/*
* hook_hdata: hook a hdata
*/
struct t_hook *
hook_hdata (struct t_weechat_plugin *plugin, const char *hdata_name,
const char *description,
t_hook_callback_hdata *callback, void *callback_data)
{
struct t_hook *new_hook;
struct t_hook_hdata *new_hook_hdata;
int priority;
const char *ptr_hdata_name;
if (!hdata_name || !hdata_name[0] || !callback)
return NULL;
new_hook = malloc (sizeof (*new_hook));
if (!new_hook)
return NULL;
new_hook_hdata = malloc (sizeof (*new_hook_hdata));
if (!new_hook_hdata)
{
free (new_hook);
return NULL;
}
hook_get_priority_and_name (hdata_name, &priority, &ptr_hdata_name);
hook_init_data (new_hook, plugin, HOOK_TYPE_HDATA, priority,
callback_data);
new_hook->hook_data = new_hook_hdata;
new_hook_hdata->callback = callback;
new_hook_hdata->hdata_name = strdup ((ptr_hdata_name) ?
ptr_hdata_name : hdata_name);
new_hook_hdata->description = strdup ((description) ? description : "");
hook_add_to_list (new_hook);
return new_hook;
}
/*
* hook_hdata_get: get hdata via info hook
*/
struct t_hdata *
hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name)
{
struct t_hook *ptr_hook, *next_hook;
struct t_hdata *value;
/* make C compiler happy */
(void) plugin;
if (!hdata_name || !hdata_name[0])
return NULL;
hook_exec_start ();
ptr_hook = weechat_hooks[HOOK_TYPE_HDATA];
while (ptr_hook)
{
next_hook = ptr_hook->next_hook;
if (!ptr_hook->deleted
&& !ptr_hook->running
&& (string_strcasecmp (HOOK_HDATA(ptr_hook, hdata_name),
hdata_name) == 0))
{
ptr_hook->running = 1;
value = (HOOK_HDATA(ptr_hook, callback))
(ptr_hook->callback_data,
HOOK_HDATA(ptr_hook, hdata_name));
ptr_hook->running = 0;
hook_exec_end ();
return value;
}
ptr_hook = next_hook;
}
hook_exec_end ();
/* hdata not found */
return NULL;
}
/*
* unhook: unhook something
*/
@@ -2810,6 +2919,12 @@ unhook (struct t_hook *hook)
if (HOOK_INFOLIST(hook, args_description))
free (HOOK_INFOLIST(hook, args_description));
break;
case HOOK_TYPE_HDATA:
if (HOOK_HDATA(hook, hdata_name))
free (HOOK_HDATA(hook, hdata_name));
if (HOOK_HDATA(hook, description))
free (HOOK_HDATA(hook, description));
break;
case HOOK_NUM_TYPES:
/*
* this constant is used to count types only,
@@ -2879,6 +2994,529 @@ unhook_all ()
}
}
/*
* hook_hdata_hook_cb: return hdata for hook (variables common to all hook
* types)
*/
struct t_hdata *
hook_hdata_hook_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook)
return hook_hdata_hook;
hdata = hdata_new (hdata_name, "prev_hook", "next_hook");
if (hdata)
{
hook_hdata_hook = hdata;
HDATA_VAR(struct t_hook, plugin, POINTER);
HDATA_VAR(struct t_hook, type, INTEGER);
HDATA_VAR(struct t_hook, deleted, INTEGER);
HDATA_VAR(struct t_hook, running, INTEGER);
HDATA_VAR(struct t_hook, priority, INTEGER);
HDATA_VAR(struct t_hook, callback_data, POINTER);
HDATA_VAR(struct t_hook, hook_data, POINTER);
HDATA_VAR(struct t_hook, prev_hook, POINTER);
HDATA_VAR(struct t_hook, next_hook, POINTER);
}
return hook_hdata_hook;
}
/*
* hook_hdata_hook_command_cb: return hdata for hook of type "command"
*/
struct t_hdata *
hook_hdata_hook_command_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_command)
return hook_hdata_hook_command;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_command = hdata;
HDATA_VAR(struct t_hook_command, callback, POINTER);
HDATA_VAR(struct t_hook_command, command, STRING);
HDATA_VAR(struct t_hook_command, description, STRING);
HDATA_VAR(struct t_hook_command, args, STRING);
HDATA_VAR(struct t_hook_command, args_description, STRING);
HDATA_VAR(struct t_hook_command, completion, STRING);
HDATA_VAR(struct t_hook_command, cplt_num_templates, INTEGER);
HDATA_VAR(struct t_hook_command, cplt_templates, POINTER);
HDATA_VAR(struct t_hook_command, cplt_templates_static, POINTER);
HDATA_VAR(struct t_hook_command, cplt_template_num_args, POINTER);
HDATA_VAR(struct t_hook_command, cplt_template_args, POINTER);
HDATA_VAR(struct t_hook_command, cplt_template_num_args_concat, INTEGER);
HDATA_VAR(struct t_hook_command, cplt_template_args_concat, POINTER);
hdata_new_list(hdata, "weechat_hooks_command", &weechat_hooks[HOOK_TYPE_COMMAND]);
hdata_new_list(hdata, "last_weechat_hook_command", &last_weechat_hook[HOOK_TYPE_COMMAND]);
}
return hook_hdata_hook_command;
}
/*
* hook_hdata_hook_command_run_cb: return hdata for hook of type "command_run"
*/
struct t_hdata *
hook_hdata_hook_command_run_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_command_run)
return hook_hdata_hook_command_run;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_command_run = hdata;
HDATA_VAR(struct t_hook_command_run, callback, POINTER);
HDATA_VAR(struct t_hook_command_run, command, STRING);
hdata_new_list(hdata, "weechat_hooks_command_run", &weechat_hooks[HOOK_TYPE_COMMAND_RUN]);
hdata_new_list(hdata, "last_weechat_hook_command_run", &last_weechat_hook[HOOK_TYPE_COMMAND_RUN]);
}
return hook_hdata_hook_command_run;
}
/*
* hook_hdata_hook_timer_cb: return hdata for hook of type "timer"
*/
struct t_hdata *
hook_hdata_hook_timer_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_timer)
return hook_hdata_hook_timer;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_timer = hdata;
HDATA_VAR(struct t_hook_timer, callback, POINTER);
HDATA_VAR(struct t_hook_timer, interval, LONG);
HDATA_VAR(struct t_hook_timer, align_second, INTEGER);
HDATA_VAR(struct t_hook_timer, remaining_calls, INTEGER);
HDATA_VAR(struct t_hook_timer, last_exec, OTHER);
HDATA_VAR(struct t_hook_timer, next_exec, OTHER);
hdata_new_list(hdata, "weechat_hooks_timer", &weechat_hooks[HOOK_TYPE_TIMER]);
hdata_new_list(hdata, "last_weechat_hook_timer", &last_weechat_hook[HOOK_TYPE_TIMER]);
}
return hook_hdata_hook_timer;
}
/*
* hook_hdata_hook_fd_cb: return hdata for hook of type "fd"
*/
struct t_hdata *
hook_hdata_hook_fd_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_fd)
return hook_hdata_hook_fd;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_fd = hdata;
HDATA_VAR(struct t_hook_fd, callback, POINTER);
HDATA_VAR(struct t_hook_fd, fd, INTEGER);
HDATA_VAR(struct t_hook_fd, flags, INTEGER);
hdata_new_list(hdata, "weechat_hooks_fd", &weechat_hooks[HOOK_TYPE_FD]);
hdata_new_list(hdata, "last_weechat_hook_fd", &last_weechat_hook[HOOK_TYPE_FD]);
}
return hook_hdata_hook_fd;
}
/*
* hook_hdata_hook_process_cb: return hdata for hook of type "process"
*/
struct t_hdata *
hook_hdata_hook_process_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_process)
return hook_hdata_hook_process;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_process = hdata;
HDATA_VAR(struct t_hook_process, callback, POINTER);
HDATA_VAR(struct t_hook_process, command, STRING);
HDATA_VAR(struct t_hook_process, timeout, LONG);
HDATA_VAR(struct t_hook_process, child_read, POINTER);
HDATA_VAR(struct t_hook_process, child_write, POINTER);
HDATA_VAR(struct t_hook_process, child_pid, OTHER);
HDATA_VAR(struct t_hook_process, hook_fd, POINTER);
HDATA_VAR(struct t_hook_process, hook_timer, POINTER);
HDATA_VAR(struct t_hook_process, buffer, POINTER);
HDATA_VAR(struct t_hook_process, buffer_size, POINTER);
hdata_new_list(hdata, "weechat_hooks_process", &weechat_hooks[HOOK_TYPE_PROCESS]);
hdata_new_list(hdata, "last_weechat_hook_process", &last_weechat_hook[HOOK_TYPE_PROCESS]);
}
return hook_hdata_hook_process;
}
/*
* hook_hdata_hook_connect_cb: return hdata for hook of type "connect"
*/
struct t_hdata *
hook_hdata_hook_connect_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_connect)
return hook_hdata_hook_connect;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_connect = hdata;
HDATA_VAR(struct t_hook_connect, callback, POINTER);
HDATA_VAR(struct t_hook_connect, proxy, STRING);
HDATA_VAR(struct t_hook_connect, address, STRING);
HDATA_VAR(struct t_hook_connect, port, INTEGER);
HDATA_VAR(struct t_hook_connect, sock, INTEGER);
HDATA_VAR(struct t_hook_connect, ipv6, INTEGER);
#ifdef HAVE_GNUTLS
HDATA_VAR(struct t_hook_connect, gnutls_sess, POINTER);
HDATA_VAR(struct t_hook_connect, gnutls_cb, POINTER);
HDATA_VAR(struct t_hook_connect, gnutls_dhkey_size, INTEGER);
HDATA_VAR(struct t_hook_connect, gnutls_priorities, STRING);
#endif
HDATA_VAR(struct t_hook_connect, local_hostname, STRING);
HDATA_VAR(struct t_hook_connect, child_read, INTEGER);
HDATA_VAR(struct t_hook_connect, child_write, INTEGER);
HDATA_VAR(struct t_hook_connect, child_pid, OTHER);
HDATA_VAR(struct t_hook_connect, hook_fd, POINTER);
HDATA_VAR(struct t_hook_connect, handshake_hook_fd, POINTER);
HDATA_VAR(struct t_hook_connect, handshake_hook_timer, POINTER);
HDATA_VAR(struct t_hook_connect, handshake_fd_flags, INTEGER);
HDATA_VAR(struct t_hook_connect, handshake_ip_address, STRING);
hdata_new_list(hdata, "weechat_hooks_connect", &weechat_hooks[HOOK_TYPE_CONNECT]);
hdata_new_list(hdata, "last_weechat_hook_connect", &last_weechat_hook[HOOK_TYPE_CONNECT]);
}
return hook_hdata_hook_connect;
}
/*
* hook_hdata_hook_print_cb: return hdata for hook of type "print"
*/
struct t_hdata *
hook_hdata_hook_print_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_print)
return hook_hdata_hook_print;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_print = hdata;
HDATA_VAR(struct t_hook_print, callback, POINTER);
HDATA_VAR(struct t_hook_print, buffer, POINTER);
HDATA_VAR(struct t_hook_print, tags_count, INTEGER);
HDATA_VAR(struct t_hook_print, tags_array, POINTER);
HDATA_VAR(struct t_hook_print, message, STRING);
HDATA_VAR(struct t_hook_print, strip_colors, INTEGER);
hdata_new_list(hdata, "weechat_hooks_print", &weechat_hooks[HOOK_TYPE_PRINT]);
hdata_new_list(hdata, "last_weechat_hook_print", &last_weechat_hook[HOOK_TYPE_PRINT]);
}
return hook_hdata_hook_print;
}
/*
* hook_hdata_hook_signal_cb: return hdata for hook of type "signal"
*/
struct t_hdata *
hook_hdata_hook_signal_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_signal)
return hook_hdata_hook_signal;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_signal = hdata;
HDATA_VAR(struct t_hook_signal, callback, POINTER);
HDATA_VAR(struct t_hook_signal, signal, STRING);
hdata_new_list(hdata, "weechat_hooks_signal", &weechat_hooks[HOOK_TYPE_SIGNAL]);
hdata_new_list(hdata, "last_weechat_hook_signal", &last_weechat_hook[HOOK_TYPE_SIGNAL]);
}
return hook_hdata_hook_signal;
}
/*
* hook_hdata_hook_hsignal_cb: return hdata for hook of type "hsignal"
*/
struct t_hdata *
hook_hdata_hook_hsignal_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_hsignal)
return hook_hdata_hook_hsignal;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_hsignal = hdata;
HDATA_VAR(struct t_hook_hsignal, callback, POINTER);
HDATA_VAR(struct t_hook_hsignal, signal, STRING);
hdata_new_list(hdata, "weechat_hooks_hsignal", &weechat_hooks[HOOK_TYPE_HSIGNAL]);
hdata_new_list(hdata, "last_weechat_hook_hsignal", &last_weechat_hook[HOOK_TYPE_HSIGNAL]);
}
return hook_hdata_hook_hsignal;
}
/*
* hook_hdata_hook_config_cb: return hdata for hook of type "config"
*/
struct t_hdata *
hook_hdata_hook_config_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_config)
return hook_hdata_hook_config;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_config = hdata;
HDATA_VAR(struct t_hook_config, callback, POINTER);
HDATA_VAR(struct t_hook_config, option, STRING);
hdata_new_list(hdata, "weechat_hooks_config", &weechat_hooks[HOOK_TYPE_CONFIG]);
hdata_new_list(hdata, "last_weechat_hook_config", &last_weechat_hook[HOOK_TYPE_CONFIG]);
}
return hook_hdata_hook_config;
}
/*
* hook_hdata_hook_completion_cb: return hdata for hook of type "completion"
*/
struct t_hdata *
hook_hdata_hook_completion_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_completion)
return hook_hdata_hook_completion;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_completion = hdata;
HDATA_VAR(struct t_hook_completion, callback, POINTER);
HDATA_VAR(struct t_hook_completion, completion_item, STRING);
HDATA_VAR(struct t_hook_completion, description, STRING);
hdata_new_list(hdata, "weechat_hooks_completion", &weechat_hooks[HOOK_TYPE_COMPLETION]);
hdata_new_list(hdata, "last_weechat_hook_completion", &last_weechat_hook[HOOK_TYPE_COMPLETION]);
}
return hook_hdata_hook_completion;
}
/*
* hook_hdata_hook_modifier_cb: return hdata for hook of type "modifier"
*/
struct t_hdata *
hook_hdata_hook_modifier_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_modifier)
return hook_hdata_hook_modifier;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_modifier = hdata;
HDATA_VAR(struct t_hook_modifier, callback, POINTER);
HDATA_VAR(struct t_hook_modifier, modifier, STRING);
hdata_new_list(hdata, "weechat_hooks_modifier", &weechat_hooks[HOOK_TYPE_MODIFIER]);
hdata_new_list(hdata, "last_weechat_hook_modifier", &last_weechat_hook[HOOK_TYPE_MODIFIER]);
}
return hook_hdata_hook_modifier;
}
/*
* hook_hdata_hook_info_cb: return hdata for hook of type "info"
*/
struct t_hdata *
hook_hdata_hook_info_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_info)
return hook_hdata_hook_info;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_info = hdata;
HDATA_VAR(struct t_hook_info, callback, POINTER);
HDATA_VAR(struct t_hook_info, info_name, STRING);
HDATA_VAR(struct t_hook_info, description, STRING);
HDATA_VAR(struct t_hook_info, args_description, STRING);
hdata_new_list(hdata, "weechat_hooks_info", &weechat_hooks[HOOK_TYPE_INFO]);
hdata_new_list(hdata, "last_weechat_hook_info", &last_weechat_hook[HOOK_TYPE_INFO]);
}
return hook_hdata_hook_info;
}
/*
* hook_hdata_hook_info_hashtable_cb: return hdata for hook of type
* "info_hashtable"
*/
struct t_hdata *
hook_hdata_hook_info_hashtable_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_info_hashtable)
return hook_hdata_hook_info_hashtable;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_info_hashtable = hdata;
HDATA_VAR(struct t_hook_info_hashtable, callback, POINTER);
HDATA_VAR(struct t_hook_info_hashtable, info_name, STRING);
HDATA_VAR(struct t_hook_info_hashtable, description, STRING);
HDATA_VAR(struct t_hook_info_hashtable, args_description, STRING);
HDATA_VAR(struct t_hook_info_hashtable, output_description, STRING);
hdata_new_list(hdata, "weechat_hooks_info_hashtable", &weechat_hooks[HOOK_TYPE_INFO_HASHTABLE]);
hdata_new_list(hdata, "last_weechat_hook_info_hashtable", &last_weechat_hook[HOOK_TYPE_INFO_HASHTABLE]);
}
return hook_hdata_hook_info_hashtable;
}
/*
* hook_hdata_hook_infolist_cb: return hdata for hook of type "infolist"
*/
struct t_hdata *
hook_hdata_hook_infolist_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_infolist)
return hook_hdata_hook_infolist;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_infolist = hdata;
HDATA_VAR(struct t_hook_infolist, callback, POINTER);
HDATA_VAR(struct t_hook_infolist, infolist_name, STRING);
HDATA_VAR(struct t_hook_infolist, description, STRING);
HDATA_VAR(struct t_hook_infolist, pointer_description, STRING);
HDATA_VAR(struct t_hook_infolist, args_description, STRING);
hdata_new_list(hdata, "weechat_hooks_infolist", &weechat_hooks[HOOK_TYPE_INFOLIST]);
hdata_new_list(hdata, "last_weechat_hook_infolist", &last_weechat_hook[HOOK_TYPE_INFOLIST]);
}
return hook_hdata_hook_infolist;
}
/*
* hook_hdata_hook_hdata_cb: return hdata for hook of type "hdata"
*/
struct t_hdata *
hook_hdata_hook_hdata_cb (void *data, const char *hdata_name)
{
struct t_hdata *hdata;
/* make C compiler happy */
(void) data;
if (hook_hdata_hook_hdata)
return hook_hdata_hook_hdata;
hdata = hdata_new (hdata_name, NULL, NULL);
if (hdata)
{
hook_hdata_hook_hdata = hdata;
HDATA_VAR(struct t_hook_hdata, callback, POINTER);
HDATA_VAR(struct t_hook_hdata, hdata_name, STRING);
HDATA_VAR(struct t_hook_hdata, description, STRING);
hdata_new_list(hdata, "weechat_hooks_hdata", &weechat_hooks[HOOK_TYPE_HDATA]);
hdata_new_list(hdata, "last_weechat_hook_hdata", &last_weechat_hook[HOOK_TYPE_HDATA]);
}
return hook_hdata_hook_hdata;
}
/*
* hook_add_to_infolist_type: add hooks of a type in an infolist
* return 1 if ok, 0 if error
@@ -3231,6 +3869,22 @@ hook_add_to_infolist_type (struct t_infolist *infolist, int type,
return 0;
}
break;
case HOOK_TYPE_HDATA:
if (!ptr_hook->deleted)
{
if (!infolist_new_var_pointer (ptr_item, "callback", HOOK_HDATA(ptr_hook, callback)))
return 0;
if (!infolist_new_var_string (ptr_item, "hdata_name", HOOK_HDATA(ptr_hook, hdata_name)))
return 0;
if (!infolist_new_var_string (ptr_item, "description", HOOK_HDATA(ptr_hook, description)))
return 0;
if (!infolist_new_var_string (ptr_item, "description_nls",
(HOOK_HDATA(ptr_hook, description)
&& HOOK_HDATA(ptr_hook, description)[0]) ?
_(HOOK_HDATA(ptr_hook, description)) : ""))
return 0;
}
break;
case HOOK_NUM_TYPES:
/*
* this constant is used to count types only,
@@ -3520,6 +4174,15 @@ hook_print_log ()
log_printf (" args_description. . . : '%s'", HOOK_INFOLIST(ptr_hook, args_description));
}
break;
case HOOK_TYPE_HDATA:
if (!ptr_hook->deleted)
{
log_printf (" hdata data:");
log_printf (" callback. . . . . . . : 0x%lx", HOOK_HDATA(ptr_hook, callback));
log_printf (" hdata_name. . . . . . : '%s'", HOOK_HDATA(ptr_hook, hdata_name));
log_printf (" description . . . . . : '%s'", HOOK_HDATA(ptr_hook, description));
}
break;
case HOOK_NUM_TYPES:
/*
* this constant is used to count types only,
+55
View File
@@ -50,6 +50,7 @@ enum t_hook_type
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 */
HOOK_TYPE_HDATA, /* get hdata pointer */
/* number of hook types */
HOOK_NUM_TYPES,
};
@@ -89,6 +90,7 @@ enum t_hook_type
#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)
#define HOOK_HDATA(hook, var) (((struct t_hook_hdata *)hook->hook_data)->var)
struct t_hook
{
@@ -358,6 +360,18 @@ struct t_hook_infolist
char *args_description; /* description of arguments */
};
/* hook hdata */
typedef struct t_hdata *(t_hook_callback_hdata)(void *data,
const char *hdata_name);
struct t_hook_hdata
{
t_hook_callback_hdata *callback; /* hdata callback */
char *hdata_name; /* hdata name */
char *description; /* description */
};
/* hook variables */
extern struct t_hook *weechat_hooks[];
@@ -498,9 +512,50 @@ extern struct t_infolist *hook_infolist_get (struct t_weechat_plugin *plugin,
const char *infolist_name,
void *pointer,
const char *arguments);
extern struct t_hook *hook_hdata (struct t_weechat_plugin *plugin,
const char *hdata_name,
const char *description,
t_hook_callback_hdata *callback,
void *callback_data);
extern struct t_hdata *hook_hdata_get (struct t_weechat_plugin *plugin,
const char *hdata_name);
extern void unhook (struct t_hook *hook);
extern void unhook_all_plugin (struct t_weechat_plugin *plugin);
extern void unhook_all ();
extern struct t_hdata *hook_hdata_hook_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_command_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_command_run_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_timer_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_fd_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_process_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_connect_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_print_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_signal_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_hsignal_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_config_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_completion_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_modifier_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_info_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_info_hashtable_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_infolist_cb (void *data,
const char *hdata_name);
extern struct t_hdata *hook_hdata_hook_hdata_cb (void *data,
const char *hdata_name);
extern int hook_add_to_infolist (struct t_infolist *infolist,
const char *arguments);
extern void hook_print_log ();