Mercurial > hg
comparison mcabber/src/hooks.c @ 1107:1db3d045e95c
Fix 2 hooks bugs
- do not write to file descriptor if mkstemp() fails;
- remove bogus mkcmdstr("me ").
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 14 Dec 2006 20:39:18 +0100 |
parents | c0d44a9a99bc |
children | a0e9eaa9f5b4 |
comparison
equal
deleted
inserted
replaced
1106:8e12137fab20 | 1107:1db3d045e95c |
---|---|
31 #include "settings.h" | 31 #include "settings.h" |
32 #include "utils.h" | 32 #include "utils.h" |
33 | 33 |
34 static char *extcmd; | 34 static char *extcmd; |
35 | 35 |
36 static const char *COMMAND_ME = "/me "; | |
37 | |
36 inline void hk_message_in(const char *bjid, const char *resname, | 38 inline void hk_message_in(const char *bjid, const char *resname, |
37 time_t timestamp, const char *msg, const char *type, | 39 time_t timestamp, const char *msg, const char *type, |
38 guint encrypted) | 40 guint encrypted) |
39 { | 41 { |
40 int new_guy = FALSE; | 42 int new_guy = FALSE; |
54 is_groupchat = TRUE; | 56 is_groupchat = TRUE; |
55 log_muc_conf = settings_opt_get_int("log_muc_conf"); | 57 log_muc_conf = settings_opt_get_int("log_muc_conf"); |
56 if (!resname) { | 58 if (!resname) { |
57 message_flags = HBB_PREFIX_INFO | HBB_PREFIX_NOFLAG; | 59 message_flags = HBB_PREFIX_INFO | HBB_PREFIX_NOFLAG; |
58 resname = ""; | 60 resname = ""; |
59 bmsg = g_strdup_printf("~ %s", msg); | 61 wmsg = bmsg = g_strdup_printf("~ %s", msg); |
60 } else { | 62 } else { |
61 bmsg = g_strdup_printf("<%s> %s", resname, msg); | 63 wmsg = bmsg = g_strdup_printf("<%s> %s", resname, msg); |
62 } | 64 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) |
63 wmsg = bmsg; | 65 wmsg = mmsg = g_strdup_printf("*%s %s", resname, msg+4); |
64 if (!strncmp(msg, mkcmdstr("me "), strlen(mkcmdstr("me ")))) | 66 } |
65 wmsg = mmsg = g_strdup_printf("*%s %s", resname, msg+4); | |
66 } else { | 67 } else { |
67 if (!strncmp(msg, mkcmdstr("me "), strlen(mkcmdstr("me ")))) | 68 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) |
68 wmsg = mmsg = g_strdup_printf("*%s %s", bjid, msg+4); | 69 wmsg = mmsg = g_strdup_printf("*%s %s", bjid, msg+4); |
69 else | 70 else |
70 wmsg = (char*) msg; | 71 wmsg = (char*) msg; |
71 } | 72 } |
72 | 73 |
94 if (!resname) { | 95 if (!resname) { |
95 resname = ""; | 96 resname = ""; |
96 wmsg = bmsg = g_strdup(msg); | 97 wmsg = bmsg = g_strdup(msg); |
97 } else { | 98 } else { |
98 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", resname, msg); | 99 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", resname, msg); |
99 if (!strncmp(msg, mkcmdstr("me "), strlen(mkcmdstr("me ")))) | 100 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) |
100 wmsg = mmsg = g_strdup_printf("PRIV#*%s %s", resname, msg+4); | 101 wmsg = mmsg = g_strdup_printf("PRIV#*%s %s", resname, msg+4); |
101 } | 102 } |
102 } else { | 103 } else { |
103 // This is a regular chatroom message. | 104 // This is a regular chatroom message. |
104 // Let's see if we are the message sender, in which case we'll | 105 // Let's see if we are the message sender, in which case we'll |
173 { | 174 { |
174 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; | 175 char *wmsg = NULL, *bmsg = NULL, *mmsg = NULL; |
175 | 176 |
176 if (nick) { | 177 if (nick) { |
177 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", nick, msg); | 178 wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", nick, msg); |
179 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) | |
180 wmsg = mmsg = g_strdup_printf("PRIV#*%s %s", nick, msg+4); | |
178 } else { | 181 } else { |
179 wmsg = (char*)msg; | 182 wmsg = (char*)msg; |
180 if (!strncmp(msg, mkcmdstr("me "), strlen(mkcmdstr("me ")))) { | 183 if (!strncmp(msg, COMMAND_ME, strlen(COMMAND_ME))) { |
181 const char *myid = settings_opt_get("username"); | 184 const char *myid = settings_opt_get("username"); |
182 if (myid) | 185 if (myid) |
183 wmsg = mmsg = g_strdup_printf("*%s %s", settings_opt_get("username"), | 186 wmsg = mmsg = g_strdup_printf("*%s %s", settings_opt_get("username"), |
184 msg+4); | 187 msg+4); |
185 } | 188 } |
189 // cases scr_WriteOutgoingMessage() will load the history and we'd | 192 // cases scr_WriteOutgoingMessage() will load the history and we'd |
190 // have the message twice... | 193 // have the message twice... |
191 scr_WriteOutgoingMessage(bjid, wmsg, (encrypted ? HBB_PREFIX_PGPCRYPT : 0)); | 194 scr_WriteOutgoingMessage(bjid, wmsg, (encrypted ? HBB_PREFIX_PGPCRYPT : 0)); |
192 | 195 |
193 // We don't log private messages | 196 // We don't log private messages |
194 if (!nick) hlog_write_message(bjid, timestamp, TRUE, msg); | 197 if (!nick) |
198 hlog_write_message(bjid, timestamp, TRUE, msg); | |
195 | 199 |
196 // External command | 200 // External command |
197 hk_ext_cmd(bjid, 'M', 'S', NULL); | 201 hk_ext_cmd(bjid, 'M', 'S', NULL); |
198 | 202 |
199 g_free(bmsg); | 203 g_free(bmsg); |
342 if (fd == -1) { | 346 if (fd == -1) { |
343 g_free(datafname); | 347 g_free(datafname); |
344 datafname = NULL; | 348 datafname = NULL; |
345 scr_LogPrint(LPRINT_LOGNORM, | 349 scr_LogPrint(LPRINT_LOGNORM, |
346 "Unable to create temp file for external command."); | 350 "Unable to create temp file for external command."); |
347 } | 351 } else { |
348 write(fd, data_locale, strlen(data_locale)); | 352 write(fd, data_locale, strlen(data_locale)); |
349 write(fd, "\n", 1); | 353 write(fd, "\n", 1); |
350 close(fd); | 354 close(fd); |
351 arg_data = datafname; | 355 arg_data = datafname; |
356 } | |
352 g_free(data_locale); | 357 g_free(data_locale); |
353 } | 358 } |
354 | 359 |
355 if ((pid=fork()) == -1) { | 360 if ((pid=fork()) == -1) { |
356 scr_LogPrint(LPRINT_LOGNORM, "Fork error, cannot launch external command."); | 361 scr_LogPrint(LPRINT_LOGNORM, "Fork error, cannot launch external command."); |