17 * along with this program; if not, write to the Free Software |
17 * along with this program; if not, write to the Free Software |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 * USA |
19 * USA |
20 */ |
20 */ |
21 |
21 |
|
22 #include <sys/types.h> |
|
23 #include <unistd.h> |
22 #include <screen.h> |
24 #include <screen.h> |
23 |
25 |
24 #include "hooks.h" |
26 #include "hooks.h" |
25 #include "roster.h" |
27 #include "roster.h" |
26 #include "histolog.h" |
28 #include "histolog.h" |
27 #include "utf8.h" |
29 #include "utf8.h" |
28 |
30 |
|
31 static char *extcommand; |
29 |
32 |
30 inline void hk_message_in(const char *jid, time_t timestamp, const char *msg) |
33 inline void hk_message_in(const char *jid, time_t timestamp, const char *msg) |
31 { |
34 { |
32 char *buffer = utf8_decode(msg); |
35 char *buffer = utf8_decode(msg); |
33 int new_guy = FALSE; |
36 int new_guy = FALSE; |
38 new_guy = TRUE; |
41 new_guy = TRUE; |
39 } |
42 } |
40 |
43 |
41 scr_WriteIncomingMessage(jid, buffer); |
44 scr_WriteIncomingMessage(jid, buffer); |
42 hlog_write_message(jid, timestamp, FALSE, buffer); |
45 hlog_write_message(jid, timestamp, FALSE, buffer); |
|
46 hk_ext_cmd(jid, 'M', 'R', NULL); |
43 free(buffer); |
47 free(buffer); |
44 // We need to rebuild the list if the sender is unknown or |
48 // We need to rebuild the list if the sender is unknown or |
45 // if the sender is offline/invisible and hide_offline_buddies is set |
49 // if the sender is offline/invisible and hide_offline_buddies is set |
46 if (new_guy || |
50 if (new_guy || |
47 (roster_getstatus(jid) == offline && buddylist_get_hide_offline_buddies())) |
51 (roster_getstatus(jid) == offline && buddylist_get_hide_offline_buddies())) |
77 scr_LogPrint("Your status has changed: [%c>%c]", |
81 scr_LogPrint("Your status has changed: [%c>%c]", |
78 imstatus2char[old_status], imstatus2char[new_status]); |
82 imstatus2char[old_status], imstatus2char[new_status]); |
79 //hlog_write_status(NULL, 0, status); |
83 //hlog_write_status(NULL, 0, status); |
80 } |
84 } |
81 |
85 |
|
86 |
|
87 /* External commands */ |
|
88 |
|
89 // hk_ext_cmd_init() |
|
90 // Initialize external command variable. |
|
91 // Can be called with parameter NULL to reset and free memory. |
|
92 void hk_ext_cmd_init(char *command) |
|
93 { |
|
94 if (extcommand) { |
|
95 g_free(extcommand); |
|
96 extcommand = NULL; |
|
97 } |
|
98 if (command) |
|
99 extcommand = g_strdup(command); |
|
100 } |
|
101 |
|
102 // hk_ext_cmd() |
|
103 // Launch an external command (process) for the given event. |
|
104 // For now, data should be NULL. |
|
105 void hk_ext_cmd(const char *jid, guchar type, guchar info, const char *data) |
|
106 { |
|
107 pid_t pid; |
|
108 |
|
109 if (!extcommand) return; |
|
110 |
|
111 // For now we'll only handle incoming messages |
|
112 if (type != 'M') return; |
|
113 if (info != 'R') return; |
|
114 |
|
115 if ((pid=fork()) == -1) { |
|
116 scr_LogPrint("Fork error, cannot launch external command."); |
|
117 return; |
|
118 } |
|
119 |
|
120 // I don't remember what I should do with the parent process... |
|
121 if (pid == 0) { // child |
|
122 if (execl(extcommand, extcommand, "MSG", "IN", jid, NULL) == -1) { |
|
123 // ut_WriteLog("Cannot execute external command.\n"); |
|
124 exit(1); |
|
125 } |
|
126 } |
|
127 } |
|
128 |