e2fd0d5e42
* gnomevfs/Makefile.am: * gnomevfs/ModuleCallback.cs: * gnomevfs/ModuleCallbackAuthentication.cs: * gnomevfs/ModuleCallbackFullAuthentication.cs: * gnomevfs/Vfs.cs: Use a custom VfsException for Result errors. * gnomevfs/VfsException.cs: new custom Exception class. * sample/gnomevfs/Makefile.am: * sample/gnomevfs/TestCallback.cs: Implement custom bindings for the ModuleCallback mechanism. Atm, only the GNOME_VFS_MODULE_CALLBACK_AUTHENTICATION and GNOME_VFS_MODULE_CALLBACK_FULL_AUTHENTICATION callbacks are implemented. Also added a test-case using the full authentication callback (tested using the sftp: method). [Partially fixes #70602] svn path=/trunk/gtk-sharp/; revision=37972
73 lines
2 KiB
C#
73 lines
2 KiB
C#
using GLib;
|
|
using Gnome.Vfs;
|
|
using System;
|
|
using System.Text;
|
|
|
|
namespace Test.Gnome.Vfs {
|
|
public class TestCallback {
|
|
private static MainLoop loop;
|
|
|
|
static void Main (string[] args)
|
|
{
|
|
if (args.Length != 1) {
|
|
Console.WriteLine ("Usage: TestCallback <uri>");
|
|
return;
|
|
}
|
|
|
|
Gnome.Vfs.Vfs.Initialize ();
|
|
|
|
Gnome.Vfs.Uri uri = new Gnome.Vfs.Uri (args[0]);
|
|
Handle handle;
|
|
|
|
// Test 1: Attempt to access a URI requiring authentication w/o a callback registered.
|
|
try {
|
|
handle = Sync.Open (uri, OpenMode.Read);
|
|
Sync.Close (handle);
|
|
Console.WriteLine ("Uri '{0}' doesn't require authentication", uri);
|
|
return;
|
|
} catch (VfsException ex) {
|
|
if (ex.Result != Result.ErrorAccessDenied)
|
|
throw ex;
|
|
}
|
|
|
|
// Test 2: Attempt an open that requires authentication.
|
|
ModuleCallbackFullAuthentication cb = new ModuleCallbackFullAuthentication ();
|
|
cb.Callback += new ModuleCallbackHandler (OnAuthenticate);
|
|
cb.SetDefault ();
|
|
|
|
handle = Sync.Open (uri, OpenMode.Read);
|
|
Sync.Close (handle);
|
|
|
|
// Test 3: This call should not require any new authentication.
|
|
Console.WriteLine ("File info: \n{0}", uri.GetFileInfo ());
|
|
|
|
// Test 4: Attempt a call to the parent uri.
|
|
FileInfo[] entries = Directory.GetEntries (uri.Parent);
|
|
Console.WriteLine ("Directory '{0}' has {1} entries", uri.Parent, entries.Length);
|
|
|
|
// Test 5: Pop the authentication callback and try again.
|
|
cb.Pop ();
|
|
try {
|
|
handle = Sync.Open (uri, OpenMode.Read);
|
|
} catch (VfsException ex) {
|
|
if (ex.Result != Result.ErrorAccessDenied)
|
|
throw ex;
|
|
}
|
|
|
|
Gnome.Vfs.Vfs.Shutdown ();
|
|
}
|
|
|
|
private static void OnAuthenticate (ModuleCallback cb)
|
|
{
|
|
ModuleCallbackFullAuthentication fcb = cb as ModuleCallbackFullAuthentication;
|
|
Console.Write ("Enter your username ({0}): ", fcb.Username);
|
|
string username = Console.ReadLine ();
|
|
Console.Write ("Enter your password : ");
|
|
string passwd = Console.ReadLine ();
|
|
|
|
if (username.Length > 0)
|
|
fcb.Username = username;
|
|
fcb.Password = passwd;
|
|
}
|
|
}
|
|
}
|