===== faxd/Trigger.c++ 1.3 vs edited =====
--- 1.3/faxd/Trigger.c++	2007-02-13 11:28:02 -05:00
+++ edited/faxd/Trigger.c++	2007-02-13 11:27:09 -05:00
@@ -407,6 +407,7 @@ Trigger::post(TriggerEvent e, const Job&
 	    msg.put(info);
 	post(e, job.triggers, any, msg);
     }
+    hook(e, job.jobid, info);
 }
 void
 Trigger::post(TriggerEvent e, const Modem& modem, const char* info)
@@ -421,4 +422,50 @@ Trigger::post(TriggerEvent e, const Mode
 	    modem.encode(msg);
 	post(e, modem.triggers, any, msg);
     }
+    hook(e, modem.devID, info);
 }
+
+
+u_short Trigger::hookInterests[TRIGGER_MAXEVENT>>4];
+fxStr Trigger::hookCmd;
+
+void
+Trigger::hook (TriggerEvent e, const char* id, const char* info)
+{
+    static const char* classNames[4] = { "JOB", "SEND", "RECV", "MODEM" };
+    u_short mask = 1<<(e&15);
+    if (hookInterests[e>>4] & mask)
+    {
+	fxStr cmd = fxStr::format("%s %s 0x%04x \"%s\"",
+		(const char*)hookCmd, classNames[EventClass(e)], mask, id);
+	if (info)
+		cmd.append(fxStr::format(" \"%s\"", info));
+	logInfo("HOOK CMD %s", (const char*)cmd);
+	faxApp::runCmd(cmd);
+    }
+}
+
+
+bool
+Trigger::setTriggerHook (const char* prg, const char* spec)
+{
+    TriggerEvent hookTID = tidNextFree();
+
+    if (hookTID == TRIGGER_MAXTID) {
+	logError("TRIGGER: tid table overflow for EVENT");
+	return false;
+    }
+
+    Trigger* event = new Trigger(hookTID, "/dev/null");
+    if (!event->parse(spec))
+    {
+        logWarning("TRIGGER EVENT: Couldn't parse spec: %s", spec);
+    }
+
+    memcpy(hookInterests, event->interests, sizeof(hookInterests));
+    event->cancel();
+    delete event;
+    hookCmd = prg;
+}
+
+
===== faxd/Trigger.h 1.2 vs edited =====
--- 1.2/faxd/Trigger.h	2007-02-13 11:28:02 -05:00
+++ edited/faxd/Trigger.h	2007-02-13 11:27:10 -05:00
@@ -136,6 +136,9 @@ private:
     static u_int tidRotor;
     static trid_t tidNextFree();
 
+    static u_short hookInterests[TRIGGER_MAXEVENT>>4];	// bitmask of hook interests
+    static fxStr hookCmd;
+
     friend class TriggerRef;		// for access to reference count
 
     Trigger(trid_t, const fxStr& fifoName);
@@ -148,6 +151,8 @@ private:
 
     static void post(TriggerEvent, const QLink&, const QLink&, fxStackBuffer&);
     void send(const char* fmt ...);
+
+    static void hook (TriggerEvent, const char* id, const char* info);
 public:
     ~Trigger();
 
@@ -158,5 +163,7 @@ public:
 
     static void post(TriggerEvent, const Job&, const char* = NULL);
     static void post(TriggerEvent, const Modem&, const char* = NULL);
+
+    static bool setTriggerHook (const char* prg, const char* spec);
 };
 #endif /* _Trigger_ */
===== faxd/faxApp.h 1.5 vs edited =====
--- 1.5/faxd/faxApp.h	2007-02-13 11:28:02 -05:00
+++ edited/faxd/faxApp.h	2007-02-13 11:27:10 -05:00
@@ -80,7 +80,7 @@ public:
     static const fxStr quote;
     static const fxStr enquote;
 
-    bool runCmd(const char* cmd, bool changeIDs = false, IOHandler* waiter = NULL);
+    static bool runCmd(const char* cmd, bool changeIDs = false, IOHandler* waiter = NULL);
 };
 inline bool faxApp::isRunning(void) const	{ return running; }
 
===== faxd/faxQueueApp.c++ 1.90 vs edited =====
--- 1.90/faxd/faxQueueApp.c++	2007-02-13 11:28:02 -05:00
+++ edited/faxd/faxQueueApp.c++	2007-02-13 11:27:48 -05:00
@@ -152,6 +152,7 @@ faxQueueApp::initialize(int argc, char**
 void
 faxQueueApp::open()
 {
+//    Trigger::setTriggerHook("bin/hook", "J*M*R*S*");
     faxApp::open();
     scanQueueDirectory();
     Modem::broadcast("HELLO");		// announce queuer presence
@@ -3302,7 +3303,24 @@ faxQueueApp::setConfigItem(const char* t
 	    pageChop = FaxRequest::chop_last;
     } else if (streq(tag, "pagechopthreshold"))
 	pageChopThreshold = atof(value);
-    else
+    else if (streq(tag, "audithook") )
+    {
+        const char* cp;
+	for (cp = value; *cp && *cp != ':'; cp++)
+	    ;
+	if (*cp == ':') {
+	    fxStr cmd(value, cp-value);
+	    for (cp++; *cp && isspace(*cp); cp++)
+		;
+	    if (*cp != '\0') {
+	    	Trigger::setTriggerHook(cmd, cp);
+	    } else
+		configError("No trigger specification for audit hook");
+	} else
+	    configError("Missing ':' separator in audit hook specification");
+	
+    	
+    } else
 	return (false);
     return (true);
 }
