Mercurial > hg
annotate mcabber/src/hooks.c @ 510:6c3cd3aa4a91
New 'buddy_format' option
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 12 Nov 2005 17:36:20 +0100 |
parents | 21ab22a60bcb |
children | 979eb0fe2969 |
rev | line source |
---|---|
113 | 1 /* |
2 * hooks.c -- Hooks layer | |
393 | 3 * |
113 | 4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
160 | 22 #include <sys/types.h> |
23 #include <unistd.h> | |
113 | 24 |
25 #include "hooks.h" | |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
26 #include "screen.h" |
113 | 27 #include "roster.h" |
28 #include "histolog.h" | |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
29 #include "hbuf.h" |
477 | 30 #include "settings.h" |
113 | 31 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
32 static char *extcmd; |
113 | 33 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
34 inline void hk_message_in(const char *jid, const char *resname, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
35 time_t timestamp, const char *msg, const char *type) |
113 | 36 { |
141 | 37 int new_guy = FALSE; |
477 | 38 int is_groupchat = FALSE; // groupchat message |
39 int is_room = FALSE; // window is a room window | |
40 int log_muc_conf = FALSE; | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
41 int message_flags = 0; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
42 guint rtype = ROSTER_TYPE_USER; |
477 | 43 char *wmsg = NULL, *bmsg = NULL; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
44 GSList *roster_usr; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
45 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
46 if (type && !strcmp(type, "groupchat")) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
47 rtype = ROSTER_TYPE_ROOM; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
48 is_groupchat = TRUE; |
477 | 49 log_muc_conf = settings_opt_get_int("log_muc_conf"); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
50 if (!resname) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
51 message_flags = HBB_PREFIX_INFO; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
52 resname = ""; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
53 } |
477 | 54 wmsg = bmsg = g_strdup_printf("<%s> %s", resname, msg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
55 } else { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
56 wmsg = (char*) msg; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
57 } |
141 | 58 |
59 // If this user isn't in the roster, we add it | |
483
4a10c04ac2fb
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
479
diff
changeset
|
60 roster_usr = roster_find(jid, jidsearch, 0); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
61 if (!roster_usr) { |
141 | 62 new_guy = TRUE; |
477 | 63 roster_usr = roster_add_user(jid, NULL, NULL, rtype); |
64 if (!roster_usr) { // Shouldn't happen... | |
65 scr_LogPrint(LPRINT_LOGNORM, "ERROR: unable to add buddy!"); | |
66 if (bmsg) g_free(bmsg); | |
67 return; | |
68 } | |
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
485
diff
changeset
|
69 } else if (is_groupchat) { |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
485
diff
changeset
|
70 // Make sure the type is ROOM |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
485
diff
changeset
|
71 buddy_settype(roster_usr->data, ROSTER_TYPE_ROOM); |
477 | 72 } |
73 | |
74 is_room = !!(buddy_gettype(roster_usr->data) & ROSTER_TYPE_ROOM); | |
75 | |
76 if (!is_groupchat && is_room) { | |
77 // This is a private message from a room participant | |
479
b82428ac107d
resname can be a null pointer in sme cases
Mikael Berthe <mikael@lilotux.net>
parents:
477
diff
changeset
|
78 if (!resname) resname = ""; |
477 | 79 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", resname, msg); |
141 | 80 } |
81 | |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
82 if (type && !strcmp(type, "error")) { |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
83 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
84 scr_LogPrint(LPRINT_LOGNORM, "Error message received from <%s>", jid); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
85 } |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
86 |
178 | 87 // Note: the hlog_write should not be called first, because in some |
88 // cases scr_WriteIncomingMessage() will load the history and we'd | |
89 // have the message twice... | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
90 scr_WriteIncomingMessage(jid, wmsg, timestamp, message_flags); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
91 |
477 | 92 // - We don't log the message if it is an error message |
93 // - We don't log the message if it is a private conf. message | |
94 // - We don't log the message if it is groupchat message and the log_muc_conf | |
95 // option is off (and it is not a history line) | |
96 if (!(message_flags & HBB_PREFIX_ERR) && | |
97 (!is_room || (is_groupchat && log_muc_conf && !timestamp))) | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
98 hlog_write_message(jid, timestamp, FALSE, wmsg); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
99 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
100 // External command |
477 | 101 // - We do not call hk_ext_cmd() for history lines in MUC |
102 // - We do call hk_ext_cmd() for private messages in a room | |
103 if ((is_groupchat && !timestamp) || !is_groupchat) | |
458
33dc3ca6e9ca
Do not call external command for history lines in a MUC room
Mikael Berthe <mikael@lilotux.net>
parents:
453
diff
changeset
|
104 hk_ext_cmd(jid, (is_groupchat ? 'G' : 'M'), 'R', NULL); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
105 |
146 | 106 // We need to rebuild the list if the sender is unknown or |
107 // if the sender is offline/invisible and hide_offline_buddies is set | |
108 if (new_guy || | |
477 | 109 (buddy_getstatus(roster_usr->data, NULL) == offline && |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
110 buddylist_get_hide_offline_buddies())) |
146 | 111 { |
141 | 112 buddylist_build(); |
113 update_roster = TRUE; | |
114 } | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
115 |
477 | 116 if (bmsg) g_free(bmsg); |
113 | 117 } |
118 | |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
119 // hk_message_out() |
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
120 // nick should be set for private messages in a chat room, and null for |
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
121 // normal messages. |
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
122 inline void hk_message_out(const char *jid, const char *nick, |
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
123 time_t timestamp, const char *msg) |
113 | 124 { |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
125 char *wmsg = NULL, *bmsg = NULL; |
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
126 |
485 | 127 if (nick) wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", nick, msg); |
128 else wmsg = (char*)msg; | |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
129 |
485 | 130 // Note: the hlog_write should not be called first, because in some |
131 // cases scr_WriteOutgoingMessage() will load the history and we'd | |
132 // have the message twice... | |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
133 scr_WriteOutgoingMessage(jid, wmsg); |
485 | 134 |
135 // We don't log private messages | |
136 if (!nick) hlog_write_message(jid, timestamp, TRUE, msg); | |
137 | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
138 // External command |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
139 hk_ext_cmd(jid, 'M', 'S', NULL); |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
140 |
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
141 if (bmsg) g_free(bmsg); |
113 | 142 } |
143 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
144 inline void hk_statuschange(const char *jid, const char *resname, gchar prio, |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
145 time_t timestamp, enum imstatus status, |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
146 const char *status_msg) |
113 | 147 { |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
148 int buddy_format; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
149 char *bn = NULL; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
150 const char *rn = (resname ? resname : "default"); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
151 |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
152 buddy_format = settings_opt_get_int("buddy_format"); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
153 if (buddy_format) { |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
154 const char *name = roster_getname(jid); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
155 if (name && strcmp(name, jid)) { |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
156 if (buddy_format == 1) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
157 bn = g_strdup_printf("%s <%s/%s>", name, jid, rn); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
158 else if (buddy_format == 2) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
159 bn = g_strdup_printf("%s/%s", name, rn); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
160 else if (buddy_format == 3) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
161 bn = g_strdup_printf("%s", name); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
162 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
163 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
164 |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
165 if (!bn) { |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
166 bn = g_strdup_printf("<%s/%s>", jid, rn); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
167 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
168 |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
169 scr_LogPrint(LPRINT_LOGNORM, "Buddy status has changed: [%c>%c] %s %s", |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
170 imstatus2char[roster_getstatus(jid, resname)], |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
171 imstatus2char[status], bn, |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
172 ((status_msg) ? status_msg : "")); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
173 g_free(bn); |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
458
diff
changeset
|
174 roster_setstatus(jid, rn, prio, status, status_msg, role_none, NULL); |
120 | 175 buddylist_build(); |
176 scr_DrawRoster(); | |
221 | 177 hlog_write_status(jid, 0, status, status_msg); |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
178 // External command |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
179 hk_ext_cmd(jid, 'S', imstatus2char[status], NULL); |
113 | 180 } |
181 | |
116 | 182 inline void hk_mystatuschange(time_t timestamp, |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
183 enum imstatus old_status, enum imstatus new_status, const char *msg) |
116 | 184 { |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
185 if (!msg && (old_status == new_status)) |
116 | 186 return; |
187 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
188 scr_LogPrint(LPRINT_LOGNORM, "Your status has changed: [%c>%c] %s", |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
189 imstatus2char[old_status], imstatus2char[new_status], |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
281
diff
changeset
|
190 ((msg) ? msg : "")); |
116 | 191 //hlog_write_status(NULL, 0, status); |
192 } | |
193 | |
160 | 194 |
195 /* External commands */ | |
196 | |
197 // hk_ext_cmd_init() | |
198 // Initialize external command variable. | |
199 // Can be called with parameter NULL to reset and free memory. | |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
221
diff
changeset
|
200 void hk_ext_cmd_init(const char *command) |
160 | 201 { |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
202 if (extcmd) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
203 g_free(extcmd); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
204 extcmd = NULL; |
160 | 205 } |
206 if (command) | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
207 extcmd = g_strdup(command); |
160 | 208 } |
209 | |
210 // hk_ext_cmd() | |
211 // Launch an external command (process) for the given event. | |
212 // For now, data should be NULL. | |
213 void hk_ext_cmd(const char *jid, guchar type, guchar info, const char *data) | |
214 { | |
215 pid_t pid; | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
216 char *arg_type = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
217 char *arg_info = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
218 char *arg_data = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
219 char status_str[2]; |
160 | 220 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
221 if (!extcmd) return; |
160 | 222 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
223 // Prepare arg_* (external command parameters) |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
224 switch (type) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
225 case 'M': |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
226 arg_type = "MSG"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
227 if (info == 'R') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
228 arg_info = "IN"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
229 else if (info == 'S') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
230 arg_info = "OUT"; |
453
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
231 break; |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
232 case 'G': |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
233 arg_type = "MSG"; |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
234 arg_info = "MUC"; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
235 break; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
236 case 'S': |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
237 arg_type = "STATUS"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
238 if (strchr(imstatus2char, tolower(info))) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
239 status_str[0] = toupper(info); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
240 status_str[1] = 0; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
241 arg_info = status_str; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
242 } |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
243 break; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
244 default: |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
245 return; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
246 } |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
247 |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
248 if (!arg_type || !arg_info) return; |
160 | 249 |
250 if ((pid=fork()) == -1) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
251 scr_LogPrint(LPRINT_LOGNORM, "Fork error, cannot launch external command."); |
160 | 252 return; |
253 } | |
254 | |
255 if (pid == 0) { // child | |
391
868a350fefca
Fix "missing sentinel in function call" warning with gcc4
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
256 if (execl(extcmd, extcmd, arg_type, arg_info, jid, arg_data, NULL) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
257 // scr_LogPrint(LPRINT_LOGNORM, "Cannot execute external command."); |
160 | 258 exit(1); |
259 } | |
260 } | |
261 } | |
262 |