зеркало из https://github.com/mozilla/pjs.git
Work in progress on SOAP call component
This commit is contained in:
Родитель
9032fabd4c
Коммит
6aa74b76ff
|
@ -0,0 +1,185 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMElement;
|
||||
interface nsISOAPParameter;
|
||||
interface nsISOAPResponse;
|
||||
|
||||
[scriptable, uuid(a8fefe40-52bc-11d4-9a57-000064657374)]
|
||||
interface nsISOAPCall : nsISupports {
|
||||
|
||||
/**
|
||||
* The DOM element representing the SOAP envelope itself. By default,
|
||||
* this element has a namespace declaration for the SOAP envelope
|
||||
* namespace defined in the SOAP specification. It also has an
|
||||
* <code>encodingStyle</code> attribute that corresponds to the
|
||||
* current encoding style for the call. The Envelope element also
|
||||
* has two children representing the SOAP header and body. DOM methods
|
||||
* may be used to add additional attributes to the envelope.
|
||||
*/
|
||||
readonly attribute nsIDOMElement envelope;
|
||||
|
||||
/**
|
||||
* A convenience attribute to obtain the DOM element representing the
|
||||
* SOAP header. DOM methods may be used to add header entries. By default
|
||||
* this element has no attributes or children. If this is still the case
|
||||
* at the point at which the call is invoked, the SOAP message will not
|
||||
* contain a header.
|
||||
*/
|
||||
readonly attribute nsIDOMElement header;
|
||||
|
||||
/**
|
||||
* A convenience attribute to obtain the DOM element representing the
|
||||
* SOAP body. DOM methods may be used to add additional attributes to
|
||||
* the body element. DOM methods may also be used to add body entries,
|
||||
* though the expectation is that in most cases the SOAP message will
|
||||
* contain a single body entry created as a result of invoking the
|
||||
* call with a method name and a set of parameters.
|
||||
*/
|
||||
readonly attribute nsIDOMElement body;
|
||||
|
||||
/**
|
||||
* The encodingStyle to be used for the envelope. This URI will be
|
||||
* specified in the SOAP message using the encodingStyle attribute
|
||||
* of the Envelope element.
|
||||
*/
|
||||
attribute string encodingStyleURI;
|
||||
|
||||
/**
|
||||
* The target object on which the method is being invoked. This URI
|
||||
* is used as the namespace to qualify the tagname of the element
|
||||
* that is the single body entry of the SOAP message.
|
||||
*
|
||||
* For example, if the <code>targetObjectURI</code> is
|
||||
* "urn:some-namespace" and the <code>methodName</code> is
|
||||
* GetLastTradePrice, the single body entry will be the
|
||||
* following element:
|
||||
* <code>
|
||||
* <m:GetLastTradePrice xmlns:m="urn:some-namespace">
|
||||
* ...
|
||||
* </code>
|
||||
*
|
||||
*/
|
||||
attribute string targetObjectURI;
|
||||
|
||||
/**
|
||||
* The name of the method being invoked. The methodName is used as
|
||||
* the tagname for the element that is the single body entry of the
|
||||
* SOAP message.
|
||||
*
|
||||
* For example, if the <code>targetObjectURI</code> is
|
||||
* "urn:some-namespace" and the <code>methodName</code> is
|
||||
* GetLastTradePrice, the single body entry will be the
|
||||
* following element:
|
||||
* <code>
|
||||
* <m:GetLastTradePrice xmlns:m="urn:some-namespace">
|
||||
* ...
|
||||
* </code>
|
||||
*/
|
||||
attribute wstring methodName;
|
||||
|
||||
/**
|
||||
* The URI to which the RPC call is made. This does not have to
|
||||
* match the <code>targetObjectURI</code>.
|
||||
*/
|
||||
attribute string destinationURI;
|
||||
|
||||
/**
|
||||
* An optional URI that can be used to add a SOAPAction HTTP
|
||||
* header field. If this attribute is NULL (the default case),
|
||||
* no SOAPAction header will be added.
|
||||
*/
|
||||
attribute string actionURI;
|
||||
|
||||
/**
|
||||
* Native (non-script) method to set the list of parameters to
|
||||
* include in the SOAP call.
|
||||
*
|
||||
* @param parameters The array of parameters to include in the call
|
||||
* @param count The number of parameters in the array
|
||||
*/
|
||||
[noscript] void setSOAPParameters([array, size_is(count)] in nsISOAPParameter parameters, in unsigned long count);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void setParameters(in nsISupports parameters);
|
||||
|
||||
/**
|
||||
* A script-only method for setting the list of parameters, where
|
||||
* the parameters are unnamed and are encoded using the default
|
||||
* encoding style. This method actually expects a variable number
|
||||
* of arguments, each representing an individual parameter - an
|
||||
* actual script type and not a nsISOAPParameter object. This is
|
||||
* purely a convenience for scripters who want unnamed parameters
|
||||
* and don't want to create an array of parameter objects.
|
||||
*/
|
||||
void setSimpleParameters();
|
||||
|
||||
/**
|
||||
* Synchronously make the SOAP call. At this point, the document
|
||||
* rooted by the Envelope element is serialized to form the body
|
||||
* of the SOAP message. The method returns only when we receive
|
||||
* a response (or a protocol error occurs). The expectation is that
|
||||
* at this point the <code>targetObjectURI</code>,
|
||||
* <code>methodName</code>, <code>destinationURI</code> and
|
||||
* parameters (if any) have been set. If this is not the case,
|
||||
* the methods throws and NS_ERROR_NOT_INITIALIZED error.
|
||||
*
|
||||
* @returns The SOAP response
|
||||
*/
|
||||
nsISOAPResponse invoke();
|
||||
|
||||
/**
|
||||
* Asynchronously makes the SOAP call. At this point, the document
|
||||
* rooted by the Envelope element is serialized to form the body
|
||||
* of the SOAP message. The method returns immediately, and the
|
||||
* listener is triggered when we eventually receive a response
|
||||
* (or a protocol error occurs). The expectation is that
|
||||
* at this point the <code>targetObjectURI</code>,
|
||||
* <code>methodName</code>, <code>destinationURI</code> and
|
||||
* parameters (if any) have been set. If this is not the case,
|
||||
* the methods throws and NS_ERROR_NOT_INITIALIZED error.
|
||||
*
|
||||
* @param listener For a native (non-script) invocation of this
|
||||
* method, this should be a nsISOAPResponseListener instance.
|
||||
* For a script invocation of this method, this
|
||||
* is expected to be a Function object.
|
||||
*/
|
||||
void asyncInvoke(in nsISupports listener);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPCALL_CID \
|
||||
{ /* 87d21ec0-539d-11d4-9a59-00104bdf5339 */ \
|
||||
0x87d21ec0, 0x539d, 0x11d4, \
|
||||
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_SOAPCALL_PROGID \
|
||||
"component://netscape/xmlextras/soap/call"
|
||||
%}
|
|
@ -0,0 +1,51 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMElement;
|
||||
interface nsIDOMDocument;
|
||||
interface nsISOAPParameter;
|
||||
|
||||
[scriptable, uuid(99ec6693-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPEncoder : nsISupports {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
nsIDOMElement parameterToElement(in nsISOAPParameter parameter,
|
||||
in string encodingStyle,
|
||||
in nsIDOMDocument document);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
nsISOAPParameter elementToParameter(in nsIDOMElement element,
|
||||
in string encodingStyle);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPENCODER_PROGID \
|
||||
"component://netscape/xmlextras/soap/encoder"
|
||||
#define NS_SOAPENCODER_PROGID_PREFIX NS_SOAPENCODER_PROGID "?encodingStyle="
|
||||
%}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMElement;
|
||||
|
||||
[scriptable, uuid(99ec6694-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPFault : nsISupports {
|
||||
/**
|
||||
* The DOM element representing the fault in the response SOAP message.
|
||||
*/
|
||||
readonly attribute nsIDOMElement element;
|
||||
|
||||
/**
|
||||
* The fault code
|
||||
*/
|
||||
readonly attribute wstring faultCode;
|
||||
|
||||
/**
|
||||
* The fault string
|
||||
*/
|
||||
readonly attribute wstring faultString;
|
||||
|
||||
/**
|
||||
* The fault actor if one was specified.
|
||||
*/
|
||||
readonly attribute wstring faultActor;
|
||||
|
||||
/**
|
||||
* The DOM element representing the fault details
|
||||
*/
|
||||
readonly attribute nsIDOMElement detail;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPFAULT_CID \
|
||||
{ /* 87d21ec1-539d-11d4-9a59-00104bdf5339 */ \
|
||||
0x87d21ec1, 0x539d, 0x11d4, \
|
||||
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_SOAPFAULT_PROGID \
|
||||
"component://netscape/xmlextras/soap/fault"
|
||||
%}
|
|
@ -0,0 +1,150 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
[ptr] native JSObjectPtr(JSObject);
|
||||
|
||||
[scriptable, uuid(99ec6690-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPParameter : nsISupports {
|
||||
|
||||
/**
|
||||
* <p>Possible values for the type of a Parameter object. Native
|
||||
* (non-script) callers must specify the type of a parameter
|
||||
* when setting the value. The list below indicates the native
|
||||
* type expected in each case. Both native and script callers
|
||||
* may query the type of the parameter. The list below also
|
||||
* indicates the native or script type passed back when the
|
||||
* value is retrieved.</p>
|
||||
* <p>Notes:
|
||||
* <ul>
|
||||
* <li><code>PARAMETER_TYPE_STRING</code> - The value is of type
|
||||
* nsISupportsWString for native callers, a JavaScript string
|
||||
* for script callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_BOOLEAN</code> - The value is of type
|
||||
* nsISupportsPRBool for native callers, a boolean for script
|
||||
* callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_DOUBLE</code> - The value is of type
|
||||
* nsISupportsDouble for native callers, a double for script
|
||||
* callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_FLOAT</code> - The value is of type
|
||||
* nsISupportsFloat for native callers, a double for script
|
||||
* callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_LONG</code> - The value is of type
|
||||
* nsISupportsPRInt64 for native callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_INT</code> - The value is of type
|
||||
* nsISupportsPRInt32 for native callers, an integer for
|
||||
* script callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_SHORT</code> - The value is of type
|
||||
* nsISupportsPRInt16 for native callers, an integer for
|
||||
* script callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_BYTE</code> - The value is of type
|
||||
* nsISupportsPRInt8 for native callers, an integer for script
|
||||
* callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_ARRAY</code> - The value is of type
|
||||
* nsISupportsArray for native callers (each element is itself
|
||||
* an instance of nsISOAPParameter).</li>
|
||||
* <li><code>PARAMETER_TYPE_JAVASCRIPT_ARRAY</code> - The value is
|
||||
* a JSObject that is an array.</li>
|
||||
* <li><code>PARAMETER_TYPE_JAVASCRIPT_OBJECT</code> - The value is
|
||||
* a generic JSObject.</li>
|
||||
* </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;
|
||||
|
||||
/**
|
||||
* An optional encodingStyle specifically for this parameter. The
|
||||
* default is to inherit the encodingStyle from the element parent
|
||||
* chain.
|
||||
*/
|
||||
attribute string encodingStyleURI;
|
||||
|
||||
/**
|
||||
* The name of the parameter. If the parameter is left unnamed, it
|
||||
* will be encoded using the element types defined in the SOAP-ENC
|
||||
* schema. For example, <code><SOAP-ENC:int>45</SOAP-ENC:int>
|
||||
*/
|
||||
attribute wstring name;
|
||||
|
||||
/**
|
||||
* The type of the parameter. See the descriptions for the type
|
||||
* constants for details.
|
||||
*/
|
||||
readonly attribute long type;
|
||||
|
||||
/**
|
||||
* Native (non-script) method for setting the value 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 The value of the parameter. Either NULL or an object
|
||||
* that implements an interface specified by the
|
||||
* <code>type</code> parameter.
|
||||
* @param type The type of the parameter. See the description of
|
||||
* the type contants for details.
|
||||
*/
|
||||
[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
|
||||
* <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.
|
||||
*/
|
||||
readonly attribute nsISupports value;
|
||||
|
||||
/**
|
||||
* Used by native callers (SOAP encoders, for example) to retrieve
|
||||
* the JSObject value if the <code>type</code> attribute is either
|
||||
* <code>PARAMETER_TYPE_JAVASCRIPT_ARRAY</code> or
|
||||
* <code>PARAMETER_TYPE_JAVASCRIPT_OBJECT</code>.
|
||||
*/
|
||||
[noscript] readonly attribute JSObjectPtr JSValue;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPPARAMETER_CID \
|
||||
{ /* 87d21ec2-539d-11d4-9a59-00104bdf5339 */ \
|
||||
0x87d21ec2, 0x539d, 0x11d4, \
|
||||
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_SOAPCPARAMETER_PROGID \
|
||||
"component://netscape/xmlextras/soap/parameter"
|
||||
%}
|
|
@ -0,0 +1,103 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMElement;
|
||||
interface nsISOAPParameter;
|
||||
interface nsISOAPFault;
|
||||
|
||||
[scriptable, uuid(99ec6691-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPResponse : nsISupports {
|
||||
|
||||
/**
|
||||
* The DOM element representing the SOAP envelope in the response.
|
||||
* DOM methods may be used to access attributes and children of this
|
||||
* element. While the element and it's subtree are not readonly,
|
||||
* the expectation is that they will not be modified.
|
||||
*/
|
||||
readonly attribute nsIDOMElement envelope;
|
||||
|
||||
/**
|
||||
* A convenience attribute to obtain the DOM element representing
|
||||
* the response envelope header, if one exists. NULL if no header
|
||||
* exists in the response.
|
||||
*/
|
||||
readonly attribute nsIDOMElement header;
|
||||
|
||||
/**
|
||||
* A convenience attribute to obtain the DOM element representing
|
||||
* the response envelope body. While DOM interfaces and methods may
|
||||
* be used to access body entries, the expectation is that the
|
||||
* <code>returnValue</code> property will be used if the response
|
||||
* represents the result of a RPC call.
|
||||
*/
|
||||
readonly attribute nsIDOMElement body;
|
||||
|
||||
/**
|
||||
* The status code returned by the underlying transport.
|
||||
*/
|
||||
readonly attribute unsigned long status;
|
||||
|
||||
/**
|
||||
* The target object on which the method was invoked. This URI
|
||||
* is generally used as the namespace to qualify the tagname of
|
||||
* the element that is the single body entry of the SOAP response.
|
||||
*/
|
||||
readonly attribute string targetObjectURI;
|
||||
|
||||
/**
|
||||
* The name of the method that was invoked. The methodName is used as
|
||||
* the tagname for the element that is the single body entry of the
|
||||
* SOAP message.
|
||||
*/
|
||||
readonly attribute string methodName;
|
||||
|
||||
/**
|
||||
* Did the response generate a fault?
|
||||
*
|
||||
* @returns Whether a fault was generated a not. If the return value
|
||||
* is <code>true</code>, the fault details can be obtained
|
||||
* from the <code>fault</code> property.
|
||||
*/
|
||||
boolean generatedFault();
|
||||
|
||||
/**
|
||||
* The fault returned in the response, if one was generated. NULL
|
||||
* if there was no fault.
|
||||
*/
|
||||
readonly attribute nsISOAPFault fault;
|
||||
|
||||
/**
|
||||
* The result from the first body entry in the response SOAP message.
|
||||
*/
|
||||
readonly attribute nsISOAPParameter returnValue;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPRESPONSE_CID \
|
||||
{ /* 87d21ec3-539d-11d4-9a59-00104bdf5339 */ \
|
||||
0x87d21ec3, 0x539d, 0x11d4, \
|
||||
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_SOAPRESPONSE_PROGID \
|
||||
"component://netscape/xmlextras/soap/response"
|
||||
%}
|
|
@ -0,0 +1,42 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsISOAPCall;
|
||||
interface nsISOAPResponse;
|
||||
|
||||
[scriptable, uuid(99ec6692-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPResponseListener : nsISupports {
|
||||
/**
|
||||
* This method is invoked when we receive an asynchronous response to
|
||||
* a SOAP message. The listener is registered as part of the original
|
||||
* asynchronous call invocation.
|
||||
*
|
||||
* @param response The decoded version of the response
|
||||
* @param call The SOAPCall object that triggered the response
|
||||
* @param result The result code from the call
|
||||
*/
|
||||
void handleResponse(in nsISOAPResponse response,
|
||||
in nsISOAPCall call,
|
||||
in nsresult result);
|
||||
};
|
|
@ -0,0 +1,44 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMDocument;
|
||||
interface nsISOAPTransportListener;
|
||||
|
||||
[scriptable, uuid(99ec6695-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPTransport : nsISupports {
|
||||
boolean canDoSync();
|
||||
nsIDOMDocument syncCall(in string url,
|
||||
in string action,
|
||||
in nsIDOMDocument messageDocument);
|
||||
void asyncCall(in string url,
|
||||
in string action,
|
||||
in nsIDOMDocument messageDocument,
|
||||
in nsISOAPTransportListener listener);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPTRANSPORT_PROGID \
|
||||
"component://netscape/xmlextras/soap/transport"
|
||||
#define NS_SOAPTRANSPORT_PROGID_PREFIX NS_SOAPTRANSPORT_PROGID "?protocol="
|
||||
%}
|
|
@ -0,0 +1,42 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMDocument;
|
||||
|
||||
[scriptable, uuid(99ec6696-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPTransportListener : nsISupports {
|
||||
/**
|
||||
* This method is invoked when an ansynchronous response is
|
||||
* completed. The listener is registered as part of the original
|
||||
* call to the transport.
|
||||
*
|
||||
* @param document The XML document that is the body of the response
|
||||
* @param status The protocol status returned
|
||||
* @param result The call result
|
||||
*/
|
||||
void handleResponse(in nsIDOMDocument document,
|
||||
in unsigned long status,
|
||||
in nsresult result);
|
||||
};
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#
|
||||
# The contents of this file are subject to the Mozilla 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/MPL/
|
||||
#
|
||||
# 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):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,46 @@
|
|||
#
|
||||
# The contents of this file are subject to the Mozilla 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/MPL/
|
||||
#
|
||||
# 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):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xmlextras
|
||||
LIBRARY_NAME = xmlextrassoap_s
|
||||
|
||||
CPPSRCS = \
|
||||
nsSOAPCall.cpp \
|
||||
nsSOAPResponse.cpp \
|
||||
nsSOAPUtils.cpp \
|
||||
nsSOAPFault.cpp \
|
||||
nsSOAPParameter.cpp \
|
||||
nsDefaultSOAPEncoder.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
# static lib.
|
||||
override NO_SHARED_LIB=1
|
||||
override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,71 @@
|
|||
/* -*- 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 "nsDefaultSOAPEncoder.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
|
||||
|
||||
nsDefaultSOAPEncoder::nsDefaultSOAPEncoder()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsDefaultSOAPEncoder::~nsDefaultSOAPEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsDefaultSOAPEncoder, nsISOAPEncoder)
|
||||
|
||||
/* nsIDOMElement parameterToElement (in nsISOAPParameter parameter, in string encodingStyle, in nsIDOMDocument document); */
|
||||
NS_IMETHODIMP
|
||||
nsDefaultSOAPEncoder::ParameterToElement(nsISOAPParameter *parameter,
|
||||
const char *encodingStyle,
|
||||
nsIDOMDocument *document,
|
||||
nsIDOMElement **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(parameter);
|
||||
NS_ENSURE_ARG(encodingStyle);
|
||||
NS_ENSURE_ARG(document);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
PRInt32 type;
|
||||
parameter->GetType(&type);
|
||||
|
||||
XPIDLString name;
|
||||
parameter->GetName(getter_Copies(name));
|
||||
|
||||
// If it's an unnamed parameter, we use the type names defined
|
||||
// by SOAP
|
||||
if (!name) {
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* nsISOAPParameter elementToParameter (in nsIDOMElement element, in string encodingStyle); */
|
||||
NS_IMETHODIMP
|
||||
nsDefaultSOAPEncoder::ElementToParameter(nsIDOMElement *element,
|
||||
const char *encodingStyle,
|
||||
nsISOAPParameter **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/* -*- 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 nsDefaultSOAPEncoder_h__
|
||||
#define nsDefaultSOAPEncoder_h__
|
||||
|
||||
#include "nsISOAPEncoder.h"
|
||||
|
||||
class nsDefaultSOAPEncoder : public nsISOAPEncoder {
|
||||
public:
|
||||
nsDefaultSOAPEncoder();
|
||||
virtual ~nsDefaultSOAPEncoder();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPEncoder
|
||||
NS_DECL_NSISOAPENCODER
|
||||
};
|
||||
|
||||
#define NS_DEFAULTSOAPENCODER_CID \
|
||||
{ /* 0b6e6ef0-56c4-11d4-9a5e-00104bdf5339 */ \
|
||||
0x0b6e6ef0, 0x56c4, 0x11d4, \
|
||||
{0x9a, 0x5e, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_DEFAULTSOAPENCODER_PROGID NS_SOAPENCODER_PROGID_PREFIX "http://schemas.xmlsoap.org/soap/encoding/"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,880 @@
|
|||
/* -*- 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 "nsSOAPCall.h"
|
||||
#include "nsSOAPResponse.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
#include "nsCRT.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsIDOMParser.h"
|
||||
#include "nsISOAPEncoder.h"
|
||||
#include "nsISOAPParameter.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
static NS_DEFINE_CID(kDOMParserCID, NS_DOMPARSER_CID);
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
/////////////////////////////////////////////
|
||||
|
||||
class nsScriptResponseListener : public nsISOAPResponseListener
|
||||
{
|
||||
public:
|
||||
nsScriptResponseListener(JSObject* aScopeObj, JSObject* aFunctionObj);
|
||||
~nsScriptResponseListener();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPResponseListener
|
||||
NS_DECL_NSISOAPRESPONSELISTENER
|
||||
|
||||
protected:
|
||||
JSObject* mScopeObj;
|
||||
JSObject* mFunctionObj;
|
||||
};
|
||||
|
||||
nsScriptResponseListener::nsScriptResponseListener(JSObject* aScopeObj,
|
||||
JSObject* aFunctionObj)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
// We don't have to add a GC root for the scope object
|
||||
// since we'll go away if it goes away
|
||||
mScopeObj = aScopeObj;
|
||||
mFunctionObj = aFunctionObj;
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
if (cx) {
|
||||
JS_AddNamedRoot(cx, &mFunctionObj, "nsSOAPCall");
|
||||
}
|
||||
}
|
||||
|
||||
nsScriptResponseListener::~nsScriptResponseListener()
|
||||
{
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
if (cx) {
|
||||
JS_RemoveRoot(cx, &mFunctionObj);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsScriptResponseListener,
|
||||
nsISOAPResponseListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptResponseListener::HandleResponse(nsISOAPResponse* aResponse,
|
||||
nsISOAPCall* aCall,
|
||||
nsresult aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetCurrentContext();
|
||||
if (!cx) {
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
}
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
if (!xpc) return NS_OK;
|
||||
|
||||
jsval params[3];
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
JSObject* obj;
|
||||
|
||||
// Get the JSObject wrapper for the response
|
||||
rv = xpc->WrapNative(cx, mScopeObj,
|
||||
aResponse, NS_GET_IID(nsISOAPResponse),
|
||||
getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv)) return NS_OK;
|
||||
|
||||
rv = holder->GetJSObject(&obj);
|
||||
if (!obj) return NS_OK;
|
||||
|
||||
params[0] = OBJECT_TO_JSVAL(obj);
|
||||
|
||||
// Get the JSObject wrapper for the call
|
||||
rv = xpc->WrapNative(cx, mScopeObj,
|
||||
aCall, NS_GET_IID(nsISOAPCall),
|
||||
getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv)) return NS_OK;
|
||||
|
||||
rv = holder->GetJSObject(&obj);
|
||||
if (!obj) return NS_OK;
|
||||
|
||||
params[1] = OBJECT_TO_JSVAL(obj);
|
||||
|
||||
params[2] = INT_TO_JSVAL(aResult);
|
||||
|
||||
jsval val;
|
||||
JS_CallFunctionValue(cx, mScopeObj, OBJECT_TO_JSVAL(mFunctionObj),
|
||||
3, params, &val);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
/////////////////////////////////////////////
|
||||
|
||||
nsSOAPCall::nsSOAPCall()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsSOAPCall::~nsSOAPCall()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsSOAPCall,
|
||||
nsISOAPCall,
|
||||
nsISecurityCheckedComponent,
|
||||
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/\">"
|
||||
"<SOAP-ENV:Header>"
|
||||
"</SOAP-ENV:Header>"
|
||||
"<SOAP-ENV:Body>"
|
||||
"</SOAP-ENV:Body>"
|
||||
"</SOAP-ENV:Envelope>";
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::EnsureDocumentAllocated()
|
||||
{
|
||||
if (!mEnvelopeDocument) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIDOMParser> parser = do_CreateInstance(kDOMParserCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString docstr;
|
||||
docstr.AssignWithConversion(kEmptySOAPDocStr);
|
||||
rv = parser->ParseFromString(docstr.GetUnicode(), "text/xml",
|
||||
getter_AddRefs(mEnvelopeDocument));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
mEnvelopeDocument->GetDocumentElement(getter_AddRefs(mEnvelopeElement));
|
||||
if (!mEnvelopeElement) return NS_ERROR_FAILURE;
|
||||
|
||||
nsSOAPUtils::GetFirstChildElement(mEnvelopeElement,
|
||||
getter_AddRefs(mHeaderElement));
|
||||
if (!mHeaderElement) return NS_ERROR_FAILURE;
|
||||
|
||||
nsSOAPUtils::GetNextSiblingElement(mHeaderElement,
|
||||
getter_AddRefs(mBodyElement));
|
||||
if (!mBodyElement) return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement envelope; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetEnvelope(nsIDOMElement * *aEnvelope)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEnvelope);
|
||||
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aEnvelope = mEnvelopeElement;
|
||||
NS_ADDREF(*aEnvelope);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement header; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetHeader(nsIDOMElement * *aHeader)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aHeader);
|
||||
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aHeader = mHeaderElement;
|
||||
NS_ADDREF(*aHeader);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement body; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetBody(nsIDOMElement * *aBody)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBody);
|
||||
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aBody = mBodyElement;
|
||||
NS_ADDREF(*aBody);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string encodingStyleURI; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetEncodingStyleURI(char * *aEncodingStyleURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEncodingStyleURI);
|
||||
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString value;
|
||||
rv = mEnvelopeElement->GetAttributeNS(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI),
|
||||
NS_ConvertASCIItoUCS2(nsSOAPUtils::kEncodingStyleAttribute),
|
||||
value);
|
||||
|
||||
if (value.Length() > 0) {
|
||||
*aEncodingStyleURI = value.ToNewCString();
|
||||
if (nsnull == *aEncodingStyleURI) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*aEncodingStyleURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSOAPCall::SetEncodingStyleURI(const char * aEncodingStyleURI)
|
||||
{
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (nsnull == aEncodingStyleURI) {
|
||||
mEnvelopeElement->RemoveAttributeNS(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI),
|
||||
NS_ConvertASCIItoUCS2(nsSOAPUtils::kEncodingStyleAttribute));
|
||||
}
|
||||
else {
|
||||
mEnvelopeElement->SetAttributeNS(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI),
|
||||
NS_ConvertASCIItoUCS2(nsSOAPUtils::kEncodingStyleAttribute),
|
||||
NS_ConvertASCIItoUCS2(aEncodingStyleURI));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsSOAPCall::HasBodyEntry()
|
||||
{
|
||||
if (!mBodyElement) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> entry;
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement, getter_AddRefs(entry));
|
||||
|
||||
if (entry) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::CreateBodyEntry(PRBool aNewParameters)
|
||||
{
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Create the element that will be the new body entry
|
||||
nsCOMPtr<nsIDOMElement> entry;
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
|
||||
rv = mEnvelopeDocument->CreateElementNS(NS_ConvertASCIItoUCS2(mTargetObjectURI.GetBuffer()),
|
||||
mMethodName, getter_AddRefs(entry));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
// See if there's an existing body entry (we only worry
|
||||
// about the first).
|
||||
nsCOMPtr<nsIDOMElement> oldEntry;
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement, getter_AddRefs(oldEntry));
|
||||
|
||||
// If there is, we're going to replace it, but preserve its
|
||||
// children.
|
||||
if (entry) {
|
||||
// Remove the old entry from the body
|
||||
mBodyElement->RemoveChild(oldEntry, getter_AddRefs(dummy));
|
||||
|
||||
if (!aNewParameters) {
|
||||
// Transfer the children from the old to the new
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
oldEntry->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
oldEntry->RemoveChild(child, getter_AddRefs(dummy));
|
||||
entry->AppendChild(child, getter_AddRefs(dummy));
|
||||
|
||||
nsCOMPtr<nsIDOMNode> temp = child;
|
||||
temp->GetNextSibling(getter_AddRefs(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mBodyElement->AppendChild(entry, getter_AddRefs(dummy));
|
||||
|
||||
// If there wasn't an old entry and we have parameters, or we
|
||||
// we have new parameters, create the parameter elements.
|
||||
if ((!entry && mParameters) || aNewParameters) {
|
||||
rv = CreateParameterElements();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string targetObjectURI; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetTargetObjectURI(char * *aTargetObjectURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aTargetObjectURI);
|
||||
|
||||
if (mTargetObjectURI.Length() > 0) {
|
||||
*aTargetObjectURI = mTargetObjectURI.ToNewCString();
|
||||
}
|
||||
else {
|
||||
*aTargetObjectURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPCall::SetTargetObjectURI(const char * aTargetObjectURI)
|
||||
{
|
||||
NS_ENSURE_ARG(aTargetObjectURI);
|
||||
|
||||
mTargetObjectURI.Assign(aTargetObjectURI);
|
||||
if ((mTargetObjectURI.Length() > 0) && (mMethodName.Length() > 0)) {
|
||||
return CreateBodyEntry(PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string methodName; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetMethodName(PRUnichar * *aMethodName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aMethodName);
|
||||
|
||||
if (mMethodName.Length() > 0) {
|
||||
*aMethodName = mMethodName.ToNewUnicode();
|
||||
}
|
||||
else {
|
||||
*aMethodName = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPCall::SetMethodName(const PRUnichar * aMethodName)
|
||||
{
|
||||
NS_ENSURE_ARG(aMethodName);
|
||||
|
||||
mMethodName.Assign(aMethodName);
|
||||
if ((mTargetObjectURI.Length() > 0) && (mMethodName.Length() > 0)) {
|
||||
return CreateBodyEntry(PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string destinationURI; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetDestinationURI(char * *aDestinationURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDestinationURI);
|
||||
|
||||
if (mDestinationURI.Length() > 0) {
|
||||
*aDestinationURI = mDestinationURI.ToNewCString();
|
||||
}
|
||||
else {
|
||||
*aDestinationURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPCall::SetDestinationURI(const char * aDestinationURI)
|
||||
{
|
||||
if (aDestinationURI) {
|
||||
mDestinationURI.Assign(aDestinationURI);
|
||||
}
|
||||
else {
|
||||
mDestinationURI.Truncate();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string actionURI; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetActionURI(char * *aActionURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aActionURI);
|
||||
|
||||
if (mActionURI.Length() > 0) {
|
||||
*aActionURI = mActionURI.ToNewCString();
|
||||
}
|
||||
else {
|
||||
*aActionURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPCall::SetActionURI(const char * aActionURI)
|
||||
{
|
||||
if (aActionURI) {
|
||||
mActionURI.Assign(aActionURI);
|
||||
}
|
||||
else {
|
||||
mActionURI.Truncate();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::CreateParameterElements()
|
||||
{
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get the body entry that's going to be the parent of
|
||||
// the parameter elements. If we got here, there should
|
||||
// be one.
|
||||
nsCOMPtr<nsIDOMElement> entry;
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement, getter_AddRefs(entry));
|
||||
if (!entry) return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the inherited encoding style starting from the
|
||||
// body entry.
|
||||
nsXPIDLCString encodingStyle;
|
||||
nsSOAPUtils::GetInheritedEncodingStyle(entry, getter_Copies(encodingStyle));
|
||||
|
||||
// Find the corresponding encoder
|
||||
nsCAutoString encoderProgid;
|
||||
encoderProgid.Assign(NS_SOAPENCODER_PROGID_PREFIX);
|
||||
encoderProgid.Append(encodingStyle);
|
||||
|
||||
nsCOMPtr<nsISOAPEncoder> encoder = do_CreateInstance(encoderProgid);
|
||||
if (!encoder) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
PRUint32 index, count;
|
||||
mParameters->Count(&count);
|
||||
|
||||
for(index = 0; index < count; index++) {
|
||||
nsCOMPtr<nsISupports> isup = getter_AddRefs(mParameters->ElementAt(index));
|
||||
nsCOMPtr<nsISOAPParameter> parameter = do_QueryInterface(isup);
|
||||
|
||||
if (parameter) {
|
||||
nsCOMPtr<nsISOAPEncoder> paramEncoder = encoder;
|
||||
|
||||
// See if the parameter has its own encoding style
|
||||
nsXPIDLCString paramEncoding;
|
||||
parameter->GetEncodingStyleURI(getter_Copies(paramEncoding));
|
||||
|
||||
// If it does and it's different from the inherited one,
|
||||
// find an encoder
|
||||
if (paramEncoding &&
|
||||
(nsCRT::strcmp(encodingStyle, paramEncoding) != 0)) {
|
||||
nsCAutoString paramEncoderProgid;
|
||||
paramEncoderProgid.Assign(NS_SOAPENCODER_PROGID_PREFIX);
|
||||
paramEncoderProgid.Append(paramEncoding);
|
||||
|
||||
paramEncoder = do_CreateInstance(paramEncoderProgid);
|
||||
if (!paramEncoder) return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Convert the parameter to an element
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
encoder->ParameterToElement(parameter,
|
||||
paramEncoding ? paramEncoding : encodingStyle,
|
||||
mEnvelopeDocument,
|
||||
getter_AddRefs(element));
|
||||
|
||||
// Append the parameter element to the body entry
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
entry->AppendChild(element, getter_AddRefs(dummy));
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::ClearParameterElements()
|
||||
{
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get the body entry that's the parent of the parameter
|
||||
// elements (assuming there is one)
|
||||
nsCOMPtr<nsIDOMElement> entry;
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement, getter_AddRefs(entry));
|
||||
|
||||
if (entry) {
|
||||
// Get rid of all the children of the body entry
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
entry->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
entry->RemoveChild(child, getter_AddRefs(dummy));
|
||||
entry->GetFirstChild(getter_AddRefs(child));
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [noscript] void setSOAPParameters ([array, size_is (count)] in nsISOAPParameter parameters, in unsigned long count); */
|
||||
NS_IMETHODIMP nsSOAPCall::SetSOAPParameters(nsISOAPParameter **parameters, PRUint32 count)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Clear out any existing parameters
|
||||
if (mParameters) {
|
||||
ClearParameterElements();
|
||||
mParameters->Clear();
|
||||
}
|
||||
else {
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mParameters));
|
||||
if (!mParameters) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
PRUint32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsISOAPParameter* parameter = parameters[index];
|
||||
if (parameter) {
|
||||
mParameters->AppendElement(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBodyEntry()) {
|
||||
return CreateParameterElements();
|
||||
}
|
||||
else if ((mTargetObjectURI.Length() > 0) && (mMethodName.Length() > 0)) {
|
||||
return CreateBodyEntry(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setParameters (in nsISupports parameters); */
|
||||
NS_IMETHODIMP nsSOAPCall::SetParameters(nsISupports *parameters)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Clear out any existing parameters
|
||||
if (mParameters) {
|
||||
ClearParameterElements();
|
||||
mParameters->Clear();
|
||||
}
|
||||
else {
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mParameters));
|
||||
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);
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIXPCNativeCallContext> cc;
|
||||
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBodyEntry()) {
|
||||
return CreateParameterElements();
|
||||
}
|
||||
else if ((mTargetObjectURI.Length() > 0) && (mMethodName.Length() > 0)) {
|
||||
return CreateBodyEntry(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setSimpleParameters (); */
|
||||
NS_IMETHODIMP nsSOAPCall::SetSimpleParameters()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::GetTransport(nsISOAPTransport** aTransport)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsXPIDLCString protocol;
|
||||
|
||||
rv = NS_NewURI(getter_AddRefs(uri), mDestinationURI.GetBuffer());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
uri->GetScheme(getter_Copies(protocol));
|
||||
|
||||
nsCAutoString transportProgid;
|
||||
transportProgid.Assign(NS_SOAPTRANSPORT_PROGID_PREFIX);
|
||||
transportProgid.Append(protocol);
|
||||
|
||||
nsCOMPtr<nsISOAPTransport> transport = do_CreateInstance(transportProgid);
|
||||
if (!transport) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
*aTransport = transport.get();
|
||||
NS_ADDREF(*aTransport);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsISOAPResponse invoke (); */
|
||||
NS_IMETHODIMP nsSOAPCall::Invoke(nsISOAPResponse **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISOAPTransport> transport;
|
||||
|
||||
if (mDestinationURI.Length() == 0) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
rv = GetTransport(getter_AddRefs(transport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool canDoSync;
|
||||
transport->CanDoSync(&canDoSync);
|
||||
|
||||
if (!canDoSync) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> responseDocument;
|
||||
rv = transport->SyncCall(mDestinationURI,
|
||||
mActionURI,
|
||||
mEnvelopeDocument,
|
||||
getter_AddRefs(responseDocument));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsSOAPResponse* response;
|
||||
response = new nsSOAPResponse(responseDocument);
|
||||
if (!response) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return response->QueryInterface(NS_GET_IID(nsISOAPResponse), (void**)_retval);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::GetScriptListener(nsISupports* aObject,
|
||||
nsISOAPResponseListener** aListener)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIXPCNativeCallContext> cc;
|
||||
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && cc) {
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> jsobjholder = do_QueryInterface(aObject);
|
||||
if (jsobjholder) {
|
||||
JSObject* funobj;
|
||||
rv = jsobjholder->GetJSObject(&funobj);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
JSContext* cx;
|
||||
rv = cc->GetJSContext(&cx);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
JSFunction* fun = JS_ValueToFunction(cx, OBJECT_TO_JSVAL(funobj));
|
||||
if (!fun) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
||||
rv = cc->GetCalleeWrapper(getter_AddRefs(wrapper));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
JSObject* scopeobj;
|
||||
rv = wrapper->GetJSObject(&scopeobj);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsScriptResponseListener* listener = new nsScriptResponseListener(scopeobj, funobj);
|
||||
if (!listener) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
*aListener = listener;
|
||||
NS_ADDREF(*aListener);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void asyncInvoke (in nsISupports listener); */
|
||||
NS_IMETHODIMP nsSOAPCall::AsyncInvoke(nsISupports *listener)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISOAPTransport> transport;
|
||||
|
||||
if (mDestinationURI.Length() == 0) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
rv = GetTransport(getter_AddRefs(transport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mListener = do_QueryInterface(listener);
|
||||
// We first try to do a direct QI, if that doesn't work
|
||||
// maybe it's a script event listener
|
||||
if (!mListener) {
|
||||
rv = GetScriptListener(listener, getter_AddRefs(mListener));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rv = transport->AsyncCall(mDestinationURI,
|
||||
mActionURI,
|
||||
mEnvelopeDocument,
|
||||
this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* void handleResponse (in nsIDOMDocument document, in unsigned long status); */
|
||||
NS_IMETHODIMP nsSOAPCall::HandleResponse(nsIDOMDocument *document, PRUint32 status, nsresult result)
|
||||
{
|
||||
if (mListener) {
|
||||
nsCOMPtr<nsISOAPResponse> response;
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsSOAPResponse* respobj;
|
||||
respobj = new nsSOAPResponse(document);
|
||||
if (!respobj) result = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
response = (nsISOAPResponse*)respobj;
|
||||
}
|
||||
|
||||
mListener->HandleResponse(response,
|
||||
this,
|
||||
result);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static const char* kAllAccess = "AllAccess";
|
||||
|
||||
/* string canCreateWrapper (in nsIIDPtr iid); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPCall::CanCreateWrapper(const nsIID * iid, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPCall))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPCall::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPCall))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPCall::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPCall))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPCall::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPCall))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/* -*- 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 nsSOAPCall_h__
|
||||
#define nsSOAPCall_h__
|
||||
|
||||
#include "nsISOAPCall.h"
|
||||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsISOAPTransportListener.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsISOAPResponseListener.h"
|
||||
#include "nsISOAPTransport.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsSOAPCall : public nsISOAPCall,
|
||||
public nsISecurityCheckedComponent,
|
||||
public nsISOAPTransportListener
|
||||
{
|
||||
public:
|
||||
nsSOAPCall();
|
||||
virtual ~nsSOAPCall();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPCall
|
||||
NS_DECL_NSISOAPCALL
|
||||
|
||||
// nsISecurityCheckedComponent
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
// nsISOAPTransportListener
|
||||
NS_DECL_NSISOAPTRANSPORTLISTENER
|
||||
|
||||
protected:
|
||||
|
||||
nsresult EnsureDocumentAllocated();
|
||||
PRBool HasBodyEntry();
|
||||
nsresult CreateBodyEntry(PRBool aNewParameters);
|
||||
nsresult CreateParameterElements();
|
||||
nsresult ClearParameterElements();
|
||||
nsresult GetTransport(nsISOAPTransport** aTransport);
|
||||
nsresult GetScriptListener(nsISupports* aObject,
|
||||
nsISOAPResponseListener** aListener);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> mEnvelopeDocument;
|
||||
nsCOMPtr<nsIDOMElement> mEnvelopeElement;
|
||||
nsCOMPtr<nsIDOMElement> mHeaderElement;
|
||||
nsCOMPtr<nsIDOMElement> mBodyElement;
|
||||
nsCString mDestinationURI;
|
||||
nsCString mActionURI;
|
||||
nsCString mTargetObjectURI;
|
||||
nsString mMethodName;
|
||||
nsCOMPtr<nsISupportsArray> mParameters;
|
||||
nsCOMPtr<nsISOAPResponseListener> mListener;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,170 @@
|
|||
/* -*- 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 "nsSOAPFault.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
|
||||
nsSOAPFault::nsSOAPFault(nsIDOMElement* aElement)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mFaultElement = aElement;
|
||||
}
|
||||
|
||||
nsSOAPFault::~nsSOAPFault()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSOAPFault, nsISOAPFault, nsISecurityCheckedComponent)
|
||||
|
||||
/* readonly attribute nsIDOMElement element; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetElement(nsIDOMElement * *aElement)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aElement);
|
||||
*aElement = mFaultElement;
|
||||
NS_IF_ADDREF(*aElement);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute wstring faultCode; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetFaultCode(PRUnichar * *aFaultCode)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFaultCode);
|
||||
|
||||
*aFaultCode = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
|
||||
nsAutoString tagname;
|
||||
tagname.AssignWithConversion(nsSOAPUtils::kFaultCodeTagName);
|
||||
mFaultElement->GetElementsByTagName(tagname, getter_AddRefs(list));
|
||||
PRUint32 length;
|
||||
list->GetLength(&length);
|
||||
if (length > 0) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
|
||||
list->Item(0, getter_AddRefs(node));
|
||||
element = do_QueryInterface(node);
|
||||
|
||||
nsAutoString text;
|
||||
nsSOAPUtils::GetElementTextContent(element, text);
|
||||
if (text.Length() > 0) {
|
||||
*aFaultCode = text.ToNewUnicode();
|
||||
if (!*aFaultCode) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute wstring faultString; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetFaultString(PRUnichar * *aFaultString)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFaultString);
|
||||
|
||||
*aFaultString = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
|
||||
nsAutoString tagname;
|
||||
tagname.AssignWithConversion(nsSOAPUtils::kFaultStringTagName);
|
||||
mFaultElement->GetElementsByTagName(tagname, getter_AddRefs(list));
|
||||
PRUint32 length;
|
||||
list->GetLength(&length);
|
||||
if (length > 0) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
|
||||
list->Item(0, getter_AddRefs(node));
|
||||
element = do_QueryInterface(node);
|
||||
|
||||
nsAutoString text;
|
||||
nsSOAPUtils::GetElementTextContent(element, text);
|
||||
if (text.Length() > 0) {
|
||||
*aFaultString = text.ToNewUnicode();
|
||||
if (!*aFaultString) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute wstring faultActor; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetFaultActor(PRUnichar * *aFaultActor)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFaultActor);
|
||||
|
||||
*aFaultActor = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
|
||||
nsAutoString tagname;
|
||||
tagname.AssignWithConversion(nsSOAPUtils::kFaultActorTagName);
|
||||
mFaultElement->GetElementsByTagName(tagname, getter_AddRefs(list));
|
||||
PRUint32 length;
|
||||
list->GetLength(&length);
|
||||
if (length > 0) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
|
||||
list->Item(0, getter_AddRefs(node));
|
||||
element = do_QueryInterface(node);
|
||||
|
||||
nsAutoString text;
|
||||
nsSOAPUtils::GetElementTextContent(element, text);
|
||||
if (text.Length() > 0) {
|
||||
*aFaultActor = text.ToNewUnicode();
|
||||
if (!*aFaultActor) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement detail; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetDetail(nsIDOMElement * *aDetail)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDetail);
|
||||
|
||||
*aDetail = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
|
||||
nsAutoString tagname;
|
||||
tagname.AssignWithConversion(nsSOAPUtils::kFaultDetailTagName);
|
||||
mFaultElement->GetElementsByTagName(tagname, getter_AddRefs(list));
|
||||
PRUint32 length;
|
||||
list->GetLength(&length);
|
||||
if (length > 0) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
|
||||
list->Item(0, getter_AddRefs(node));
|
||||
return node->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aDetail);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/* -*- 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 nsSOAPFault_h__
|
||||
#define nsSOAPFault_h__
|
||||
|
||||
#include "nsISOAPFault.h"
|
||||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsSOAPFault : public nsISOAPFault,
|
||||
public nsISecurityCheckedComponent
|
||||
{
|
||||
public:
|
||||
nsSOAPFault(nsIDOMElement* aElement);
|
||||
virtual ~nsSOAPFault();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPFault
|
||||
NS_DECL_NSISOAPFAULT
|
||||
|
||||
// nsISecurityCheckedComponent
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIDOMElement> mFaultElement;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,254 @@
|
|||
/* -*- 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 "nsSOAPParameter.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
nsSOAPParameter::nsSOAPParameter()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mType = PARAMETER_TYPE_NULL;
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
if (cx) {
|
||||
JS_AddNamedRoot(cx, &mJSValue, "nsSOAPParameter");
|
||||
}
|
||||
}
|
||||
|
||||
nsSOAPParameter::~nsSOAPParameter()
|
||||
{
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
if (cx) {
|
||||
JS_RemoveRoot(cx, &mJSValue);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSOAPParameter, nsISOAPParameter, nsISecurityCheckedComponent)
|
||||
|
||||
/* attribute string encodingStyleURI; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetEncodingStyleURI(char * *aEncodingStyleURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEncodingStyleURI);
|
||||
if (mEncodingStyleURI.Length() > 0) {
|
||||
*aEncodingStyleURI = mEncodingStyleURI.ToNewCString();
|
||||
}
|
||||
else {
|
||||
*aEncodingStyleURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPParameter::SetEncodingStyleURI(const char * aEncodingStyleURI)
|
||||
{
|
||||
if (aEncodingStyleURI) {
|
||||
mEncodingStyleURI.Assign(aEncodingStyleURI);
|
||||
}
|
||||
else {
|
||||
mEncodingStyleURI.Truncate();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute wstring name; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetName(PRUnichar * *aName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aName);
|
||||
if (mName.Length() > 0) {
|
||||
*aName = mName.ToNewUnicode();
|
||||
}
|
||||
else {
|
||||
*aName = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPParameter::SetName(const PRUnichar * aName)
|
||||
{
|
||||
if (aName) {
|
||||
mName.Assign(aName);
|
||||
}
|
||||
else {
|
||||
mName.Truncate();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute long type; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetType(PRInt32 *aType)
|
||||
{
|
||||
NS_ENSURE_ARG(aType);
|
||||
*aType = mType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [noscript] void setValueAndType (in nsISupports value, in long type); */
|
||||
NS_IMETHODIMP nsSOAPParameter::SetValueAndType(nsISupports *value, PRInt32 type)
|
||||
{
|
||||
mValue = value;
|
||||
mType = type;
|
||||
mJSValue = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsISupports value; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetValue(nsISupports * *aValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aValue);
|
||||
nsresult rv;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// We can't make this a setter in xpidl without a variant type.
|
||||
// For now, use nsIXPCScriptable to do the setting.
|
||||
NS_IMETHODIMP nsSOAPParameter::SetValue(JSContext* aContext,
|
||||
jsval aValue)
|
||||
{
|
||||
return nsSOAPUtils::ConvertJSValToValue(aContext,
|
||||
aValue,
|
||||
getter_AddRefs(mValue),
|
||||
&mJSValue,
|
||||
&mType);
|
||||
}
|
||||
|
||||
/* [noscript] readonly attribute JSObjectPtr JSValue; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetJSValue(JSObject * *aJSValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aJSValue);
|
||||
*aJSValue = mJSValue;
|
||||
|
||||
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)
|
||||
XPC_IMPLEMENT_IGNORE_DEFAULTVALUE(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_ENUMERATE(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_CHECKACCESS(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_CALL(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_CONSTRUCT(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_FINALIZE(nsSOAPParameter)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::SetProperty(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")) {
|
||||
return SetValue(cx, *vp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
static const char* kAllAccess = "AllAccess";
|
||||
|
||||
/* string canCreateWrapper (in nsIIDPtr iid); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::CanCreateWrapper(const nsIID * iid, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPParameter))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPParameter))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPParameter))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPParameter))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/* -*- 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 nsSOAPParameter_h__
|
||||
#define nsSOAPParameter_h__
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsISOAPParameter.h"
|
||||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsSOAPParameter : public nsISOAPParameter,
|
||||
public nsISecurityCheckedComponent,
|
||||
public nsIXPCScriptable
|
||||
{
|
||||
public:
|
||||
nsSOAPParameter();
|
||||
virtual ~nsSOAPParameter();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPParameter
|
||||
NS_DECL_NSISOAPPARAMETER
|
||||
|
||||
// nsISecurityCheckedComponent
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
// nsIXPCScriptable
|
||||
XPC_DECLARE_IXPCSCRIPTABLE
|
||||
|
||||
NS_IMETHODIMP SetValue(JSContext* aContext,
|
||||
jsval aValue);
|
||||
|
||||
protected:
|
||||
nsCString mEncodingStyleURI;
|
||||
nsString mName;
|
||||
PRInt32 mType;
|
||||
nsCOMPtr<nsISupports> mValue;
|
||||
JSObject* mJSValue;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,276 @@
|
|||
/* -*- 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 "nsSOAPResponse.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
#include "nsSOAPFault.h"
|
||||
#include "nsISOAPEncoder.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsISOAPParameter.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsMemory.h"
|
||||
|
||||
nsSOAPResponse::nsSOAPResponse(nsIDOMDocument* aEnvelopeDocument)
|
||||
{
|
||||
mEnvelopeDocument = aEnvelopeDocument;
|
||||
if (mEnvelopeDocument) {
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
mEnvelopeDocument->GetDocumentElement(getter_AddRefs(element));
|
||||
if (!element) return;
|
||||
|
||||
nsAutoString ns, name;
|
||||
element->GetNamespaceURI(ns);
|
||||
element->GetLocalName(name);
|
||||
|
||||
if (ns.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI)) &&
|
||||
name.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kEnvelopeTagName))) {
|
||||
mEnvelopeElement = element;
|
||||
nsSOAPUtils::GetFirstChildElement(mEnvelopeElement,
|
||||
getter_AddRefs(element));
|
||||
if (!element) return;
|
||||
|
||||
element->GetNamespaceURI(ns);
|
||||
element->GetLocalName(name);
|
||||
|
||||
if (ns.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI)) &&
|
||||
name.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kHeaderTagName))) {
|
||||
mHeaderElement = element;
|
||||
|
||||
nsSOAPUtils::GetNextSiblingElement(mHeaderElement,
|
||||
getter_AddRefs(element));
|
||||
if (!element) return;
|
||||
|
||||
element->GetNamespaceURI(ns);
|
||||
element->GetLocalName(name);
|
||||
}
|
||||
|
||||
if (ns.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI)) &&
|
||||
name.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kBodyTagName))) {
|
||||
mBodyElement = element;
|
||||
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement,
|
||||
getter_AddRefs(element));
|
||||
if (!element) return;
|
||||
|
||||
element->GetNamespaceURI(ns);
|
||||
element->GetLocalName(name);
|
||||
|
||||
// XXX This assumes that the first body entry is either a fault
|
||||
// or a result and that the two are mutually exclusive
|
||||
if (ns.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI)) &&
|
||||
name.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kFaultTagName))) {
|
||||
mFaultElement = element;
|
||||
}
|
||||
else {
|
||||
mResultElement = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsSOAPResponse::~nsSOAPResponse()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSOAPResponse, nsISOAPResponse, nsISecurityCheckedComponent)
|
||||
|
||||
/* readonly attribute nsIDOMElement envelope; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetEnvelope(nsIDOMElement * *aEnvelope)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEnvelope);
|
||||
*aEnvelope = mEnvelopeElement;
|
||||
NS_IF_ADDREF(*aEnvelope);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement header; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetHeader(nsIDOMElement * *aHeader)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aHeader);
|
||||
*aHeader = mHeaderElement;
|
||||
NS_IF_ADDREF(*aHeader);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement body; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetBody(nsIDOMElement * *aBody)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBody);
|
||||
*aBody = mBodyElement;
|
||||
NS_IF_ADDREF(*aBody);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long status; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetStatus(PRUint32 *aStatus)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* readonly attribute string targetObjectURI; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetTargetObjectURI(char * *aTargetObjectURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aTargetObjectURI);
|
||||
*aTargetObjectURI = nsnull;
|
||||
if (mResultElement) {
|
||||
nsAutoString ns;
|
||||
mResultElement->GetNamespaceURI(ns);
|
||||
if (ns.Length() > 0) {
|
||||
*aTargetObjectURI = ns.ToNewCString();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute string methodName; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetMethodName(char * *aMethodName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aMethodName);
|
||||
*aMethodName = nsnull;
|
||||
if (mResultElement) {
|
||||
nsAutoString localName;
|
||||
mResultElement->GetLocalName(localName);
|
||||
if (localName.Length() > 0) {
|
||||
*aMethodName = localName.ToNewCString();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* boolean generatedFault (); */
|
||||
NS_IMETHODIMP nsSOAPResponse::GeneratedFault(PRBool *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(_retval);
|
||||
if (mFaultElement) {
|
||||
*_retval = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
*_retval = PR_FALSE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsISOAPFault fault; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetFault(nsISOAPFault * *aFault)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFault);
|
||||
*aFault = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsSOAPFault* fault = new nsSOAPFault(mFaultElement);
|
||||
if (!fault) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return fault->QueryInterface(NS_GET_IID(nsISOAPFault), (void**)aFault);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsISOAPParameter returnValue; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetReturnValue(nsISOAPParameter * *aReturnValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturnValue);
|
||||
nsresult rv;
|
||||
|
||||
*aReturnValue = nsnull;
|
||||
|
||||
if (mResultElement) {
|
||||
// Get the inherited encoding style starting from the
|
||||
// body entry.
|
||||
char* encodingStyle;
|
||||
nsSOAPUtils::GetInheritedEncodingStyle(mResultElement,
|
||||
&encodingStyle);
|
||||
|
||||
if (!encodingStyle) {
|
||||
encodingStyle = nsCRT::strdup(nsSOAPUtils::kSOAPEncodingURI);
|
||||
}
|
||||
|
||||
// Find the corresponding encoder
|
||||
nsCAutoString encoderProgid;
|
||||
encoderProgid.Assign(NS_SOAPENCODER_PROGID_PREFIX);
|
||||
encoderProgid.Append(encodingStyle);
|
||||
|
||||
nsCOMPtr<nsISOAPEncoder> encoder = do_CreateInstance(encoderProgid);
|
||||
if (!encoder) {
|
||||
nsMemory::Free(encodingStyle);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Convert the result element to a parameter
|
||||
nsCOMPtr<nsISOAPParameter> param;
|
||||
rv = encoder->ElementToParameter(mResultElement,
|
||||
encodingStyle,
|
||||
getter_AddRefs(param));
|
||||
nsMemory::Free(encodingStyle);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aReturnValue = param;
|
||||
NS_IF_ADDREF(*aReturnValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static const char* kAllAccess = "AllAccess";
|
||||
|
||||
/* string canCreateWrapper (in nsIIDPtr iid); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPResponse::CanCreateWrapper(const nsIID * iid, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPResponse))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPResponse::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPResponse))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPResponse::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPResponse))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPResponse::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPResponse))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/* -*- 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 nsSOAPResponse_h__
|
||||
#define nsSOAPResponse_h__
|
||||
|
||||
#include "nsISOAPResponse.h"
|
||||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsSOAPResponse : public nsISOAPResponse,
|
||||
public nsISecurityCheckedComponent
|
||||
{
|
||||
public:
|
||||
nsSOAPResponse(nsIDOMDocument* aEnvelopeDocument);
|
||||
virtual ~nsSOAPResponse();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPResponse
|
||||
NS_DECL_NSISOAPRESPONSE
|
||||
|
||||
// nsISecurityCheckedComponent
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIDOMDocument> mEnvelopeDocument;
|
||||
nsCOMPtr<nsIDOMElement> mEnvelopeElement;
|
||||
nsCOMPtr<nsIDOMElement> mHeaderElement;
|
||||
nsCOMPtr<nsIDOMElement> mBodyElement;
|
||||
nsCOMPtr<nsIDOMElement> mResultElement;
|
||||
nsCOMPtr<nsIDOMElement> mFaultElement;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,374 @@
|
|||
/* -*- 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 "nsSOAPUtils.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsISOAPParameter.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
const char* nsSOAPUtils::kSOAPEnvURI = "http://schemas.xmlsoap.org/soap/envelope/";
|
||||
const char* nsSOAPUtils::kSOAPEncodingURI = "http://schemas.xmlsoap.org/soap/encoding/";
|
||||
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";
|
||||
|
||||
void
|
||||
nsSOAPUtils::GetFirstChildElement(nsIDOMElement* aParent,
|
||||
nsIDOMElement** aElement)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
|
||||
*aElement = nsnull;
|
||||
aParent->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
PRUint16 type;
|
||||
child->GetNodeType(&type);
|
||||
if (nsIDOMNode::ELEMENT_NODE == type) {
|
||||
child->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aElement);
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp = child;
|
||||
temp->GetNextSibling(getter_AddRefs(child));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsSOAPUtils::GetNextSiblingElement(nsIDOMElement* aStart,
|
||||
nsIDOMElement** aElement)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> sibling;
|
||||
|
||||
*aElement = nsnull;
|
||||
aStart->GetNextSibling(getter_AddRefs(sibling));
|
||||
while (sibling) {
|
||||
PRUint16 type;
|
||||
sibling->GetNodeType(&type);
|
||||
if (nsIDOMNode::ELEMENT_NODE == type) {
|
||||
sibling->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aElement);
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp = sibling;
|
||||
temp->GetNextSibling(getter_AddRefs(sibling));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsSOAPUtils::GetElementTextContent(nsIDOMElement* aElement,
|
||||
nsString& aText)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> sibling;
|
||||
|
||||
aText.Truncate();
|
||||
aElement->GetNextSibling(getter_AddRefs(sibling));
|
||||
while (sibling) {
|
||||
PRUint16 type;
|
||||
sibling->GetNodeType(&type);
|
||||
if (nsIDOMNode::TEXT_NODE == type) {
|
||||
nsCOMPtr<nsIDOMText> text = do_QueryInterface(sibling);
|
||||
nsAutoString data;
|
||||
text->GetData(data);
|
||||
aText.Append(data);
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp = sibling;
|
||||
temp->GetNextSibling(getter_AddRefs(sibling));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsSOAPUtils::GetInheritedEncodingStyle(nsIDOMElement* aEntry,
|
||||
char** aEncodingStyle)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> node = aEntry;
|
||||
|
||||
*aEncodingStyle = nsnull;
|
||||
while (node) {
|
||||
nsAutoString value;
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
|
||||
if (element) {
|
||||
element->GetAttributeNS(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI),
|
||||
NS_ConvertASCIItoUCS2(nsSOAPUtils::kEncodingStyleAttribute),
|
||||
value);
|
||||
if (value.Length() > 0) {
|
||||
*aEncodingStyle = value.ToNewCString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp = node;
|
||||
temp->GetParentNode(getter_AddRefs(node));
|
||||
}
|
||||
}
|
||||
|
||||
JSContext*
|
||||
nsSOAPUtils::GetSafeContext()
|
||||
{
|
||||
// Get the "safe" JSContext: our JSContext of last resort
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIJSContextStack, stack, "nsThreadJSContextStack",
|
||||
&rv);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
nsCOMPtr<nsIThreadJSContextStack> tcs = do_QueryInterface(stack);
|
||||
JSContext* cx;
|
||||
if (NS_FAILED(tcs->GetSafeJSContext(&cx))) {
|
||||
return nsnull;
|
||||
}
|
||||
return cx;
|
||||
}
|
||||
|
||||
JSContext*
|
||||
nsSOAPUtils::GetCurrentContext()
|
||||
{
|
||||
// Get JSContext from stack.
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIJSContextStack, stack, "nsThreadJSContextStack",
|
||||
&rv);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
JSContext *cx;
|
||||
if (NS_FAILED(stack->Peek(&cx)))
|
||||
return nsnull;
|
||||
return cx;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPUtils::ConvertValueToJSVal(JSContext* aContext,
|
||||
nsISupports* aValue,
|
||||
JSObject* aJSValue,
|
||||
PRInt32 aType,
|
||||
jsval* vp)
|
||||
{
|
||||
*vp = JSVAL_NULL;
|
||||
switch(aType) {
|
||||
case nsISOAPParameter::PARAMETER_TYPE_VOID:
|
||||
*vp = JSVAL_VOID;
|
||||
break;
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_STRING:
|
||||
{
|
||||
nsCOMPtr<nsISupportsWString> wstr = do_QueryInterface(aValue);
|
||||
if (!wstr) return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLString data;
|
||||
wstr->GetData(getter_Copies(data));
|
||||
|
||||
if (data) {
|
||||
JSString* jsstr = JS_NewUCStringCopyZ(aContext,
|
||||
(const jschar*)data);
|
||||
if (jsstr) {
|
||||
*vp = STRING_TO_JSVAL(jsstr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_BOOLEAN:
|
||||
{
|
||||
nsCOMPtr<nsISupportsPRBool> prb = do_QueryInterface(aValue);
|
||||
if (!prb) return NS_ERROR_FAILURE;
|
||||
|
||||
PRBool data;
|
||||
prb->GetData(&data);
|
||||
|
||||
if (data) {
|
||||
*vp = JSVAL_TRUE;
|
||||
}
|
||||
else {
|
||||
*vp = JSVAL_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_DOUBLE:
|
||||
{
|
||||
nsCOMPtr<nsISupportsDouble> dub = do_QueryInterface(aValue);
|
||||
if (!dub) return NS_ERROR_FAILURE;
|
||||
|
||||
double data;
|
||||
dub->GetData(&data);
|
||||
|
||||
*vp = DOUBLE_TO_JSVAL((jsdouble)data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_FLOAT:
|
||||
{
|
||||
nsCOMPtr<nsISupportsFloat> flt = do_QueryInterface(aValue);
|
||||
if (!flt) return NS_ERROR_FAILURE;
|
||||
|
||||
float data;
|
||||
flt->GetData(&data);
|
||||
|
||||
*vp = DOUBLE_TO_JSVAL((jsdouble)data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_LONG:
|
||||
{
|
||||
// XXX How to express 64-bit values in JavaScript?
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_INT:
|
||||
{
|
||||
nsCOMPtr<nsISupportsPRInt32> isupint32 = do_QueryInterface(aValue);
|
||||
if (!isupint32) return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt32 data;
|
||||
isupint32->GetData(&data);
|
||||
|
||||
*vp = INT_TO_JSVAL(data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_SHORT:
|
||||
{
|
||||
nsCOMPtr<nsISupportsPRInt16> isupint16 = do_QueryInterface(aValue);
|
||||
if (!isupint16) return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt16 data;
|
||||
isupint16->GetData(&data);
|
||||
|
||||
*vp = INT_TO_JSVAL((PRInt32)data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_BYTE:
|
||||
{
|
||||
nsCOMPtr<nsISupportsChar> isupchar = do_QueryInterface(aValue);
|
||||
if (!isupchar) return NS_ERROR_FAILURE;
|
||||
|
||||
char data;
|
||||
isupchar->GetData(&data);
|
||||
|
||||
*vp = INT_TO_JSVAL((PRInt32)data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_ARRAY:
|
||||
{
|
||||
// XXX Can't (easily) convert a native nsISupportsArray
|
||||
// to a script array.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_ARRAY:
|
||||
case nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_OBJECT:
|
||||
{
|
||||
*vp = OBJECT_TO_JSVAL(aJSValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPUtils::ConvertJSValToValue(JSContext* aContext,
|
||||
jsval val,
|
||||
nsISupports** aValue,
|
||||
JSObject** aJSValue,
|
||||
PRInt32* aType)
|
||||
{
|
||||
*aValue = nsnull;
|
||||
*aJSValue = nsnull;
|
||||
if (JSVAL_IS_NULL(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_NULL;
|
||||
}
|
||||
else if (JSVAL_IS_VOID(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_VOID;
|
||||
}
|
||||
else if (JSVAL_IS_STRING(val)) {
|
||||
JSString* jsstr;
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_STRING;
|
||||
|
||||
jsstr = JSVAL_TO_STRING(val);
|
||||
if (jsstr) {
|
||||
nsCOMPtr<nsISupportsWString> wstr = do_CreateInstance(NS_SUPPORTS_WSTRING_PROGID);
|
||||
if (!wstr) return NS_ERROR_FAILURE;
|
||||
|
||||
PRUnichar* data = NS_REINTERPRET_CAST(PRUnichar*,
|
||||
JS_GetStringChars(jsstr));
|
||||
if (data) {
|
||||
wstr->SetData(data);
|
||||
}
|
||||
*aValue = wstr;
|
||||
NS_ADDREF(*aValue);
|
||||
}
|
||||
}
|
||||
else if (JSVAL_IS_DOUBLE(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_DOUBLE;
|
||||
|
||||
nsCOMPtr<nsISupportsDouble> dub = do_CreateInstance(NS_SUPPORTS_DOUBLE_PROGID);
|
||||
if (!dub) return NS_ERROR_FAILURE;
|
||||
|
||||
dub->SetData((double)(*JSVAL_TO_DOUBLE(val)));
|
||||
*aValue = dub;
|
||||
NS_ADDREF(*aValue);
|
||||
}
|
||||
else if (JSVAL_IS_INT(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_INT;
|
||||
|
||||
nsCOMPtr<nsISupportsPRInt32> isupint = do_CreateInstance(NS_SUPPORTS_PRINT32_PROGID);
|
||||
if (!isupint) return NS_ERROR_FAILURE;
|
||||
|
||||
isupint->SetData((PRInt32)JSVAL_TO_INT(val));
|
||||
*aValue = isupint;
|
||||
NS_ADDREF(*aValue);
|
||||
}
|
||||
else if (JSVAL_IS_BOOLEAN(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_BOOLEAN;
|
||||
|
||||
nsCOMPtr<nsISupportsPRBool> isupbool = do_CreateInstance(NS_SUPPORTS_PRBOOL_PROGID);
|
||||
if (!isupbool) return NS_ERROR_FAILURE;
|
||||
|
||||
isupbool->SetData((PRBool)JSVAL_TO_BOOLEAN(val));
|
||||
*aValue = isupbool;
|
||||
NS_ADDREF(*aValue);
|
||||
}
|
||||
else if (JSVAL_IS_OBJECT(val)) {
|
||||
JSObject* jsobj = JSVAL_TO_OBJECT(val);
|
||||
if (JS_IsArrayObject(aContext, jsobj)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_ARRAY;
|
||||
}
|
||||
else {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_OBJECT;
|
||||
}
|
||||
*aJSValue = jsobj;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/* -*- 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 nsSOAPUtils_h__
|
||||
#define nsSOAPUtils_h__
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
class nsSOAPUtils {
|
||||
public:
|
||||
static void GetFirstChildElement(nsIDOMElement* aParent,
|
||||
nsIDOMElement** aElement);
|
||||
static void GetNextSiblingElement(nsIDOMElement* aStart,
|
||||
nsIDOMElement** aElement);
|
||||
static void GetElementTextContent(nsIDOMElement* aElement,
|
||||
nsString& aText);
|
||||
static void GetInheritedEncodingStyle(nsIDOMElement* aEntry,
|
||||
char** aEncodingStyle);
|
||||
static JSContext* GetSafeContext();
|
||||
static JSContext* GetCurrentContext();
|
||||
static nsresult ConvertValueToJSVal(JSContext* aContext,
|
||||
nsISupports* aValue,
|
||||
JSObject* aJSValue,
|
||||
PRInt32 aType,
|
||||
jsval* vp);
|
||||
static nsresult ConvertJSValToValue(JSContext* aContext,
|
||||
jsval val,
|
||||
nsISupports** aValue,
|
||||
JSObject** aJSValue,
|
||||
PRInt32* aType);
|
||||
|
||||
static const char* kSOAPEnvURI;
|
||||
static const char* kSOAPEncodingURI;
|
||||
static const char* kEncodingStyleAttribute;
|
||||
static const char* kEnvelopeTagName;
|
||||
static const char* kHeaderTagName;
|
||||
static const char* kBodyTagName;
|
||||
static const char* kFaultTagName;
|
||||
static const char* kFaultCodeTagName;
|
||||
static const char* kFaultStringTagName;
|
||||
static const char* kFaultActorTagName;
|
||||
static const char* kFaultDetailTagName;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist:idl directory
|
||||
#
|
||||
|
||||
nsISOAPCall.idl
|
||||
nsISOAPParameter.idl
|
||||
nsISOAPResponse.idl
|
||||
nsISOAPResponseListener.idl
|
||||
nsISOAPEncoder.idl
|
||||
nsISOAPFault.idl
|
||||
nsISOAPTransport.idl
|
||||
nsISOAPTransportListener.idl
|
|
@ -0,0 +1,42 @@
|
|||
#
|
||||
# The contents of this file are subject to the Mozilla 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/MPL/
|
||||
#
|
||||
# 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):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xmlextras
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsISOAPCall.idl \
|
||||
nsISOAPParameter.idl \
|
||||
nsISOAPResponse.idl \
|
||||
nsISOAPResponseListener.idl \
|
||||
nsISOAPEncoder.idl \
|
||||
nsISOAPFault.idl \
|
||||
nsISOAPTransport.idl \
|
||||
nsISOAPTransportListener.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,37 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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):
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
XPIDLSRCS = .\nsISOAPCall.idl \
|
||||
.\nsISOAPParameter.idl \
|
||||
.\nsISOAPResponse.idl \
|
||||
.\nsISOAPResponseListener.idl \
|
||||
.\nsISOAPEncoder.idl \
|
||||
.\nsISOAPFault.idl \
|
||||
.\nsISOAPTransport.idl \
|
||||
.\nsISOAPTransportListener.idl \
|
||||
$(NULL)
|
||||
|
||||
MODULE=xmlextras
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMElement;
|
||||
interface nsISOAPParameter;
|
||||
interface nsISOAPResponse;
|
||||
|
||||
[scriptable, uuid(a8fefe40-52bc-11d4-9a57-000064657374)]
|
||||
interface nsISOAPCall : nsISupports {
|
||||
|
||||
/**
|
||||
* The DOM element representing the SOAP envelope itself. By default,
|
||||
* this element has a namespace declaration for the SOAP envelope
|
||||
* namespace defined in the SOAP specification. It also has an
|
||||
* <code>encodingStyle</code> attribute that corresponds to the
|
||||
* current encoding style for the call. The Envelope element also
|
||||
* has two children representing the SOAP header and body. DOM methods
|
||||
* may be used to add additional attributes to the envelope.
|
||||
*/
|
||||
readonly attribute nsIDOMElement envelope;
|
||||
|
||||
/**
|
||||
* A convenience attribute to obtain the DOM element representing the
|
||||
* SOAP header. DOM methods may be used to add header entries. By default
|
||||
* this element has no attributes or children. If this is still the case
|
||||
* at the point at which the call is invoked, the SOAP message will not
|
||||
* contain a header.
|
||||
*/
|
||||
readonly attribute nsIDOMElement header;
|
||||
|
||||
/**
|
||||
* A convenience attribute to obtain the DOM element representing the
|
||||
* SOAP body. DOM methods may be used to add additional attributes to
|
||||
* the body element. DOM methods may also be used to add body entries,
|
||||
* though the expectation is that in most cases the SOAP message will
|
||||
* contain a single body entry created as a result of invoking the
|
||||
* call with a method name and a set of parameters.
|
||||
*/
|
||||
readonly attribute nsIDOMElement body;
|
||||
|
||||
/**
|
||||
* The encodingStyle to be used for the envelope. This URI will be
|
||||
* specified in the SOAP message using the encodingStyle attribute
|
||||
* of the Envelope element.
|
||||
*/
|
||||
attribute string encodingStyleURI;
|
||||
|
||||
/**
|
||||
* The target object on which the method is being invoked. This URI
|
||||
* is used as the namespace to qualify the tagname of the element
|
||||
* that is the single body entry of the SOAP message.
|
||||
*
|
||||
* For example, if the <code>targetObjectURI</code> is
|
||||
* "urn:some-namespace" and the <code>methodName</code> is
|
||||
* GetLastTradePrice, the single body entry will be the
|
||||
* following element:
|
||||
* <code>
|
||||
* <m:GetLastTradePrice xmlns:m="urn:some-namespace">
|
||||
* ...
|
||||
* </code>
|
||||
*
|
||||
*/
|
||||
attribute string targetObjectURI;
|
||||
|
||||
/**
|
||||
* The name of the method being invoked. The methodName is used as
|
||||
* the tagname for the element that is the single body entry of the
|
||||
* SOAP message.
|
||||
*
|
||||
* For example, if the <code>targetObjectURI</code> is
|
||||
* "urn:some-namespace" and the <code>methodName</code> is
|
||||
* GetLastTradePrice, the single body entry will be the
|
||||
* following element:
|
||||
* <code>
|
||||
* <m:GetLastTradePrice xmlns:m="urn:some-namespace">
|
||||
* ...
|
||||
* </code>
|
||||
*/
|
||||
attribute wstring methodName;
|
||||
|
||||
/**
|
||||
* The URI to which the RPC call is made. This does not have to
|
||||
* match the <code>targetObjectURI</code>.
|
||||
*/
|
||||
attribute string destinationURI;
|
||||
|
||||
/**
|
||||
* An optional URI that can be used to add a SOAPAction HTTP
|
||||
* header field. If this attribute is NULL (the default case),
|
||||
* no SOAPAction header will be added.
|
||||
*/
|
||||
attribute string actionURI;
|
||||
|
||||
/**
|
||||
* Native (non-script) method to set the list of parameters to
|
||||
* include in the SOAP call.
|
||||
*
|
||||
* @param parameters The array of parameters to include in the call
|
||||
* @param count The number of parameters in the array
|
||||
*/
|
||||
[noscript] void setSOAPParameters([array, size_is(count)] in nsISOAPParameter parameters, in unsigned long count);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void setParameters(in nsISupports parameters);
|
||||
|
||||
/**
|
||||
* A script-only method for setting the list of parameters, where
|
||||
* the parameters are unnamed and are encoded using the default
|
||||
* encoding style. This method actually expects a variable number
|
||||
* of arguments, each representing an individual parameter - an
|
||||
* actual script type and not a nsISOAPParameter object. This is
|
||||
* purely a convenience for scripters who want unnamed parameters
|
||||
* and don't want to create an array of parameter objects.
|
||||
*/
|
||||
void setSimpleParameters();
|
||||
|
||||
/**
|
||||
* Synchronously make the SOAP call. At this point, the document
|
||||
* rooted by the Envelope element is serialized to form the body
|
||||
* of the SOAP message. The method returns only when we receive
|
||||
* a response (or a protocol error occurs). The expectation is that
|
||||
* at this point the <code>targetObjectURI</code>,
|
||||
* <code>methodName</code>, <code>destinationURI</code> and
|
||||
* parameters (if any) have been set. If this is not the case,
|
||||
* the methods throws and NS_ERROR_NOT_INITIALIZED error.
|
||||
*
|
||||
* @returns The SOAP response
|
||||
*/
|
||||
nsISOAPResponse invoke();
|
||||
|
||||
/**
|
||||
* Asynchronously makes the SOAP call. At this point, the document
|
||||
* rooted by the Envelope element is serialized to form the body
|
||||
* of the SOAP message. The method returns immediately, and the
|
||||
* listener is triggered when we eventually receive a response
|
||||
* (or a protocol error occurs). The expectation is that
|
||||
* at this point the <code>targetObjectURI</code>,
|
||||
* <code>methodName</code>, <code>destinationURI</code> and
|
||||
* parameters (if any) have been set. If this is not the case,
|
||||
* the methods throws and NS_ERROR_NOT_INITIALIZED error.
|
||||
*
|
||||
* @param listener For a native (non-script) invocation of this
|
||||
* method, this should be a nsISOAPResponseListener instance.
|
||||
* For a script invocation of this method, this
|
||||
* is expected to be a Function object.
|
||||
*/
|
||||
void asyncInvoke(in nsISupports listener);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPCALL_CID \
|
||||
{ /* 87d21ec0-539d-11d4-9a59-00104bdf5339 */ \
|
||||
0x87d21ec0, 0x539d, 0x11d4, \
|
||||
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_SOAPCALL_PROGID \
|
||||
"component://netscape/xmlextras/soap/call"
|
||||
%}
|
|
@ -0,0 +1,51 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMElement;
|
||||
interface nsIDOMDocument;
|
||||
interface nsISOAPParameter;
|
||||
|
||||
[scriptable, uuid(99ec6693-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPEncoder : nsISupports {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
nsIDOMElement parameterToElement(in nsISOAPParameter parameter,
|
||||
in string encodingStyle,
|
||||
in nsIDOMDocument document);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
nsISOAPParameter elementToParameter(in nsIDOMElement element,
|
||||
in string encodingStyle);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPENCODER_PROGID \
|
||||
"component://netscape/xmlextras/soap/encoder"
|
||||
#define NS_SOAPENCODER_PROGID_PREFIX NS_SOAPENCODER_PROGID "?encodingStyle="
|
||||
%}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMElement;
|
||||
|
||||
[scriptable, uuid(99ec6694-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPFault : nsISupports {
|
||||
/**
|
||||
* The DOM element representing the fault in the response SOAP message.
|
||||
*/
|
||||
readonly attribute nsIDOMElement element;
|
||||
|
||||
/**
|
||||
* The fault code
|
||||
*/
|
||||
readonly attribute wstring faultCode;
|
||||
|
||||
/**
|
||||
* The fault string
|
||||
*/
|
||||
readonly attribute wstring faultString;
|
||||
|
||||
/**
|
||||
* The fault actor if one was specified.
|
||||
*/
|
||||
readonly attribute wstring faultActor;
|
||||
|
||||
/**
|
||||
* The DOM element representing the fault details
|
||||
*/
|
||||
readonly attribute nsIDOMElement detail;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPFAULT_CID \
|
||||
{ /* 87d21ec1-539d-11d4-9a59-00104bdf5339 */ \
|
||||
0x87d21ec1, 0x539d, 0x11d4, \
|
||||
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_SOAPFAULT_PROGID \
|
||||
"component://netscape/xmlextras/soap/fault"
|
||||
%}
|
|
@ -0,0 +1,150 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
[ptr] native JSObjectPtr(JSObject);
|
||||
|
||||
[scriptable, uuid(99ec6690-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPParameter : nsISupports {
|
||||
|
||||
/**
|
||||
* <p>Possible values for the type of a Parameter object. Native
|
||||
* (non-script) callers must specify the type of a parameter
|
||||
* when setting the value. The list below indicates the native
|
||||
* type expected in each case. Both native and script callers
|
||||
* may query the type of the parameter. The list below also
|
||||
* indicates the native or script type passed back when the
|
||||
* value is retrieved.</p>
|
||||
* <p>Notes:
|
||||
* <ul>
|
||||
* <li><code>PARAMETER_TYPE_STRING</code> - The value is of type
|
||||
* nsISupportsWString for native callers, a JavaScript string
|
||||
* for script callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_BOOLEAN</code> - The value is of type
|
||||
* nsISupportsPRBool for native callers, a boolean for script
|
||||
* callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_DOUBLE</code> - The value is of type
|
||||
* nsISupportsDouble for native callers, a double for script
|
||||
* callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_FLOAT</code> - The value is of type
|
||||
* nsISupportsFloat for native callers, a double for script
|
||||
* callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_LONG</code> - The value is of type
|
||||
* nsISupportsPRInt64 for native callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_INT</code> - The value is of type
|
||||
* nsISupportsPRInt32 for native callers, an integer for
|
||||
* script callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_SHORT</code> - The value is of type
|
||||
* nsISupportsPRInt16 for native callers, an integer for
|
||||
* script callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_BYTE</code> - The value is of type
|
||||
* nsISupportsPRInt8 for native callers, an integer for script
|
||||
* callers.</li>
|
||||
* <li><code>PARAMETER_TYPE_ARRAY</code> - The value is of type
|
||||
* nsISupportsArray for native callers (each element is itself
|
||||
* an instance of nsISOAPParameter).</li>
|
||||
* <li><code>PARAMETER_TYPE_JAVASCRIPT_ARRAY</code> - The value is
|
||||
* a JSObject that is an array.</li>
|
||||
* <li><code>PARAMETER_TYPE_JAVASCRIPT_OBJECT</code> - The value is
|
||||
* a generic JSObject.</li>
|
||||
* </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;
|
||||
|
||||
/**
|
||||
* An optional encodingStyle specifically for this parameter. The
|
||||
* default is to inherit the encodingStyle from the element parent
|
||||
* chain.
|
||||
*/
|
||||
attribute string encodingStyleURI;
|
||||
|
||||
/**
|
||||
* The name of the parameter. If the parameter is left unnamed, it
|
||||
* will be encoded using the element types defined in the SOAP-ENC
|
||||
* schema. For example, <code><SOAP-ENC:int>45</SOAP-ENC:int>
|
||||
*/
|
||||
attribute wstring name;
|
||||
|
||||
/**
|
||||
* The type of the parameter. See the descriptions for the type
|
||||
* constants for details.
|
||||
*/
|
||||
readonly attribute long type;
|
||||
|
||||
/**
|
||||
* Native (non-script) method for setting the value 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 The value of the parameter. Either NULL or an object
|
||||
* that implements an interface specified by the
|
||||
* <code>type</code> parameter.
|
||||
* @param type The type of the parameter. See the description of
|
||||
* the type contants for details.
|
||||
*/
|
||||
[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
|
||||
* <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.
|
||||
*/
|
||||
readonly attribute nsISupports value;
|
||||
|
||||
/**
|
||||
* Used by native callers (SOAP encoders, for example) to retrieve
|
||||
* the JSObject value if the <code>type</code> attribute is either
|
||||
* <code>PARAMETER_TYPE_JAVASCRIPT_ARRAY</code> or
|
||||
* <code>PARAMETER_TYPE_JAVASCRIPT_OBJECT</code>.
|
||||
*/
|
||||
[noscript] readonly attribute JSObjectPtr JSValue;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPPARAMETER_CID \
|
||||
{ /* 87d21ec2-539d-11d4-9a59-00104bdf5339 */ \
|
||||
0x87d21ec2, 0x539d, 0x11d4, \
|
||||
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_SOAPCPARAMETER_PROGID \
|
||||
"component://netscape/xmlextras/soap/parameter"
|
||||
%}
|
|
@ -0,0 +1,103 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMElement;
|
||||
interface nsISOAPParameter;
|
||||
interface nsISOAPFault;
|
||||
|
||||
[scriptable, uuid(99ec6691-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPResponse : nsISupports {
|
||||
|
||||
/**
|
||||
* The DOM element representing the SOAP envelope in the response.
|
||||
* DOM methods may be used to access attributes and children of this
|
||||
* element. While the element and it's subtree are not readonly,
|
||||
* the expectation is that they will not be modified.
|
||||
*/
|
||||
readonly attribute nsIDOMElement envelope;
|
||||
|
||||
/**
|
||||
* A convenience attribute to obtain the DOM element representing
|
||||
* the response envelope header, if one exists. NULL if no header
|
||||
* exists in the response.
|
||||
*/
|
||||
readonly attribute nsIDOMElement header;
|
||||
|
||||
/**
|
||||
* A convenience attribute to obtain the DOM element representing
|
||||
* the response envelope body. While DOM interfaces and methods may
|
||||
* be used to access body entries, the expectation is that the
|
||||
* <code>returnValue</code> property will be used if the response
|
||||
* represents the result of a RPC call.
|
||||
*/
|
||||
readonly attribute nsIDOMElement body;
|
||||
|
||||
/**
|
||||
* The status code returned by the underlying transport.
|
||||
*/
|
||||
readonly attribute unsigned long status;
|
||||
|
||||
/**
|
||||
* The target object on which the method was invoked. This URI
|
||||
* is generally used as the namespace to qualify the tagname of
|
||||
* the element that is the single body entry of the SOAP response.
|
||||
*/
|
||||
readonly attribute string targetObjectURI;
|
||||
|
||||
/**
|
||||
* The name of the method that was invoked. The methodName is used as
|
||||
* the tagname for the element that is the single body entry of the
|
||||
* SOAP message.
|
||||
*/
|
||||
readonly attribute string methodName;
|
||||
|
||||
/**
|
||||
* Did the response generate a fault?
|
||||
*
|
||||
* @returns Whether a fault was generated a not. If the return value
|
||||
* is <code>true</code>, the fault details can be obtained
|
||||
* from the <code>fault</code> property.
|
||||
*/
|
||||
boolean generatedFault();
|
||||
|
||||
/**
|
||||
* The fault returned in the response, if one was generated. NULL
|
||||
* if there was no fault.
|
||||
*/
|
||||
readonly attribute nsISOAPFault fault;
|
||||
|
||||
/**
|
||||
* The result from the first body entry in the response SOAP message.
|
||||
*/
|
||||
readonly attribute nsISOAPParameter returnValue;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPRESPONSE_CID \
|
||||
{ /* 87d21ec3-539d-11d4-9a59-00104bdf5339 */ \
|
||||
0x87d21ec3, 0x539d, 0x11d4, \
|
||||
{0x9a, 0x59, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_SOAPRESPONSE_PROGID \
|
||||
"component://netscape/xmlextras/soap/response"
|
||||
%}
|
|
@ -0,0 +1,42 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsISOAPCall;
|
||||
interface nsISOAPResponse;
|
||||
|
||||
[scriptable, uuid(99ec6692-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPResponseListener : nsISupports {
|
||||
/**
|
||||
* This method is invoked when we receive an asynchronous response to
|
||||
* a SOAP message. The listener is registered as part of the original
|
||||
* asynchronous call invocation.
|
||||
*
|
||||
* @param response The decoded version of the response
|
||||
* @param call The SOAPCall object that triggered the response
|
||||
* @param result The result code from the call
|
||||
*/
|
||||
void handleResponse(in nsISOAPResponse response,
|
||||
in nsISOAPCall call,
|
||||
in nsresult result);
|
||||
};
|
|
@ -0,0 +1,44 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMDocument;
|
||||
interface nsISOAPTransportListener;
|
||||
|
||||
[scriptable, uuid(99ec6695-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPTransport : nsISupports {
|
||||
boolean canDoSync();
|
||||
nsIDOMDocument syncCall(in string url,
|
||||
in string action,
|
||||
in nsIDOMDocument messageDocument);
|
||||
void asyncCall(in string url,
|
||||
in string action,
|
||||
in nsIDOMDocument messageDocument,
|
||||
in nsISOAPTransportListener listener);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
#define NS_SOAPTRANSPORT_PROGID \
|
||||
"component://netscape/xmlextras/soap/transport"
|
||||
#define NS_SOAPTRANSPORT_PROGID_PREFIX NS_SOAPTRANSPORT_PROGID "?protocol="
|
||||
%}
|
|
@ -0,0 +1,42 @@
|
|||
/* -*- 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 "nsISupports.idl"
|
||||
|
||||
interface nsIDOMDocument;
|
||||
|
||||
[scriptable, uuid(99ec6696-535f-11d4-9a58-000064657374)]
|
||||
interface nsISOAPTransportListener : nsISupports {
|
||||
/**
|
||||
* This method is invoked when an ansynchronous response is
|
||||
* completed. The listener is registered as part of the original
|
||||
* call to the transport.
|
||||
*
|
||||
* @param document The XML document that is the body of the response
|
||||
* @param status The protocol status returned
|
||||
* @param result The call result
|
||||
*/
|
||||
void handleResponse(in nsIDOMDocument document,
|
||||
in unsigned long status,
|
||||
in nsresult result);
|
||||
};
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#
|
||||
# The contents of this file are subject to the Mozilla 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/MPL/
|
||||
#
|
||||
# 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):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xmlextras
|
||||
LIBRARY_NAME = xmlextrassoap_s
|
||||
|
||||
CPPSRCS = \
|
||||
nsSOAPCall.cpp \
|
||||
nsSOAPResponse.cpp \
|
||||
nsSOAPUtils.cpp \
|
||||
nsSOAPFault.cpp \
|
||||
nsSOAPParameter.cpp \
|
||||
nsDefaultSOAPEncoder.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
# static lib.
|
||||
override NO_SHARED_LIB=1
|
||||
override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,65 @@
|
|||
#!nmake
|
||||
#
|
||||
# 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):
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
LIBRARY_NAME=xmlextrassoap_s
|
||||
MODULE=xmlextras
|
||||
|
||||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
CPPSRCS= \
|
||||
nsSOAPCall.cpp \
|
||||
nsSOAPResponse.cpp \
|
||||
nsSOAPUtils.cpp \
|
||||
nsSOAPFault.cpp \
|
||||
nsSOAPParameter.cpp \
|
||||
nsDefaultSOAPEncoder.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsSOAPCall.obj \
|
||||
.\$(OBJDIR)\nsSOAPResponse.obj \
|
||||
.\$(OBJDIR)\nsSOAPUtils.obj \
|
||||
.\$(OBJDIR)\nsSOAPFault.obj \
|
||||
.\$(OBJDIR)\nsSOAPParameter.obj \
|
||||
.\$(OBJDIR)\nsDefaultSOAPEncoder.obj \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \
|
||||
-I$(PUBLIC)\dom -I$(PUBLIC)\uconv
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
|
@ -0,0 +1,71 @@
|
|||
/* -*- 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 "nsDefaultSOAPEncoder.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
|
||||
|
||||
nsDefaultSOAPEncoder::nsDefaultSOAPEncoder()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsDefaultSOAPEncoder::~nsDefaultSOAPEncoder()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsDefaultSOAPEncoder, nsISOAPEncoder)
|
||||
|
||||
/* nsIDOMElement parameterToElement (in nsISOAPParameter parameter, in string encodingStyle, in nsIDOMDocument document); */
|
||||
NS_IMETHODIMP
|
||||
nsDefaultSOAPEncoder::ParameterToElement(nsISOAPParameter *parameter,
|
||||
const char *encodingStyle,
|
||||
nsIDOMDocument *document,
|
||||
nsIDOMElement **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(parameter);
|
||||
NS_ENSURE_ARG(encodingStyle);
|
||||
NS_ENSURE_ARG(document);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
|
||||
PRInt32 type;
|
||||
parameter->GetType(&type);
|
||||
|
||||
XPIDLString name;
|
||||
parameter->GetName(getter_Copies(name));
|
||||
|
||||
// If it's an unnamed parameter, we use the type names defined
|
||||
// by SOAP
|
||||
if (!name) {
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* nsISOAPParameter elementToParameter (in nsIDOMElement element, in string encodingStyle); */
|
||||
NS_IMETHODIMP
|
||||
nsDefaultSOAPEncoder::ElementToParameter(nsIDOMElement *element,
|
||||
const char *encodingStyle,
|
||||
nsISOAPParameter **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/* -*- 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 nsDefaultSOAPEncoder_h__
|
||||
#define nsDefaultSOAPEncoder_h__
|
||||
|
||||
#include "nsISOAPEncoder.h"
|
||||
|
||||
class nsDefaultSOAPEncoder : public nsISOAPEncoder {
|
||||
public:
|
||||
nsDefaultSOAPEncoder();
|
||||
virtual ~nsDefaultSOAPEncoder();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPEncoder
|
||||
NS_DECL_NSISOAPENCODER
|
||||
};
|
||||
|
||||
#define NS_DEFAULTSOAPENCODER_CID \
|
||||
{ /* 0b6e6ef0-56c4-11d4-9a5e-00104bdf5339 */ \
|
||||
0x0b6e6ef0, 0x56c4, 0x11d4, \
|
||||
{0x9a, 0x5e, 0x00, 0x10, 0x4b, 0xdf, 0x53, 0x39} }
|
||||
#define NS_DEFAULTSOAPENCODER_PROGID NS_SOAPENCODER_PROGID_PREFIX "http://schemas.xmlsoap.org/soap/encoding/"
|
||||
|
||||
#endif
|
|
@ -0,0 +1,880 @@
|
|||
/* -*- 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 "nsSOAPCall.h"
|
||||
#include "nsSOAPResponse.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
#include "nsCRT.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsIDOMParser.h"
|
||||
#include "nsISOAPEncoder.h"
|
||||
#include "nsISOAPParameter.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
static NS_DEFINE_CID(kDOMParserCID, NS_DOMPARSER_CID);
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
/////////////////////////////////////////////
|
||||
|
||||
class nsScriptResponseListener : public nsISOAPResponseListener
|
||||
{
|
||||
public:
|
||||
nsScriptResponseListener(JSObject* aScopeObj, JSObject* aFunctionObj);
|
||||
~nsScriptResponseListener();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPResponseListener
|
||||
NS_DECL_NSISOAPRESPONSELISTENER
|
||||
|
||||
protected:
|
||||
JSObject* mScopeObj;
|
||||
JSObject* mFunctionObj;
|
||||
};
|
||||
|
||||
nsScriptResponseListener::nsScriptResponseListener(JSObject* aScopeObj,
|
||||
JSObject* aFunctionObj)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
// We don't have to add a GC root for the scope object
|
||||
// since we'll go away if it goes away
|
||||
mScopeObj = aScopeObj;
|
||||
mFunctionObj = aFunctionObj;
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
if (cx) {
|
||||
JS_AddNamedRoot(cx, &mFunctionObj, "nsSOAPCall");
|
||||
}
|
||||
}
|
||||
|
||||
nsScriptResponseListener::~nsScriptResponseListener()
|
||||
{
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
if (cx) {
|
||||
JS_RemoveRoot(cx, &mFunctionObj);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsScriptResponseListener,
|
||||
nsISOAPResponseListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptResponseListener::HandleResponse(nsISOAPResponse* aResponse,
|
||||
nsISOAPCall* aCall,
|
||||
nsresult aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetCurrentContext();
|
||||
if (!cx) {
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
}
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIXPConnect> xpc =
|
||||
do_GetService(nsIXPConnect::GetCID());
|
||||
if (!xpc) return NS_OK;
|
||||
|
||||
jsval params[3];
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
|
||||
JSObject* obj;
|
||||
|
||||
// Get the JSObject wrapper for the response
|
||||
rv = xpc->WrapNative(cx, mScopeObj,
|
||||
aResponse, NS_GET_IID(nsISOAPResponse),
|
||||
getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv)) return NS_OK;
|
||||
|
||||
rv = holder->GetJSObject(&obj);
|
||||
if (!obj) return NS_OK;
|
||||
|
||||
params[0] = OBJECT_TO_JSVAL(obj);
|
||||
|
||||
// Get the JSObject wrapper for the call
|
||||
rv = xpc->WrapNative(cx, mScopeObj,
|
||||
aCall, NS_GET_IID(nsISOAPCall),
|
||||
getter_AddRefs(holder));
|
||||
if (NS_FAILED(rv)) return NS_OK;
|
||||
|
||||
rv = holder->GetJSObject(&obj);
|
||||
if (!obj) return NS_OK;
|
||||
|
||||
params[1] = OBJECT_TO_JSVAL(obj);
|
||||
|
||||
params[2] = INT_TO_JSVAL(aResult);
|
||||
|
||||
jsval val;
|
||||
JS_CallFunctionValue(cx, mScopeObj, OBJECT_TO_JSVAL(mFunctionObj),
|
||||
3, params, &val);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
/////////////////////////////////////////////
|
||||
|
||||
nsSOAPCall::nsSOAPCall()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsSOAPCall::~nsSOAPCall()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsSOAPCall,
|
||||
nsISOAPCall,
|
||||
nsISecurityCheckedComponent,
|
||||
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/\">"
|
||||
"<SOAP-ENV:Header>"
|
||||
"</SOAP-ENV:Header>"
|
||||
"<SOAP-ENV:Body>"
|
||||
"</SOAP-ENV:Body>"
|
||||
"</SOAP-ENV:Envelope>";
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::EnsureDocumentAllocated()
|
||||
{
|
||||
if (!mEnvelopeDocument) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIDOMParser> parser = do_CreateInstance(kDOMParserCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString docstr;
|
||||
docstr.AssignWithConversion(kEmptySOAPDocStr);
|
||||
rv = parser->ParseFromString(docstr.GetUnicode(), "text/xml",
|
||||
getter_AddRefs(mEnvelopeDocument));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
mEnvelopeDocument->GetDocumentElement(getter_AddRefs(mEnvelopeElement));
|
||||
if (!mEnvelopeElement) return NS_ERROR_FAILURE;
|
||||
|
||||
nsSOAPUtils::GetFirstChildElement(mEnvelopeElement,
|
||||
getter_AddRefs(mHeaderElement));
|
||||
if (!mHeaderElement) return NS_ERROR_FAILURE;
|
||||
|
||||
nsSOAPUtils::GetNextSiblingElement(mHeaderElement,
|
||||
getter_AddRefs(mBodyElement));
|
||||
if (!mBodyElement) return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement envelope; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetEnvelope(nsIDOMElement * *aEnvelope)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEnvelope);
|
||||
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aEnvelope = mEnvelopeElement;
|
||||
NS_ADDREF(*aEnvelope);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement header; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetHeader(nsIDOMElement * *aHeader)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aHeader);
|
||||
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aHeader = mHeaderElement;
|
||||
NS_ADDREF(*aHeader);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement body; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetBody(nsIDOMElement * *aBody)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBody);
|
||||
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aBody = mBodyElement;
|
||||
NS_ADDREF(*aBody);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string encodingStyleURI; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetEncodingStyleURI(char * *aEncodingStyleURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEncodingStyleURI);
|
||||
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString value;
|
||||
rv = mEnvelopeElement->GetAttributeNS(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI),
|
||||
NS_ConvertASCIItoUCS2(nsSOAPUtils::kEncodingStyleAttribute),
|
||||
value);
|
||||
|
||||
if (value.Length() > 0) {
|
||||
*aEncodingStyleURI = value.ToNewCString();
|
||||
if (nsnull == *aEncodingStyleURI) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*aEncodingStyleURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSOAPCall::SetEncodingStyleURI(const char * aEncodingStyleURI)
|
||||
{
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (nsnull == aEncodingStyleURI) {
|
||||
mEnvelopeElement->RemoveAttributeNS(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI),
|
||||
NS_ConvertASCIItoUCS2(nsSOAPUtils::kEncodingStyleAttribute));
|
||||
}
|
||||
else {
|
||||
mEnvelopeElement->SetAttributeNS(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI),
|
||||
NS_ConvertASCIItoUCS2(nsSOAPUtils::kEncodingStyleAttribute),
|
||||
NS_ConvertASCIItoUCS2(aEncodingStyleURI));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsSOAPCall::HasBodyEntry()
|
||||
{
|
||||
if (!mBodyElement) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMElement> entry;
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement, getter_AddRefs(entry));
|
||||
|
||||
if (entry) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::CreateBodyEntry(PRBool aNewParameters)
|
||||
{
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Create the element that will be the new body entry
|
||||
nsCOMPtr<nsIDOMElement> entry;
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
|
||||
rv = mEnvelopeDocument->CreateElementNS(NS_ConvertASCIItoUCS2(mTargetObjectURI.GetBuffer()),
|
||||
mMethodName, getter_AddRefs(entry));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
// See if there's an existing body entry (we only worry
|
||||
// about the first).
|
||||
nsCOMPtr<nsIDOMElement> oldEntry;
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement, getter_AddRefs(oldEntry));
|
||||
|
||||
// If there is, we're going to replace it, but preserve its
|
||||
// children.
|
||||
if (entry) {
|
||||
// Remove the old entry from the body
|
||||
mBodyElement->RemoveChild(oldEntry, getter_AddRefs(dummy));
|
||||
|
||||
if (!aNewParameters) {
|
||||
// Transfer the children from the old to the new
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
oldEntry->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
oldEntry->RemoveChild(child, getter_AddRefs(dummy));
|
||||
entry->AppendChild(child, getter_AddRefs(dummy));
|
||||
|
||||
nsCOMPtr<nsIDOMNode> temp = child;
|
||||
temp->GetNextSibling(getter_AddRefs(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mBodyElement->AppendChild(entry, getter_AddRefs(dummy));
|
||||
|
||||
// If there wasn't an old entry and we have parameters, or we
|
||||
// we have new parameters, create the parameter elements.
|
||||
if ((!entry && mParameters) || aNewParameters) {
|
||||
rv = CreateParameterElements();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string targetObjectURI; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetTargetObjectURI(char * *aTargetObjectURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aTargetObjectURI);
|
||||
|
||||
if (mTargetObjectURI.Length() > 0) {
|
||||
*aTargetObjectURI = mTargetObjectURI.ToNewCString();
|
||||
}
|
||||
else {
|
||||
*aTargetObjectURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPCall::SetTargetObjectURI(const char * aTargetObjectURI)
|
||||
{
|
||||
NS_ENSURE_ARG(aTargetObjectURI);
|
||||
|
||||
mTargetObjectURI.Assign(aTargetObjectURI);
|
||||
if ((mTargetObjectURI.Length() > 0) && (mMethodName.Length() > 0)) {
|
||||
return CreateBodyEntry(PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string methodName; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetMethodName(PRUnichar * *aMethodName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aMethodName);
|
||||
|
||||
if (mMethodName.Length() > 0) {
|
||||
*aMethodName = mMethodName.ToNewUnicode();
|
||||
}
|
||||
else {
|
||||
*aMethodName = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPCall::SetMethodName(const PRUnichar * aMethodName)
|
||||
{
|
||||
NS_ENSURE_ARG(aMethodName);
|
||||
|
||||
mMethodName.Assign(aMethodName);
|
||||
if ((mTargetObjectURI.Length() > 0) && (mMethodName.Length() > 0)) {
|
||||
return CreateBodyEntry(PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string destinationURI; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetDestinationURI(char * *aDestinationURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDestinationURI);
|
||||
|
||||
if (mDestinationURI.Length() > 0) {
|
||||
*aDestinationURI = mDestinationURI.ToNewCString();
|
||||
}
|
||||
else {
|
||||
*aDestinationURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPCall::SetDestinationURI(const char * aDestinationURI)
|
||||
{
|
||||
if (aDestinationURI) {
|
||||
mDestinationURI.Assign(aDestinationURI);
|
||||
}
|
||||
else {
|
||||
mDestinationURI.Truncate();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute string actionURI; */
|
||||
NS_IMETHODIMP nsSOAPCall::GetActionURI(char * *aActionURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aActionURI);
|
||||
|
||||
if (mActionURI.Length() > 0) {
|
||||
*aActionURI = mActionURI.ToNewCString();
|
||||
}
|
||||
else {
|
||||
*aActionURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPCall::SetActionURI(const char * aActionURI)
|
||||
{
|
||||
if (aActionURI) {
|
||||
mActionURI.Assign(aActionURI);
|
||||
}
|
||||
else {
|
||||
mActionURI.Truncate();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::CreateParameterElements()
|
||||
{
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get the body entry that's going to be the parent of
|
||||
// the parameter elements. If we got here, there should
|
||||
// be one.
|
||||
nsCOMPtr<nsIDOMElement> entry;
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement, getter_AddRefs(entry));
|
||||
if (!entry) return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the inherited encoding style starting from the
|
||||
// body entry.
|
||||
nsXPIDLCString encodingStyle;
|
||||
nsSOAPUtils::GetInheritedEncodingStyle(entry, getter_Copies(encodingStyle));
|
||||
|
||||
// Find the corresponding encoder
|
||||
nsCAutoString encoderProgid;
|
||||
encoderProgid.Assign(NS_SOAPENCODER_PROGID_PREFIX);
|
||||
encoderProgid.Append(encodingStyle);
|
||||
|
||||
nsCOMPtr<nsISOAPEncoder> encoder = do_CreateInstance(encoderProgid);
|
||||
if (!encoder) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
PRUint32 index, count;
|
||||
mParameters->Count(&count);
|
||||
|
||||
for(index = 0; index < count; index++) {
|
||||
nsCOMPtr<nsISupports> isup = getter_AddRefs(mParameters->ElementAt(index));
|
||||
nsCOMPtr<nsISOAPParameter> parameter = do_QueryInterface(isup);
|
||||
|
||||
if (parameter) {
|
||||
nsCOMPtr<nsISOAPEncoder> paramEncoder = encoder;
|
||||
|
||||
// See if the parameter has its own encoding style
|
||||
nsXPIDLCString paramEncoding;
|
||||
parameter->GetEncodingStyleURI(getter_Copies(paramEncoding));
|
||||
|
||||
// If it does and it's different from the inherited one,
|
||||
// find an encoder
|
||||
if (paramEncoding &&
|
||||
(nsCRT::strcmp(encodingStyle, paramEncoding) != 0)) {
|
||||
nsCAutoString paramEncoderProgid;
|
||||
paramEncoderProgid.Assign(NS_SOAPENCODER_PROGID_PREFIX);
|
||||
paramEncoderProgid.Append(paramEncoding);
|
||||
|
||||
paramEncoder = do_CreateInstance(paramEncoderProgid);
|
||||
if (!paramEncoder) return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Convert the parameter to an element
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
encoder->ParameterToElement(parameter,
|
||||
paramEncoding ? paramEncoding : encodingStyle,
|
||||
mEnvelopeDocument,
|
||||
getter_AddRefs(element));
|
||||
|
||||
// Append the parameter element to the body entry
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
entry->AppendChild(element, getter_AddRefs(dummy));
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::ClearParameterElements()
|
||||
{
|
||||
nsresult rv = EnsureDocumentAllocated();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get the body entry that's the parent of the parameter
|
||||
// elements (assuming there is one)
|
||||
nsCOMPtr<nsIDOMElement> entry;
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement, getter_AddRefs(entry));
|
||||
|
||||
if (entry) {
|
||||
// Get rid of all the children of the body entry
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
entry->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
nsCOMPtr<nsIDOMNode> dummy;
|
||||
entry->RemoveChild(child, getter_AddRefs(dummy));
|
||||
entry->GetFirstChild(getter_AddRefs(child));
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [noscript] void setSOAPParameters ([array, size_is (count)] in nsISOAPParameter parameters, in unsigned long count); */
|
||||
NS_IMETHODIMP nsSOAPCall::SetSOAPParameters(nsISOAPParameter **parameters, PRUint32 count)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Clear out any existing parameters
|
||||
if (mParameters) {
|
||||
ClearParameterElements();
|
||||
mParameters->Clear();
|
||||
}
|
||||
else {
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mParameters));
|
||||
if (!mParameters) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
PRUint32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsISOAPParameter* parameter = parameters[index];
|
||||
if (parameter) {
|
||||
mParameters->AppendElement(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBodyEntry()) {
|
||||
return CreateParameterElements();
|
||||
}
|
||||
else if ((mTargetObjectURI.Length() > 0) && (mMethodName.Length() > 0)) {
|
||||
return CreateBodyEntry(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setParameters (in nsISupports parameters); */
|
||||
NS_IMETHODIMP nsSOAPCall::SetParameters(nsISupports *parameters)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// Clear out any existing parameters
|
||||
if (mParameters) {
|
||||
ClearParameterElements();
|
||||
mParameters->Clear();
|
||||
}
|
||||
else {
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(mParameters));
|
||||
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);
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIXPCNativeCallContext> cc;
|
||||
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (HasBodyEntry()) {
|
||||
return CreateParameterElements();
|
||||
}
|
||||
else if ((mTargetObjectURI.Length() > 0) && (mMethodName.Length() > 0)) {
|
||||
return CreateBodyEntry(PR_TRUE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void setSimpleParameters (); */
|
||||
NS_IMETHODIMP nsSOAPCall::SetSimpleParameters()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::GetTransport(nsISOAPTransport** aTransport)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsXPIDLCString protocol;
|
||||
|
||||
rv = NS_NewURI(getter_AddRefs(uri), mDestinationURI.GetBuffer());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
uri->GetScheme(getter_Copies(protocol));
|
||||
|
||||
nsCAutoString transportProgid;
|
||||
transportProgid.Assign(NS_SOAPTRANSPORT_PROGID_PREFIX);
|
||||
transportProgid.Append(protocol);
|
||||
|
||||
nsCOMPtr<nsISOAPTransport> transport = do_CreateInstance(transportProgid);
|
||||
if (!transport) return NS_ERROR_INVALID_ARG;
|
||||
|
||||
*aTransport = transport.get();
|
||||
NS_ADDREF(*aTransport);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* nsISOAPResponse invoke (); */
|
||||
NS_IMETHODIMP nsSOAPCall::Invoke(nsISOAPResponse **_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISOAPTransport> transport;
|
||||
|
||||
if (mDestinationURI.Length() == 0) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
rv = GetTransport(getter_AddRefs(transport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool canDoSync;
|
||||
transport->CanDoSync(&canDoSync);
|
||||
|
||||
if (!canDoSync) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> responseDocument;
|
||||
rv = transport->SyncCall(mDestinationURI,
|
||||
mActionURI,
|
||||
mEnvelopeDocument,
|
||||
getter_AddRefs(responseDocument));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsSOAPResponse* response;
|
||||
response = new nsSOAPResponse(responseDocument);
|
||||
if (!response) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return response->QueryInterface(NS_GET_IID(nsISOAPResponse), (void**)_retval);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPCall::GetScriptListener(nsISupports* aObject,
|
||||
nsISOAPResponseListener** aListener)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIXPCNativeCallContext> cc;
|
||||
NS_WITH_SERVICE(nsIXPConnect, xpc, nsIXPConnect::GetCID(), &rv);
|
||||
if(NS_SUCCEEDED(rv)) {
|
||||
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(cc));
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv) && cc) {
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> jsobjholder = do_QueryInterface(aObject);
|
||||
if (jsobjholder) {
|
||||
JSObject* funobj;
|
||||
rv = jsobjholder->GetJSObject(&funobj);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
JSContext* cx;
|
||||
rv = cc->GetJSContext(&cx);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
JSFunction* fun = JS_ValueToFunction(cx, OBJECT_TO_JSVAL(funobj));
|
||||
if (!fun) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
||||
rv = cc->GetCalleeWrapper(getter_AddRefs(wrapper));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
JSObject* scopeobj;
|
||||
rv = wrapper->GetJSObject(&scopeobj);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsScriptResponseListener* listener = new nsScriptResponseListener(scopeobj, funobj);
|
||||
if (!listener) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
*aListener = listener;
|
||||
NS_ADDREF(*aListener);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void asyncInvoke (in nsISupports listener); */
|
||||
NS_IMETHODIMP nsSOAPCall::AsyncInvoke(nsISupports *listener)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISOAPTransport> transport;
|
||||
|
||||
if (mDestinationURI.Length() == 0) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
rv = GetTransport(getter_AddRefs(transport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mListener = do_QueryInterface(listener);
|
||||
// We first try to do a direct QI, if that doesn't work
|
||||
// maybe it's a script event listener
|
||||
if (!mListener) {
|
||||
rv = GetScriptListener(listener, getter_AddRefs(mListener));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rv = transport->AsyncCall(mDestinationURI,
|
||||
mActionURI,
|
||||
mEnvelopeDocument,
|
||||
this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* void handleResponse (in nsIDOMDocument document, in unsigned long status); */
|
||||
NS_IMETHODIMP nsSOAPCall::HandleResponse(nsIDOMDocument *document, PRUint32 status, nsresult result)
|
||||
{
|
||||
if (mListener) {
|
||||
nsCOMPtr<nsISOAPResponse> response;
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsSOAPResponse* respobj;
|
||||
respobj = new nsSOAPResponse(document);
|
||||
if (!respobj) result = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
response = (nsISOAPResponse*)respobj;
|
||||
}
|
||||
|
||||
mListener->HandleResponse(response,
|
||||
this,
|
||||
result);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static const char* kAllAccess = "AllAccess";
|
||||
|
||||
/* string canCreateWrapper (in nsIIDPtr iid); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPCall::CanCreateWrapper(const nsIID * iid, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPCall))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPCall::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPCall))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPCall::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPCall))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPCall::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPCall))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/* -*- 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 nsSOAPCall_h__
|
||||
#define nsSOAPCall_h__
|
||||
|
||||
#include "nsISOAPCall.h"
|
||||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsISOAPTransportListener.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsISOAPResponseListener.h"
|
||||
#include "nsISOAPTransport.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsSOAPCall : public nsISOAPCall,
|
||||
public nsISecurityCheckedComponent,
|
||||
public nsISOAPTransportListener
|
||||
{
|
||||
public:
|
||||
nsSOAPCall();
|
||||
virtual ~nsSOAPCall();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPCall
|
||||
NS_DECL_NSISOAPCALL
|
||||
|
||||
// nsISecurityCheckedComponent
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
// nsISOAPTransportListener
|
||||
NS_DECL_NSISOAPTRANSPORTLISTENER
|
||||
|
||||
protected:
|
||||
|
||||
nsresult EnsureDocumentAllocated();
|
||||
PRBool HasBodyEntry();
|
||||
nsresult CreateBodyEntry(PRBool aNewParameters);
|
||||
nsresult CreateParameterElements();
|
||||
nsresult ClearParameterElements();
|
||||
nsresult GetTransport(nsISOAPTransport** aTransport);
|
||||
nsresult GetScriptListener(nsISupports* aObject,
|
||||
nsISOAPResponseListener** aListener);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> mEnvelopeDocument;
|
||||
nsCOMPtr<nsIDOMElement> mEnvelopeElement;
|
||||
nsCOMPtr<nsIDOMElement> mHeaderElement;
|
||||
nsCOMPtr<nsIDOMElement> mBodyElement;
|
||||
nsCString mDestinationURI;
|
||||
nsCString mActionURI;
|
||||
nsCString mTargetObjectURI;
|
||||
nsString mMethodName;
|
||||
nsCOMPtr<nsISupportsArray> mParameters;
|
||||
nsCOMPtr<nsISOAPResponseListener> mListener;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,170 @@
|
|||
/* -*- 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 "nsSOAPFault.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
|
||||
nsSOAPFault::nsSOAPFault(nsIDOMElement* aElement)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mFaultElement = aElement;
|
||||
}
|
||||
|
||||
nsSOAPFault::~nsSOAPFault()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSOAPFault, nsISOAPFault, nsISecurityCheckedComponent)
|
||||
|
||||
/* readonly attribute nsIDOMElement element; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetElement(nsIDOMElement * *aElement)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aElement);
|
||||
*aElement = mFaultElement;
|
||||
NS_IF_ADDREF(*aElement);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute wstring faultCode; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetFaultCode(PRUnichar * *aFaultCode)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFaultCode);
|
||||
|
||||
*aFaultCode = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
|
||||
nsAutoString tagname;
|
||||
tagname.AssignWithConversion(nsSOAPUtils::kFaultCodeTagName);
|
||||
mFaultElement->GetElementsByTagName(tagname, getter_AddRefs(list));
|
||||
PRUint32 length;
|
||||
list->GetLength(&length);
|
||||
if (length > 0) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
|
||||
list->Item(0, getter_AddRefs(node));
|
||||
element = do_QueryInterface(node);
|
||||
|
||||
nsAutoString text;
|
||||
nsSOAPUtils::GetElementTextContent(element, text);
|
||||
if (text.Length() > 0) {
|
||||
*aFaultCode = text.ToNewUnicode();
|
||||
if (!*aFaultCode) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute wstring faultString; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetFaultString(PRUnichar * *aFaultString)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFaultString);
|
||||
|
||||
*aFaultString = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
|
||||
nsAutoString tagname;
|
||||
tagname.AssignWithConversion(nsSOAPUtils::kFaultStringTagName);
|
||||
mFaultElement->GetElementsByTagName(tagname, getter_AddRefs(list));
|
||||
PRUint32 length;
|
||||
list->GetLength(&length);
|
||||
if (length > 0) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
|
||||
list->Item(0, getter_AddRefs(node));
|
||||
element = do_QueryInterface(node);
|
||||
|
||||
nsAutoString text;
|
||||
nsSOAPUtils::GetElementTextContent(element, text);
|
||||
if (text.Length() > 0) {
|
||||
*aFaultString = text.ToNewUnicode();
|
||||
if (!*aFaultString) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute wstring faultActor; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetFaultActor(PRUnichar * *aFaultActor)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFaultActor);
|
||||
|
||||
*aFaultActor = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
|
||||
nsAutoString tagname;
|
||||
tagname.AssignWithConversion(nsSOAPUtils::kFaultActorTagName);
|
||||
mFaultElement->GetElementsByTagName(tagname, getter_AddRefs(list));
|
||||
PRUint32 length;
|
||||
list->GetLength(&length);
|
||||
if (length > 0) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
|
||||
list->Item(0, getter_AddRefs(node));
|
||||
element = do_QueryInterface(node);
|
||||
|
||||
nsAutoString text;
|
||||
nsSOAPUtils::GetElementTextContent(element, text);
|
||||
if (text.Length() > 0) {
|
||||
*aFaultActor = text.ToNewUnicode();
|
||||
if (!*aFaultActor) return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement detail; */
|
||||
NS_IMETHODIMP nsSOAPFault::GetDetail(nsIDOMElement * *aDetail)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDetail);
|
||||
|
||||
*aDetail = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsCOMPtr<nsIDOMNodeList> list;
|
||||
|
||||
nsAutoString tagname;
|
||||
tagname.AssignWithConversion(nsSOAPUtils::kFaultDetailTagName);
|
||||
mFaultElement->GetElementsByTagName(tagname, getter_AddRefs(list));
|
||||
PRUint32 length;
|
||||
list->GetLength(&length);
|
||||
if (length > 0) {
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
|
||||
list->Item(0, getter_AddRefs(node));
|
||||
return node->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aDetail);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/* -*- 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 nsSOAPFault_h__
|
||||
#define nsSOAPFault_h__
|
||||
|
||||
#include "nsISOAPFault.h"
|
||||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsSOAPFault : public nsISOAPFault,
|
||||
public nsISecurityCheckedComponent
|
||||
{
|
||||
public:
|
||||
nsSOAPFault(nsIDOMElement* aElement);
|
||||
virtual ~nsSOAPFault();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPFault
|
||||
NS_DECL_NSISOAPFAULT
|
||||
|
||||
// nsISecurityCheckedComponent
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIDOMElement> mFaultElement;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,254 @@
|
|||
/* -*- 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 "nsSOAPParameter.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
nsSOAPParameter::nsSOAPParameter()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
mType = PARAMETER_TYPE_NULL;
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
if (cx) {
|
||||
JS_AddNamedRoot(cx, &mJSValue, "nsSOAPParameter");
|
||||
}
|
||||
}
|
||||
|
||||
nsSOAPParameter::~nsSOAPParameter()
|
||||
{
|
||||
JSContext* cx;
|
||||
cx = nsSOAPUtils::GetSafeContext();
|
||||
if (cx) {
|
||||
JS_RemoveRoot(cx, &mJSValue);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSOAPParameter, nsISOAPParameter, nsISecurityCheckedComponent)
|
||||
|
||||
/* attribute string encodingStyleURI; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetEncodingStyleURI(char * *aEncodingStyleURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEncodingStyleURI);
|
||||
if (mEncodingStyleURI.Length() > 0) {
|
||||
*aEncodingStyleURI = mEncodingStyleURI.ToNewCString();
|
||||
}
|
||||
else {
|
||||
*aEncodingStyleURI = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPParameter::SetEncodingStyleURI(const char * aEncodingStyleURI)
|
||||
{
|
||||
if (aEncodingStyleURI) {
|
||||
mEncodingStyleURI.Assign(aEncodingStyleURI);
|
||||
}
|
||||
else {
|
||||
mEncodingStyleURI.Truncate();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* attribute wstring name; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetName(PRUnichar * *aName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aName);
|
||||
if (mName.Length() > 0) {
|
||||
*aName = mName.ToNewUnicode();
|
||||
}
|
||||
else {
|
||||
*aName = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsSOAPParameter::SetName(const PRUnichar * aName)
|
||||
{
|
||||
if (aName) {
|
||||
mName.Assign(aName);
|
||||
}
|
||||
else {
|
||||
mName.Truncate();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute long type; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetType(PRInt32 *aType)
|
||||
{
|
||||
NS_ENSURE_ARG(aType);
|
||||
*aType = mType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [noscript] void setValueAndType (in nsISupports value, in long type); */
|
||||
NS_IMETHODIMP nsSOAPParameter::SetValueAndType(nsISupports *value, PRInt32 type)
|
||||
{
|
||||
mValue = value;
|
||||
mType = type;
|
||||
mJSValue = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsISupports value; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetValue(nsISupports * *aValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aValue);
|
||||
nsresult rv;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// We can't make this a setter in xpidl without a variant type.
|
||||
// For now, use nsIXPCScriptable to do the setting.
|
||||
NS_IMETHODIMP nsSOAPParameter::SetValue(JSContext* aContext,
|
||||
jsval aValue)
|
||||
{
|
||||
return nsSOAPUtils::ConvertJSValToValue(aContext,
|
||||
aValue,
|
||||
getter_AddRefs(mValue),
|
||||
&mJSValue,
|
||||
&mType);
|
||||
}
|
||||
|
||||
/* [noscript] readonly attribute JSObjectPtr JSValue; */
|
||||
NS_IMETHODIMP nsSOAPParameter::GetJSValue(JSObject * *aJSValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aJSValue);
|
||||
*aJSValue = mJSValue;
|
||||
|
||||
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)
|
||||
XPC_IMPLEMENT_IGNORE_DEFAULTVALUE(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_ENUMERATE(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_CHECKACCESS(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_CALL(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_CONSTRUCT(nsSOAPParameter)
|
||||
XPC_IMPLEMENT_IGNORE_FINALIZE(nsSOAPParameter)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::SetProperty(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")) {
|
||||
return SetValue(cx, *vp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
static const char* kAllAccess = "AllAccess";
|
||||
|
||||
/* string canCreateWrapper (in nsIIDPtr iid); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::CanCreateWrapper(const nsIID * iid, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPParameter))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPParameter))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPParameter))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPParameter::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPParameter))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/* -*- 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 nsSOAPParameter_h__
|
||||
#define nsSOAPParameter_h__
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nsISOAPParameter.h"
|
||||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsIXPCScriptable.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsSOAPParameter : public nsISOAPParameter,
|
||||
public nsISecurityCheckedComponent,
|
||||
public nsIXPCScriptable
|
||||
{
|
||||
public:
|
||||
nsSOAPParameter();
|
||||
virtual ~nsSOAPParameter();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPParameter
|
||||
NS_DECL_NSISOAPPARAMETER
|
||||
|
||||
// nsISecurityCheckedComponent
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
// nsIXPCScriptable
|
||||
XPC_DECLARE_IXPCSCRIPTABLE
|
||||
|
||||
NS_IMETHODIMP SetValue(JSContext* aContext,
|
||||
jsval aValue);
|
||||
|
||||
protected:
|
||||
nsCString mEncodingStyleURI;
|
||||
nsString mName;
|
||||
PRInt32 mType;
|
||||
nsCOMPtr<nsISupports> mValue;
|
||||
JSObject* mJSValue;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,276 @@
|
|||
/* -*- 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 "nsSOAPResponse.h"
|
||||
#include "nsSOAPUtils.h"
|
||||
#include "nsSOAPFault.h"
|
||||
#include "nsISOAPEncoder.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsISOAPParameter.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsMemory.h"
|
||||
|
||||
nsSOAPResponse::nsSOAPResponse(nsIDOMDocument* aEnvelopeDocument)
|
||||
{
|
||||
mEnvelopeDocument = aEnvelopeDocument;
|
||||
if (mEnvelopeDocument) {
|
||||
nsCOMPtr<nsIDOMElement> element;
|
||||
mEnvelopeDocument->GetDocumentElement(getter_AddRefs(element));
|
||||
if (!element) return;
|
||||
|
||||
nsAutoString ns, name;
|
||||
element->GetNamespaceURI(ns);
|
||||
element->GetLocalName(name);
|
||||
|
||||
if (ns.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI)) &&
|
||||
name.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kEnvelopeTagName))) {
|
||||
mEnvelopeElement = element;
|
||||
nsSOAPUtils::GetFirstChildElement(mEnvelopeElement,
|
||||
getter_AddRefs(element));
|
||||
if (!element) return;
|
||||
|
||||
element->GetNamespaceURI(ns);
|
||||
element->GetLocalName(name);
|
||||
|
||||
if (ns.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI)) &&
|
||||
name.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kHeaderTagName))) {
|
||||
mHeaderElement = element;
|
||||
|
||||
nsSOAPUtils::GetNextSiblingElement(mHeaderElement,
|
||||
getter_AddRefs(element));
|
||||
if (!element) return;
|
||||
|
||||
element->GetNamespaceURI(ns);
|
||||
element->GetLocalName(name);
|
||||
}
|
||||
|
||||
if (ns.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI)) &&
|
||||
name.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kBodyTagName))) {
|
||||
mBodyElement = element;
|
||||
|
||||
nsSOAPUtils::GetFirstChildElement(mBodyElement,
|
||||
getter_AddRefs(element));
|
||||
if (!element) return;
|
||||
|
||||
element->GetNamespaceURI(ns);
|
||||
element->GetLocalName(name);
|
||||
|
||||
// XXX This assumes that the first body entry is either a fault
|
||||
// or a result and that the two are mutually exclusive
|
||||
if (ns.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI)) &&
|
||||
name.Equals(NS_ConvertASCIItoUCS2(nsSOAPUtils::kFaultTagName))) {
|
||||
mFaultElement = element;
|
||||
}
|
||||
else {
|
||||
mResultElement = element;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsSOAPResponse::~nsSOAPResponse()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSOAPResponse, nsISOAPResponse, nsISecurityCheckedComponent)
|
||||
|
||||
/* readonly attribute nsIDOMElement envelope; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetEnvelope(nsIDOMElement * *aEnvelope)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aEnvelope);
|
||||
*aEnvelope = mEnvelopeElement;
|
||||
NS_IF_ADDREF(*aEnvelope);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement header; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetHeader(nsIDOMElement * *aHeader)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aHeader);
|
||||
*aHeader = mHeaderElement;
|
||||
NS_IF_ADDREF(*aHeader);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsIDOMElement body; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetBody(nsIDOMElement * *aBody)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aBody);
|
||||
*aBody = mBodyElement;
|
||||
NS_IF_ADDREF(*aBody);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute unsigned long status; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetStatus(PRUint32 *aStatus)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
/* readonly attribute string targetObjectURI; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetTargetObjectURI(char * *aTargetObjectURI)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aTargetObjectURI);
|
||||
*aTargetObjectURI = nsnull;
|
||||
if (mResultElement) {
|
||||
nsAutoString ns;
|
||||
mResultElement->GetNamespaceURI(ns);
|
||||
if (ns.Length() > 0) {
|
||||
*aTargetObjectURI = ns.ToNewCString();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute string methodName; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetMethodName(char * *aMethodName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aMethodName);
|
||||
*aMethodName = nsnull;
|
||||
if (mResultElement) {
|
||||
nsAutoString localName;
|
||||
mResultElement->GetLocalName(localName);
|
||||
if (localName.Length() > 0) {
|
||||
*aMethodName = localName.ToNewCString();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* boolean generatedFault (); */
|
||||
NS_IMETHODIMP nsSOAPResponse::GeneratedFault(PRBool *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG(_retval);
|
||||
if (mFaultElement) {
|
||||
*_retval = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
*_retval = PR_FALSE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsISOAPFault fault; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetFault(nsISOAPFault * *aFault)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aFault);
|
||||
*aFault = nsnull;
|
||||
if (mFaultElement) {
|
||||
nsSOAPFault* fault = new nsSOAPFault(mFaultElement);
|
||||
if (!fault) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return fault->QueryInterface(NS_GET_IID(nsISOAPFault), (void**)aFault);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* readonly attribute nsISOAPParameter returnValue; */
|
||||
NS_IMETHODIMP nsSOAPResponse::GetReturnValue(nsISOAPParameter * *aReturnValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aReturnValue);
|
||||
nsresult rv;
|
||||
|
||||
*aReturnValue = nsnull;
|
||||
|
||||
if (mResultElement) {
|
||||
// Get the inherited encoding style starting from the
|
||||
// body entry.
|
||||
char* encodingStyle;
|
||||
nsSOAPUtils::GetInheritedEncodingStyle(mResultElement,
|
||||
&encodingStyle);
|
||||
|
||||
if (!encodingStyle) {
|
||||
encodingStyle = nsCRT::strdup(nsSOAPUtils::kSOAPEncodingURI);
|
||||
}
|
||||
|
||||
// Find the corresponding encoder
|
||||
nsCAutoString encoderProgid;
|
||||
encoderProgid.Assign(NS_SOAPENCODER_PROGID_PREFIX);
|
||||
encoderProgid.Append(encodingStyle);
|
||||
|
||||
nsCOMPtr<nsISOAPEncoder> encoder = do_CreateInstance(encoderProgid);
|
||||
if (!encoder) {
|
||||
nsMemory::Free(encodingStyle);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
// Convert the result element to a parameter
|
||||
nsCOMPtr<nsISOAPParameter> param;
|
||||
rv = encoder->ElementToParameter(mResultElement,
|
||||
encodingStyle,
|
||||
getter_AddRefs(param));
|
||||
nsMemory::Free(encodingStyle);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aReturnValue = param;
|
||||
NS_IF_ADDREF(*aReturnValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static const char* kAllAccess = "AllAccess";
|
||||
|
||||
/* string canCreateWrapper (in nsIIDPtr iid); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPResponse::CanCreateWrapper(const nsIID * iid, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPResponse))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canCallMethod (in nsIIDPtr iid, in wstring methodName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPResponse::CanCallMethod(const nsIID * iid, const PRUnichar *methodName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPResponse))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canGetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPResponse::CanGetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPResponse))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string canSetProperty (in nsIIDPtr iid, in wstring propertyName); */
|
||||
NS_IMETHODIMP
|
||||
nsSOAPResponse::CanSetProperty(const nsIID * iid, const PRUnichar *propertyName, char **_retval)
|
||||
{
|
||||
if (iid->Equals(NS_GET_IID(nsISOAPResponse))) {
|
||||
*_retval = nsCRT::strdup(kAllAccess);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/* -*- 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 nsSOAPResponse_h__
|
||||
#define nsSOAPResponse_h__
|
||||
|
||||
#include "nsISOAPResponse.h"
|
||||
#include "nsISecurityCheckedComponent.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsSOAPResponse : public nsISOAPResponse,
|
||||
public nsISecurityCheckedComponent
|
||||
{
|
||||
public:
|
||||
nsSOAPResponse(nsIDOMDocument* aEnvelopeDocument);
|
||||
virtual ~nsSOAPResponse();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsISOAPResponse
|
||||
NS_DECL_NSISOAPRESPONSE
|
||||
|
||||
// nsISecurityCheckedComponent
|
||||
NS_DECL_NSISECURITYCHECKEDCOMPONENT
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIDOMDocument> mEnvelopeDocument;
|
||||
nsCOMPtr<nsIDOMElement> mEnvelopeElement;
|
||||
nsCOMPtr<nsIDOMElement> mHeaderElement;
|
||||
nsCOMPtr<nsIDOMElement> mBodyElement;
|
||||
nsCOMPtr<nsIDOMElement> mResultElement;
|
||||
nsCOMPtr<nsIDOMElement> mFaultElement;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,374 @@
|
|||
/* -*- 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 "nsSOAPUtils.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsISOAPParameter.h"
|
||||
#include "nsISupportsPrimitives.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
const char* nsSOAPUtils::kSOAPEnvURI = "http://schemas.xmlsoap.org/soap/envelope/";
|
||||
const char* nsSOAPUtils::kSOAPEncodingURI = "http://schemas.xmlsoap.org/soap/encoding/";
|
||||
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";
|
||||
|
||||
void
|
||||
nsSOAPUtils::GetFirstChildElement(nsIDOMElement* aParent,
|
||||
nsIDOMElement** aElement)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
|
||||
*aElement = nsnull;
|
||||
aParent->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
PRUint16 type;
|
||||
child->GetNodeType(&type);
|
||||
if (nsIDOMNode::ELEMENT_NODE == type) {
|
||||
child->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aElement);
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp = child;
|
||||
temp->GetNextSibling(getter_AddRefs(child));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsSOAPUtils::GetNextSiblingElement(nsIDOMElement* aStart,
|
||||
nsIDOMElement** aElement)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> sibling;
|
||||
|
||||
*aElement = nsnull;
|
||||
aStart->GetNextSibling(getter_AddRefs(sibling));
|
||||
while (sibling) {
|
||||
PRUint16 type;
|
||||
sibling->GetNodeType(&type);
|
||||
if (nsIDOMNode::ELEMENT_NODE == type) {
|
||||
sibling->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aElement);
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp = sibling;
|
||||
temp->GetNextSibling(getter_AddRefs(sibling));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsSOAPUtils::GetElementTextContent(nsIDOMElement* aElement,
|
||||
nsString& aText)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> sibling;
|
||||
|
||||
aText.Truncate();
|
||||
aElement->GetNextSibling(getter_AddRefs(sibling));
|
||||
while (sibling) {
|
||||
PRUint16 type;
|
||||
sibling->GetNodeType(&type);
|
||||
if (nsIDOMNode::TEXT_NODE == type) {
|
||||
nsCOMPtr<nsIDOMText> text = do_QueryInterface(sibling);
|
||||
nsAutoString data;
|
||||
text->GetData(data);
|
||||
aText.Append(data);
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp = sibling;
|
||||
temp->GetNextSibling(getter_AddRefs(sibling));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsSOAPUtils::GetInheritedEncodingStyle(nsIDOMElement* aEntry,
|
||||
char** aEncodingStyle)
|
||||
{
|
||||
nsCOMPtr<nsIDOMNode> node = aEntry;
|
||||
|
||||
*aEncodingStyle = nsnull;
|
||||
while (node) {
|
||||
nsAutoString value;
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node);
|
||||
if (element) {
|
||||
element->GetAttributeNS(NS_ConvertASCIItoUCS2(nsSOAPUtils::kSOAPEnvURI),
|
||||
NS_ConvertASCIItoUCS2(nsSOAPUtils::kEncodingStyleAttribute),
|
||||
value);
|
||||
if (value.Length() > 0) {
|
||||
*aEncodingStyle = value.ToNewCString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> temp = node;
|
||||
temp->GetParentNode(getter_AddRefs(node));
|
||||
}
|
||||
}
|
||||
|
||||
JSContext*
|
||||
nsSOAPUtils::GetSafeContext()
|
||||
{
|
||||
// Get the "safe" JSContext: our JSContext of last resort
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIJSContextStack, stack, "nsThreadJSContextStack",
|
||||
&rv);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
nsCOMPtr<nsIThreadJSContextStack> tcs = do_QueryInterface(stack);
|
||||
JSContext* cx;
|
||||
if (NS_FAILED(tcs->GetSafeJSContext(&cx))) {
|
||||
return nsnull;
|
||||
}
|
||||
return cx;
|
||||
}
|
||||
|
||||
JSContext*
|
||||
nsSOAPUtils::GetCurrentContext()
|
||||
{
|
||||
// Get JSContext from stack.
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIJSContextStack, stack, "nsThreadJSContextStack",
|
||||
&rv);
|
||||
if (NS_FAILED(rv))
|
||||
return nsnull;
|
||||
JSContext *cx;
|
||||
if (NS_FAILED(stack->Peek(&cx)))
|
||||
return nsnull;
|
||||
return cx;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPUtils::ConvertValueToJSVal(JSContext* aContext,
|
||||
nsISupports* aValue,
|
||||
JSObject* aJSValue,
|
||||
PRInt32 aType,
|
||||
jsval* vp)
|
||||
{
|
||||
*vp = JSVAL_NULL;
|
||||
switch(aType) {
|
||||
case nsISOAPParameter::PARAMETER_TYPE_VOID:
|
||||
*vp = JSVAL_VOID;
|
||||
break;
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_STRING:
|
||||
{
|
||||
nsCOMPtr<nsISupportsWString> wstr = do_QueryInterface(aValue);
|
||||
if (!wstr) return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLString data;
|
||||
wstr->GetData(getter_Copies(data));
|
||||
|
||||
if (data) {
|
||||
JSString* jsstr = JS_NewUCStringCopyZ(aContext,
|
||||
(const jschar*)data);
|
||||
if (jsstr) {
|
||||
*vp = STRING_TO_JSVAL(jsstr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_BOOLEAN:
|
||||
{
|
||||
nsCOMPtr<nsISupportsPRBool> prb = do_QueryInterface(aValue);
|
||||
if (!prb) return NS_ERROR_FAILURE;
|
||||
|
||||
PRBool data;
|
||||
prb->GetData(&data);
|
||||
|
||||
if (data) {
|
||||
*vp = JSVAL_TRUE;
|
||||
}
|
||||
else {
|
||||
*vp = JSVAL_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_DOUBLE:
|
||||
{
|
||||
nsCOMPtr<nsISupportsDouble> dub = do_QueryInterface(aValue);
|
||||
if (!dub) return NS_ERROR_FAILURE;
|
||||
|
||||
double data;
|
||||
dub->GetData(&data);
|
||||
|
||||
*vp = DOUBLE_TO_JSVAL((jsdouble)data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_FLOAT:
|
||||
{
|
||||
nsCOMPtr<nsISupportsFloat> flt = do_QueryInterface(aValue);
|
||||
if (!flt) return NS_ERROR_FAILURE;
|
||||
|
||||
float data;
|
||||
flt->GetData(&data);
|
||||
|
||||
*vp = DOUBLE_TO_JSVAL((jsdouble)data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_LONG:
|
||||
{
|
||||
// XXX How to express 64-bit values in JavaScript?
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_INT:
|
||||
{
|
||||
nsCOMPtr<nsISupportsPRInt32> isupint32 = do_QueryInterface(aValue);
|
||||
if (!isupint32) return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt32 data;
|
||||
isupint32->GetData(&data);
|
||||
|
||||
*vp = INT_TO_JSVAL(data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_SHORT:
|
||||
{
|
||||
nsCOMPtr<nsISupportsPRInt16> isupint16 = do_QueryInterface(aValue);
|
||||
if (!isupint16) return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt16 data;
|
||||
isupint16->GetData(&data);
|
||||
|
||||
*vp = INT_TO_JSVAL((PRInt32)data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_BYTE:
|
||||
{
|
||||
nsCOMPtr<nsISupportsChar> isupchar = do_QueryInterface(aValue);
|
||||
if (!isupchar) return NS_ERROR_FAILURE;
|
||||
|
||||
char data;
|
||||
isupchar->GetData(&data);
|
||||
|
||||
*vp = INT_TO_JSVAL((PRInt32)data);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_ARRAY:
|
||||
{
|
||||
// XXX Can't (easily) convert a native nsISupportsArray
|
||||
// to a script array.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
case nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_ARRAY:
|
||||
case nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_OBJECT:
|
||||
{
|
||||
*vp = OBJECT_TO_JSVAL(aJSValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSOAPUtils::ConvertJSValToValue(JSContext* aContext,
|
||||
jsval val,
|
||||
nsISupports** aValue,
|
||||
JSObject** aJSValue,
|
||||
PRInt32* aType)
|
||||
{
|
||||
*aValue = nsnull;
|
||||
*aJSValue = nsnull;
|
||||
if (JSVAL_IS_NULL(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_NULL;
|
||||
}
|
||||
else if (JSVAL_IS_VOID(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_VOID;
|
||||
}
|
||||
else if (JSVAL_IS_STRING(val)) {
|
||||
JSString* jsstr;
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_STRING;
|
||||
|
||||
jsstr = JSVAL_TO_STRING(val);
|
||||
if (jsstr) {
|
||||
nsCOMPtr<nsISupportsWString> wstr = do_CreateInstance(NS_SUPPORTS_WSTRING_PROGID);
|
||||
if (!wstr) return NS_ERROR_FAILURE;
|
||||
|
||||
PRUnichar* data = NS_REINTERPRET_CAST(PRUnichar*,
|
||||
JS_GetStringChars(jsstr));
|
||||
if (data) {
|
||||
wstr->SetData(data);
|
||||
}
|
||||
*aValue = wstr;
|
||||
NS_ADDREF(*aValue);
|
||||
}
|
||||
}
|
||||
else if (JSVAL_IS_DOUBLE(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_DOUBLE;
|
||||
|
||||
nsCOMPtr<nsISupportsDouble> dub = do_CreateInstance(NS_SUPPORTS_DOUBLE_PROGID);
|
||||
if (!dub) return NS_ERROR_FAILURE;
|
||||
|
||||
dub->SetData((double)(*JSVAL_TO_DOUBLE(val)));
|
||||
*aValue = dub;
|
||||
NS_ADDREF(*aValue);
|
||||
}
|
||||
else if (JSVAL_IS_INT(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_INT;
|
||||
|
||||
nsCOMPtr<nsISupportsPRInt32> isupint = do_CreateInstance(NS_SUPPORTS_PRINT32_PROGID);
|
||||
if (!isupint) return NS_ERROR_FAILURE;
|
||||
|
||||
isupint->SetData((PRInt32)JSVAL_TO_INT(val));
|
||||
*aValue = isupint;
|
||||
NS_ADDREF(*aValue);
|
||||
}
|
||||
else if (JSVAL_IS_BOOLEAN(val)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_BOOLEAN;
|
||||
|
||||
nsCOMPtr<nsISupportsPRBool> isupbool = do_CreateInstance(NS_SUPPORTS_PRBOOL_PROGID);
|
||||
if (!isupbool) return NS_ERROR_FAILURE;
|
||||
|
||||
isupbool->SetData((PRBool)JSVAL_TO_BOOLEAN(val));
|
||||
*aValue = isupbool;
|
||||
NS_ADDREF(*aValue);
|
||||
}
|
||||
else if (JSVAL_IS_OBJECT(val)) {
|
||||
JSObject* jsobj = JSVAL_TO_OBJECT(val);
|
||||
if (JS_IsArrayObject(aContext, jsobj)) {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_ARRAY;
|
||||
}
|
||||
else {
|
||||
*aType = nsISOAPParameter::PARAMETER_TYPE_JAVASCRIPT_OBJECT;
|
||||
}
|
||||
*aJSValue = jsobj;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/* -*- 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 nsSOAPUtils_h__
|
||||
#define nsSOAPUtils_h__
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
class nsSOAPUtils {
|
||||
public:
|
||||
static void GetFirstChildElement(nsIDOMElement* aParent,
|
||||
nsIDOMElement** aElement);
|
||||
static void GetNextSiblingElement(nsIDOMElement* aStart,
|
||||
nsIDOMElement** aElement);
|
||||
static void GetElementTextContent(nsIDOMElement* aElement,
|
||||
nsString& aText);
|
||||
static void GetInheritedEncodingStyle(nsIDOMElement* aEntry,
|
||||
char** aEncodingStyle);
|
||||
static JSContext* GetSafeContext();
|
||||
static JSContext* GetCurrentContext();
|
||||
static nsresult ConvertValueToJSVal(JSContext* aContext,
|
||||
nsISupports* aValue,
|
||||
JSObject* aJSValue,
|
||||
PRInt32 aType,
|
||||
jsval* vp);
|
||||
static nsresult ConvertJSValToValue(JSContext* aContext,
|
||||
jsval val,
|
||||
nsISupports** aValue,
|
||||
JSObject** aJSValue,
|
||||
PRInt32* aType);
|
||||
|
||||
static const char* kSOAPEnvURI;
|
||||
static const char* kSOAPEncodingURI;
|
||||
static const char* kEncodingStyleAttribute;
|
||||
static const char* kEnvelopeTagName;
|
||||
static const char* kHeaderTagName;
|
||||
static const char* kBodyTagName;
|
||||
static const char* kFaultTagName;
|
||||
static const char* kFaultCodeTagName;
|
||||
static const char* kFaultStringTagName;
|
||||
static const char* kFaultActorTagName;
|
||||
static const char* kFaultDetailTagName;
|
||||
};
|
||||
|
||||
#endif
|
Загрузка…
Ссылка в новой задаче