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