# HG changeset patch # User Mikael Berthe # Date 1132441729 -3600 # Node ID 05c0e55c4bb1573869c9ee6d6bded66c78ebf29d # Parent fc6bc26f891e16ef179405f38e98eed2c93ed3df Pass message body to external command Introduce 2 new options: event_log_files & event_log_dir diff -r fc6bc26f891e -r 05c0e55c4bb1 mcabber/src/hooks.c --- a/mcabber/src/hooks.c Sat Nov 19 18:12:37 2005 +0100 +++ b/mcabber/src/hooks.c Sun Nov 20 00:08:49 2005 +0100 @@ -21,6 +21,7 @@ #include #include +#include #include "hooks.h" #include "screen.h" @@ -28,6 +29,7 @@ #include "histolog.h" #include "hbuf.h" #include "settings.h" +#include "utils.h" static char *extcmd; @@ -101,7 +103,7 @@ // - We do not call hk_ext_cmd() for history lines in MUC // - We do call hk_ext_cmd() for private messages in a room if ((is_groupchat && !timestamp) || !is_groupchat) - hk_ext_cmd(jid, (is_groupchat ? 'G' : 'M'), 'R', NULL); + hk_ext_cmd(jid, (is_groupchat ? 'G' : 'M'), 'R', wmsg); // We need to rebuild the list if the sender is unknown or // if the sender is offline/invisible and hide_offline_buddies is set @@ -233,6 +235,7 @@ char *arg_info = NULL; char *arg_data = NULL; char status_str[2]; + char *datafname = NULL; if (!extcmd) return; @@ -263,8 +266,31 @@ if (!arg_type || !arg_info) return; + if (strchr("MG", type) && data && settings_opt_get_int("event_log_files")) { + int fd; + const char *prefix; + prefix = settings_opt_get("event_log_dir"); + if (!prefix) + prefix = ut_get_tmpdir(); + datafname = g_strdup_printf("%s/mcabber-%d.XXXXXX", prefix, getpid()); + // XXX Some old systems may require us to set umask first. + fd = mkstemp(datafname); + if (fd == -1) { + g_free(datafname); + datafname = NULL; + scr_LogPrint(LPRINT_LOGNORM, + "Unable to create temp file for external command."); + } + write(fd, data, strlen(data)); + write(fd, "\n", 1); + close(fd); + arg_data = datafname; + } + if ((pid=fork()) == -1) { scr_LogPrint(LPRINT_LOGNORM, "Fork error, cannot launch external command."); + if (datafname) + g_free(datafname); return; } @@ -274,5 +300,6 @@ exit(1); } } + if (datafname) + g_free(datafname); } - diff -r fc6bc26f891e -r 05c0e55c4bb1 mcabber/src/utils.c --- a/mcabber/src/utils.c Sat Nov 19 18:12:37 2005 +0100 +++ b/mcabber/src/utils.c Sun Nov 20 00:08:49 2005 +0100 @@ -145,6 +145,28 @@ return 0; } +const char *ut_get_tmpdir(void) +{ + static const char *tmpdir; + const char *tmpvars[] = { "MCABBERTMPDIR", "TMP", "TMPDIR", "TEMP" }; + int i; + + if (tmpdir) + return tmpdir; + + for (i = 0; i < (sizeof(tmpvars) / sizeof(const char *)); i++) { + tmpdir = getenv(tmpvars[i]); + if (tmpdir && tmpdir[0] && tmpdir[0] == '/' && tmpdir[1]) { + // Looks ok. + return tmpdir; + } + } + + // Default temporary directory + tmpdir = "/tmp"; + return tmpdir; +} + // to_iso8601(dststr, timestamp) // Convert timestamp to iso8601 format, and store it in dststr. // NOTE: dststr should be at last 19 chars long. diff -r fc6bc26f891e -r 05c0e55c4bb1 mcabber/src/utils.h --- a/mcabber/src/utils.h Sat Nov 19 18:12:37 2005 +0100 +++ b/mcabber/src/utils.h Sun Nov 20 00:08:49 2005 +0100 @@ -9,6 +9,8 @@ int checkset_perm(const char *name, unsigned int setmode); +const char *ut_get_tmpdir(void); + int to_iso8601(char *dststr, time_t timestamp); time_t from_iso8601(const char *timestamp, int utc);