diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-01-06 19:22:24 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-01-06 19:22:24 +0100 |
commit | 990c0bc1217d781066206d0caf459e40bf1b1bea (patch) | |
tree | 8ac9af162ba77fb56a65a2a969622103a568f93f /src/plugins | |
parent | e01ed80669059fb6042543bf0798ad31109563a4 (diff) | |
download | weechat-990c0bc1217d781066206d0caf459e40bf1b1bea.zip |
exec: add option "-oc" in command /exec to execute commands in process output (closes #877)
The behavior of existing option "-o" is changed: now commands are NOT
executed (which is more secure by default).
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/exec/exec-command.c | 23 | ||||
-rw-r--r-- | src/plugins/exec/exec-command.h | 1 | ||||
-rw-r--r-- | src/plugins/exec/exec.c | 77 | ||||
-rw-r--r-- | src/plugins/exec/exec.h | 1 |
4 files changed, 75 insertions, 27 deletions
diff --git a/src/plugins/exec/exec-command.c b/src/plugins/exec/exec-command.c index 7cc9c2cbf..cbae927c9 100644 --- a/src/plugins/exec/exec-command.c +++ b/src/plugins/exec/exec-command.c @@ -227,21 +227,31 @@ exec_command_parse_options (struct t_exec_cmd_options *cmd_options, else if (weechat_strcasecmp (argv[i], "-l") == 0) { cmd_options->output_to_buffer = 0; + cmd_options->output_to_buffer_exec_cmd = 0; cmd_options->new_buffer = 0; } else if (weechat_strcasecmp (argv[i], "-o") == 0) { cmd_options->output_to_buffer = 1; + cmd_options->output_to_buffer_exec_cmd = 0; + cmd_options->new_buffer = 0; + } + else if (weechat_strcasecmp (argv[i], "-oc") == 0) + { + cmd_options->output_to_buffer = 1; + cmd_options->output_to_buffer_exec_cmd = 1; cmd_options->new_buffer = 0; } else if (weechat_strcasecmp (argv[i], "-n") == 0) { cmd_options->output_to_buffer = 0; + cmd_options->output_to_buffer_exec_cmd = 0; cmd_options->new_buffer = 1; } else if (weechat_strcasecmp (argv[i], "-nf") == 0) { cmd_options->output_to_buffer = 0; + cmd_options->output_to_buffer_exec_cmd = 0; cmd_options->new_buffer = 2; } else if (weechat_strcasecmp (argv[i], "-cl") == 0) @@ -409,6 +419,7 @@ exec_command_run (struct t_gui_buffer *buffer, cmd_options.ptr_buffer_name = NULL; cmd_options.ptr_buffer = buffer; cmd_options.output_to_buffer = 0; + cmd_options.output_to_buffer_exec_cmd = 0; cmd_options.new_buffer = 0; cmd_options.new_buffer_clear = 0; cmd_options.switch_to_buffer = 1; @@ -435,12 +446,12 @@ exec_command_run (struct t_gui_buffer *buffer, if (!exec_command_parse_options (&cmd_options, argc, argv, start_arg, 1)) return WEECHAT_RC_ERROR; - /* options "-bg" and "-o"/"-n" are incompatible */ + /* options "-bg" and "-o"/"-oc"/"-n" are incompatible */ if (cmd_options.detached && (cmd_options.output_to_buffer || cmd_options.new_buffer)) return WEECHAT_RC_ERROR; - /* options "-pipe" and "-bg"/"-o"/"-n" are incompatible */ + /* options "-pipe" and "-bg"/"-o"/"-oc"/"-n" are incompatible */ if (cmd_options.pipe_command && (cmd_options.detached || cmd_options.output_to_buffer || cmd_options.new_buffer)) @@ -494,6 +505,7 @@ exec_command_run (struct t_gui_buffer *buffer, { /* output in a new buffer using given name */ new_exec_cmd->output_to_buffer = 0; + new_exec_cmd->output_to_buffer_exec_cmd = 0; snprintf (str_buffer, sizeof (str_buffer), "exec.%s", cmd_options.ptr_buffer_name); ptr_new_buffer = exec_buffer_new (str_buffer, @@ -544,10 +556,12 @@ exec_command_run (struct t_gui_buffer *buffer, EXEC_PLUGIN_NAME) == 0)) { cmd_options.output_to_buffer = 0; + cmd_options.output_to_buffer_exec_cmd = 0; cmd_options.new_buffer = 1; } } new_exec_cmd->output_to_buffer = cmd_options.output_to_buffer; + new_exec_cmd->output_to_buffer_exec_cmd = cmd_options.output_to_buffer_exec_cmd; new_exec_cmd->line_numbers = (cmd_options.line_numbers < 0) ? cmd_options.new_buffer : cmd_options.line_numbers; new_exec_cmd->color = cmd_options.color; @@ -808,7 +822,10 @@ exec_command_init () "buffer is not found, a new buffer with name \"exec.exec.xxx\" is " "created)\n" " -l: display locally output of command on buffer (default)\n" - " -o: send output of command to the buffer " + " -o: send output of command to the buffer without executing " + "commands (not compatible with option -bg)\n" + " -oc: send output of command to the buffer and execute commands " + "(lines starting with \"/\" or another custom command char) " "(not compatible with option -bg)\n" " -n: display output of command in a new buffer (not compatible " "with option -bg)\n" diff --git a/src/plugins/exec/exec-command.h b/src/plugins/exec/exec-command.h index d2506307c..06be3ae4a 100644 --- a/src/plugins/exec/exec-command.h +++ b/src/plugins/exec/exec-command.h @@ -30,6 +30,7 @@ struct t_exec_cmd_options const char *ptr_buffer_name; /* name of buffer */ struct t_gui_buffer *ptr_buffer; /* pointer to buffer */ int output_to_buffer; /* 1 if output is sent to buffer */ + int output_to_buffer_exec_cmd; /* execute commands found */ int new_buffer; /* 1=new buffer, 2=new buf. free cont*/ int new_buffer_clear; /* 1 to clear buffer before output */ int switch_to_buffer; /* switch to the output buffer */ diff --git a/src/plugins/exec/exec.c b/src/plugins/exec/exec.c index 05fb97ae4..1df680da9 100644 --- a/src/plugins/exec/exec.c +++ b/src/plugins/exec/exec.c @@ -152,6 +152,7 @@ exec_add () new_exec_cmd->start_time = time (NULL); new_exec_cmd->end_time = 0; new_exec_cmd->output_to_buffer = 0; + new_exec_cmd->output_to_buffer_exec_cmd = 0; new_exec_cmd->buffer_full_name = NULL; new_exec_cmd->line_numbers = 0; new_exec_cmd->display_rc = 0; @@ -204,6 +205,8 @@ exec_timer_delete_cb (const void *pointer, void *data, int remaining_calls) * Decodes colors in a string (from stdout/stderr). * * Returns string with colors as-is, decoded or removed. + * + * Note: result must be freed after use. */ char * @@ -249,7 +252,8 @@ void exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, int out, const char *line) { - char *line_color, *line2, str_number[32], str_tags[1024]; + char *line_color, *line_color2, *line2, str_number[32], str_tags[1024]; + const char *ptr_line_color; int length; if (!exec_cmd || !line) @@ -311,7 +315,31 @@ exec_display_line (struct t_exec_cmd *exec_cmd, struct t_gui_buffer *buffer, } } else - weechat_command (buffer, (line_color[0]) ? line_color : " "); + { + if (exec_cmd->output_to_buffer_exec_cmd) + ptr_line_color = line_color; + else + ptr_line_color = weechat_string_input_for_buffer (line_color); + + if (ptr_line_color) + { + weechat_command (buffer, + (ptr_line_color[0]) ? ptr_line_color : " "); + } + else + { + length = 1 + strlen (line_color) + 1; + line_color2 = malloc (length); + if (line_color2) + { + snprintf (line_color2, length, "%c%s", + line_color[0], line_color); + weechat_command (buffer, + (line_color2[0]) ? line_color2 : " "); + free (line_color2); + } + } + } } else { @@ -657,28 +685,29 @@ exec_print_log () { weechat_log_printf (""); weechat_log_printf ("[exec command (addr:0x%lx)]", ptr_exec_cmd); - weechat_log_printf (" number. . . . . . . . . : %d", ptr_exec_cmd->number); - weechat_log_printf (" name. . . . . . . . . . : '%s'", ptr_exec_cmd->name); - weechat_log_printf (" hook. . . . . . . . . . : 0x%lx", ptr_exec_cmd->hook); - weechat_log_printf (" command . . . . . . . . : '%s'", ptr_exec_cmd->command); - weechat_log_printf (" pid . . . . . . . . . . : %d", ptr_exec_cmd->pid); - weechat_log_printf (" detached. . . . . . . . : %d", ptr_exec_cmd->detached); - weechat_log_printf (" start_time. . . . . . . : %ld", ptr_exec_cmd->start_time); - weechat_log_printf (" end_time. . . . . . . . : %ld", ptr_exec_cmd->end_time); - weechat_log_printf (" output_to_buffer. . . . : %d", ptr_exec_cmd->output_to_buffer); - weechat_log_printf (" buffer_full_name. . . . : '%s'", ptr_exec_cmd->buffer_full_name); - weechat_log_printf (" line_numbers. . . . . . : %d", ptr_exec_cmd->line_numbers); - weechat_log_printf (" display_rc. . . . . . . : %d", ptr_exec_cmd->display_rc); - weechat_log_printf (" output_line_nb. . . . . : %d", ptr_exec_cmd->output_line_nb); - weechat_log_printf (" output_size[stdout] . . : %d", ptr_exec_cmd->output_size[EXEC_STDOUT]); - weechat_log_printf (" output[stdout]. . . . . : '%s'", ptr_exec_cmd->output[EXEC_STDOUT]); - weechat_log_printf (" output_size[stderr] . . : %d", ptr_exec_cmd->output_size[EXEC_STDERR]); - weechat_log_printf (" output[stderr]. . . . . : '%s'", ptr_exec_cmd->output[EXEC_STDERR]); - weechat_log_printf (" return_code . . . . . . : %d", ptr_exec_cmd->return_code); - weechat_log_printf (" pipe_command. . . . . . : '%s'", ptr_exec_cmd->pipe_command); - weechat_log_printf (" hsignal . . . . . . . . : '%s'", ptr_exec_cmd->hsignal); - weechat_log_printf (" prev_cmd. . . . . . . . : 0x%lx", ptr_exec_cmd->prev_cmd); - weechat_log_printf (" next_cmd. . . . . . . . : 0x%lx", ptr_exec_cmd->next_cmd); + weechat_log_printf (" number. . . . . . . . . . : %d", ptr_exec_cmd->number); + weechat_log_printf (" name. . . . . . . . . . . : '%s'", ptr_exec_cmd->name); + weechat_log_printf (" hook. . . . . . . . . . . : 0x%lx", ptr_exec_cmd->hook); + weechat_log_printf (" command . . . . . . . . . : '%s'", ptr_exec_cmd->command); + weechat_log_printf (" pid . . . . . . . . . . . : %d", ptr_exec_cmd->pid); + weechat_log_printf (" detached. . . . . . . . . : %d", ptr_exec_cmd->detached); + weechat_log_printf (" start_time. . . . . . . . : %ld", ptr_exec_cmd->start_time); + weechat_log_printf (" end_time. . . . . . . . . : %ld", ptr_exec_cmd->end_time); + weechat_log_printf (" output_to_buffer. . . . . : %d", ptr_exec_cmd->output_to_buffer); + weechat_log_printf (" output_to_buffer_exec_cmd : %d", ptr_exec_cmd->output_to_buffer_exec_cmd); + weechat_log_printf (" buffer_full_name. . . . . : '%s'", ptr_exec_cmd->buffer_full_name); + weechat_log_printf (" line_numbers. . . . . . . : %d", ptr_exec_cmd->line_numbers); + weechat_log_printf (" display_rc. . . . . . . . : %d", ptr_exec_cmd->display_rc); + weechat_log_printf (" output_line_nb. . . . . . : %d", ptr_exec_cmd->output_line_nb); + weechat_log_printf (" output_size[stdout] . . . : %d", ptr_exec_cmd->output_size[EXEC_STDOUT]); + weechat_log_printf (" output[stdout]. . . . . . : '%s'", ptr_exec_cmd->output[EXEC_STDOUT]); + weechat_log_printf (" output_size[stderr] . . . : %d", ptr_exec_cmd->output_size[EXEC_STDERR]); + weechat_log_printf (" output[stderr]. . . . . . : '%s'", ptr_exec_cmd->output[EXEC_STDERR]); + weechat_log_printf (" return_code . . . . . . . : %d", ptr_exec_cmd->return_code); + weechat_log_printf (" pipe_command. . . . . . . : '%s'", ptr_exec_cmd->pipe_command); + weechat_log_printf (" hsignal . . . . . . . . . : '%s'", ptr_exec_cmd->hsignal); + weechat_log_printf (" prev_cmd. . . . . . . . . : 0x%lx", ptr_exec_cmd->prev_cmd); + weechat_log_printf (" next_cmd. . . . . . . . . : 0x%lx", ptr_exec_cmd->next_cmd); } } diff --git a/src/plugins/exec/exec.h b/src/plugins/exec/exec.h index f1c781991..d034befe4 100644 --- a/src/plugins/exec/exec.h +++ b/src/plugins/exec/exec.h @@ -53,6 +53,7 @@ struct t_exec_cmd /* display */ int output_to_buffer; /* 1 if output is sent to buffer */ + int output_to_buffer_exec_cmd; /* 1 if commands are executed */ char *buffer_full_name; /* buffer where output is displayed */ int line_numbers; /* 1 if lines numbers are displayed */ int color; /* what to do with ANSI colors */ |