summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2002-01-09 16:04:53 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2002-01-09 16:04:53 +0000
commit6e4730b65dfaa034f9160291df1307d849fe61c4 (patch)
tree92d6c21278b85b18d6d516fc84af49b6ec8465bf
parenta01aab7a649b73cee3e7a73ade21498293f1a03e (diff)
downloadirssi-6e4730b65dfaa034f9160291df1307d849fe61c4.zip
Added "message dcc xxx" signals for printing DCC messages.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2298 dbcabf3a-b0e7-0310-adc4-f8d773084564
-rw-r--r--docs/signals.txt8
-rw-r--r--src/fe-common/irc/dcc/Makefile.am3
-rw-r--r--src/fe-common/irc/dcc/fe-dcc-chat-messages.c128
-rw-r--r--src/fe-common/irc/dcc/fe-dcc-chat.c62
-rw-r--r--src/fe-common/irc/dcc/module-formats.c3
-rw-r--r--src/fe-common/irc/dcc/module-formats.h1
-rw-r--r--src/irc/dcc/dcc-chat.c26
7 files changed, 181 insertions, 50 deletions
diff --git a/docs/signals.txt b/docs/signals.txt
index 545e5350..a7936edc 100644
--- a/docs/signals.txt
+++ b/docs/signals.txt
@@ -298,6 +298,14 @@ fe-irc-messages.c:
"message irc own_ctcp", SERVER_REC, char *cmd, char *data, char *target
"message irc ctcp", SERVER_REC, char *msg, char *nick, char *address, char *target
+dcc/fe-dcc-chat-messages.c:
+ "message dcc own", DCC_REC *dcc, char *msg
+ "message dcc own_action", DCC_REC *dcc, char *msg
+ "message dcc own_ctcp", DCC_REC *dcc, char *cmd, char *data
+ "message dcc", DCC_REC *dcc, char *msg
+ "message dcc action", DCC_REC *dcc, char *msg
+ "message dcc ctcp", DCC_REC *dcc, char *cmd, char *data
+
Text FE
-------
diff --git a/src/fe-common/irc/dcc/Makefile.am b/src/fe-common/irc/dcc/Makefile.am
index ad487e95..dbe31f30 100644
--- a/src/fe-common/irc/dcc/Makefile.am
+++ b/src/fe-common/irc/dcc/Makefile.am
@@ -13,6 +13,7 @@ INCLUDES = \
libfe_irc_dcc_a_SOURCES = \
fe-dcc.c \
fe-dcc-chat.c \
+ fe-dcc-chat-messages.c \
fe-dcc-get.c \
fe-dcc-send.c \
module-formats.c
@@ -20,4 +21,4 @@ libfe_irc_dcc_a_SOURCES = \
noinst_HEADERS = \
module.h \
module-formats.h \
- fe-dcc.h \ No newline at end of file
+ fe-dcc.h
diff --git a/src/fe-common/irc/dcc/fe-dcc-chat-messages.c b/src/fe-common/irc/dcc/fe-dcc-chat-messages.c
new file mode 100644
index 00000000..8da38fda
--- /dev/null
+++ b/src/fe-common/irc/dcc/fe-dcc-chat-messages.c
@@ -0,0 +1,128 @@
+/*
+ fe-dcc-chat-messages.c : irssi
+
+ Copyright (C) 2002 Timo Sirainen
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "module.h"
+#include "signals.h"
+#include "levels.h"
+
+#include "irc-queries.h"
+#include "dcc-chat.h"
+
+#include "module-formats.h"
+#include "printtext.h"
+
+static void sig_message_dcc_own(CHAT_DCC_REC *dcc, const char *msg)
+{
+ QUERY_REC *query;
+ char *tag;
+
+ tag = g_strconcat("=", dcc->id, NULL);
+ query = query_find(NULL, tag);
+
+ printformat(NULL, tag, MSGLEVEL_DCCMSGS | MSGLEVEL_NOHILIGHT,
+ query != NULL ? IRCTXT_OWN_DCC_QUERY :
+ IRCTXT_OWN_DCC, dcc->mynick, dcc->id, msg);
+ g_free(tag);
+}
+
+static void sig_message_dcc_own_action(CHAT_DCC_REC *dcc, const char *msg)
+{
+ QUERY_REC *query;
+ char *tag;
+
+ tag = g_strconcat("=", dcc->id, NULL);
+ query = query_find(NULL, tag);
+
+ printformat(NULL, tag, MSGLEVEL_DCCMSGS | MSGLEVEL_NOHILIGHT,
+ query != NULL ? IRCTXT_OWN_DCC_ACTION_QUERY :
+ IRCTXT_OWN_DCC_ACTION, dcc->mynick, dcc->id, msg);
+ g_free(tag);
+}
+
+static void sig_message_dcc_own_ctcp(CHAT_DCC_REC *dcc, const char *cmd,
+ const char *data)
+{
+ char *tag;
+
+ tag = g_strconcat("=", dcc->id, NULL);
+
+ printformat(NULL, tag, MSGLEVEL_DCC, IRCTXT_OWN_DCC_CTCP,
+ dcc->id, cmd, data);
+ g_free(tag);
+}
+
+static void sig_message_dcc(CHAT_DCC_REC *dcc, const char *msg)
+{
+ QUERY_REC *query;
+ char *tag;
+
+ tag = g_strconcat("=", dcc->id, NULL);
+
+ query = query_find(NULL, tag);
+ printformat(NULL, tag, MSGLEVEL_DCCMSGS,
+ query != NULL ? IRCTXT_DCC_MSG_QUERY : IRCTXT_DCC_MSG,
+ dcc->id, msg);
+ g_free(tag);
+}
+
+static void sig_message_dcc_action(CHAT_DCC_REC *dcc, const char *msg)
+{
+ QUERY_REC *query;
+ char *tag;
+
+ tag = g_strconcat("=", dcc->id, NULL);
+
+ query = query_find(NULL, tag);
+ printformat(NULL, tag, MSGLEVEL_DCCMSGS | MSGLEVEL_ACTIONS,
+ query != NULL ? IRCTXT_ACTION_DCC_QUERY :
+ IRCTXT_ACTION_DCC, dcc->id, dcc->mynick, msg);
+ g_free(tag);
+}
+
+static void sig_message_dcc_ctcp(CHAT_DCC_REC *dcc, const char *cmd,
+ const char *data)
+{
+ char *tag;
+
+ tag = g_strconcat("=", dcc->id, NULL);
+ printformat(NULL, tag, MSGLEVEL_DCC, IRCTXT_DCC_CTCP,
+ dcc->id, cmd, data);
+ g_free(tag);
+}
+
+void fe_dcc_chat_messages_init(void)
+{
+ signal_add("message dcc own", (SIGNAL_FUNC) sig_message_dcc_own);
+ signal_add("message dcc own_action", (SIGNAL_FUNC) sig_message_dcc_own_action);
+ signal_add("message dcc own_ctcp", (SIGNAL_FUNC) sig_message_dcc_own_ctcp);
+ signal_add("message dcc", (SIGNAL_FUNC) sig_message_dcc);
+ signal_add("message dcc action", (SIGNAL_FUNC) sig_message_dcc_action);
+ signal_add("message dcc ctcp", (SIGNAL_FUNC) sig_message_dcc_ctcp);
+}
+
+void fe_dcc_chat_messages_deinit(void)
+{
+ signal_remove("message dcc own", (SIGNAL_FUNC) sig_message_dcc_own);
+ signal_remove("message dcc own_action", (SIGNAL_FUNC) sig_message_dcc_own_action);
+ signal_remove("message dcc own_ctcp", (SIGNAL_FUNC) sig_message_dcc_own_ctcp);
+ signal_remove("message dcc", (SIGNAL_FUNC) sig_message_dcc);
+ signal_remove("message dcc action", (SIGNAL_FUNC) sig_message_dcc_action);
+ signal_remove("message dcc ctcp", (SIGNAL_FUNC) sig_message_dcc_ctcp);
+}
diff --git a/src/fe-common/irc/dcc/fe-dcc-chat.c b/src/fe-common/irc/dcc/fe-dcc-chat.c
index b1bad934..e57056e0 100644
--- a/src/fe-common/irc/dcc/fe-dcc-chat.c
+++ b/src/fe-common/irc/dcc/fe-dcc-chat.c
@@ -1,7 +1,7 @@
/*
fe-dcc-chat.c : irssi
- Copyright (C) 1999-2001 Timo Sirainen
+ Copyright (C) 1999-2002 Timo Sirainen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,6 +35,9 @@
#include "chat-completion.h"
+void fe_dcc_chat_messages_init(void);
+void fe_dcc_chat_messages_deinit(void);
+
static int autocreate_dccquery;
static void dcc_request(CHAT_DCC_REC *dcc)
@@ -95,17 +98,15 @@ static void dcc_chat_msg(CHAT_DCC_REC *dcc, const char *msg)
else
freemsg = NULL;
- if (query_find(NULL, sender) == NULL)
+ if (query == NULL)
completion_last_message_add(sender);
- printformat(NULL, sender, MSGLEVEL_DCCMSGS,
- query != NULL ? IRCTXT_DCC_MSG_QUERY :
- IRCTXT_DCC_MSG, dcc->id, msg);
+ signal_emit("message dcc", 2, dcc, msg);
g_free_not_null(freemsg);
g_free(sender);
}
-static void dcc_chat_action(const char *msg, CHAT_DCC_REC *dcc)
+static void dcc_chat_action(CHAT_DCC_REC *dcc, const char *msg)
{
char *sender;
@@ -115,22 +116,16 @@ static void dcc_chat_action(const char *msg, CHAT_DCC_REC *dcc)
sender = g_strconcat("=", dcc->id, NULL);
if (query_find(NULL, sender) == NULL)
completion_last_message_add(sender);
- printformat(NULL, sender, MSGLEVEL_DCCMSGS | MSGLEVEL_ACTIONS,
- IRCTXT_ACTION_DCC, dcc->id, msg);
+
+ signal_emit("message dcc action", 2, dcc, msg);
g_free(sender);
}
-static void dcc_chat_ctcp(const char *msg, CHAT_DCC_REC *dcc)
+static void dcc_chat_ctcp(CHAT_DCC_REC *dcc, const char *cmd, const char *data)
{
- char *sender;
-
g_return_if_fail(IS_DCC_CHAT(dcc));
- g_return_if_fail(msg != NULL);
- sender = g_strconcat("=", dcc->id, NULL);
- printformat(NULL, sender, MSGLEVEL_DCC,
- IRCTXT_DCC_CTCP, dcc->id, msg);
- g_free(sender);
+ signal_emit("message dcc ctcp", 3, dcc, cmd, data);
}
static void dcc_error_ctcp(const char *type, const char *data,
@@ -233,7 +228,6 @@ static void sig_dcc_list_print(CHAT_DCC_REC *dcc)
static void cmd_msg(const char *data)
{
- QUERY_REC *query;
CHAT_DCC_REC *dcc;
char *text, *target;
void *free_arg;
@@ -254,13 +248,10 @@ static void cmd_msg(const char *data)
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
IRCTXT_DCC_CHAT_NOT_FOUND, target+1);
} else {
- query = query_find(NULL, target);
-
- printformat(NULL, target, MSGLEVEL_DCCMSGS | MSGLEVEL_NOHILIGHT,
- query != NULL ? IRCTXT_OWN_DCC_QUERY :
- IRCTXT_OWN_DCC, dcc->mynick, target+1, text);
- if (query == NULL)
+ if (query_find(NULL, target) == NULL)
completion_last_message_add(target);
+
+ signal_emit("message dcc own", 2, dcc, text);
}
cmd_params_free(free_arg);
@@ -270,18 +261,13 @@ static void cmd_me(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
CHAT_DCC_REC *dcc;
- g_return_if_fail(data != NULL);
-
dcc = item_get_dcc(item);
- if (dcc == NULL) return;
-
- printformat(NULL, item->name, MSGLEVEL_DCCMSGS | MSGLEVEL_NOHILIGHT,
- IRCTXT_OWN_DCC_ACTION_QUERY, dcc->mynick, item->name, data);
+ if (dcc != NULL)
+ signal_emit("message dcc own_action", 2, dcc, data);
}
static void cmd_action(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
- QUERY_REC *query;
CHAT_DCC_REC *dcc;
char *target, *text;
void *free_arg;
@@ -304,13 +290,10 @@ static void cmd_action(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
IRCTXT_DCC_CHAT_NOT_FOUND, target+1);
} else {
- query = query_find(NULL, target);
-
- printformat(NULL, target, MSGLEVEL_DCCMSGS | MSGLEVEL_NOHILIGHT,
- query != NULL ? IRCTXT_OWN_DCC_ACTION_QUERY :
- IRCTXT_OWN_DCC_ACTION, dcc->mynick, target, text);
- if (query == NULL)
+ if (query_find(NULL, target) == NULL)
completion_last_message_add(target);
+
+ signal_emit("message dcc own_action", 2, dcc, text);
}
cmd_params_free(free_arg);
}
@@ -343,8 +326,7 @@ static void cmd_ctcp(const char *data, SERVER_REC *server)
IRCTXT_DCC_CHAT_NOT_FOUND, target+1);
} else {
g_strup(ctcpcmd);
- printformat(server, target, MSGLEVEL_DCC, IRCTXT_OWN_DCC_CTCP,
- target, ctcpcmd, ctcpdata);
+ signal_emit("message dcc own_ctcp", 3, dcc, ctcpcmd, ctcpdata);
}
cmd_params_free(free_arg);
@@ -361,6 +343,8 @@ static void read_settings(void)
void fe_dcc_chat_init(void)
{
read_settings();
+ fe_dcc_chat_messages_init();
+
signal_add("dcc request", (SIGNAL_FUNC) dcc_request);
signal_add("dcc connected", (SIGNAL_FUNC) dcc_connected);
signal_add("dcc closed", (SIGNAL_FUNC) dcc_closed);
@@ -383,6 +367,8 @@ void fe_dcc_chat_init(void)
void fe_dcc_chat_deinit(void)
{
+ fe_dcc_chat_messages_deinit();
+
signal_remove("dcc request", (SIGNAL_FUNC) dcc_request);
signal_remove("dcc connected", (SIGNAL_FUNC) dcc_connected);
signal_remove("dcc closed", (SIGNAL_FUNC) dcc_closed);
diff --git a/src/fe-common/irc/dcc/module-formats.c b/src/fe-common/irc/dcc/module-formats.c
index 8f1aea81..d4858148 100644
--- a/src/fe-common/irc/dcc/module-formats.c
+++ b/src/fe-common/irc/dcc/module-formats.c
@@ -33,9 +33,10 @@ FORMAT_REC fecommon_irc_dcc_formats[] = {
{ "own_dcc_ctcp", "{ownctcp ctcp $0}$1 $2", 3, { 0, 0, 0 } },
{ "dcc_msg", "{dccmsg dcc $0}$1", 2, { 0, 0 } },
{ "action_dcc", "{dccaction $0}$1", 2, { 0, 0 } },
+ { "action_dcc_query", "{dccaction $0}$1", 2, { 0, 0 } },
{ "own_dcc_query", "{ownmsgnick {ownnick $0}}$2", 3, { 0, 0, 0 } },
{ "dcc_msg_query", "{privmsgnick $0}$1", 2, { 0, 0 } },
- { "dcc_ctcp", "{dcc >>> DCC CTCP received from {hilight $0}: $1}", 2, { 0, 0 } },
+ { "dcc_ctcp", "{dcc >>> DCC CTCP {hilight $1} received from {hilight $0}: $2}", 3, { 0, 0, 0 } },
{ "dcc_chat", "{dcc DCC CHAT from {nick $0} [$1 port $2]}", 3, { 0, 0, 1 } },
{ "dcc_chat_channel", "{dcc DCC CHAT from {nick $0} [$1 port $2] requested in channel {channel $3}}", 4, { 0, 0, 1, 0 } },
{ "dcc_chat_not_found", "{dcc No DCC CHAT connection open to {nick $0}}", 1, { 0 } },
diff --git a/src/fe-common/irc/dcc/module-formats.h b/src/fe-common/irc/dcc/module-formats.h
index bc783a04..23e948fd 100644
--- a/src/fe-common/irc/dcc/module-formats.h
+++ b/src/fe-common/irc/dcc/module-formats.h
@@ -11,6 +11,7 @@ enum {
IRCTXT_OWN_DCC_CTCP,
IRCTXT_DCC_MSG,
IRCTXT_ACTION_DCC,
+ IRCTXT_ACTION_DCC_QUERY,
IRCTXT_OWN_DCC_QUERY,
IRCTXT_DCC_MSG_QUERY,
IRCTXT_DCC_CTCP,
diff --git a/src/irc/dcc/dcc-chat.c b/src/irc/dcc/dcc-chat.c
index 8ca8f8bc..af0084c8 100644
--- a/src/irc/dcc/dcc-chat.c
+++ b/src/irc/dcc/dcc-chat.c
@@ -574,7 +574,7 @@ static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
/* DCC CHAT: text received */
static void dcc_chat_msg(CHAT_DCC_REC *dcc, const char *msg)
{
- char *cmd, *ptr;
+ char *event, *cmd, *ptr;
int reply;
g_return_if_fail(IS_DCC_CHAT(dcc));
@@ -600,23 +600,29 @@ static void dcc_chat_msg(CHAT_DCC_REC *dcc, const char *msg)
return;
/* get ctcp command, remove \001 chars */
- cmd = g_strconcat(reply ? "dcc reply " : "dcc ctcp ", msg+1, NULL);
- if (cmd[strlen(cmd)-1] == 1) cmd[strlen(cmd)-1] = '\0';
+ event = g_strconcat(reply ? "dcc reply " : "dcc ctcp ", msg+1, NULL);
+ if (event[strlen(event)-1] == 1) event[strlen(event)-1] = '\0';
- ptr = strchr(cmd+(reply ? 10 : 9), ' ');
+ cmd = event + (reply ? 10 : 9);
+ ptr = strchr(cmd, ' ');
if (ptr != NULL) *ptr++ = '\0'; else ptr = "";
- g_strdown(cmd+9);
- if (!signal_emit(cmd, 2, ptr, dcc)) {
+ cmd = g_strdup(cmd);
+ g_strup(cmd);
+
+ g_strdown(event+9);
+ if (!signal_emit(event, 2, dcc, ptr)) {
signal_emit(reply ? "default dcc reply" :
- "default dcc ctcp", 2, msg, dcc);
+ "default dcc ctcp", 3, dcc, cmd, ptr);
}
- g_free(cmd);
+
+ g_free(cmd);
+ g_free(event);
signal_stop();
}
-static void dcc_ctcp_redirect(const char *msg, CHAT_DCC_REC *dcc)
+static void dcc_ctcp_redirect(CHAT_DCC_REC *dcc, const char *msg)
{
g_return_if_fail(msg != NULL);
g_return_if_fail(IS_DCC_CHAT(dcc));
@@ -625,7 +631,7 @@ static void dcc_ctcp_redirect(const char *msg, CHAT_DCC_REC *dcc)
dcc->nick, "dcc", dcc->mynick, dcc);
}
-static void dcc_ctcp_reply_redirect(const char *msg, CHAT_DCC_REC *dcc)
+static void dcc_ctcp_reply_redirect(CHAT_DCC_REC *dcc, const char *msg)
{
g_return_if_fail(msg != NULL);
g_return_if_fail(IS_DCC_CHAT(dcc));