Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Attributes
nsHTTPIndex Class Reference

#include <nsDirectoryViewer.h>

Inheritance diagram for nsHTTPIndex:
Inheritance graph
[legend]
Collaboration diagram for nsHTTPIndex:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsHTTPIndex ()
virtual ~nsHTTPIndex ()
nsresult Init (void)
void OnFTPControlLog (in boolean server, in string msg)

Static Public Member Functions

static nsresult Create (nsIURI *aBaseURI, nsIInterfaceRequestor *aContainer, nsIHTTPIndex **aResult)

Protected Member Functions

 nsHTTPIndex (nsIInterfaceRequestor *aRequestor)
nsresult CommonInit (void)
nsresult Init (nsIURI *aBaseURL)
void GetDestination (nsIRDFResource *r, nsXPIDLCString &dest)
PRBool isWellknownContainerURI (nsIRDFResource *r)
nsresult AddElement (nsIRDFResource *parent, nsIRDFResource *prop, nsIRDFNode *child)

Static Protected Member Functions

static void FireTimer (nsITimer *aTimer, void *aClosure)

Protected Attributes

nsCOMPtr< nsIRDFDataSourcemInner
nsCOMPtr< nsISupportsArraymConnectionList
nsCOMPtr< nsISupportsArraymNodeList
nsCOMPtr< nsITimermTimer
nsCOMPtr< nsIDirIndexParsermParser
nsCString mBaseURL
nsCString mEncoding
PRBool mBindToGlobalObject
nsIInterfaceRequestormRequestor
nsCOMPtr< nsIRDFResourcemDirectory

Private Attributes

nsCOMPtr< nsIRDFResourcekNC_Child
nsCOMPtr< nsIRDFResourcekNC_Comment
nsCOMPtr< nsIRDFResourcekNC_Loading
nsCOMPtr< nsIRDFResourcekNC_URL
nsCOMPtr< nsIRDFResourcekNC_Description
nsCOMPtr< nsIRDFResourcekNC_ContentLength
nsCOMPtr< nsIRDFResourcekNC_LastModified
nsCOMPtr< nsIRDFResourcekNC_ContentType
nsCOMPtr< nsIRDFResourcekNC_FileType
nsCOMPtr< nsIRDFResourcekNC_IsContainer
nsCOMPtr< nsIRDFLiteralkTrueLiteral
nsCOMPtr< nsIRDFLiteralkFalseLiteral
nsCOMPtr< nsIRDFServicemDirRDF

Detailed Description

Definition at line 70 of file nsDirectoryViewer.h.


Constructor & Destructor Documentation

nsHTTPIndex::nsHTTPIndex ( nsIInterfaceRequestor aRequestor) [protected]

Definition at line 567 of file nsDirectoryViewer.cpp.

  : mBindToGlobalObject(PR_TRUE),
    mRequestor(aRequestor)
{
}

Definition at line 560 of file nsDirectoryViewer.cpp.

Here is the caller graph for this function:

Definition at line 574 of file nsDirectoryViewer.cpp.

{
  // note: these are NOT statics due to the native of nsHTTPIndex
  // where it may or may not be treated as a singleton

    if (mTimer)
    {
        // be sure to cancel the timer, as it holds a
        // weak reference back to nsHTTPIndex
        mTimer->Cancel();
        mTimer = nsnull;
    }

    mConnectionList = nsnull;
    mNodeList = nsnull;
    
    if (mDirRDF)
      {
        // UnregisterDataSource() may fail; just ignore errors
        mDirRDF->UnregisterDataSource(this);
      }
}

Member Function Documentation

nsresult nsHTTPIndex::AddElement ( nsIRDFResource parent,
nsIRDFResource prop,
nsIRDFNode child 
) [protected]

Definition at line 964 of file nsDirectoryViewer.cpp.

{
    nsresult    rv;

    if (!mNodeList)
    {
        rv = NS_NewISupportsArray(getter_AddRefs(mNodeList));
        if (NS_FAILED(rv)) return(rv);
    }

    // order required: parent, prop, then child
    mNodeList->AppendElement(parent);
    mNodeList->AppendElement(prop);
    mNodeList->AppendElement(child);

       if (!mTimer)
       {
              mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
              NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create a timer");
              if (NS_FAILED(rv))  return(rv);

              mTimer->InitWithFuncCallback(nsHTTPIndex::FireTimer, this, 1,
                  nsITimer::TYPE_ONE_SHOT);
              // Note: don't addref "this" as we'll cancel the
              // timer in the httpIndex destructor
       }

    return(NS_OK);
}

