Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsGnomeVFSProtocolHandler.cpp File Reference
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomevfs/gnome-vfs-standard-callbacks.h>
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include "nsIGenericFactory.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsIObserver.h"
#include "nsEventQueueUtils.h"
#include "nsProxyRelease.h"
#include "nsIAuthPrompt.h"
#include "nsIStringBundle.h"
#include "nsIStandardURL.h"
#include "nsIURL.h"
#include "nsMimeTypes.h"
#include "nsNetUtil.h"
#include "nsAutoPtr.h"
#include "nsError.h"
#include "nsEscape.h"
#include "nsCRT.h"
#include "netCore.h"
#include "prlog.h"
#include "prtime.h"

Go to the source code of this file.

Classes

struct  nsGnomeVFSAuthParams
class  nsGnomeVFSInputStream
class  nsGnomeVFSSetContentTypeEvent
class  nsGnomeVFSProtocolHandler

Defines

#define MOZ_GNOMEVFS_SCHEME   "moz-gnomevfs"
#define MOZ_GNOMEVFS_SUPPORTED_PROTOCOLS   "network.gnomevfs.supported-protocols"
#define LOG(args)
#define NS_GNOMEVFSPROTOCOLHANDLER_CID

Functions

static nsresult MapGnomeVFSResult (GnomeVFSResult result)
static void ProxiedAuthCallback (gconstpointer in, gsize in_size, gpointer out, gsize out_size, gpointer callback_data)
 AuthCallbackEventHandler (PLEvent *ev)
 AuthCallbackEventDestructor (PLEvent *ev)
static void AuthCallback (gconstpointer in, gsize in_size, gpointer out, gsize out_size, gpointer callback_data)
static gint FileInfoComparator (gconstpointer a, gconstpointer b)

Variables

static const nsModuleComponentInfo components []

Class Documentation

struct nsGnomeVFSAuthParams

Definition at line 285 of file nsGnomeVFSProtocolHandler.cpp.

Class Members
gpointer callback_data
gconstpointer in
gsize in_size
gpointer out
gsize out_size

Define Documentation

#define LOG (   args)

Definition at line 76 of file nsGnomeVFSProtocolHandler.cpp.

#define MOZ_GNOMEVFS_SCHEME   "moz-gnomevfs"

Definition at line 66 of file nsGnomeVFSProtocolHandler.cpp.

#define MOZ_GNOMEVFS_SUPPORTED_PROTOCOLS   "network.gnomevfs.supported-protocols"

Definition at line 67 of file nsGnomeVFSProtocolHandler.cpp.

Value:
{ /* 9b6dc177-a2e4-49e1-9c98-0a8384de7f6c */         \
    0x9b6dc177,                                      \
    0xa2e4,                                          \
    0x49e1,                                          \
    {0x9c, 0x98, 0x0a, 0x83, 0x84, 0xde, 0x7f, 0x6c} \
}

Definition at line 992 of file nsGnomeVFSProtocolHandler.cpp.


Function Documentation

static void AuthCallback ( gconstpointer  in,
gsize  in_size,
gpointer  out,
gsize  out_size,
gpointer  callback_data 
) [static]

Definition at line 311 of file nsGnomeVFSProtocolHandler.cpp.

