diff options
Diffstat (limited to 'src')
53 files changed, 2314 insertions, 916 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 8041fc0bd..cbd763792 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -497,14 +497,17 @@ command_buffer (void *data, struct t_gui_buffer *buffer, ptr_buffer = ptr_buffer->next_buffer) { gui_chat_printf (NULL, - " %s[%s%d%s]%s (%s) %s", + " %s[%s%d%s]%s (%s) %s%s%s (notify: %d)", GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT), ptr_buffer->number, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT), plugin_get_name (ptr_buffer->plugin), - ptr_buffer->name); + GUI_COLOR(GUI_COLOR_CHAT_BUFFER), + ptr_buffer->name, + GUI_COLOR(GUI_COLOR_CHAT), + ptr_buffer->notify); } return WEECHAT_RC_OK; @@ -708,8 +711,7 @@ command_buffer (void *data, struct t_gui_buffer *buffer, ptr_buffer = gui_buffer_search_by_partial_name (NULL, argv_eol[1]); if (ptr_buffer) { - gui_window_switch_to_buffer (gui_current_window, - ptr_buffer); + gui_window_switch_to_buffer (gui_current_window, ptr_buffer, 1); } } diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index d78b344d3..5aa48ae9f 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -177,7 +177,12 @@ config_file_new_section (struct t_config_file *config_file, const char *name, struct t_config_section *section, const char *option_name, const char *value), - void *callback_create_option_data) + void *callback_create_option_data, + int (*callback_delete_option)(void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option), + void *callback_delete_option_data) { struct t_config_section *new_section; @@ -201,6 +206,8 @@ config_file_new_section (struct t_config_file *config_file, const char *name, new_section->callback_write_default_data = callback_write_default_data; new_section->callback_create_option = callback_create_option; new_section->callback_create_option_data = callback_create_option_data; + new_section->callback_delete_option = callback_delete_option; + new_section->callback_delete_option_data = callback_delete_option_data; new_section->options = NULL; new_section->last_option = NULL; @@ -458,12 +465,20 @@ config_file_new_option (struct t_config_file *config_file, number = strtol (default_value, &error, 10); if (!error || error[0]) number = 0; + if (number < min) + number = min; + else if (number > max) + number = max; new_option->default_value = malloc (sizeof (int)); *((int *)new_option->default_value) = number; error = NULL; number = strtol (value, &error, 10); if (!error || error[0]) number = 0; + if (number < min) + number = min; + else if (number > max) + number = max; new_option->value = malloc (sizeof (int)); *((int *)new_option->value) = number; } @@ -1166,9 +1181,20 @@ config_file_option_unset (struct t_config_option *option) } option_full_name = config_file_option_full_name (option); - - config_file_option_free (option); - rc = WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; + + if (option->section->callback_delete_option) + { + rc = (int)(option->section->callback_delete_option) + (option->section->callback_delete_option_data, + option->config_file, + option->section, + option); + } + else + { + config_file_option_free (option); + rc = WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; + } if (option_full_name) { @@ -2224,7 +2250,7 @@ config_file_add_to_infolist (struct t_infolist *infolist, free (option_full_name); return 0; } - string_values = string_build_with_exploded (ptr_option->string_values, + string_values = string_build_with_exploded ((const char **)ptr_option->string_values, "|"); if (!infolist_new_var_string (ptr_item, "string_values", @@ -2528,6 +2554,8 @@ config_file_print_log () log_printf (" callback_write_default_data: 0x%x", ptr_section->callback_write_default_data); log_printf (" callback_create_option. . .: 0x%x", ptr_section->callback_create_option); log_printf (" callback_create_option_data: 0x%x", ptr_section->callback_create_option_data); + log_printf (" callback_delete_option. . .: 0x%x", ptr_section->callback_delete_option); + log_printf (" callback_delete_option_data: 0x%x", ptr_section->callback_delete_option_data); log_printf (" options. . . . . . . . . . : 0x%x", ptr_section->options); log_printf (" last_option. . . . . . . . : 0x%x", ptr_section->last_option); log_printf (" prev_section . . . . . . . : 0x%x", ptr_section->prev_section); diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index e3be39cc7..ba1c647e5 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -38,6 +38,8 @@ struct t_weelist; struct t_infolist; +struct t_config_option; + struct t_config_file { struct t_weechat_plugin *plugin; /* plugin which created this cfg */ @@ -84,6 +86,12 @@ struct t_config_section const char *option_name, const char *value); void *callback_create_option_data; /* data sent to create callback */ + int (*callback_delete_option) /* called to delete option in */ + (void *data, /* section */ + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option); + void *callback_delete_option_data; /* data sent to delete callback */ struct t_config_option *options; /* options in section */ struct t_config_option *last_option; /* last option in section */ struct t_config_section *prev_section; /* link to previous section */ @@ -163,7 +171,12 @@ extern struct t_config_section *config_file_new_section (struct t_config_file *c struct t_config_section *section, const char *option_name, const char *value), - void *callback_create_option_data); + void *callback_create_option_data, + int (*callback_delete_option)(void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option), + void *callback_delete_option_data); extern struct t_config_section *config_file_search_section (struct t_config_file *config_file, const char *section_name); extern int config_file_section_valid_for_plugin (struct t_weechat_plugin *plugin, diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 427934900..e8adb7152 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -825,7 +825,7 @@ config_weechat_init () ptr_section = config_file_new_section (weechat_config_file, "startup", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -862,7 +862,7 @@ config_weechat_init () ptr_section = config_file_new_section (weechat_config_file, "look", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1074,7 +1074,7 @@ config_weechat_init () ptr_section = config_file_new_section (weechat_config_file, "color", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1502,7 +1502,7 @@ config_weechat_init () ptr_section = config_file_new_section (weechat_config_file, "completion", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1557,7 +1557,7 @@ config_weechat_init () ptr_section = config_file_new_section (weechat_config_file, "history", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1587,7 +1587,7 @@ config_weechat_init () ptr_section = config_file_new_section (weechat_config_file, "proxy", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1634,7 +1634,7 @@ config_weechat_init () ptr_section = config_file_new_section (weechat_config_file, "plugin", 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1683,8 +1683,7 @@ config_weechat_init () ptr_section = config_file_new_section (weechat_config_file, "bar", 0, 0, &config_weechat_bar_read, NULL, - NULL, NULL, - NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { @@ -1699,8 +1698,7 @@ config_weechat_init () 0, 0, &config_weechat_layout_read, NULL, &config_weechat_layout_write, NULL, - NULL, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1713,7 +1711,7 @@ config_weechat_init () &config_weechat_filter_read, NULL, &config_weechat_filter_write, NULL, &config_weechat_filter_write, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); @@ -1726,7 +1724,7 @@ config_weechat_init () &config_weechat_key_read, NULL, &config_weechat_key_write, NULL, &config_weechat_key_write, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { config_file_free (weechat_config_file); diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index d1fdbab7a..b1706de54 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -921,7 +921,8 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, void hook_print_exec (struct t_gui_buffer *buffer, time_t date, int tags_count, - char **tags_array, const char *prefix, const char *message) + const char **tags_array, const char *prefix, + const char *message) { struct t_hook *ptr_hook, *next_hook; char *prefix_no_color, *message_no_color; diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index 295eb4367..6d17efe01 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -142,7 +142,7 @@ struct t_hook_connect typedef int (t_hook_callback_print)(void *data, struct t_gui_buffer *buffer, time_t date, int tags_count, - char **tags, const char *prefix, + const char **tags, const char *prefix, const char *message); struct t_hook_print @@ -267,7 +267,7 @@ extern struct t_hook *hook_print (struct t_weechat_plugin *plugin, void *callback_data); extern void hook_print_exec (struct t_gui_buffer *buffer, time_t date, int tags_count, - char **tags_array, const char *prefix, + const char **tags_array, const char *prefix, const char *message); extern struct t_hook *hook_signal (struct t_weechat_plugin *plugin, const char *signal, diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 41d10232d..232b48df4 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -854,7 +854,7 @@ string_free_exploded (char **exploded_string) */ char * -string_build_with_exploded (char **exploded_string, const char *separator) +string_build_with_exploded (const char **exploded_string, const char *separator) { int i, length, length_separator; char *result; diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 62df98f7f..3dc5c5d56 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -44,7 +44,7 @@ extern int string_has_highlight (const char *string, extern char **string_explode (const char *string, const char *separators, int keep_eol, int num_items_max, int *num_items); extern void string_free_exploded (char **exploded_string); -extern char *string_build_with_exploded (char **exploded_string, +extern char *string_build_with_exploded (const char **exploded_string, const char *separator); extern char **string_split_command (const char *command, char separator); extern void string_free_splitted_command (char **splitted_command); diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 51ff45ee0..a2fc242f5 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -491,8 +491,10 @@ upgrade_weechat_load () gui_hotlist_clear (); if (upgrade_set_current_buffer) + { gui_window_switch_to_buffer (gui_current_window, - upgrade_set_current_buffer); + upgrade_set_current_buffer, 0); + } return rc; } diff --git a/src/core/wee-util.c b/src/core/wee-util.c index 9491efbe7..107094851 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -28,6 +28,7 @@ #include <string.h> #include <sys/types.h> #include <sys/stat.h> +#include <unistd.h> #include <dirent.h> #include <signal.h> #include <ctype.h> @@ -138,28 +139,113 @@ util_catch_signal (int signum, void (*handler)(int)) } /* - * util_create_dir: create a directory - * return: 1 if ok (or directory already exists) - * 0 if error + * util_mkdir_home: create a directory in WeeChat home + * return 1 if ok, 0 if error */ int -util_create_dir (const char *directory, int permissions) +util_mkdir_home (const char *directory, int mode) { - if (mkdir (directory, 0755) < 0) + char *dir_name; + int dir_length; + + if (!directory) + return 0; + + /* build directory, adding WeeChat home */ + dir_length = strlen (weechat_home) + strlen (directory) + 2; + dir_name = malloc (dir_length); + if (!dir_name) + return 0; + + snprintf (dir_name, dir_length, "%s/%s", weechat_home, directory); + + if (mkdir (dir_name, mode) < 0) { - /* exit if error (except if directory already exists) */ if (errno != EEXIST) { - string_iconv_fprintf (stderr, - _("Error: cannot create directory \"%s\"\n"), - directory); + free (dir_name); return 0; } - return 1; } - if ((permissions != 0) && (strcmp (directory, getenv ("HOME")) != 0)) - chmod (directory, permissions); + + free (dir_name); + return 1; +} + +/* + * util_mkdir: create a directory + * return 1 if ok, 0 if error + */ + +int +util_mkdir (const char *directory, int mode) +{ + if (!directory) + return 0; + + if (mkdir (directory, mode) < 0) + { + if (errno != EEXIST) + return 0; + } + + return 1; +} + +/* + * util_mkdir_parents: create a directory and make parent directories as needed + * return 1 if ok, 0 if error + */ + +int +util_mkdir_parents (const char *directory, int mode) +{ + char *string, *ptr_string, *pos_sep; + struct stat buf; + int rc; + + if (!directory) + return 0; + + string = strdup (directory); + if (!string) + return 0; + + ptr_string = string; + while (ptr_string[0] == DIR_SEPARATOR_CHAR) + { + ptr_string++; + } + + while (ptr_string && ptr_string[0]) + { + pos_sep = strchr (ptr_string, DIR_SEPARATOR_CHAR); + if (pos_sep) + pos_sep[0] = '\0'; + + rc = stat (string, &buf); + if ((rc < 0) || !S_ISDIR(buf.st_mode)) + { + /* try to create directory */ + if (!util_mkdir (string, mode)) + { + free (string); + return 0; + } + } + + if (pos_sep) + { + pos_sep[0] = DIR_SEPARATOR_CHAR; + ptr_string = pos_sep + 1; + } + else + ptr_string = NULL; + } + + free (string); + return 1; } diff --git a/src/core/wee-util.h b/src/core/wee-util.h index bc84180d5..d94561a76 100644 --- a/src/core/wee-util.h +++ b/src/core/wee-util.h @@ -25,7 +25,9 @@ extern long util_timeval_diff (struct timeval *tv1, struct timeval *tv2); extern void util_timeval_add (struct timeval *tv, long interval); extern int util_get_time_length (const char *time_format); extern void util_catch_signal (int signum, void (*handler)(int)); -extern int util_create_dir (const char *directory, int permissions); +extern int util_mkdir_home (const char *directory, int mode); +extern int util_mkdir (const char *directory, int mode); +extern int util_mkdir_parents (const char *directory, int mode); extern void util_exec_on_files (const char *directory, void *data, void (*callback)(void *data, const char *filename)); diff --git a/src/core/weechat.c b/src/core/weechat.c index 31181a0b4..51c89997f 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -256,10 +256,10 @@ weechat_create_home_dirs () } /* create home directory; error is fatal */ - if (!util_create_dir (weechat_home, 0)) + if (!util_mkdir (weechat_home, 0755)) { string_iconv_fprintf (stderr, - _("Error: unable to create \"%s\" directory\n"), + _("Error: cannot create directory \"%s\"\n"), weechat_home); weechat_shutdown (EXIT_FAILURE, 0); } diff --git a/src/gui/curses/gui-curses-main.c b/src/gui/curses/gui-curses-main.c index 3b199d315..251ebfe7f 100644 --- a/src/gui/curses/gui-curses-main.c +++ b/src/gui/curses/gui-curses-main.c @@ -264,7 +264,7 @@ gui_main_loop () { if (ptr_win->refresh_needed) { - gui_window_switch_to_buffer (ptr_win, ptr_win->buffer); + gui_window_switch_to_buffer (ptr_win, ptr_win->buffer, 0); gui_window_redraw_buffer (ptr_win->buffer); ptr_win->refresh_needed = 0; } diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index c5942e8d5..af2f96c67 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -450,7 +450,8 @@ gui_window_redraw_all_buffers () void gui_window_switch_to_buffer (struct t_gui_window *window, - struct t_gui_buffer *buffer) + struct t_gui_buffer *buffer, + int set_last_read) { struct t_gui_bar_window *ptr_bar_win; struct t_gui_buffer *old_buffer; @@ -467,11 +468,14 @@ gui_window_switch_to_buffer (struct t_gui_window *window, { window->start_line = NULL; window->start_line_pos = 0; - if (window->buffer->num_displayed == 0) - window->buffer->last_read_line = window->buffer->last_line; - if (buffer->last_read_line == buffer->last_line) - buffer->last_read_line = NULL; gui_previous_buffer = window->buffer; + if (set_last_read) + { + if (window->buffer->num_displayed == 0) + window->buffer->last_read_line = window->buffer->last_line; + if (buffer->last_read_line == buffer->last_line) + buffer->last_read_line = NULL; + } } window->buffer = buffer; @@ -547,12 +551,12 @@ gui_window_switch (struct t_gui_window *window) { gui_current_window = old_window; gui_window_switch_to_buffer (gui_current_window, - gui_current_window->buffer); + gui_current_window->buffer, 1); gui_current_window = window; } gui_window_switch_to_buffer (gui_current_window, - gui_current_window->buffer); + gui_current_window->buffer, 1); gui_current_window->refresh_needed = 1; } @@ -936,7 +940,7 @@ gui_window_refresh_windows () for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { - gui_window_switch_to_buffer (ptr_win, ptr_win->buffer); + gui_window_switch_to_buffer (ptr_win, ptr_win->buffer, 0); gui_window_draw_separator (ptr_win); ptr_win->refresh_needed = 0; } @@ -986,7 +990,7 @@ gui_window_split_horiz (struct t_gui_window *window, int percentage) new_window->buffer = window->buffer; new_window->buffer->num_displayed++; - gui_window_switch_to_buffer (window, window->buffer); + gui_window_switch_to_buffer (window, window->buffer, 1); gui_window_switch (new_window); } @@ -1030,7 +1034,7 @@ gui_window_split_vertic (struct t_gui_window *window, int percentage) new_window->buffer = window->buffer; new_window->buffer->num_displayed++; - gui_window_switch_to_buffer (window, window->buffer); + gui_window_switch_to_buffer (window, window->buffer, 1); gui_window_switch (new_window); @@ -1121,7 +1125,7 @@ gui_window_merge (struct t_gui_window *window) gui_window_free (sister->window); gui_window_tree_node_to_leaf (parent, window); - gui_window_switch_to_buffer (window, window->buffer); + gui_window_switch_to_buffer (window, window->buffer, 1); window->refresh_needed = 1; return 1; } @@ -1166,7 +1170,7 @@ gui_window_merge_all (struct t_gui_window *window) window->win_height_pct = 100; gui_current_window = window; - gui_window_switch_to_buffer (window, window->buffer); + gui_window_switch_to_buffer (window, window->buffer, 1); window->refresh_needed = 1; } } diff --git a/src/gui/gtk/gui-gtk-window.c b/src/gui/gtk/gui-gtk-window.c index b7a683ea6..2872c54d0 100644 --- a/src/gui/gtk/gui-gtk-window.c +++ b/src/gui/gtk/gui-gtk-window.c @@ -183,7 +183,7 @@ gui_window_switch (struct t_gui_window *window) gui_current_window = window; - gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer, 1); gui_window_redraw_buffer (gui_current_window->buffer); } @@ -193,7 +193,9 @@ gui_window_switch (struct t_gui_window *window) */ void -gui_window_switch_to_buffer (struct t_gui_window *window, struct t_gui_buffer *buffer) +gui_window_switch_to_buffer (struct t_gui_window *window, + struct t_gui_buffer *buffer, + int set_last_read) { GtkTextIter start, end; @@ -202,9 +204,16 @@ gui_window_switch_to_buffer (struct t_gui_window *window, struct t_gui_buffer *b if (window->buffer != buffer) { - window->buffer->last_read_line = window->buffer->last_line; - if (buffer->last_read_line == buffer->last_line) - buffer->last_read_line = NULL; + window->start_line = NULL; + window->start_line_pos = 0; + gui_previous_buffer = window->buffer; + if (set_last_read) + { + if (window->buffer->num_displayed == 0) + window->buffer->last_read_line = window->buffer->last_line; + if (buffer->last_read_line == buffer->last_line) + buffer->last_read_line = NULL; + } } window->buffer = buffer; @@ -490,10 +499,10 @@ gui_window_split_horiz (struct t_gui_window *window, int percentage) new_window->buffer = window->buffer; new_window->buffer->num_displayed++; - gui_window_switch_to_buffer (window, window->buffer); + gui_window_switch_to_buffer (window, window->buffer, 1); gui_current_window = new_window; - gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer, 1); gui_window_redraw_buffer (gui_current_window->buffer); } } @@ -535,10 +544,10 @@ gui_window_split_vertic (struct t_gui_window *window, int percentage) new_window->buffer = window->buffer; new_window->buffer->num_displayed++; - gui_window_switch_to_buffer (window, window->buffer); + gui_window_switch_to_buffer (window, window->buffer, 1); gui_current_window = new_window; - gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer, 1); gui_window_redraw_buffer (gui_current_window->buffer); /* create & draw separator */ @@ -599,7 +608,7 @@ gui_window_merge (struct t_gui_window *window) gui_window_free (sister->window); gui_window_tree_node_to_leaf (parent, window); - gui_window_switch_to_buffer (window, window->buffer); + gui_window_switch_to_buffer (window, window->buffer, 1); gui_window_redraw_buffer (window->buffer); return 1; } @@ -688,7 +697,7 @@ gui_window_switch_up (struct t_gui_window *window) (gui_window_side_by_side (window, ptr_win) == 1)) { gui_current_window = ptr_win; - gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer, 1); gui_window_redraw_buffer (gui_current_window->buffer); return; } @@ -711,7 +720,7 @@ gui_window_switch_down (struct t_gui_window *window) (gui_window_side_by_side (window, ptr_win) == 3)) { gui_current_window = ptr_win; - gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer, 1); gui_window_redraw_buffer (gui_current_window->buffer); return; } @@ -734,7 +743,7 @@ gui_window_switch_left (struct t_gui_window *window) (gui_window_side_by_side (window, ptr_win) == 4)) { gui_current_window = ptr_win; - gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer, 1); gui_window_redraw_buffer (gui_current_window->buffer); return; } @@ -757,7 +766,7 @@ gui_window_switch_right (struct t_gui_window *window) (gui_window_side_by_side (window, ptr_win) == 2)) { gui_current_window = ptr_win; - gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer); + gui_window_switch_to_buffer (gui_current_window, gui_current_window->buffer, 1); gui_window_redraw_buffer (gui_current_window->buffer); return; } diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 3102a5d42..59736806f 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -87,6 +87,119 @@ gui_buffer_find_pos (struct t_gui_buffer *buffer) } /* + * gui_buffer_local_var_search: search a local variable with name + */ + +struct t_gui_buffer_local_var * +gui_buffer_local_var_search (struct t_gui_buffer *buffer, const char *name) +{ + struct t_gui_buffer_local_var *ptr_local_var; + + if (!buffer || !name) + return NULL; + + for (ptr_local_var = buffer->local_variables; ptr_local_var; + ptr_local_var = ptr_local_var->next_var) + { + if (strcmp (ptr_local_var->name, name) == 0) + return ptr_local_var; + } + + /* local variable not found */ + return NULL; +} + +/* + * gui_buffer_local_var_add: add a new local variable to a buffer + */ + +struct t_gui_buffer_local_var * +gui_buffer_local_var_add (struct t_gui_buffer *buffer, const char *name, + const char *value) +{ + struct t_gui_buffer_local_var *new_local_var; + + if (!buffer || !name || !value) + return NULL; + + new_local_var = gui_buffer_local_var_search (buffer, name); + if (new_local_var) + { + if (new_local_var->name) + free (new_local_var->name); + if (new_local_var->value) + free (new_local_var->value); + new_local_var->name = strdup (name); + new_local_var->value = strdup (value); + } + else + { + new_local_var = malloc (sizeof (*new_local_var)); + if (new_local_var) + { + new_local_var->name = strdup (name); + new_local_var->value = strdup (value); + + new_local_var->prev_var = buffer->last_local_var; + new_local_var->next_var = NULL; + if (buffer->local_variables) + buffer->last_local_var->next_var = new_local_var; + else + buffer->local_variables = new_local_var; + buffer->last_local_var = new_local_var; + } + } + + return new_local_var; +} + +/* + * gui_buffer_local_var_remove: remove a local variable in a buffer + */ + +void +gui_buffer_local_var_remove (struct t_gui_buffer *buffer, + struct t_gui_buffer_local_var *local_var) +{ + if (!buffer || !local_var) + return; + + /* free data */ + if (local_var->name) + free (local_var->name); + if (local_var->value) + free (local_var->value); + + /* remove local variable from list */ + if (local_var->prev_var) + (local_var->prev_var)->next_var = local_var->next_var; + if (local_var->next_var) + (local_var->next_var)->prev_var = local_var->prev_var; + if (buffer->local_variables == local_var) + buffer->local_variables = local_var->next_var; + if (buffer->last_local_var == local_var) + buffer->last_local_var = local_var->prev_var; + + free (local_var); +} + +/* + * gui_buffer_local_var_remove_all: remove all local variables in a buffer + */ + +void +gui_buffer_local_var_remove_all (struct t_gui_buffer *buffer) +{ + if (buffer) + { + while (buffer->local_variables) + { + gui_buffer_local_var_remove (buffer, buffer->local_variables); + } + } +} + +/* * gui_buffer_insert: insert buffer in good position in list of buffers */ @@ -245,6 +358,8 @@ gui_buffer_new (struct t_weechat_plugin *plugin, /* local variables */ new_buffer->local_variables = NULL; new_buffer->last_local_var = NULL; + gui_buffer_local_var_add (new_buffer, "plugin", plugin_get_name (plugin)); + gui_buffer_local_var_add (new_buffer, "name", name); /* add buffer to buffers list */ gui_buffer_insert (new_buffer); @@ -257,7 +372,7 @@ gui_buffer_new (struct t_weechat_plugin *plugin, gui_current_window->start_line = NULL; gui_current_window->start_line_pos = 0; gui_window_calculate_pos_size (gui_current_window); - gui_window_switch_to_buffer (gui_current_window, new_buffer); + gui_window_switch_to_buffer (gui_current_window, new_buffer, 0); } /* check if this buffer should be assigned to a window, @@ -300,120 +415,6 @@ gui_buffer_valid (struct t_gui_buffer *buffer) } /* - * gui_buffer_local_var_search: search a local variable with name - */ - -struct t_gui_buffer_local_var * -gui_buffer_local_var_search (struct t_gui_buffer *buffer, const char *name) -{ - struct t_gui_buffer_local_var *ptr_local_var; - - if (!buffer || !name) - return NULL; - - for (ptr_local_var = buffer->local_variables; ptr_local_var; - ptr_local_var = ptr_local_var->next_var) - { - if (strcmp (ptr_local_var->name, name) == 0) - return ptr_local_var; - } - - /* local variable not found */ - return NULL; -} - - -/* - * gui_buffer_local_var_add: add a new local variable to a buffer - */ - -struct t_gui_buffer_local_var * -gui_buffer_local_var_add (struct t_gui_buffer *buffer, const char *name, - const char *value) -{ - struct t_gui_buffer_local_var *new_local_var; - - if (!buffer || !name || !value) - return NULL; - - new_local_var = gui_buffer_local_var_search (buffer, name); - if (new_local_var) - { - if (new_local_var->name) - free (new_local_var->name); - if (new_local_var->value) - free (new_local_var->value); - new_local_var->name = strdup (name); - new_local_var->value = strdup (value); - } - else - { - new_local_var = malloc (sizeof (*new_local_var)); - if (new_local_var) - { - new_local_var->name = strdup (name); - new_local_var->value = strdup (value); - - new_local_var->prev_var = buffer->last_local_var; - new_local_var->next_var = NULL; - if (buffer->local_variables) - buffer->last_local_var->next_var = new_local_var; - else - buffer->local_variables = new_local_var; - buffer->last_local_var = new_local_var; - } - } - - return new_local_var; -} - -/* - * gui_buffer_local_var_remove: remove a local variable in a buffer - */ - -void -gui_buffer_local_var_remove (struct t_gui_buffer *buffer, - struct t_gui_buffer_local_var *local_var) -{ - if (!buffer || !local_var) - return; - - /* free data */ - if (local_var->name) - free (local_var->name); - if (local_var->value) - free (local_var->value); - - /* remove local variable from list */ - if (local_var->prev_var) - (local_var->prev_var)->next_var = local_var->next_var; - if (local_var->next_var) - (local_var->next_var)->prev_var = local_var->prev_var; - if (buffer->local_variables == local_var) - buffer->local_variables = local_var->next_var; - if (buffer->last_local_var == local_var) - buffer->last_local_var = local_var->prev_var; - - free (local_var); -} - -/* - * gui_buffer_local_var_remove_all: remove all local variables in a buffer - */ - -void -gui_buffer_local_var_remove_all (struct t_gui_buffer *buffer) -{ - if (buffer) - { - while (buffer->local_variables) - { - gui_buffer_local_var_remove (buffer, buffer->local_variables); - } - } -} - -/* * gui_buffer_string_replace_local_var: replace local variables ($var) in a * string, using value of local variables */ @@ -615,6 +616,8 @@ gui_buffer_set_name (struct t_gui_buffer *buffer, const char *name) free (buffer->name); buffer->name = strdup (name); + gui_buffer_local_var_add (buffer, "name", name); + hook_signal_send ("buffer_renamed", WEECHAT_HOOK_SIGNAL_POINTER, buffer); } @@ -798,18 +801,18 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, gui_hotlist_add (buffer, number, NULL, 1); } } - else if (string_strcasecmp (property, "unread") == 0) - { - gui_buffer_set_unread (buffer); - } if (!buffer) return; /* properties that need a buffer */ - if (string_strcasecmp (property, "display") == 0) + if (string_strcasecmp (property, "unread") == 0) { - gui_window_switch_to_buffer (gui_current_window, buffer); + gui_buffer_set_unread (buffer); + } + else if (string_strcasecmp (property, "display") == 0) + { + gui_window_switch_to_buffer (gui_current_window, buffer, 0); } else if (string_strcasecmp (property, "name") == 0) { @@ -1280,9 +1283,9 @@ gui_buffer_switch_previous (struct t_gui_window *window) return; if (window->buffer->prev_buffer) - gui_window_switch_to_buffer (window, window->buffer->prev_buffer); + gui_window_switch_to_buffer (window, window->buffer->prev_buffer, 1); else - gui_window_switch_to_buffer (window, last_gui_buffer); + gui_window_switch_to_buffer (window, last_gui_buffer, 1); } /* @@ -1300,9 +1303,9 @@ gui_buffer_switch_next (struct t_gui_window *window) return; if (window->buffer->next_buffer) - gui_window_switch_to_buffer (window, window->buffer->next_buffer); + gui_window_switch_to_buffer (window, window->buffer->next_buffer, 1); else - gui_window_switch_to_buffer (window, gui_buffers); + gui_window_switch_to_buffer (window, gui_buffers, 1); } /* @@ -1327,7 +1330,7 @@ gui_buffer_switch_by_number (struct t_gui_window *window, int number) { if ((ptr_buffer != window->buffer) && (number == ptr_buffer->number)) { - gui_window_switch_to_buffer (window, ptr_buffer); + gui_window_switch_to_buffer (window, ptr_buffer, 1); return; } } @@ -1595,7 +1598,7 @@ gui_buffer_dump_hexa (struct t_gui_buffer *buffer) { struct t_gui_line *ptr_line; int num_line, msg_pos; - char *message_without_colors; + char *message_without_colors, *tags; char hexa[(16 * 3) + 1], ascii[(16 * 2) + 1]; int hexa_pos, ascii_pos; @@ -1613,7 +1616,11 @@ gui_buffer_dump_hexa (struct t_gui_buffer *buffer) message_without_colors : "(null)"); if (message_without_colors) free (message_without_colors); - + tags = string_build_with_exploded ((const char **)ptr_line->tags_array, ","); + log_printf (" tags: %s", (tags) ? tags : "(none)"); + if (tags) + free (tags); + /* display raw message for line */ if (ptr_line->message) { @@ -1766,7 +1773,7 @@ gui_buffer_print_log () while (ptr_line) { num--; - tags = string_build_with_exploded (ptr_line->tags_array, ","); + tags = string_build_with_exploded ((const char **)ptr_line->tags_array, ","); log_printf (" line N-%05d: y:%d, str_time:'%s', tags:'%s', " "displayed:%d, highlight:%d, refresh_needed:%d, prefix:'%s'", num, ptr_line->y, ptr_line->str_time, diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index 1a0e7cf30..657a4e46f 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -1036,7 +1036,7 @@ gui_chat_printf_date_tags (struct t_gui_buffer *buffer, time_t date, { hook_print_exec (buffer, buffer->last_line->date, buffer->last_line->tags_count, - buffer->last_line->tags_array, + (const char **)buffer->last_line->tags_array, buffer->last_line->prefix, buffer->last_line->message); } diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index dd45a4754..70bc2b9f0 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -1140,7 +1140,7 @@ gui_input_jump_smart () if (!gui_hotlist_initial_buffer) gui_hotlist_initial_buffer = gui_current_window->buffer; gui_window_switch_to_buffer (gui_current_window, - gui_hotlist->buffer); + gui_hotlist->buffer, 1); gui_window_scroll_bottom (gui_current_window); } else @@ -1148,7 +1148,7 @@ gui_input_jump_smart () if (gui_hotlist_initial_buffer) { gui_window_switch_to_buffer (gui_current_window, - gui_hotlist_initial_buffer); + gui_hotlist_initial_buffer, 1); gui_window_scroll_bottom (gui_current_window); gui_hotlist_initial_buffer = NULL; } diff --git a/src/gui/gui-layout.c b/src/gui/gui-layout.c index 6ff52c78a..762d19f2f 100644 --- a/src/gui/gui-layout.c +++ b/src/gui/gui-layout.c @@ -419,7 +419,7 @@ gui_layout_window_check_buffer (struct t_gui_buffer *buffer) if ((strcmp (ptr_win->layout_plugin_name, plugin_name) == 0) && (strcmp (ptr_win->layout_buffer_name, buffer->name) == 0)) { - gui_window_switch_to_buffer (ptr_win, buffer); + gui_window_switch_to_buffer (ptr_win, buffer, 0); } } } @@ -450,7 +450,7 @@ gui_layout_window_check_all_buffers () if ((strcmp (ptr_win->layout_plugin_name, plugin_name) == 0) && (strcmp (ptr_win->layout_buffer_name, ptr_buffer->name) == 0)) { - gui_window_switch_to_buffer (ptr_win, ptr_buffer); + gui_window_switch_to_buffer (ptr_win, ptr_buffer, 0); break; } } diff --git a/src/gui/gui-window.h b/src/gui/gui-window.h index 82ca05beb..6441b1033 100644 --- a/src/gui/gui-window.h +++ b/src/gui/gui-window.h @@ -139,7 +139,8 @@ extern void gui_window_objects_free (struct t_gui_window *window, int free_bar_windows); extern void gui_window_calculate_pos_size (struct t_gui_window *window); extern void gui_window_switch_to_buffer (struct t_gui_window *window, - struct t_gui_buffer *buffer); + struct t_gui_buffer *buffer, + int set_last_read); extern void gui_window_switch (struct t_gui_window *window); extern void gui_window_page_up (struct t_gui_window *window); extern void gui_window_page_down (struct t_gui_window *window); diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index 3fbf012e0..d61cf3646 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -677,7 +677,8 @@ alias_config_init () NULL, NULL, NULL, NULL, &alias_config_write_default, NULL, - &alias_config_create_option, NULL); + &alias_config_create_option, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (alias_config_file); diff --git a/src/plugins/aspell/weechat-aspell-config.c b/src/plugins/aspell/weechat-aspell-config.c index a286c7268..46816d347 100644 --- a/src/plugins/aspell/weechat-aspell-config.c +++ b/src/plugins/aspell/weechat-aspell-config.c @@ -111,15 +111,51 @@ weechat_aspell_config_change_default_dict (void *data, } /* - * weechat_aspell_config_create_option: set a dictionary for a buffer + * weechat_aspell_config_dict_change: called when a dictionary is changed + */ + +void +weechat_aspell_config_dict_change (void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) data; + (void) option; + + weechat_aspell_create_spellers (weechat_current_buffer); +} + +/* + * weechat_aspell_config_dict_delete_option: delete option in "dict" section + */ + +int +weechat_aspell_config_dict_delete_option (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) data; + (void) config_file; + (void) section; + + weechat_config_option_free (option); + weechat_aspell_create_spellers (weechat_current_buffer); + + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; +} + +/* + * weechat_aspell_config_dict_create_option: create option in "dict" section */ int -weechat_aspell_config_create_option (void *data, - struct t_config_file *config_file, - struct t_config_section *section, - const char *option_name, - const char *value) +weechat_aspell_config_dict_create_option (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, + const char *value) { struct t_config_option *ptr_option; int rc; @@ -154,7 +190,9 @@ weechat_aspell_config_create_option (void *data, config_file, section, option_name, "string", _("comma separated list of dictionaries to use on this buffer"), - NULL, 0, 0, "", value, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "", value, NULL, NULL, + &weechat_aspell_config_dict_change, NULL, + NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } @@ -195,11 +233,11 @@ weechat_aspell_config_get_dict (const char *name) int weechat_aspell_config_set_dict (const char *name, const char *value) { - return weechat_aspell_config_create_option (NULL, - weechat_aspell_config_file, - weechat_aspell_config_section_dict, - name, - value); + return weechat_aspell_config_dict_create_option (NULL, + weechat_aspell_config_file, + weechat_aspell_config_section_dict, + name, + value); } /* @@ -221,7 +259,8 @@ weechat_aspell_config_init () ptr_section = weechat_config_new_section (weechat_aspell_config_file, "look", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (weechat_aspell_config_file); @@ -238,7 +277,8 @@ weechat_aspell_config_init () ptr_section = weechat_config_new_section (weechat_aspell_config_file, "check", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (weechat_aspell_config_file); @@ -269,12 +309,14 @@ weechat_aspell_config_init () "words)"), NULL, 0, INT_MAX, "2", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + /* dict */ ptr_section = weechat_config_new_section (weechat_aspell_config_file, "dict", 1, 1, NULL, NULL, NULL, NULL, NULL, NULL, - &weechat_aspell_config_create_option, NULL); + &weechat_aspell_config_dict_create_option, NULL, + &weechat_aspell_config_dict_delete_option, NULL); if (!ptr_section) { weechat_config_free (weechat_aspell_config_file); diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c index 778d92647..a87812e4e 100644 --- a/src/plugins/aspell/weechat-aspell.c +++ b/src/plugins/aspell/weechat-aspell.c @@ -257,6 +257,8 @@ weechat_aspell_get_dict (struct t_gui_buffer *buffer) if (ptr_option) return weechat_config_string (ptr_option); } + else + free (name); /* nothing found => return default dictionary (if set) */ if (weechat_config_string (weechat_aspell_config_check_default_dict) @@ -283,10 +285,10 @@ weechat_aspell_set_dict (struct t_gui_buffer *buffer, const char *value) if (weechat_aspell_config_set_dict (name, value) > 0) { if (value && value[0]) - weechat_printf (NULL, "%s: %s => %s", + weechat_printf (NULL, "%s: \"%s\" => %s", ASPELL_PLUGIN_NAME, name, value); else - weechat_printf (NULL, _("%s: %s: removed"), + weechat_printf (NULL, _("%s: \"%s\" removed"), ASPELL_PLUGIN_NAME, name); } diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c index e4c7a88a1..c3379491d 100644 --- a/src/plugins/charset/charset.c +++ b/src/plugins/charset/charset.c @@ -181,9 +181,8 @@ charset_config_init () ptr_section = weechat_config_new_section (charset_config_file, "default", 0, 0, - NULL, NULL, - NULL, NULL, - NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL); if (!ptr_section) { @@ -210,10 +209,10 @@ charset_config_init () ptr_section = weechat_config_new_section (charset_config_file, "decode", 1, 1, + NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, - NULL, NULL, - &charset_config_create_option, NULL); + &charset_config_create_option, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (charset_config_file); @@ -224,10 +223,10 @@ charset_config_init () ptr_section = weechat_config_new_section (charset_config_file, "encode", 1, 1, + NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, - NULL, NULL, - &charset_config_create_option, NULL); + &charset_config_create_option, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (charset_config_file); @@ -407,10 +406,10 @@ charset_set (struct t_config_section *section, const char *type, value) > 0) { if (value && value[0]) - weechat_printf (NULL, "%s: %s, %s => %s", + weechat_printf (NULL, "%s: %s, \"%s\" => %s", CHARSET_PLUGIN_NAME, type, name, value); else - weechat_printf (NULL, _("%s: %s, %s: removed"), + weechat_printf (NULL, _("%s: %s, \"%s\": removed"), CHARSET_PLUGIN_NAME, type, name); } } diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 1c3082ae1..ee7a42ed0 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -2067,7 +2067,7 @@ irc_command_msg (void *data, struct t_gui_buffer *buffer, int argc, { msg_pwd_hidden = strdup (argv_eol[2]); if (msg_pwd_hidden - && (weechat_config_boolean (irc_config_log_hide_nickserv_pwd))) + && (weechat_config_boolean (irc_config_look_hide_nickserv_pwd))) irc_display_hide_password (msg_pwd_hidden, 0); string = irc_color_decode ( (msg_pwd_hidden) ? msg_pwd_hidden : argv_eol[2], diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 240a6a842..e21874931 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -57,6 +57,7 @@ struct t_config_option *irc_config_look_nick_suffix; struct t_config_option *irc_config_look_nick_completion_smart; struct t_config_option *irc_config_look_display_away; struct t_config_option *irc_config_look_display_channel_modes; +struct t_config_option *irc_config_look_hide_nickserv_pwd; struct t_config_option *irc_config_look_highlight_tags; struct t_config_option *irc_config_look_show_away_once; struct t_config_option *irc_config_look_smart_filter; @@ -77,13 +78,6 @@ struct t_config_option *irc_config_network_colors_receive; struct t_config_option *irc_config_network_colors_send; struct t_config_option *irc_config_network_send_unknown_commands; -/* IRC config, log section */ - -struct t_config_option *irc_config_log_auto_log_server; -struct t_config_option *irc_config_log_auto_log_channel; -struct t_config_option *irc_config_log_auto_log_private; -struct t_config_option *irc_config_log_hide_nickserv_pwd; - /* IRC config, server section */ struct t_config_option *irc_config_server_default[IRC_CONFIG_NUM_SERVER_OPTIONS]; @@ -176,27 +170,6 @@ irc_config_change_display_channel_modes (void *data, } /* - * irc_config_change_smart_filter: called when the "smart_filter" option is - * changed - */ - -void -irc_config_change_smart_filter (void *data, - struct t_config_option *option) -{ - /* make C compiler happy */ - (void) data; - (void) option; - - if (weechat_config_boolean (irc_config_look_smart_filter)) - { - weechat_printf (NULL, - _("You should now create filter on tag " - "\"irc_smart_filter\" with command /filter.")); - } -} - -/* * irc_config_change_away_check: called when away check is changed */ @@ -228,60 +201,6 @@ irc_config_change_away_check (void *data, } /* - * irc_config_change_log: called when log settings are changed - * (for server/channel/private logging) - */ - -void -irc_config_change_log (void *data, - struct t_config_option *option) -{ - /* make C compiler happy */ - (void) data; - (void) option; - - /*t_gui_buffer *ptr_buffer; - t_irc_server *ptr_server; - t_irc_channel *ptr_channel; - - for (ptr_buffer = gui_buffers; ptr_buffer; - ptr_buffer = ptr_buffer->next_buffer) - { - if (ptr_buffer->protocol == irc_protocol) - { - ptr_server = irc_server_search (ptr_buffer->category); - ptr_channel = irc_channel_search (ptr_server, ptr_buffer->name); - - if (ptr_server && !ptr_channel) - { - if (irc_config_log_auto_server && !ptr_buffer->log_file) - gui_log_start (ptr_buffer); - else if (!irc_config_log_auto_server && ptr_buffer->log_file) - gui_log_end (ptr_buffer); - } - if (ptr_server && ptr_channel) - { - if (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL) - { - if (irc_config_log_auto_channel && !ptr_buffer->log_file) - gui_log_start (ptr_buffer); - else if (!irc_config_log_auto_channel && ptr_buffer->log_file) - gui_log_end (ptr_buffer); - } - else - { - if (irc_config_log_auto_private && !ptr_buffer->log_file) - gui_log_start (ptr_buffer); - else if (!irc_config_log_auto_private && ptr_buffer->log_file) - gui_log_end (ptr_buffer); - } - } - } - } - */ -} - -/* * irc_config_server_default_change_cb: callback called when a default server * option is modified */ @@ -1014,7 +933,8 @@ irc_config_init () ptr_section = weechat_config_new_section (irc_config_file, "look", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (irc_config_file); @@ -1056,6 +976,11 @@ irc_config_init () "display_channel_modes", "boolean", N_("display channel modes in \"buffer_name\" bar item"), NULL, 0, 0, "on", NULL, NULL, NULL, &irc_config_change_display_channel_modes, NULL, NULL, NULL); + irc_config_look_hide_nickserv_pwd = weechat_config_new_option ( + irc_config_file, ptr_section, + "hide_nickserv_pwd", "boolean", + N_("hide password displayed by nickserv"), + NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_highlight_tags = weechat_config_new_option ( irc_config_file, ptr_section, "highlight_tags", "string", @@ -1072,8 +997,9 @@ irc_config_init () irc_config_file, ptr_section, "smart_filter", "boolean", N_("filter join/part/quit messages for a nick if not speaking for " - "some minutes on channel"), - NULL, 0, 0, "off", NULL, NULL, NULL, &irc_config_change_smart_filter, NULL, NULL, NULL); + "some minutes on channel (you must create a filter on tag " + "\"irc_smart_filter\")"), + NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); irc_config_look_smart_filter_delay = weechat_config_new_option ( irc_config_file, ptr_section, "smart_filter_delay", "integer", @@ -1089,7 +1015,8 @@ irc_config_init () ptr_section = weechat_config_new_section (irc_config_file, "network", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (irc_config_file); @@ -1161,45 +1088,13 @@ irc_config_init () N_("send unknown commands to IRC server"), NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL); - /* log */ - ptr_section = weechat_config_new_section (irc_config_file, "log", - 0, 0, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); - if (!ptr_section) - { - weechat_config_free (irc_config_file); - return 0; - } - - irc_config_log_auto_log_server = weechat_config_new_option ( - irc_config_file, ptr_section, - "auto_log_server", "boolean", - N_("automatically log server messages"), - NULL, 0, 0, "off", NULL, NULL, NULL, &irc_config_change_log, NULL, NULL, NULL); - irc_config_log_auto_log_channel = weechat_config_new_option ( - irc_config_file, ptr_section, - "auto_log_channel", "boolean", - N_("automatically log channel chats"), - NULL, 0, 0, "off", NULL, NULL, NULL, &irc_config_change_log, NULL, NULL, NULL); - irc_config_log_auto_log_private = weechat_config_new_option ( - irc_config_file, ptr_section, - "auto_log_private", "boolean", - N_("automatically log private chats"), - NULL, 0, 0, "off", NULL, NULL, NULL, &irc_config_change_log, NULL, NULL, NULL); - irc_config_log_hide_nickserv_pwd = weechat_config_new_option ( - irc_config_file, ptr_section, - "hide_nickserv_pwd", "boolean", - N_("hide password displayed by nickserv"), - NULL, 0, 0, "on", NULL, NULL, NULL, &irc_config_change_log, NULL, NULL, NULL); - /* filters */ ptr_section = weechat_config_new_section (irc_config_file, "ignore", 0, 0, &irc_config_ignore_read, NULL, &irc_config_ignore_write, NULL, &irc_config_ignore_write, NULL, - NULL, NULL); + NULL, NULL, NULL, NULL); if (!ptr_section) { weechat_config_free (irc_config_file); @@ -1210,7 +1105,8 @@ irc_config_init () ptr_section = weechat_config_new_section (irc_config_file, "server_default", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (irc_config_file); @@ -1227,7 +1123,8 @@ irc_config_init () NULL, NULL, NULL, NULL, &irc_config_server_write_default, NULL, - &irc_config_server_create_option, NULL); + &irc_config_server_create_option, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (irc_config_file); diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 4a16077a3..c18501634 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -69,6 +69,7 @@ extern struct t_config_option *irc_config_look_nick_suffix; extern struct t_config_option *irc_config_look_nick_completion_smart; extern struct t_config_option *irc_config_look_display_away; extern struct t_config_option *irc_config_look_display_channel_modes; +extern struct t_config_option *irc_config_look_hide_nickserv_pwd; extern struct t_config_option *irc_config_look_highlight_tags; extern struct t_config_option *irc_config_look_show_away_once; extern struct t_config_option *irc_config_look_smart_filter; @@ -87,11 +88,6 @@ extern struct t_config_option *irc_config_network_colors_receive; extern struct t_config_option *irc_config_network_colors_send; extern struct t_config_option *irc_config_network_send_unknown_commands; -extern struct t_config_option *irc_config_log_auto_log_server; -extern struct t_config_option *irc_config_log_auto_log_channel; -extern struct t_config_option *irc_config_log_auto_log_private; -extern struct t_config_option *irc_config_log_hide_nickserv_pwd; - extern struct t_config_option *irc_config_server_default[]; extern int irc_config_search_server_option (const char *option_name); diff --git a/src/plugins/irc/irc-display.c b/src/plugins/irc/irc-display.c index e1c8a4a61..c221f739e 100644 --- a/src/plugins/irc/irc-display.c +++ b/src/plugins/irc/irc-display.c @@ -201,7 +201,7 @@ irc_display_server (struct t_irc_server *server, int with_detail) string = NULL; if (string) { - if (weechat_config_boolean (irc_config_log_hide_nickserv_pwd)) + if (weechat_config_boolean (irc_config_look_hide_nickserv_pwd)) irc_display_hide_password (string, 1); weechat_printf (NULL, " command . . . . . . : %s", string); diff --git a/src/plugins/irc/irc-input.c b/src/plugins/irc/irc-input.c index 689ac735e..0d77558c1 100644 --- a/src/plugins/irc/irc-input.c +++ b/src/plugins/irc/irc-input.c @@ -30,6 +30,7 @@ #include "irc-nick.h" #include "irc-color.h" #include "irc-config.h" +#include "irc-protocol.h" /* @@ -54,12 +55,13 @@ irc_input_user_message_display (struct t_gui_buffer *buffer, const char *text) else ptr_nick = NULL; - weechat_printf (buffer, - "%s%s", - irc_nick_as_prefix ((ptr_nick) ? ptr_nick : NULL, - (ptr_nick) ? NULL : ptr_server->nick, - IRC_COLOR_CHAT_NICK_SELF), - (text_decoded) ? text_decoded : text); + weechat_printf_tags (buffer, + irc_protocol_tags ("privmsg", NULL), + "%s%s", + irc_nick_as_prefix ((ptr_nick) ? ptr_nick : NULL, + (ptr_nick) ? NULL : ptr_server->nick, + IRC_COLOR_CHAT_NICK_SELF), + (text_decoded) ? text_decoded : text); } if (text_decoded) diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 1e7257609..0e7b1df6a 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -100,27 +100,69 @@ irc_protocol_get_address_from_host (const char *host) } /* + * irc_protocol_log_level_for_command: get log level for IRC command + */ + +int +irc_protocol_log_level_for_command (const char *command) +{ + if (!command || !command[0]) + return 0; + + if ((strcmp (command, "privmsg") == 0) + || (strcmp (command, "notice") == 0)) + return 1; + + if (strcmp (command, "nick") == 0) + return 2; + + if ((strcmp (command, "join") == 0) + || (strcmp (command, "part") == 0) + || (strcmp (command, "quit") == 0)) + return 4; + + return 3; +} + +/* * irc_protocol_tags: build tags list with IRC command and/or tags */ char * irc_protocol_tags (const char *command, const char *tags) { - static char string[256]; + static char string[512]; + int log_level; + char str_log_level[32]; - if (command && tags) + log_level = 0; + str_log_level[0] = '\0'; + + if (command && command[0]) { - snprintf (string, sizeof (string), "irc_cmd_%s,%s", command, tags); + log_level = irc_protocol_log_level_for_command (command); + if (log_level > 0) + { + snprintf (str_log_level, sizeof (str_log_level), + ",log%d", log_level); + } + } + + if (command && command[0] && tags && tags[0]) + { + snprintf (string, sizeof (string), + "irc_cmd_%s,%s%s", command, tags, str_log_level); return string; } - if (command) + if (command && command[0]) { - snprintf (string, sizeof (string), "irc_cmd_%s", command); + snprintf (string, sizeof (string), + "irc_cmd_%s%s", command, str_log_level); return string; } - if (tags) + if (tags && tags[0]) { snprintf (string, sizeof (string), "%s", tags); return string; @@ -243,7 +285,7 @@ irc_protocol_cmd_invite (struct t_irc_server *server, const char *command, if (!irc_ignore_check (server, NULL, nick, host)) { weechat_printf_tags (server->buffer, - "irc_invite,notify_highlight", + irc_protocol_tags (command, "otify_highlight"), _("%sYou have been invited to %s%s%s by " "%s%s"), irc_buffer_get_server_prefix (server, "network"), @@ -305,10 +347,11 @@ irc_protocol_cmd_join (struct t_irc_server *server, const char *command, ptr_nick_speaking = (weechat_config_boolean (irc_config_look_smart_filter)) ? irc_channel_nick_speaking_time_search (ptr_channel, nick, 1) : NULL; weechat_printf_tags (ptr_channel->buffer, - (local_join - || !weechat_config_boolean (irc_config_look_smart_filter) - || ptr_nick_speaking) ? - "irc_join" : "irc_join,irc_smart_filter", + irc_protocol_tags (command, + (local_join + || !weechat_config_boolean (irc_config_look_smart_filter) + || ptr_nick_speaking) ? + NULL : "irc_smart_filter"), _("%s%s%s %s(%s%s%s)%s has joined %s%s"), weechat_prefix ("join"), IRC_COLOR_CHAT_NICK, @@ -378,7 +421,7 @@ irc_protocol_cmd_kick (struct t_irc_server *server, const char *command, if (pos_comment) { weechat_printf_tags (ptr_channel->buffer, - "irc_kick", + irc_protocol_tags (command, NULL), _("%s%s%s%s has kicked %s%s%s from %s%s " "%s(%s%s%s)"), weechat_prefix ("quit"), @@ -398,7 +441,7 @@ irc_protocol_cmd_kick (struct t_irc_server *server, const char *command, else { weechat_printf_tags (ptr_channel->buffer, - "irc_kick", + irc_protocol_tags (command, NULL), _("%s%s%s%s has kicked %s%s%s from %s%s"), weechat_prefix ("quit"), IRC_COLOR_CHAT_NICK, @@ -463,7 +506,7 @@ irc_protocol_cmd_kill (struct t_irc_server *server, const char *command, if (pos_comment) { weechat_printf_tags (ptr_channel->buffer, - "irc_kill", + irc_protocol_tags (command, NULL), _("%sYou were killed by %s%s %s(%s%s%s)"), weechat_prefix ("quit"), IRC_COLOR_CHAT_NICK, @@ -476,7 +519,7 @@ irc_protocol_cmd_kill (struct t_irc_server *server, const char *command, else { weechat_printf_tags (ptr_channel->buffer, - "irc_kill", + irc_protocol_tags (command, NULL), _("%sYou were killed by %s%s"), weechat_prefix ("quit"), IRC_COLOR_CHAT_NICK, @@ -536,7 +579,7 @@ irc_protocol_cmd_mode (struct t_irc_server *server, const char *command, { weechat_printf_tags ((ptr_channel) ? ptr_channel->buffer : server->buffer, - "irc_mode", + irc_protocol_tags (command, NULL), _("%sMode %s%s %s[%s%s%s]%s by %s%s"), (ptr_channel) ? weechat_prefix ("network") : irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_CHANNEL, @@ -555,7 +598,7 @@ irc_protocol_cmd_mode (struct t_irc_server *server, const char *command, if (!irc_ignore_check (server, NULL, nick, host)) { weechat_printf_tags (server->buffer, - "irc_mode", + irc_protocol_tags (command, NULL), _("%sUser mode %s[%s%s%s]%s by %s%s"), irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_DELIMITERS, @@ -627,7 +670,7 @@ irc_protocol_cmd_nick (struct t_irc_server *server, const char *command, if (local_nick) { weechat_printf_tags (ptr_channel->buffer, - "irc_nick", + irc_protocol_tags (command, NULL), _("%sYou are now known as " "%s%s"), weechat_prefix ("network"), @@ -639,7 +682,7 @@ irc_protocol_cmd_nick (struct t_irc_server *server, const char *command, if (!irc_ignore_check (server, ptr_channel, nick, host)) { weechat_printf_tags (ptr_channel->buffer, - "irc_nick", + irc_protocol_tags (command, NULL), _("%s%s%s%s is now known as " "%s%s"), weechat_prefix ("network"), @@ -676,10 +719,11 @@ int irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, int argc, char **argv, char **argv_eol) { - char *pos_target, *pos_args, *pos_end, *pos_usec, tags[128]; + char *pos_target, *pos_args, *pos_end, *pos_usec; struct timeval tv; long sec1, usec1, sec2, usec2, difftime; struct t_irc_channel *ptr_channel; + int notify_private; /* NOTICE message looks like: NOTICE AUTH :*** Looking up your hostname... @@ -711,7 +755,7 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, if (pos_end) pos_end[0] = '\0'; weechat_printf_tags (server->buffer, - "irc_notice", + irc_protocol_tags (command, NULL), _("%sCTCP %sVERSION%s reply from %s%s%s: %s"), irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_CHANNEL, @@ -749,7 +793,7 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, ((sec1 * 1000000) + usec1); weechat_printf_tags (server->buffer, - "irc_notice,irc_ctcp", + irc_protocol_tags (command, "irc_ctcp"), _("%sCTCP %sPING%s reply from " "%s%s%s: %ld.%ld %s"), irc_buffer_get_server_prefix (server, @@ -776,7 +820,7 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, /* notice for channel */ ptr_channel = irc_channel_search (server, pos_target); weechat_printf_tags ((ptr_channel) ? ptr_channel->buffer : server->buffer, - "irc_notice", + irc_protocol_tags (command, NULL), "%sNotice%s(%s%s%s)%s: %s", (ptr_channel) ? weechat_prefix ("network") : irc_buffer_get_server_prefix (server, "network"), @@ -790,18 +834,13 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, else { /* notice for user */ + notify_private = 0; if (nick && (weechat_strcasecmp (nick, "nickserv") != 0) && (weechat_strcasecmp (nick, "chanserv") != 0) && (weechat_strcasecmp (nick, "memoserv") != 0)) { - snprintf (tags, sizeof (tags), - "%s", "irc_notice,notify_private"); - } - else - { - snprintf (tags, sizeof (tags), - "%s", "irc_notice"); + notify_private = 1; } if (nick && weechat_config_boolean (irc_config_look_notice_as_pv)) @@ -827,7 +866,8 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, irc_channel_set_topic (ptr_channel, address); weechat_printf_tags (ptr_channel->buffer, - tags, + irc_protocol_tags (command, + (notify_private) ? "notify_private" : NULL), "%s%s", irc_nick_as_prefix (NULL, nick, IRC_COLOR_CHAT_NICK_OTHER), @@ -838,7 +878,8 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, if (address && address[0]) { weechat_printf_tags (server->buffer, - tags, + irc_protocol_tags (command, + (notify_private) ? "notify_private" : NULL), "%s%s%s %s(%s%s%s)%s: %s", irc_buffer_get_server_prefix (server, "network"), @@ -856,7 +897,8 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, if (nick && nick[0]) { weechat_printf_tags (server->buffer, - tags, + irc_protocol_tags (command, + (notify_private) ? "notify_private" : NULL), "%s%s%s%s: %s", irc_buffer_get_server_prefix (server, "network"), @@ -868,7 +910,8 @@ irc_protocol_cmd_notice (struct t_irc_server *server, const char *command, else { weechat_printf_tags (server->buffer, - tags, + irc_protocol_tags (command, + (notify_private) ? "notify_private" : NULL), "%s%s", irc_buffer_get_server_prefix (server, "network"), @@ -923,10 +966,11 @@ irc_protocol_cmd_part (struct t_irc_server *server, const char *command, if (pos_comment) { weechat_printf_tags (ptr_channel->buffer, - (local_part - || !weechat_config_boolean (irc_config_look_smart_filter) - || ptr_nick_speaking) ? - "irc_part" : "irc_part,irc_smart_filter", + irc_protocol_tags (command, + (local_part + || !weechat_config_boolean (irc_config_look_smart_filter) + || ptr_nick_speaking) ? + NULL : "irc_smart_filter"), _("%s%s%s %s(%s%s%s)%s has left %s%s " "%s(%s%s%s)"), weechat_prefix ("quit"), @@ -947,10 +991,11 @@ irc_protocol_cmd_part (struct t_irc_server *server, const char *command, else { weechat_printf_tags (ptr_channel->buffer, - (local_part - || !weechat_config_boolean (irc_config_look_smart_filter) - || ptr_nick_speaking) ? - "irc_part" : "irc_part,irc_smart_filter", + irc_protocol_tags (command, + (local_part + || !weechat_config_boolean (irc_config_look_smart_filter) + || ptr_nick_speaking) ? + NULL : "irc_smart_filter"), _("%s%s%s %s(%s%s%s)%s has left " "%s%s"), weechat_prefix ("quit"), @@ -1173,7 +1218,8 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, pos_end_01[0] = '\0'; weechat_printf_tags (ptr_channel->buffer, - "irc_privmsg,irc_action,notify_message", + irc_protocol_tags (command, + "irc_action,notify_message"), "%s%s%s %s%s", weechat_prefix ("action"), IRC_COLOR_CHAT_NICK, @@ -1202,7 +1248,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, pos_end_01[0] = '\0'; weechat_printf_tags (ptr_channel->buffer, - "irc_privmsg,irc_ctcp", + irc_protocol_tags (command, "irc_ctcp"), _("%sReceived a CTCP %sSOUND%s \"%s\" " "from %s%s"), weechat_prefix ("network"), @@ -1239,7 +1285,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, irc_server_sendf (server, "NOTICE %s :\01PING\01", nick); weechat_printf_tags (ptr_channel->buffer, - "irc_privmsg,irc_ctcp", + irc_protocol_tags (command, "irc_ctcp"), _("%sCTCP %sPING%s received from %s%s"), weechat_prefix ("network"), IRC_COLOR_CHAT_CHANNEL, @@ -1290,7 +1336,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, if (pos_message) { weechat_printf_tags (ptr_channel->buffer, - "irc_privmsg,irc_ctcp", + irc_protocol_tags (command, "irc_ctcp"), _("%sUnknown CTCP %s%s%s " "received from %s%s%s: %s"), weechat_prefix ("network"), @@ -1305,7 +1351,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, else { weechat_printf_tags (ptr_channel->buffer, - "irc_privmsg,irc_ctcp", + irc_protocol_tags (command, "irc_ctcp"), _("%sUnknown CTCP %s%s%s " "received from %s%s"), weechat_prefix ("network"), @@ -1334,7 +1380,8 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, if (!irc_ignore_check (server, ptr_channel, nick, host)) { weechat_printf_tags (ptr_channel->buffer, - "irc_privmsg,notify_message", + irc_protocol_tags (command, + "notify_message"), "%s%s", irc_nick_as_prefix (ptr_nick, (ptr_nick) ? NULL : nick, @@ -1395,7 +1442,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, irc_server_sendf (server, "NOTICE %s :\01PING\01", nick); weechat_printf_tags (server->buffer, - "irc_privmsg,irc_ctcp", + irc_protocol_tags (command, "irc_ctcp"), _("%sCTCP %sPING%s received from %s%s"), irc_buffer_get_server_prefix (server, "network"), @@ -1906,7 +1953,8 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, pos_end_01[0] = '\0'; weechat_printf_tags (ptr_channel->buffer, - "irc_privmsg,irc_action,notify_private", + irc_protocol_tags (command, + "irc_action,notify_private"), "%s%s%s %s%s", weechat_prefix ("action"), IRC_COLOR_CHAT_NICK, @@ -1950,7 +1998,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, if (pos_message) { weechat_printf_tags (server->buffer, - "irc_privmsg,irc_ctcp", + irc_protocol_tags (command, "irc_ctcp"), _("%sUnknown CTCP %s%s%s " "received from %s%s%s: %s"), irc_buffer_get_server_prefix (server, @@ -1966,7 +2014,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, else { weechat_printf_tags (server->buffer, - "irc_privmsg,irc_ctcp", + irc_protocol_tags (command, "irc_ctcp"), _("%sUnknown CTCP %s%s%s " "received from %s%s"), irc_buffer_get_server_prefix (server, @@ -2011,7 +2059,7 @@ irc_protocol_cmd_privmsg (struct t_irc_server *server, const char *command, irc_channel_set_topic (ptr_channel, address); weechat_printf_tags (ptr_channel->buffer, - "irc_privmsg,notify_private", + irc_protocol_tags (command, "notify_private"), "%s%s", irc_nick_as_prefix (NULL, nick, @@ -2076,10 +2124,11 @@ irc_protocol_cmd_quit (struct t_irc_server *server, const char *command, if (pos_comment && pos_comment[0]) { weechat_printf_tags (ptr_channel->buffer, - (local_quit - || !weechat_config_boolean (irc_config_look_smart_filter) - || ptr_nick_speaking) ? - "irc_quit" : "irc_quit,irc_smart_filter", + irc_protocol_tags (command, + (local_quit + || !weechat_config_boolean (irc_config_look_smart_filter) + || ptr_nick_speaking) ? + NULL : "irc_smart_filter"), _("%s%s%s %s(%s%s%s)%s has quit " "%s(%s%s%s)"), weechat_prefix ("quit"), @@ -2098,10 +2147,11 @@ irc_protocol_cmd_quit (struct t_irc_server *server, const char *command, else { weechat_printf_tags (ptr_channel->buffer, - (local_quit - || !weechat_config_boolean (irc_config_look_smart_filter) - || ptr_nick_speaking) ? - "irc_quit" : "irc_quit,irc_smart_filter", + irc_protocol_tags (command, + (local_quit + || !weechat_config_boolean (irc_config_look_smart_filter) + || ptr_nick_speaking) ? + NULL : "irc_smart_filter"), _("%s%s%s %s(%s%s%s)%s has quit"), weechat_prefix ("quit"), IRC_COLOR_CHAT_NICK, @@ -2229,7 +2279,7 @@ irc_protocol_cmd_topic (struct t_irc_server *server, const char *command, topic_color = irc_color_decode (pos_topic, weechat_config_boolean (irc_config_network_colors_receive)); weechat_printf_tags (ptr_buffer, - "irc_topic", + irc_protocol_tags (command, NULL), _("%s%s%s%s has changed topic for %s%s%s to: " "\"%s%s\""), (ptr_buffer == server->buffer) ? @@ -2248,7 +2298,7 @@ irc_protocol_cmd_topic (struct t_irc_server *server, const char *command, else { weechat_printf_tags (ptr_buffer, - "irc_topic", + irc_protocol_tags (command, NULL), _("%s%s%s%s has unset topic for %s%s"), (ptr_buffer == server->buffer) ? irc_buffer_get_server_prefix (server, "network") : weechat_prefix ("network"), @@ -2284,7 +2334,7 @@ irc_protocol_cmd_wallops (struct t_irc_server *server, const char *command, if (!irc_ignore_check (server, NULL, nick, host)) { weechat_printf_tags (server->buffer, - "irc_wallops", + irc_protocol_tags (command, NULL), _("%sWallops from %s%s %s(%s%s%s)%s: %s"), irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_NICK, @@ -2553,15 +2603,7 @@ irc_protocol_cmd_305 (struct t_irc_server *server, const char *command, server->is_away = 0; server->away_time = 0; - /* - for (ptr_window = gui_windows; ptr_window; - ptr_window = ptr_window->next_window) - { - if ((ptr_window->buffer->protocol == irc_protocol) - && (IRC_BUFFER_SERVER(ptr_window->buffer) == server)) - gui_status_draw (ptr_window->buffer, 1); - } - */ + weechat_bar_item_update ("buffer_name"); return WEECHAT_RC_OK; } @@ -2595,21 +2637,7 @@ irc_protocol_cmd_306 (struct t_irc_server *server, const char *command, server->is_away = 1; server->away_time = time (NULL); - /* - for (ptr_window = gui_windows; ptr_window; - ptr_window = ptr_window->next_window) - { - if (ptr_window->buffer->protocol == irc_protocol) - { - if (IRC_BUFFER_SERVER(ptr_window->buffer) == server) - { - gui_status_draw (ptr_window->buffer, 1); - ptr_window->buffer->last_read_line = - ptr_window->buffer->last_line; - } - } - } - */ + weechat_bar_item_update ("buffer_name"); return WEECHAT_RC_OK; } @@ -2689,7 +2717,7 @@ irc_protocol_cmd_312 (struct t_irc_server *server, const char *command, IRC_PROTOCOL_MIN_ARGS(6); weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s[%s%s%s] %s%s %s(%s%s%s)", irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_DELIMITERS, @@ -2721,7 +2749,7 @@ irc_protocol_cmd_314 (struct t_irc_server *server, const char *command, IRC_PROTOCOL_MIN_ARGS(8); weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%s%s%s %s(%s%s@%s%s)%s was %s"), irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_NICK, @@ -2761,7 +2789,7 @@ irc_protocol_cmd_315 (struct t_irc_server *server, const char *command, else { weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s[%s%s%s]%s %s", irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_DELIMITERS, @@ -2806,7 +2834,7 @@ irc_protocol_cmd_317 (struct t_irc_server *server, const char *command, if (day > 0) { weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%s%s[%s%s%s]%s idle: %s%d %s%s, " "%s%02d %s%s %s%02d %s%s %s%02d " "%s%s, signon at: %s%s"), @@ -2838,7 +2866,7 @@ irc_protocol_cmd_317 (struct t_irc_server *server, const char *command, else { weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%s%s[%s%s%s]%s idle: %s%02d %s%s " "%s%02d %s%s %s%02d %s%s, " "signon at: %s%s"), @@ -2887,7 +2915,7 @@ irc_protocol_cmd_321 (struct t_irc_server *server, const char *command, ((argv_eol[4][0] == ':') ? argv_eol[4] + 1 : argv_eol[4]) : NULL; weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s%s%s", irc_buffer_get_server_prefix (server, "network"), argv[3], @@ -2920,7 +2948,7 @@ irc_protocol_cmd_322 (struct t_irc_server *server, const char *command, (regexec (server->cmd_list_regexp, argv[3], 0, NULL, 0) == 0)) { weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s%s%s(%s%s%s)%s%s%s", irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_CHANNEL, @@ -2960,7 +2988,7 @@ irc_protocol_cmd_323 (struct t_irc_server *server, const char *command, ((argv_eol[3][0] == ':') ? argv_eol[3] + 1 : argv_eol[3]) : NULL; weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s", irc_buffer_get_server_prefix (server, "network"), (pos_args && pos_args[0]) ? pos_args : ""); @@ -3030,7 +3058,7 @@ irc_protocol_cmd_327 (struct t_irc_server *server, const char *command, if (pos_realname && pos_realname[0]) { weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s[%s%s%s] %s%s %s %s(%s%s%s)", irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_DELIMITERS, @@ -3048,7 +3076,7 @@ irc_protocol_cmd_327 (struct t_irc_server *server, const char *command, else { weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s[%s%s%s] %s%s %s", irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_DELIMITERS, @@ -3083,7 +3111,7 @@ irc_protocol_cmd_328 (struct t_irc_server *server, const char *command, if (ptr_channel) { weechat_printf_tags (ptr_channel->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%sURL for %s%s%s: %s"), weechat_prefix ("network"), IRC_COLOR_CHAT_CHANNEL, @@ -3123,7 +3151,7 @@ irc_protocol_cmd_329 (struct t_irc_server *server, const char *command, if (ptr_channel->display_creation_date) { weechat_printf_tags (ptr_channel->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%sChannel created on %s"), weechat_prefix ("network"), ctime (&datetime)); @@ -3133,7 +3161,7 @@ irc_protocol_cmd_329 (struct t_irc_server *server, const char *command, else { weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%sChannel %s%s%s created on %s"), irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_CHANNEL, @@ -3168,7 +3196,7 @@ irc_protocol_cmd_331 (struct t_irc_server *server, const char *command, ptr_channel = irc_channel_search (server, argv[3]); ptr_buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer; weechat_printf_tags (ptr_buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%sNo topic set for channel %s%s"), (ptr_buffer == server->buffer) ? irc_buffer_get_server_prefix (server, "network") : weechat_prefix ("network"), @@ -3209,7 +3237,7 @@ irc_protocol_cmd_332 (struct t_irc_server *server, const char *command, ptr_buffer = server->buffer; weechat_printf_tags (ptr_buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%sTopic for %s%s%s is: \"%s%s\""), (ptr_buffer == server->buffer) ? irc_buffer_get_server_prefix (server, "network") : weechat_prefix ("network"), @@ -3245,7 +3273,7 @@ irc_protocol_cmd_333 (struct t_irc_server *server, const char *command, if (ptr_channel && ptr_channel->nicks) { weechat_printf_tags (ptr_channel->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%sTopic set by %s%s%s on %s"), weechat_prefix ("network"), IRC_COLOR_CHAT_NICK, @@ -3256,7 +3284,7 @@ irc_protocol_cmd_333 (struct t_irc_server *server, const char *command, else { weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%sTopic for %s%s%s set by %s%s%s on %s"), irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_CHANNEL, @@ -3286,7 +3314,7 @@ irc_protocol_cmd_338 (struct t_irc_server *server, const char *command, IRC_PROTOCOL_MIN_ARGS(6); weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s[%s%s%s]%s %s %s%s", irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_DELIMITERS, @@ -3319,7 +3347,7 @@ irc_protocol_cmd_341 (struct t_irc_server *server, const char *command, (void) argv_eol; weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%s%s%s%s has invited %s%s%s on %s%s"), irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_NICK, @@ -3349,7 +3377,7 @@ irc_protocol_cmd_344 (struct t_irc_server *server, const char *command, IRC_PROTOCOL_MIN_ARGS(5); weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%sChannel reop %s%s%s: %s%s"), irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_CHANNEL, @@ -3376,7 +3404,7 @@ irc_protocol_cmd_345 (struct t_irc_server *server, const char *command, IRC_PROTOCOL_MIN_ARGS(5); weechat_printf_tags (server->buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), "%s%s%s%s: %s", irc_buffer_get_server_prefix (server, "network"), IRC_COLOR_CHAT_CHANNEL, @@ -3416,7 +3444,7 @@ irc_protocol_cmd_348 (struct t_irc_server *server, const char *command, { datetime = (time_t)(atol (argv[6])); weechat_printf_tags (ptr_buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%s%s[%s%s%s]%s exception %s%s%s " "by %s%s %s(%s%s%s)%s on %s"), (ptr_buffer == server->buffer) ? @@ -3441,7 +3469,7 @@ irc_protocol_cmd_348 (struct t_irc_server *server, const char *command, else { weechat_printf_tags (ptr_buffer, - irc_protocol_tags(command, "irc_numeric"), + irc_protocol_tags (command, "irc_numeric"), _("%s%s[%s%s%s]%s exception %s%s"), (ptr_buffer == server->buffer) ? irc_buffer_get_server_prefix (server, "network") : weechat_prefix ("network"), diff --git a/src/plugins/irc/irc-protocol.h b/src/plugins/irc/irc-protocol.h index 29b56bfac..cee34c829 100644 --- a/src/plugins/irc/irc-protocol.h +++ b/src/plugins/irc/irc-protocol.h @@ -70,6 +70,7 @@ struct t_irc_protocol_msg }; extern char *irc_protocol_get_nick_from_host (const char *host); +extern char *irc_protocol_tags (const char *command, const char *tags); extern void irc_protocol_recv_command (struct t_irc_server *server, const char *entire_line, const char *host, const char *command, diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 3e298c0ab..b2f41342d 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -2111,6 +2111,10 @@ irc_server_create_buffer (struct t_irc_server *server, int all_servers) if (!server->buffer) return NULL; + weechat_buffer_set (server->buffer, "short_name", server->name); + weechat_buffer_set (server->buffer, "localvar_set_server", server->name); + weechat_buffer_set (server->buffer, "localvar_set_channel", server->name); + weechat_hook_signal_send ("logger_backlog", WEECHAT_HOOK_SIGNAL_POINTER, server->buffer); @@ -2192,9 +2196,6 @@ irc_server_connect (struct t_irc_server *server, int disable_autojoin) irc_buffer_servers = server->buffer; } - weechat_buffer_set (server->buffer, "short_name", server->name); - weechat_buffer_set (server->buffer, "localvar_set_server", server->name); - weechat_buffer_set (server->buffer, "display", "1"); weechat_bar_item_update ("buffer_name"); diff --git a/src/plugins/logger/logger-buffer.c b/src/plugins/logger/logger-buffer.c index 446d48133..bada5e47c 100644 --- a/src/plugins/logger/logger-buffer.c +++ b/src/plugins/logger/logger-buffer.c @@ -66,20 +66,29 @@ logger_buffer_valid (struct t_logger_buffer *logger_buffer) */ struct t_logger_buffer * -logger_buffer_add (struct t_gui_buffer *buffer, const char *log_filename) +logger_buffer_add (struct t_gui_buffer *buffer, int log_level) { struct t_logger_buffer *new_logger_buffer; - if (!buffer || !log_filename) + if (!buffer) return NULL; + if (logger_debug) + { + weechat_printf (NULL, + "%s: start logging for buffer \"%s\"", + LOGGER_PLUGIN_NAME, + weechat_buffer_get_string (buffer, "name")); + } + new_logger_buffer = malloc (sizeof (*new_logger_buffer)); if (new_logger_buffer) { new_logger_buffer->buffer = buffer; - new_logger_buffer->log_filename = strdup (log_filename); + new_logger_buffer->log_filename = NULL; new_logger_buffer->log_file = NULL; new_logger_buffer->log_enabled = 1; + new_logger_buffer->log_level = log_level; new_logger_buffer->prev_buffer = last_logger_buffer; new_logger_buffer->next_buffer = NULL; @@ -94,11 +103,11 @@ logger_buffer_add (struct t_gui_buffer *buffer, const char *log_filename) } /* - * logger_buffer_search: search a logger buffer by buffer pointer + * logger_buffer_search_buffer: search a logger buffer by buffer pointer */ struct t_logger_buffer * -logger_buffer_search (struct t_gui_buffer *buffer) +logger_buffer_search_buffer (struct t_gui_buffer *buffer) { struct t_logger_buffer *ptr_logger_buffer; @@ -114,6 +123,32 @@ logger_buffer_search (struct t_gui_buffer *buffer) } /* + * logger_buffer_search_log_filename: search a logger buffer by log filename + */ + +struct t_logger_buffer * +logger_buffer_search_log_filename (const char *log_filename) +{ + struct t_logger_buffer *ptr_logger_buffer; + + if (!log_filename) + return NULL; + + for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer; + ptr_logger_buffer = ptr_logger_buffer->next_buffer) + { + if (ptr_logger_buffer->log_filename) + { + if (strcmp (ptr_logger_buffer->log_filename, log_filename) == 0) + return ptr_logger_buffer; + } + } + + /* logger buffer not found */ + return NULL; +} + +/* * logger_buffer_free: remove a logger buffer from list */ @@ -122,6 +157,14 @@ logger_buffer_free (struct t_logger_buffer *logger_buffer) { struct t_logger_buffer *new_logger_buffers; + if (logger_debug) + { + weechat_printf (NULL, + "%s: stop logging for buffer \"%s\"", + LOGGER_PLUGIN_NAME, + weechat_buffer_get_string (logger_buffer->buffer, "name")); + } + /* remove logger buffer */ if (last_logger_buffer == logger_buffer) last_logger_buffer = logger_buffer->prev_buffer; @@ -182,6 +225,8 @@ logger_buffer_add_to_infolist (struct t_infolist *infolist, return 0; if (!weechat_infolist_new_var_integer (ptr_item, "log_enabled", logger_buffer->log_enabled)) return 0; + if (!weechat_infolist_new_var_integer (ptr_item, "log_level", logger_buffer->log_level)) + return 0; return 1; } diff --git a/src/plugins/logger/logger-buffer.h b/src/plugins/logger/logger-buffer.h index d2d464461..4cc715d38 100644 --- a/src/plugins/logger/logger-buffer.h +++ b/src/plugins/logger/logger-buffer.h @@ -28,6 +28,7 @@ struct t_logger_buffer char *log_filename; /* log filename */ FILE *log_file; /* log file */ int log_enabled; /* log enabled ? */ + int log_level; /* log level (0..9) */ struct t_logger_buffer *prev_buffer; /* link to previous buffer */ struct t_logger_buffer *next_buffer; /* link to next buffer */ }; @@ -37,8 +38,9 @@ extern struct t_logger_buffer *last_logger_buffer; extern int logger_buffer_valid (struct t_logger_buffer *logger_buffer); extern struct t_logger_buffer *logger_buffer_add (struct t_gui_buffer *, - const char *log_filename); -extern struct t_logger_buffer *logger_buffer_search (struct t_gui_buffer *buffer); + int log_level); +extern struct t_logger_buffer *logger_buffer_search_buffer (struct t_gui_buffer *buffer); +extern struct t_logger_buffer *logger_buffer_search_log_filename (const char *log_filename); extern void logger_buffer_free (struct t_logger_buffer *logger_buffer); extern void logger_buffer_free_all (); extern int logger_buffer_add_to_infolist (struct t_infolist *infolist, diff --git a/src/plugins/logger/logger-config.c b/src/plugins/logger/logger-config.c index 3569337c4..3183be4a5 100644 --- a/src/plugins/logger/logger-config.c +++ b/src/plugins/logger/logger-config.c @@ -28,6 +28,10 @@ struct t_config_file *logger_config_file = NULL; +struct t_config_section *logger_config_section_level = NULL; +struct t_config_section *logger_config_section_mask = NULL; + +int logger_config_loading = 0; /* logger config, look section */ @@ -38,11 +42,272 @@ struct t_config_option *logger_config_look_backlog; struct t_config_option *logger_config_file_auto_log; struct t_config_option *logger_config_file_name_lower_case; struct t_config_option *logger_config_file_path; +struct t_config_option *logger_config_file_mask; struct t_config_option *logger_config_file_info_lines; struct t_config_option *logger_config_file_time_format; /* + * logger_config_change_file_option_restart_log: called when a file option is + * changed and that logging must + * be restarted for all buffers + */ + +void +logger_config_change_file_option_restart_log (void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) data; + (void) option; + + if (!logger_config_loading) + { + logger_stop_all (); + logger_start_buffer_all (); + } +} + +/* + * logger_config_level_change: called when a level option is changed + */ + +void +logger_config_level_change (void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) data; + (void) option; + + if (!logger_config_loading) + logger_start_buffer_all (); +} + +/* + * logger_config_level_delete_option: delete option in "level" section + */ + +int +logger_config_level_delete_option (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) data; + (void) config_file; + (void) section; + + weechat_config_option_free (option); + + logger_start_buffer_all (); + + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; +} + +/* + * logger_config_level_create_option: create option in "level" section + */ + +int +logger_config_level_create_option (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, + const char *value) +{ + struct t_config_option *ptr_option; + int rc; + + /* make C compiler happy */ + (void) data; + + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; + + if (option_name) + { + ptr_option = weechat_config_search_option (config_file, section, + option_name); + if (ptr_option) + { + if (value && value[0]) + rc = weechat_config_option_set (ptr_option, value, 1); + else + { + weechat_config_option_free (ptr_option); + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + } + else + { + if (value && value[0]) + { + ptr_option = weechat_config_new_option ( + config_file, section, + option_name, "integer", + _("logging level for this buffer (0 = logging disabled, " + "1 = a few messages (most important) .. 9 = all messages)"), + NULL, 0, 9, "9", value, NULL, NULL, + &logger_config_level_change, NULL, + NULL, NULL); + rc = (ptr_option) ? + WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; + } + else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + } + + if (!logger_config_loading) + logger_start_buffer_all (); + + return rc; +} + +/* + * logger_config_get_level: get a level option + */ + +struct t_config_option * +logger_config_get_level (const char *name) +{ + return weechat_config_search_option (logger_config_file, + logger_config_section_level, + name); +} + +/* + * logger_config_set_level: set a level option + */ + +int +logger_config_set_level (const char *name, const char *value) +{ + return logger_config_level_create_option (NULL, + logger_config_file, + logger_config_section_level, + name, + value); +} + +/* + * logger_config_mask_change: called when a mask option is changed + */ + +void +logger_config_mask_change (void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) data; + (void) option; + + if (!logger_config_loading) + { + logger_stop_all (); + logger_start_buffer_all (); + } +} + +/* + * logger_config_mask_delete_option: delete option in "mask" section + */ + +int +logger_config_mask_delete_option (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) data; + (void) config_file; + (void) section; + + weechat_config_option_free (option); + + logger_stop_all (); + logger_start_buffer_all (); + + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; +} + +/* + * logger_config_mask_create_option: create option in "mask" section + */ + +int +logger_config_mask_create_option (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + const char *option_name, + const char *value) +{ + struct t_config_option *ptr_option; + int rc; + + /* make C compiler happy */ + (void) data; + + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; + + if (option_name) + { + ptr_option = weechat_config_search_option (config_file, section, + option_name); + if (ptr_option) + { + if (value && value[0]) + rc = weechat_config_option_set (ptr_option, value, 1); + else + { + weechat_config_option_free (ptr_option); + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + } + else + { + if (value && value[0]) + { + ptr_option = weechat_config_new_option ( + config_file, section, + option_name, "string", + _("file mask for log file; local buffer variables are " + "permitted"), + NULL, 0, 0, "", value, NULL, NULL, + &logger_config_mask_change, NULL, + NULL, NULL); + rc = (ptr_option) ? + WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; + } + else + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } + } + + if (!logger_config_loading) + { + logger_stop_all (); + logger_start_buffer_all (); + } + + return rc; +} + +/* + * logger_config_get_mask: get a mask option + */ + +struct t_config_option * +logger_config_get_mask (const char *name) +{ + return weechat_config_search_option (logger_config_file, + logger_config_section_mask, + name); +} + +/* * logger_config_init: init logger configuration file * return: 1 if ok, 0 if error */ @@ -61,7 +326,8 @@ logger_config_init () ptr_section = weechat_config_new_section (logger_config_file, "look", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (logger_config_file); @@ -79,7 +345,8 @@ logger_config_init () ptr_section = weechat_config_new_section (logger_config_file, "file", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (logger_config_file); @@ -96,13 +363,23 @@ logger_config_init () logger_config_file, ptr_section, "name_lower_case", "boolean", N_("use only lower case for log filenames"), - NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "on", NULL, NULL, NULL, + &logger_config_change_file_option_restart_log, NULL, NULL, NULL); logger_config_file_path = weechat_config_new_option ( logger_config_file, ptr_section, "path", "string", N_("path for WeeChat log files ('%h' will be replaced by WeeChat " "home, ~/.weechat by default)"), - NULL, 0, 0, "%h/logs/", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + NULL, 0, 0, "%h/logs/", NULL, NULL, NULL, + &logger_config_change_file_option_restart_log, NULL, NULL, NULL); + logger_config_file_mask = weechat_config_new_option ( + logger_config_file, ptr_section, + "mask", "string", + N_("default file name mask for log files (format is 'directory/to/file' " + "or 'file', without first '/' because 'path' option is used to " + "build complete path to file); local buffer variables are permitted"), + NULL, 0, 0, "$plugin.$name.weechatlog", NULL, NULL, NULL, + &logger_config_change_file_option_restart_log, NULL, NULL, NULL); logger_config_file_info_lines = weechat_config_new_option ( logger_config_file, ptr_section, "info_lines", "boolean", @@ -116,6 +393,36 @@ logger_config_init () "specifiers)"), NULL, 0, 0, "%Y-%m-%d %H:%M:%S", NULL, NULL, NULL, NULL, NULL, NULL, NULL); + /* level */ + ptr_section = weechat_config_new_section (logger_config_file, "level", + 1, 1, + NULL, NULL, NULL, NULL, + NULL, NULL, + &logger_config_level_create_option, NULL, + &logger_config_level_delete_option, NULL); + if (!ptr_section) + { + weechat_config_free (logger_config_file); + return 0; + } + + logger_config_section_level = ptr_section; + + /* mask */ + ptr_section = weechat_config_new_section (logger_config_file, "mask", + 1, 1, + NULL, NULL, NULL, NULL, + NULL, NULL, + &logger_config_mask_create_option, NULL, + &logger_config_mask_delete_option, NULL); + if (!ptr_section) + { + weechat_config_free (logger_config_file); + return 0; + } + + logger_config_section_mask = ptr_section; + return 1; } @@ -126,7 +433,13 @@ logger_config_init () int logger_config_read () { - return weechat_config_read (logger_config_file); + int rc; + + logger_config_loading = 1; + rc = weechat_config_read (logger_config_file); + logger_config_loading = 0; + + return rc; } /* diff --git a/src/plugins/logger/logger-config.h b/src/plugins/logger/logger-config.h index c2c1d6fa1..519542bd2 100644 --- a/src/plugins/logger/logger-config.h +++ b/src/plugins/logger/logger-config.h @@ -28,9 +28,13 @@ extern struct t_config_option *logger_config_look_backlog; extern struct t_config_option *logger_config_file_auto_log; extern struct t_config_option *logger_config_file_name_lower_case; extern struct t_config_option *logger_config_file_path; +extern struct t_config_option *logger_config_file_mask; extern struct t_config_option *logger_config_file_info_lines; extern struct t_config_option *logger_config_file_time_format; +extern struct t_config_option *logger_config_get_level (const char *name); +extern int logger_config_set_level (const char *name, const char *value); +extern struct t_config_option *logger_config_get_mask (const char *name); extern int logger_config_init (); extern int logger_config_read (); extern int logger_config_write (); diff --git a/src/plugins/logger/logger-tail.c b/src/plugins/logger/logger-tail.c index e129d2a75..2023252b3 100644 --- a/src/plugins/logger/logger-tail.c +++ b/src/plugins/logger/logger-tail.c @@ -30,6 +30,7 @@ #include <fcntl.h> #include <string.h> +#include "../weechat-plugin.h" #include "logger.h" #include "logger-tail.h" @@ -108,7 +109,7 @@ logger_tail_file (const char *filename, int n_lines) while (ptr_buf && (ptr_buf >= buf)) { pos_eol = logger_tail_last_eol (buf, ptr_buf); - if ((pos_eol && pos_eol[1]) || (!pos_eol && (file_pos == 0))) + if ((pos_eol && (pos_eol[1] || part_of_line)) || (file_pos == 0)) { /* use data and part_of_line (if existing) to build a new line */ if (!pos_eol) @@ -209,14 +210,20 @@ logger_tail_file (const char *filename, int n_lines) void logger_tail_free (struct t_logger_line *lines) { + struct t_logger_line *ptr_line, *next_line; + if (!lines) return; - - while (lines->next_line) + + ptr_line = lines; + while (ptr_line) { - if (lines->data) - free (lines->data); - lines = lines->next_line; + next_line = ptr_line->next_line; + + if (ptr_line->data) + free (ptr_line->data); + free (ptr_line); + + ptr_line = next_line; } - free (lines); } diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index 9d3bbf597..fbf947fb4 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <stdarg.h> #include <string.h> +#include <ctype.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -51,10 +52,45 @@ WEECHAT_PLUGIN_LICENSE("GPL3"); struct t_weechat_plugin *weechat_logger_plugin = NULL; +int logger_debug = 0; + char *logger_buf_write = NULL; /* buffer for writing a line */ /* + * logger_debug_cb: callback for "debug" signal + */ + +int +logger_debug_cb (void *data, const char *signal, const char *type_data, + void *signal_data) +{ + /* make C compiler happy */ + (void) data; + (void) signal; + + if (strcmp (type_data, WEECHAT_HOOK_SIGNAL_STRING) == 0) + { + if (weechat_strcasecmp ((char *)signal_data, LOGGER_PLUGIN_NAME) == 0) + { + logger_debug ^= 1; + if (logger_debug) + { + weechat_printf (NULL, _("%s: debug enabled"), + LOGGER_PLUGIN_NAME); + } + else + { + weechat_printf (NULL, _("%s: debug disabled"), + LOGGER_PLUGIN_NAME); + } + } + } + + return WEECHAT_RC_OK; +} + +/* * logger_create_directory: create logger directory * return 1 if success (directory created or already * exists), 0 if failed @@ -78,13 +114,9 @@ logger_create_directory () dir2 = weechat_string_replace (dir1, "%h", weechat_dir); if (dir2) { - if (mkdir (dir2, 0755) < 0) - { - if (errno != EEXIST) - rc = 0; - } - else - chmod (dir2, 0700); + if (!weechat_mkdir_parents (dir2, 0700)) + rc = 0; + free (dir2); } else @@ -101,20 +133,179 @@ logger_create_directory () } /* + * logger_build_option_name: build option name with a buffer + */ + +char * +logger_build_option_name (struct t_gui_buffer *buffer) +{ + char *plugin_name, *name, *option_name; + int length; + + if (!buffer) + return NULL; + + plugin_name = weechat_buffer_get_string (buffer, "plugin"); + name = weechat_buffer_get_string (buffer, "name"); + + length = strlen (plugin_name) + 1 + strlen (name) + 1; + option_name = malloc (length); + if (!option_name) + return NULL; + + snprintf (option_name, length, "%s.%s", plugin_name, name); + + return option_name; +} + +/* + * logger_get_level_for_buffer: get logging level for buffer (0 = disabled, 1..9) + */ + +int +logger_get_level_for_buffer (struct t_gui_buffer *buffer) +{ + char *name, *option_name, *ptr_end; + struct t_config_option *ptr_option; + + name = logger_build_option_name (buffer); + if (!name) + return LOGGER_LEVEL_DEFAULT; + + option_name = strdup (name); + if (option_name) + { + ptr_end = option_name + strlen (option_name); + while (ptr_end >= option_name) + { + ptr_option = logger_config_get_level (option_name); + if (ptr_option) + { + free (option_name); + free (name); + return weechat_config_integer (ptr_option); + } + ptr_end--; + while ((ptr_end >= option_name) && (ptr_end[0] != '.')) + { + ptr_end--; + } + if ((ptr_end >= option_name) && (ptr_end[0] == '.')) + ptr_end[0] = '\0'; + } + ptr_option = logger_config_get_level (option_name); + + free (option_name); + free (name); + + if (ptr_option) + return weechat_config_integer (ptr_option); + } + else + free (name); + + /* nothing found => return default level */ + return LOGGER_LEVEL_DEFAULT; +} + +/* + * logger_get_mask_for_buffer: get filename mask for a buffer + * we first try with all arguments, then remove one by + * one to find mask (from specific to general mask) + */ + +char * +logger_get_mask_for_buffer (struct t_gui_buffer *buffer) +{ + char *name, *option_name, *ptr_end; + struct t_config_option *ptr_option; + + name = logger_build_option_name (buffer); + if (!name) + return NULL; + + option_name = strdup (name); + if (option_name) + { + ptr_end = option_name + strlen (option_name); + while (ptr_end >= option_name) + { + ptr_option = logger_config_get_mask (option_name); + if (ptr_option) + { + free (option_name); + free (name); + return weechat_config_string (ptr_option); + } + ptr_end--; + while ((ptr_end >= option_name) && (ptr_end[0] != '.')) + { + ptr_end--; + } + if ((ptr_end >= option_name) && (ptr_end[0] == '.')) + ptr_end[0] = '\0'; + } + ptr_option = logger_config_get_mask (option_name); + + free (option_name); + free (name); + + if (ptr_option) + return weechat_config_string (ptr_option); + } + else + free (name); + + /* nothing found => return default mask (if set) */ + if (weechat_config_string (logger_config_file_mask) + && weechat_config_string (logger_config_file_mask)[0]) + return weechat_config_string (logger_config_file_mask); + + /* no default mask set */ + return NULL; +} + +/* * logger_get_filename: build log filename for a buffer */ char * logger_get_filename (struct t_gui_buffer *buffer) { - struct t_infolist *ptr_infolist; - char *res; - char *dir_separator, *weechat_dir, *log_path, *log_path2; - char *plugin_name, *plugin_name2, *name, *name2; + char *res, *mask, *mask_decoded, *dir_separator, *weechat_dir; + char *log_path, *log_path2, *pos_last_sep; int length; res = NULL; + /* get filename mask for buffer */ + mask = logger_get_mask_for_buffer (buffer); + if (!mask) + { + weechat_printf (NULL, + _("%s%s: unable to find filename mask for buffer " + "\"%s\", logging is disabled for this buffer"), + weechat_prefix ("error"), LOGGER_PLUGIN_NAME, + weechat_buffer_get_string (buffer, "name")); + return NULL; + } + mask_decoded = weechat_buffer_string_replace_local_var (buffer, mask); + if (!mask_decoded) + return NULL; + + if (logger_debug) + { + weechat_printf (NULL, + "%s: buffer = \"%s\", mask = \"%s\", " + "decoded mask = \"%s\"", + LOGGER_PLUGIN_NAME, + weechat_buffer_get_string (buffer, "name"), + mask, mask_decoded); + } + + if (weechat_config_boolean (logger_config_file_name_lower_case)) + weechat_string_tolower (mask_decoded); + dir_separator = weechat_info_get ("dir_separator", ""); weechat_dir = weechat_info_get ("weechat_dir", ""); log_path = weechat_string_replace (weechat_config_string (logger_config_file_path), @@ -123,49 +314,17 @@ logger_get_filename (struct t_gui_buffer *buffer) if (dir_separator && weechat_dir && log_path && log_path2) { - ptr_infolist = weechat_infolist_get ("buffer", buffer, NULL); - if (ptr_infolist) + length = strlen (log_path2) + strlen (mask_decoded) + 1; + res = malloc (length); + if (res) { - plugin_name2 = NULL; - name2 = NULL; - if (weechat_infolist_next (ptr_infolist)) - { - plugin_name = weechat_infolist_string (ptr_infolist, "plugin_name"); - plugin_name2 = (plugin_name) ? - weechat_string_replace (plugin_name, dir_separator, "_") : NULL; - name = weechat_infolist_string (ptr_infolist, "name"); - name2 = (name) ? - weechat_string_replace (name, dir_separator, "_") : NULL; - } - length = strlen (log_path2); - if (plugin_name2) - length += strlen (plugin_name2) + 1; - if (name2) - length += strlen (name2) + 1; - length += 16; - res = malloc (length); - if (res) - { - strcpy (res, log_path2); - if (plugin_name2) - { - if (weechat_config_boolean (logger_config_file_name_lower_case)) - weechat_string_tolower (plugin_name2); - strcat (res, plugin_name2); - strcat (res, "."); - } - if (name2) - { - if (weechat_config_boolean (logger_config_file_name_lower_case)) - weechat_string_tolower (name2); - strcat (res, name2); - strcat (res, "."); - } - strcat (res, "weechatlog"); - } - if (name2) - free (name2); - weechat_infolist_free (ptr_infolist); + snprintf (res, length, "%s%s", log_path2, mask_decoded); + pos_last_sep = strrchr (res, dir_separator[0]); + if (pos_last_sep) + pos_last_sep[0] = '\0'; + weechat_mkdir_parents (res, 0700); + if (pos_last_sep) + pos_last_sep[0] = dir_separator[0]; } } @@ -178,6 +337,44 @@ logger_get_filename (struct t_gui_buffer *buffer) } /* + * logger_set_log_filename: set log filename for a logger buffer + */ + +void +logger_set_log_filename (struct t_logger_buffer *logger_buffer) +{ + char *log_filename; + struct t_logger_buffer *ptr_logger_buffer; + + log_filename = logger_get_filename (logger_buffer->buffer); + if (!log_filename) + { + weechat_printf (NULL, + _("%s%s: not enough memory"), + weechat_prefix ("error"), + LOGGER_PLUGIN_NAME); + return; + } + + ptr_logger_buffer = logger_buffer_search_log_filename (log_filename); + if (ptr_logger_buffer) + { + weechat_printf (NULL, + _("%s%s: unable to start logging for buffer " + "\"%s\": filename \"%s\" is already user by " + "another buffer (check your log settings)"), + weechat_prefix ("error"), + LOGGER_PLUGIN_NAME, + weechat_buffer_get_string (logger_buffer->buffer, "name"), + log_filename); + free (log_filename); + return; + } + + logger_buffer->log_filename = log_filename; +} + +/* * logger_write_line: write a line to log file */ @@ -190,75 +387,130 @@ logger_write_line (struct t_logger_buffer *logger_buffer, time_t seconds; struct tm *date_tmp; char buf_time[256]; - + if (!logger_buf_write) logger_buf_write = malloc (LOGGER_BUF_WRITE_SIZE); if (!logger_buf_write) return; - if (logger_buffer->log_filename) + charset = weechat_info_get ("charset_terminal", ""); + + if (!logger_buffer->log_file) { - charset = weechat_info_get ("charset_terminal", ""); + if (!logger_create_directory ()) + { + weechat_printf (NULL, + _("%s%s: unable to create directory for logs " + "(\"%s\")"), + weechat_prefix ("error"), LOGGER_PLUGIN_NAME, + weechat_config_string (logger_config_file_path)); + logger_buffer_free (logger_buffer); + return; + } + if (!logger_buffer->log_filename) + logger_set_log_filename (logger_buffer); - if (!logger_buffer->log_file) + if (!logger_buffer->log_filename) { - if (!logger_create_directory ()) - { - weechat_printf (NULL, - _("%s%s: unable to create directory for logs " - "(\"%s\")"), - weechat_prefix ("error"), LOGGER_PLUGIN_NAME, - weechat_config_string (logger_config_file_path)); - free (logger_buffer->log_filename); - logger_buffer->log_filename = NULL; - return; - } - logger_buffer->log_file = - fopen (logger_buffer->log_filename, "a"); - if (!logger_buffer->log_file) - { - weechat_printf (NULL, - _("%s%s: unable to write log file \"%s\""), - weechat_prefix ("error"), LOGGER_PLUGIN_NAME, - logger_buffer->log_filename); - free (logger_buffer->log_filename); - logger_buffer->log_filename = NULL; - return; - } - - if (weechat_config_boolean (logger_config_file_info_lines)) - { - seconds = time (NULL); - date_tmp = localtime (&seconds); - buf_time[0] = '\0'; - if (date_tmp) - strftime (buf_time, sizeof (buf_time) - 1, - weechat_config_string (logger_config_file_time_format), - date_tmp); - snprintf (logger_buf_write, LOGGER_BUF_WRITE_SIZE, - _("%s\t**** Beginning of log ****"), - buf_time); - message = (charset) ? - weechat_iconv_from_internal (charset, logger_buf_write) : NULL; - fprintf (logger_buffer->log_file, - "%s\n", (message) ? message : logger_buf_write); - if (message) - free (message); - } + logger_buffer_free (logger_buffer); + return; } - - va_start (argptr, format); - vsnprintf (logger_buf_write, LOGGER_BUF_WRITE_SIZE, format, argptr); - va_end (argptr); - message = (charset) ? - weechat_iconv_from_internal (charset, logger_buf_write) : NULL; + logger_buffer->log_file = + fopen (logger_buffer->log_filename, "a"); + if (!logger_buffer->log_file) + { + weechat_printf (NULL, + _("%s%s: unable to write log file \"%s\""), + weechat_prefix ("error"), LOGGER_PLUGIN_NAME, + logger_buffer->log_filename); + logger_buffer_free (logger_buffer); + return; + } - fprintf (logger_buffer->log_file, - "%s\n", (message) ? message : logger_buf_write); - fflush (logger_buffer->log_file); - if (message) - free (message); + if (weechat_config_boolean (logger_config_file_info_lines)) + { + seconds = time (NULL); + date_tmp = localtime (&seconds); + buf_time[0] = '\0'; + if (date_tmp) + strftime (buf_time, sizeof (buf_time) - 1, + weechat_config_string (logger_config_file_time_format), + date_tmp); + snprintf (logger_buf_write, LOGGER_BUF_WRITE_SIZE, + _("%s\t**** Beginning of log ****"), + buf_time); + message = (charset) ? + weechat_iconv_from_internal (charset, logger_buf_write) : NULL; + fprintf (logger_buffer->log_file, + "%s\n", (message) ? message : logger_buf_write); + if (message) + free (message); + } + } + + va_start (argptr, format); + vsnprintf (logger_buf_write, LOGGER_BUF_WRITE_SIZE, format, argptr); + va_end (argptr); + + message = (charset) ? + weechat_iconv_from_internal (charset, logger_buf_write) : NULL; + + fprintf (logger_buffer->log_file, + "%s\n", (message) ? message : logger_buf_write); + fflush (logger_buffer->log_file); + if (message) + free (message); +} + +/* + * logger_stop: stop log for a logger buffer + */ + +void +logger_stop (struct t_logger_buffer *logger_buffer, int write_info_line) +{ + time_t seconds; + struct tm *date_tmp; + char buf_time[256]; + + if (!logger_buffer) + return; + + if (logger_buffer->log_enabled && logger_buffer->log_file) + { + if (write_info_line && weechat_config_boolean (logger_config_file_info_lines)) + { + seconds = time (NULL); + date_tmp = localtime (&seconds); + buf_time[0] = '\0'; + if (date_tmp) + strftime (buf_time, sizeof (buf_time) - 1, + weechat_config_string (logger_config_file_time_format), + date_tmp); + logger_write_line (logger_buffer, + _("%s\t**** End of log ****"), + buf_time); + } + fclose (logger_buffer->log_file); + logger_buffer->log_file = NULL; + } + logger_buffer_free (logger_buffer); +} + +/* + * logger_stop_all: end log for all buffers + */ + +void +logger_stop_all () +{ + struct t_logger_buffer *ptr_logger_buffer; + + for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer; + ptr_logger_buffer = ptr_logger_buffer->next_buffer) + { + logger_stop (ptr_logger_buffer, 1); } } @@ -270,28 +522,43 @@ void logger_start_buffer (struct t_gui_buffer *buffer) { struct t_logger_buffer *ptr_logger_buffer; - char *log_filename; + int log_level, log_enabled; - if (!buffer || !weechat_config_boolean (logger_config_file_auto_log)) + if (!buffer) return; - ptr_logger_buffer = logger_buffer_search (buffer); - if (!ptr_logger_buffer) + log_level = logger_get_level_for_buffer (buffer); + log_enabled = weechat_config_boolean (logger_config_file_auto_log) + && (log_level > 0); + + ptr_logger_buffer = logger_buffer_search_buffer (buffer); + + /* logging is disabled for buffer */ + if (!log_enabled) { - log_filename = logger_get_filename (buffer); - if (!log_filename) - return; - ptr_logger_buffer = logger_buffer_add (buffer, log_filename); - free (log_filename); + /* stop logger if it is active */ + if (ptr_logger_buffer) + logger_stop (ptr_logger_buffer, 1); } - if (ptr_logger_buffer) + else { - if (ptr_logger_buffer->log_filename) + /* logging is enabled for buffer */ + if (ptr_logger_buffer) + ptr_logger_buffer->log_level = log_level; + else { - if (ptr_logger_buffer->log_file) + ptr_logger_buffer = logger_buffer_add (buffer, log_level); + + if (ptr_logger_buffer) { - fclose (ptr_logger_buffer->log_file); - ptr_logger_buffer->log_file = NULL; + if (ptr_logger_buffer->log_filename) + { + if (ptr_logger_buffer->log_file) + { + fclose (ptr_logger_buffer->log_file); + ptr_logger_buffer->log_file = NULL; + } + } } } } @@ -319,54 +586,125 @@ logger_start_buffer_all () } /* - * logger_stop: stop log for a logger buffer + * logger_list: show logging status for buffers */ void -logger_stop (struct t_logger_buffer *logger_buffer, int write_info_line) +logger_list () { - time_t seconds; - struct tm *date_tmp; - char buf_time[256]; + struct t_infolist *ptr_infolist; + struct t_logger_buffer *ptr_logger_buffer; + struct t_gui_buffer *ptr_buffer; + char status[128]; - if (!logger_buffer) - return; + weechat_printf (NULL, ""); + weechat_printf (NULL, _("Logging on buffers:")); - if (logger_buffer->log_file) + ptr_infolist = weechat_infolist_get ("buffer", NULL, NULL); + if (ptr_infolist) { - if (write_info_line && weechat_config_boolean (logger_config_file_info_lines)) + while (weechat_infolist_next (ptr_infolist)) { - seconds = time (NULL); - date_tmp = localtime (&seconds); - buf_time[0] = '\0'; - if (date_tmp) - strftime (buf_time, sizeof (buf_time) - 1, - weechat_config_string (logger_config_file_time_format), - date_tmp); - logger_write_line (logger_buffer, - _("%s\t**** End of log ****"), - buf_time); + ptr_buffer = weechat_infolist_pointer (ptr_infolist, "pointer"); + if (ptr_buffer) + { + ptr_logger_buffer = logger_buffer_search_buffer (ptr_buffer); + if (ptr_logger_buffer) + { + snprintf (status, sizeof (status), + _("logging (level: %d)"), + ptr_logger_buffer->log_level); + } + else + { + snprintf (status, sizeof (status), _("not logging")); + } + weechat_printf (NULL, + " %s[%s%d%s]%s (%s) %s%s%s: %s%s%s%s", + weechat_color("chat_delimiters"), + weechat_color("chat"), + weechat_infolist_integer (ptr_infolist, "number"), + weechat_color("chat_delimiters"), + weechat_color("chat"), + weechat_infolist_string (ptr_infolist, "plugin_name"), + weechat_color("chat_buffer"), + weechat_infolist_string (ptr_infolist, "name"), + weechat_color("chat"), + status, + (ptr_logger_buffer) ? " (" : "", + (ptr_logger_buffer) ? + ((ptr_logger_buffer->log_filename) ? + ptr_logger_buffer->log_filename : _("log not started")) : "", + (ptr_logger_buffer) ? ")" : ""); + } } - fclose (logger_buffer->log_file); - logger_buffer->log_file = NULL; + weechat_infolist_free (ptr_infolist); } - logger_buffer_free (logger_buffer); } /* - * logger_stop_all: end log for all buffers + * logger_set_buffer: enable/disable log on a buffer */ void -logger_stop_all () +logger_set_buffer (struct t_gui_buffer *buffer, const char *value) { - struct t_logger_buffer *ptr_logger_buffer; + char *name; + struct t_config_option *ptr_option; - for (ptr_logger_buffer = logger_buffers; ptr_logger_buffer; - ptr_logger_buffer = ptr_logger_buffer->next_buffer) + name = logger_build_option_name (buffer); + if (!name) + return; + + if (logger_config_set_level (name, value) != WEECHAT_CONFIG_OPTION_SET_ERROR) { - logger_stop (ptr_logger_buffer, 1); + ptr_option = logger_config_get_level (name); + if (ptr_option) + { + weechat_printf (NULL, _("%s: \"%s\" => level %d"), + LOGGER_PLUGIN_NAME, name, + weechat_config_integer (ptr_option)); + } + } + + free (name); +} + +/* + * logger_command_cb: callback for /logger command + */ + +int +logger_command_cb (void *data, struct t_gui_buffer *buffer, + int argc, char **argv, char **argv_eol) +{ + /* make C compiler happy */ + (void) data; + (void) argv_eol; + + if ((argc == 1) + || ((argc == 2) && (weechat_strcasecmp (argv[1], "list") == 0))) + { + logger_list (); + return WEECHAT_RC_OK; } + + if (argc > 1) + { + if (weechat_strcasecmp (argv[1], "set") == 0) + { + if (argc > 2) + logger_set_buffer (buffer, argv[2]); + return WEECHAT_RC_OK; + } + + if (weechat_strcasecmp (argv[1], "disable") == 0) + { + logger_set_buffer (buffer, "0"); + } + } + + return WEECHAT_RC_OK; } /* @@ -400,7 +738,7 @@ logger_buffer_closing_signal_cb (void *data, const char *signal, (void) signal; (void) type_data; - logger_stop (logger_buffer_search (signal_data), 1); + logger_stop (logger_buffer_search_buffer (signal_data), 1); return WEECHAT_RC_OK; } @@ -452,9 +790,12 @@ logger_backlog (struct t_gui_buffer *buffer, const char *filename, int lines) if (last_lines) logger_tail_free (last_lines); if (num_lines > 0) + { weechat_printf (buffer, _("===\t========== End of backlog (%d lines) =========="), num_lines); + weechat_buffer_set (buffer, "unread", ""); + } } /* @@ -474,17 +815,22 @@ logger_backlog_signal_cb (void *data, const char *signal, if (weechat_config_integer (logger_config_look_backlog) >= 0) { - ptr_logger_buffer = logger_buffer_search (signal_data); - if (ptr_logger_buffer && ptr_logger_buffer->log_filename - && ptr_logger_buffer->log_enabled) + ptr_logger_buffer = logger_buffer_search_buffer (signal_data); + if (ptr_logger_buffer && ptr_logger_buffer->log_enabled) { - ptr_logger_buffer->log_enabled = 0; + if (!ptr_logger_buffer->log_filename) + logger_set_log_filename (ptr_logger_buffer); - logger_backlog (signal_data, - ptr_logger_buffer->log_filename, - weechat_config_integer (logger_config_look_backlog)); - - ptr_logger_buffer->log_enabled = 1; + if (ptr_logger_buffer->log_filename) + { + ptr_logger_buffer->log_enabled = 0; + + logger_backlog (signal_data, + ptr_logger_buffer->log_filename, + weechat_config_integer (logger_config_look_backlog)); + + ptr_logger_buffer->log_enabled = 1; + } } } @@ -524,7 +870,7 @@ logger_stop_signal_cb (void *data, const char *signal, const char *type_data, (void) signal; (void) type_data; - ptr_logger_buffer = logger_buffer_search (signal_data); + ptr_logger_buffer = logger_buffer_search_buffer (signal_data); if (ptr_logger_buffer) logger_stop (ptr_logger_buffer, 0); @@ -532,27 +878,52 @@ logger_stop_signal_cb (void *data, const char *signal, const char *type_data, } /* + * logger_line_log_level: get log level for a line (with its tags) + */ + +int +logger_line_log_level (int tags_count, const char **tags) +{ + int i; + + for (i = 0; i < tags_count; i++) + { + if (strncmp (tags[i], "log", 3) == 0) + { + if (isdigit (tags[i][3])) + { + return (tags[i][3] - '0'); + } + } + } + + return 9; +} + +/* * logger_print_cb: callback for print hook */ int logger_print_cb (void *data, struct t_gui_buffer *buffer, time_t date, - int tags_count, char **tags, + int tags_count, const char **tags, const char *prefix, const char *message) { struct t_logger_buffer *ptr_logger_buffer; struct tm *date_tmp; char buf_time[256]; + int line_log_level; /* make C compiler happy */ (void) data; - (void) tags_count; - (void) tags; - ptr_logger_buffer = logger_buffer_search (buffer); - if (ptr_logger_buffer && ptr_logger_buffer->log_filename + line_log_level = logger_line_log_level (tags_count, tags); + + ptr_logger_buffer = logger_buffer_search_buffer (buffer); + if (ptr_logger_buffer && ptr_logger_buffer->log_enabled - && (date > 0)) + && (date > 0) + && (line_log_level <= ptr_logger_buffer->log_level)) { date_tmp = localtime (&date); buf_time[0] = '\0'; @@ -592,6 +963,43 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) if (logger_config_read () < 0) return WEECHAT_RC_ERROR; + /* callback for debug */ + weechat_hook_signal ("debug", &logger_debug_cb, NULL); + + /* command /logger */ + weechat_hook_command ("logger", + N_("logger plugin configuration"), + N_("[list | set level | disable]"), + N_(" list: show logging status for open buffers\n" + " set: set logging level on current buffer\n" + " level: level for messages to be logged (0 = " + "logging disabled, 1 = a few messages (most " + "important) .. 9 = all messages)\n" + "disable: disable logging on current buffer (set " + "level to 0)\n\n" + "Options \"logger.level.*\" and \"logger.mask.*\" " + "can be used to set level or mask for a buffer, " + "or buffers beginning with name.\n\n" + "Examples:\n" + " set level to 5 for current buffer:\n" + " /logger set 5\n" + " disable logging for current buffer:\n" + " /logger disable\n\n" + " set level to 3 for all IRC buffers:\n" + " /set logger.level.irc = 3\n" + " disable logging for main WeeChat buffer:\n" + " /set logger.level.core.weechat = 0\n" + " use a directory per IRC server and a file per channel inside:\n" + " /set logger.mask.irc = $server/$channel.weechatlog\n\n" + "Log levels used by IRC plugin:\n" + " 1: user message, notice, private\n" + " 2: nick change\n" + " 3: server message\n" + " 4: join/part/quit\n" + " 9: all other messages"), + "list|set|disable", + &logger_command_cb, NULL); + logger_start_buffer_all (); weechat_hook_signal ("buffer_open", &logger_buffer_open_signal_cb, NULL); diff --git a/src/plugins/logger/logger.h b/src/plugins/logger/logger.h index a999322f0..e623a371a 100644 --- a/src/plugins/logger/logger.h +++ b/src/plugins/logger/logger.h @@ -24,6 +24,9 @@ #define LOGGER_PLUGIN_NAME "logger" #define LOGGER_BUF_WRITE_SIZE (16*1024) +#define LOGGER_LEVEL_DEFAULT 9 + +extern int logger_debug; extern struct t_weechat_plugin *weechat_logger_plugin; diff --git a/src/plugins/notify/notify.c b/src/plugins/notify/notify.c index 9c79d07d9..2855902c0 100644 --- a/src/plugins/notify/notify.c +++ b/src/plugins/notify/notify.c @@ -331,7 +331,8 @@ notify_config_init () NULL, NULL, NULL, NULL, NULL, NULL, - ¬ify_config_create_option, NULL); + ¬ify_config_create_option, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (notify_config_file); @@ -404,10 +405,11 @@ notify_set (struct t_gui_buffer *buffer, const char *name, int value) /* display message */ if (value >= 0) - weechat_printf (NULL, _("Notify level: %s => %s"), - name, notify_string[value]); + weechat_printf (NULL, "%s: \"%s\" => %s", + NOTIFY_PLUGIN_NAME, name, notify_string[value]); else - weechat_printf (NULL, _("Notify level: %s: removed"), name); + weechat_printf (NULL, _("%s: \"%s\" removed"), + NOTIFY_PLUGIN_NAME, name); } } diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 36f989b63..4844052b2 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -87,61 +87,6 @@ plugin_api_ngettext (const char *single, const char *plural, int count) } /* - * plugin_api_mkdir_home: create a directory in WeeChat home - * return 1 if ok, 0 if error - */ - -int -plugin_api_mkdir_home (const char *directory, int mode) -{ - char *dir_name; - int dir_length; - - if (!directory) - return 0; - - /* build directory, adding WeeChat home */ - dir_length = strlen (weechat_home) + strlen (directory) + 2; - dir_name = malloc (dir_length); - if (!dir_name) - return 0; - - snprintf (dir_name, dir_length, "%s/%s", weechat_home, directory); - - if (mkdir (dir_name, mode) < 0) - { - if (errno != EEXIST) - { - free (dir_name); - return 0; - } - } - - free (dir_name); - return 1; -} - -/* - * plugin_api_mkdir: create a directory - * return 1 if ok, 0 if error - */ - -int -plugin_api_mkdir (const char *directory, int mode) -{ - if (!directory) - return 0; - - if (mkdir (directory, mode) < 0) - { - if (errno != EEXIST) - return 0; - } - - return 1; -} - -/* * plugin_api_config_get: get value of an option */ diff --git a/src/plugins/plugin-api.h b/src/plugins/plugin-api.h index 21f23a54a..3bd0bb23b 100644 --- a/src/plugins/plugin-api.h +++ b/src/plugins/plugin-api.h @@ -27,10 +27,6 @@ extern char *plugin_api_gettext (const char *string); extern char *plugin_api_ngettext (const char *single, const char *plural, int count); -/* directories */ -extern int plugin_api_mkdir_home (const char *directory, int mode); -extern int plugin_api_mkdir (const char *directory, int mode); - /* config */ extern struct t_config_option *plugin_api_config_get (const char *option_name); extern char *plugin_api_config_get_plugin (struct t_weechat_plugin *plugin, diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c index 57eb8b999..bc0aa97ea 100644 --- a/src/plugins/plugin-config.c +++ b/src/plugins/plugin-config.c @@ -186,7 +186,8 @@ plugin_config_init () NULL, NULL, NULL, NULL, NULL, NULL, - &plugin_config_create_option, NULL); + &plugin_config_create_option, NULL, + NULL, NULL); } else plugin_config_section_var = NULL; diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 81ef8375c..e4a34cd82 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -332,8 +332,9 @@ plugin_load (const char *filename) new_plugin->utf8_real_pos = &utf8_real_pos; new_plugin->utf8_pos = &utf8_pos; - new_plugin->mkdir_home = &plugin_api_mkdir_home; - new_plugin->mkdir = &plugin_api_mkdir; + new_plugin->mkdir_home = &util_mkdir_home; + new_plugin->mkdir = &util_mkdir; + new_plugin->mkdir_parents = &util_mkdir_parents; new_plugin->exec_on_files = &util_exec_on_files; new_plugin->timeval_cmp = &util_timeval_cmp; diff --git a/src/plugins/scripts/lua/weechat-lua-api.c b/src/plugins/scripts/lua/weechat-lua-api.c index 081a2e083..1c5767727 100644 --- a/src/plugins/scripts/lua/weechat-lua-api.c +++ b/src/plugins/scripts/lua/weechat-lua-api.c @@ -443,6 +443,46 @@ weechat_lua_api_mkdir (lua_State *L) } /* + * weechat_lua_api_mkdir_parents: create a directory and make parent + * directories as needed + */ + +static int +weechat_lua_api_mkdir_parents (lua_State *L) +{ + const char *directory; + int mode, n; + + /* make C compiler happy */ + (void) L; + + if (!lua_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir_parents"); + LUA_RETURN_ERROR; + } + + directory = NULL; + mode = 0; + + n = lua_gettop (lua_current_interpreter); + + if (n < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_parents"); + LUA_RETURN_ERROR; + } + + directory = lua_tostring (lua_current_interpreter, -2); + mode = lua_tonumber (lua_current_interpreter, -1); + + if (weechat_mkdir_parents (directory, mode)) + LUA_RETURN_OK; + + LUA_RETURN_OK; +} + +/* * weechat_lua_api_list_new: create a new list */ @@ -1158,6 +1198,54 @@ weechat_lua_api_config_section_create_option_cb (void *data, } /* + * weechat_lua_api_config_section_delete_option_cb: callback to delete an option + */ + +int +weechat_lua_api_config_section_delete_option_cb (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *lua_argv[4]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + lua_argv[0] = script_ptr2str (config_file); + lua_argv[1] = script_ptr2str (section); + lua_argv[2] = script_ptr2str (option); + lua_argv[3] = NULL; + + rc = (int *) weechat_lua_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + lua_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (lua_argv[0]) + free (lua_argv[0]); + if (lua_argv[1]) + free (lua_argv[1]); + if (lua_argv[2]) + free (lua_argv[2]); + + return ret; + } + + return 0; +} + +/* * weechat_lua_api_config_new_section: create a new section in configuration file */ @@ -1166,6 +1254,7 @@ weechat_lua_api_config_new_section (lua_State *L) { const char *config_file, *name, *function_read, *function_write; const char *function_write_default, *function_create_option; + const char *function_delete_option; char *result; int n, user_can_add_options, user_can_delete_options; @@ -1186,23 +1275,25 @@ weechat_lua_api_config_new_section (lua_State *L) function_write = NULL; function_write_default = NULL; function_create_option = NULL; + function_delete_option = NULL; n = lua_gettop (lua_current_interpreter); - if (n < 8) + if (n < 9) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section"); LUA_RETURN_EMPTY; } - config_file = lua_tostring (lua_current_interpreter, -8); - name = lua_tostring (lua_current_interpreter, -7); - user_can_add_options = lua_tonumber (lua_current_interpreter, -6); - user_can_delete_options = lua_tonumber (lua_current_interpreter, -5); - function_read = lua_tostring (lua_current_interpreter, -4); - function_write = lua_tostring (lua_current_interpreter, -3); - function_write_default = lua_tostring (lua_current_interpreter, -2); - function_create_option = lua_tostring (lua_current_interpreter, -1); + config_file = lua_tostring (lua_current_interpreter, -9); + name = lua_tostring (lua_current_interpreter, -8); + user_can_add_options = lua_tonumber (lua_current_interpreter, -7); + user_can_delete_options = lua_tonumber (lua_current_interpreter, -6); + function_read = lua_tostring (lua_current_interpreter, -5); + function_write = lua_tostring (lua_current_interpreter, -4); + function_write_default = lua_tostring (lua_current_interpreter, -3); + function_create_option = lua_tostring (lua_current_interpreter, -2); + function_delete_option = lua_tostring (lua_current_interpreter, -1); result = script_ptr2str (script_api_config_new_section (weechat_lua_plugin, lua_current_script, @@ -1217,7 +1308,9 @@ weechat_lua_api_config_new_section (lua_State *L) &weechat_lua_api_config_section_write_default_cb, function_write_default, &weechat_lua_api_config_section_create_option_cb, - function_create_option)); + function_create_option, + &weechat_lua_api_config_section_delete_option_cb, + function_delete_option)); LUA_RETURN_STRING_FREE(result); } @@ -2722,7 +2815,8 @@ weechat_lua_api_hook_connect (lua_State *L) int weechat_lua_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, int tags_count, char **tags, + time_t date, + int tags_count, const char **tags, const char *prefix, const char *message) { struct t_script_callback *script_callback; @@ -5603,6 +5697,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = { { "ngettext", &weechat_lua_api_ngettext }, { "mkdir_home", &weechat_lua_api_mkdir_home }, { "mkdir", &weechat_lua_api_mkdir }, + { "mkdir_parents", &weechat_lua_api_mkdir_parents }, { "list_new", &weechat_lua_api_list_new }, { "list_add", &weechat_lua_api_list_add }, { "list_search", &weechat_lua_api_list_search }, diff --git a/src/plugins/scripts/perl/weechat-perl-api.c b/src/plugins/scripts/perl/weechat-perl-api.c index f9ac735f9..68cdcf6a6 100644 --- a/src/plugins/scripts/perl/weechat-perl-api.c +++ b/src/plugins/scripts/perl/weechat-perl-api.c @@ -367,6 +367,37 @@ static XS (XS_weechat_api_mkdir) } /* + * weechat::mkdir_parents: create a directory and make parent directories as + * needed + */ + +static XS (XS_weechat_api_mkdir_parents) +{ + dXSARGS; + + /* make C compiler happy */ + (void) cv; + + if (!perl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir_parents"); + PERL_RETURN_ERROR; + } + + if (items < 2) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_parents"); + PERL_RETURN_ERROR; + } + + if (weechat_mkdir_parents (SvPV (ST (0), PL_na), /* directory */ + SvIV (ST (1)))) /* mode */ + PERL_RETURN_OK; + + PERL_RETURN_ERROR; +} + +/* * weechat::list_new: create a new list */ @@ -977,6 +1008,54 @@ weechat_perl_api_config_section_create_option_cb (void *data, } /* + * weechat_perl_api_config_section_delete_option_cb: callback to delete an option + */ + +int +weechat_perl_api_config_section_delete_option_cb (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *perl_argv[4]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + perl_argv[0] = script_ptr2str (config_file); + perl_argv[1] = script_ptr2str (section); + perl_argv[2] = script_ptr2str (option); + perl_argv[3] = NULL; + + rc = (int *) weechat_perl_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + perl_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (perl_argv[0]) + free (perl_argv[0]); + if (perl_argv[1]) + free (perl_argv[1]); + if (perl_argv[2]) + free (perl_argv[2]); + + return ret; + } + + return 0; +} + +/* * weechat::config_new_section: create a new section in configuration file */ @@ -984,6 +1063,7 @@ static XS (XS_weechat_api_config_new_section) { char *result, *cfg_file, *name, *function_read, *function_write; char *function_write_default, *function_create_option; + char *function_delete_option; dXSARGS; /* make C compiler happy */ @@ -995,7 +1075,7 @@ static XS (XS_weechat_api_config_new_section) PERL_RETURN_EMPTY; } - if (items < 8) + if (items < 9) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section"); PERL_RETURN_EMPTY; @@ -1007,6 +1087,7 @@ static XS (XS_weechat_api_config_new_section) function_write = SvPV (ST (5), PL_na); function_write_default = SvPV (ST (6), PL_na); function_create_option = SvPV (ST (7), PL_na); + function_delete_option = SvPV (ST (8), PL_na); result = script_ptr2str (script_api_config_new_section (weechat_perl_plugin, perl_current_script, script_str2ptr (cfg_file), @@ -1020,7 +1101,9 @@ static XS (XS_weechat_api_config_new_section) &weechat_perl_api_config_section_write_default_cb, function_write_default, &weechat_perl_api_config_section_create_option_cb, - function_create_option)); + function_create_option, + &weechat_perl_api_config_section_delete_option_cb, + function_delete_option)); PERL_RETURN_STRING_FREE(result); } @@ -2256,7 +2339,8 @@ static XS (XS_weechat_api_hook_connect) int weechat_perl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, int tags_count, char **tags, + time_t date, + int tags_count, const char **tags, const char *prefix, const char *message) { struct t_script_callback *script_callback; @@ -4359,6 +4443,7 @@ weechat_perl_api_init (pTHX) newXS ("weechat::ngettext", XS_weechat_api_ngettext, "weechat"); newXS ("weechat::mkdir_home", XS_weechat_api_mkdir_home, "weechat"); newXS ("weechat::mkdir", XS_weechat_api_mkdir, "weechat"); + newXS ("weechat::mkdir_parents", XS_weechat_api_mkdir_parents, "weechat"); newXS ("weechat::list_new", XS_weechat_api_list_new, "weechat"); newXS ("weechat::list_add", XS_weechat_api_list_add, "weechat"); newXS ("weechat::list_search", XS_weechat_api_list_search, "weechat"); diff --git a/src/plugins/scripts/python/weechat-python-api.c b/src/plugins/scripts/python/weechat-python-api.c index cc854bbf8..4b60ea0d7 100644 --- a/src/plugins/scripts/python/weechat-python-api.c +++ b/src/plugins/scripts/python/weechat-python-api.c @@ -380,6 +380,41 @@ weechat_python_api_mkdir (PyObject *self, PyObject *args) } /* + * weechat_python_api_mkdir_parents: create a directory and make parent + * directories as needed + */ + +static PyObject * +weechat_python_api_mkdir_parents (PyObject *self, PyObject *args) +{ + char *directory; + int mode; + + /* make C compiler happy */ + (void) self; + + if (!python_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir_parents"); + PYTHON_RETURN_ERROR; + } + + directory = NULL; + mode = 0; + + if (!PyArg_ParseTuple (args, "si", &directory, &mode)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_parents"); + PYTHON_RETURN_ERROR; + } + + if (weechat_mkdir_parents (directory, mode)) + PYTHON_RETURN_OK; + + PYTHON_RETURN_ERROR; +} + +/* * weechat_python_api_list_new: create a new list */ @@ -1024,6 +1059,54 @@ weechat_python_api_config_section_create_option_cb (void *data, } /* + * weechat_python_api_config_section_delete_option_cb: callback to delete an option + */ + +int +weechat_python_api_config_section_delete_option_cb (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *python_argv[4]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + python_argv[0] = script_ptr2str (config_file); + python_argv[1] = script_ptr2str (section); + python_argv[2] = script_ptr2str (option); + python_argv[3] = NULL; + + rc = (int *) weechat_python_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + python_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (python_argv[0]) + free (python_argv[0]); + if (python_argv[1]) + free (python_argv[1]); + if (python_argv[2]) + free (python_argv[2]); + + return ret; + } + + return 0; +} + +/* * weechat_python_api_config_new_section: create a new section in configuration file */ @@ -1032,6 +1115,7 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args) { char *config_file, *name, *function_read, *function_write; char *function_write_default, *function_create_option; + char *function_delete_option; char *result; int user_can_add_options, user_can_delete_options; PyObject *object; @@ -1053,11 +1137,13 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args) function_write = NULL; function_write_default = NULL; function_create_option = NULL; + function_delete_option = NULL; - if (!PyArg_ParseTuple (args, "ssiissss", &config_file, &name, + if (!PyArg_ParseTuple (args, "ssiisssss", &config_file, &name, &user_can_add_options, &user_can_delete_options, &function_read, &function_write, - &function_write_default, &function_create_option)) + &function_write_default, &function_create_option, + &function_delete_option)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section"); PYTHON_RETURN_EMPTY; @@ -1076,7 +1162,9 @@ weechat_python_api_config_new_section (PyObject *self, PyObject *args) &weechat_python_api_config_section_write_default_cb, function_write_default, &weechat_python_api_config_section_create_option_cb, - function_create_option)); + function_create_option, + &weechat_python_api_config_section_delete_option_cb, + function_delete_option)); PYTHON_RETURN_STRING_FREE(result); } @@ -2404,7 +2492,8 @@ weechat_python_api_hook_connect (PyObject *self, PyObject *args) int weechat_python_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, int tags_count, char **tags, + time_t date, + int tags_count, const char **tags, const char *prefix, const char *message) { struct t_script_callback *script_callback; @@ -4630,6 +4719,7 @@ PyMethodDef weechat_python_funcs[] = { "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" }, { "mkdir_home", &weechat_python_api_mkdir_home, METH_VARARGS, "" }, { "mkdir", &weechat_python_api_mkdir, METH_VARARGS, "" }, + { "mkdir_parents", &weechat_python_api_mkdir_parents, METH_VARARGS, "" }, { "list_new", &weechat_python_api_list_new, METH_VARARGS, "" }, { "list_add", &weechat_python_api_list_add, METH_VARARGS, "" }, { "list_search", &weechat_python_api_list_search, METH_VARARGS, "" }, diff --git a/src/plugins/scripts/ruby/weechat-ruby-api.c b/src/plugins/scripts/ruby/weechat-ruby-api.c index a0068ef6a..7758467ef 100644 --- a/src/plugins/scripts/ruby/weechat-ruby-api.c +++ b/src/plugins/scripts/ruby/weechat-ruby-api.c @@ -442,6 +442,47 @@ weechat_ruby_api_mkdir (VALUE class, VALUE directory, VALUE mode) } /* + * weechat_ruby_api_mkdir_parents: create a directory and make parent + * directories as needed + */ + +static VALUE +weechat_ruby_api_mkdir_parents (VALUE class, VALUE directory, VALUE mode) +{ + char *c_directory; + int c_mode; + + /* make C compiler happy */ + (void) class; + + if (!ruby_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir_parents"); + RUBY_RETURN_ERROR; + } + + c_directory = NULL; + c_mode = 0; + + if (NIL_P (directory) || NIL_P (mode)) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_parents"); + RUBY_RETURN_ERROR; + } + + Check_Type (directory, T_STRING); + Check_Type (mode, T_FIXNUM); + + c_directory = STR2CSTR (directory); + c_mode = FIX2INT (mode); + + if (weechat_mkdir_parents (c_directory, c_mode)) + RUBY_RETURN_OK; + + RUBY_RETURN_ERROR; +} + +/* * weechat_ruby_api_list_new: create a new list */ @@ -1147,6 +1188,54 @@ weechat_ruby_api_config_section_create_option_cb (void *data, } /* + * weechat_ruby_api_config_section_delete_option_cb: callback to delete an option + */ + +int +weechat_ruby_api_config_section_delete_option_cb (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *ruby_argv[4]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + ruby_argv[0] = script_ptr2str (config_file); + ruby_argv[1] = script_ptr2str (section); + ruby_argv[2] = script_ptr2str (option); + ruby_argv[3] = NULL; + + rc = (int *) weechat_ruby_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + ruby_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (ruby_argv[0]) + free (ruby_argv[0]); + if (ruby_argv[1]) + free (ruby_argv[1]); + if (ruby_argv[2]) + free (ruby_argv[2]); + + return ret; + } + + return 0; +} + +/* * weechat_ruby_api_config_new_section: create a new section in configuration file */ @@ -1157,10 +1246,12 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file, VALUE function_read, VALUE function_write, VALUE function_write_default, - VALUE function_create_option) + VALUE function_create_option, + VALUE function_delete_option) { char *c_config_file, *c_name, *c_function_read, *c_function_write; char *c_function_write_default, *c_function_create_option; + char *c_function_delete_option; char *result; int c_user_can_add_options, c_user_can_delete_options; VALUE return_value; @@ -1182,11 +1273,12 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file, c_function_write = NULL; c_function_write_default = NULL; c_function_create_option = NULL; + c_function_delete_option = NULL; if (NIL_P (config_file) || NIL_P (name) || NIL_P (user_can_add_options) || NIL_P (user_can_delete_options) || NIL_P (function_read) || NIL_P (function_write) || NIL_P (function_write_default) - || NIL_P (function_create_option)) + || NIL_P (function_create_option) || NIL_P (function_delete_option)) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section"); RUBY_RETURN_EMPTY; @@ -1200,6 +1292,7 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file, Check_Type (function_write, T_STRING); Check_Type (function_write_default, T_STRING); Check_Type (function_create_option, T_STRING); + Check_Type (function_delete_option, T_STRING); c_config_file = STR2CSTR (config_file); c_name = STR2CSTR (name); @@ -1209,6 +1302,7 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file, c_function_write = STR2CSTR (function_write); c_function_write_default = STR2CSTR (function_write_default); c_function_create_option = STR2CSTR (function_create_option); + c_function_delete_option = STR2CSTR (function_delete_option); result = script_ptr2str (script_api_config_new_section (weechat_ruby_plugin, ruby_current_script, @@ -1223,7 +1317,9 @@ weechat_ruby_api_config_new_section (VALUE class, VALUE config_file, &weechat_ruby_api_config_section_write_default_cb, c_function_write_default, &weechat_ruby_api_config_section_create_option_cb, - c_function_create_option)); + c_function_create_option, + &weechat_ruby_api_config_section_delete_option_cb, + c_function_delete_option)); RUBY_RETURN_STRING_FREE(result); } @@ -2777,7 +2873,8 @@ weechat_ruby_api_hook_connect (VALUE class, VALUE address, VALUE port, int weechat_ruby_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, int tags_count, char **tags, + time_t date, + int tags_count, const char **tags, const char *prefix, const char *message) { struct t_script_callback *script_callback; @@ -5344,6 +5441,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3); rb_define_module_function (ruby_mWeechat, "mkdir_home", &weechat_ruby_api_mkdir_home, 2); rb_define_module_function (ruby_mWeechat, "mkdir", &weechat_ruby_api_mkdir, 2); + rb_define_module_function (ruby_mWeechat, "mkdir_parents", &weechat_ruby_api_mkdir_parents, 2); rb_define_module_function (ruby_mWeechat, "list_new", &weechat_ruby_api_list_new, 0); rb_define_module_function (ruby_mWeechat, "list_add", &weechat_ruby_api_list_add, 3); rb_define_module_function (ruby_mWeechat, "list_search", &weechat_ruby_api_list_search, 2); @@ -5358,7 +5456,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) rb_define_module_function (ruby_mWeechat, "list_remove_all", &weechat_ruby_api_list_remove_all, 1); rb_define_module_function (ruby_mWeechat, "list_free", &weechat_ruby_api_list_free, 1); rb_define_module_function (ruby_mWeechat, "config_new", &weechat_ruby_api_config_new, 2); - rb_define_module_function (ruby_mWeechat, "config_new_section", &weechat_ruby_api_config_new_section, 8); + rb_define_module_function (ruby_mWeechat, "config_new_section", &weechat_ruby_api_config_new_section, 9); rb_define_module_function (ruby_mWeechat, "config_search_section", &weechat_ruby_api_config_search_section, 2); rb_define_module_function (ruby_mWeechat, "config_new_option", &weechat_ruby_api_config_new_option, 13); rb_define_module_function (ruby_mWeechat, "config_search_option", &weechat_ruby_api_config_search_option, 3); diff --git a/src/plugins/scripts/script-api.c b/src/plugins/scripts/script-api.c index 6e2df96f6..6a0e7d6b4 100644 --- a/src/plugins/scripts/script-api.c +++ b/src/plugins/scripts/script-api.c @@ -118,21 +118,29 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, struct t_config_section *section, const char *option_name, const char *value), - const char *function_create_option) + const char *function_create_option, + int (*callback_delete_option)(void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option), + const char *function_delete_option) { struct t_script_callback *new_script_callback1, *new_script_callback2; struct t_script_callback *new_script_callback3, *new_script_callback4; + struct t_script_callback *new_script_callback5; struct t_config_section *new_section; - void *callback1, *callback2, *callback3, *callback4; - + void *callback1, *callback2, *callback3, *callback4, *callback5; + new_script_callback1 = NULL; new_script_callback2 = NULL; new_script_callback3 = NULL; new_script_callback4 = NULL; + new_script_callback5 = NULL; callback1 = NULL; callback2 = NULL; callback3 = NULL; callback4 = NULL; + callback5 = NULL; if (function_read && function_read[0]) { @@ -141,7 +149,7 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, return NULL; callback1 = callback_read; } - + if (function_write && function_write[0]) { new_script_callback2 = script_callback_alloc (); @@ -202,6 +210,36 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, callback4 = callback_create_option; } + if (function_delete_option && function_delete_option[0]) + { + new_script_callback5 = script_callback_alloc (); + if (!new_script_callback5) + { + if (new_script_callback1) + { + script_callback_free_data (new_script_callback1); + free (new_script_callback1); + } + if (new_script_callback2) + { + script_callback_free_data (new_script_callback2); + free (new_script_callback2); + } + if (new_script_callback3) + { + script_callback_free_data (new_script_callback3); + free (new_script_callback3); + } + if (new_script_callback4) + { + script_callback_free_data (new_script_callback4); + free (new_script_callback4); + } + return NULL; + } + callback5 = callback_delete_option; + } + new_section = weechat_config_new_section (config_file, name, user_can_add_options, @@ -213,7 +251,9 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, callback3, new_script_callback3, callback4, - new_script_callback4); + new_script_callback4, + callback5, + new_script_callback5); if (!new_section) { if (new_script_callback1) @@ -236,6 +276,11 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, script_callback_free_data (new_script_callback4); free (new_script_callback4); } + if (new_script_callback5) + { + script_callback_free_data (new_script_callback5); + free (new_script_callback5); + } return NULL; } @@ -275,6 +320,15 @@ script_api_config_new_section (struct t_weechat_plugin *weechat_plugin, script_callback_add (script, new_script_callback4); } + if (new_script_callback5) + { + new_script_callback5->script = script; + new_script_callback5->function = strdup (function_delete_option); + new_script_callback5->config_file = config_file; + new_script_callback5->config_section = new_section; + script_callback_add (script, new_script_callback5); + } + return new_section; } @@ -734,7 +788,7 @@ script_api_hook_print (struct t_weechat_plugin *weechat_plugin, int (*callback)(void *data, struct t_gui_buffer *buffer, time_t date, - int tags_count, char **tags, + int tags_count, const char **tags, const char *prefix, const char *message), const char *function) diff --git a/src/plugins/scripts/script-api.h b/src/plugins/scripts/script-api.h index 392d6c7c9..3633044ff 100644 --- a/src/plugins/scripts/script-api.h +++ b/src/plugins/scripts/script-api.h @@ -51,7 +51,12 @@ extern struct t_config_section *script_api_config_new_section (struct t_weechat_ struct t_config_section *section, const char *option_name, const char *value), - const char *function_create_option); + const char *function_create_option, + int (*callback_delete_option)(void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option), + const char *function_delete_option); extern struct t_config_option *script_api_config_new_option (struct t_weechat_plugin *weechat_plugin, struct t_plugin_script *script, struct t_config_file *config_file, @@ -136,7 +141,7 @@ extern struct t_hook *script_api_hook_print (struct t_weechat_plugin *weechat_pl struct t_gui_buffer *buffer, time_t date, int tags_count, - char **tags, + const char **tags, const char *prefix, const char *message), const char *function); diff --git a/src/plugins/scripts/tcl/weechat-tcl-api.c b/src/plugins/scripts/tcl/weechat-tcl-api.c index 8e11e3b84..1eae1ae3e 100644 --- a/src/plugins/scripts/tcl/weechat-tcl-api.c +++ b/src/plugins/scripts/tcl/weechat-tcl-api.c @@ -155,7 +155,7 @@ /* - * weechat::register: startup function for all WeeChat Tcl scripts + * weechat_tcl_api_register: startup function for all WeeChat Tcl scripts */ static int @@ -220,7 +220,8 @@ weechat_tcl_api_register (ClientData clientData, Tcl_Interp *interp, int objc, } /* - * weechat::plugin_get_name: get name of plugin (return "core" for WeeChat core) + * weechat_tcl_api_plugin_get_name: get name of plugin (return "core" for + * WeeChat core) */ static int @@ -254,7 +255,7 @@ weechat_tcl_api_plugin_get_name (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::charset_set: set script charset + * weechat_tcl_api_charset_set: set script charset */ static int @@ -286,7 +287,8 @@ weechat_tcl_api_charset_set (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::iconv_to_internal: convert string to internal WeeChat charset + * weechat_tcl_api_iconv_to_internal: convert string to internal WeeChat + * charset */ static int @@ -314,15 +316,14 @@ weechat_tcl_api_iconv_to_internal (ClientData clientData, Tcl_Interp *interp, charset = Tcl_GetStringFromObj (objv[1], &i); string = Tcl_GetStringFromObj (objv[2], &i); - result = weechat_iconv_to_internal (charset, string); TCL_RETURN_STRING_FREE(result); } /* - * weechat::iconv_from_internal: convert string from WeeChat inernal charset - * to another one + * weechat_tcl_api_iconv_from_internal: convert string from WeeChat inernal + * charset to another one */ static int @@ -356,7 +357,7 @@ weechat_tcl_api_iconv_from_internal (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::gettext: get translated string + * weechat_tcl_api_gettext: get translated string */ static int @@ -388,7 +389,7 @@ weechat_tcl_api_gettext (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::ngettext: get translated string with plural form + * weechat_tcl_api_ngettext: get translated string with plural form */ static int @@ -397,8 +398,8 @@ weechat_tcl_api_ngettext (ClientData clientData, Tcl_Interp *interp, { Tcl_Obj* objp; char *result, *single, *plural; - int i; - + int i, count; + /* make C compiler happy */ (void) clientData; @@ -417,20 +418,19 @@ weechat_tcl_api_ngettext (ClientData clientData, Tcl_Interp *interp, single = Tcl_GetStringFromObj (objv[1], &i); plural = Tcl_GetStringFromObj (objv[2], &i); - if (Tcl_GetIntFromObj (interp, objv[3], &i) != TCL_OK) + if (Tcl_GetIntFromObj (interp, objv[3], &count) != TCL_OK) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("ngettext"); TCL_RETURN_EMPTY; } - result = weechat_ngettext (single, plural, - i); /* count */ + result = weechat_ngettext (single, plural, count); TCL_RETURN_STRING(result); } /* - * weechat::mkdir_home: create a directory in WeeChat home + * weechat_tcl_api_mkdir_home: create a directory in WeeChat home */ static int @@ -438,7 +438,7 @@ weechat_tcl_api_mkdir_home (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { Tcl_Obj* objp; - int i; + int i, mode; /* make C compiler happy */ (void) clientData; @@ -455,21 +455,21 @@ weechat_tcl_api_mkdir_home (ClientData clientData, Tcl_Interp *interp, TCL_RETURN_ERROR; } - if (Tcl_GetIntFromObj (interp, objv[2], &i) != TCL_OK) + if (Tcl_GetIntFromObj (interp, objv[2], &mode) != TCL_OK) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_home"); TCL_RETURN_EMPTY; } - + if (weechat_mkdir_home (Tcl_GetStringFromObj (objv[1], &i), /* directory */ - i)) /* mode */ + mode)) TCL_RETURN_OK; TCL_RETURN_ERROR; } /* - * weechat::mkdir: create a directory + * weechat_tcl_api_mkdir: create a directory */ static int @@ -477,8 +477,8 @@ weechat_tcl_api_mkdir (ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { Tcl_Obj* objp; - int i; - + int i, mode; + /* make C compiler happy */ (void) clientData; @@ -493,22 +493,62 @@ weechat_tcl_api_mkdir (ClientData clientData, Tcl_Interp *interp, WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir"); TCL_RETURN_ERROR; } - - if (Tcl_GetIntFromObj (interp, objv[2], &i) != TCL_OK) + + if (Tcl_GetIntFromObj (interp, objv[2], &mode) != TCL_OK) { - WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_home"); + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir"); TCL_RETURN_EMPTY; } - + if (weechat_mkdir (Tcl_GetStringFromObj (objv[1], &i), /* directory */ - i)) /* mode */ + mode)) + TCL_RETURN_OK; + + TCL_RETURN_ERROR; +} + +/* + * weechat_tcl_api_mkdir_parents: create a directory and make parent + * directories as needed + */ + +static int +weechat_tcl_api_mkdir_parents (ClientData clientData, Tcl_Interp *interp, + int objc, Tcl_Obj *CONST objv[]) +{ + Tcl_Obj* objp; + int i, mode; + + /* make C compiler happy */ + (void) clientData; + + if (!tcl_current_script) + { + WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("mkdir_parents"); + TCL_RETURN_ERROR; + } + + if (objc < 3) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_parents"); + TCL_RETURN_ERROR; + } + + if (Tcl_GetIntFromObj (interp, objv[2], &mode) != TCL_OK) + { + WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("mkdir_parents"); + TCL_RETURN_EMPTY; + } + + if (weechat_mkdir_parents (Tcl_GetStringFromObj (objv[1], &i), /* directory */ + mode)) TCL_RETURN_OK; TCL_RETURN_ERROR; } /* - * weechat::list_new: create a new list + * weechat_tcl_api_list_new: create a new list */ static int @@ -535,7 +575,7 @@ weechat_tcl_api_list_new (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_add: add a string to list + * weechat_tcl_api_list_add: add a string to list */ static int @@ -573,7 +613,7 @@ weechat_tcl_api_list_add (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_search: search a string in list + * weechat_tcl_api_list_search: search a string in list */ static int @@ -608,7 +648,7 @@ weechat_tcl_api_list_search (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_casesearch: search a string in list (ignore case) + * weechat_tcl_api_list_casesearch: search a string in list (ignore case) */ static int @@ -643,7 +683,7 @@ weechat_tcl_api_list_casesearch (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_get: get item by position + * weechat_tcl_api_list_get: get item by position */ static int @@ -652,12 +692,11 @@ weechat_tcl_api_list_get (ClientData clientData, Tcl_Interp *interp, { Tcl_Obj* objp; char *result; - int i; - + int i, position; + /* make C compiler happy */ (void) clientData; - if (!tcl_current_script) { WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("list_get"); @@ -670,20 +709,20 @@ weechat_tcl_api_list_get (ClientData clientData, Tcl_Interp *interp, TCL_RETURN_EMPTY; } - if (Tcl_GetIntFromObj (interp, objv[2], &i) != TCL_OK) + if (Tcl_GetIntFromObj (interp, objv[2], &position) != TCL_OK) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("list_get"); TCL_RETURN_EMPTY; } result = script_ptr2str (weechat_list_get (script_str2ptr (Tcl_GetStringFromObj (objv[1], &i)), /* weelist */ - i)); /* position */ + position)); TCL_RETURN_STRING_FREE(result); } /* - * weechat::list_set: set new value for item + * weechat_tcl_api_list_set: set new value for item */ static int @@ -717,7 +756,7 @@ weechat_tcl_api_list_set (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_next: get next item + * weechat_tcl_api_list_next: get next item */ static int @@ -749,7 +788,7 @@ weechat_tcl_api_list_next (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_prev: get previous item + * weechat_tcl_api_list_prev: get previous item */ static int @@ -781,7 +820,7 @@ weechat_tcl_api_list_prev (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_string: get string value of item + * weechat_tcl_api_list_string: get string value of item */ static int @@ -813,7 +852,7 @@ weechat_tcl_api_list_string (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_size: get number of elements in list + * weechat_tcl_api_list_size: get number of elements in list */ static int @@ -845,7 +884,7 @@ weechat_tcl_api_list_size (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_remove: remove item from list + * weechat_tcl_api_list_remove: remove item from list */ static int @@ -879,7 +918,7 @@ weechat_tcl_api_list_remove (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_remove_all: remove all items from list + * weechat_tcl_api_list_remove_all: remove all items from list */ static int @@ -909,7 +948,7 @@ weechat_tcl_api_list_remove_all (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::list_free: free list + * weechat_tcl_api_list_free: free list */ static int @@ -981,7 +1020,7 @@ weechat_tcl_api_config_reload_cb (void *data, } /* - * weechat::config_new: create a new configuration file + * weechat_tcl_api_config_new: create a new configuration file */ static int @@ -1019,7 +1058,8 @@ weechat_tcl_api_config_new (ClientData clientData, Tcl_Interp *interp, } /* - * weechat_tcl_api_config_section_read_cb: callback for reading option in section + * weechat_tcl_api_config_section_read_cb: callback for reading option in + * section */ void @@ -1120,7 +1160,8 @@ weechat_tcl_api_config_section_write_default_cb (void *data, } /* - * weechat_tcl_api_config_section_create_option_cb: callback to create an option + * weechat_tcl_api_config_section_create_option_cb: callback to create an + * option */ int @@ -1168,7 +1209,57 @@ weechat_tcl_api_config_section_create_option_cb (void *data, } /* - * weechat::config_new_section: create a new section in configuration file + * weechat_tcl_api_config_section_delete_option_cb: callback to delete an + * option + */ + +int +weechat_tcl_api_config_section_delete_option_cb (void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option) +{ + struct t_script_callback *script_callback; + char *tcl_argv[4]; + int *rc, ret; + + script_callback = (struct t_script_callback *)data; + + if (script_callback->function && script_callback->function[0]) + { + tcl_argv[0] = script_ptr2str (config_file); + tcl_argv[1] = script_ptr2str (section); + tcl_argv[2] = script_ptr2str (option); + tcl_argv[3] = NULL; + + rc = (int *) weechat_tcl_exec (script_callback->script, + WEECHAT_SCRIPT_EXEC_INT, + script_callback->function, + tcl_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (tcl_argv[0]) + free (tcl_argv[0]); + if (tcl_argv[1]) + free (tcl_argv[1]); + if (tcl_argv[2]) + free (tcl_argv[2]); + + return ret; + } + + return 0; +} + +/* + * weechat_tcl_api_config_new_section: create a new section in configuration + * file */ static int @@ -1178,6 +1269,7 @@ weechat_tcl_api_config_new_section (ClientData clientData, Tcl_Interp *interp, Tcl_Obj* objp; char *result, *cfg_file, *name, *function_read, *function_write; char *function_write_default, *function_create_option; + char *function_delete_option; int i,can_add,can_delete; /* make C compiler happy */ @@ -1189,7 +1281,7 @@ weechat_tcl_api_config_new_section (ClientData clientData, Tcl_Interp *interp, TCL_RETURN_EMPTY; } - if (objc < 9) + if (objc < 10) { WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("config_new_section"); TCL_RETURN_EMPTY; @@ -1208,6 +1300,7 @@ weechat_tcl_api_config_new_section (ClientData clientData, Tcl_Interp *interp, function_write = Tcl_GetStringFromObj (objv[6], &i); function_write_default = Tcl_GetStringFromObj (objv[7], &i); function_create_option = Tcl_GetStringFromObj (objv[8], &i); + function_delete_option = Tcl_GetStringFromObj (objv[9], &i); result = script_ptr2str (script_api_config_new_section (weechat_tcl_plugin, tcl_current_script, script_str2ptr (cfg_file), @@ -1221,13 +1314,15 @@ weechat_tcl_api_config_new_section (ClientData clientData, Tcl_Interp *interp, &weechat_tcl_api_config_section_write_default_cb, function_write_default, &weechat_tcl_api_config_section_create_option_cb, - function_create_option)); + function_create_option, + &weechat_tcl_api_config_section_delete_option_cb, + function_delete_option)); TCL_RETURN_STRING_FREE(result); } /* - * weechat::config_search_section: search section in configuration file + * weechat_tcl_api_config_search_section: search section in configuration file */ static int @@ -1264,7 +1359,7 @@ weechat_tcl_api_config_search_section (ClientData clientData, Tcl_Interp *interp /* * weechat_tcl_api_config_option_check_value_cb: callback for checking new - * value for option + * value for option */ void @@ -1366,7 +1461,7 @@ weechat_tcl_api_config_option_delete_cb (void *data, /* - * weechat::config_new_option: create a new option in section + * weechat_tcl_api_config_new_option: create a new option in section */ static int @@ -1436,7 +1531,8 @@ weechat_tcl_api_config_new_option (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_search_option: search option in configuration file or section + * weechat_tcl_api_config_search_option: search option in configuration file or + * section */ static int @@ -1473,7 +1569,7 @@ weechat_tcl_api_config_search_option (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_string_to_boolean: return boolean value of a string + * weechat_tcl_api_config_string_to_boolean: return boolean value of a string */ static int @@ -1504,7 +1600,7 @@ weechat_tcl_api_config_string_to_boolean (ClientData clientData, Tcl_Interp *int } /* - * weechat::config_option_reset: reset an option with default value + * weechat_tcl_api_config_option_reset: reset an option with default value */ static int @@ -1545,7 +1641,7 @@ weechat_tcl_api_config_option_reset (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_option_set: set new value for option + * weechat_tcl_api_config_option_set: set new value for option */ static int @@ -1588,7 +1684,7 @@ weechat_tcl_api_config_option_set (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_option_unset: unset an option + * weechat_tcl_api_config_option_unset: unset an option */ static int @@ -1622,7 +1718,7 @@ weechat_tcl_api_config_option_unset (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_option_rename: rename an option + * weechat_tcl_api_config_option_rename: rename an option */ static int @@ -1657,7 +1753,7 @@ weechat_tcl_api_config_option_rename (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_boolean: return boolean value of option + * weechat_tcl_api_config_boolean: return boolean value of option */ static int @@ -1688,7 +1784,7 @@ weechat_tcl_api_config_boolean (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_integer: return integer value of option + * weechat_tcl_api_config_integer: return integer value of option */ static int @@ -1719,7 +1815,7 @@ weechat_tcl_api_config_integer (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_string: return string value of option + * weechat_tcl_api_config_string: return string value of option */ static int @@ -1751,7 +1847,7 @@ weechat_tcl_api_config_string (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_color: return color value of option + * weechat_tcl_api_config_color: return color value of option */ static int @@ -1782,7 +1878,7 @@ weechat_tcl_api_config_color (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_write_line: write a line in configuration file + * weechat_tcl_api_config_write_line: write a line in configuration file */ static int @@ -1818,7 +1914,7 @@ weechat_tcl_api_config_write_line (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_write: write configuration file + * weechat_tcl_api_config_write: write configuration file */ static int @@ -1850,7 +1946,7 @@ weechat_tcl_api_config_write (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_read: read configuration file + * weechat_tcl_api_config_read: read configuration file */ static int @@ -1882,7 +1978,7 @@ weechat_tcl_api_config_read (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_reload: reload configuration file + * weechat_tcl_api_config_reload: reload configuration file */ static int @@ -1914,7 +2010,7 @@ weechat_tcl_api_config_reload (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_free: free configuration file + * weechat_tcl_api_config_free: free configuration file */ static int @@ -1947,7 +2043,7 @@ weechat_tcl_api_config_free (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_get: get config option + * weechat_tcl_api_config_get: get config option */ static int @@ -1979,7 +2075,7 @@ weechat_tcl_api_config_get (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_get_plugin: get value of a plugin option + * weechat_tcl_api_config_get_plugin: get value of a plugin option */ static int @@ -2013,7 +2109,7 @@ weechat_tcl_api_config_get_plugin (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::config_set_plugin: set value of a plugin option + * weechat_tcl_api_config_set_plugin: set value of a plugin option */ static int @@ -2051,7 +2147,7 @@ weechat_tcl_api_config_set_plugin (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::prefix: get a prefix, used for display + * weechat_tcl_api_prefix: get a prefix, used for display */ static int @@ -2083,7 +2179,7 @@ weechat_tcl_api_prefix (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::color: get a color code, used for display + * weechat_tcl_api_color: get a color code, used for display */ static int @@ -2115,7 +2211,7 @@ weechat_tcl_api_color (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::print: print message in a buffer + * weechat_tcl_api_print: print message in a buffer */ static int @@ -2152,8 +2248,8 @@ weechat_tcl_api_print (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::print_date_tags: print message in a buffer with optional date and - * tags + * weechat_tcl_api_print_date_tags: print message in a buffer with optional + * date and tags */ static int @@ -2199,7 +2295,7 @@ weechat_tcl_api_print_date_tags (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::print_y: print message in a buffer with free content + * weechat_tcl_api_print_y: print message in a buffer with free content */ static int @@ -2243,7 +2339,7 @@ weechat_tcl_api_print_y (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::log_print: print message in WeeChat log file + * weechat_tcl_api_log_print: print message in WeeChat log file */ static int @@ -2315,7 +2411,7 @@ weechat_tcl_api_hook_command_cb (void *data, struct t_gui_buffer *buffer, } /* - * weechat::hook_command: hook a command + * weechat_tcl_api_hook_command: hook a command */ static int @@ -2393,7 +2489,7 @@ weechat_tcl_api_hook_timer_cb (void *data) } /* - * weechat::hook_timer: hook a timer + * weechat_tcl_api_hook_timer: hook a timer */ static int @@ -2472,7 +2568,7 @@ weechat_tcl_api_hook_fd_cb (void *data) } /* - * weechat::hook_fd: hook a fd + * weechat_tcl_api_hook_fd: hook a fd */ static int @@ -2556,7 +2652,7 @@ weechat_tcl_api_hook_connect_cb (void *data, int status, } /* - * weechat::hook_connect: hook a connection + * weechat_tcl_api_hook_connect: hook a connection */ static int @@ -2613,8 +2709,9 @@ weechat_tcl_api_hook_connect (ClientData clientData, Tcl_Interp *interp, int weechat_tcl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, - time_t date, int tags_count, char **tags, - const char *prefix, const char *message) + time_t date, + int tags_count, const char **tags, + const char *prefix, const char *message) { struct t_script_callback *script_callback; char *tcl_argv[6]; @@ -2656,7 +2753,7 @@ weechat_tcl_api_hook_print_cb (void *data, struct t_gui_buffer *buffer, } /* - * weechat::hook_print: hook a print + * weechat_tcl_api_hook_print: hook a print */ static int @@ -2759,7 +2856,7 @@ weechat_tcl_api_hook_signal_cb (void *data, const char *signal, const char *type } /* - * weechat::hook_signal: hook a signal + * weechat_tcl_api_hook_signal: hook a signal */ static int @@ -2797,7 +2894,7 @@ weechat_tcl_api_hook_signal (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::hook_signal_send: send a signal + * weechat_tcl_api_hook_signal_send: send a signal */ static int @@ -2889,7 +2986,7 @@ weechat_tcl_api_hook_config_cb (void *data, const char *option, const char *valu } /* - * weechat::hook_config: hook a config option + * weechat_tcl_api_hook_config: hook a config option */ static int @@ -2967,7 +3064,7 @@ weechat_tcl_api_hook_completion_cb (void *data, const char *completion_item, } /* - * weechat::hook_completion: hook a completion + * weechat_tcl_api_hook_completion: hook a completion */ static int @@ -3005,7 +3102,7 @@ weechat_tcl_api_hook_completion (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::hook_completion_list_add: add a word to list for a completion + * weechat_tcl_api_hook_completion_list_add: add a word to list for a completion */ static int @@ -3074,7 +3171,7 @@ weechat_tcl_api_hook_modifier_cb (void *data, const char *modifier, } /* - * weechat::hook_modifier: hook a modifier + * weechat_tcl_api_hook_modifier: hook a modifier */ static int @@ -3112,7 +3209,7 @@ weechat_tcl_api_hook_modifier (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::hook_modifier_exec: execute a modifier hook + * weechat_tcl_api_hook_modifier_exec: execute a modifier hook */ static int @@ -3170,7 +3267,7 @@ weechat_tcl_api_hook_info_cb (void *data, const char *info_name, } /* - * weechat::hook_info: hook an info + * weechat_tcl_api_hook_info: hook an info */ static int @@ -3240,7 +3337,7 @@ weechat_tcl_api_hook_infolist_cb (void *data, const char *infolist_name, } /* - * weechat::hook_infolist: hook an infolist + * weechat_tcl_api_hook_infolist: hook an infolist */ static int @@ -3280,7 +3377,7 @@ weechat_tcl_api_hook_infolist (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::unhook: unhook something + * weechat_tcl_api_unhook: unhook something */ static int @@ -3313,7 +3410,7 @@ weechat_tcl_api_unhook (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::unhook_all: unhook all for script + * weechat_tcl_api_unhook_all: unhook all for script */ static int @@ -3407,7 +3504,7 @@ weechat_tcl_api_buffer_close_cb (void *data, struct t_gui_buffer *buffer) } /* - * weechat::buffer_new: create a new buffer + * weechat_tcl_api_buffer_new: create a new buffer */ static int @@ -3448,7 +3545,7 @@ weechat_tcl_api_buffer_new (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::buffer_search: search a buffer + * weechat_tcl_api_buffer_search: search a buffer */ static int @@ -3482,7 +3579,7 @@ weechat_tcl_api_buffer_search (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::buffer_clear: clear a buffer + * weechat_tcl_api_buffer_clear: clear a buffer */ static int @@ -3513,7 +3610,7 @@ weechat_tcl_api_buffer_clear (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::buffer_close: close a buffer + * weechat_tcl_api_buffer_close: close a buffer */ static int @@ -3553,7 +3650,7 @@ weechat_tcl_api_buffer_close (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::buffer_get_integer: get a buffer property as integer + * weechat_tcl_api_buffer_get_integer: get a buffer property as integer */ static int @@ -3589,7 +3686,7 @@ weechat_tcl_api_buffer_get_integer (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::buffer_get_string: get a buffer property as string + * weechat_tcl_api_buffer_get_string: get a buffer property as string */ static int @@ -3624,7 +3721,7 @@ weechat_tcl_api_buffer_get_string (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::buffer_get_pointer: get a buffer property as pointer + * weechat_tcl_api_buffer_get_pointer: get a buffer property as pointer */ static int @@ -3660,7 +3757,7 @@ weechat_tcl_api_buffer_get_pointer (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::buffer_set: set a buffer property + * weechat_tcl_api_buffer_set: set a buffer property */ static int @@ -3696,7 +3793,7 @@ weechat_tcl_api_buffer_set (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::nicklist_add_group: add a group in nicklist + * weechat_tcl_api_nicklist_add_group: add a group in nicklist */ static int @@ -3742,7 +3839,7 @@ weechat_tcl_api_nicklist_add_group (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::nicklist_search_group: search a group in nicklist + * weechat_tcl_api_nicklist_search_group: search a group in nicklist */ static int @@ -3779,7 +3876,7 @@ weechat_tcl_api_nicklist_search_group (ClientData clientData, Tcl_Interp *interp } /* - * weechat::nicklist_add_nick: add a nick in nicklist + * weechat_tcl_api_nicklist_add_nick: add a nick in nicklist */ static int @@ -3835,7 +3932,7 @@ weechat_tcl_api_nicklist_add_nick (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::nicklist_search_nick: search a nick in nicklist + * weechat_tcl_api_nicklist_search_nick: search a nick in nicklist */ static int @@ -3872,7 +3969,7 @@ weechat_tcl_api_nicklist_search_nick (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::nicklist_remove_group: remove a group from nicklist + * weechat_tcl_api_nicklist_remove_group: remove a group from nicklist */ static int @@ -3907,7 +4004,7 @@ weechat_tcl_api_nicklist_remove_group (ClientData clientData, Tcl_Interp *interp } /* - * weechat::nicklist_remove_nick: remove a nick from nicklist + * weechat_tcl_api_nicklist_remove_nick: remove a nick from nicklist */ static int @@ -3942,7 +4039,7 @@ weechat_tcl_api_nicklist_remove_nick (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::nicklist_remove_all: remove all groups/nicks from nicklist + * weechat_tcl_api_nicklist_remove_all: remove all groups/nicks from nicklist */ static int @@ -3973,7 +4070,7 @@ weechat_tcl_api_nicklist_remove_all (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::bar_item_search: search a bar item + * weechat_tcl_api_bar_item_search: search a bar item */ static int @@ -4042,7 +4139,7 @@ weechat_tcl_api_bar_item_build_cb (void *data, struct t_gui_bar_item *item, } /* - * weechat::bar_item_new: add a new bar item + * weechat_tcl_api_bar_item_new: add a new bar item */ static int @@ -4080,7 +4177,7 @@ weechat_tcl_api_bar_item_new (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::bar_item_update: update a bar item on screen + * weechat_tcl_api_bar_item_update: update a bar item on screen */ static int @@ -4111,7 +4208,7 @@ weechat_tcl_api_bar_item_update (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::bar_item_remove: remove a bar item + * weechat_tcl_api_bar_item_remove: remove a bar item */ static int @@ -4144,7 +4241,7 @@ weechat_tcl_api_bar_item_remove (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::bar_search: search a bar + * weechat_tcl_api_bar_search: search a bar */ static int @@ -4176,7 +4273,7 @@ weechat_tcl_api_bar_search (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::bar_new: add a new bar + * weechat_tcl_api_bar_new: add a new bar */ static int @@ -4239,7 +4336,7 @@ weechat_tcl_api_bar_new (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::bar_set: set a bar property + * weechat_tcl_api_bar_set: set a bar property */ static int @@ -4275,7 +4372,7 @@ weechat_tcl_api_bar_set (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::bar_update: update a bar on screen + * weechat_tcl_api_bar_update: update a bar on screen */ static int @@ -4306,7 +4403,7 @@ weechat_tcl_api_bar_update (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::bar_remove: remove a bar + * weechat_tcl_api_bar_remove: remove a bar */ static int @@ -4337,7 +4434,7 @@ weechat_tcl_api_bar_remove (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::command: execute a command on a buffer + * weechat_tcl_api_command: execute a command on a buffer */ static int @@ -4374,7 +4471,7 @@ weechat_tcl_api_command (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::info_get: get info about WeeChat + * weechat_tcl_api_info_get: get info about WeeChat */ static int @@ -4407,7 +4504,7 @@ weechat_tcl_api_info_get (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_new: create a new infolist + * weechat_tcl_api_infolist_new: create a new infolist */ static int @@ -4434,7 +4531,8 @@ weechat_tcl_api_infolist_new (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_new_var_integer: create new integer variable in infolist + * weechat_tcl_api_infolist_new_var_integer: create new integer variable in + * infolist */ static int @@ -4474,7 +4572,8 @@ weechat_tcl_api_infolist_new_var_integer (ClientData clientData, Tcl_Interp *int } /* - * weechat::infolist_new_var_string: create new string variable in infolist + * weechat_tcl_api_infolist_new_var_string: create new string variable in + * infolist */ static int @@ -4508,7 +4607,7 @@ weechat_tcl_api_infolist_new_var_string (ClientData clientData, Tcl_Interp *inte } /* - * weechat::infolist_new_var_pointer: create new pointer variable in infolist + * weechat_tcl_api_infolist_new_var_pointer: create new pointer variable in infolist */ static int @@ -4542,7 +4641,7 @@ weechat_tcl_api_infolist_new_var_pointer (ClientData clientData, Tcl_Interp *int } /* - * weechat::infolist_new_var_time: create new time variable in infolist + * weechat_tcl_api_infolist_new_var_time: create new time variable in infolist */ static int @@ -4582,7 +4681,7 @@ weechat_tcl_api_infolist_new_var_time (ClientData clientData, Tcl_Interp *interp } /* - * weechat::infolist_get: get list with infos + * weechat_tcl_api_infolist_get: get list with infos */ static int @@ -4619,7 +4718,7 @@ weechat_tcl_api_infolist_get (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_next: move item pointer to next item in infolist + * weechat_tcl_api_infolist_next: move item pointer to next item in infolist */ static int @@ -4650,7 +4749,8 @@ weechat_tcl_api_infolist_next (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_prev: move item pointer to previous item in infolist + * weechat_tcl_api_infolist_prev: move item pointer to previous item in + * infolist */ static int @@ -4681,7 +4781,8 @@ weechat_tcl_api_infolist_prev (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_fields: get list of fields for current item of infolist + * weechat_tcl_api_infolist_fields: get list of fields for current item of + * infolist */ static int @@ -4713,7 +4814,8 @@ weechat_tcl_api_infolist_fields (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_integer: get integer value of a variable in infolist + * weechat_tcl_api_infolist_integer: get integer value of a variable in + * infolist */ static int @@ -4748,7 +4850,7 @@ weechat_tcl_api_infolist_integer (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_string: get string value of a variable in infolist + * weechat_tcl_api_infolist_string: get string value of a variable in infolist */ static int @@ -4783,7 +4885,8 @@ weechat_tcl_api_infolist_string (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_pointer: get pointer value of a variable in infolist + * weechat_tcl_api_infolist_pointer: get pointer value of a variable in + * infolist */ static int @@ -4818,7 +4921,7 @@ weechat_tcl_api_infolist_pointer (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_time: get time value of a variable in infolist + * weechat_tcl_api_infolist_time: get time value of a variable in infolist */ static int @@ -4856,7 +4959,7 @@ weechat_tcl_api_infolist_time (ClientData clientData, Tcl_Interp *interp, } /* - * weechat::infolist_free: free infolist + * weechat_tcl_api_infolist_free: free infolist */ static int @@ -5006,6 +5109,8 @@ void weechat_tcl_api_init (Tcl_Interp *interp) { weechat_tcl_api_mkdir_home, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::mkdir", weechat_tcl_api_mkdir, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); + Tcl_CreateObjCommand (interp,"weechat::mkdir_parents", + weechat_tcl_api_mkdir_parents, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::list_new", weechat_tcl_api_list_new, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL); Tcl_CreateObjCommand (interp,"weechat::list_add", diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index f39e04216..6a63fd4ae 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -23,6 +23,7 @@ #include <sys/types.h> +struct t_config_option; struct t_gui_window; struct t_gui_buffer; struct t_gui_bar; @@ -148,7 +149,7 @@ struct t_weechat_plugin char **(*string_explode) (const char *string, const char *separators, int keep_eol, int num_items_max, int *num_items); void (*string_free_exploded) (char **exploded_string); - char *(*string_build_with_exploded) (char **exploded_string, + char *(*string_build_with_exploded) (const char **exploded_string, const char *separator); char **(*string_split_command) (const char *command, char separator); void (*string_free_splitted_command) (char **splitted_command); @@ -172,6 +173,7 @@ struct t_weechat_plugin /* directories */ int (*mkdir_home) (const char *directory, int mode); int (*mkdir) (const char *directory, int mode); + int (*mkdir_parents) (const char *directory, int mode); void (*exec_on_files) (const char *directory, void *data, void (*callback)(void *data, const char *filename)); @@ -200,7 +202,7 @@ struct t_weechat_plugin struct t_weelist_item *item); void (*list_remove_all) (struct t_weelist *weelist); void (*list_free) (struct t_weelist *weelist); - + /* config files */ struct t_config_file *(*config_new) (struct t_weechat_plugin *plugin, const char *name, @@ -230,7 +232,12 @@ struct t_weechat_plugin struct t_config_section *section, const char *option_name, const char *value), - void *callback_create_option_data); + void *callback_create_option_data, + int (*callback_delete_option)(void *data, + struct t_config_file *config_file, + struct t_config_section *section, + struct t_config_option *option), + void *callback_delete_option_data); struct t_config_section *(*config_search_section) (struct t_config_file *config_file, const char *section_name); struct t_config_option *(*config_new_option) (struct t_config_file *config_file, @@ -342,7 +349,7 @@ struct t_weechat_plugin struct t_gui_buffer *buffer, time_t date, int tags_count, - char **tags, + const char **tags, const char *prefix, const char *message), void *callback_data); @@ -659,6 +666,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); weechat_plugin->mkdir_home(__directory, __mode) #define weechat_mkdir(__directory, __mode) \ weechat_plugin->mkdir(__directory, __mode) +#define weechat_mkdir_parents(__directory, __mode) \ + weechat_plugin->mkdir_parents(__directory, __mode) #define weechat_exec_on_files(__directory, __data, __callback) \ weechat_plugin->exec_on_files(__directory, __data, __callback) @@ -711,7 +720,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __cb_write_std, __cb_write_std_data, \ __cb_write_def, __cb_write_def_data, \ __cb_create_option, \ - __cb_create_option_data) \ + __cb_create_option_data, \ + __cb_delete_option, \ + __cb_delete_option_data) \ weechat_plugin->config_new_section(__config, __name, \ __user_can_add_options, \ __user_can_delete_options, \ @@ -721,7 +732,9 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __cb_write_def, \ __cb_write_def_data, \ __cb_create_option, \ - __cb_create_option_data) + __cb_create_option_data, \ + __cb_delete_option, \ + __cb_delete_option_data) #define weechat_config_search_section(__config, __name) \ weechat_plugin->config_search_section(__config, __name) #define weechat_config_new_option(__config, __section, __name, __type, \ diff --git a/src/plugins/xfer/xfer-config.c b/src/plugins/xfer/xfer-config.c index e36a3cc56..f4dcdfc45 100644 --- a/src/plugins/xfer/xfer-config.c +++ b/src/plugins/xfer/xfer-config.c @@ -111,7 +111,8 @@ xfer_config_init () ptr_section = weechat_config_new_section (xfer_config_file, "look", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (xfer_config_file); @@ -134,7 +135,8 @@ xfer_config_init () ptr_section = weechat_config_new_section (xfer_config_file, "color", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (xfer_config_file); @@ -199,7 +201,8 @@ xfer_config_init () ptr_section = weechat_config_new_section (xfer_config_file, "network", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (xfer_config_file); @@ -245,7 +248,8 @@ xfer_config_init () ptr_section = weechat_config_new_section (xfer_config_file, "file", 0, 0, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, + NULL, NULL); if (!ptr_section) { weechat_config_free (xfer_config_file); |