Here is the call graph for this function:

Definition at line 600 of file nsDirectoryViewer.cpp.

{
    nsresult  rv = NS_OK;

    // set initial/default encoding to ISO-8859-1 (not UTF-8)
    mEncoding = "ISO-8859-1";

    mDirRDF = do_GetService(kRDFServiceCID, &rv);
    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
    if (NS_FAILED(rv)) {
      return(rv);
    }

    mInner = do_CreateInstance("@mozilla.org/rdf/datasource;1?name=in-memory-datasource", &rv);

    if (NS_FAILED(rv))
      return rv;

    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
                         getter_AddRefs(kNC_Child));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "loading"),
                         getter_AddRefs(kNC_Loading));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Comment"),
                         getter_AddRefs(kNC_Comment));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"),
                         getter_AddRefs(kNC_URL));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"),
                         getter_AddRefs(kNC_Description));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Content-Length"),
                         getter_AddRefs(kNC_ContentLength));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastModifiedDate"),
                         getter_AddRefs(kNC_LastModified));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Content-Type"),
                         getter_AddRefs(kNC_ContentType));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "File-Type"),
                         getter_AddRefs(kNC_FileType));
    mDirRDF->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IsContainer"),
                         getter_AddRefs(kNC_IsContainer));

    rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("true").get(), getter_AddRefs(kTrueLiteral));
    if (NS_FAILED(rv)) return(rv);
    rv = mDirRDF->GetLiteral(NS_LITERAL_STRING("false").get(), getter_AddRefs(kFalseLiteral));
    if (NS_FAILED(rv)) return(rv);

    rv = NS_NewISupportsArray(getter_AddRefs(mConnectionList));
    if (NS_FAILED(rv)) return(rv);

    // note: don't register DS here
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTTPIndex::Create ( nsIURI aBaseURI,
nsIInterfaceRequestor aContainer,
nsIHTTPIndex **  aResult 
) [static]

Definition at line 700 of file nsDirectoryViewer.cpp.

{
  *aResult = nsnull;

  nsHTTPIndex* result = new nsHTTPIndex(aRequestor);
  if (! result)
    return NS_ERROR_OUT_OF_MEMORY;

  nsresult rv = result->Init(aBaseURL);
  if (NS_SUCCEEDED(rv))
  {
    NS_ADDREF(result);
    *aResult = result;
  }
  else
  {
    delete result;
  }
  return rv;
}

Here is the call graph for this function:

void nsHTTPIndex::FireTimer ( nsITimer aTimer,
void aClosure 
) [static, protected]

Definition at line 995 of file nsDirectoryViewer.cpp.

