Mercurial > ~mikael > mcabber > hg
annotate mcabber/mcabber/hooks.c @ 1787:1f913c92c9b2
Add urgent flag to the hook-message-in hook
Small coding style update, and bump API to v6
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 14 Mar 2010 17:34:56 +0100 |
parents | 5c043358ded0 |
children | 47699a09ceb3 |
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; | |
1623
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
44 guint32 flags; |
1607 | 45 gpointer userdata; |
46 } hook_list_data_t; | |
47 | |
48 static GSList *hk_handler_queue = NULL; | |
49 | |
1784
250ad919f03f
Small code cleanup in hooks.[ch]
Mikael Berthe <mikael@lilotux.net>
parents:
1783
diff
changeset
|
50 void hk_add_handler(hk_handler_t handler, guint32 flags, gpointer userdata) |
1607 | 51 { |
1784
250ad919f03f
Small code cleanup in hooks.[ch]
Mikael Berthe <mikael@lilotux.net>
parents:
1783
diff
changeset
|
52 hook_list_data_t *h = g_new(hook_list_data_t, 1); |
1607 | 53 h->handler = handler; |
1623
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
54 h->flags = flags; |
1607 | 55 h->userdata = userdata; |
1784
250ad919f03f
Small code cleanup in hooks.[ch]
Mikael Berthe <mikael@lilotux.net>
parents:
1783
diff
changeset
|
56 hk_handler_queue = g_slist_append(hk_handler_queue, h); |
1607 | 57 } |
58 | |
1784
250ad919f03f
Small code cleanup in hooks.[ch]
Mikael Berthe <mikael@lilotux.net>
parents:
1783
diff
changeset
|
59 static gint hk_queue_search_cb(hook_list_data_t *a, hook_list_data_t *b) |
1607 | 60 { |
61 if (a->handler == b->handler && a->userdata == b->userdata) | |
62 return 0; | |
63 else | |
64 return 1; | |
65 } | |
66 | |
1784
250ad919f03f
Small code cleanup in hooks.[ch]
Mikael Berthe <mikael@lilotux.net>
parents:
1783
diff
changeset
|
67 void hk_del_handler(hk_handler_t handler, gpointer userdata) |
1607 | 68 { |
1623
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
69 hook_list_data_t h = { handler, 0, userdata }; |
1784
250ad919f03f
Small code cleanup in hooks.[ch]
Mikael Berthe <mikael@lilotux.net>
parents:
1783
diff
changeset
|
70 GSList *el = g_slist_find_custom(hk_handler_queue, &h, |
250ad919f03f
Small code cleanup in hooks.[ch]
Mikael Berthe <mikael@lilotux.net>
parents:
1783
diff
changeset
|
71 (GCompareFunc) hk_queue_search_cb); |
1607 | 72 if (el) { |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
73 g_free(el->data); |
1784
250ad919f03f
Small code cleanup in hooks.[ch]
Mikael Berthe <mikael@lilotux.net>
parents:
1783
diff
changeset
|
74 hk_handler_queue = g_slist_delete_link(hk_handler_queue, el); |
1607 | 75 } |
76 } | |
77 #endif | |
78 | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
79 static char *extcmd; |
113 | 80 |
1107 | 81 static const char *COMMAND_ME = "/me "; |
82 | |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
83 void hk_message_in(const char *bjid, const char *resname, |
1598 | 84 time_t timestamp, const char *msg, LmMessageSubType type, |
85 guint encrypted) | |
113 | 86 { |
141 | 87 int new_guy = FALSE; |
477 | 88 int is_groupchat = FALSE; // groupchat message |
89 int is_room = FALSE; // window is a room window | |
90 int log_muc_conf = FALSE; | |
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
91 int active_window = FALSE; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
92 int message_flags = 0; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
93 guint rtype = ROSTER_TYPE_USER; |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
94 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
95 GSList *roster_usr; |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1210
diff
changeset
|
96 unsigned mucnicklen = 0; |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
97 const char *ename = NULL; |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
98 gboolean urgent = FALSE; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
99 |
1484
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
100 if (encrypted == ENCRYPTED_PGP) |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
101 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
|
102 else if (encrypted == ENCRYPTED_OTR) |
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
103 message_flags |= HBB_PREFIX_OTRCRYPT; |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
104 |
1598 | 105 if (type == LM_MESSAGE_SUB_TYPE_GROUPCHAT) { |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
106 rtype = ROSTER_TYPE_ROOM; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
107 is_groupchat = TRUE; |
477 | 108 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
|
109 if (!resname) { |
648
16cd6c858a5d
MUC: No new_message flag for server messages
Mikael Berthe <mikael@lilotux.net>
parents:
646
diff
changeset
|
110 message_flags = HBB_PREFIX_INFO | HBB_PREFIX_NOFLAG; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
111 resname = ""; |
1107 | 112 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
|
113 } else { |
1107 | 114 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
|
115 mucnicklen = strlen(resname) + 2; |
1107 | 116 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) |
117 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
|
118 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
119 } else { |
1116
14e458020e23
Fix a bug in the history logging (incoming "/me " messages)
Mikael Berthe <mikael@lilotux.net>
parents:
1109
diff
changeset
|
120 bmsg = g_strdup(msg); |
1188
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
121 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
122 gchar *shortid = g_strdup(bjid); |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
123 if (settings_opt_get_int("buddy_me_fulljid") == FALSE) { |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
124 gchar *p = strchr(shortid, '@'); // Truncate the jid |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
125 if (p) |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
126 *p = '\0'; |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
127 } |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
128 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
|
129 g_free(shortid); |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
130 } else |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
131 wmsg = (char*) msg; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
132 } |
141 | 133 |
134 // If this user isn't in the roster, we add it | |
1058 | 135 roster_usr = roster_find(bjid, jidsearch, 0); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
136 if (!roster_usr) { |
141 | 137 new_guy = TRUE; |
1355 | 138 roster_usr = roster_add_user(bjid, NULL, NULL, rtype, sub_none, -1); |
477 | 139 if (!roster_usr) { // Shouldn't happen... |
140 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
|
141 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
142 g_free(mmsg); |
477 | 143 return; |
144 } | |
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
485
diff
changeset
|
145 } 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
|
146 // 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
|
147 buddy_settype(roster_usr->data, ROSTER_TYPE_ROOM); |
477 | 148 } |
149 | |
150 is_room = !!(buddy_gettype(roster_usr->data) & ROSTER_TYPE_ROOM); | |
151 | |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
152 if (is_room) { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
153 if (!is_groupchat) { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
154 // 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
|
155 g_free(bmsg); |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
156 if (!resname) { |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
157 resname = ""; |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
158 wmsg = bmsg = g_strdup(msg); |
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
159 } else { |
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
160 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
|
161 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
|
162 g_free(mmsg); |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
163 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
|
164 } |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
165 } |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
166 message_flags |= HBB_PREFIX_HLIGHT; |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
167 } else { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
168 // This is a regular chatroom message. |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
169 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
|
170 |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
171 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
|
172 // 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
|
173 // 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
|
174 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
|
175 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
|
176 } 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
|
177 // 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
|
178 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
|
179 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
|
180 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
|
181 // 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
|
182 // 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
|
183 // 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
|
184 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
|
185 if (msgptr == msg) |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
186 leftb = NULL; |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
187 else |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
188 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
|
189 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
|
190 // Check left boundary |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
191 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
|
192 continue; |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
193 // Check right boundary |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
194 if (!iswalnum(get_char(rightb)) && get_char(rightb) != '_') |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
195 urgent = TRUE; |
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
196 if (urgent && !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
|
197 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
|
198 } |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
199 } |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
200 } |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
201 } |
141 | 202 } |
203 | |
1598 | 204 if (type == LM_MESSAGE_SUB_TYPE_ERROR) { |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
205 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; |
1058 | 206 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
|
207 } |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
208 |
178 | 209 // 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
|
210 // cases scr_write_incoming_message() will load the history and we'd |
178 | 211 // have the message twice... |
1783
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
212 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
|
213 |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
214 // 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
|
215 if (wmsg == mmsg) |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
216 wmsg = bmsg; |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
217 |
477 | 218 // - We don't log the message if it is an error message |
219 // - We don't log the message if it is a private conf. message | |
220 // - We don't log the message if it is groupchat message and the log_muc_conf | |
221 // option is off (and it is not a history line) | |
222 if (!(message_flags & HBB_PREFIX_ERR) && | |
223 (!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
|
224 hlog_write_message(bjid, timestamp, 0, wmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
225 |
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
226 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
|
227 current_buddy && scr_get_chatmode()) { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
228 gpointer bud = BUDDATA(current_buddy); |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
229 if (bud) { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
230 const char *cjid = buddy_getjid(bud); |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
231 if (cjid && !strcasecmp(cjid, bjid)) |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
232 active_window = TRUE; |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
233 } |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
234 } |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
235 |
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
236 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
|
237 ename = roster_getname(bjid); |
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
238 |
1607 | 239 #ifdef MODULES_ENABLE |
240 { | |
241 GSList *h = hk_handler_queue; | |
242 if (h) { | |
243 // We can use a const array for keys/static values, so modules | |
244 // can do fast known to them args check by just comparing pointers... | |
245 hk_arg_t args[] = { | |
246 { "hook", "hook-message-in" }, | |
247 { "jid", bjid }, | |
1785
5c043358ded0
Add resource name to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1784
diff
changeset
|
248 { "resource", resname }, |
1607 | 249 { "message", wmsg }, |
250 { "groupchat", is_groupchat ? "true" : "false" }, | |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
251 { "urgent", urgent ? "true" : "false" }, |
1607 | 252 { NULL, NULL }, |
253 }; | |
254 while (h) { | |
255 hook_list_data_t *data = h->data; | |
1623
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
256 if (data->flags & HOOK_MESSAGE_IN) |
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
257 (data->handler) (HOOK_MESSAGE_IN, args, data->userdata); |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
258 h = g_slist_next(h); |
1607 | 259 } |
260 } | |
261 } | |
262 #endif | |
263 | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
264 // External command |
477 | 265 // - We do not call hk_ext_cmd() for history lines in MUC |
266 // - 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
|
267 // - 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
|
268 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
|
269 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
|
270 |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
271 // Display the sender in the log window |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
272 if ((!is_groupchat) && !(message_flags & HBB_PREFIX_ERR) && |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
273 settings_opt_get_int("log_display_sender")) { |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
274 const char *name = roster_getname(bjid); |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
275 if (!name) name = ""; |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
276 scr_LogPrint(LPRINT_NORMAL, "Message received from %s <%s/%s>", |
1058 | 277 name, bjid, (resname ? resname : "")); |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
278 } |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
279 |
1210
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
280 // Beep, if enabled: |
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
281 // - 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
|
282 // - 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
|
283 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
|
284 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
|
285 (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
|
286 scr_beep(); |
887
df4bb1535ef8
Fix beep_on_message in rooms
Mikael Berthe <mikael@lilotux.net>
parents:
856
diff
changeset
|
287 } |
675
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
656
diff
changeset
|
288 |
1010
54405d09b15a
Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
289 // 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
|
290 // if the sender is offline/invisible and a filter is set. |
146 | 291 if (new_guy || |
477 | 292 (buddy_getstatus(roster_usr->data, NULL) == offline && |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
293 buddylist_isset_filter())) |
146 | 294 { |
141 | 295 update_roster = TRUE; |
296 } | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
297 |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
298 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
299 g_free(mmsg); |
113 | 300 } |
301 | |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
302 // 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
|
303 // 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
|
304 // normal messages. |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
305 void hk_message_out(const char *bjid, const char *nick, |
1602 | 306 time_t timestamp, const char *msg, |
307 guint encrypted, gpointer xep184) | |
113 | 308 { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
309 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
1484
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
310 guint cryptflag = 0; |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
311 |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
312 if (nick) { |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
313 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
|
314 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
|
315 const char *mynick = roster_getnickname(bjid); |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
316 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
|
317 (mynick ? mynick : "me"), msg+4); |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
318 } |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
319 } else { |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
320 wmsg = (char*)msg; |
1107 | 321 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
|
322 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
|
323 if (myid) { |
f9bf561e54d0
Use the username for authentication, added jid_get_username() to utils.c
franky
parents:
1607
diff
changeset
|
324 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
|
325 g_free(myid); |
f9bf561e54d0
Use the username for authentication, added jid_get_username() to utils.c
franky
parents:
1607
diff
changeset
|
326 } |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
327 } |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
328 } |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
329 |
485 | 330 // 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
|
331 // cases scr_write_outgoing_message() will load the history and we'd |
485 | 332 // have the message twice... |
1484
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
333 if (encrypted == ENCRYPTED_PGP) |
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
334 cryptflag = HBB_PREFIX_PGPCRYPT; |
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
335 else if (encrypted == ENCRYPTED_OTR) |
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1450
diff
changeset
|
336 cryptflag = HBB_PREFIX_OTRCRYPT; |
1783
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
337 scr_write_outgoing_message(bjid, wmsg, cryptflag, xep184); |
485 | 338 |
339 // We don't log private messages | |
1107 | 340 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
|
341 hlog_write_message(bjid, timestamp, 1, msg); |
485 | 342 |
1607 | 343 #ifdef MODULES_ENABLE |
344 { | |
345 GSList *h = hk_handler_queue; | |
346 if (h) { | |
347 hk_arg_t args[] = { | |
348 { "hook", "hook-message-out" }, | |
349 { "jid", bjid }, | |
350 { "message", wmsg }, | |
351 { NULL, NULL }, | |
352 }; | |
353 while (h) { | |
354 hook_list_data_t *data = h->data; | |
1623
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
355 if (data->flags & HOOK_MESSAGE_OUT) |
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
356 (data->handler) (HOOK_MESSAGE_OUT, args, data->userdata); |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
357 h = g_slist_next(h); |
1607 | 358 } |
359 } | |
360 } | |
361 #endif | |
362 | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
363 // External command |
1058 | 364 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
|
365 |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
366 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
367 g_free(mmsg); |
113 | 368 } |
369 | |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
370 void hk_statuschange(const char *bjid, const char *resname, gchar prio, |
1598 | 371 time_t timestamp, enum imstatus status, |
372 const char *status_msg) | |
113 | 373 { |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
374 int st_in_buf; |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
375 enum imstatus oldstat; |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
376 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
|
377 char *logsmsg; |
614 | 378 const char *rn = (resname ? resname : ""); |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
379 const char *ename = NULL; |
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
380 |
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
381 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
|
382 ename = roster_getname(bjid); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
383 |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
384 oldstat = roster_getstatus(bjid, resname); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
385 |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
386 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
|
387 |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
388 if (settings_opt_get_int("log_display_presence")) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
389 int buddy_format = settings_opt_get_int("buddy_format"); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
390 bn = NULL; |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
391 if (buddy_format) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
392 const char *name = roster_getname(bjid); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
393 if (name && strcmp(name, bjid)) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
394 if (buddy_format == 1) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
395 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
|
396 else if (buddy_format == 2) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
397 bn = g_strdup_printf("%s/%s", name, rn); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
398 else if (buddy_format == 3) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
399 bn = g_strdup_printf("%s", name); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
400 } |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
401 } |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
402 |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
403 if (!bn) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
404 bn = g_strdup_printf("<%s/%s>", bjid, rn); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
405 |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
406 logsmsg = g_strdup(status_msg ? status_msg : ""); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
407 replace_nl_with_dots(logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
408 |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
409 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
|
410 imstatus2char[oldstat], imstatus2char[status], bn, logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
411 g_free(logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
412 g_free(bn); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
413 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
414 |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
415 if (st_in_buf == 2 || |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
416 (st_in_buf == 1 && (status == offline || oldstat == offline))) { |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
417 // 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
|
418 if (scr_buddy_buffer_exists(bjid)) { |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
419 bn = g_strdup_printf("Buddy status has changed: [%c>%c] %s", |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
420 imstatus2char[oldstat], imstatus2char[status], |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
421 ((status_msg) ? status_msg : "")); |
1783
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
422 scr_write_incoming_message(bjid, bn, timestamp, |
af3de54ef986
Convert scr_LogPrint() to scr_log_print()
Mikael Berthe <mikael@lilotux.net>
parents:
1780
diff
changeset
|
423 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
424 g_free(bn); |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
425 } |
514
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
426 } |
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
427 |
1058 | 428 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
|
429 role_none, affil_none, NULL); |
120 | 430 buddylist_build(); |
1780
e4378fbab5d7
Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
431 scr_draw_roster(); |
1058 | 432 hlog_write_status(bjid, timestamp, status, status_msg); |
1607 | 433 |
434 #ifdef MODULES_ENABLE | |
435 { | |
436 GSList *h = hk_handler_queue; | |
437 if (h) { | |
438 char os[2] = " \0"; | |
439 char ns[2] = " \0"; | |
440 hk_arg_t args[] = { | |
441 { "hook", "hook-status-change" }, | |
442 { "jid", bjid }, | |
443 { "resource", rn }, | |
444 { "old_status", os }, | |
445 { "new_status", ns }, | |
446 { "message", status_msg ? status_msg : "" }, | |
447 { NULL, NULL }, | |
448 }; | |
449 os[0] = imstatus2char[oldstat]; | |
450 ns[0] = imstatus2char[status]; | |
451 while (h) { | |
452 hook_list_data_t *data = h->data; | |
1623
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
453 if (data->flags & HOOK_STATUS_CHANGE) |
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
454 (data->handler) (HOOK_STATUS_CHANGE, args, data->userdata); |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
455 h = g_slist_next(h); |
1607 | 456 } |
457 } | |
458 } | |
459 #endif | |
460 | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
461 // External command |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
462 hk_ext_cmd(ename ? ename : bjid, 'S', imstatus2char[status], NULL); |
113 | 463 } |
464 | |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
465 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
|
466 enum imstatus new_status, const char *msg) |
116 | 467 { |
541
87165382e4ce
Fix error introduced in changeset 56f641155579
Mikael Berthe <mikael@lilotux.net>
parents:
536
diff
changeset
|
468 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
|
469 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
|
470 (msg ? msg : "")); |
1607 | 471 |
472 #ifdef MODULES_ENABLE | |
473 { | |
474 GSList *h = hk_handler_queue; | |
475 if (h) { | |
476 char ns[2] = " \0"; | |
477 hk_arg_t args[] = { | |
478 { "hook", "hook-my-status-change" }, | |
479 { "new_status", ns }, | |
480 { "message", msg ? msg : "" }, | |
481 { NULL, NULL }, | |
482 }; | |
483 ns[0] = imstatus2char[new_status]; | |
484 while (h) { | |
485 hook_list_data_t *data = h->data; | |
1623
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
486 if (data->flags & HOOK_MY_STATUS_CHANGE) |
b008ac166b91
Flags for hook handlers
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1611
diff
changeset
|
487 (data->handler) (HOOK_MY_STATUS_CHANGE, args, data->userdata); |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
488 h = g_slist_next(h); |
1607 | 489 } |
490 } | |
491 } | |
492 #endif | |
493 | |
116 | 494 //hlog_write_status(NULL, 0, status); |
495 } | |
496 | |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
497 void hk_postconnect(void) |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
498 { |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
499 const char *hook_command; |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
500 char *cmdline; |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
501 |
1607 | 502 #ifdef MODULES_ENABLE |
503 { | |
504 GSList *h = hk_handler_queue; | |
505 if (h) { | |
506 hk_arg_t args[] = { | |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
507 { "hook", "hook-post-connect" }, |
1607 | 508 { NULL, NULL }, |
509 }; | |
510 while (h) { | |
511 hook_list_data_t *data = h->data; | |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
512 if (data->flags & HOOK_POST_CONNECT) |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
513 (data->handler) (HOOK_POST_CONNECT, args, data->userdata); |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
514 h = g_slist_next(h); |
1607 | 515 } |
516 } | |
517 } | |
518 #endif | |
519 | |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
520 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
|
521 if (!hook_command) |
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
522 return; |
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
523 |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
524 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
|
525 |
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
526 cmdline = from_utf8(hook_command); |
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
527 if (process_command(cmdline, TRUE) == 255) |
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
528 mcabber_set_terminate_ui(); |
cd67b29e04e3
Fix not execution of HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1623
diff
changeset
|
529 |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
530 g_free(cmdline); |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
531 } |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
532 |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
533 void hk_predisconnect(void) |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
534 { |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
535 const char *hook_command; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
536 char *cmdline; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
537 |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
538 #ifdef MODULES_ENABLE |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
539 { |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
540 GSList *h = hk_handler_queue; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
541 if (h) { |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
542 hk_arg_t args[] = { |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
543 { "hook", "hook-pre-disconnect" }, |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
544 { NULL, NULL }, |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
545 }; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
546 while (h) { |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
547 hook_list_data_t *data = h->data; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
548 if (data->flags & HOOK_PRE_DISCONNECT) |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
549 (data->handler) (HOOK_PRE_DISCONNECT, args, data->userdata); |
1787
1f913c92c9b2
Add urgent flag to the hook-message-in hook
Mikael Berthe <mikael@lilotux.net>
parents:
1785
diff
changeset
|
550 h = g_slist_next(h); |
1683
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
551 } |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
552 } |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
553 } |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
554 #endif |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
555 |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
556 hook_command = settings_opt_get("hook-pre-disconnect"); |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
557 if (!hook_command) |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
558 return; |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
559 |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
560 scr_LogPrint(LPRINT_LOGNORM, "Running hook-pre-disconnect..."); |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
561 |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
562 cmdline = from_utf8(hook_command); |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
563 if (process_command(cmdline, TRUE) == 255) |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
564 mcabber_set_terminate_ui(); |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
565 |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
566 g_free(cmdline); |
b09f82f61745
Split HOOK_INTERNAL
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1668
diff
changeset
|
567 } |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
568 |
160 | 569 /* External commands */ |
570 | |
571 // hk_ext_cmd_init() | |
572 // Initialize external command variable. | |
573 // 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
|
574 void hk_ext_cmd_init(const char *command) |
160 | 575 { |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
576 if (extcmd) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
577 g_free(extcmd); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
578 extcmd = NULL; |
160 | 579 } |
580 if (command) | |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
581 extcmd = expand_filename(command); |
160 | 582 } |
583 | |
584 // hk_ext_cmd() | |
585 // Launch an external command (process) for the given event. | |
586 // For now, data should be NULL. | |
1058 | 587 void hk_ext_cmd(const char *bjid, guchar type, guchar info, const char *data) |
160 | 588 { |
589 pid_t pid; | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
590 char *arg_type = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
591 char *arg_info = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
592 char *arg_data = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
593 char status_str[2]; |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
594 char *datafname = NULL; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
595 char unread_str[16]; |
160 | 596 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
597 if (!extcmd) return; |
160 | 598 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
599 // Prepare arg_* (external command parameters) |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
600 switch (type) { |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
601 case 'M': /* Normal message */ |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
602 arg_type = "MSG"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
603 if (info == 'R') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
604 arg_info = "IN"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
605 else if (info == 'S') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
606 arg_info = "OUT"; |
453
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
607 break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
608 case 'G': /* Groupchat message */ |
453
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
609 arg_type = "MSG"; |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
610 arg_info = "MUC"; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
611 break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
612 case 'S': /* Status change */ |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
613 arg_type = "STATUS"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
614 if (strchr(imstatus2char, tolower(info))) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
615 status_str[0] = toupper(info); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
616 status_str[1] = 0; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
617 arg_info = status_str; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
618 } |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
619 break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
620 case 'U': /* Unread buffer count */ |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
621 arg_type = "UNREAD"; |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
622 g_snprintf(unread_str, sizeof unread_str, "%d", info); |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
623 arg_info = unread_str; /* number of remaining unread bjids */ |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
624 break; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
625 default: |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
626 return; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
627 } |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
628 |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
629 if (!arg_type || !arg_info) return; |
160 | 630 |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
631 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
|
632 int fd; |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
633 const char *prefix; |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
634 char *prefix_xp = NULL; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
635 char *data_locale; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
636 |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
637 data_locale = from_utf8(data); |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
638 prefix = settings_opt_get("event_log_dir"); |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
639 if (prefix) |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
640 prefix = prefix_xp = expand_filename(prefix); |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
641 else |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
642 prefix = ut_get_tmpdir(); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
643 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
|
644 g_free(prefix_xp); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
645 |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
646 // 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
|
647 fd = mkstemp(datafname); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
648 if (fd == -1) { |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
649 g_free(datafname); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
650 datafname = NULL; |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
651 scr_LogPrint(LPRINT_LOGNORM, |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
652 "Unable to create temp file for external command."); |
1107 | 653 } else { |
1598 | 654 size_t data_locale_len = strlen(data_locale); |
655 ssize_t a = write(fd, data_locale, data_locale_len); | |
656 ssize_t b = write(fd, "\n", 1); | |
1604
351427ef0b4b
Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents:
1602
diff
changeset
|
657 if ((size_t)a != data_locale_len || b != 1) { |
1598 | 658 g_free(datafname); |
659 datafname = NULL; | |
660 scr_LogPrint(LPRINT_LOGNORM, | |
661 "Unable to write to temp file for external command."); | |
662 } | |
1107 | 663 close(fd); |
664 arg_data = datafname; | |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
665 } |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
666 g_free(data_locale); |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
667 } |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
668 |
160 | 669 if ((pid=fork()) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
670 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
|
671 g_free(datafname); |
160 | 672 return; |
673 } | |
674 | |
675 if (pid == 0) { // child | |
656
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
676 // Close standard file descriptors |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
677 close(STDIN_FILENO); |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
678 close(STDOUT_FILENO); |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
679 close(STDERR_FILENO); |
1339
1ea5a4cf2ae0
Correct execl() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
680 if (execl(extcmd, extcmd, arg_type, arg_info, bjid, arg_data, |
1ea5a4cf2ae0
Correct execl() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
681 (char *)NULL) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
682 // scr_LogPrint(LPRINT_LOGNORM, "Cannot execute external command."); |
160 | 683 exit(1); |
684 } | |
685 } | |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
686 g_free(datafname); |
160 | 687 } |
576 | 688 |
580 | 689 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |