Back to index

lightning-sunbird  0.9+nobinonly
nsSOAPHeaderBlock.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsString.h"
00039 #include "nsReadableUtils.h"
00040 #include "nsSOAPHeaderBlock.h"
00041 #include "nsSOAPUtils.h"
00042 #include "nsIServiceManager.h"
00043 #include "nsISOAPAttachments.h"
00044 #include "nsISOAPMessage.h"
00045 #include "nsSOAPException.h"
00046 
00047 nsSOAPHeaderBlock::nsSOAPHeaderBlock()
00048 {
00049 }
00050 
00051 NS_IMPL_CI_INTERFACE_GETTER2(nsSOAPHeaderBlock, nsISOAPBlock,
00052                              nsISOAPHeaderBlock)
00053     NS_IMPL_ADDREF_INHERITED(nsSOAPHeaderBlock, nsSOAPBlock)
00054     NS_IMPL_RELEASE_INHERITED(nsSOAPHeaderBlock, nsSOAPBlock)
00055     NS_INTERFACE_MAP_BEGIN(nsSOAPHeaderBlock)
00056     NS_INTERFACE_MAP_ENTRY(nsISOAPHeaderBlock)
00057     NS_IMPL_QUERY_CLASSINFO(nsSOAPHeaderBlock)
00058     NS_INTERFACE_MAP_END_INHERITING(nsSOAPBlock) nsSOAPHeaderBlock::
00059     ~nsSOAPHeaderBlock()
00060 {
00061 }
00062 
00063 /* attribute AString actorURI; */
00064 NS_IMETHODIMP nsSOAPHeaderBlock::GetActorURI(nsAString & aActorURI)
00065 {
00066   if (mElement) {
00067     if (mVersion == nsISOAPMessage::VERSION_UNKNOWN)
00068       return SOAP_EXCEPTION(NS_ERROR_NOT_AVAILABLE,"SOAP_HEADER_INIT", "Header has not been properly initialized.");
00069     return mElement->GetAttributeNS(*gSOAPStrings->kSOAPEnvURI[mVersion],
00070                                     gSOAPStrings->kActorAttribute,
00071                                     aActorURI);
00072   } else {
00073     aActorURI.Assign(mActorURI);
00074   }
00075   return NS_OK;
00076 }
00077 
00078 NS_IMETHODIMP nsSOAPHeaderBlock::SetActorURI(const nsAString & aActorURI)
00079 {
00080   nsresult rc = SetElement(nsnull);
00081   if (NS_FAILED(rc))
00082     return rc;
00083   mActorURI.Assign(aActorURI);
00084   return NS_OK;
00085 }
00086 
00087 /* attribute AString mustUnderstand; */
00088 NS_IMETHODIMP nsSOAPHeaderBlock::GetMustUnderstand(PRBool *
00089                                                    aMustUnderstand)
00090 {
00091   if (mElement) {
00092     if (mVersion == nsISOAPMessage::VERSION_UNKNOWN)
00093       return SOAP_EXCEPTION(NS_ERROR_NOT_AVAILABLE,"SOAP_HEADER_INIT", "Header has not been properly initialized.");
00094     nsAutoString m;
00095     nsresult
00096         rc =
00097         mElement->
00098         GetAttributeNS(*gSOAPStrings->kSOAPEnvURI[mVersion],
00099                        gSOAPStrings->kMustUnderstandAttribute, m);
00100     if (NS_FAILED(rc))
00101       return rc;
00102     if (m.IsEmpty())
00103       *aMustUnderstand = PR_FALSE;
00104     else if (m.Equals(gSOAPStrings->kTrue)
00105              || m.Equals(gSOAPStrings->kTrueA))
00106       *aMustUnderstand = PR_TRUE;
00107     else if (m.Equals(gSOAPStrings->kFalse)
00108              || m.Equals(gSOAPStrings->kFalseA))
00109       *aMustUnderstand = PR_FALSE;
00110     else
00111       return SOAP_EXCEPTION(NS_ERROR_ILLEGAL_VALUE,"SOAP_HEADER_MUSTUNDERSTAND", "Must understand value in header has an illegal value.");
00112     return NS_OK;
00113   } else {
00114     *aMustUnderstand = mMustUnderstand;
00115   }
00116   return NS_OK;
00117 }
00118 
00119 NS_IMETHODIMP nsSOAPHeaderBlock::SetMustUnderstand(PRBool aMustUnderstand)
00120 {
00121   nsresult rc = SetElement(nsnull);
00122   if (NS_FAILED(rc))
00123     return rc;
00124   mMustUnderstand = aMustUnderstand;
00125   return NS_OK;
00126 }