Mercurial > ~mikael > mcabber > hg
annotate mcabber/src/hooks.c @ 1176:547a8ca7c1a8
Move init_bindings() to screen.c, with a few updates
- Move the function init_bindings() to screen.c scr_init_bindings()
- Get rid of the malloc/free
- Add two key bindings: Meta-a, Meta-b
- Put the comments on the same line when it is possible, in order to save
some space.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Wed, 04 Apr 2007 22:03:49 +0200 |
parents | 9726c78a91f3 |
children | ef40688d87bd |
rev | line source |
---|---|
113 | 1 /* |
699 | 2 * hooks.c -- Hooks layer |
393 | 3 * |
699 | 4 * Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.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" |
113 | 33 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
34 static char *extcmd; |
113 | 35 |
1107 | 36 static const char *COMMAND_ME = "/me "; |
37 | |
1058 | 38 inline 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
|
39 time_t timestamp, const char *msg, const char *type, |
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
40 guint encrypted) |
113 | 41 { |
141 | 42 int new_guy = FALSE; |
477 | 43 int is_groupchat = FALSE; // groupchat message |
44 int is_room = FALSE; // window is a room window | |
45 int log_muc_conf = FALSE; | |
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
46 int active_window = FALSE; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
47 int message_flags = 0; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
48 guint rtype = ROSTER_TYPE_USER; |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
49 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
50 GSList *roster_usr; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
51 |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
52 if (encrypted) |
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
53 message_flags |= HBB_PREFIX_PGPCRYPT; |
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
54 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
55 if (type && !strcmp(type, "groupchat")) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
56 rtype = ROSTER_TYPE_ROOM; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
57 is_groupchat = TRUE; |
477 | 58 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
|
59 if (!resname) { |
648
16cd6c858a5d
MUC: No new_message flag for server messages
Mikael Berthe <mikael@lilotux.net>
parents:
646
diff
changeset
|
60 message_flags = HBB_PREFIX_INFO | HBB_PREFIX_NOFLAG; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
61 resname = ""; |
1107 | 62 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
|
63 } else { |
1107 | 64 wmsg = bmsg = g_strdup_printf("<%s> %s", resname, msg); |
65 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) | |
66 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
|
67 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
68 } else { |
1116
14e458020e23
Fix a bug in the history logging (incoming "/me " messages)
Mikael Berthe <mikael@lilotux.net>
parents:
1109
diff
changeset
|
69 bmsg = g_strdup(msg); |
1107 | 70 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) |
1058 | 71 wmsg = mmsg = g_strdup_printf("*%s %s", bjid, msg+4); |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
72 else |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
73 wmsg = (char*) msg; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
74 } |
141 | 75 |
76 // If this user isn't in the roster, we add it | |
1058 | 77 roster_usr = roster_find(bjid, jidsearch, 0); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
78 if (!roster_usr) { |
141 | 79 new_guy = TRUE; |
1058 | 80 roster_usr = roster_add_user(bjid, NULL, NULL, rtype, sub_none); |
477 | 81 if (!roster_usr) { // Shouldn't happen... |
82 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
|
83 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
84 g_free(mmsg); |
477 | 85 return; |
86 } | |
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
485
diff
changeset
|
87 } 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
|
88 // 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
|
89 buddy_settype(roster_usr->data, ROSTER_TYPE_ROOM); |
477 | 90 } |
91 | |
92 is_room = !!(buddy_gettype(roster_usr->data) & ROSTER_TYPE_ROOM); | |
93 | |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
94 if (is_room) { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
95 if (!is_groupchat) { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
96 // 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
|
97 g_free(bmsg); |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
98 if (!resname) { |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
99 resname = ""; |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
100 wmsg = bmsg = g_strdup(msg); |
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
101 } else { |
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
102 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
|
103 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
|
104 g_free(mmsg); |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
105 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
|
106 } |
734
1d9f0efcfcee
MUC: Do not mark error messages as private
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
107 } |
728
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
108 } else { |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
109 // This is a regular chatroom message. |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
110 // Let's see if we are the message sender, in which case we'll |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
111 // highlight it. |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
112 const char *nick = buddy_getnickname(roster_usr->data); |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
113 if (resname && nick && !strcmp(resname, nick)) |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
114 message_flags |= HBB_PREFIX_HLIGHT; |
421b337dc6d2
Chat window: Highlight the flag in our messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
115 } |
141 | 116 } |
117 | |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
118 if (type && !strcmp(type, "error")) { |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
119 message_flags = HBB_PREFIX_ERR | HBB_PREFIX_IN; |
1058 | 120 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
|
121 } |
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
318
diff
changeset
|
122 |
178 | 123 // Note: the hlog_write should not be called first, because in some |
124 // cases scr_WriteIncomingMessage() will load the history and we'd | |
125 // have the message twice... | |
1058 | 126 scr_WriteIncomingMessage(bjid, wmsg, timestamp, message_flags); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
127 |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
128 // 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
|
129 if (wmsg == mmsg) |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
130 wmsg = bmsg; |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
131 |
477 | 132 // - We don't log the message if it is an error message |
133 // - We don't log the message if it is a private conf. message | |
134 // - We don't log the message if it is groupchat message and the log_muc_conf | |
135 // option is off (and it is not a history line) | |
136 if (!(message_flags & HBB_PREFIX_ERR) && | |
137 (!is_room || (is_groupchat && log_muc_conf && !timestamp))) | |
1058 | 138 hlog_write_message(bjid, timestamp, FALSE, wmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
139 |
1129
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
140 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
|
141 current_buddy && scr_get_chatmode()) { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
142 gpointer bud = BUDDATA(current_buddy); |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
143 if (bud) { |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
144 const char *cjid = buddy_getjid(bud); |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
145 if (cjid && !strcasecmp(cjid, bjid)) |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
146 active_window = TRUE; |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
147 } |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
148 } |
1a109ebf3f24
Add option "events_ignore_active_window"
Mikael Berthe <mikael@lilotux.net>
parents:
1116
diff
changeset
|
149 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
150 // External command |
477 | 151 // - We do not call hk_ext_cmd() for history lines in MUC |
152 // - 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
|
153 // - 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
|
154 if (!active_window && ((is_groupchat && !timestamp) || !is_groupchat)) |
1058 | 155 hk_ext_cmd(bjid, (is_groupchat ? 'G' : 'M'), 'R', wmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
156 |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
157 // Display the sender in the log window |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
158 if ((!is_groupchat) && !(message_flags & HBB_PREFIX_ERR) && |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
159 settings_opt_get_int("log_display_sender")) { |
1058 | 160 const char *name = roster_getname(bjid); |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
161 if (!name) name = ""; |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
162 scr_LogPrint(LPRINT_NORMAL, "Message received from %s <%s/%s>", |
1058 | 163 name, bjid, (resname ? resname : "")); |
808
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
164 } |
4a6ce276ffca
New option "log_display_sender"
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
165 |
675
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
656
diff
changeset
|
166 // Beep, if enabled |
887
df4bb1535ef8
Fix beep_on_message in rooms
Mikael Berthe <mikael@lilotux.net>
parents:
856
diff
changeset
|
167 if ((!is_groupchat) && !(message_flags & HBB_PREFIX_ERR) && |
df4bb1535ef8
Fix beep_on_message in rooms
Mikael Berthe <mikael@lilotux.net>
parents:
856
diff
changeset
|
168 settings_opt_get_int("beep_on_message")) { |
675
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
656
diff
changeset
|
169 scr_Beep(); |
887
df4bb1535ef8
Fix beep_on_message in rooms
Mikael Berthe <mikael@lilotux.net>
parents:
856
diff
changeset
|
170 } |
675
ae7016aae014
New "beep_on_message" option
Mikael Berthe <mikael@lilotux.net>
parents:
656
diff
changeset
|
171 |
1010
54405d09b15a
Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents:
967
diff
changeset
|
172 // We need to update the roster if the sender is unknown or |
146 | 173 // if the sender is offline/invisible and hide_offline_buddies is set |
174 if (new_guy || | |
477 | 175 (buddy_getstatus(roster_usr->data, NULL) == offline && |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
176 buddylist_get_hide_offline_buddies())) |
146 | 177 { |
141 | 178 update_roster = TRUE; |
179 } | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
180 |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
181 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
182 g_free(mmsg); |
113 | 183 } |
184 | |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
185 // 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
|
186 // 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
|
187 // normal messages. |
1058 | 188 inline 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
|
189 time_t timestamp, const char *msg, guint encrypted) |
113 | 190 { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
191 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
|
192 |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
193 if (nick) { |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
194 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
|
195 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
|
196 const char *mynick = roster_getnickname(bjid); |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
197 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
|
198 (mynick ? mynick : "me"), msg+4); |
7e383aa48b3d
Fix a small mistake introduced in changeset 1db3d045e95c
Mikael Berthe <mikael@lilotux.net>
parents:
1108
diff
changeset
|
199 } |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
200 } else { |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
201 wmsg = (char*)msg; |
1107 | 202 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
567
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
203 const char *myid = settings_opt_get("username"); |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
204 if (myid) |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
205 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
|
206 msg+4); |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
207 } |
6f490c725999
Handle "/me " in messages
Mikael Berthe <mikael@lilotux.net>
parents:
541
diff
changeset
|
208 } |
484
00e2d3821a5b
Display PRIV for private messages in a room when using /say_to
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
209 |
485 | 210 // Note: the hlog_write should not be called first, because in some |
211 // cases scr_WriteOutgoingMessage() will load the history and we'd | |
212 // have the message twice... | |
1058 | 213 scr_WriteOutgoingMessage(bjid, wmsg, (encrypted ? HBB_PREFIX_PGPCRYPT : 0)); |
485 | 214 |
215 // We don't log private messages | |
1107 | 216 if (!nick) |
217 hlog_write_message(bjid, timestamp, TRUE, msg); | |
485 | 218 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
219 // External command |
1058 | 220 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
|
221 |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
222 g_free(bmsg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
223 g_free(mmsg); |
113 | 224 } |
225 | |
1058 | 226 inline 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
|
227 time_t timestamp, enum imstatus status, |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
228 const char *status_msg) |
113 | 229 { |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
230 int buddy_format; |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
231 int st_in_buf; |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
232 enum imstatus oldstat; |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
233 char *bn = NULL; |
655
de6837908702
Use "(...)" when cutting a multi-line status message in the log window
Mikael Berthe <mikael@lilotux.net>
parents:
648
diff
changeset
|
234 char *logsmsg; |
614 | 235 const char *rn = (resname ? resname : ""); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
236 |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
237 st_in_buf = settings_opt_get_int("show_status_in_buffer"); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
238 buddy_format = settings_opt_get_int("buddy_format"); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
239 if (buddy_format) { |
1058 | 240 const char *name = roster_getname(bjid); |
241 if (name && strcmp(name, bjid)) { | |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
242 if (buddy_format == 1) |
1058 | 243 bn = g_strdup_printf("%s <%s/%s>", name, bjid, rn); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
244 else if (buddy_format == 2) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
245 bn = g_strdup_printf("%s/%s", name, rn); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
246 else if (buddy_format == 3) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
247 bn = g_strdup_printf("%s", name); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
248 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
249 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
250 |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
251 if (!bn) { |
1058 | 252 bn = g_strdup_printf("<%s/%s>", bjid, rn); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
253 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
254 |
591
5a685e9012b4
Show only the 1st line of the status message, in the log window
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
255 logsmsg = g_strdup(status_msg ? status_msg : ""); |
655
de6837908702
Use "(...)" when cutting a multi-line status message in the log window
Mikael Berthe <mikael@lilotux.net>
parents:
648
diff
changeset
|
256 replace_nl_with_dots(logsmsg); |
591
5a685e9012b4
Show only the 1st line of the status message, in the log window
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
257 |
1058 | 258 oldstat = roster_getstatus(bjid, resname); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
259 scr_LogPrint(LPRINT_LOGNORM, "Buddy status has changed: [%c>%c] %s %s", |
591
5a685e9012b4
Show only the 1st line of the status message, in the log window
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
260 imstatus2char[oldstat], imstatus2char[status], bn, logsmsg); |
5a685e9012b4
Show only the 1st line of the status message, in the log window
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
261 g_free(logsmsg); |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
262 g_free(bn); |
514
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
263 |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
264 if (st_in_buf == 2 || |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
265 (st_in_buf == 1 && (status == offline || oldstat == offline))) { |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
266 // Write the status change in the buddy's buffer, only if it already exists |
1058 | 267 if (scr_BuddyBufferExists(bjid)) { |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
268 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
|
269 imstatus2char[oldstat], imstatus2char[status], |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
270 ((status_msg) ? status_msg : "")); |
1058 | 271 scr_WriteIncomingMessage(bjid, bn, timestamp, |
830
80434fde7cfa
Display presence notification timestamps when they exist
Mikael Berthe <mikael@lilotux.net>
parents:
808
diff
changeset
|
272 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); |
516
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
273 g_free(bn); |
e5008032edb8
Add option 'show_status_in_buffer'
Mikael Berthe <mikael@lilotux.net>
parents:
514
diff
changeset
|
274 } |
514
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
275 } |
979eb0fe2969
Show status changes in buddy window, if it is open
Mikael Berthe <mikael@lilotux.net>
parents:
510
diff
changeset
|
276 |
1058 | 277 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
|
278 role_none, affil_none, NULL); |
120 | 279 buddylist_build(); |
280 scr_DrawRoster(); | |
1058 | 281 hlog_write_status(bjid, timestamp, status, status_msg); |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
282 // External command |
1058 | 283 hk_ext_cmd(bjid, 'S', imstatus2char[status], NULL); |
113 | 284 } |
285 | |
536
56f641155579
Status change was not displayed when same status but message removed
Mikael Berthe <mikael@lilotux.net>
parents:
524
diff
changeset
|
286 inline void hk_mystatuschange(time_t timestamp, enum imstatus old_status, |
56f641155579
Status change was not displayed when same status but message removed
Mikael Berthe <mikael@lilotux.net>
parents:
524
diff
changeset
|
287 enum imstatus new_status, const char *msg) |
116 | 288 { |
541
87165382e4ce
Fix error introduced in changeset 56f641155579
Mikael Berthe <mikael@lilotux.net>
parents:
536
diff
changeset
|
289 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
|
290 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
|
291 (msg ? msg : "")); |
116 | 292 //hlog_write_status(NULL, 0, status); |
293 } | |
294 | |
160 | 295 |
296 /* External commands */ | |
297 | |
298 // hk_ext_cmd_init() | |
299 // Initialize external command variable. | |
300 // 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
|
301 void hk_ext_cmd_init(const char *command) |
160 | 302 { |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
303 if (extcmd) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
304 g_free(extcmd); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
305 extcmd = NULL; |
160 | 306 } |
307 if (command) | |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
308 extcmd = expand_filename(command); |
160 | 309 } |
310 | |
311 // hk_ext_cmd() | |
312 // Launch an external command (process) for the given event. | |
313 // For now, data should be NULL. | |
1058 | 314 void hk_ext_cmd(const char *bjid, guchar type, guchar info, const char *data) |
160 | 315 { |
316 pid_t pid; | |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
317 char *arg_type = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
318 char *arg_info = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
319 char *arg_data = NULL; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
320 char status_str[2]; |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
321 char *datafname = NULL; |
160 | 322 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
323 if (!extcmd) return; |
160 | 324 |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
325 // Prepare arg_* (external command parameters) |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
326 switch (type) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
327 case 'M': |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
328 arg_type = "MSG"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
329 if (info == 'R') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
330 arg_info = "IN"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
331 else if (info == 'S') |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
332 arg_info = "OUT"; |
453
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
333 break; |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
334 case 'G': |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
335 arg_type = "MSG"; |
39e173645f9c
External command is called for MUC messages
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
336 arg_info = "MUC"; |
355
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
337 break; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
338 case 'S': |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
339 arg_type = "STATUS"; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
340 if (strchr(imstatus2char, tolower(info))) { |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
341 status_str[0] = toupper(info); |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
342 status_str[1] = 0; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
343 arg_info = status_str; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
344 } |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
345 break; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
346 default: |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
347 return; |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
348 } |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
349 |
c5a7a7273986
Add some external actions
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
350 if (!arg_type || !arg_info) return; |
160 | 351 |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
352 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
|
353 int fd; |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
354 const char *prefix; |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
355 char *prefix_xp = NULL; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
356 char *data_locale; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
357 |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
358 data_locale = from_utf8(data); |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
359 prefix = settings_opt_get("event_log_dir"); |
1167
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
360 if (prefix) |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
361 prefix = prefix_xp = expand_filename(prefix); |
9726c78a91f3
Allow '~' (HOME directory) in config options
Mikael Berthe <mikael@lilotux.net>
parents:
1129
diff
changeset
|
362 else |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
363 prefix = ut_get_tmpdir(); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
364 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
|
365 g_free(prefix_xp); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
366 |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
367 // 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
|
368 fd = mkstemp(datafname); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
369 if (fd == -1) { |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
370 g_free(datafname); |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
371 datafname = NULL; |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
372 scr_LogPrint(LPRINT_LOGNORM, |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
373 "Unable to create temp file for external command."); |
1107 | 374 } else { |
375 write(fd, data_locale, strlen(data_locale)); | |
376 write(fd, "\n", 1); | |
377 close(fd); | |
378 arg_data = datafname; | |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
379 } |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
380 g_free(data_locale); |
524
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
381 } |
05c0e55c4bb1
Pass message body to external command
Mikael Berthe <mikael@lilotux.net>
parents:
516
diff
changeset
|
382 |
160 | 383 if ((pid=fork()) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
384 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
|
385 g_free(datafname); |
160 | 386 return; |
387 } | |
388 | |
389 if (pid == 0) { // child | |
656
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
390 // Close standard file descriptors |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
391 close(STDIN_FILENO); |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
392 close(STDOUT_FILENO); |
29a0637c176f
Close standard fds before launching the eventcmd process
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
393 close(STDERR_FILENO); |
1058 | 394 if (execl(extcmd, extcmd, arg_type, arg_info, bjid, arg_data, NULL) == -1) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
395 // scr_LogPrint(LPRINT_LOGNORM, "Cannot execute external command."); |
160 | 396 exit(1); |
397 } | |
398 } | |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
399 g_free(datafname); |
160 | 400 } |
576 | 401 |
580 | 402 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |