Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsXFormsSubmissionElement.cpp File Reference
#include <stdlib.h>
#include "nsXFormsSubmissionElement.h"
#include "nsXFormsAtoms.h"
#include "nsIInstanceElementPrivate.h"
#include "nsIXTFGenericElementWrapper.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMAttr.h"
#include "nsIDOMText.h"
#include "nsIDOMCDATASection.h"
#include "nsIDOMEvent.h"
#include "nsIDOMDocumentEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMEventListener.h"
#include "nsIDOM3Node.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMXMLDocument.h"
#include "nsIDOMXPathResult.h"
#include "nsIDOMSerializer.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMParser.h"
#include "nsIAttribute.h"
#include "nsComponentManagerUtils.h"
#include "nsStringStream.h"
#include "nsIDocShell.h"
#include "nsIInputStream.h"
#include "nsIStorageStream.h"
#include "nsIMultiplexInputStream.h"
#include "nsIMIMEInputStream.h"
#include "nsINameSpaceManager.h"
#include "nsIContent.h"
#include "nsIFileURL.h"
#include "nsIMIMEService.h"
#include "nsIUploadChannel.h"
#include "nsIHttpChannel.h"
#include "nsIScriptSecurityManager.h"
#include "nsIPipe.h"
#include "nsLinebreakConverter.h"
#include "nsEscape.h"
#include "nsString.h"
#include "nsMemory.h"
#include "nsCOMPtr.h"
#include "nsNetUtil.h"
#include "nsXFormsUtils.h"
#include "nsIDOMNamedNodeMap.h"
#include "nsIPermissionManager.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIMIMEHeaderParam.h"
#include "nsIExternalProtocolService.h"
#include "nsAutoPtr.h"

Go to the source code of this file.

Classes

struct  SubmissionFormat
struct  SubmissionAttachment
class  SubmissionAttachmentArray

Defines

#define LOG(args)
#define kXMLNSNameSpaceURI   NS_LITERAL_STRING("http://www.w3.org/2000/xmlns/")
#define kIncludeNamespacePrefixes   NS_LITERAL_STRING("includenamespaceprefixes")
#define METHOD_GET   0x01
#define METHOD_POST   0x02
#define METHOD_PUT   0x04
#define ENCODING_XML   0x10
#define ENCODING_URL   0x20
#define ENCODING_MULTIPART_RELATED   0x40
#define ENCODING_MULTIPART_FORM_DATA   0x80
#define kError_SubmissionInProgress   NS_LITERAL_STRING("submission-in-progress");
#define kError_NoData   NS_LITERAL_STRING("no-data");
#define kError_ValidationError   NS_LITERAL_STRING("validation-error");
#define kError_ParseError   NS_LITERAL_STRING("parse-error");
#define kError_ResourceError   NS_LITERAL_STRING("resource-error");
#define kError_TargetError   NS_LITERAL_STRING("target-error");
#define ELEMENT_ENCTYPE_STRING   0
#define ELEMENT_ENCTYPE_URI   1
#define ELEMENT_ENCTYPE_BASE64   2
#define ELEMENT_ENCTYPE_HEX   3

Functions

static PRUint32 GetSubmissionFormat (nsIDOMElement *aElement)
static void MakeMultipartBoundary (nsCString &boundary)
static void MakeMultipartContentID (nsCString &cid)
static nsresult URLEncode (const nsString &buf, nsCString &result)
static void GetMimeTypeFromFile (nsIFile *file, nsCString &result)
static PRBool HasToken (const nsString &aTokenList, const nsString &aToken)
 NS_IMPL_ISUPPORTS_INHERITED4 (nsXFormsSubmissionElement, nsXFormsStubElement, nsIRequestObserver, nsIXFormsSubmissionElement, nsIInterfaceRequestor, nsIChannelEventSink) NS_IMETHODIMP nsXFormsSubmissionElement
static void ReleaseObject (void *aObject, nsIAtom *aPropertyName, void *aPropertyValue, void *aData)
nsresult NS_NewXFormsSubmissionElement (nsIXTFElement **aResult)

Variables

static const SubmissionFormat sSubmissionFormats []

Class Documentation

struct SubmissionFormat

Definition at line 135 of file nsXFormsSubmissionElement.cpp.

Class Members
PRUint32 format
const char * method
struct SubmissionAttachment

Definition at line 252 of file nsXFormsSubmissionElement.cpp.

Collaboration diagram for SubmissionAttachment:
Class Members
nsCString cid
nsCOMPtr< nsIFile > file

Define Documentation

Definition at line 168 of file nsXFormsSubmissionElement.cpp.

Definition at line 169 of file nsXFormsSubmissionElement.cpp.

Definition at line 166 of file nsXFormsSubmissionElement.cpp.

Definition at line 167 of file nsXFormsSubmissionElement.cpp.

Definition at line 119 of file nsXFormsSubmissionElement.cpp.

Definition at line 118 of file nsXFormsSubmissionElement.cpp.

#define ENCODING_URL   0x20

Definition at line 117 of file nsXFormsSubmissionElement.cpp.

#define ENCODING_XML   0x10

Definition at line 116 of file nsXFormsSubmissionElement.cpp.

Definition at line 124 of file nsXFormsSubmissionElement.cpp.

Definition at line 128 of file nsXFormsSubmissionElement.cpp.

Definition at line 130 of file nsXFormsSubmissionElement.cpp.

Definition at line 122 of file nsXFormsSubmissionElement.cpp.

Definition at line 132 of file nsXFormsSubmissionElement.cpp.

Definition at line 126 of file nsXFormsSubmissionElement.cpp.

#define kIncludeNamespacePrefixes   NS_LITERAL_STRING("includenamespaceprefixes")

Definition at line 107 of file nsXFormsSubmissionElement.cpp.

#define kXMLNSNameSpaceURI   NS_LITERAL_STRING("http://www.w3.org/2000/xmlns/")

Definition at line 104 of file nsXFormsSubmissionElement.cpp.

#define LOG (   args)

Definition at line 45 of file nsXFormsSubmissionElement.cpp.

#define METHOD_GET   0x01

Definition at line 111 of file nsXFormsSubmissionElement.cpp.

#define METHOD_POST   0x02

Definition at line 112 of file nsXFormsSubmissionElement.cpp.

#define METHOD_PUT   0x04

Definition at line 113 of file nsXFormsSubmissionElement.cpp.


Function Documentation

static void GetMimeTypeFromFile ( nsIFile file,
nsCString result 
) [static]

Definition at line 214 of file nsXFormsSubmissionElement.cpp.

{
  nsCOMPtr<nsIMIMEService> mime = do_GetService("@mozilla.org/mime;1");
  if (mime)
    mime->GetTypeFromFile(file, result);
  if (result.IsEmpty())
    result.Assign("application/octet-stream");
}

Here is the call graph for this function:

static PRUint32 GetSubmissionFormat ( nsIDOMElement aElement) [static]

Definition at line 151 of file nsXFormsSubmissionElement.cpp.

{
  nsAutoString method;
  aElement->GetAttribute(NS_LITERAL_STRING("method"), method);

  NS_ConvertUTF16toUTF8 utf8method(method);
  for (PRUint32 i=0; i<NS_ARRAY_LENGTH(sSubmissionFormats); ++i)
  {
    // XXX case sensitive compare ok?
    if (utf8method.Equals(sSubmissionFormats[i].method))
      return sSubmissionFormats[i].format;
  }
  return 0;
}
static PRBool HasToken ( const nsString aTokenList,
const nsString aToken 
) [static]

Definition at line 224 of file nsXFormsSubmissionElement.cpp.

{
  PRInt32 i = aTokenList.Find(aToken);
  if (i == kNotFound)
    return PR_FALSE;
  
  // else, check that leading and trailing characters are either
  // not present or whitespace (#x20, #x9, #xD or #xA).

  if (i > 0)
  {
    PRUnichar c = aTokenList[i - 1];
    if (!(c == 0x20 || c == 0x9 || c == 0xD || c == 0xA))
      return PR_FALSE;
  }

  if (i + aToken.Length() < aTokenList.Length())
  {
    PRUnichar c = aTokenList[i + aToken.Length()];
    if (!(c == 0x20 || c == 0x9 || c == 0xD || c == 0xA))
      return PR_FALSE;
  }

  return PR_TRUE;
}
static void MakeMultipartBoundary ( nsCString boundary) [static]

Definition at line 172 of file nsXFormsSubmissionElement.cpp.

{
  boundary.AssignLiteral("---------------------------");
  boundary.AppendInt(rand());
  boundary.AppendInt(rand());
  boundary.AppendInt(rand());
}
static void MakeMultipartContentID ( nsCString cid) [static]

Definition at line 181 of file nsXFormsSubmissionElement.cpp.

{
  cid.AppendInt(rand(), 16);
  cid.Append('.');
  cid.AppendInt(rand(), 16);
  cid.AppendLiteral("@mozilla.org");
}

Here is the caller graph for this function:

Definition at line 290 of file nsXFormsSubmissionElement.cpp.

{
  mElement = nsnull;
  return NS_OK;
}

Definition at line 2995 of file nsXFormsSubmissionElement.cpp.

{
  *aResult = new nsXFormsSubmissionElement();
  if (!*aResult)
    return NS_ERROR_OUT_OF_MEMORY;

  NS_ADDREF(*aResult);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ReleaseObject ( void aObject,
nsIAtom aPropertyName,
void aPropertyValue,
void aData 
) [static]

Definition at line 1797 of file nsXFormsSubmissionElement.cpp.

{
  NS_STATIC_CAST(nsISupports *, aPropertyValue)->Release();
}
static nsresult URLEncode ( const nsString buf,
nsCString result 
) [static]

Definition at line 190 of file nsXFormsSubmissionElement.cpp.

{
  // 1. convert to UTF-8
  // 2. normalize newlines to \r\n
  // 3. escape, converting ' ' to '+'

  NS_ConvertUTF16toUTF8 utf8Buf(buf);

  char *convertedBuf =
      nsLinebreakConverter::ConvertLineBreaks(utf8Buf.get(),
                                              nsLinebreakConverter::eLinebreakAny,
                                              nsLinebreakConverter::eLinebreakNet);
  NS_ENSURE_TRUE(convertedBuf, NS_ERROR_OUT_OF_MEMORY);

  char *escapedBuf = nsEscape(convertedBuf, url_XPAlphas);
  nsMemory::Free(convertedBuf);

  NS_ENSURE_TRUE(escapedBuf, NS_ERROR_OUT_OF_MEMORY);

  result.Adopt(escapedBuf);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {
  { "post",            ENCODING_XML                 | METHOD_POST },
  { "get",             ENCODING_URL                 | METHOD_GET  },
  { "put",             ENCODING_XML                 | METHOD_PUT  },
  { "multipart-post",  ENCODING_MULTIPART_RELATED   | METHOD_POST },
  { "form-data-post",  ENCODING_MULTIPART_FORM_DATA | METHOD_POST },
  { "urlencoded-post", ENCODING_URL                 | METHOD_POST }
}

Definition at line 141 of file nsXFormsSubmissionElement.cpp.