diff mcabber/src/hooks.c @ 524:05c0e55c4bb1

Pass message body to external command Introduce 2 new options: event_log_files & event_log_dir
author Mikael Berthe <mikael@lilotux.net>
date Sun, 20 Nov 2005 00:08:49 +0100
parents e5008032edb8
children 56f641155579
line wrap: on
line diff
--- 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 <sys/types.h>
 #include <unistd.h>
+#include <stdlib.h>
 
 #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);
 }
-