Additional SOAP call work. This is not part of the Seamonkey project.

This commit is contained in:
vidur%netscape.com 2000-07-13 23:11:16 +00:00
Родитель cd5bb8ed1f
Коммит 0d8f10e1f6
33 изменённых файлов: 3034 добавлений и 318 удалений

Просмотреть файл

@ -123,13 +123,12 @@ interface nsISOAPCall : nsISupports {
/**
* The script-only method for setting the list of parameters to
* include in the SOAP call.
*
* @param parameters The expectation is that this parameter is either a
* JavaScript array that holds the nsISOAPParameter
* instances or a single nsISOAPParameter.
* include in the SOAP call. Despite what the idl implies, this
* method takes an arbitrary number of arguments. Each is either
* a SOAPParameter object or a JavaScript value which will be
* converted to an unnamed SOAPParameter.
*/
void setParameters(in nsISupports parameters);
void setParameters();
/**
* A script-only method for setting the list of parameters, where

Просмотреть файл

@ -40,7 +40,8 @@ interface nsISOAPEncoder : nsISupports {
*
*/
nsISOAPParameter elementToParameter(in nsIDOMElement element,
in string encodingStyle);
in string encodingStyle,
in long hintType);
};
%{ C++

Просмотреть файл

@ -70,19 +70,20 @@ interface nsISOAPParameter : nsISupports {
* </ul>
* </p>
*/
const long PARAMETER_TYPE_NULL = 0;
const long PARAMETER_TYPE_VOID = 1;
const long PARAMETER_TYPE_STRING = 2;
const long PARAMETER_TYPE_BOOLEAN = 3;
const long PARAMETER_TYPE_DOUBLE = 4;
const long PARAMETER_TYPE_FLOAT = 5;
const long PARAMETER_TYPE_LONG = 6;
const long PARAMETER_TYPE_INT = 7;
const long PARAMETER_TYPE_SHORT = 8;
const long PARAMETER_TYPE_BYTE = 9;
const long PARAMETER_TYPE_ARRAY = 10;
const long PARAMETER_TYPE_JAVASCRIPT_ARRAY = 11;
const long PARAMETER_TYPE_JAVASCRIPT_OBJECT = 12;
const long PARAMETER_TYPE_UNKNOWN = 0;
const long PARAMETER_TYPE_NULL = 1;
const long PARAMETER_TYPE_VOID = 2;
const long PARAMETER_TYPE_STRING = 3;
const long PARAMETER_TYPE_BOOLEAN = 4;
const long PARAMETER_TYPE_DOUBLE = 5;
const long PARAMETER_TYPE_FLOAT = 6;
const long PARAMETER_TYPE_LONG = 7;
const long PARAMETER_TYPE_INT = 8;
const long PARAMETER_TYPE_SHORT = 9;
const long PARAMETER_TYPE_BYTE = 10;
const long PARAMETER_TYPE_ARRAY = 11;
const long PARAMETER_TYPE_JAVASCRIPT_ARRAY = 12;
const long PARAMETER_TYPE_JAVASCRIPT_OBJECT = 13;
/**
* An optional encodingStyle specifically for this parameter. The
@ -119,17 +120,32 @@ interface nsISOAPParameter : nsISupports {
[noscript] void setValueAndType(in nsISupports value, in long type);
/**
* <p>The getter is for native and script callers. For native callers,
* the interface implemented by the returned value depends on the
* Native (non-script) method for getting the value and type of a parameter.
* The interface implemented by the <code>value</code> parameter
* depends on the value of <code>type</code> parameter. Additional
* details can be found in the descriptions for the type constants.
*
* @param value Out parameter returning the value of the parameter.
* Either NULL or an object that implements an interface
* specified by the <code>type</code> parameter.
* @param type Out parameter returning the type of the parameter. See
* the description of the type contants for details.
*/
[noscript] void getValueAndType(out nsISupports value, out long type);
/**
* <p>The getter is for native and script callers (despite the
* [noscript] qualification). For native callers, the interface
* implemented by the returned value depends on the
* <code>type</code> attribute as detailed in the description of the
* type constants. For script callers, the value returned is either
* a string, boolean, double, integer, Array or object.</p>
* <p>Even though the attribute is readonly in IDL, script callers can
* set it (native callers should use the <code>setValueAndType</code>
* method). For script callers, the value can be either a string,
* boolean, double, integer, Array or object.
* a string, boolean, double, integer, Array or object.</p>
* <p>The setter is for script callers only. Native callers should
* use the <code>setValueAndType</code> method). For script callers,
* the value can be either a string, boolean, double, integer, Array
* or object.
*/
readonly attribute nsISupports value;
[noscript] attribute nsISupports value;
/**
* Used by native callers (SOAP encoders, for example) to retrieve
@ -145,6 +161,6 @@ interface nsISOAPParameter : nsISupports {
{ /* 87d21ec2-539d-11d4-9a59-00104bdf5339 */ \
0x87d21ec2, 0x539d, 0x11d4, \
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
#define NS_SOAPCPARAMETER_PROGID \
#define NS_SOAPPARAMETER_PROGID \
"component://netscape/xmlextras/soap/parameter"
%}

Просмотреть файл

@ -36,7 +36,7 @@ interface nsISOAPTransportListener : nsISupports {
* @param result The call result
*/
void handleResponse(in nsIDOMDocument document,
in unsigned long status,
in nsresult result);
in unsigned long status,
in nsresult result);
};

Просмотреть файл

@ -36,6 +36,7 @@ CPPSRCS = \
nsSOAPFault.cpp \
nsSOAPParameter.cpp \
nsDefaultSOAPEncoder.cpp \
nsHTTPSOAPTransport.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -24,6 +24,8 @@
#define nsDefaultSOAPEncoder_h__
#include "nsISOAPEncoder.h"
#include "nsISupportsArray.h"
#include "jsapi.h"
class nsDefaultSOAPEncoder : public nsISOAPEncoder {
public:
@ -34,6 +36,35 @@ public:
// nsISOAPEncoder
NS_DECL_NSISOAPENCODER
protected:
nsresult EncodeParameter(nsISOAPParameter* parameter,
nsIDOMDocument* document,
nsIDOMElement** element);
nsresult SerializeSupportsArray(nsISupportsArray* array,
nsIDOMElement* element,
nsIDOMDocument* document);
nsresult SerializeJavaScriptArray(JSObject* arrayobj,
nsIDOMElement* element,
nsIDOMDocument* document);
nsresult SerializeJavaScriptObject(JSObject* obj,
nsIDOMElement* element,
nsIDOMDocument* document);
nsresult SerializeParameterValue(nsISOAPParameter* parameter,
nsIDOMElement* element,
nsIDOMDocument* document);
nsresult DecodeParameter(nsIDOMElement* element,
PRInt32 type,
nsISOAPParameter **_retval);
nsresult DeserializeSupportsArray(nsIDOMElement *element,
nsISupportsArray **_retval);
nsresult DeserializeJavaScriptObject(nsIDOMElement *element,
JSObject** obj);
nsresult DeserializeParameter(nsIDOMElement *element,
PRInt32 type,
nsISOAPParameter **_retval);
};
#define NS_DEFAULTSOAPENCODER_CID \

Просмотреть файл

@ -0,0 +1,133 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsHTTPSOAPTransport.h"
#include "nsIComponentManager.h"
#include "nsIDOMDocument.h"
nsHTTPSOAPTransport::nsHTTPSOAPTransport()
{
NS_INIT_ISUPPORTS();
}
nsHTTPSOAPTransport::~nsHTTPSOAPTransport()
{
}
NS_IMPL_ISUPPORTS2(nsHTTPSOAPTransport, nsISOAPTransport, nsIDOMEventListener)
/* boolean canDoSync (); */
NS_IMETHODIMP
nsHTTPSOAPTransport::CanDoSync(PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = PR_TRUE;
return NS_OK;
}
/* nsIDOMDocument syncCall (in string url, in string action, in nsIDOMDocument messageDocument); */
NS_IMETHODIMP
nsHTTPSOAPTransport::SyncCall(const char *url,
const char *action,
nsIDOMDocument *messageDocument,
nsIDOMDocument **_retval)
{
NS_ENSURE_ARG(url);
NS_ENSURE_ARG(messageDocument);
NS_ENSURE_ARG_POINTER(_retval);
nsresult rv;
nsCOMPtr<nsIXMLHttpRequest> request;
request = do_CreateInstance(NS_XMLHTTPREQUEST_PROGID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (action) {
request->SetRequestHeader("SOAPAction", action);
}
rv = request->OpenRequest("POST", url, PR_FALSE, nsnull, nsnull);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = request->Send(messageDocument);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = request->GetResponseXML(_retval);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
return NS_OK;
}
/* void asyncCall (in string url, in string action, in nsIDOMDocument messageDocument, in nsISOAPTransportListener listener); */
NS_IMETHODIMP
nsHTTPSOAPTransport::AsyncCall(const char *url,
const char *action,
nsIDOMDocument *messageDocument,
nsISOAPTransportListener *listener)
{
NS_ENSURE_ARG(url);
NS_ENSURE_ARG(messageDocument);
nsresult rv;
mRequest = do_CreateInstance(NS_XMLHTTPREQUEST_PROGID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (action) {
mRequest->SetRequestHeader("SOAPAction", action);
}
rv = mRequest->OpenRequest("POST", url, PR_TRUE, nsnull, nsnull);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
mListener = listener;
mRequest->AddEventListener("load",
NS_STATIC_CAST(nsIDOMEventListener*, this));
mRequest->AddEventListener("error",
NS_STATIC_CAST(nsIDOMEventListener*, this));
rv = mRequest->Send(messageDocument);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
return NS_OK;
}
nsresult
nsHTTPSOAPTransport::HandleEvent(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMDocument> document;
PRUint32 status;
mRequest->GetResponseXML(getter_AddRefs(document));
mRequest->GetStatus(&status);
if (mListener) {
// XXX If this is an error, we need to pass in NS_ERROR_FAILURE
mListener->HandleResponse(document, status, NS_OK);
mListener = 0;
}
mRequest = 0;
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsHTTPSOAPTransport_h__
#define nsHTTPSOAPTransport_h__
#include "nsISOAPTransport.h"
#include "nsIXMLHttpRequest.h"
#include "nsIDOMEventListener.h"
#include "nsISOAPTransportListener.h"
#include "nsCOMPtr.h"
class nsHTTPSOAPTransport : public nsISOAPTransport,
public nsIDOMEventListener
{
public:
nsHTTPSOAPTransport();
virtual ~nsHTTPSOAPTransport();
NS_DECL_ISUPPORTS
// nsISOAPTransport
NS_DECL_NSISOAPTRANSPORT
// nsIDOMEventListener
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
protected:
nsCOMPtr<nsIXMLHttpRequest> mRequest;
nsCOMPtr<nsISOAPTransportListener> mListener;
};
#define NS_HTTPSOAPTRANSPORT_CID \
{ /* d852ade0-5823-11d4-9a62-00104bdf5339 */ \
0xd852ade0, 0x5823, 0x11d4, \
{0x9a, 0x62, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
#define NS_HTTPSOAPTRANSPORT_PROGID NS_SOAPTRANSPORT_PROGID_PREFIX "http"
#endif

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsSOAPCall.h"
#include "nsSOAPResponse.h"
#include "nsSOAPParameter.h"
#include "nsSOAPUtils.h"
#include "nsCRT.h"
#include "jsapi.h"
@ -158,7 +159,7 @@ NS_IMPL_ISUPPORTS3(nsSOAPCall,
nsISOAPTransportListener)
static const char* kEmptySOAPDocStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
static const char* kEmptySOAPDocStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">"
"<SOAP-ENV:Header>"
"</SOAP-ENV:Header>"
"<SOAP-ENV:Body>"
@ -320,7 +321,7 @@ nsSOAPCall::CreateBodyEntry(PRBool aNewParameters)
// If there is, we're going to replace it, but preserve its
// children.
if (entry) {
if (oldEntry) {
// Remove the old entry from the body
mBodyElement->RemoveChild(oldEntry, getter_AddRefs(dummy));
@ -580,8 +581,8 @@ NS_IMETHODIMP nsSOAPCall::SetSOAPParameters(nsISOAPParameter **parameters, PRUin
return NS_OK;
}
/* void setParameters (in nsISupports parameters); */
NS_IMETHODIMP nsSOAPCall::SetParameters(nsISupports *parameters)
/* void setParameters (); */
NS_IMETHODIMP nsSOAPCall::SetParameters()
{
nsresult rv;
@ -595,69 +596,65 @@ NS_IMETHODIMP nsSOAPCall::SetParameters(nsISupports *parameters)
if (!mParameters) return NS_ERROR_OUT_OF_MEMORY;
}
// If it's a single parameter, just add it to the list
nsCOMPtr<nsISOAPParameter> singleParam = do_QueryInterface(parameters);
if (singleParam) {
mParameters->AppendElement(singleParam);
nsCOMPtr<nsIXPCNativeCallContext> cc;
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
if(NS_SUCCEEDED(rv)) {
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
}
else {
nsCOMPtr<nsIXPCNativeCallContext> cc;
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
if(NS_SUCCEEDED(rv)) {
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
}
// This should only be called from script
if (NS_FAILED(rv) || !cc) {
return NS_ERROR_FAILURE;
}
PRUint32 argc;
rv = cc->GetArgc(&argc);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
jsval* argv;
rv = cc->GetArgvPtr(&argv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// For each parameter to this method
PRUint32 index;
for (index = 0; index < argc; index++) {
nsCOMPtr<nsISOAPParameter> param;
jsval val = argv[index];
// Otherwise see if it's a JSObject
if (NS_SUCCEEDED(rv) && cc) {
nsCOMPtr<nsIXPConnectJSObjectHolder> jsobjholder = do_QueryInterface(parameters);
if (jsobjholder) {
JSObject* arrayobj;
rv = jsobjholder->GetJSObject(&arrayobj);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// First check if it's a parameter
if (JSVAL_IS_OBJECT(val)) {
JSObject* paramobj;
paramobj = JSVAL_TO_OBJECT(val);
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// We expect a JS array
if (!JS_IsArrayObject(cx, arrayobj)) {
return NS_ERROR_INVALID_ARG;
}
jsuint index, count;
if (!JS_GetArrayLength(cx, arrayobj, &count)) {
return NS_ERROR_INVALID_ARG;
}
// For each element in the array
for (index = 0; index < count; index++) {
jsval val;
JSObject* paramobj;
if (!JS_GetElement(cx, arrayobj, (jsint)index, &val)) {
return NS_ERROR_FAILURE;
}
// Make sure it's an object
if (!JSVAL_IS_OBJECT(val)) return NS_ERROR_INVALID_ARG;
paramobj = JSVAL_TO_OBJECT(val);
// It should be a wrapped native
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
xpc->GetWrappedNativeOfJSObject(cx, paramobj, getter_AddRefs(wrapper));
if (!wrapper) return NS_ERROR_INVALID_ARG;
// Get the native and make sure it's a SOAPParameter
nsCOMPtr<nsISupports> isup;
wrapper->GetNative(getter_AddRefs(isup));
if (!isup) return NS_ERROR_INVALID_ARG;
nsCOMPtr<nsISOAPParameter> param = do_QueryInterface(isup);
if (!param) return NS_ERROR_INVALID_ARG;
mParameters->AppendElement(param);
// Check if it's a wrapped native
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
xpc->GetWrappedNativeOfJSObject(cx, paramobj, getter_AddRefs(wrapper));
if (wrapper) {
// Get the native and see if it's a SOAPParameter
nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native));
if (native) {
param = do_QueryInterface(native);
}
}
}
// Otherwise create a new parameter with the value
if (!param) {
nsSOAPParameter* newparam = new nsSOAPParameter();
if (!newparam) return NS_ERROR_OUT_OF_MEMORY;
param = (nsISOAPParameter*)newparam;
rv = newparam->SetValue(cx, val);
if (NS_FAILED(rv)) return rv;
}
mParameters->AppendElement(param);
}
if (HasBodyEntry()) {

Просмотреть файл

@ -168,3 +168,49 @@ NS_IMETHODIMP nsSOAPFault::GetDetail(nsIDOMElement * *aDetail)
}
return NS_OK;
}
static const char* kAllAccess = "AllAccess";
/* string canCreateWrapper (in nsIIDPtr iid); */
NS_IMETHODIMP
nsSOAPFault::CanCreateWrapper(const nsIID * iid, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsISOAPFault))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
NS_IMETHODIMP
nsSOAPFault::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsISOAPFault))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsSOAPFault::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsISOAPFault))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsSOAPFault::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsISOAPFault))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}

Просмотреть файл

@ -29,6 +29,7 @@ nsSOAPParameter::nsSOAPParameter()
{
NS_INIT_ISUPPORTS();
mType = PARAMETER_TYPE_NULL;
mJSValue = nsnull;
JSContext* cx;
cx = nsSOAPUtils::GetSafeContext();
if (cx) {
@ -45,7 +46,11 @@ nsSOAPParameter::~nsSOAPParameter()
}
}
NS_IMPL_ISUPPORTS2(nsSOAPParameter, nsISOAPParameter, nsISecurityCheckedComponent)
NS_IMPL_ISUPPORTS4(nsSOAPParameter,
nsISOAPParameter,
nsISecurityCheckedComponent,
nsIXPCScriptable,
nsIJSNativeInitializer)
/* attribute string encodingStyleURI; */
NS_IMETHODIMP nsSOAPParameter::GetEncodingStyleURI(char * *aEncodingStyleURI)
@ -112,46 +117,48 @@ NS_IMETHODIMP nsSOAPParameter::SetValueAndType(nsISupports *value, PRInt32 type)
return NS_OK;
}
/* readonly attribute nsISupports value; */
NS_IMETHODIMP nsSOAPParameter::GetValue(nsISupports * *aValue)
/* [noscript] void getValueAndType (out nsISupports value, out long type); */
NS_IMETHODIMP nsSOAPParameter::GetValueAndType(nsISupports **value, PRInt32 *type)
{
NS_ENSURE_ARG_POINTER(aValue);
nsresult rv;
NS_ENSURE_ARG_POINTER(value);
NS_ENSURE_ARG_POINTER(type);
// Check if this is a script or native call
nsCOMPtr<nsIXPCNativeCallContext> cc;
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
if(NS_SUCCEEDED(rv)) {
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
}
// If this is a script call
if (NS_SUCCEEDED(rv) && cc) {
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
jsval val;
rv = nsSOAPUtils::ConvertValueToJSVal(cx, mValue, mJSValue, mType, &val);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
jsval* vp;
rv = cc->GetRetValPtr(&vp);
if (NS_SUCCEEDED(rv)) {
*vp = val;
cc->SetReturnValueWasSet(JS_TRUE);
}
}
else {
*aValue = mValue;
NS_IF_ADDREF(*aValue);
}
*value = mValue;
NS_IF_ADDREF(*value);
*type = mType;
return NS_OK;
}
// We can't make this a setter in xpidl without a variant type.
// For now, use nsIXPCScriptable to do the setting.
/* attribute nsISupports value; */
// We can't use this attribute for script calls without a variant type
// in xpidl. For now, use nsIXPCScriptable to implement.
NS_IMETHODIMP nsSOAPParameter::GetValue(nsISupports * *aValue)
{
NS_ENSURE_ARG_POINTER(aValue);
*aValue = mValue;
NS_IF_ADDREF(*aValue);
return NS_OK;
}
NS_IMETHODIMP
nsSOAPParameter::SetValue(nsISupports* value)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsSOAPParameter::GetValue(JSContext* aContext,
jsval* aValue)
{
return nsSOAPUtils::ConvertValueToJSVal(aContext,
mValue,
mJSValue,
mType,
aValue);
}
NS_IMETHODIMP nsSOAPParameter::SetValue(JSContext* aContext,
jsval aValue)
{
@ -171,11 +178,27 @@ NS_IMETHODIMP nsSOAPParameter::GetJSValue(JSObject * *aJSValue)
return NS_OK;
}
NS_IMETHODIMP
nsSOAPParameter::Initialize(JSContext *cx, JSObject *obj,
PRUint32 argc, jsval *argv)
{
if (argc > 0) {
JSString* namestr = JS_ValueToString(cx, argv[0]);
if (namestr) {
SetName(NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(namestr)));
if (argc > 1) {
SetValue(cx, argv[1]);
}
}
}
return NS_OK;
}
XPC_IMPLEMENT_IGNORE_CREATE(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_GETFLAGS(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_LOOKUPPROPERTY(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_DEFINEPROPERTY(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_GETPROPERTY(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_GETATTRIBUTES(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_SETATTRIBUTES(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_DELETEPROPERTY(nsSOAPParameter)
@ -184,8 +207,30 @@ XPC_IMPLEMENT_IGNORE_ENUMERATE(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_CHECKACCESS(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_CALL(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_CONSTRUCT(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_HASINSTANCE(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_FINALIZE(nsSOAPParameter)
NS_IMETHODIMP
nsSOAPParameter::GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
*retval = JS_TRUE;
jsval val;
if (JS_IdToValue(cx, id, &val)) {
if (JSVAL_IS_STRING(val)) {
JSString* str = JSVAL_TO_STRING(val);
char* name = JS_GetStringBytes(str);
if (nsCRT::strcmp(name, "value") == 0) {
return GetValue(cx, vp);
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsSOAPParameter::SetProperty(JSContext *cx, JSObject *obj, jsid id,
jsval *vp, nsIXPConnectWrappedNative* wrapper,
@ -198,7 +243,7 @@ nsSOAPParameter::SetProperty(JSContext *cx, JSObject *obj, jsid id,
if (JSVAL_IS_STRING(val)) {
JSString* str = JSVAL_TO_STRING(val);
char* name = JS_GetStringBytes(str);
if (nsCRT::strcmp(name, "value")) {
if (nsCRT::strcmp(name, "value") == 0) {
return SetValue(cx, *vp);
}
}

Просмотреть файл

@ -27,12 +27,14 @@
#include "nsISOAPParameter.h"
#include "nsISecurityCheckedComponent.h"
#include "nsIXPCScriptable.h"
#include "nsIJSNativeInitializer.h"
#include "nsString.h"
#include "nsCOMPtr.h"
class nsSOAPParameter : public nsISOAPParameter,
public nsISecurityCheckedComponent,
public nsIXPCScriptable
public nsIXPCScriptable,
public nsIJSNativeInitializer
{
public:
nsSOAPParameter();
@ -49,9 +51,15 @@ public:
// nsIXPCScriptable
XPC_DECLARE_IXPCSCRIPTABLE
NS_IMETHODIMP GetValue(JSContext* aContext,
jsval* aValue);
NS_IMETHODIMP SetValue(JSContext* aContext,
jsval aValue);
// nsIJSNativeInitializer
NS_IMETHOD Initialize(JSContext *cx, JSObject *obj,
PRUint32 argc, jsval *argv);
protected:
nsCString mEncodingStyleURI;
nsString mName;

Просмотреть файл

@ -31,6 +31,7 @@
nsSOAPResponse::nsSOAPResponse(nsIDOMDocument* aEnvelopeDocument)
{
NS_INIT_ISUPPORTS();
mEnvelopeDocument = aEnvelopeDocument;
if (mEnvelopeDocument) {
nsCOMPtr<nsIDOMElement> element;
@ -193,10 +194,15 @@ NS_IMETHODIMP nsSOAPResponse::GetReturnValue(nsISOAPParameter * *aReturnValue)
*aReturnValue = nsnull;
if (mResultElement) {
// The first child element is assumed to be the returned
// value
nsCOMPtr<nsIDOMElement> value;
nsSOAPUtils::GetFirstChildElement(mResultElement, getter_AddRefs(value));
// Get the inherited encoding style starting from the
// body entry.
// value
char* encodingStyle;
nsSOAPUtils::GetInheritedEncodingStyle(mResultElement,
nsSOAPUtils::GetInheritedEncodingStyle(value,
&encodingStyle);
if (!encodingStyle) {
@ -216,8 +222,9 @@ NS_IMETHODIMP nsSOAPResponse::GetReturnValue(nsISOAPParameter * *aReturnValue)
// Convert the result element to a parameter
nsCOMPtr<nsISOAPParameter> param;
rv = encoder->ElementToParameter(mResultElement,
rv = encoder->ElementToParameter(value,
encodingStyle,
nsISOAPParameter::PARAMETER_TYPE_UNKNOWN,
getter_AddRefs(param));
nsMemory::Free(encodingStyle);
if (NS_FAILED(rv)) return rv;

Просмотреть файл

@ -29,14 +29,25 @@
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsXPIDLString.h"
#include "nsISupportsArray.h"
const char* nsSOAPUtils::kSOAPEnvURI = "http://schemas.xmlsoap.org/soap/envelope/";
const char* nsSOAPUtils::kSOAPEncodingURI = "http://schemas.xmlsoap.org/soap/encoding/";
const char* nsSOAPUtils::kSOAPEnvPrefix = "SOAP-ENV";
const char* nsSOAPUtils::kSOAPEncodingPrefix = "SOAP-ENC";
const char* nsSOAPUtils::kXSIURI = "http://www.w3.org/1999/XMLSchema-instance";
const char* nsSOAPUtils::kXSDURI = "http://www.w3.org/1999/XMLSchema";
const char* nsSOAPUtils::kXSIPrefix = "xsi";
const char* nsSOAPUtils::kXSDPrefix = "xsd";
const char* nsSOAPUtils::kEncodingStyleAttribute = "encodingStyle";
const char* nsSOAPUtils::kEnvelopeTagName = "Envelope";
const char* nsSOAPUtils::kHeaderTagName = "Header";
const char* nsSOAPUtils::kBodyTagName = "Body";
const char* nsSOAPUtils::kFaultTagName = "Fault";
const char* nsSOAPUtils::kFaultCodeTagName = "faultcode";
const char* nsSOAPUtils::kFaultStringTagName = "faultstring";
const char* nsSOAPUtils::kFaultActorTagName = "faultactor";
const char* nsSOAPUtils::kFaultDetailTagName = "detail";
void
nsSOAPUtils::GetFirstChildElement(nsIDOMElement* aParent,
@ -82,31 +93,49 @@ void
nsSOAPUtils::GetElementTextContent(nsIDOMElement* aElement,
nsString& aText)
{
nsCOMPtr<nsIDOMNode> sibling;
nsCOMPtr<nsIDOMNode> child;
aText.Truncate();
aElement->GetNextSibling(getter_AddRefs(sibling));
while (sibling) {
aElement->GetFirstChild(getter_AddRefs(child));
while (child) {
PRUint16 type;
sibling->GetNodeType(&type);
child->GetNodeType(&type);
if (nsIDOMNode::TEXT_NODE == type) {
nsCOMPtr<nsIDOMText> text = do_QueryInterface(sibling);
nsCOMPtr<nsIDOMText> text = do_QueryInterface(child);
nsAutoString data;
text->GetData(data);
aText.Append(data);
}
nsCOMPtr<nsIDOMNode> temp = sibling;
temp->GetNextSibling(getter_AddRefs(sibling));
nsCOMPtr<nsIDOMNode> temp = child;
temp->GetNextSibling(getter_AddRefs(child));
}
}
PRBool
nsSOAPUtils::HasChildElements(nsIDOMElement* aElement)
{
nsCOMPtr<nsIDOMNode> child;
aElement->GetFirstChild(getter_AddRefs(child));
while (child) {
PRUint16 type;
child->GetNodeType(&type);
if (nsIDOMNode::ELEMENT_NODE == type) {
return PR_TRUE;
}
nsCOMPtr<nsIDOMNode> temp = child;
temp->GetNextSibling(getter_AddRefs(child));
}
return PR_FALSE;
}
void
nsSOAPUtils::GetInheritedEncodingStyle(nsIDOMElement* aEntry,
char** aEncodingStyle)
{
nsCOMPtr<nsIDOMNode> node = aEntry;
*aEncodingStyle = nsnull;
while (node) {
nsAutoString value;
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
@ -116,12 +145,13 @@ nsSOAPUtils::GetInheritedEncodingStyle(nsIDOMElement* aEntry,
value);
if (value.Length() > 0) {
*aEncodingStyle = value.ToNewCString();
break;
return;
}
}
nsCOMPtr<nsIDOMNode> temp = node;
temp->GetParentNode(getter_AddRefs(node));
}
*aEncodingStyle = nsCRT::strdup(kSOAPEncodingURI);
}
JSContext*
@ -212,7 +242,8 @@ nsSOAPUtils::ConvertValueToJSVal(JSContext* aContext,
double data;
dub->GetData(&data);
*vp = DOUBLE_TO_JSVAL((jsdouble)data);
double* dataPtr = JS_NewDouble(aContext, (jsdouble)data);
*vp = DOUBLE_TO_JSVAL(dataPtr);
break;
}
@ -225,7 +256,8 @@ nsSOAPUtils::ConvertValueToJSVal(JSContext* aContext,
float data;
flt->GetData(&data);
*vp = DOUBLE_TO_JSVAL((jsdouble)data);
double* dataPtr = JS_NewDouble(aContext, (jsdouble)data);
*vp = DOUBLE_TO_JSVAL(dataPtr);
break;
}
@ -277,9 +309,37 @@ nsSOAPUtils::ConvertValueToJSVal(JSContext* aContext,
case nsISOAPParameter::PARAMETER_TYPE_ARRAY:
{
// XXX Can't (easily) convert a native nsISupportsArray
// to a script array.
return NS_ERROR_NOT_IMPLEMENTED;
nsCOMPtr<nsISupportsArray> array = do_QueryInterface(aValue);
if (!array) return NS_ERROR_FAILURE;
JSObject* arrayobj = JS_NewArrayObject(aContext, 0, nsnull);
if (!arrayobj) return NS_ERROR_FAILURE;
PRUint32 index, count;
array->Count(&count);
for (index = 0; index < count; index++) {
nsCOMPtr<nsISupports> isup = getter_AddRefs(array->ElementAt(index));
nsCOMPtr<nsISOAPParameter> param = do_QueryInterface(isup);
if (!param) return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports> paramVal;
JSObject* paramObj;
PRInt32 paramType;
param->GetValueAndType(getter_AddRefs(paramVal), &paramType);
param->GetJSValue(&paramObj);
jsval val;
nsresult rv = ConvertValueToJSVal(aContext, paramVal, paramObj,
paramType, &val);
if (NS_FAILED(rv)) return rv;
JS_SetElement(aContext, arrayobj, (jsint)index, &val);
}
*vp = OBJECT_TO_JSVAL(arrayobj);
break;
}
case nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_ARRAY:

Просмотреть файл

@ -34,6 +34,7 @@ public:
nsIDOMElement** aElement);
static void GetElementTextContent(nsIDOMElement* aElement,
nsString& aText);
static PRBool HasChildElements(nsIDOMElement* aElement);
static void GetInheritedEncodingStyle(nsIDOMElement* aEntry,
char** aEncodingStyle);
static JSContext* GetSafeContext();
@ -51,6 +52,12 @@ public:
static const char* kSOAPEnvURI;
static const char* kSOAPEncodingURI;
static const char* kSOAPEnvPrefix;
static const char* kSOAPEncodingPrefix;
static const char* kXSIURI;
static const char* kXSDURI;
static const char* kXSIPrefix;
static const char* kXSDPrefix;
static const char* kEncodingStyleAttribute;
static const char* kEnvelopeTagName;
static const char* kHeaderTagName;

Просмотреть файл

@ -123,13 +123,12 @@ interface nsISOAPCall : nsISupports {
/**
* The script-only method for setting the list of parameters to
* include in the SOAP call.
*
* @param parameters The expectation is that this parameter is either a
* JavaScript array that holds the nsISOAPParameter
* instances or a single nsISOAPParameter.
* include in the SOAP call. Despite what the idl implies, this
* method takes an arbitrary number of arguments. Each is either
* a SOAPParameter object or a JavaScript value which will be
* converted to an unnamed SOAPParameter.
*/
void setParameters(in nsISupports parameters);
void setParameters();
/**
* A script-only method for setting the list of parameters, where

Просмотреть файл

@ -40,7 +40,8 @@ interface nsISOAPEncoder : nsISupports {
*
*/
nsISOAPParameter elementToParameter(in nsIDOMElement element,
in string encodingStyle);
in string encodingStyle,
in long hintType);
};
%{ C++

Просмотреть файл

@ -70,19 +70,20 @@ interface nsISOAPParameter : nsISupports {
* </ul>
* </p>
*/
const long PARAMETER_TYPE_NULL = 0;
const long PARAMETER_TYPE_VOID = 1;
const long PARAMETER_TYPE_STRING = 2;
const long PARAMETER_TYPE_BOOLEAN = 3;
const long PARAMETER_TYPE_DOUBLE = 4;
const long PARAMETER_TYPE_FLOAT = 5;
const long PARAMETER_TYPE_LONG = 6;
const long PARAMETER_TYPE_INT = 7;
const long PARAMETER_TYPE_SHORT = 8;
const long PARAMETER_TYPE_BYTE = 9;
const long PARAMETER_TYPE_ARRAY = 10;
const long PARAMETER_TYPE_JAVASCRIPT_ARRAY = 11;
const long PARAMETER_TYPE_JAVASCRIPT_OBJECT = 12;
const long PARAMETER_TYPE_UNKNOWN = 0;
const long PARAMETER_TYPE_NULL = 1;
const long PARAMETER_TYPE_VOID = 2;
const long PARAMETER_TYPE_STRING = 3;
const long PARAMETER_TYPE_BOOLEAN = 4;
const long PARAMETER_TYPE_DOUBLE = 5;
const long PARAMETER_TYPE_FLOAT = 6;
const long PARAMETER_TYPE_LONG = 7;
const long PARAMETER_TYPE_INT = 8;
const long PARAMETER_TYPE_SHORT = 9;
const long PARAMETER_TYPE_BYTE = 10;
const long PARAMETER_TYPE_ARRAY = 11;
const long PARAMETER_TYPE_JAVASCRIPT_ARRAY = 12;
const long PARAMETER_TYPE_JAVASCRIPT_OBJECT = 13;
/**
* An optional encodingStyle specifically for this parameter. The
@ -119,17 +120,32 @@ interface nsISOAPParameter : nsISupports {
[noscript] void setValueAndType(in nsISupports value, in long type);
/**
* <p>The getter is for native and script callers. For native callers,
* the interface implemented by the returned value depends on the
* Native (non-script) method for getting the value and type of a parameter.
* The interface implemented by the <code>value</code> parameter
* depends on the value of <code>type</code> parameter. Additional
* details can be found in the descriptions for the type constants.
*
* @param value Out parameter returning the value of the parameter.
* Either NULL or an object that implements an interface
* specified by the <code>type</code> parameter.
* @param type Out parameter returning the type of the parameter. See
* the description of the type contants for details.
*/
[noscript] void getValueAndType(out nsISupports value, out long type);
/**
* <p>The getter is for native and script callers (despite the
* [noscript] qualification). For native callers, the interface
* implemented by the returned value depends on the
* <code>type</code> attribute as detailed in the description of the
* type constants. For script callers, the value returned is either
* a string, boolean, double, integer, Array or object.</p>
* <p>Even though the attribute is readonly in IDL, script callers can
* set it (native callers should use the <code>setValueAndType</code>
* method). For script callers, the value can be either a string,
* boolean, double, integer, Array or object.
* a string, boolean, double, integer, Array or object.</p>
* <p>The setter is for script callers only. Native callers should
* use the <code>setValueAndType</code> method). For script callers,
* the value can be either a string, boolean, double, integer, Array
* or object.
*/
readonly attribute nsISupports value;
[noscript] attribute nsISupports value;
/**
* Used by native callers (SOAP encoders, for example) to retrieve
@ -145,6 +161,6 @@ interface nsISOAPParameter : nsISupports {
{ /* 87d21ec2-539d-11d4-9a59-00104bdf5339 */ \
0x87d21ec2, 0x539d, 0x11d4, \
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
#define NS_SOAPCPARAMETER_PROGID \
#define NS_SOAPPARAMETER_PROGID \
"component://netscape/xmlextras/soap/parameter"
%}

Просмотреть файл

@ -36,7 +36,7 @@ interface nsISOAPTransportListener : nsISupports {
* @param result The call result
*/
void handleResponse(in nsIDOMDocument document,
in unsigned long status,
in nsresult result);
in unsigned long status,
in nsresult result);
};

Просмотреть файл

@ -36,6 +36,7 @@ CPPSRCS = \
nsSOAPFault.cpp \
nsSOAPParameter.cpp \
nsDefaultSOAPEncoder.cpp \
nsHTTPSOAPTransport.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a

Просмотреть файл

@ -33,6 +33,7 @@ CPPSRCS= \
nsSOAPFault.cpp \
nsSOAPParameter.cpp \
nsDefaultSOAPEncoder.cpp \
nsHTTPSOAPTransport.cpp \
$(NULL)
@ -43,6 +44,7 @@ CPP_OBJS= \
.\$(OBJDIR)\nsSOAPFault.obj \
.\$(OBJDIR)\nsSOAPParameter.obj \
.\$(OBJDIR)\nsDefaultSOAPEncoder.obj \
.\$(OBJDIR)\nsHTTPSOAPTransport.obj \
$(NULL)
EXPORTS = \

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -24,6 +24,8 @@
#define nsDefaultSOAPEncoder_h__
#include "nsISOAPEncoder.h"
#include "nsISupportsArray.h"
#include "jsapi.h"
class nsDefaultSOAPEncoder : public nsISOAPEncoder {
public:
@ -34,6 +36,35 @@ public:
// nsISOAPEncoder
NS_DECL_NSISOAPENCODER
protected:
nsresult EncodeParameter(nsISOAPParameter* parameter,
nsIDOMDocument* document,
nsIDOMElement** element);
nsresult SerializeSupportsArray(nsISupportsArray* array,
nsIDOMElement* element,
nsIDOMDocument* document);
nsresult SerializeJavaScriptArray(JSObject* arrayobj,
nsIDOMElement* element,
nsIDOMDocument* document);
nsresult SerializeJavaScriptObject(JSObject* obj,
nsIDOMElement* element,
nsIDOMDocument* document);
nsresult SerializeParameterValue(nsISOAPParameter* parameter,
nsIDOMElement* element,
nsIDOMDocument* document);
nsresult DecodeParameter(nsIDOMElement* element,
PRInt32 type,
nsISOAPParameter **_retval);
nsresult DeserializeSupportsArray(nsIDOMElement *element,
nsISupportsArray **_retval);
nsresult DeserializeJavaScriptObject(nsIDOMElement *element,
JSObject** obj);
nsresult DeserializeParameter(nsIDOMElement *element,
PRInt32 type,
nsISOAPParameter **_retval);
};
#define NS_DEFAULTSOAPENCODER_CID \

Просмотреть файл

@ -0,0 +1,133 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsHTTPSOAPTransport.h"
#include "nsIComponentManager.h"
#include "nsIDOMDocument.h"
nsHTTPSOAPTransport::nsHTTPSOAPTransport()
{
NS_INIT_ISUPPORTS();
}
nsHTTPSOAPTransport::~nsHTTPSOAPTransport()
{
}
NS_IMPL_ISUPPORTS2(nsHTTPSOAPTransport, nsISOAPTransport, nsIDOMEventListener)
/* boolean canDoSync (); */
NS_IMETHODIMP
nsHTTPSOAPTransport::CanDoSync(PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval = PR_TRUE;
return NS_OK;
}
/* nsIDOMDocument syncCall (in string url, in string action, in nsIDOMDocument messageDocument); */
NS_IMETHODIMP
nsHTTPSOAPTransport::SyncCall(const char *url,
const char *action,
nsIDOMDocument *messageDocument,
nsIDOMDocument **_retval)
{
NS_ENSURE_ARG(url);
NS_ENSURE_ARG(messageDocument);
NS_ENSURE_ARG_POINTER(_retval);
nsresult rv;
nsCOMPtr<nsIXMLHttpRequest> request;
request = do_CreateInstance(NS_XMLHTTPREQUEST_PROGID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (action) {
request->SetRequestHeader("SOAPAction", action);
}
rv = request->OpenRequest("POST", url, PR_FALSE, nsnull, nsnull);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = request->Send(messageDocument);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = request->GetResponseXML(_retval);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
return NS_OK;
}
/* void asyncCall (in string url, in string action, in nsIDOMDocument messageDocument, in nsISOAPTransportListener listener); */
NS_IMETHODIMP
nsHTTPSOAPTransport::AsyncCall(const char *url,
const char *action,
nsIDOMDocument *messageDocument,
nsISOAPTransportListener *listener)
{
NS_ENSURE_ARG(url);
NS_ENSURE_ARG(messageDocument);
nsresult rv;
mRequest = do_CreateInstance(NS_XMLHTTPREQUEST_PROGID, &rv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (action) {
mRequest->SetRequestHeader("SOAPAction", action);
}
rv = mRequest->OpenRequest("POST", url, PR_TRUE, nsnull, nsnull);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
mListener = listener;
mRequest->AddEventListener("load",
NS_STATIC_CAST(nsIDOMEventListener*, this));
mRequest->AddEventListener("error",
NS_STATIC_CAST(nsIDOMEventListener*, this));
rv = mRequest->Send(messageDocument);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
return NS_OK;
}
nsresult
nsHTTPSOAPTransport::HandleEvent(nsIDOMEvent* aEvent)
{
nsCOMPtr<nsIDOMDocument> document;
PRUint32 status;
mRequest->GetResponseXML(getter_AddRefs(document));
mRequest->GetStatus(&status);
if (mListener) {
// XXX If this is an error, we need to pass in NS_ERROR_FAILURE
mListener->HandleResponse(document, status, NS_OK);
mListener = 0;
}
mRequest = 0;
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsHTTPSOAPTransport_h__
#define nsHTTPSOAPTransport_h__
#include "nsISOAPTransport.h"
#include "nsIXMLHttpRequest.h"
#include "nsIDOMEventListener.h"
#include "nsISOAPTransportListener.h"
#include "nsCOMPtr.h"
class nsHTTPSOAPTransport : public nsISOAPTransport,
public nsIDOMEventListener
{
public:
nsHTTPSOAPTransport();
virtual ~nsHTTPSOAPTransport();
NS_DECL_ISUPPORTS
// nsISOAPTransport
NS_DECL_NSISOAPTRANSPORT
// nsIDOMEventListener
virtual nsresult HandleEvent(nsIDOMEvent* aEvent);
protected:
nsCOMPtr<nsIXMLHttpRequest> mRequest;
nsCOMPtr<nsISOAPTransportListener> mListener;
};
#define NS_HTTPSOAPTRANSPORT_CID \
{ /* d852ade0-5823-11d4-9a62-00104bdf5339 */ \
0xd852ade0, 0x5823, 0x11d4, \
{0x9a, 0x62, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
#define NS_HTTPSOAPTRANSPORT_PROGID NS_SOAPTRANSPORT_PROGID_PREFIX "http"
#endif

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsSOAPCall.h"
#include "nsSOAPResponse.h"
#include "nsSOAPParameter.h"
#include "nsSOAPUtils.h"
#include "nsCRT.h"
#include "jsapi.h"
@ -158,7 +159,7 @@ NS_IMPL_ISUPPORTS3(nsSOAPCall,
nsISOAPTransportListener)
static const char* kEmptySOAPDocStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
static const char* kEmptySOAPDocStr = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">"
"<SOAP-ENV:Header>"
"</SOAP-ENV:Header>"
"<SOAP-ENV:Body>"
@ -320,7 +321,7 @@ nsSOAPCall::CreateBodyEntry(PRBool aNewParameters)
// If there is, we're going to replace it, but preserve its
// children.
if (entry) {
if (oldEntry) {
// Remove the old entry from the body
mBodyElement->RemoveChild(oldEntry, getter_AddRefs(dummy));
@ -580,8 +581,8 @@ NS_IMETHODIMP nsSOAPCall::SetSOAPParameters(nsISOAPParameter **parameters, PRUin
return NS_OK;
}
/* void setParameters (in nsISupports parameters); */
NS_IMETHODIMP nsSOAPCall::SetParameters(nsISupports *parameters)
/* void setParameters (); */
NS_IMETHODIMP nsSOAPCall::SetParameters()
{
nsresult rv;
@ -595,69 +596,65 @@ NS_IMETHODIMP nsSOAPCall::SetParameters(nsISupports *parameters)
if (!mParameters) return NS_ERROR_OUT_OF_MEMORY;
}
// If it's a single parameter, just add it to the list
nsCOMPtr<nsISOAPParameter> singleParam = do_QueryInterface(parameters);
if (singleParam) {
mParameters->AppendElement(singleParam);
nsCOMPtr<nsIXPCNativeCallContext> cc;
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
if(NS_SUCCEEDED(rv)) {
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
}
else {
nsCOMPtr<nsIXPCNativeCallContext> cc;
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
if(NS_SUCCEEDED(rv)) {
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
}
// This should only be called from script
if (NS_FAILED(rv) || !cc) {
return NS_ERROR_FAILURE;
}
PRUint32 argc;
rv = cc->GetArgc(&argc);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
jsval* argv;
rv = cc->GetArgvPtr(&argv);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// For each parameter to this method
PRUint32 index;
for (index = 0; index < argc; index++) {
nsCOMPtr<nsISOAPParameter> param;
jsval val = argv[index];
// Otherwise see if it's a JSObject
if (NS_SUCCEEDED(rv) && cc) {
nsCOMPtr<nsIXPConnectJSObjectHolder> jsobjholder = do_QueryInterface(parameters);
if (jsobjholder) {
JSObject* arrayobj;
rv = jsobjholder->GetJSObject(&arrayobj);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// First check if it's a parameter
if (JSVAL_IS_OBJECT(val)) {
JSObject* paramobj;
paramobj = JSVAL_TO_OBJECT(val);
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
// We expect a JS array
if (!JS_IsArrayObject(cx, arrayobj)) {
return NS_ERROR_INVALID_ARG;
}
jsuint index, count;
if (!JS_GetArrayLength(cx, arrayobj, &count)) {
return NS_ERROR_INVALID_ARG;
}
// For each element in the array
for (index = 0; index < count; index++) {
jsval val;
JSObject* paramobj;
if (!JS_GetElement(cx, arrayobj, (jsint)index, &val)) {
return NS_ERROR_FAILURE;
}
// Make sure it's an object
if (!JSVAL_IS_OBJECT(val)) return NS_ERROR_INVALID_ARG;
paramobj = JSVAL_TO_OBJECT(val);
// It should be a wrapped native
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
xpc->GetWrappedNativeOfJSObject(cx, paramobj, getter_AddRefs(wrapper));
if (!wrapper) return NS_ERROR_INVALID_ARG;
// Get the native and make sure it's a SOAPParameter
nsCOMPtr<nsISupports> isup;
wrapper->GetNative(getter_AddRefs(isup));
if (!isup) return NS_ERROR_INVALID_ARG;
nsCOMPtr<nsISOAPParameter> param = do_QueryInterface(isup);
if (!param) return NS_ERROR_INVALID_ARG;
mParameters->AppendElement(param);
// Check if it's a wrapped native
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
xpc->GetWrappedNativeOfJSObject(cx, paramobj, getter_AddRefs(wrapper));
if (wrapper) {
// Get the native and see if it's a SOAPParameter
nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native));
if (native) {
param = do_QueryInterface(native);
}
}
}
// Otherwise create a new parameter with the value
if (!param) {
nsSOAPParameter* newparam = new nsSOAPParameter();
if (!newparam) return NS_ERROR_OUT_OF_MEMORY;
param = (nsISOAPParameter*)newparam;
rv = newparam->SetValue(cx, val);
if (NS_FAILED(rv)) return rv;
}
mParameters->AppendElement(param);
}
if (HasBodyEntry()) {

Просмотреть файл

@ -168,3 +168,49 @@ NS_IMETHODIMP nsSOAPFault::GetDetail(nsIDOMElement * *aDetail)
}
return NS_OK;
}
static const char* kAllAccess = "AllAccess";
/* string canCreateWrapper (in nsIIDPtr iid); */
NS_IMETHODIMP
nsSOAPFault::CanCreateWrapper(const nsIID * iid, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsISOAPFault))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
NS_IMETHODIMP
nsSOAPFault::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsISOAPFault))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsSOAPFault::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsISOAPFault))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
NS_IMETHODIMP
nsSOAPFault::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
{
if (iid->Equals(NS_GET_IID(nsISOAPFault))) {
*_retval = nsCRT::strdup(kAllAccess);
}
return NS_OK;
}

Просмотреть файл

@ -29,6 +29,7 @@ nsSOAPParameter::nsSOAPParameter()
{
NS_INIT_ISUPPORTS();
mType = PARAMETER_TYPE_NULL;
mJSValue = nsnull;
JSContext* cx;
cx = nsSOAPUtils::GetSafeContext();
if (cx) {
@ -45,7 +46,11 @@ nsSOAPParameter::~nsSOAPParameter()
}
}
NS_IMPL_ISUPPORTS2(nsSOAPParameter, nsISOAPParameter, nsISecurityCheckedComponent)
NS_IMPL_ISUPPORTS4(nsSOAPParameter,
nsISOAPParameter,
nsISecurityCheckedComponent,
nsIXPCScriptable,
nsIJSNativeInitializer)
/* attribute string encodingStyleURI; */
NS_IMETHODIMP nsSOAPParameter::GetEncodingStyleURI(char * *aEncodingStyleURI)
@ -112,46 +117,48 @@ NS_IMETHODIMP nsSOAPParameter::SetValueAndType(nsISupports *value, PRInt32 type)
return NS_OK;
}
/* readonly attribute nsISupports value; */
NS_IMETHODIMP nsSOAPParameter::GetValue(nsISupports * *aValue)
/* [noscript] void getValueAndType (out nsISupports value, out long type); */
NS_IMETHODIMP nsSOAPParameter::GetValueAndType(nsISupports **value, PRInt32 *type)
{
NS_ENSURE_ARG_POINTER(aValue);
nsresult rv;
NS_ENSURE_ARG_POINTER(value);
NS_ENSURE_ARG_POINTER(type);
// Check if this is a script or native call
nsCOMPtr<nsIXPCNativeCallContext> cc;
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
if(NS_SUCCEEDED(rv)) {
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
}
// If this is a script call
if (NS_SUCCEEDED(rv) && cc) {
JSContext* cx;
rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
jsval val;
rv = nsSOAPUtils::ConvertValueToJSVal(cx, mValue, mJSValue, mType, &val);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
jsval* vp;
rv = cc->GetRetValPtr(&vp);
if (NS_SUCCEEDED(rv)) {
*vp = val;
cc->SetReturnValueWasSet(JS_TRUE);
}
}
else {
*aValue = mValue;
NS_IF_ADDREF(*aValue);
}
*value = mValue;
NS_IF_ADDREF(*value);
*type = mType;
return NS_OK;
}
// We can't make this a setter in xpidl without a variant type.
// For now, use nsIXPCScriptable to do the setting.
/* attribute nsISupports value; */
// We can't use this attribute for script calls without a variant type
// in xpidl. For now, use nsIXPCScriptable to implement.
NS_IMETHODIMP nsSOAPParameter::GetValue(nsISupports * *aValue)
{
NS_ENSURE_ARG_POINTER(aValue);
*aValue = mValue;
NS_IF_ADDREF(*aValue);
return NS_OK;
}
NS_IMETHODIMP
nsSOAPParameter::SetValue(nsISupports* value)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP nsSOAPParameter::GetValue(JSContext* aContext,
jsval* aValue)
{
return nsSOAPUtils::ConvertValueToJSVal(aContext,
mValue,
mJSValue,
mType,
aValue);
}
NS_IMETHODIMP nsSOAPParameter::SetValue(JSContext* aContext,
jsval aValue)
{
@ -171,11 +178,27 @@ NS_IMETHODIMP nsSOAPParameter::GetJSValue(JSObject * *aJSValue)
return NS_OK;
}
NS_IMETHODIMP
nsSOAPParameter::Initialize(JSContext *cx, JSObject *obj,
PRUint32 argc, jsval *argv)
{
if (argc > 0) {
JSString* namestr = JS_ValueToString(cx, argv[0]);
if (namestr) {
SetName(NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(namestr)));
if (argc > 1) {
SetValue(cx, argv[1]);
}
}
}
return NS_OK;
}
XPC_IMPLEMENT_IGNORE_CREATE(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_GETFLAGS(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_LOOKUPPROPERTY(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_DEFINEPROPERTY(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_GETPROPERTY(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_GETATTRIBUTES(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_SETATTRIBUTES(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_DELETEPROPERTY(nsSOAPParameter)
@ -184,8 +207,30 @@ XPC_IMPLEMENT_IGNORE_ENUMERATE(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_CHECKACCESS(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_CALL(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_CONSTRUCT(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_HASINSTANCE(nsSOAPParameter)
XPC_IMPLEMENT_IGNORE_FINALIZE(nsSOAPParameter)
NS_IMETHODIMP
nsSOAPParameter::GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
*retval = JS_TRUE;
jsval val;
if (JS_IdToValue(cx, id, &val)) {
if (JSVAL_IS_STRING(val)) {
JSString* str = JSVAL_TO_STRING(val);
char* name = JS_GetStringBytes(str);
if (nsCRT::strcmp(name, "value") == 0) {
return GetValue(cx, vp);
}
}
}
return NS_OK;
}
NS_IMETHODIMP
nsSOAPParameter::SetProperty(JSContext *cx, JSObject *obj, jsid id,
jsval *vp, nsIXPConnectWrappedNative* wrapper,
@ -198,7 +243,7 @@ nsSOAPParameter::SetProperty(JSContext *cx, JSObject *obj, jsid id,
if (JSVAL_IS_STRING(val)) {
JSString* str = JSVAL_TO_STRING(val);
char* name = JS_GetStringBytes(str);
if (nsCRT::strcmp(name, "value")) {
if (nsCRT::strcmp(name, "value") == 0) {
return SetValue(cx, *vp);
}
}

Просмотреть файл

@ -27,12 +27,14 @@
#include "nsISOAPParameter.h"
#include "nsISecurityCheckedComponent.h"
#include "nsIXPCScriptable.h"
#include "nsIJSNativeInitializer.h"
#include "nsString.h"
#include "nsCOMPtr.h"
class nsSOAPParameter : public nsISOAPParameter,
public nsISecurityCheckedComponent,
public nsIXPCScriptable
public nsIXPCScriptable,
public nsIJSNativeInitializer
{
public:
nsSOAPParameter();
@ -49,9 +51,15 @@ public:
// nsIXPCScriptable
XPC_DECLARE_IXPCSCRIPTABLE
NS_IMETHODIMP GetValue(JSContext* aContext,
jsval* aValue);
NS_IMETHODIMP SetValue(JSContext* aContext,
jsval aValue);
// nsIJSNativeInitializer
NS_IMETHOD Initialize(JSContext *cx, JSObject *obj,
PRUint32 argc, jsval *argv);
protected:
nsCString mEncodingStyleURI;
nsString mName;

Просмотреть файл

@ -31,6 +31,7 @@
nsSOAPResponse::nsSOAPResponse(nsIDOMDocument* aEnvelopeDocument)
{
NS_INIT_ISUPPORTS();
mEnvelopeDocument = aEnvelopeDocument;
if (mEnvelopeDocument) {
nsCOMPtr<nsIDOMElement> element;
@ -193,10 +194,15 @@ NS_IMETHODIMP nsSOAPResponse::GetReturnValue(nsISOAPParameter * *aReturnValue)
*aReturnValue = nsnull;
if (mResultElement) {
// The first child element is assumed to be the returned
// value
nsCOMPtr<nsIDOMElement> value;
nsSOAPUtils::GetFirstChildElement(mResultElement, getter_AddRefs(value));
// Get the inherited encoding style starting from the
// body entry.
// value
char* encodingStyle;
nsSOAPUtils::GetInheritedEncodingStyle(mResultElement,
nsSOAPUtils::GetInheritedEncodingStyle(value,
&encodingStyle);
if (!encodingStyle) {
@ -216,8 +222,9 @@ NS_IMETHODIMP nsSOAPResponse::GetReturnValue(nsISOAPParameter * *aReturnValue)
// Convert the result element to a parameter
nsCOMPtr<nsISOAPParameter> param;
rv = encoder->ElementToParameter(mResultElement,
rv = encoder->ElementToParameter(value,
encodingStyle,
nsISOAPParameter::PARAMETER_TYPE_UNKNOWN,
getter_AddRefs(param));
nsMemory::Free(encodingStyle);
if (NS_FAILED(rv)) return rv;

Просмотреть файл

@ -29,14 +29,25 @@
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsXPIDLString.h"
#include "nsISupportsArray.h"
const char* nsSOAPUtils::kSOAPEnvURI = "http://schemas.xmlsoap.org/soap/envelope/";
const char* nsSOAPUtils::kSOAPEncodingURI = "http://schemas.xmlsoap.org/soap/encoding/";
const char* nsSOAPUtils::kSOAPEnvPrefix = "SOAP-ENV";
const char* nsSOAPUtils::kSOAPEncodingPrefix = "SOAP-ENC";
const char* nsSOAPUtils::kXSIURI = "http://www.w3.org/1999/XMLSchema-instance";
const char* nsSOAPUtils::kXSDURI = "http://www.w3.org/1999/XMLSchema";
const char* nsSOAPUtils::kXSIPrefix = "xsi";
const char* nsSOAPUtils::kXSDPrefix = "xsd";
const char* nsSOAPUtils::kEncodingStyleAttribute = "encodingStyle";
const char* nsSOAPUtils::kEnvelopeTagName = "Envelope";
const char* nsSOAPUtils::kHeaderTagName = "Header";
const char* nsSOAPUtils::kBodyTagName = "Body";
const char* nsSOAPUtils::kFaultTagName = "Fault";
const char* nsSOAPUtils::kFaultCodeTagName = "faultcode";
const char* nsSOAPUtils::kFaultStringTagName = "faultstring";
const char* nsSOAPUtils::kFaultActorTagName = "faultactor";
const char* nsSOAPUtils::kFaultDetailTagName = "detail";
void
nsSOAPUtils::GetFirstChildElement(nsIDOMElement* aParent,
@ -82,31 +93,49 @@ void
nsSOAPUtils::GetElementTextContent(nsIDOMElement* aElement,
nsString& aText)
{
nsCOMPtr<nsIDOMNode> sibling;
nsCOMPtr<nsIDOMNode> child;
aText.Truncate();
aElement->GetNextSibling(getter_AddRefs(sibling));
while (sibling) {
aElement->GetFirstChild(getter_AddRefs(child));
while (child) {
PRUint16 type;
sibling->GetNodeType(&type);
child->GetNodeType(&type);
if (nsIDOMNode::TEXT_NODE == type) {
nsCOMPtr<nsIDOMText> text = do_QueryInterface(sibling);
nsCOMPtr<nsIDOMText> text = do_QueryInterface(child);
nsAutoString data;
text->GetData(data);
aText.Append(data);
}
nsCOMPtr<nsIDOMNode> temp = sibling;
temp->GetNextSibling(getter_AddRefs(sibling));
nsCOMPtr<nsIDOMNode> temp = child;
temp->GetNextSibling(getter_AddRefs(child));
}
}
PRBool
nsSOAPUtils::HasChildElements(nsIDOMElement* aElement)
{
nsCOMPtr<nsIDOMNode> child;
aElement->GetFirstChild(getter_AddRefs(child));
while (child) {
PRUint16 type;
child->GetNodeType(&type);
if (nsIDOMNode::ELEMENT_NODE == type) {
return PR_TRUE;
}
nsCOMPtr<nsIDOMNode> temp = child;
temp->GetNextSibling(getter_AddRefs(child));
}
return PR_FALSE;
}
void
nsSOAPUtils::GetInheritedEncodingStyle(nsIDOMElement* aEntry,
char** aEncodingStyle)
{
nsCOMPtr<nsIDOMNode> node = aEntry;
*aEncodingStyle = nsnull;
while (node) {
nsAutoString value;
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
@ -116,12 +145,13 @@ nsSOAPUtils::GetInheritedEncodingStyle(nsIDOMElement* aEntry,
value);
if (value.Length() > 0) {
*aEncodingStyle = value.ToNewCString();
break;
return;
}
}
nsCOMPtr<nsIDOMNode> temp = node;
temp->GetParentNode(getter_AddRefs(node));
}
*aEncodingStyle = nsCRT::strdup(kSOAPEncodingURI);
}
JSContext*
@ -212,7 +242,8 @@ nsSOAPUtils::ConvertValueToJSVal(JSContext* aContext,
double data;
dub->GetData(&data);
*vp = DOUBLE_TO_JSVAL((jsdouble)data);
double* dataPtr = JS_NewDouble(aContext, (jsdouble)data);
*vp = DOUBLE_TO_JSVAL(dataPtr);
break;
}
@ -225,7 +256,8 @@ nsSOAPUtils::ConvertValueToJSVal(JSContext* aContext,
float data;
flt->GetData(&data);
*vp = DOUBLE_TO_JSVAL((jsdouble)data);
double* dataPtr = JS_NewDouble(aContext, (jsdouble)data);
*vp = DOUBLE_TO_JSVAL(dataPtr);
break;
}
@ -277,9 +309,37 @@ nsSOAPUtils::ConvertValueToJSVal(JSContext* aContext,
case nsISOAPParameter::PARAMETER_TYPE_ARRAY:
{
// XXX Can't (easily) convert a native nsISupportsArray
// to a script array.
return NS_ERROR_NOT_IMPLEMENTED;
nsCOMPtr<nsISupportsArray> array = do_QueryInterface(aValue);
if (!array) return NS_ERROR_FAILURE;
JSObject* arrayobj = JS_NewArrayObject(aContext, 0, nsnull);
if (!arrayobj) return NS_ERROR_FAILURE;
PRUint32 index, count;
array->Count(&count);
for (index = 0; index < count; index++) {
nsCOMPtr<nsISupports> isup = getter_AddRefs(array->ElementAt(index));
nsCOMPtr<nsISOAPParameter> param = do_QueryInterface(isup);
if (!param) return NS_ERROR_FAILURE;
nsCOMPtr<nsISupports> paramVal;
JSObject* paramObj;
PRInt32 paramType;
param->GetValueAndType(getter_AddRefs(paramVal), &paramType);
param->GetJSValue(&paramObj);
jsval val;
nsresult rv = ConvertValueToJSVal(aContext, paramVal, paramObj,
paramType, &val);
if (NS_FAILED(rv)) return rv;
JS_SetElement(aContext, arrayobj, (jsint)index, &val);
}
*vp = OBJECT_TO_JSVAL(arrayobj);
break;
}
case nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_ARRAY:

Просмотреть файл

@ -34,6 +34,7 @@ public:
nsIDOMElement** aElement);
static void GetElementTextContent(nsIDOMElement* aElement,
nsString& aText);
static PRBool HasChildElements(nsIDOMElement* aElement);
static void GetInheritedEncodingStyle(nsIDOMElement* aEntry,
char** aEncodingStyle);
static JSContext* GetSafeContext();
@ -51,6 +52,12 @@ public:
static const char* kSOAPEnvURI;
static const char* kSOAPEncodingURI;
static const char* kSOAPEnvPrefix;
static const char* kSOAPEncodingPrefix;
static const char* kXSIURI;
static const char* kXSDURI;
static const char* kXSIPrefix;
static const char* kXSDPrefix;
static const char* kEncodingStyleAttribute;
static const char* kEnvelopeTagName;
static const char* kHeaderTagName;