summaryrefslogtreecommitdiff
path: root/src/irc/dcc/dcc-autoget.c
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-01-18 02:30:59 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-01-18 02:30:59 +0000
commitce6e5a12f92f5375da6bcf499be666210856dbf3 (patch)
tree172f342986f4f86aaf1ccf7f99331c642ef617f5 /src/irc/dcc/dcc-autoget.c
parentbabf7c77ac9344c8b12ca2ce87096e7ed079b687 (diff)
downloadirssi-ce6e5a12f92f5375da6bcf499be666210856dbf3.zip
DCC cleanups - half rewrite. New features: file names with spaces work
properly, you can have multiple dcc chats with same people (or more useful, same nick in different ircnets), /DCC CHAT|GET|RESUME with no arguments accepts the last request, notifies if dcc request was sent to channel, warns about connecting to lowports, /SET dcc_autoget_lowports specifies if autogetting should work with lowports, complains of invalid dcc ctcps instead of ignoring. And fixed /SET dcc_autorename OFF which didn't work before. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1135 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc/dcc/dcc-autoget.c')
-rw-r--r--src/irc/dcc/dcc-autoget.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/irc/dcc/dcc-autoget.c b/src/irc/dcc/dcc-autoget.c
new file mode 100644
index 00000000..cb25ecf8
--- /dev/null
+++ b/src/irc/dcc/dcc-autoget.c
@@ -0,0 +1,84 @@
+/*
+ dcc-autoget.c : irssi
+
+ Copyright (C) 1999-2001 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 "masks.h"
+#include "settings.h"
+
+#include "dcc-get.h"
+
+static void sig_dcc_request(DCC_REC *dcc, const char *nickaddr)
+{
+ struct stat statbuf;
+ const char *masks;
+ char *str, *file;
+ int max_size;
+
+ g_return_if_fail(dcc != NULL);
+ if (dcc->type != DCC_TYPE_GET) return;
+
+ /* check if we want to autoget file offer */
+ if (!settings_get_bool("dcc_autoget") &&
+ !settings_get_bool("dcc_autoresume"))
+ return;
+
+ /* check for lowports */
+ if (dcc->port < 1024 && !settings_get_bool("dcc_autoget_lowports"))
+ return;
+
+ /* check that autoget masks match */
+ masks = settings_get_str("dcc_autoget_masks");
+ if (*masks != '\0' &&
+ !masks_match(SERVER(dcc->server), masks, dcc->nick, nickaddr))
+ return;
+
+ /* check file size limit, NOTE: it's still possible to send a
+ bogus file size and then just send what ever sized file.. */
+ max_size = settings_get_int("dcc_autoget_max_size");
+ if (max_size > 0 && max_size*1024 < dcc->size)
+ return;
+
+ /* ok. but do we want/need to resume? */
+ file = dcc_get_download_path(dcc->arg);
+ str = g_strdup_printf(settings_get_bool("dcc_autoresume") &&
+ stat(file, &statbuf) == 0 ?
+ "RESUME %s %s" : "GET %s %s",
+ dcc->nick, dcc->arg);
+ signal_emit("command dcc", 2, str, dcc->server);
+ g_free(file);
+ g_free(str);
+}
+
+void dcc_autoget_init(void)
+{
+ settings_add_bool("dcc", "dcc_autoget", FALSE);
+ settings_add_bool("dcc", "dcc_autoget_lowports", FALSE);
+ settings_add_bool("dcc", "dcc_autoresume", FALSE);
+ settings_add_int("dcc", "dcc_autoget_max_size", 1000);
+ settings_add_str("dcc", "dcc_autoget_masks", "");
+
+ signal_add_last("dcc request", (SIGNAL_FUNC) sig_dcc_request);
+}
+
+void dcc_autoget_deinit(void)
+{
+ signal_remove("dcc request", (SIGNAL_FUNC) sig_dcc_request);
+}