summaryrefslogtreecommitdiff
path: root/src/irc/core/irc-queries.c
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-08-26 15:39:44 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-08-26 15:39:44 +0000
commite395e87dedd9aa85f05e5c74330a76f1ef700371 (patch)
tree1184487b13038499f1771e4c553222f85b8524d2 /src/irc/core/irc-queries.c
parent3d124da13b8da5c0b535abfe6265fc471d9d2ebd (diff)
downloadirssi-e395e87dedd9aa85f05e5c74330a76f1ef700371.zip
Lots of moving stuff around - hopefully I didn't break too much :)
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@632 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc/core/irc-queries.c')
-rw-r--r--src/irc/core/irc-queries.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/irc/core/irc-queries.c b/src/irc/core/irc-queries.c
new file mode 100644
index 00000000..b013d9cf
--- /dev/null
+++ b/src/irc/core/irc-queries.c
@@ -0,0 +1,109 @@
+/*
+ irc-queries.c : irssi
+
+ Copyright (C) 1999-2000 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 "misc.h"
+
+#include "irc.h"
+#include "irc-queries.h"
+
+QUERY_REC *irc_query_create(IRC_SERVER_REC *server,
+ const char *nick, int automatic)
+{
+ QUERY_REC *rec;
+
+ g_return_val_if_fail(server == NULL || IS_IRC_SERVER(server), NULL);
+ g_return_val_if_fail(nick != NULL, NULL);
+
+ rec = g_new0(QUERY_REC, 1);
+ rec->chat_type = module_get_uniq_id("IRC QUERY", 0);
+ rec->name = g_strdup(nick);
+ rec->server = (SERVER_REC *) server;
+ query_init(rec, automatic);
+ return rec;
+}
+
+static void sig_connected(SERVER_REC *server)
+{
+ if (!IS_IRC_SERVER(server))
+ return;
+
+ server->query_type = module_get_uniq_id("IRC QUERY", 0);;
+}
+
+static void event_privmsg(const char *data, IRC_SERVER_REC *server, const char *nick, const char *addr)
+{
+ char *params, *target, *msg;
+ QUERY_REC *query;
+
+ g_return_if_fail(data != NULL);
+
+ params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg);
+
+ if (addr != NULL && !ischannel(*target)) {
+ /* save nick's address to query */
+ query = irc_query_find(server, nick);
+ if (query != NULL && (query->address == NULL || strcmp(query->address, addr) != 0)) {
+ g_free_not_null(query->address);
+ query->address = g_strdup(addr);
+
+ signal_emit("query address changed", 1, query);
+ }
+ }
+
+ g_free(params);
+}
+
+static void event_nick(const char *data, IRC_SERVER_REC *server, const char *orignick)
+{
+ char *params, *nick;
+ GSList *tmp;
+
+ params = event_get_params(data, 1, &nick);
+
+ for (tmp = server->queries; tmp != NULL; tmp = tmp->next) {
+ QUERY_REC *rec = tmp->data;
+
+ if (g_strcasecmp(rec->name, orignick) == 0) {
+ g_free(rec->name);
+ rec->name = g_strdup(nick);
+ signal_emit("query nick changed", 1, rec);
+ }
+ }
+
+ g_free(params);
+}
+
+void irc_queries_init(void)
+{
+ signal_add("server connected", (SIGNAL_FUNC) sig_connected);
+ signal_add_last("event privmsg", (SIGNAL_FUNC) event_privmsg);
+ signal_add("event nick", (SIGNAL_FUNC) event_nick);
+}
+
+void irc_queries_deinit(void)
+{
+ signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
+ signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg);
+ signal_remove("event nick", (SIGNAL_FUNC) event_nick);
+
+ module_uniq_destroy("IRC QUERY");
+}