author | Mikael Berthe <mikael@lilotux.net> |
Sun, 05 Jun 2016 20:06:46 +0200 | |
changeset 2268 | f5402d705f67 |
parent 2193 | 18fa5ecb1ef4 |
child 2280 | f1eebfdd6db7 |
permissions | -rw-r--r-- |
113 | 1 |
/* |
699 | 2 |
* hooks.c -- Hooks layer |
393 | 3 |
* |
1729
e6e89b1d7831
Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents:
1683
diff
changeset
|
4 |
* Copyright (C) 2005-2010 Mikael Berthe <mikael@lilotux.net> |
113 | 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 |
|
2268
f5402d705f67
Fix FSF addresses in all files
Mikael Berthe <mikael@lilotux.net>
parents:
2193
diff
changeset
|
17 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
113 | 18 |
*/ |
19 |
||
1598 | 20 |
#include <loudmouth/loudmouth.h> |
21 |
#include <stdlib.h> |
|
22 |
#include <string.h> |
|
160 | 23 |
#include <sys/types.h> |
24 |
#include <unistd.h> |
|
113 | 25 |
|
26 |
#include "hooks.h" |
|
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
27 |
#include "screen.h" |
113 | 28 |
#include "roster.h" |
29 |
#include "histolog.h" |
|
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
30 |
#include "hbuf.h" |
477 | 31 |
#include "settings.h" |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
32 |
#include "utils.h" |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
33 |
#include "utf8.h" |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
34 |
#include "commands.h" |
1654
fca9a4c17432
Improve UI latency and CPU usage
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1642
diff
changeset
|
35 |
#include "main.h" |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
36 |
|
1607 | 37 |
#ifdef MODULES_ENABLE |
38 |
#include <glib.h> |
|
39 |
||
40 |
typedef struct { |
|
41 |
hk_handler_t handler; |
|
1795 | 42 |
gint priority; |
43 |
gpointer userdata; |
|
44 |
guint hid; |
|
1607 | 45 |
} hook_list_data_t; |
46 |
||
1795 | 47 |
static GHashTable *hk_handler_hash = NULL; |
1607 | 48 |
|
1795 | 49 |
// _new_hook_id() |
50 |
// Return a unique Hook Id |
|
51 |
static guint _new_hook_id(void) |
|
52 |
{ |
|
53 |
static guint hidcounter; |
|
54 |
||
55 |
return ++hidcounter; |
|
56 |
} |
|
57 |
||
58 |
// _new_hook_queue(hookname) |
|
59 |
// Create a new hash table entry with a GSList pointer for the specified hook |
|
60 |
static GSList **_new_hook_queue(const gchar *hookname) |
|
1607 | 61 |
{ |
1795 | 62 |
GSList **p; |
63 |
// Create the hash table if needed. |
|
64 |
if (!hk_handler_hash) { |
|
65 |
hk_handler_hash = g_hash_table_new_full(&g_str_hash, &g_str_equal, |
|
66 |
&g_free, &g_free); |
|
67 |
if (!hk_handler_hash) { |
|
68 |
scr_log_print(LPRINT_LOGNORM, "Couldn't create hook hash table!"); |
|
69 |
return NULL; |
|
70 |
} |
|
71 |
} |
|
72 |
||
73 |
// Add a queue for the requested hook |
|
74 |
p = g_new(GSList*, 1); |
|
75 |
*p = NULL; |
|
76 |
g_hash_table_insert(hk_handler_hash, g_strdup(hookname), p); |
|
77 |
||
78 |
return p; |
|
79 |
} |
|
80 |
||
81 |
static gint _hk_compare_prio(hook_list_data_t *a, hook_list_data_t *b) |
|
82 |
{ |
|
83 |
if (a->priority > b->priority) |
|
84 |
return 1; |
|
85 |
return 0; |
|
1607 | 86 |
} |
87 |
||
1795 | 88 |
// hk_add_handler(handler, hookname, priority, userdata) |
89 |
// Create a hook handler and a hook hash entry if needed. |
|
90 |
// Return the handler id. |
|
91 |
guint hk_add_handler(hk_handler_t handler, const gchar *hookname, |
|
92 |
gint priority, gpointer userdata) |
|
1607 | 93 |
{ |
1795 | 94 |
GSList **hqueue = NULL; |
95 |
hook_list_data_t *h = g_new(hook_list_data_t, 1); |
|
96 |
||
97 |
h->handler = handler; |
|
98 |
h->priority = priority; |
|
99 |
h->userdata = userdata; |
|
100 |
h->hid = _new_hook_id(); |
|
101 |
||
102 |
if (hk_handler_hash) |
|
103 |
hqueue = g_hash_table_lookup(hk_handler_hash, hookname); |
|
104 |
||
105 |
if (!hqueue) |
|
106 |
hqueue = _new_hook_queue(hookname); |
|
107 |
||
108 |
if (!hqueue) |
|
1607 | 109 |
return 0; |
1795 | 110 |
|
111 |
*hqueue = g_slist_insert_sorted(*hqueue, h, (GCompareFunc)_hk_compare_prio); |
|
112 |
||
113 |
return h->hid; |
|
114 |
} |
|
115 |
||
116 |
static gint _hk_queue_search_cb(hook_list_data_t *a, guint *hid) |
|
117 |
{ |
|
118 |
if (a->hid == *hid) |
|
119 |
return 0; |
|
120 |
return 1; |
|
1607 | 121 |
} |
122 |
||
1795 | 123 |
// hk_del_handler(hookname, hook_id) |
124 |
// Remove the handler with specified hook id from the hookname queue. |
|
125 |
// The hash entry is removed if the queue is empty. |
|
126 |
void hk_del_handler(const gchar *hookname, guint hid) |
|
1607 | 127 |
{ |
1795 | 128 |
GSList **hqueue; |
129 |
GSList *el; |
|
130 |
||
131 |
if (!hid) |
|
132 |
return; |
|
133 |
||
134 |
hqueue = g_hash_table_lookup(hk_handler_hash, hookname); |
|
135 |
||
136 |
if (!hqueue) { |
|
137 |
scr_log_print(LPRINT_LOGNORM, "*ERROR*: Couldn't remove hook handler!"); |
|
138 |
return; |
|
139 |
} |
|
140 |
||
141 |
el = g_slist_find_custom(*hqueue, &hid, |
|
142 |
(GCompareFunc)_hk_queue_search_cb); |
|
1607 | 143 |
if (el) { |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
144 |
g_free(el->data); |
1795 | 145 |
*hqueue = g_slist_delete_link(*hqueue, el); |
146 |
// Remove hook hash table entry if the hook queue is empty |
|
147 |
if (!*hqueue) |
|
148 |
g_hash_table_remove(hk_handler_hash, hookname); |
|
1607 | 149 |
} |
150 |
} |
|
1795 | 151 |
|
152 |
// hk_run_handlers(hookname, args) |
|
153 |
// Process all hooks for the "hookname" event. |
|
154 |
// Note that the processing is interrupted as soon as one of the handlers |
|
1813
1c3efa9bc422
s/HOOK_HANDLER_RESULT_ALLOW_MORE_HOOKS/HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS
Mikael Berthe <mikael@lilotux.net>
parents:
1812
diff
changeset
|
155 |
// do not return HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS (i.e. 0). |
1795 | 156 |
guint hk_run_handlers(const gchar *hookname, hk_arg_t *args) |
157 |
{ |
|
158 |
GSList **hqueue; |
|
159 |
GSList *h; |
|
160 |
guint ret = 0; |
|
161 |
||
162 |
if (!hk_handler_hash) |
|
163 |
return 0; |
|
164 |
||
165 |
hqueue = g_hash_table_lookup(hk_handler_hash, hookname); |
|
166 |
if (!hqueue) |
|
167 |
return 0; // Should we use a special code? |
|
168 |
||
169 |
for (h = *hqueue; h; h = g_slist_next(h)) { |
|
170 |
hook_list_data_t *data = h->data; |
|
171 |
ret = (data->handler)(hookname, args, data->userdata); |
|
172 |
if (ret) break; |
|
173 |
} |
|
174 |
return ret; |
|
175 |
} |
|
1607 | 176 |
#endif |
177 |
||
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
178 |
static char *extcmd; |
113 | 179 |
|
1107 | 180 |
static const char *COMMAND_ME = "/me "; |
181 |
||
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
182 |
void hk_message_in(const char *bjid, const char *resname, |
1598 | 183 |
time_t timestamp, const char *msg, LmMessageSubType type, |
2156
a54c084af4d6
Add a "carbon" parameter to the hook-{pre,post}-message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
2013
diff
changeset
|
184 |
guint encrypted, gboolean carbon) |
113 | 185 |
{ |
141 | 186 |
int new_guy = FALSE; |
477 | 187 |
int is_groupchat = FALSE; // groupchat message |
188 |
int is_room = FALSE; // window is a room window |
|
189 |
int log_muc_conf = FALSE; |
|
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
190 |
int active_window = FALSE; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
191 |
int message_flags = 0; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
192 |
guint rtype = ROSTER_TYPE_USER; |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
193 |
char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
194 |
GSList *roster_usr; |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1210
diff
changeset
|
195 |
unsigned mucnicklen = 0; |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
196 |
const char *ename = NULL; |
1805 | 197 |
gboolean attention = FALSE, mucprivmsg = FALSE; |
1913
3cabdacf58df
Add "error" field to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1906
diff
changeset
|
198 |
gboolean error_msg_subtype = (type == LM_MESSAGE_SUB_TYPE_ERROR); |
1892
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
199 |
#ifdef MODULES_ENABLE |
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
200 |
gchar strdelay[32]; |
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
201 |
|
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
202 |
if (timestamp) |
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
203 |
to_iso8601(strdelay, timestamp); |
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
204 |
else |
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
205 |
strdelay[0] = '\0'; |
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
206 |
#endif |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
207 |
|
1484
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
208 |
if (encrypted == ENCRYPTED_PGP) |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
209 |
message_flags |= HBB_PREFIX_PGPCRYPT; |
1484
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
210 |
else if (encrypted == ENCRYPTED_OTR) |
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
211 |
message_flags |= HBB_PREFIX_OTRCRYPT; |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
212 |
|
2190
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
213 |
if (carbon) |
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
214 |
message_flags |= HBB_PREFIX_CARBON; |
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
215 |
|
1598 | 216 |
if (type == LM_MESSAGE_SUB_TYPE_GROUPCHAT) { |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
217 |
rtype = ROSTER_TYPE_ROOM; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
218 |
is_groupchat = TRUE; |
477 | 219 |
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
|
220 |
if (!resname) { |
648
16cd6c858a5d
MUC: No new_message flag for server messages
Mikael Berthe <mikael@lilotux.net>
parents:
646
diff
changeset
|
221 |
message_flags = HBB_PREFIX_INFO | HBB_PREFIX_NOFLAG; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
222 |
resname = ""; |
1107 | 223 |
wmsg = bmsg = g_strdup_printf("~ %s", msg); |
646
a8cb28ca5ff4
MUC: Server messages are prefixed with "~ " instead of "<> "
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
224 |
} else { |
1107 | 225 |
wmsg = bmsg = g_strdup_printf("<%s> %s", resname, msg); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1210
diff
changeset
|
226 |
mucnicklen = strlen(resname) + 2; |
1107 | 227 |
if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) |
228 |
wmsg = mmsg = g_strdup_printf("*%s %s", resname, msg+4); |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
229 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
230 |
} else { |
1116
14e458020e23
Fix a bug in the history logging (incoming "/me " messages)
Mikael Berthe <mikael@lilotux.net>
parents:
1109
diff
changeset
|
231 |
bmsg = g_strdup(msg); |
1188
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
232 |
if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
233 |
gchar *shortid = g_strdup(bjid); |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
234 |
if (settings_opt_get_int("buddy_me_fulljid") == FALSE) { |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
235 |
gchar *p = strchr(shortid, '@'); // Truncate the jid |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
236 |
if (p) |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
237 |
*p = '\0'; |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
238 |
} |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
239 |
wmsg = mmsg = g_strdup_printf("*%s %s", shortid, msg+4); |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
240 |
g_free(shortid); |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
241 |
} else |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
242 |
wmsg = (char*) msg; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
243 |
} |
141 | 244 |
|
1797
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
245 |
#ifdef MODULES_ENABLE |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
246 |
{ |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
247 |
guint h_result; |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
248 |
hk_arg_t args[] = { |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
249 |
{ "jid", bjid }, |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
250 |
{ "resource", resname }, |
1887
b210c3d0de1f
Provide raw message in message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1847
diff
changeset
|
251 |
{ "message", msg }, |
1797
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
252 |
{ "groupchat", is_groupchat ? "true" : "false" }, |
1892
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
253 |
{ "delayed", strdelay }, |
1913
3cabdacf58df
Add "error" field to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1906
diff
changeset
|
254 |
{ "error", error_msg_subtype ? "true" : "false" }, |
2156
a54c084af4d6
Add a "carbon" parameter to the hook-{pre,post}-message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
2013
diff
changeset
|
255 |
{ "carbon", carbon ? "true" : "false" }, |
1797
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
256 |
{ NULL, NULL }, |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
257 |
}; |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
258 |
h_result = hk_run_handlers(HOOK_PRE_MESSAGE_IN, args); |
1816
6ac5718f8d25
Update handler return code defines (take #2)
Mikael Berthe <mikael@lilotux.net>
parents:
1813
diff
changeset
|
259 |
if (h_result == HOOK_HANDLER_RESULT_NO_MORE_HANDLER_DROP_DATA) { |
1797
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
260 |
scr_LogPrint(LPRINT_DEBUG, "Message dropped (hook result)."); |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
261 |
g_free(bmsg); |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
262 |
g_free(mmsg); |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
263 |
return; |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
264 |
} |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
265 |
} |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
266 |
#endif |
246c5d359c97
Add "hook-pre-message-in" hook
Mikael Berthe <mikael@lilotux.net>
parents:
1796
diff
changeset
|
267 |
|
141 | 268 |
// If this user isn't in the roster, we add it |
1058 | 269 |
roster_usr = roster_find(bjid, jidsearch, 0); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
270 |
if (!roster_usr) { |
141 | 271 |
new_guy = TRUE; |
1355 | 272 |
roster_usr = roster_add_user(bjid, NULL, NULL, rtype, sub_none, -1); |
477 | 273 |
if (!roster_usr) { // Shouldn't happen... |
274 |
scr_LogPrint(LPRINT_LOGNORM, "ERROR: unable to add buddy!"); |
|
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
275 |
g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
276 |
g_free(mmsg); |
477 | 277 |
return; |
278 |
} |
|
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
485
diff
changeset
|
279 |
} 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
|
280 |
// 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
|
281 |
buddy_settype(roster_usr->data, ROSTER_TYPE_ROOM); |
477 | 282 |
} |
283 |
||
284 |
is_room = !!(buddy_gettype(roster_usr->data) & ROSTER_TYPE_ROOM); |
|
285 |
||
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
286 |
if (is_room) { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
287 |
if (!is_groupchat) { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
288 |
// This is a private message from a room participant |
1108
a0e9eaa9f5b4
Fix small memory leak in hk_message_in()
Mikael Berthe <mikael@lilotux.net>
parents:
1107
diff
changeset
|
289 |
g_free(bmsg); |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
290 |
if (!resname) { |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
291 |
resname = ""; |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
292 |
wmsg = bmsg = g_strdup(msg); |
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
293 |
} else { |
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
294 |
wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", resname, msg); |
1108
a0e9eaa9f5b4
Fix small memory leak in hk_message_in()
Mikael Berthe <mikael@lilotux.net>
parents:
1107
diff
changeset
|
295 |
if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
a0e9eaa9f5b4
Fix small memory leak in hk_message_in()
Mikael Berthe <mikael@lilotux.net>
parents:
1107
diff
changeset
|
296 |
g_free(mmsg); |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
297 |
wmsg = mmsg = g_strdup_printf("PRIV#*%s %s", resname, msg+4); |
1108
a0e9eaa9f5b4
Fix small memory leak in hk_message_in()
Mikael Berthe <mikael@lilotux.net>
parents:
1107
diff
changeset
|
298 |
} |
1805 | 299 |
mucprivmsg = TRUE; |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
300 |
} |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
301 |
message_flags |= HBB_PREFIX_HLIGHT; |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
302 |
} else { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
303 |
// This is a regular chatroom message. |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
304 |
const char *nick = buddy_getnickname(roster_usr->data); |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
305 |
|
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
306 |
if (nick) { |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
307 |
// Let's see if we are the message sender, in which case we'll |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
308 |
// highlight it. |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
309 |
if (resname && !strcmp(resname, nick)) { |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
310 |
message_flags |= HBB_PREFIX_HLIGHT_OUT; |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
311 |
} else { |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
312 |
// We're not the sender. Can we see our nick? |
1207
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
313 |
const char *msgptr = msg; |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
314 |
while ((msgptr = strcasestr(msgptr, nick)) != NULL) { |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
315 |
const char *leftb, *rightb; |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
316 |
// The message contains our nick. Let's check it's not |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
317 |
// in the middle of another word (i.e. preceded/followed |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
318 |
// immediately by an alphanumeric character or an underscore. |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
319 |
rightb = msgptr+strlen(nick); |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
320 |
if (msgptr == msg) |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
321 |
leftb = NULL; |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
322 |
else |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
323 |
leftb = prev_char((char*)msgptr, msg); |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
324 |
msgptr = next_char((char*)msgptr); |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
325 |
// Check left boundary |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
326 |
if (leftb && (iswalnum(get_char(leftb)) || get_char(leftb) == '_')) |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
327 |
continue; |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
328 |
// Check right boundary |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
329 |
if (!iswalnum(get_char(rightb)) && get_char(rightb) != '_') |
1801
07e73049f7c5
Replace "urgent" with "attention" in HOOK_POST_MESSAGE_IN
Mikael Berthe <mikael@lilotux.net>
parents:
1797
diff
changeset
|
330 |
attention = TRUE; |
07e73049f7c5
Replace "urgent" with "attention" in HOOK_POST_MESSAGE_IN
Mikael Berthe <mikael@lilotux.net>
parents:
1797
diff
changeset
|
331 |
if (attention && !settings_opt_get_int("muc_disable_nick_hl")) |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
332 |
message_flags |= HBB_PREFIX_HLIGHT; |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
333 |
} |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
334 |
} |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
335 |
} |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
336 |
} |
2013
8dc418af3e72
Allow to select to which buddy resource messages go. Closes issue #55
Hermitifier
parents:
1913
diff
changeset
|
337 |
} else if (settings_opt_get_int("roster_autolock_resource")) { |
8dc418af3e72
Allow to select to which buddy resource messages go. Closes issue #55
Hermitifier
parents:
1913
diff
changeset
|
338 |
buddy_setactiveresource(roster_usr->data, resname); |
8dc418af3e72
Allow to select to which buddy resource messages go. Closes issue #55
Hermitifier
parents:
1913
diff
changeset
|
339 |
scr_update_chat_status(FALSE); |
141 | 340 |
} |
341 |
||
1913
3cabdacf58df
Add "error" field to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1906
diff
changeset
|
342 |
if (error_msg_subtype) { |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
343 |
message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; |
1058 | 344 |
scr_LogPrint(LPRINT_LOGNORM, "Error message received from <%s>", bjid); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
345 |
} |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
346 |
|
178 | 347 |
// Note: the hlog_write should not be called first, because in some |
1783
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
348 |
// cases scr_write_incoming_message() will load the history and we'd |
178 | 349 |
// have the message twice... |
1783
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
350 |
scr_write_incoming_message(bjid, wmsg, timestamp, message_flags, mucnicklen); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
351 |
|
1805 | 352 |
// Set urgent (a.k.a. "attention") flag |
353 |
{ |
|
354 |
guint uip; |
|
355 |
if (is_groupchat) { |
|
1808
7a1c40549291
Fix attention sign for MUC private messages
Mikael Berthe <mikael@lilotux.net>
parents:
1805
diff
changeset
|
356 |
if (attention) uip = ROSTER_UI_PRIO_MUC_HL_MESSAGE; |
1805 | 357 |
else uip = ROSTER_UI_PRIO_MUC_MESSAGE; |
358 |
} else { |
|
1808
7a1c40549291
Fix attention sign for MUC private messages
Mikael Berthe <mikael@lilotux.net>
parents:
1805
diff
changeset
|
359 |
if (mucprivmsg) uip = ROSTER_UI_PRIO_MUC_PRIV_MESSAGE; |
7a1c40549291
Fix attention sign for MUC private messages
Mikael Berthe <mikael@lilotux.net>
parents:
1805
diff
changeset
|
360 |
else if (attention) uip = ROSTER_UI_PRIO_ATTENTION_MESSAGE; |
7a1c40549291
Fix attention sign for MUC private messages
Mikael Berthe <mikael@lilotux.net>
parents:
1805
diff
changeset
|
361 |
else uip = ROSTER_UI_PRIO_PRIVATE_MESSAGE; |
1805 | 362 |
} |
363 |
scr_setattentionflag_if_needed(bjid, FALSE, uip, prio_max); |
|
364 |
} |
|
365 |
||
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
366 |
// We don't log the modified message, but the original one |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
367 |
if (wmsg == mmsg) |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
368 |
wmsg = bmsg; |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
369 |
|
477 | 370 |
// - We don't log the message if it is an error message |
371 |
// - We don't log the message if it is a private conf. message |
|
372 |
// - We don't log the message if it is groupchat message and the log_muc_conf |
|
373 |
// option is off (and it is not a history line) |
|
374 |
if (!(message_flags & HBB_PREFIX_ERR) && |
|
375 |
(!is_room || (is_groupchat && log_muc_conf && !timestamp))) |
|
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1339
diff
changeset
|
376 |
hlog_write_message(bjid, timestamp, 0, wmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
377 |
|
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
378 |
if (settings_opt_get_int("events_ignore_active_window") && |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
379 |
current_buddy && scr_get_chatmode()) { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
380 |
gpointer bud = BUDDATA(current_buddy); |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
381 |
if (bud) { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
382 |
const char *cjid = buddy_getjid(bud); |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
383 |
if (cjid && !strcasecmp(cjid, bjid)) |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
384 |
active_window = TRUE; |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
385 |
} |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
386 |
} |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
387 |
|
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
388 |
if (settings_opt_get_int("eventcmd_use_nickname")) |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
389 |
ename = roster_getname(bjid); |
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
390 |
|
1847
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
391 |
// Display the sender in the log window |
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
392 |
if ((!is_groupchat) && !(message_flags & HBB_PREFIX_ERR) && |
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
393 |
settings_opt_get_int("log_display_sender")) { |
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
394 |
const char *name = roster_getname(bjid); |
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
395 |
if (!name) name = ""; |
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
396 |
scr_LogPrint(LPRINT_NORMAL, "Message received from %s <%s/%s>", |
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
397 |
name, bjid, (resname ? resname : "")); |
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
398 |
} |
2e133fc0e3d9
Display the sender in the log window before processing hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1839
diff
changeset
|
399 |
|
1607 | 400 |
#ifdef MODULES_ENABLE |
401 |
{ |
|
1795 | 402 |
hk_arg_t args[] = { |
403 |
{ "jid", bjid }, |
|
404 |
{ "resource", resname }, |
|
1887
b210c3d0de1f
Provide raw message in message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1847
diff
changeset
|
405 |
{ "message", msg }, |
1795 | 406 |
{ "groupchat", is_groupchat ? "true" : "false" }, |
1801
07e73049f7c5
Replace "urgent" with "attention" in HOOK_POST_MESSAGE_IN
Mikael Berthe <mikael@lilotux.net>
parents:
1797
diff
changeset
|
407 |
{ "attention", attention ? "true" : "false" }, |
1892
ea3f9b4f3558
Add "delayed" argument to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1887
diff
changeset
|
408 |
{ "delayed", strdelay }, |
1913
3cabdacf58df
Add "error" field to the message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
1906
diff
changeset
|
409 |
{ "error", error_msg_subtype ? "true" : "false" }, |
2156
a54c084af4d6
Add a "carbon" parameter to the hook-{pre,post}-message-in hooks
Mikael Berthe <mikael@lilotux.net>
parents:
2013
diff
changeset
|
410 |
{ "carbon", carbon ? "true" : "false" }, |
1795 | 411 |
{ NULL, NULL }, |
412 |
}; |
|
1796
5e2db25fdb17
Rename "hook-message-in" to "hook-post-message-in"
Mikael Berthe <mikael@lilotux.net>
parents:
1795
diff
changeset
|
413 |
hk_run_handlers(HOOK_POST_MESSAGE_IN, args); |
1607 | 414 |
} |
415 |
#endif |
|
416 |
||
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
417 |
// External command |
477 | 418 |
// - We do not call hk_ext_cmd() for history lines in MUC |
419 |
// - We do call hk_ext_cmd() for private messages in a room |
|
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
420 |
// - We do call hk_ext_cmd() for messages to the current window |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
421 |
if (!active_window && ((is_groupchat && !timestamp) || !is_groupchat)) |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
422 |
hk_ext_cmd(ename ? ename : bjid, (is_groupchat ? 'G' : 'M'), 'R', wmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
423 |
|
1210
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
424 |
// Beep, if enabled: |
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
425 |
// - if it's a private message |
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
426 |
// - if it's a public message and it's highlighted |
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
427 |
if (settings_opt_get_int("beep_on_message")) { |
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
428 |
if ((!is_groupchat && !(message_flags & HBB_PREFIX_ERR)) || |
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
429 |
(is_groupchat && (message_flags & HBB_PREFIX_HLIGHT))) |
1780
e4378fbab5d7
Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
430 |
scr_beep(); |
887
df4bb1535ef8
Fix beep_on_message in rooms
Mikael Berthe <mikael@lilotux.net>
parents:
856
diff
changeset
|
431 |
} |
675
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
656
diff
changeset
|
432 |
|
1010
54405d09b15a
Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
433 |
// We need to update the roster if the sender is unknown or |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
434 |
// if the sender is offline/invisible and a filter is set. |
146 | 435 |
if (new_guy || |
477 | 436 |
(buddy_getstatus(roster_usr->data, NULL) == offline && |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
437 |
buddylist_isset_filter())) |
146 | 438 |
{ |
141 | 439 |
update_roster = TRUE; |
440 |
} |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
441 |
|
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
442 |
g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
443 |
g_free(mmsg); |
113 | 444 |
} |
445 |
||
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
446 |
// 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
|
447 |
// 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
|
448 |
// normal messages. |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
449 |
void hk_message_out(const char *bjid, const char *nick, |
1602 | 450 |
time_t timestamp, const char *msg, |
2190
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
451 |
guint encrypted, gboolean carbon, gpointer xep184) |
113 | 452 |
{ |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
453 |
char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
2190
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
454 |
guint message_flags = 0; |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
455 |
|
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
456 |
if (nick) { |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
457 |
wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", nick, msg); |
1109
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
458 |
if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
459 |
const char *mynick = roster_getnickname(bjid); |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
460 |
wmsg = mmsg = g_strdup_printf("PRIV#<%s> *%s %s", nick, |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
461 |
(mynick ? mynick : "me"), msg+4); |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
462 |
} |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
463 |
} else { |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
464 |
wmsg = (char*)msg; |
1107 | 465 |
if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
1611
f9bf561e54d0
Use the username for authentication, added jid_get_username() to utils.c
franky
parents:
1607
diff
changeset
|
466 |
char *myid = jid_get_username(settings_opt_get("jid")); |
f9bf561e54d0
Use the username for authentication, added jid_get_username() to utils.c
franky
parents:
1607
diff
changeset
|
467 |
if (myid) { |
f9bf561e54d0
Use the username for authentication, added jid_get_username() to utils.c
franky
parents:
1607
diff
changeset
|
468 |
wmsg = mmsg = g_strdup_printf("*%s %s", myid, msg+4); |
f9bf561e54d0
Use the username for authentication, added jid_get_username() to utils.c
franky
parents:
1607
diff
changeset
|
469 |
g_free(myid); |
f9bf561e54d0
Use the username for authentication, added jid_get_username() to utils.c
franky
parents:
1607
diff
changeset
|
470 |
} |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
471 |
} |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
472 |
} |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
473 |
|
485 | 474 |
// Note: the hlog_write should not be called first, because in some |
1783
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
475 |
// cases scr_write_outgoing_message() will load the history and we'd |
485 | 476 |
// have the message twice... |
1484
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
477 |
if (encrypted == ENCRYPTED_PGP) |
2190
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
478 |
message_flags |= HBB_PREFIX_PGPCRYPT; |
1484
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
479 |
else if (encrypted == ENCRYPTED_OTR) |
2190
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
480 |
message_flags |= HBB_PREFIX_OTRCRYPT; |
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
481 |
|
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
482 |
if (carbon) |
2193
18fa5ecb1ef4
Make sure outgoing carbons won't set unread flag
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2190
diff
changeset
|
483 |
message_flags |= HBB_PREFIX_CARBON | HBB_PREFIX_NOFLAG; |
2190
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
484 |
|
ee3a40ffcd8b
New option: 'clear_unread_on_carbon'
Holger Weiß <holger@zedat.fu-berlin.de>
parents:
2164
diff
changeset
|
485 |
scr_write_outgoing_message(bjid, wmsg, message_flags, xep184); |
485 | 486 |
|
487 |
// We don't log private messages |
|
1107 | 488 |
if (!nick) |
1342
06441b6cc23a
History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents:
1339
diff
changeset
|
489 |
hlog_write_message(bjid, timestamp, 1, msg); |
485 | 490 |
|
1607 | 491 |
#ifdef MODULES_ENABLE |
492 |
{ |
|
1795 | 493 |
hk_arg_t args[] = { |
494 |
{ "jid", bjid }, |
|
495 |
{ "message", wmsg }, |
|
496 |
{ NULL, NULL }, |
|
497 |
}; |
|
498 |
hk_run_handlers(HOOK_MESSAGE_OUT, args); |
|
499 |
// TODO: check (and use) return value |
|
1607 | 500 |
} |
501 |
#endif |
|
502 |
||
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
503 |
// External command |
1058 | 504 |
hk_ext_cmd(bjid, '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
|
505 |
|
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
506 |
g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
507 |
g_free(mmsg); |
113 | 508 |
} |
509 |
||
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
510 |
void hk_statuschange(const char *bjid, const char *resname, gchar prio, |
1598 | 511 |
time_t timestamp, enum imstatus status, |
512 |
const char *status_msg) |
|
113 | 513 |
{ |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
514 |
int st_in_buf; |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
515 |
enum imstatus oldstat; |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
516 |
char *bn; |
655
de6837908702
Use "(...)" when cutting a multi-line status message in the log window
Mikael Berthe <mikael@lilotux.net>
parents:
648
diff
changeset
|
517 |
char *logsmsg; |
614 | 518 |
const char *rn = (resname ? resname : ""); |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
519 |
const char *ename = NULL; |
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
520 |
|
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
521 |
if (settings_opt_get_int("eventcmd_use_nickname")) |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
522 |
ename = roster_getname(bjid); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
523 |
|
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
524 |
oldstat = roster_getstatus(bjid, resname); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
525 |
|
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
526 |
st_in_buf = settings_opt_get_int("show_status_in_buffer"); |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
527 |
|
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
528 |
if (settings_opt_get_int("log_display_presence")) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
529 |
int buddy_format = settings_opt_get_int("buddy_format"); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
530 |
bn = NULL; |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
531 |
if (buddy_format) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
532 |
const char *name = roster_getname(bjid); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
533 |
if (name && strcmp(name, bjid)) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
534 |
if (buddy_format == 1) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
535 |
bn = g_strdup_printf("%s <%s/%s>", name, bjid, rn); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
536 |
else if (buddy_format == 2) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
537 |
bn = g_strdup_printf("%s/%s", name, rn); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
538 |
else if (buddy_format == 3) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
539 |
bn = g_strdup_printf("%s", name); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
540 |
} |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
541 |
} |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
542 |
|
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
543 |
if (!bn) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
544 |
bn = g_strdup_printf("<%s/%s>", bjid, rn); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
545 |
|
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
546 |
logsmsg = g_strdup(status_msg ? status_msg : ""); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
547 |
replace_nl_with_dots(logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
548 |
|
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
549 |
scr_LogPrint(LPRINT_LOGNORM, "Buddy status has changed: [%c>%c] %s %s", |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
550 |
imstatus2char[oldstat], imstatus2char[status], bn, logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
551 |
g_free(logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
552 |
g_free(bn); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
553 |
} |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
554 |
|
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
555 |
if (st_in_buf == 2 || |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
556 |
(st_in_buf == 1 && (status == offline || oldstat == offline))) { |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
557 |
// Write the status change in the buddy's buffer, only if it already exists |
1780
e4378fbab5d7
Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
558 |
if (scr_buddy_buffer_exists(bjid)) { |
2162
9e40d8f5bbe6
When show_status_in_buffer is set, display the resource name in the buffer
Mikael Berthe <mikael@lilotux.net>
parents:
2156
diff
changeset
|
559 |
bn = g_strdup_printf("Buddy status has changed: [%c>%c] [%s] %s", |
9e40d8f5bbe6
When show_status_in_buffer is set, display the resource name in the buffer
Mikael Berthe <mikael@lilotux.net>
parents:
2156
diff
changeset
|
560 |
imstatus2char[oldstat], imstatus2char[status], rn, |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
561 |
((status_msg) ? status_msg : "")); |
1783
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
562 |
scr_write_incoming_message(bjid, bn, timestamp, |
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
563 |
HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
564 |
g_free(bn); |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
565 |
} |
514
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
566 |
} |
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
567 |
|
1058 | 568 |
roster_setstatus(bjid, rn, prio, status, status_msg, timestamp, |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
614
diff
changeset
|
569 |
role_none, affil_none, NULL); |
120 | 570 |
buddylist_build(); |
1780
e4378fbab5d7
Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
571 |
scr_draw_roster(); |
1058 | 572 |
hlog_write_status(bjid, timestamp, status, status_msg); |
1607 | 573 |
|
574 |
#ifdef MODULES_ENABLE |
|
575 |
{ |
|
1795 | 576 |
char os[2] = " \0"; |
577 |
char ns[2] = " \0"; |
|
578 |
hk_arg_t args[] = { |
|
579 |
{ "jid", bjid }, |
|
580 |
{ "resource", rn }, |
|
581 |
{ "old_status", os }, |
|
582 |
{ "new_status", ns }, |
|
583 |
{ "message", status_msg ? status_msg : "" }, |
|
584 |
{ NULL, NULL }, |
|
585 |
}; |
|
586 |
os[0] = imstatus2char[oldstat]; |
|
587 |
ns[0] = imstatus2char[status]; |
|
588 |
||
589 |
hk_run_handlers(HOOK_STATUS_CHANGE, args); |
|
1607 | 590 |
} |
591 |
#endif |
|
592 |
||
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
593 |
// External command |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
594 |
hk_ext_cmd(ename ? ename : bjid, 'S', imstatus2char[status], NULL); |
113 | 595 |
} |
596 |
||
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
597 |
void hk_mystatuschange(time_t timestamp, enum imstatus old_status, |
536
56f641155579
Status change was not displayed when same status but message removed
Mikael Berthe <mikael@lilotux.net>
parents:
524
diff
changeset
|
598 |
enum imstatus new_status, const char *msg) |
116 | 599 |
{ |
541
87165382e4ce
Fix error introduced in changeset 56f641155579
Mikael Berthe <mikael@lilotux.net>
parents:
536
diff
changeset
|
600 |
scr_LogPrint(LPRINT_LOGNORM, "Your status has been set: [%c>%c] %s", |
536
56f641155579
Status change was not displayed when same status but message removed
Mikael Berthe <mikael@lilotux.net>
parents:
524
diff
changeset
|
601 |
imstatus2char[old_status], imstatus2char[new_status], |
56f641155579
Status change was not displayed when same status but message removed
Mikael Berthe <mikael@lilotux.net>
parents:
524
diff
changeset
|
602 |
(msg ? msg : "")); |
1607 | 603 |
|
604 |
#ifdef MODULES_ENABLE |
|
605 |
{ |
|
1795 | 606 |
char ns[2] = " \0"; |
607 |
hk_arg_t args[] = { |
|
608 |
{ "new_status", ns }, |
|
609 |
{ "message", msg ? msg : "" }, |
|
610 |
{ NULL, NULL }, |
|
611 |
}; |
|
612 |
ns[0] = imstatus2char[new_status]; |
|
613 |
||
614 |
hk_run_handlers(HOOK_MY_STATUS_CHANGE, args); |
|
1607 | 615 |
} |
616 |
#endif |
|
617 |
||
116 | 618 |
//hlog_write_status(NULL, 0, status); |
619 |
} |
|
620 |
||
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
621 |
void hk_postconnect(void) |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
622 |
{ |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
623 |
const char *hook_command; |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
624 |
char *cmdline; |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
625 |
|
1607 | 626 |
#ifdef MODULES_ENABLE |
627 |
{ |
|
1795 | 628 |
hk_arg_t args[] = { |
629 |
{ NULL, NULL }, |
|
630 |
}; |
|
631 |
hk_run_handlers(HOOK_POST_CONNECT, args); |
|
1607 | 632 |
} |
633 |
#endif |
|
634 |
||
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
635 |
hook_command = settings_opt_get("hook-post-connect"); |
1642
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
636 |
if (!hook_command) |
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
637 |
return; |
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
638 |
|
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
639 |
scr_LogPrint(LPRINT_LOGNORM, "Running hook-post-connect..."); |
1642
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
640 |
|
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
641 |
cmdline = from_utf8(hook_command); |
2164 | 642 |
process_command(cmdline, TRUE); |
1642
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
643 |
|
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
644 |
g_free(cmdline); |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
645 |
} |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
646 |
|
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
647 |
void hk_predisconnect(void) |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
648 |
{ |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
649 |
const char *hook_command; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
650 |
char *cmdline; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
651 |
|
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
652 |
#ifdef MODULES_ENABLE |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
653 |
{ |
1795 | 654 |
hk_arg_t args[] = { |
655 |
{ NULL, NULL }, |
|
656 |
}; |
|
657 |
hk_run_handlers(HOOK_PRE_DISCONNECT, args); |
|
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
658 |
} |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
659 |
#endif |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
660 |
|
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
661 |
hook_command = settings_opt_get("hook-pre-disconnect"); |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
662 |
if (!hook_command) |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
663 |
return; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
664 |
|
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
665 |
scr_LogPrint(LPRINT_LOGNORM, "Running hook-pre-disconnect..."); |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
666 |
|
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
667 |
cmdline = from_utf8(hook_command); |
2164 | 668 |
process_command(cmdline, TRUE); |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
669 |
|
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
670 |
g_free(cmdline); |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
671 |
} |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
672 |
|
1812
5dbb3ebbc466
Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
673 |
void hk_unread_list_change(guint unread_count, guint attention_count, |
5dbb3ebbc466
Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
674 |
guint muc_unread, guint muc_attention) |
5dbb3ebbc466
Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
675 |
{ |
1838
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
676 |
// Previous static variables are initialized with an unlikely value |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
677 |
static guint prev_unread = 65535; |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
678 |
static guint prev_attention = 65535; |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
679 |
static guint prev_muc_unread = 65535; |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
680 |
static guint prev_muc_attention = 65535; |
1839
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
681 |
gchar *str_unread; |
1838
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
682 |
|
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
683 |
// Do not call the handlers if the unread values haven't changed |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
684 |
if (unread_count == prev_unread && |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
685 |
attention_count == prev_attention && |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
686 |
muc_unread == prev_muc_unread && |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
687 |
muc_attention == prev_muc_attention) |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
688 |
return; |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
689 |
|
1839
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
690 |
#ifdef MODULES_ENABLE |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
691 |
{ |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
692 |
str_unread = g_strdup_printf("%u", unread_count); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
693 |
gchar *str_attention = g_strdup_printf("%u", attention_count); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
694 |
gchar *str_muc_unread = g_strdup_printf("%u", muc_unread); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
695 |
gchar *str_muc_attention = g_strdup_printf("%u", muc_attention); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
696 |
hk_arg_t args[] = { |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
697 |
{ "unread", str_unread }, // All unread |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
698 |
{ "attention", str_attention }, // Attention (private) |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
699 |
{ "muc_unread", str_muc_unread }, // MUC unread |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
700 |
{ "muc_attention", str_muc_attention }, // MUC attention (highlight) |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
701 |
{ NULL, NULL }, |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
702 |
}; |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
703 |
hk_run_handlers(HOOK_UNREAD_LIST_CHANGE, args); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
704 |
g_free(str_unread); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
705 |
g_free(str_attention); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
706 |
g_free(str_muc_unread); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
707 |
g_free(str_muc_attention); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
708 |
} |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
709 |
#endif |
1838
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
710 |
|
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
711 |
prev_unread = unread_count; |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
712 |
prev_attention = attention_count; |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
713 |
prev_muc_unread = muc_unread; |
d10c291d31a7
Do not call hk_unread_list_change() too frequently
Mikael Berthe <mikael@lilotux.net>
parents:
1816
diff
changeset
|
714 |
prev_muc_attention = muc_attention; |
1839
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
715 |
|
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
716 |
/* Call external command */ |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
717 |
str_unread = g_strdup_printf("%u %u %u %u", unread_count, attention_count, |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
718 |
muc_unread, muc_attention); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
719 |
hk_ext_cmd("", 'U', (guchar)MIN(255, unread_count), str_unread); |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
720 |
g_free(str_unread); |
1812
5dbb3ebbc466
Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
721 |
} |
5dbb3ebbc466
Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
722 |
|
1906
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
723 |
// hk_presence_subscription_request(jid, message) |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
724 |
// Return non-zero if mcabber should stop processing the subscription request |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
725 |
guint hk_subscription(LmMessageSubType mstype, const gchar *bjid, |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
726 |
const gchar *msg) |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
727 |
{ |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
728 |
#ifdef MODULES_ENABLE |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
729 |
guint h_result; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
730 |
const char *stype; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
731 |
|
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
732 |
if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBE) |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
733 |
stype = "subscribe"; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
734 |
else if (mstype == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBE) |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
735 |
stype = "unsubscribe"; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
736 |
else if (mstype == LM_MESSAGE_SUB_TYPE_SUBSCRIBED) |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
737 |
stype = "subscribed"; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
738 |
else if (mstype == LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED) |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
739 |
stype = "unsubscribed"; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
740 |
else return 0; // Should not happen |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
741 |
|
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
742 |
{ |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
743 |
hk_arg_t args[] = { |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
744 |
{ "type", stype }, |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
745 |
{ "jid", bjid }, |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
746 |
{ "message", msg ? msg : "" }, |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
747 |
{ NULL, NULL }, |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
748 |
}; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
749 |
h_result = hk_run_handlers(HOOK_SUBSCRIPTION, args); |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
750 |
} |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
751 |
if (h_result != HOOK_HANDLER_RESULT_ALLOW_MORE_HANDLERS) { |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
752 |
scr_LogPrint(LPRINT_DEBUG, "Subscription message ignored (hook result)."); |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
753 |
return h_result; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
754 |
} |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
755 |
#endif |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
756 |
return 0; |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
757 |
} |
5d37cee8c6c6
Add "hook-subscription" hook and hk_subscription()
Mikael Berthe <mikael@lilotux.net>
parents:
1892
diff
changeset
|
758 |
|
1812
5dbb3ebbc466
Add hk_unread_list_change()
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
759 |
|
160 | 760 |
/* External commands */ |
761 |
||
762 |
// hk_ext_cmd_init() |
|
763 |
// Initialize external command variable. |
|
764 |
// 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
|
765 |
void hk_ext_cmd_init(const char *command) |
160 | 766 |
{ |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
767 |
if (extcmd) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
768 |
g_free(extcmd); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
769 |
extcmd = NULL; |
160 | 770 |
} |
771 |
if (command) |
|
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
772 |
extcmd = expand_filename(command); |
160 | 773 |
} |
774 |
||
775 |
// hk_ext_cmd() |
|
776 |
// Launch an external command (process) for the given event. |
|
777 |
// For now, data should be NULL. |
|
1058 | 778 |
void hk_ext_cmd(const char *bjid, guchar type, guchar info, const char *data) |
160 | 779 |
{ |
780 |
pid_t pid; |
|
1839
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
781 |
const char *arg_type = NULL; |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
782 |
const char *arg_info = NULL; |
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
783 |
const char *arg_data = NULL; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
784 |
char status_str[2]; |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
785 |
char *datafname = NULL; |
160 | 786 |
|
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
787 |
if (!extcmd) return; |
160 | 788 |
|
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
789 |
// Prepare arg_* (external command parameters) |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
790 |
switch (type) { |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
791 |
case 'M': /* Normal message */ |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
792 |
arg_type = "MSG"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
793 |
if (info == 'R') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
794 |
arg_info = "IN"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
795 |
else if (info == 'S') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
796 |
arg_info = "OUT"; |
453
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
797 |
break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
798 |
case 'G': /* Groupchat message */ |
453
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
799 |
arg_type = "MSG"; |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
800 |
arg_info = "MUC"; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
801 |
break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
802 |
case 'S': /* Status change */ |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
803 |
arg_type = "STATUS"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
804 |
if (strchr(imstatus2char, tolower(info))) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
805 |
status_str[0] = toupper(info); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
806 |
status_str[1] = 0; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
807 |
arg_info = status_str; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
808 |
} |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
809 |
break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
810 |
case 'U': /* Unread buffer count */ |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
811 |
arg_type = "UNREAD"; |
1839
f0a07658e009
Update UNREAD event data
Mikael Berthe <mikael@lilotux.net>
parents:
1838
diff
changeset
|
812 |
arg_info = data; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
813 |
break; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
814 |
default: |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
815 |
return; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
816 |
} |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
817 |
|
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
818 |
if (!arg_type || !arg_info) return; |
160 | 819 |
|
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
820 |
if (strchr("MG", type) && data && settings_opt_get_int("event_log_files")) { |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
821 |
int fd; |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
822 |
const char *prefix; |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
823 |
char *prefix_xp = NULL; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
824 |
char *data_locale; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
825 |
|
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
826 |
data_locale = from_utf8(data); |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
827 |
prefix = settings_opt_get("event_log_dir"); |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
828 |
if (prefix) |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
829 |
prefix = prefix_xp = expand_filename(prefix); |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
830 |
else |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
831 |
prefix = ut_get_tmpdir(); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
832 |
datafname = g_strdup_printf("%s/mcabber-%d.XXXXXX", prefix, getpid()); |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
833 |
g_free(prefix_xp); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
834 |
|
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
835 |
// XXX Some old systems may require us to set umask first. |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
836 |
fd = mkstemp(datafname); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
837 |
if (fd == -1) { |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
838 |
g_free(datafname); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
839 |
datafname = NULL; |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
840 |
scr_LogPrint(LPRINT_LOGNORM, |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
841 |
"Unable to create temp file for external command."); |
1107 | 842 |
} else { |
1598 | 843 |
size_t data_locale_len = strlen(data_locale); |
844 |
ssize_t a = write(fd, data_locale, data_locale_len); |
|
845 |
ssize_t b = write(fd, "\n", 1); |
|
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
846 |
if ((size_t)a != data_locale_len || b != 1) { |
1598 | 847 |
g_free(datafname); |
848 |
datafname = NULL; |
|
849 |
scr_LogPrint(LPRINT_LOGNORM, |
|
850 |
"Unable to write to temp file for external command."); |
|
851 |
} |
|
1107 | 852 |
close(fd); |
853 |
arg_data = datafname; |
|
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
854 |
} |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
855 |
g_free(data_locale); |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
856 |
} |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
857 |
|
160 | 858 |
if ((pid=fork()) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
859 |
scr_LogPrint(LPRINT_LOGNORM, "Fork error, cannot launch external command."); |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
860 |
g_free(datafname); |
160 | 861 |
return; |
862 |
} |
|
863 |
||
864 |
if (pid == 0) { // child |
|
656
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
865 |
// Close standard file descriptors |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
866 |
close(STDIN_FILENO); |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
867 |
close(STDOUT_FILENO); |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
868 |
close(STDERR_FILENO); |
1339
1ea5a4cf2ae0
Correct execl() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
869 |
if (execl(extcmd, extcmd, arg_type, arg_info, bjid, arg_data, |
1ea5a4cf2ae0
Correct execl() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
870 |
(char *)NULL) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
871 |
// scr_LogPrint(LPRINT_LOGNORM, "Cannot execute external command."); |
160 | 872 |
exit(1); |
873 |
} |
|
874 |
} |
|
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
875 |
g_free(datafname); |
160 | 876 |
} |
576 | 877 |
|
1811 | 878 |
/* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */ |