Mercurial > hg
annotate mcabber/src/hooks.c @ 1458:17e95be6c39b
time_t fix from the MirBSD port (Thorsten Glaser)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 11 Apr 2008 21:24:02 +0200 |
parents | c6ebf66a4f80 |
children | 7b36b91a4388 |
rev | line source |
---|---|
113 | 1 /* |
699 | 2 * hooks.c -- Hooks layer |
393 | 3 * |
1414 | 4 * Copyright (C) 2005-2008 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 | |
160 | 22 #include <sys/types.h> |
23 #include <unistd.h> | |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
24 #include <stdlib.h> |
113 | 25 |
26 #include "hooks.h" | |
378
2e6c7b1440d1
Improve debugging/logging
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
27 #include "screen.h" |
113 | 28 #include "roster.h" |
29 #include "histolog.h" | |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
30 #include "hbuf.h" |
477 | 31 #include "settings.h" |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
32 #include "utils.h" |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
33 #include "utf8.h" |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
34 #include "commands.h" |
1448
844410b9b4cc
Remove configure option --enable-fifo
Mikael Berthe <mikael@lilotux.net>
parents:
1447
diff
changeset
|
35 #include "fifo.h" |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
36 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
37 static char *extcmd; |
113 | 38 |
1107 | 39 static const char *COMMAND_ME = "/me "; |
40 | |
1425 | 41 void hk_mainloop(void) |
42 { | |
43 /* | |
44 static time_t last; | |
45 time_t now; | |
46 | |
47 time(&now); | |
48 | |
49 if (now > last + 1) { | |
50 // custom_hook(); | |
51 last = now; | |
52 } | |
53 */ | |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1425
diff
changeset
|
54 fifo_read(); |
1425 | 55 } |
56 | |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
57 void hk_message_in(const char *bjid, const char *resname, |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
58 time_t timestamp, const char *msg, const char *type, |
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
59 guint encrypted) |
113 | 60 { |
141 | 61 int new_guy = FALSE; |
477 | 62 int is_groupchat = FALSE; // groupchat message |
63 int is_room = FALSE; // window is a room window | |
64 int log_muc_conf = FALSE; | |
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
65 int active_window = FALSE; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
66 int message_flags = 0; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
67 guint rtype = ROSTER_TYPE_USER; |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
68 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
69 GSList *roster_usr; |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1210
diff
changeset
|
70 unsigned mucnicklen = 0; |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
71 const char *ename = NULL; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
72 |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
73 if (encrypted) |
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
74 message_flags |= HBB_PREFIX_PGPCRYPT; |
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
75 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
76 if (type && !strcmp(type, "groupchat")) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
77 rtype = ROSTER_TYPE_ROOM; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
78 is_groupchat = TRUE; |
477 | 79 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
|
80 if (!resname) { |
648
16cd6c858a5d
MUC: No new_message flag for server messages
Mikael Berthe <mikael@lilotux.net>
parents:
646
diff
changeset
|
81 message_flags = HBB_PREFIX_INFO | HBB_PREFIX_NOFLAG; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
82 resname = ""; |
1107 | 83 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
|
84 } else { |
1107 | 85 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
|
86 mucnicklen = strlen(resname) + 2; |
1107 | 87 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) |
88 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
|
89 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
90 } else { |
1116
14e458020e23
Fix a bug in the history logging (incoming "/me " messages)
Mikael Berthe <mikael@lilotux.net>
parents:
1109
diff
changeset
|
91 bmsg = g_strdup(msg); |
1188
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
92 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
93 gchar *shortid = g_strdup(bjid); |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
94 if (settings_opt_get_int("buddy_me_fulljid") == FALSE) { |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
95 gchar *p = strchr(shortid, '@'); // Truncate the jid |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
96 if (p) |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
97 *p = '\0'; |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
98 } |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
99 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
|
100 g_free(shortid); |
ef40688d87bd
Add option 'buddy_me_fulljid'
Mikael Berthe <mikael@lilotux.net>
parents:
1167
diff
changeset
|
101 } else |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
102 wmsg = (char*) msg; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
103 } |
141 | 104 |
105 // If this user isn't in the roster, we add it | |
1058 | 106 roster_usr = roster_find(bjid, jidsearch, 0); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
107 if (!roster_usr) { |
141 | 108 new_guy = TRUE; |
1355 | 109 roster_usr = roster_add_user(bjid, NULL, NULL, rtype, sub_none, -1); |
477 | 110 if (!roster_usr) { // Shouldn't happen... |
111 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
|
112 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
113 g_free(mmsg); |
477 | 114 return; |
115 } | |
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
485
diff
changeset
|
116 } 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
|
117 // 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
|
118 buddy_settype(roster_usr->data, ROSTER_TYPE_ROOM); |
477 | 119 } |
120 | |
121 is_room = !!(buddy_gettype(roster_usr->data) & ROSTER_TYPE_ROOM); | |
122 | |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
123 if (is_room) { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
124 if (!is_groupchat) { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
125 // 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
|
126 g_free(bmsg); |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
127 if (!resname) { |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
128 resname = ""; |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
129 wmsg = bmsg = g_strdup(msg); |
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
130 } else { |
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
131 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
|
132 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
|
133 g_free(mmsg); |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
134 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
|
135 } |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
136 } |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
137 message_flags |= HBB_PREFIX_HLIGHT; |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
138 } else { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
139 // This is a regular chatroom message. |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
140 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
|
141 |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
142 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
|
143 // 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
|
144 // 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
|
145 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
|
146 message_flags |= HBB_PREFIX_HLIGHT_OUT; |
1207
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
147 } else if (!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
|
148 // 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
|
149 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
|
150 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
|
151 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
|
152 // 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
|
153 // 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
|
154 // 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
|
155 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
|
156 if (msgptr == msg) |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
157 leftb = NULL; |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
158 else |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
159 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
|
160 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
|
161 // Check left boundary |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
162 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
|
163 continue; |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
164 // Check right boundary |
8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
165 if (!iswalnum(get_char(rightb)) && get_char(rightb) != '_') |
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; |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
167 } |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
168 } |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1188
diff
changeset
|
169 } |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
170 } |
141 | 171 } |
172 | |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
173 if (type && !strcmp(type, "error")) { |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
174 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; |
1058 | 175 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
|
176 } |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
177 |
178 | 178 // Note: the hlog_write should not be called first, because in some |
179 // cases scr_WriteIncomingMessage() will load the history and we'd | |
180 // have the message twice... | |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1210
diff
changeset
|
181 scr_WriteIncomingMessage(bjid, wmsg, timestamp, message_flags, mucnicklen); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
182 |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
183 // 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
|
184 if (wmsg == mmsg) |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
185 wmsg = bmsg; |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
186 |
477 | 187 // - We don't log the message if it is an error message |
188 // - We don't log the message if it is a private conf. message | |
189 // - We don't log the message if it is groupchat message and the log_muc_conf | |
190 // option is off (and it is not a history line) | |
191 if (!(message_flags & HBB_PREFIX_ERR) && | |
192 (!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
|
193 hlog_write_message(bjid, timestamp, 0, wmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
194 |
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
195 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
|
196 current_buddy && scr_get_chatmode()) { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
197 gpointer bud = BUDDATA(current_buddy); |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
198 if (bud) { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
199 const char *cjid = buddy_getjid(bud); |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
200 if (cjid && !strcasecmp(cjid, bjid)) |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
201 active_window = TRUE; |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
202 } |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
203 } |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
204 |
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
205 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
|
206 ename = roster_getname(bjid); |
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
207 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
208 // External command |
477 | 209 // - We do not call hk_ext_cmd() for history lines in MUC |
210 // - 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
|
211 // - 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
|
212 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
|
213 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
|
214 |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
215 // Display the sender in the log window |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
216 if ((!is_groupchat) && !(message_flags & HBB_PREFIX_ERR) && |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
217 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
|
218 const char *name = roster_getname(bjid); |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
219 if (!name) name = ""; |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
220 scr_LogPrint(LPRINT_NORMAL, "Message received from %s <%s/%s>", |
1058 | 221 name, bjid, (resname ? resname : "")); |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
222 } |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
223 |
1210
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
224 // Beep, if enabled: |
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
225 // - 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
|
226 // - 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
|
227 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
|
228 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
|
229 (is_groupchat && (message_flags & HBB_PREFIX_HLIGHT))) |
7c8672bbede5
Use beep_on_message's value for highlighted MUC room messages
Mikael Berthe <mikael@lilotux.net>
parents:
1207
diff
changeset
|
230 scr_Beep(); |
887
df4bb1535ef8
Fix beep_on_message in rooms
Mikael Berthe <mikael@lilotux.net>
parents:
856
diff
changeset
|
231 } |
675
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
656
diff
changeset
|
232 |
1010
54405d09b15a
Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
233 // 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
|
234 // if the sender is offline/invisible and a filter is set. |
146 | 235 if (new_guy || |
477 | 236 (buddy_getstatus(roster_usr->data, NULL) == offline && |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
237 buddylist_isset_filter())) |
146 | 238 { |
141 | 239 update_roster = TRUE; |
240 } | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
241 |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
242 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
243 g_free(mmsg); |
113 | 244 } |
245 | |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
246 // 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
|
247 // 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
|
248 // normal messages. |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
249 void hk_message_out(const char *bjid, const char *nick, |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
250 time_t timestamp, const char *msg, guint encrypted) |
113 | 251 { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
252 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
253 |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
254 if (nick) { |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
255 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
|
256 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
|
257 const char *mynick = roster_getnickname(bjid); |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
258 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
|
259 (mynick ? mynick : "me"), msg+4); |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
260 } |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
261 } else { |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
262 wmsg = (char*)msg; |
1107 | 263 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
264 const char *myid = settings_opt_get("username"); |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
265 if (myid) |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
266 wmsg = mmsg = g_strdup_printf("*%s %s", settings_opt_get("username"), |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
267 msg+4); |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
268 } |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
269 } |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
270 |
485 | 271 // Note: the hlog_write should not be called first, because in some |
272 // cases scr_WriteOutgoingMessage() will load the history and we'd | |
273 // have the message twice... | |
1058 | 274 scr_WriteOutgoingMessage(bjid, wmsg, (encrypted ? HBB_PREFIX_PGPCRYPT : 0)); |
485 | 275 |
276 // We don't log private messages | |
1107 | 277 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
|
278 hlog_write_message(bjid, timestamp, 1, msg); |
485 | 279 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
280 // External command |
1058 | 281 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
|
282 |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
283 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
284 g_free(mmsg); |
113 | 285 } |
286 | |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
287 void hk_statuschange(const char *bjid, const char *resname, gchar prio, |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
288 time_t timestamp, enum imstatus status, |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
289 const char *status_msg) |
113 | 290 { |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
291 int st_in_buf; |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
292 enum imstatus oldstat; |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
293 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
|
294 char *logsmsg; |
614 | 295 const char *rn = (resname ? resname : ""); |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
296 const char *ename = NULL; |
1447
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
297 |
ba706e97d6ec
Add option 'eventcmd_use_nickname'
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
298 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
|
299 ename = roster_getname(bjid); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
300 |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
301 oldstat = roster_getstatus(bjid, resname); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
302 |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
303 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
|
304 |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
305 if (settings_opt_get_int("log_display_presence")) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
306 int buddy_format = settings_opt_get_int("buddy_format"); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
307 bn = NULL; |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
308 if (buddy_format) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
309 const char *name = roster_getname(bjid); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
310 if (name && strcmp(name, bjid)) { |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
311 if (buddy_format == 1) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
312 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
|
313 else if (buddy_format == 2) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
314 bn = g_strdup_printf("%s/%s", name, rn); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
315 else if (buddy_format == 3) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
316 bn = g_strdup_printf("%s", name); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
317 } |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
318 } |
1450
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
319 |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
320 if (!bn) |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
321 bn = g_strdup_printf("<%s/%s>", bjid, rn); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
322 |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
323 logsmsg = g_strdup(status_msg ? status_msg : ""); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
324 replace_nl_with_dots(logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
325 |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
326 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
|
327 imstatus2char[oldstat], imstatus2char[status], bn, logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
328 g_free(logsmsg); |
c6ebf66a4f80
Add option 'log_display_presence'
Mikael Berthe <mikael@lilotux.net>
parents:
1449
diff
changeset
|
329 g_free(bn); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
330 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
331 |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
332 if (st_in_buf == 2 || |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
333 (st_in_buf == 1 && (status == offline || oldstat == offline))) { |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
334 // Write the status change in the buddy's buffer, only if it already exists |
1058 | 335 if (scr_BuddyBufferExists(bjid)) { |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
336 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
|
337 imstatus2char[oldstat], imstatus2char[status], |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
338 ((status_msg) ? status_msg : "")); |
1058 | 339 scr_WriteIncomingMessage(bjid, bn, timestamp, |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1210
diff
changeset
|
340 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
341 g_free(bn); |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
342 } |
514
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
343 } |
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
344 |
1058 | 345 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
|
346 role_none, affil_none, NULL); |
120 | 347 buddylist_build(); |
348 scr_DrawRoster(); | |
1058 | 349 hlog_write_status(bjid, timestamp, status, status_msg); |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
350 // External command |
1449
a9a1770e4578
Fix a bug introduced in changeset ba706e97d6ec
Mikael Berthe <mikael@lilotux.net>
parents:
1448
diff
changeset
|
351 hk_ext_cmd(ename ? ename : bjid, 'S', imstatus2char[status], NULL); |
113 | 352 } |
353 | |
1398
f8321420ed7a
Remove useless inline's
Mikael Berthe <mikael@lilotux.net>
parents:
1359
diff
changeset
|
354 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
|
355 enum imstatus new_status, const char *msg) |
116 | 356 { |
541
87165382e4ce
Fix error introduced in changeset 56f641155579
Mikael Berthe <mikael@lilotux.net>
parents:
536
diff
changeset
|
357 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
|
358 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
|
359 (msg ? msg : "")); |
116 | 360 //hlog_write_status(NULL, 0, status); |
361 } | |
362 | |
160 | 363 |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
364 /* Internal commands */ |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
365 |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
366 void hook_execute_internal(const char *hookname) |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
367 { |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
368 const char *hook_command; |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
369 char *buf; |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
370 char *cmdline; |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
371 |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
372 hook_command = settings_opt_get(hookname); |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
373 if (!hook_command) |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
374 return; |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
375 |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
376 buf = g_strdup_printf("Running %s...", hookname); |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
377 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
378 |
1357
7bbfb0073f88
Fix an UTF-8 problem in new hook_execute_internal() function
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
379 cmdline = from_utf8(hook_command); |
1359
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1357
diff
changeset
|
380 if (process_command(cmdline, TRUE) == 255) |
7daf906fbcdc
The command /quit can be used in bindings, hooks and sourced files
Mikael Berthe <mikael@lilotux.net>
parents:
1357
diff
changeset
|
381 mcabber_set_terminate_ui(); |
1352
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
382 |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
383 g_free(cmdline); |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
384 g_free(buf); |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
385 } |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
386 |
61a54e172010
Add internal hooks support
Mikael Berthe <mikael@lilotux.net>
parents:
1342
diff
changeset
|
387 |
160 | 388 /* External commands */ |
389 | |
390 // hk_ext_cmd_init() | |
391 // Initialize external command variable. | |
392 // 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
|
393 void hk_ext_cmd_init(const char *command) |
160 | 394 { |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
395 if (extcmd) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
396 g_free(extcmd); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
397 extcmd = NULL; |
160 | 398 } |
399 if (command) | |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
400 extcmd = expand_filename(command); |
160 | 401 } |
402 | |
403 // hk_ext_cmd() | |
404 // Launch an external command (process) for the given event. | |
405 // For now, data should be NULL. | |
1058 | 406 void hk_ext_cmd(const char *bjid, guchar type, guchar info, const char *data) |
160 | 407 { |
408 pid_t pid; | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
409 char *arg_type = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
410 char *arg_info = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
411 char *arg_data = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
412 char status_str[2]; |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
413 char *datafname = NULL; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
414 char unread_str[16]; |
160 | 415 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
416 if (!extcmd) return; |
160 | 417 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
418 // Prepare arg_* (external command parameters) |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
419 switch (type) { |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
420 case 'M': /* Normal message */ |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
421 arg_type = "MSG"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
422 if (info == 'R') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
423 arg_info = "IN"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
424 else if (info == 'S') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
425 arg_info = "OUT"; |
453
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
426 break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
427 case 'G': /* Groupchat message */ |
453
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
428 arg_type = "MSG"; |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
429 arg_info = "MUC"; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
430 break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
431 case 'S': /* Status change */ |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
432 arg_type = "STATUS"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
433 if (strchr(imstatus2char, tolower(info))) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
434 status_str[0] = toupper(info); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
435 status_str[1] = 0; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
436 arg_info = status_str; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
437 } |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
438 break; |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
439 case 'U': /* Unread buffer count */ |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
440 arg_type = "UNREAD"; |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
441 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
|
442 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
|
443 break; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
444 default: |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
445 return; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
446 } |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
447 |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
448 if (!arg_type || !arg_info) return; |
160 | 449 |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
450 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
|
451 int fd; |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
452 const char *prefix; |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
453 char *prefix_xp = NULL; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
454 char *data_locale; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
455 |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
456 data_locale = from_utf8(data); |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
457 prefix = settings_opt_get("event_log_dir"); |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
458 if (prefix) |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
459 prefix = prefix_xp = expand_filename(prefix); |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
460 else |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
461 prefix = ut_get_tmpdir(); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
462 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
|
463 g_free(prefix_xp); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
464 |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
465 // 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
|
466 fd = mkstemp(datafname); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
467 if (fd == -1) { |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
468 g_free(datafname); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
469 datafname = NULL; |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
470 scr_LogPrint(LPRINT_LOGNORM, |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
471 "Unable to create temp file for external command."); |
1107 | 472 } else { |
473 write(fd, data_locale, strlen(data_locale)); | |
474 write(fd, "\n", 1); | |
475 close(fd); | |
476 arg_data = datafname; | |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
477 } |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
478 g_free(data_locale); |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
479 } |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
480 |
160 | 481 if ((pid=fork()) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
482 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
|
483 g_free(datafname); |
160 | 484 return; |
485 } | |
486 | |
487 if (pid == 0) { // child | |
656
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
488 // Close standard file descriptors |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
489 close(STDIN_FILENO); |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
490 close(STDOUT_FILENO); |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
491 close(STDERR_FILENO); |
1339
1ea5a4cf2ae0
Correct execl() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
492 if (execl(extcmd, extcmd, arg_type, arg_info, bjid, arg_data, |
1ea5a4cf2ae0
Correct execl() prototype
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
493 (char *)NULL) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
494 // scr_LogPrint(LPRINT_LOGNORM, "Cannot execute external command."); |
160 | 495 exit(1); |
496 } | |
497 } | |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
498 g_free(datafname); |
160 | 499 } |
576 | 500 |
580 | 501 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |