XSURI.Assign(nsSOAPUtils::kXSURI); XSIURI.Assign(nsSOAPUtils::kXSIURI); SOAPEncURI.Assign(nsSOAPUtils::kSOAPEncURI);
XSURI.Assign(gSOAPStrings->kXSURI); XSIURI.Assign(gSOAPStrings->kXSIURI); SOAPEncURI.Assign(gSOAPStrings->kSOAPEncURI);
static nsresult GetTransportURI(nsISOAPCall * aCall, nsAString & aURI){  nsresult rc = aCall->GetTransportURI(aURI);  if (NS_FAILED(rc))    return rc;    // Create a new URI  nsCOMPtr<nsIURI> uri;  rc = NS_NewURI(getter_AddRefs(uri), aURI, nsnull);  if (NS_FAILED(rc))     return rc;  nsCOMPtr<nsIWebScriptsAccessService> wsa_service =       do_GetService(NS_WEBSCRIPTSACCESSSERVICE_CONTRACTID, &rc);  if (NS_FAILED(rc))     return rc;   PRBool safe = PR_FALSE;  rc = aCall->GetVerifySourceHeader(&safe);  if (NS_FAILED(rc))     return rc;  nsCOMPtr<nsIScriptSecurityManager> secMan;  PRBool accessGranted;  if (!safe) {    rc = wsa_service->CanAccess(uri, NS_LITERAL_STRING("soap"), &accessGranted);    if (NS_FAILED(rc))      return rc;    if (!accessGranted) {      // Get security manager, check to see if we're allowed to call this URI.      secMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rc);      if (NS_FAILED(rc))         return rc;      if (NS_FAILED(secMan->CheckConnect(nsnull, uri, "SOAPCall", "invoke")))        return SOAP_EXCEPTION(NS_ERROR_FAILURE,                              "SOAP_INVOKE_DISABLED",                               "SOAPCall.invoke not enabled by client");    }  }  else {    // Get security manager, check to see if we're allowed to call this URI.    secMan = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rc);    if (NS_FAILED(rc))      return rc;    rc = wsa_service->CanAccess(uri, NS_LITERAL_STRING("soapv"), &accessGranted);    if (NS_FAILED(rc))      return rc;    if (!accessGranted) {      if (NS_FAILED(secMan->CheckConnect(nsnull, uri, "SOAPCall", "invokeVerifySourceHeader")))        return SOAP_EXCEPTION(NS_ERROR_FAILURE,                              "SOAP_INVOKE_VERIFY_DISABLED",                               "SOAPCall.invokeVerifySourceHeader not enabled by client");    }    nsAutoString sourceURI;    {      nsCOMPtr<nsIPrincipal> principal;      rc = secMan->GetSubjectPrincipal(getter_AddRefs(principal));      if (NS_FAILED(rc))         return rc;      if (!principal) {        return SOAP_EXCEPTION(NS_ERROR_FAILURE,                              "SOAP_INVOKE_VERIFY_PRINCIPAL",                               "Source-verified message cannot be sent without principal.");      }      nsCOMPtr<nsIURI> uri;      principal->GetURI(getter_AddRefs(uri));      if (!uri) {        return SOAP_EXCEPTION(NS_ERROR_FAILURE,                              "SOAP_INVOKE_VERIFY_URI",                               "Source-verified message cannot be sent without URI.");      }      nsCAutoString spec;      rc = uri->GetSpec(spec);      if (NS_FAILED(rc))         return rc;      CopyASCIItoUCS2(spec, sourceURI);    }//  Adding a header to tell the server that it must understand and verify the source of the call    nsCOMPtr<nsIDOMElement> element;    rc = aCall->GetHeader(getter_AddRefs(element));    if (NS_FAILED(rc))       return rc;    if (!element)      return SOAP_EXCEPTION(NS_ERROR_FAILURE,"SOAP_INVOKE_VERIFY_HEADER", "Source-verified message cannot be sent without a header.");    //  Node ignored on remove / append calls    nsCOMPtr<nsIDOMNode> ignore;    //  Remove any existing elements that may conflict with this verifySource identification    nsCOMPtr<nsIDOMElement> verifySource;    for (;;) {      nsSOAPUtils::GetSpecificChildElement(nsnull, element, nsSOAPUtils::kVerifySourceNamespaceURI,         nsSOAPUtils::kVerifySourceHeader, getter_AddRefs(verifySource));      if (verifySource) {        element->RemoveChild(verifySource, getter_AddRefs(ignore));        if (NS_FAILED(rc))          return rc;      }      else       break;    }    //  Document as factory    nsCOMPtr<nsIDOMDocument> document;    rc = element->GetOwnerDocument(getter_AddRefs(document));    if (NS_FAILED(rc))       return rc;    //  Proper version to use of SOAP    PRUint16 version;    rc = aCall->GetVersion(&version);    if (NS_FAILED(rc))       return rc;    //  Proper schema to use for types    nsAutoString XSURI;    nsAutoString XSIURI;    nsAutoString SOAPEncURI;    if (version == nsISOAPMessage::VERSION_1_1) {      XSURI.Assign(nsSOAPUtils::kXSURI1999);      XSIURI.Assign(nsSOAPUtils::kXSIURI1999);      SOAPEncURI.Assign(nsSOAPUtils::kSOAPEncURI11);    }    else {      XSURI.Assign(nsSOAPUtils::kXSURI);      XSIURI.Assign(nsSOAPUtils::kXSIURI);      SOAPEncURI.Assign(nsSOAPUtils::kSOAPEncURI);    }    //  Create the header and append it with mustUnderstand and normal encoding.    rc = document->CreateElementNS(nsSOAPUtils::kVerifySourceNamespaceURI,       nsSOAPUtils::kVerifySourceHeader,       getter_AddRefs(verifySource));    if (NS_FAILED(rc))       return rc;    rc = element->AppendChild(verifySource, getter_AddRefs(ignore));    if (NS_FAILED(rc))       return rc;    rc = verifySource->SetAttributeNS(*nsSOAPUtils::kSOAPEnvURI[version],      nsSOAPUtils::kMustUnderstandAttribute,nsSOAPUtils::kTrueA);// mustUnderstand    if (NS_FAILED(rc))       return rc;    rc = verifySource->SetAttributeNS(*nsSOAPUtils::kSOAPEnvURI[version],       nsSOAPUtils::kEncodingStyleAttribute, SOAPEncURI);// 1.2 encoding    if (NS_FAILED(rc))       return rc;    //  Prefixed string for xsi:string    nsAutoString stringType;    {      nsAutoString prefix;      rc = nsSOAPUtils::MakeNamespacePrefix(nsnull, verifySource, XSURI, stringType);      if (NS_FAILED(rc))         return rc;      stringType.Append(nsSOAPUtils::kQualifiedSeparator);      stringType.Append(kAnyURISchemaType);    }    //  If it is available, add the sourceURI     if (!sourceURI.IsEmpty()) {      rc = document->CreateElementNS(nsSOAPUtils::kVerifySourceNamespaceURI,        nsSOAPUtils::kVerifySourceURI,getter_AddRefs(element));      if (NS_FAILED(rc))         return rc;      rc = verifySource->AppendChild(element, getter_AddRefs(ignore));      if (NS_FAILED(rc))         return rc;      rc = element->SetAttributeNS(XSIURI,        nsSOAPUtils::kXSITypeAttribute,stringType);      if (NS_FAILED(rc))         return rc;      nsCOMPtr<nsIDOMText> text;      rc = document->CreateTextNode(sourceURI, getter_AddRefs(text));      if (NS_FAILED(rc))       return rc;      element->AppendChild(text, getter_AddRefs(ignore));      if (NS_FAILED(rc))       return rc;    }  }  return NS_OK;}