struct t_hook * hook_line (struct t_weechat_plugin *plugin, const char *buffer_type, const char *buffer_name, const char *tags, t_hook_callback_line *callback, const void *callback_pointer, void *callback_data) { struct t_hook *new_hook; struct t_hook_line *new_hook_line; if (!callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_line = malloc (sizeof (*new_hook_line)); if (!new_hook_line) { free (new_hook); return NULL; } hook_init_data (new_hook, plugin, HOOK_TYPE_LINE, HOOK_PRIORITY_DEFAULT, callback_pointer, callback_data); new_hook->hook_data = new_hook_line; new_hook_line->callback = callback; if (!buffer_type || !buffer_type[0]) new_hook_line->buffer_type = GUI_BUFFER_TYPE_FORMATTED; else if (strcmp (buffer_type, "*") == 0) new_hook_line->buffer_type = -1; else new_hook_line->buffer_type = gui_buffer_search_type (buffer_type); new_hook_line->buffers = string_split ( (buffer_name && buffer_name[0]) ? buffer_name : "*", ",", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &new_hook_line->num_buffers); new_hook_line->tags_array = string_split_tags (tags, &new_hook_line->tags_count); hook_add_to_list (new_hook); return new_hook; }
struct t_hook * hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name, const char *description, const char *pointer_description, const char *args_description, t_hook_callback_infolist *callback, const void *callback_pointer, void *callback_data) { struct t_hook *new_hook; struct t_hook_infolist *new_hook_infolist; int priority; const char *ptr_infolist_name; if (!infolist_name || !infolist_name[0] || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_infolist = malloc (sizeof (*new_hook_infolist)); if (!new_hook_infolist) { free (new_hook); return NULL; } hook_get_priority_and_name (infolist_name, &priority, &ptr_infolist_name); hook_init_data (new_hook, plugin, HOOK_TYPE_INFOLIST, priority, callback_pointer, callback_data); new_hook->hook_data = new_hook_infolist; new_hook_infolist->callback = callback; new_hook_infolist->infolist_name = strdup ((ptr_infolist_name) ? ptr_infolist_name : infolist_name); new_hook_infolist->description = strdup ((description) ? description : ""); new_hook_infolist->pointer_description = strdup ((pointer_description) ? pointer_description : ""); new_hook_infolist->args_description = strdup ((args_description) ? args_description : ""); hook_add_to_list (new_hook); return new_hook; }
struct t_hook * hook_command_run (struct t_weechat_plugin *plugin, const char *command, t_hook_callback_command_run *callback, const void *callback_pointer, void *callback_data) { struct t_hook *new_hook; struct t_hook_command_run *new_hook_command_run; int priority; const char *ptr_command; if (!callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_command_run = malloc (sizeof (*new_hook_command_run)); if (!new_hook_command_run) { free (new_hook); return NULL; } hook_get_priority_and_name (command, &priority, &ptr_command); hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND_RUN, priority, callback_pointer, callback_data); new_hook->hook_data = new_hook_command_run; new_hook_command_run->callback = callback; new_hook_command_run->command = strdup ((ptr_command) ? ptr_command : ((command) ? command : "")); hook_add_to_list (new_hook); return new_hook; }
struct t_hook * hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second, int max_calls, t_hook_callback_timer *callback, const void *callback_pointer, void *callback_data) { struct t_hook *new_hook; struct t_hook_timer *new_hook_timer; if ((interval <= 0) || !callback) return NULL; new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; new_hook_timer = malloc (sizeof (*new_hook_timer)); if (!new_hook_timer) { free (new_hook); return NULL; } hook_init_data (new_hook, plugin, HOOK_TYPE_TIMER, HOOK_PRIORITY_DEFAULT, callback_pointer, callback_data); new_hook->hook_data = new_hook_timer; new_hook_timer->callback = callback; new_hook_timer->interval = interval; new_hook_timer->align_second = align_second; new_hook_timer->remaining_calls = max_calls; hook_timer_init (new_hook); hook_add_to_list (new_hook); return new_hook; }