From 2287c993c97b0a8338b1c718270e50fe4bc6d134 Mon Sep 17 00:00:00 2001
From: Andrew Potter <agpotter@gmail.com>
Date: Sun, 3 Mar 2013 14:38:44 -0800
Subject: [PATCH] xfer: Add new config option auto_accept_nicks

New option xfer.file.auto_accept_nicks allows automatic accept of
xfers from the comma-separated nick list.
---
 src/plugins/xfer/xfer-config.c |  7 +++++++
 src/plugins/xfer/xfer-config.h |  1 +
 src/plugins/xfer/xfer.c        | 34 +++++++++++++++++++++++++++++++++-
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/plugins/xfer/xfer-config.c b/src/plugins/xfer/xfer-config.c
index ab9171e..6f1e8dd 100644
--- a/src/plugins/xfer/xfer-config.c
+++ b/src/plugins/xfer/xfer-config.c
@@ -61,6 +61,7 @@ struct t_config_option *xfer_config_file_auto_rename;
 struct t_config_option *xfer_config_file_auto_resume;
 struct t_config_option *xfer_config_file_auto_accept_files;
 struct t_config_option *xfer_config_file_auto_accept_chats;
+struct t_config_option *xfer_config_file_auto_accept_nicks;
 
 
 
@@ -304,6 +305,12 @@ xfer_config_init ()
         "auto_accept_chats", "boolean",
         N_("automatically accept chat requests (use carefully!)"),
         NULL, 0, 0, "off", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
+    xfer_config_file_auto_accept_nicks = weechat_config_new_option (
+        xfer_config_file, ptr_section,
+        "auto_accept_nicks", "string",
+        N_("automatically accept incoming files from specific comma-separated "
+           "nicknames (use carefully!)"),
+        NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
 
     return 1;
 }
diff --git a/src/plugins/xfer/xfer-config.h b/src/plugins/xfer/xfer-config.h
index 051e4d8..e437278 100644
--- a/src/plugins/xfer/xfer-config.h
+++ b/src/plugins/xfer/xfer-config.h
@@ -49,6 +49,7 @@ extern struct t_config_option *xfer_config_file_auto_rename;
 extern struct t_config_option *xfer_config_file_auto_resume;
 extern struct t_config_option *xfer_config_file_auto_accept_files;
 extern struct t_config_option *xfer_config_file_auto_accept_chats;
+extern struct t_config_option *xfer_config_file_auto_accept_nicks;
 
 extern int xfer_config_init ();
 extern int xfer_config_read ();
diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c
index c27e52e..f1921c4 100644
--- a/src/plugins/xfer/xfer.c
+++ b/src/plugins/xfer/xfer.c
@@ -520,6 +520,36 @@ xfer_alloc ()
 }
 
 /*
+ * Tests if the given nick is an auto_accept_nick
+ *
+ * Returns:
+ *  0: False
+ *  1: True
+ */
+
+static int
+xfer_auto_accept_nick (const char* remote_nick)
+{
+	int size, i;
+	int ret = 0;
+	const char *config_nicks = weechat_config_string (xfer_config_file_auto_accept_nicks);
+	char **nicks = weechat_string_split (config_nicks, ",", 0, 0, &size);
+
+	if (size > 0) {
+		for (i = 0; i < size; ++i) {
+			if ( weechat_strcasecmp( nicks[i], remote_nick ) == 0 ) {
+				ret = 1;
+				break;
+			}
+		}
+
+		weechat_string_free_split(nicks);
+	}
+
+	return ret;
+}
+
+/*
  * Adds a xfer to list.
  *
  * Returns pointer to new xfer, NULL if error.
@@ -681,7 +711,9 @@ xfer_new (const char *plugin_name, const char *plugin_id,
     if ( ( (type == XFER_TYPE_FILE_RECV)
                 && (weechat_config_boolean (xfer_config_file_auto_accept_files)) )
          || ( (type == XFER_TYPE_CHAT_RECV)
-              && (weechat_config_boolean (xfer_config_file_auto_accept_chats)) ) )
+              && (weechat_config_boolean (xfer_config_file_auto_accept_chats)) )
+         || ( (type == XFER_TYPE_FILE_RECV)
+              && (xfer_auto_accept_nick (new_xfer->remote_nick)) ) )
         xfer_network_accept (new_xfer);
     else
         xfer_buffer_refresh (WEECHAT_HOTLIST_PRIVATE);
-- 
1.8.1.4

