[/trunk] Changeset 172 by mikael
* External command for events.
* Add a config file option "events_command".
* TODO update.
--- a/mcabber/mcabberrc.example Mon May 02 09:33:32 2005 +0000
+++ b/mcabber/mcabberrc.example Mon May 02 12:07:46 2005 +0000
@@ -27,7 +27,14 @@
# You can save the messages history: set logging = 1
# Default logging directory (logging_dir) is $HOME/.mcabber/
logging = 1
-# logging_dir = /home/mikael/.mcabber/
+#logging_dir = /home/mikael/.mcabber/
+
+# External command for events
+# You can specify a script or process to be launched when an event occurs.
+# For now it is called the following way:
+# $events_command MSG IN jabber@id
+# ... when receiving a message.
+#events_command = /home/mikael/.mcabber/eventcmd
# Debug logging
# If you want advanced debug, please specify a file here.
@@ -46,3 +53,4 @@
color_jidofflineselected = red
color_jidoffline = red
color_text = white
+
--- a/mcabber/src/TODO Mon May 02 09:33:32 2005 +0000
+++ b/mcabber/src/TODO Mon May 02 12:07:46 2005 +0000
@@ -2,9 +2,7 @@
BUGS:
* Presence notification is always accepted.
-* I have seen a segfault, but don't know how to reproduce it...
- Seems to be due to a disconnection from the server.
-* Check with strdup and efence (jabglue). J'me comprends...
+* Empty roster when disconnecting from the server / going offline.
* Check if it crashes when resized too small...
* See if we can use wbkgndset()
@@ -12,7 +10,6 @@
TODO:
* Command line history (^P/^N)
-* External commands for events
* Read history
* Display status
* show (how?) we can scroll in roster if not all buddies are displayed
--- a/mcabber/src/hooks.c Mon May 02 09:33:32 2005 +0000
+++ b/mcabber/src/hooks.c Mon May 02 12:07:46 2005 +0000
@@ -19,6 +19,8 @@
* USA
*/
+#include <sys/types.h>
+#include <unistd.h>
#include <screen.h>
#include "hooks.h"
@@ -26,6 +28,7 @@
#include "histolog.h"
#include "utf8.h"
+static char *extcommand;
inline void hk_message_in(const char *jid, time_t timestamp, const char *msg)
{
@@ -40,6 +43,7 @@
scr_WriteIncomingMessage(jid, buffer);
hlog_write_message(jid, timestamp, FALSE, buffer);
+ hk_ext_cmd(jid, 'M', 'R', NULL);
free(buffer);
// We need to rebuild the list if the sender is unknown or
// if the sender is offline/invisible and hide_offline_buddies is set
@@ -79,3 +83,46 @@
//hlog_write_status(NULL, 0, status);
}
+
+/* External commands */
+
+// hk_ext_cmd_init()
+// Initialize external command variable.
+// Can be called with parameter NULL to reset and free memory.
+void hk_ext_cmd_init(char *command)
+{
+ if (extcommand) {
+ g_free(extcommand);
+ extcommand = NULL;
+ }
+ if (command)
+ extcommand = g_strdup(command);
+}
+
+// hk_ext_cmd()
+// Launch an external command (process) for the given event.
+// For now, data should be NULL.
+void hk_ext_cmd(const char *jid, guchar type, guchar info, const char *data)
+{
+ pid_t pid;
+
+ if (!extcommand) return;
+
+ // For now we'll only handle incoming messages
+ if (type != 'M') return;
+ if (info != 'R') return;
+
+ if ((pid=fork()) == -1) {
+ scr_LogPrint("Fork error, cannot launch external command.");
+ return;
+ }
+
+ // I don't remember what I should do with the parent process...
+ if (pid == 0) { // child
+ if (execl(extcommand, extcommand, "MSG", "IN", jid, NULL) == -1) {
+ // ut_WriteLog("Cannot execute external command.\n");
+ exit(1);
+ }
+ }
+}
+
--- a/mcabber/src/hooks.h Mon May 02 09:33:32 2005 +0000
+++ b/mcabber/src/hooks.h Mon May 02 12:07:46 2005 +0000
@@ -12,4 +12,7 @@
inline void hk_mystatuschange(time_t timestamp,
enum imstatus old_status, enum imstatus new_status);
+void hk_ext_cmd_init(char *command);
+void hk_ext_cmd(const char *jid, guchar type, guchar info, const char *data);
+
#endif /* __HOOKS_H__ */
--- a/mcabber/src/main.c Mon May 02 09:33:32 2005 +0000
+++ b/mcabber/src/main.c Mon May 02 12:07:46 2005 +0000
@@ -157,6 +157,9 @@
if (optstring && (atoi(optstring) > 0))
hlog_enable(TRUE, cfg_read("logging_dir"));
+ if ((optstring = cfg_read("events_command")) != NULL)
+ hk_ext_cmd_init(optstring);
+
ssl = 0;
optstring = cfg_read("ssl");
if (optstring && (atoi(optstring) > 0))