{
  // Need to proxy this callback over to the main thread.  This code is greatly
  // simplified by the fact that we are making a synchronous callback.  E.g., we
  // don't need to allocate the PLEvent on the heap.

  nsCOMPtr<nsIEventQueue> eventQ;
  NS_GetMainEventQ(getter_AddRefs(eventQ));
  if (!eventQ)
    return;

  nsGnomeVFSAuthParams params;
  params.in = in;
  params.in_size = in_size;
  params.out = out;
  params.out_size = out_size;
  params.callback_data = callback_data;

  PLEvent ev;
  PL_InitEvent(&ev, &params,
      AuthCallbackEventHandler,
      AuthCallbackEventDestructor);

  void *result;
  if (NS_FAILED(eventQ->PostSynchronousEvent(&ev, &result)))
    PL_DestroyEvent(&ev);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 305 of file nsGnomeVFSProtocolHandler.cpp.

{
  // ignored
}

Here is the caller graph for this function:

Definition at line 295 of file nsGnomeVFSProtocolHandler.cpp.

{
  nsGnomeVFSAuthParams *params = (nsGnomeVFSAuthParams *) ev->owner;
  ProxiedAuthCallback(params->in, params->in_size,
                      params->out, params->out_size,
                      params->callback_data);
  return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static gint FileInfoComparator ( gconstpointer  a,
gconstpointer  b 
) [static]

Definition at line 346 of file nsGnomeVFSProtocolHandler.cpp.

{
  const GnomeVFSFileInfo *ia = (const GnomeVFSFileInfo *) a;
  const GnomeVFSFileInfo *ib = (const GnomeVFSFileInfo *) b;

  return strcasecmp(ia->name, ib->name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult MapGnomeVFSResult ( GnomeVFSResult  result) [static]

Definition at line 82 of file nsGnomeVFSProtocolHandler.cpp.

{
  switch (result)
  {
    case GNOME_VFS_OK:                           return NS_OK;
    case GNOME_VFS_ERROR_NOT_FOUND:              return NS_ERROR_FILE_NOT_FOUND;
    case GNOME_VFS_ERROR_INTERNAL:               return NS_ERROR_UNEXPECTED;
    case GNOME_VFS_ERROR_BAD_PARAMETERS:         return NS_ERROR_INVALID_ARG;
    case GNOME_VFS_ERROR_NOT_SUPPORTED:          return NS_ERROR_NOT_AVAILABLE;
    case GNOME_VFS_ERROR_CORRUPTED_DATA:         return NS_ERROR_FILE_CORRUPTED;
    case GNOME_VFS_ERROR_TOO_BIG:                return NS_ERROR_FILE_TOO_BIG;
    case GNOME_VFS_ERROR_NO_SPACE:               return NS_ERROR_FILE_NO_DEVICE_SPACE;
    case GNOME_VFS_ERROR_READ_ONLY:
    case GNOME_VFS_ERROR_READ_ONLY_FILE_SYSTEM:  return NS_ERROR_FILE_READ_ONLY;
    case GNOME_VFS_ERROR_INVALID_URI:
    case GNOME_VFS_ERROR_INVALID_HOST_NAME:      return NS_ERROR_MALFORMED_URI;
    case GNOME_VFS_ERROR_ACCESS_DENIED:
    case GNOME_VFS_ERROR_NOT_PERMITTED:
    case GNOME_VFS_ERROR_LOGIN_FAILED:           return NS_ERROR_FILE_ACCESS_DENIED;
    case GNOME_VFS_ERROR_EOF:                    return NS_BASE_STREAM_CLOSED;
    case GNOME_VFS_ERROR_NOT_A_DIRECTORY:        return NS_ERROR_FILE_NOT_DIRECTORY;
    case GNOME_VFS_ERROR_IN_PROGRESS:            return NS_ERROR_IN_PROGRESS;
    case GNOME_VFS_ERROR_FILE_EXISTS:            return NS_ERROR_FILE_ALREADY_EXISTS;
    case GNOME_VFS_ERROR_IS_DIRECTORY:           return NS_ERROR_FILE_IS_DIRECTORY;
    case GNOME_VFS_ERROR_NO_MEMORY:              return NS_ERROR_OUT_OF_MEMORY;
    case GNOME_VFS_ERROR_HOST_NOT_FOUND:
    case GNOME_VFS_ERROR_HOST_HAS_NO_ADDRESS:    return NS_ERROR_UNKNOWN_HOST;
    case GNOME_VFS_ERROR_CANCELLED:
    case GNOME_VFS_ERROR_INTERRUPTED:            return NS_ERROR_ABORT;
    case GNOME_VFS_ERROR_DIRECTORY_NOT_EMPTY:    return NS_ERROR_FILE_DIR_NOT_EMPTY;
    case GNOME_VFS_ERROR_NAME_TOO_LONG:          return NS_ERROR_FILE_NAME_TOO_LONG;
    case GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE:  return NS_ERROR_UNKNOWN_PROTOCOL;

    /* No special mapping for these error codes...

    case GNOME_VFS_ERROR_GENERIC:
    case GNOME_VFS_ERROR_IO:
    case GNOME_VFS_ERROR_WRONG_FORMAT:
    case GNOME_VFS_ERROR_BAD_FILE:
    case GNOME_VFS_ERROR_NOT_OPEN:
    case GNOME_VFS_ERROR_INVALID_OPEN_MODE:
    case GNOME_VFS_ERROR_TOO_MANY_OPEN_FILES:
    case GNOME_VFS_ERROR_LOOP:
    case GNOME_VFS_ERROR_DIRECTORY_BUSY:
    case GNOME_VFS_ERROR_TOO_MANY_LINKS:
    case GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM:
    case GNOME_VFS_ERROR_SERVICE_OBSOLETE:
    case GNOME_VFS_ERROR_PROTOCOL_ERROR:
    case GNOME_VFS_ERROR_NO_MASTER_BROWSER:

    */

    // Make GCC happy
    default:
      return NS_ERROR_FAILURE;
  }

  return NS_ERROR_FAILURE;
}
static void ProxiedAuthCallback ( gconstpointer  in,
gsize  in_size,
gpointer  out,
gsize  out_size,
gpointer  callback_data 
) [static]

Definition at line 145 of file nsGnomeVFSProtocolHandler.cpp.

{
  GnomeVFSModuleCallbackAuthenticationIn *authIn =
      (GnomeVFSModuleCallbackAuthenticationIn *) in;
  GnomeVFSModuleCallbackAuthenticationOut *authOut =
      (GnomeVFSModuleCallbackAuthenticationOut *) out;

  LOG(("gnomevfs: ProxiedAuthCallback [uri=%s]\n", authIn->uri));

  // Without a channel, we have no way of getting a prompter.
  nsIChannel *channel = (nsIChannel *) callback_data;
  if (!channel)
    return;

  nsCOMPtr<nsIAuthPrompt> prompt;
  NS_QueryNotificationCallbacks(channel, prompt);

  // If no auth prompt, then give up.  We could failover to using the
  // WindowWatcher service, but that might defeat a consumer's purposeful
  // attempt to disable authentication (for whatever reason).
  if (!prompt)
    return;

  // Parse out the host and port...
  nsCOMPtr<nsIURI> uri;
  channel->GetURI(getter_AddRefs(uri));
  if (!uri)
    return;

#ifdef DEBUG
  {
    //
    // Make sure authIn->uri is consistent with the channel's URI.
    //
    // XXX This check is probably not IDN safe, and it might incorrectly
    //     fire as a result of escaping differences.  It's unclear what
    //     kind of transforms GnomeVFS might have applied to the URI spec
    //     that we originally gave to it.  In spite of the likelihood of
    //     false hits, this check is probably still valuable.
    //
    nsCAutoString spec;
    uri->GetSpec(spec);
    int uriLen = strlen(authIn->uri);
    if (!StringHead(spec, uriLen).Equals(nsDependentCString(authIn->uri, uriLen)))
    {
      LOG(("gnomevfs: [spec=%s authIn->uri=%s]\n", spec.get(), authIn->uri));
      NS_ERROR("URI mismatch");
    }
  }
#endif

  nsCAutoString scheme, hostPort;
  uri->GetScheme(scheme);
  uri->GetHostPort(hostPort);

  // It doesn't make sense for either of these strings to be empty.  What kind
  // of funky URI is this?
  if (scheme.IsEmpty() || hostPort.IsEmpty())
    return;

  // Construct the single signon key.  Altering the value of this key will
  // cause peoples remembered passwords to be forgotten.  Think carefully
  // before changing the way this key is constructed.
  nsAutoString key, dispHost, realm;
  AppendUTF8toUTF16(scheme + NS_LITERAL_CSTRING("://") + hostPort, dispHost);
  key = dispHost;
  if (authIn->realm)
  {
    // We assume the realm string is ASCII.  That might be a bogus assumption,
    // but we have no idea what encoding GnomeVFS is using, so for now we'll
    // limit ourselves to ISO-Latin-1.  XXX What is a better solution?
    realm.Append(PRUnichar('"'));
    realm.AppendWithConversion(authIn->realm);
    realm.Append(PRUnichar('"'));
    key += NS_LITERAL_STRING(" ") + realm;
  }

  // Construct the message string...
  //
  // We use Necko's string bundle here.  This code really should be encapsulated
  // behind some Necko API, after all this code is based closely on the code in
  // nsHttpChannel.cpp.

  nsCOMPtr<nsIStringBundleService> bundleSvc =
      do_GetService(NS_STRINGBUNDLE_CONTRACTID);
  if (!bundleSvc)
    return;

  nsCOMPtr<nsIStringBundle> bundle;
  bundleSvc->CreateBundle(NECKO_MSGS_URL, getter_AddRefs(bundle));
  if (!bundle)
    return;

  nsXPIDLString message;
  if (!realm.IsEmpty())
  {
    const PRUnichar *strings[] = { realm.get(), dispHost.get() };
    bundle->FormatStringFromName(NS_LITERAL_STRING("EnterUserPasswordForRealm").get(),
                                 strings, 2, getter_Copies(message));
  }
  else
  {
    const PRUnichar *strings[] = { dispHost.get() };
    bundle->FormatStringFromName(NS_LITERAL_STRING("EnterUserPasswordFor").get(),
                                 strings, 1, getter_Copies(message));
  }
  if (!message)
    return;

  // Prompt the user...
  nsresult rv;
  PRBool retval = PR_FALSE;
  PRUnichar *user = nsnull, *pass = nsnull;

  rv = prompt->PromptUsernameAndPassword(nsnull, message.get(),
                                         key.get(),
                                         nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY,
                                         &user, &pass, &retval);
  if (NS_FAILED(rv))
    return;
  if (!retval || !user || !pass)
    return;

  // XXX We need to convert the UTF-16 username and password from our dialog to
  // strings that GnomeVFS can understand.  It's unclear what encoding GnomeVFS
  // expects, so for now we assume 7-bit ASCII.  Hopefully, we can get a better
  // solution at some point.

  // One copy is never enough...
  authOut->username = g_strdup(NS_LossyConvertUTF16toASCII(user).get());
  authOut->password = g_strdup(NS_LossyConvertUTF16toASCII(pass).get());

  nsMemory::Free(user);
  nsMemory::Free(pass);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
{
  { "nsGnomeVFSProtocolHandler",
    NS_GNOMEVFSPROTOCOLHANDLER_CID,
    NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX MOZ_GNOMEVFS_SCHEME,
    nsGnomeVFSProtocolHandlerConstructor
  }
}

Definition at line 1002 of file nsGnomeVFSProtocolHandler.cpp.