{
  nsHTTPIndex *httpIndex = NS_STATIC_CAST(nsHTTPIndex *, aClosure);
  if (!httpIndex)    return;
  
  // don't return out of this loop as mTimer may need to be cancelled afterwards
  PRBool      refireTimer = PR_FALSE;
  
  PRUint32    numItems = 0;
  if (httpIndex->mConnectionList)
  {
        httpIndex->mConnectionList->Count(&numItems);
        if (numItems > 0)
        {
          nsCOMPtr<nsISupports>   isupports;
          httpIndex->mConnectionList->GetElementAt((PRUint32)0, getter_AddRefs(isupports));
          httpIndex->mConnectionList->RemoveElementAt((PRUint32)0);
          
          nsCOMPtr<nsIRDFResource>    aSource;
          if (isupports)  aSource = do_QueryInterface(isupports);
          
          nsXPIDLCString uri;
          if (aSource) {
            httpIndex->GetDestination(aSource, uri);
          }
          
          if (!uri) {
            NS_ERROR("Could not reconstruct uri");
            return;
          }
          
          nsresult            rv = NS_OK;
          nsCOMPtr<nsIURI>  url;
          
          rv = NS_NewURI(getter_AddRefs(url), uri.get());
          nsCOMPtr<nsIChannel>     channel;
          if (NS_SUCCEEDED(rv) && (url)) {
            rv = NS_NewChannel(getter_AddRefs(channel), url, nsnull, nsnull);
          }
          if (NS_SUCCEEDED(rv) && (channel)) {
            channel->SetNotificationCallbacks(httpIndex);
            rv = channel->AsyncOpen(httpIndex, aSource);
          }
        }
    }
    if (httpIndex->mNodeList)
    {
        httpIndex->mNodeList->Count(&numItems);
        if (numItems > 0)
        {
            // account for order required: src, prop, then target
            numItems /=3;
            if (numItems > 10)  numItems = 10;
          
            PRInt32 loop;
            for (loop=0; loop<(PRInt32)numItems; loop++)
            {
                nsCOMPtr<nsISupports>   isupports;
                httpIndex->mNodeList->GetElementAt((PRUint32)0, getter_AddRefs(isupports));
                httpIndex->mNodeList->RemoveElementAt((PRUint32)0);
                nsCOMPtr<nsIRDFResource>    src;
                if (isupports)  src = do_QueryInterface(isupports);
                httpIndex->mNodeList->GetElementAt((PRUint32)0, getter_AddRefs(isupports));
                httpIndex->mNodeList->RemoveElementAt((PRUint32)0);
                nsCOMPtr<nsIRDFResource>    prop;
                if (isupports)  prop = do_QueryInterface(isupports);
                
                httpIndex->mNodeList->GetElementAt((PRUint32)0, getter_AddRefs(isupports));
                httpIndex->mNodeList->RemoveElementAt((PRUint32)0);
                nsCOMPtr<nsIRDFNode>    target;
                if (isupports)  target = do_QueryInterface(isupports);
                
                if (src && prop && target)
                {
                    if (prop.get() == httpIndex->kNC_Loading)
                    {
                        httpIndex->Unassert(src, prop, target);
                    }
                    else
                    {
                        httpIndex->Assert(src, prop, target, PR_TRUE);
                    }
                }
            }                
        }
    }
    
    // check both lists to see if the timer needs to continue firing
    if (httpIndex->mConnectionList)
    {
        httpIndex->mConnectionList->Count(&numItems);
        if (numItems > 0)
        {
            refireTimer = PR_TRUE;
        }
        else
        {
            httpIndex->mConnectionList->Clear();
        }
    }
    if (httpIndex->mNodeList)
    {
        httpIndex->mNodeList->Count(&numItems);
        if (numItems > 0)
        {
            refireTimer = PR_TRUE;
        }
        else
        {
            httpIndex->mNodeList->Clear();
        }
    }

    // be sure to cancel the timer, as it holds a
    // weak reference back to nsHTTPIndex
    httpIndex->mTimer->Cancel();
    httpIndex->mTimer = nsnull;
    
    // after firing off any/all of the connections be sure
    // to cancel the timer if we don't need to refire it
    if (refireTimer)
    {
      httpIndex->mTimer = do_CreateInstance("@mozilla.org/timer;1");
      if (httpIndex->mTimer)
      {
        httpIndex->mTimer->InitWithFuncCallback(nsHTTPIndex::FireTimer, aClosure, 10,
                                                nsITimer::TYPE_ONE_SHOT);
        // Note: don't addref "this" as we'll cancel the
        // timer in the httpIndex destructor
      }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 744 of file nsDirectoryViewer.cpp.

                                                                        {
  // First try the URL attribute
  nsCOMPtr<nsIRDFNode> node;
  
  GetTarget(r, kNC_URL, PR_TRUE, getter_AddRefs(node));
  nsCOMPtr<nsIRDFLiteral> url;
  
  if (node)
    url = do_QueryInterface(node);

  if (!url) {
     const char* temp;
     r->GetValueConst(&temp);
     dest.Adopt(temp ? nsCRT::strdup(temp) : 0);
  } else {
    const PRUnichar* uri;
    url->GetValueConst(&uri);
    dest.Adopt(ToNewUTF8String(nsDependentString(uri)));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsHTTPIndex::Init ( nsIURI aBaseURL) [protected]

Definition at line 673 of file nsDirectoryViewer.cpp.

{
  NS_PRECONDITION(aBaseURL != nsnull, "null ptr");
  if (! aBaseURL)
    return NS_ERROR_NULL_POINTER;

  nsresult rv;

  rv = CommonInit();
  if (NS_FAILED(rv)) return(rv);

  // note: don't register DS here (singleton case)

  rv = aBaseURL->GetSpec(mBaseURL);
  if (NS_FAILED(rv)) return rv;
  
  // Mark the base url as a container
  nsCOMPtr<nsIRDFResource> baseRes;
  mDirRDF->GetResource(mBaseURL, getter_AddRefs(baseRes));
  Assert(baseRes, kNC_IsContainer, kTrueLiteral, PR_TRUE);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 653 of file nsDirectoryViewer.cpp.

{
       nsresult      rv;

       // set initial/default encoding to ISO-8859-1 (not UTF-8)
       mEncoding = "ISO-8859-1";

       rv = CommonInit();
       if (NS_FAILED(rv))   return(rv);

       // (do this last) register this as a named data source with the RDF service
       rv = mDirRDF->RegisterDataSource(this, PR_FALSE);
       if (NS_FAILED(rv)) return(rv);

       return(NS_OK);
}

Here is the call graph for this function:

Definition at line 785 of file nsDirectoryViewer.cpp.

{
  nsCOMPtr<nsIRDFNode> node;
  GetTarget(r, kNC_IsContainer, PR_TRUE, getter_AddRefs(node));

  PRBool isContainerFlag = PR_FALSE;

  if (node && NS_SUCCEEDED(node->EqualsNode(kTrueLiteral, &isContainerFlag))) {
    return isContainerFlag;
  } else {
    nsXPIDLCString uri;
    
    // For gopher, we need to follow the URL attribute to get the
    // real destination
    GetDestination(r,uri);

    if ((uri.get()) && (!strncmp(uri, kFTPProtocol, sizeof(kFTPProtocol) - 1))) {
      if (uri.Last() == '/') {
        isContainerFlag = PR_TRUE;
      }
    }

    // A gopher url is of the form:
    // gopher://example.com/xFileNameToGet
    // where x is a single character representing the type of file
    // 1 is a directory, and 7 is a search.
    // Searches will cause a dialog to be popped up (asking the user what
    // to search for), and so even though searches return a directory as a
    // result, don't treat it as a directory here.

    // The isContainerFlag test above will correctly handle this when a
    // search url is passed in as the baseuri
    if ((uri.get()) &&
        (!strncmp(uri,kGopherProtocol, sizeof(kGopherProtocol)-1))) {
      char* pos = PL_strchr(uri+sizeof(kGopherProtocol)-1, '/');
      if (!pos || pos[1] == '\0' || pos[1] == '1')
        isContainerFlag = PR_TRUE;
    }
  }
  return isContainerFlag;
}

Here is the call graph for this function:

void nsIFTPEventSink::OnFTPControlLog ( in boolean  server,
in string  msg 
) [inherited]

Member Data Documentation

Definition at line 93 of file nsDirectoryViewer.h.

Definition at line 82 of file nsDirectoryViewer.h.

Definition at line 83 of file nsDirectoryViewer.h.

Definition at line 87 of file nsDirectoryViewer.h.

Definition at line 89 of file nsDirectoryViewer.h.

Definition at line 86 of file nsDirectoryViewer.h.

Definition at line 90 of file nsDirectoryViewer.h.

Definition at line 91 of file nsDirectoryViewer.h.

Definition at line 88 of file nsDirectoryViewer.h.

Definition at line 84 of file nsDirectoryViewer.h.

Definition at line 85 of file nsDirectoryViewer.h.

Definition at line 92 of file nsDirectoryViewer.h.

Definition at line 109 of file nsDirectoryViewer.h.

Definition at line 111 of file nsDirectoryViewer.h.

Definition at line 105 of file nsDirectoryViewer.h.

Definition at line 113 of file nsDirectoryViewer.h.

Definition at line 95 of file nsDirectoryViewer.h.

Definition at line 110 of file nsDirectoryViewer.h.

Definition at line 104 of file nsDirectoryViewer.h.

Definition at line 106 of file nsDirectoryViewer.h.

Definition at line 108 of file nsDirectoryViewer.h.

Definition at line 112 of file nsDirectoryViewer.h.

Definition at line 107 of file nsDirectoryViewer.h.


The documentation for this class was generated from the following files: