Re: yet another gnome-vfs patch



Err, I attached the wrong patch in the previous mail :)



On Wed, 28 Aug 2002 10:08:09 +0200
Christophe Fergeau <teuf users sourceforge net> wrote:

> I still don't know if/where my patches will go, but that doesn't prevent me from trying to improve gnome-vfs and nautilus remote file browsing.
> Today's patch is for the ftp method. It invokes the "simple-authentification" callback when it failed to login using the provided username/password. That way, if login failed, nautilus asks for a valid username/password. This patch is not perfect since the uri isn't modified to take into account the username/password the user entered because I don't know if I'm allowed to modify the uri provided by the user from a gnome-vfs module.
> 
> Christophe
diff -ur gnome-vfs/modules/ftp-method.c gnome-vfs-new/modules/ftp-method.c
--- gnome-vfs/modules/ftp-method.c	2002-05-08 21:04:51.000000000 +0200
+++ gnome-vfs-new/modules/ftp-method.c	2002-08-27 22:30:59.000000000 +0200
@@ -42,15 +42,18 @@
 #include <netinet/in.h>
 
 #include <arpa/inet.h>
+
 #include <libgnomevfs/gnome-vfs-context.h>
 #include <libgnomevfs/gnome-vfs-inet-connection.h>
 #include <libgnomevfs/gnome-vfs-iobuf.h>
 #include <libgnomevfs/gnome-vfs-method.h>
 #include <libgnomevfs/gnome-vfs-mime.h>
 #include <libgnomevfs/gnome-vfs-mime-utils.h>
-#include <libgnomevfs/gnome-vfs-module-shared.h>
 #include <libgnomevfs/gnome-vfs-module.h>
+#include <libgnomevfs/gnome-vfs-module-callback-module-api.h>
+#include <libgnomevfs/gnome-vfs-module-shared.h>
 #include <libgnomevfs/gnome-vfs-parse-ls.h>
+#include <libgnomevfs/gnome-vfs-standard-callbacks.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
 #include <stdio.h> /* for sscanf */
 #include <stdlib.h> /* for atoi */
@@ -504,12 +507,57 @@
 
 }
 
+
+static GnomeVFSResult ftp_login(FtpConnection *conn, 
+                                const char *user, const char *password)
+{
+	gchar *tmpstring;
+	GnomeVFSResult result;
+	static gboolean first_login_attempt = TRUE;
+	
+	tmpstring = g_strdup_printf ("USER %s", user);
+	result = do_basic_command (conn, tmpstring);
+	g_free (tmpstring);
+
+	if (IS_300 (conn->response_code)) {
+		tmpstring = g_strdup_printf ("PASS %s", password);
+		result = do_basic_command (conn, tmpstring);
+		g_free (tmpstring);
+	}
+	
+	if ((result != GNOME_VFS_OK) && (first_login_attempt)) {
+		GnomeVFSModuleCallbackAuthenticationIn in;
+		GnomeVFSModuleCallbackAuthenticationOut out;
+		gboolean callback_called;
+
+		in.uri = gnome_vfs_uri_to_string(conn->uri, FALSE);
+		in.realm = NULL;
+		in.previous_attempt_failed = TRUE;
+		in.auth_type = AuthTypeBasic;
+
+		callback_called = gnome_vfs_module_callback_invoke(GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION, 
+					 &in,
+					 sizeof(GnomeVFSModuleCallbackAuthenticationIn),
+					 &out,
+					 sizeof(GnomeVFSModuleCallbackAuthenticationOut));
+		if (callback_called) {
+			first_login_attempt = FALSE;
+		 	result = ftp_login(conn, out.username, out.password);
+			g_free(out.username);
+			g_free(out.password);
+		}
+	}
+
+	first_login_attempt = TRUE;
+	return result;
+}
+
+
 static GnomeVFSResult 
 ftp_connection_create (FtpConnection **connptr, GnomeVFSURI *uri, GnomeVFSContext *context) 
 {
 	FtpConnection *conn = g_new0 (FtpConnection, 1);
 	GnomeVFSResult result;
-	gchar *tmpstring;
 	gint port = control_port;
 	const gchar *user = anon_user;
 	const gchar *pass = anon_pass;
@@ -573,16 +621,8 @@
 		return result;
 	}
 
-	tmpstring = g_strdup_printf ("USER %s", user);
-	result = do_basic_command (conn, tmpstring);
-	g_free (tmpstring);
-
-	if (IS_300 (conn->response_code)) {
-		tmpstring = g_strdup_printf ("PASS %s", pass);
-		result = do_basic_command (conn, tmpstring);
-		g_free (tmpstring);
-	}
-
+	result = ftp_login(conn, user, pass);
+	
 	if (result != GNOME_VFS_OK) {
 		/* login failed */
 		g_warning ("FTP server said: \"%d %s\"\n", conn->response_code,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]