/* attribute AString mustUnderstand; */ NS_IMETHODIMP nsSOAPHeaderBlock::GetMustUnderstand(PRBool * aMustUnderstand) { if (mElement) { if (mVersion == nsISOAPMessage::VERSION_UNKNOWN) return SOAP_EXCEPTION(NS_ERROR_NOT_AVAILABLE,"SOAP_HEADER_INIT", "Header has not been properly initialized."); nsAutoString m; nsresult rc = mElement-> GetAttributeNS(*gSOAPStrings->kSOAPEnvURI[mVersion], gSOAPStrings->kMustUnderstandAttribute, m); if (NS_FAILED(rc)) return rc; if (m.IsEmpty()) *aMustUnderstand = PR_FALSE; else if (m.Equals(gSOAPStrings->kTrue) || m.Equals(gSOAPStrings->kTrueA)) *aMustUnderstand = PR_TRUE; else if (m.Equals(gSOAPStrings->kFalse) || m.Equals(gSOAPStrings->kFalseA)) *aMustUnderstand = PR_FALSE; else return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_HEADER_MUSTUNDERSTAND", "Must understand value in header has an illegal value."); return NS_OK; } else { *aMustUnderstand = mMustUnderstand; } return NS_OK; }
nsresult nsSOAPUtils::GetElementTextContent(nsIDOMElement * aElement, nsAString & aText) { aText.Truncate(); nsCOMPtr<nsIDOMNode> child; nsAutoString rtext; aElement->GetFirstChild(getter_AddRefs(child)); while (child) { PRUint16 type; child->GetNodeType(&type); if (nsIDOMNode::TEXT_NODE == type || nsIDOMNode::CDATA_SECTION_NODE == type) { nsCOMPtr<nsIDOMText> text = do_QueryInterface(child); nsAutoString data; text->GetData(data); rtext.Append(data); } else if (nsIDOMNode::ELEMENT_NODE == type) { return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_UNEXPECTED_ELEMENT", "Unable to retrieve simple content because a child element was present."); } nsCOMPtr<nsIDOMNode> temp = child; GetNextSibling(temp, getter_AddRefs(child)); } aText.Assign(rtext); return NS_OK; }
/* void asyncInvoke (in nsISOAPResponseListener listener); */ NS_IMETHODIMP nsSOAPCall::AsyncInvoke(nsISOAPResponseListener * listener, nsISOAPCallCompletion ** aCompletion) { NS_ENSURE_ARG_POINTER(aCompletion); nsresult rv; nsCOMPtr<nsISOAPTransport> transport; if (mTransportURI.IsEmpty()) { return SOAP_EXCEPTION(NS_ERROR_NOT_INITIALIZED,"SOAP_TRANSPORT_URI", "No transport URI was specified."); } rv = GetTransport(getter_AddRefs(transport)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsISOAPResponse> response(do_CreateInstance(NS_SOAPRESPONSE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; rv = response->SetEncoding(mEncoding); if (NS_FAILED(rv)) return rv; rv = transport->AsyncCall(this, listener, response, aCompletion); return rv; }
nsresult nsSOAPUtils::GetNamespaceURI(nsISOAPEncoding * aEncoding, nsIDOMElement * aScope, const nsAString & aQName, nsAString & aURI) { aURI.Truncate(); PRInt32 i = aQName.FindChar(':'); if (i < 0) { return NS_OK; } nsAutoString prefix; prefix = Substring(aQName, 0, i); nsAutoString result; if (prefix.Equals(gSOAPStrings->kXMLPrefix)) { result.Assign(gSOAPStrings->kXMLNamespaceURI); } else { nsresult rc; nsCOMPtr<nsIDOMNode> current = aScope; nsCOMPtr<nsIDOMNamedNodeMap> attrs; nsCOMPtr<nsIDOMNode> temp; nsAutoString value; while (current) { rc = current->GetAttributes(getter_AddRefs(attrs)); if (NS_FAILED(rc)) return rc; if (attrs) { rc = attrs->GetNamedItemNS(gSOAPStrings->kXMLNamespaceNamespaceURI, prefix, getter_AddRefs(temp)); if (NS_FAILED(rc)) return rc; if (temp) { rc = temp->GetNodeValue(result); if (NS_FAILED(rc)) return rc; break; } } rc = current->GetParentNode(getter_AddRefs(temp)); if (NS_FAILED(rc)) return rc; current = temp; } if (!current) return SOAP_EXCEPTION(NS_ERROR_FAILURE,"SOAP_NAMESPACE", "Unable to resolve prefix in attribute value to namespace URI"); } if (aEncoding) { return aEncoding->GetInternalSchemaURI(result,aURI); } aURI.Assign(result); return NS_OK; }
/* attribute AString actorURI; */ NS_IMETHODIMP nsSOAPHeaderBlock::GetActorURI(nsAString & aActorURI) { if (mElement) { if (mVersion == nsISOAPMessage::VERSION_UNKNOWN) return SOAP_EXCEPTION(NS_ERROR_NOT_AVAILABLE,"SOAP_HEADER_INIT", "Header has not been properly initialized."); return mElement->GetAttributeNS(*gSOAPStrings->kSOAPEnvURI[mVersion], gSOAPStrings->kActorAttribute, aActorURI); } else { aActorURI.Assign(mActorURI); } return NS_OK; }
/* nsIVariant decode (in nsIDOMElement aSource, in nsISchemaType aSchemaType, in nsISOAPAttachments aAttachments); */ NS_IMETHODIMP nsSOAPEncoding::Decode(nsIDOMElement * aSource, nsISchemaType * aSchemaType, nsISOAPAttachments * aAttachments, nsIVariant ** _retval) { NS_ENSURE_ARG(aSource); NS_ENSURE_ARG_POINTER(_retval); nsCOMPtr<nsISOAPDecoder> decoder; nsresult rv = GetDefaultDecoder(getter_AddRefs(decoder)); if (NS_FAILED(rv)) return rv; if (decoder) { return decoder->Decode(this, aSource, aSchemaType, aAttachments, _retval); } *_retval = nsnull; return SOAP_EXCEPTION(NS_ERROR_NOT_IMPLEMENTED,"SOAP_DEFAULT_ENCODER", "Encoding style does not have a default decoder."); }
NS_IMETHODIMP nsSOAPEncoding::MapSchemaURI(const nsAString & aExternalURI, const nsAString & aInternalURI, PRBool aOutput, PRBool *_retval) { if (aExternalURI.IsEmpty() || aInternalURI.IsEmpty()) // Permit no empty URIs. return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_SCHEMA_URI_MAPPING", "No schema URI mapping possible of empty strings."); nsStringKey externalKey(aExternalURI); if (mMappedExternal.Exists(&externalKey)) { *_retval = PR_FALSE; // Do not permit duplicate external return NS_OK; } if (aOutput) { nsStringKey internalKey(aInternalURI); if (mMappedInternal.Exists(&internalKey)) { *_retval = PR_FALSE; // Do not permit duplicate internal return NS_OK; } nsresult rc; nsCOMPtr<nsIWritableVariant> p = do_CreateInstance(NS_VARIANT_CONTRACTID, &rc); if (NS_FAILED(rc)) return rc; rc = p->SetAsAString(aExternalURI); if (NS_FAILED(rc)) return rc; mMappedInternal.Put(&internalKey, p); } nsresult rc; nsCOMPtr<nsIWritableVariant> p = do_CreateInstance(NS_VARIANT_CONTRACTID, &rc); if (NS_FAILED(rc)) return rc; rc = p->SetAsAString(aInternalURI); if (NS_FAILED(rc)) return rc; mMappedExternal.Put(&externalKey, p); if (_retval) *_retval = PR_TRUE; return NS_OK; }
/* nsISOAPResponse invoke (); */ NS_IMETHODIMP nsSOAPCall::Invoke(nsISOAPResponse ** _retval) { NS_ENSURE_ARG_POINTER(_retval); nsresult rv; nsCOMPtr<nsISOAPTransport> transport; if (mTransportURI.IsEmpty()) { return SOAP_EXCEPTION(NS_ERROR_NOT_INITIALIZED,"SOAP_TRANSPORT_URI", "No transport URI was specified."); } rv = GetTransport(getter_AddRefs(transport)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsISOAPResponse> response(do_CreateInstance(NS_SOAPRESPONSE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; rv = response->SetEncoding(mEncoding); if (NS_FAILED(rv)) return rv; rv = transport->SyncCall(this, response); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIDOMDocument> document; rv = response->GetMessage(getter_AddRefs(document)); // No XML response. if (NS_FAILED(rv)) return rv; if (!document) { *_retval = nsnull; return NS_OK; } return response->QueryInterface(NS_GET_IID(nsISOAPResponse), (void **) _retval); }
/* nsIDOMElement encode (in nsIVariant aSource, in AString aNamespaceURI, in AString aName, in nsISchemaType aSchemaType, in nsISOAPAttachments aAttachments, in nsIDOMElement aDestination); */ NS_IMETHODIMP nsSOAPEncoding::Encode(nsIVariant * aSource, const nsAString & aNamespaceURI, const nsAString & aName, nsISchemaType * aSchemaType, nsISOAPAttachments * aAttachments, nsIDOMElement * aDestination, nsIDOMElement ** _retval) { NS_ENSURE_ARG(aSource); NS_ENSURE_ARG_POINTER(_retval); nsCOMPtr<nsISOAPEncoder> encoder; nsresult rv = GetDefaultEncoder(getter_AddRefs(encoder)); if (NS_FAILED(rv)) return rv; if (encoder) { return encoder->Encode(this, aSource, aNamespaceURI, aName, aSchemaType, aAttachments, aDestination, _retval); } *_retval = nsnull; return SOAP_EXCEPTION(NS_ERROR_NOT_IMPLEMENTED,"SOAP_DEFAULT_ENCODER", "Encoding style does not have a default encoder."); }
/* void getParameters (in boolean aDocumentStyle, out PRUint32 aCount, [array, size_is (aCount), retval] out nsISOAPParameter aParameters); */ NS_IMETHODIMP nsSOAPMessage::GetParameters(PRBool aDocumentStyle, PRUint32 * aCount, nsISOAPParameter *** aParameters) { NS_ENSURE_ARG_POINTER(aParameters); nsISOAPParameter** parameters = nsnull; *aCount = 0; *aParameters = nsnull; int count = 0; int length = 0; nsCOMPtr<nsIDOMElement> element; nsresult rv = GetBody(getter_AddRefs(element)); if (NS_FAILED(rv) || !element) return rv; nsCOMPtr<nsIDOMElement> next; nsCOMPtr<nsISOAPParameter> param; nsSOAPUtils::GetFirstChildElement(element, getter_AddRefs(next)); if (!aDocumentStyle) { element = next; if (!element) return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_MISSING_METHOD","Cannot decode rpc-style message due to missing method element."); nsSOAPUtils::GetFirstChildElement(element, getter_AddRefs(next)); } nsCOMPtr<nsISOAPEncoding> encoding; PRUint16 version; rv = GetEncodingWithVersion(element, &version, getter_AddRefs(encoding)); if (NS_FAILED(rv)) return rv; while (next) { if (length == count) { length = length ? 2 * length : 10; parameters = (nsISOAPParameter * *)nsMemory::Realloc(parameters, length * sizeof(*parameters)); } element = next; param = do_CreateInstance(NS_SOAPPARAMETER_CONTRACTID); if (!param) { rv = NS_ERROR_OUT_OF_MEMORY; break; } parameters[count] = param; NS_ADDREF(parameters[count]); count++; rv = param->SetElement(element); if (NS_FAILED(rv)) break; rv = param->SetEncoding(encoding); if (NS_FAILED(rv)) break; nsSOAPUtils::GetNextSiblingElement(element, getter_AddRefs(next)); } if (NS_SUCCEEDED(rv)) { if (count) { parameters = (nsISOAPParameter * *)nsMemory::Realloc(parameters, count * sizeof(*parameters)); } } else { while (--count >= 0) { NS_IF_RELEASE(parameters[count]); } count = 0; nsMemory::Free(parameters); parameters = nsnull; } *aCount = count; *aParameters = parameters; return rv; }
NS_IMETHODIMP nsSOAPMessage::Encode(PRUint16 aVersion, const nsAString & aMethodName, const nsAString & aTargetObjectURI, PRUint32 aHeaderBlockCount, nsISOAPHeaderBlock ** aHeaderBlocks, PRUint32 aParameterCount, nsISOAPParameter ** aParameters) { static NS_NAMED_LITERAL_STRING(realEmptySOAPDocStr1, "<env:Envelope xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:enc=\"http://schemas.xmlsoap.org/soap/encoding/\"><env:Header/><env:Body/></env:Envelope>"); static NS_NAMED_LITERAL_STRING(realEmptySOAPDocStr2, "<env:Envelope xmlns:env=\"http://www.w3.org/2001/09/soap-envelope\" xmlns:enc=\"http://www.w3.org/2001/09/soap-encoding\"><env:Header/><env:Body/></env:Envelope>"); static const nsAString *kEmptySOAPDocStr[] = { &realEmptySOAPDocStr1, &realEmptySOAPDocStr2 }; if (aVersion != nsISOAPMessage::VERSION_1_1 && aVersion != nsISOAPMessage::VERSION_1_2) return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_BAD_VALUE","Cannot encode message blocks without a valid SOAP version specified."); // Construct the message skeleton nsresult rv; nsCOMPtr<nsIDOMNode> ignored; nsCOMPtr<nsIDOMParser> parser = do_CreateInstance(kDOMParserCID, &rv); if (NS_FAILED(rv)) return rv; rv = parser->ParseFromString(nsPromiseFlatString(*kEmptySOAPDocStr[aVersion]).get(), "application/xml", getter_AddRefs(mMessage)); if (NS_FAILED(rv)) return rv; // Declare the default encoding. This should always be non-null, but may be empty string. nsCOMPtr<nsISOAPEncoding> encoding; rv = GetEncoding(getter_AddRefs(encoding)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIDOMElement> envelope; rv = GetEnvelope(getter_AddRefs(envelope)); if (NS_FAILED(rv)) return rv; if (envelope) { nsAutoString enc; rv = mEncoding->GetStyleURI(enc); if (NS_FAILED(rv)) return rv; if (!enc.IsEmpty()) { rv = envelope->SetAttributeNS(*gSOAPStrings->kSOAPEnvURI[aVersion], gSOAPStrings->kEncodingStyleAttribute, enc); if (NS_FAILED(rv)) return rv; } } // Declare the schema namespaces, taking into account any mappings that are present. nsAutoString temp; nsAutoString temp2; temp.Assign(gSOAPStrings->kXMLNamespacePrefix); temp.Append(gSOAPStrings->kXSPrefix); rv = encoding->GetExternalSchemaURI(gSOAPStrings->kXSURI, temp2); if (NS_FAILED(rv)) return rv; rv = envelope->SetAttributeNS(gSOAPStrings->kXMLNamespaceNamespaceURI, temp, temp2); if (NS_FAILED(rv)) return rv; temp.Assign(gSOAPStrings->kXMLNamespacePrefix); temp.Append(gSOAPStrings->kXSIPrefix); rv = encoding->GetExternalSchemaURI(gSOAPStrings->kXSIURI, temp2); if (NS_FAILED(rv)) return rv; rv = envelope->SetAttributeNS(gSOAPStrings->kXMLNamespaceNamespaceURI, temp, temp2); if (NS_FAILED(rv)) return rv; // Encode and add headers, if any were specified if (aHeaderBlockCount) { nsCOMPtr<nsIDOMElement> parent; rv = GetHeader(getter_AddRefs(parent)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsISOAPHeaderBlock> header; nsCOMPtr<nsIDOMElement> element; nsAutoString name; nsAutoString namespaceURI; PRUint32 i; for (i = 0; i < aHeaderBlockCount; i++) { header = aHeaderBlocks[i]; if (!header) return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_NULL_HEADER","Cannot encode null in header array."); rv = header->GetElement(getter_AddRefs(element)); if (element) { nsCOMPtr<nsIDOMNode> node1; node1 = element; nsCOMPtr<nsIDOMNode> node2; rv = mMessage->ImportNode(node1, PR_TRUE, getter_AddRefs(node1)); if (NS_FAILED(rv)) return rv; rv = parent->AppendChild(node2, getter_AddRefs(node1)); if (NS_FAILED(rv)) return rv; element = do_QueryInterface(node1); } else { rv = header->GetNamespaceURI(namespaceURI); if (NS_FAILED(rv)) return rv; rv = header->GetName(name); if (NS_FAILED(rv)) return rv; nsAutoString actorURI; rv = header->GetActorURI(actorURI); if (NS_FAILED(rv)) return rv; PRBool mustUnderstand; rv = header->GetMustUnderstand(&mustUnderstand); if (NS_FAILED(rv)) return rv; rv = header->GetEncoding(getter_AddRefs(encoding)); if (NS_FAILED(rv)) return rv; if (!encoding) { rv = GetEncoding(getter_AddRefs(encoding)); if (NS_FAILED(rv)) return rv; } nsCOMPtr<nsISchemaType> schemaType; rv = header->GetSchemaType(getter_AddRefs(schemaType)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIVariant> value; rv = header->GetValue(getter_AddRefs(value)); if (NS_FAILED(rv)) return rv; rv = encoding->Encode(value, namespaceURI, name, schemaType, nsnull, parent, getter_AddRefs(element)); if (NS_FAILED(rv)) return rv; if (!actorURI.IsEmpty()) { element->SetAttributeNS(gSOAPStrings->kSOAPEnvPrefix, gSOAPStrings->kActorAttribute, actorURI); if (NS_FAILED(rv)) return rv; } if (mustUnderstand) { element->SetAttributeNS(gSOAPStrings->kSOAPEnvPrefix, gSOAPStrings->kMustUnderstandAttribute, gSOAPStrings->kTrueA); if (NS_FAILED(rv)) return rv; } if (mEncoding != encoding) { nsAutoString enc; encoding->GetStyleURI(enc); element-> SetAttributeNS(*gSOAPStrings->kSOAPEnvURI[aVersion], gSOAPStrings->kEncodingStyleAttribute, enc); } } } } nsCOMPtr<nsIDOMElement> body; rv = GetBody(getter_AddRefs(body)); if (NS_FAILED(rv)) return rv; // Only produce a call element if mMethodName was non-empty if (!aMethodName.IsEmpty()) { nsAutoString temp; rv = encoding->GetExternalSchemaURI(aTargetObjectURI, temp); nsCOMPtr<nsIDOMElement> call; rv = mMessage->CreateElementNS(temp, aMethodName, getter_AddRefs(call)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIDOMNode> ignored; rv = body->AppendChild(call, getter_AddRefs(ignored)); if (NS_FAILED(rv)) return rv; body = call; } // Encode and add all of the parameters into the body nsCOMPtr<nsISOAPParameter> param; nsCOMPtr<nsIDOMElement> element; nsCOMPtr<nsISOAPEncoding> newencoding; nsAutoString name; nsAutoString namespaceURI; PRUint32 i; for (i = 0; i < aParameterCount; i++) { param = aParameters[i]; if (!param) return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_NULL_PARAMETER","Cannot encode null in parameter array."); rv = param->GetElement(getter_AddRefs(element)); if (element) { nsCOMPtr<nsIDOMNode> node1; node1 = element; nsCOMPtr<nsIDOMNode> node2; rv = mMessage->ImportNode(node1, PR_TRUE, getter_AddRefs(node2)); if (NS_FAILED(rv)) return rv; rv = body->AppendChild(node2, getter_AddRefs(node1)); if (NS_FAILED(rv)) return rv; element = do_QueryInterface(node1); } else { rv = param->GetNamespaceURI(namespaceURI); if (NS_FAILED(rv)) return rv; rv = param->GetName(name); if (NS_FAILED(rv)) return rv; rv = param->GetEncoding(getter_AddRefs(newencoding)); if (NS_FAILED(rv)) return rv; if (!newencoding) { newencoding = encoding; } nsCOMPtr<nsISchemaType> schemaType; rv = param->GetSchemaType(getter_AddRefs(schemaType)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIVariant> value; rv = param->GetValue(getter_AddRefs(value)); if (NS_FAILED(rv)) return rv; rv = newencoding->Encode(value, namespaceURI, name, schemaType, nsnull, body, getter_AddRefs(element)); if (NS_FAILED(rv)) return rv; if (encoding != newencoding) { nsAutoString enc; newencoding->GetStyleURI(enc); element->SetAttributeNS(*gSOAPStrings->kSOAPEnvURI[aVersion], gSOAPStrings->kEncodingStyleAttribute, enc); } } } return NS_OK; }