diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-07-25 15:43:16 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-07-25 15:43:16 +0800 |
commit | e5cd4631f66e182c67bfb45df3f8a04f08761ce2 (patch) | |
tree | 1ee68a67c6ddc8e8bd7551c4627ca889d1f11fe8 | |
parent | d60d21300924fad507d812edca3de30074b52e02 (diff) | |
download | gsoc2013-evolution-e5cd4631f66e182c67bfb45df3f8a04f08761ce2.tar gsoc2013-evolution-e5cd4631f66e182c67bfb45df3f8a04f08761ce2.tar.gz gsoc2013-evolution-e5cd4631f66e182c67bfb45df3f8a04f08761ce2.tar.bz2 gsoc2013-evolution-e5cd4631f66e182c67bfb45df3f8a04f08761ce2.tar.lz gsoc2013-evolution-e5cd4631f66e182c67bfb45df3f8a04f08761ce2.tar.xz gsoc2013-evolution-e5cd4631f66e182c67bfb45df3f8a04f08761ce2.tar.zst gsoc2013-evolution-e5cd4631f66e182c67bfb45df3f8a04f08761ce2.zip |
Renamed from shell_exec(). Also, we now want to pass argc/argv on to the
2002-07-25 Jeffrey Stedfast <fejj@ximian.com>
* camel-filter-driver.c (do_shell): Renamed from
shell_exec(). Also, we now want to pass argc/argv on to the
CamelFilterDriverShellFunc.
(camel_filter_driver_set_shell_func): Renamed a bit.
* camel-filter-search.c (pipe_message): Renamed from shell_exec().
svn path=/trunk/; revision=17583
-rw-r--r-- | camel/ChangeLog | 8 | ||||
-rw-r--r-- | camel/camel-filter-driver.c | 48 | ||||
-rw-r--r-- | camel/camel-filter-driver.h | 14 | ||||
-rw-r--r-- | camel/camel-filter-search.c | 21 |
4 files changed, 64 insertions, 27 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 12ab8454cf..24fdb1bdc6 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,7 +1,11 @@ 2002-07-25 Jeffrey Stedfast <fejj@ximian.com> - * camel-filter-search.c (run_command): Use execv ("sh", "-c", - command) rather than execing the command directly. + * camel-filter-driver.c (do_shell): Renamed from + shell_exec(). Also, we now want to pass argc/argv on to the + CamelFilterDriverShellFunc. + (camel_filter_driver_set_shell_func): Renamed a bit. + + * camel-filter-search.c (pipe_message): Renamed from shell_exec(). 2002-07-25 Not Zed <NotZed@Ximian.com> diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c index dea33852de..09b138f99b 100644 --- a/camel/camel-filter-driver.c +++ b/camel/camel-filter-driver.c @@ -20,6 +20,7 @@ * Boston, MA 02111-1307, USA. */ + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -77,8 +78,8 @@ struct _CamelFilterDriverPrivate { CamelFilterStatusFunc *statusfunc; /* status callback */ void *statusdata; /* status callback data */ - CamelFilterShellExecFunc *execfunc; /* execute shell command callback */ - void *execdata; /* execute shell command callback data */ + CamelFilterShellFunc *shellfunc; /* execute shell command callback */ + void *shelldata; /* execute shell command callback data */ CamelFilterPlaySoundFunc *playfunc; /* play-sound command callback */ void *playdata; /* play-sound command callback data */ @@ -134,7 +135,7 @@ static ESExpResult *do_stop (struct _ESExp *f, int argc, struct _ESExpResult **a static ESExpResult *do_colour (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *do_score (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *do_flag (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); -static ESExpResult *shell_exec (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); +static ESExpResult *do_shell (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *do_beep (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *play_sound (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); static ESExpResult *do_only_once (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *); @@ -154,7 +155,7 @@ static struct { { "set-colour", (ESExpFunc *) do_colour, 0 }, { "set-score", (ESExpFunc *) do_score, 0 }, { "set-system-flag", (ESExpFunc *) do_flag, 0 }, - { "shell-exec", (ESExpFunc *) shell_exec, 0 }, + { "shell", (ESExpFunc *) do_shell, 0 }, { "beep", (ESExpFunc *) do_beep, 0 }, { "play-sound", (ESExpFunc *) play_sound, 0 }, { "only-once", (ESExpFunc *) do_only_once, 0 } @@ -295,12 +296,12 @@ camel_filter_driver_set_status_func (CamelFilterDriver *d, CamelFilterStatusFunc } void -camel_filter_driver_set_shell_exec_func (CamelFilterDriver *d, CamelFilterShellExecFunc *func, void *data) +camel_filter_driver_set_shell_func (CamelFilterDriver *d, CamelFilterShellFunc *func, void *data) { struct _CamelFilterDriverPrivate *p = _PRIVATE (d); - p->execfunc = func; - p->execdata = data; + p->shellfunc = func; + p->shelldata = data; } void @@ -606,18 +607,43 @@ do_flag (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriv } static ESExpResult * -shell_exec (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *driver) +do_shell (struct _ESExp *f, int argc, struct _ESExpResult **argv, CamelFilterDriver *driver) { struct _CamelFilterDriverPrivate *p = _PRIVATE (driver); + GString *command; + GPtrArray *args; + int i; d(fprintf (stderr, "executing shell command\n")); - if (p->execfunc && argc == 1 && argv[0]->type == ESEXP_RES_STRING) { - p->execfunc (driver, argv[0]->value.string, p->execdata); + command = g_string_new (""); + + args = g_ptr_array_new (); + + /* make sure all args are strings */ + for (i = 0; i < argc; i++) { + if (argv[i]->type != ESEXP_RES_STRING) + goto done; + + g_ptr_array_add (args, argv[i]->value.string); + + g_string_append (command, argv[i]->value.string); + g_string_append_c (command, ' '); + } + + g_string_truncate (command, command->len - 1); + + if (p->shellfunc && argc >= 1) { + p->shellfunc (driver, argc, (char **) args->pdata, p->shelldata); camel_filter_driver_log (driver, FILTER_LOG_ACTION, "Executing shell command: [%s]", - argv[0]->value.string); + command->str); } + done: + + g_ptr_array_free (args, TRUE); + g_string_free (command, TRUE); + return NULL; } diff --git a/camel/camel-filter-driver.h b/camel/camel-filter-driver.h index 3f86a47a33..36e3f902fb 100644 --- a/camel/camel-filter-driver.h +++ b/camel/camel-filter-driver.h @@ -33,16 +33,16 @@ extern "C" { #include <camel/camel-folder.h> #include <camel/camel-uid-cache.h> -#define CAMEL_FILTER_DRIVER_TYPE (camel_filter_driver_get_type()) -#define CAMEL_FILTER_DRIVER(obj) CAMEL_CHECK_CAST (obj, camel_filter_driver_get_type (), CamelFilterDriver) -#define CAMEL_FILTER_DRIVER_CLASS(klass) CAMEL__CHECK_CLASS_CAST (klass, camel_filter_driver_get_type (), CamelFilterDriverClass) -#define CAMEL_IS_FILTER_DRIVER(obj) CAMEL_CHECK_TYPE (obj, camel_filter_driver_get_type ()) +#define CAMEL_FILTER_DRIVER_TYPE (camel_filter_driver_get_type ()) +#define CAMEL_FILTER_DRIVER(obj) CAMEL_CHECK_CAST (obj, CAMEL_FILTER_DRIVER_TYPE, CamelFilterDriver) +#define CAMEL_FILTER_DRIVER_CLASS(klass) CAMEL__CHECK_CLASS_CAST (klass, CAMEL_FILTER_DRIVER_TYPE, CamelFilterDriverClass) +#define CAMEL_IS_FILTER_DRIVER(obj) CAMEL_CHECK_TYPE (obj, CAMEL_FILTER_DRIVER_TYPE) typedef struct _CamelFilterDriverClass CamelFilterDriverClass; struct _CamelFilterDriver { CamelObject parent; - + struct _CamelFilterDriverPrivate *priv; }; @@ -66,7 +66,7 @@ typedef CamelFolder * (*CamelFilterGetFolderFunc) (CamelFilterDriver *driver, co typedef void (CamelFilterStatusFunc) (CamelFilterDriver *driver, enum camel_filter_status_t status, int pc, const char *desc, void *data); -typedef void (CamelFilterShellExecFunc) (CamelFilterDriver *driver, const char *command, void *data); +typedef void (CamelFilterShellFunc) (CamelFilterDriver *driver, int argc, char **argv, void *data); typedef void (CamelFilterPlaySoundFunc) (CamelFilterDriver *driver, const char *filename, void *data); typedef void (CamelFilterSystemBeepFunc) (CamelFilterDriver *driver, void *data); @@ -77,7 +77,7 @@ CamelFilterDriver *camel_filter_driver_new (void); void camel_filter_driver_set_logfile (CamelFilterDriver *d, FILE *logfile); void camel_filter_driver_set_status_func (CamelFilterDriver *d, CamelFilterStatusFunc *func, void *data); -void camel_filter_driver_set_shell_exec_func (CamelFilterDriver *d, CamelFilterShellExecFunc *func, void *data); +void camel_filter_driver_set_shell_func (CamelFilterDriver *d, CamelFilterShellFunc *func, void *data); void camel_filter_driver_set_play_sound_func (CamelFilterDriver *d, CamelFilterPlaySoundFunc *func, void *data); void camel_filter_driver_set_system_beep_func (CamelFilterDriver *d, CamelFilterSystemBeepFunc *func, void *data); void camel_filter_driver_set_folder_func (CamelFilterDriver *d, CamelFilterGetFolderFunc fetcher, void *data); diff --git a/camel/camel-filter-search.c b/camel/camel-filter-search.c index 3bcb582fba..2f2fb52724 100644 --- a/camel/camel-filter-search.c +++ b/camel/camel-filter-search.c @@ -92,7 +92,7 @@ static ESExpResult *get_received_date (struct _ESExp *f, int argc, struct _ESExp static ESExpResult *get_current_date (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); static ESExpResult *get_source (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); static ESExpResult *get_size (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); -static ESExpResult *shell_exec (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); +static ESExpResult *pipe_message (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms); /* builtin functions */ static struct { @@ -120,7 +120,7 @@ static struct { { "get-current-date", (ESExpFunc *) get_current_date, 0 }, { "get-source", (ESExpFunc *) get_source, 0 }, { "get-size", (ESExpFunc *) get_size, 0 }, - { "shell-exec", (ESExpFunc *) shell_exec, 0 }, + { "pipe-message", (ESExpFunc *) pipe_message, 0 }, }; @@ -515,6 +515,7 @@ run_command (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessa if (!(pid = fork ())) { /* child process */ + GPtrArray *args; int maxfd, i; if (dup2 (in_fds[0], STDIN_FILENO) < 0) @@ -530,10 +531,16 @@ run_command (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessa } } - execv ("sh", "-c", argv[0]->value.string); + args = g_ptr_array_new (); + for (i = 0; i < argc; i++) + g_ptr_array_add (args, argv[i]->value.string); + g_ptr_array_add (args, NULL); - fprintf (stderr, "Could not execute %s: %s\n", argv[0]->value.string, - g_strerror (errno)); + execvp (argv[0]->value.string, (char **) args->pdata); + + g_ptr_array_free (args, TRUE); + + d(printf ("Could not execute %s: %s\n", argv[0]->value.string, g_strerror (errno))); _exit (255); } else if (pid < 0) { camel_exception_setv (fms->ex, CAMEL_EXCEPTION_SYSTEM, @@ -572,11 +579,11 @@ run_command (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessa if (result != -1 && WIFEXITED (status)) return WEXITSTATUS (status); else - return -1; + return -1; } static ESExpResult * -shell_exec (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms) +pipe_message (struct _ESExp *f, int argc, struct _ESExpResult **argv, FilterMessageSearch *fms) { ESExpResult *r; int retval, i; |