diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/logger/logger-backlog.c | 62 | ||||
-rw-r--r-- | src/plugins/logger/logger-backlog.h | 1 | ||||
-rw-r--r-- | src/plugins/logger/logger-buffer.c | 5 | ||||
-rw-r--r-- | src/plugins/logger/logger-config.c | 11 | ||||
-rw-r--r-- | src/plugins/logger/logger-config.h | 1 | ||||
-rw-r--r-- | src/plugins/logger/logger.c | 56 | ||||
-rw-r--r-- | src/plugins/logger/logger.h | 2 |
7 files changed, 79 insertions, 59 deletions
diff --git a/src/plugins/logger/logger-backlog.c b/src/plugins/logger/logger-backlog.c index 14ed7bffb..c85999a36 100644 --- a/src/plugins/logger/logger-backlog.c +++ b/src/plugins/logger/logger-backlog.c @@ -47,62 +47,6 @@ /* - * Checks conditions to display the backlog. - * - * Returns: - * 1: conditions OK (backlog is displayed) - * 0: conditions not OK (backlog is NOT displayed) - */ - -int -logger_backlog_check_conditions (struct t_gui_buffer *buffer) -{ - struct t_hashtable *pointers, *options; - const char *ptr_condition; - char *result; - int condition_ok; - - ptr_condition = weechat_config_string (logger_config_look_backlog_conditions); - - /* empty condition displays the backlog everywhere */ - if (!ptr_condition || !ptr_condition[0]) - return 1; - - pointers = weechat_hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_POINTER, - NULL, - NULL); - if (pointers) - { - weechat_hashtable_set (pointers, "window", - weechat_window_search_with_buffer (buffer)); - weechat_hashtable_set (pointers, "buffer", buffer); - } - - options = weechat_hashtable_new (32, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_STRING, - NULL, - NULL); - if (options) - weechat_hashtable_set (options, "type", "condition"); - - result = weechat_string_eval_expression (ptr_condition, - pointers, NULL, options); - condition_ok = (result && (strcmp (result, "1") == 0)); - if (result) - free (result); - - if (pointers) - weechat_hashtable_free (pointers); - if (options) - weechat_hashtable_free (options); - - return condition_ok; -} - -/* * Displays a line read from log file. */ @@ -227,6 +171,7 @@ logger_backlog_signal_cb (const void *pointer, void *data, const char *type_data, void *signal_data) { struct t_logger_buffer *ptr_logger_buffer; + int rc; /* make C compiler happy */ (void) pointer; @@ -237,7 +182,10 @@ logger_backlog_signal_cb (const void *pointer, void *data, if (weechat_config_integer (logger_config_look_backlog) == 0) return WEECHAT_RC_OK; - if (!logger_backlog_check_conditions (signal_data)) + rc = logger_check_conditions ( + signal_data, + weechat_config_string (logger_config_look_backlog_conditions)); + if (!rc) return WEECHAT_RC_OK; ptr_logger_buffer = logger_buffer_search_buffer (signal_data); diff --git a/src/plugins/logger/logger-backlog.h b/src/plugins/logger/logger-backlog.h index 39b13933b..779fd2df7 100644 --- a/src/plugins/logger/logger-backlog.h +++ b/src/plugins/logger/logger-backlog.h @@ -20,7 +20,6 @@ #ifndef WEECHAT_PLUGIN_LOGGER_BACKLOG_H #define WEECHAT_PLUGIN_LOGGER_BACKLOG_H -extern int logger_backlog_check_conditions (struct t_gui_buffer *buffer); extern int logger_backlog_signal_cb (const void *pointer, void *data, const char *signal, const char *type_data, void *signal_data); diff --git a/src/plugins/logger/logger-buffer.c b/src/plugins/logger/logger-buffer.c index 9c02ded58..67686abb7 100644 --- a/src/plugins/logger/logger-buffer.c +++ b/src/plugins/logger/logger-buffer.c @@ -713,7 +713,10 @@ logger_buffer_start (struct t_gui_buffer *buffer, int write_info_line) log_level = logger_get_level_for_buffer (buffer); log_enabled = weechat_config_boolean (logger_config_file_auto_log) - && (log_level > 0); + && (log_level > 0) + && (logger_check_conditions ( + buffer, + weechat_config_string (logger_config_file_log_conditions))); ptr_logger_buffer = logger_buffer_search_buffer (buffer); diff --git a/src/plugins/logger/logger-config.c b/src/plugins/logger/logger-config.c index 91683f2b8..1b5dd5c97 100644 --- a/src/plugins/logger/logger-config.c +++ b/src/plugins/logger/logger-config.c @@ -58,6 +58,7 @@ struct t_config_option *logger_config_file_color_lines = NULL; struct t_config_option *logger_config_file_flush_delay = NULL; struct t_config_option *logger_config_file_fsync = NULL; struct t_config_option *logger_config_file_info_lines = NULL; +struct t_config_option *logger_config_file_log_conditions = NULL; struct t_config_option *logger_config_file_mask = NULL; struct t_config_option *logger_config_file_name_lower_case = NULL; struct t_config_option *logger_config_file_nick_prefix = NULL; @@ -579,6 +580,16 @@ logger_config_init () "a buffer"), NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + logger_config_file_log_conditions = weechat_config_new_option ( + logger_config_file, logger_config_section_file, + "log_conditions", "string", + N_("conditions to save content of buffers to files " + "(note: content is evaluated, see /help eval); " + "empty value saves content on all buffers; " + "for example to log only private buffers: " + "\"${type} == private\""), + NULL, 0, 0, "", NULL, 0, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); logger_config_file_mask = weechat_config_new_option ( logger_config_file, logger_config_section_file, "mask", "string", diff --git a/src/plugins/logger/logger-config.h b/src/plugins/logger/logger-config.h index 45ec8aad5..ca0631a0e 100644 --- a/src/plugins/logger/logger-config.h +++ b/src/plugins/logger/logger-config.h @@ -34,6 +34,7 @@ extern struct t_config_option *logger_config_file_color_lines; extern struct t_config_option *logger_config_file_flush_delay; extern struct t_config_option *logger_config_file_fsync; extern struct t_config_option *logger_config_file_info_lines; +extern struct t_config_option *logger_config_file_log_conditions; extern struct t_config_option *logger_config_file_mask; extern struct t_config_option *logger_config_file_name_lower_case; extern struct t_config_option *logger_config_file_nick_prefix; diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index ef817faa3..6489ef1ec 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -50,6 +50,62 @@ struct t_hook *logger_hook_print = NULL; /* + * Checks conditions against a buffer. + * + * Returns: + * 1: conditions OK + * 0: conditions not OK + */ + +int +logger_check_conditions (struct t_gui_buffer *buffer, const char *conditions) +{ + struct t_hashtable *pointers, *options; + char *result; + int condition_ok; + + if (!buffer) + return 0; + + /* empty conditions = always true */ + if (!conditions || !conditions[0]) + return 1; + + pointers = weechat_hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_POINTER, + NULL, + NULL); + if (pointers) + { + weechat_hashtable_set (pointers, "window", + weechat_window_search_with_buffer (buffer)); + weechat_hashtable_set (pointers, "buffer", buffer); + } + + options = weechat_hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, + NULL); + if (options) + weechat_hashtable_set (options, "type", "condition"); + + result = weechat_string_eval_expression (conditions, + pointers, NULL, options); + condition_ok = (result && (strcmp (result, "1") == 0)); + if (result) + free (result); + + if (pointers) + weechat_hashtable_free (pointers); + if (options) + weechat_hashtable_free (options); + + return condition_ok; +} + +/* * Gets logger file path option. * * Special vars are replaced: diff --git a/src/plugins/logger/logger.h b/src/plugins/logger/logger.h index e1b5a137e..2b94acab4 100644 --- a/src/plugins/logger/logger.h +++ b/src/plugins/logger/logger.h @@ -34,6 +34,8 @@ extern struct t_weechat_plugin *weechat_logger_plugin; extern struct t_hook *logger_hook_timer; extern struct t_hook *logger_hook_print; +extern int logger_check_conditions (struct t_gui_buffer *buffer, + const char *conditions); extern int logger_create_directory (); extern char *logger_build_option_name (struct t_gui_buffer *buffer); extern int logger_get_level_for_buffer (struct t_gui_buffer *buffer); |