webservices/wsmessages/src/sensoapenvelope2.cpp
changeset 0 62f9d29f7211
child 20 f68f07157250
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:       
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include <s32strm.h>
       
    27 
       
    28 #include <SenXmlUtils.h>
       
    29 #include <SenDomFragmentBase.h>
       
    30 #include <xmlengnodelist.h>
       
    31 
       
    32 
       
    33 #include "SenSoapEnvelope2.h"
       
    34 #include "SenSoapFault2.h"
       
    35 #include "senlayeredtransportproperties.h"
       
    36 #include "senmessagecontext.h"
       
    37 #include "msenmessagecontext.h"
       
    38 
       
    39 #include "SenXmlProperties.h" // for de-alloc
       
    40 #include "senlayeredxmlproperties.h" // for de-alloc
       
    41 
       
    42 #include "sendebug.h"
       
    43 #include "senlogger.h"
       
    44 #include "wslibxml2utils.h"
       
    45 
       
    46 EXPORT_C CSenSoapEnvelope2* CSenSoapEnvelope2::NewL()
       
    47     {
       
    48     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::NewL()");    
       
    49     CSenSoapEnvelope2* pNew = CSenSoapEnvelope2::NewLC();
       
    50     CleanupStack::Pop( pNew ); // pNew
       
    51     return pNew;    
       
    52     }
       
    53     
       
    54 EXPORT_C CSenSoapEnvelope2* CSenSoapEnvelope2::NewLC()
       
    55     {
       
    56     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::NewLC()");    
       
    57     CSenSoapEnvelope2* pNew = new (ELeave) CSenSoapEnvelope2();
       
    58     CleanupStack::PushL(pNew);
       
    59     pNew->BaseConstructL();
       
    60     return pNew;
       
    61     }
       
    62 
       
    63 EXPORT_C CSenSoapEnvelope2* CSenSoapEnvelope2::NewL(MSenMessageContext& aContext)
       
    64     {
       
    65     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::NewL(aContext)");    
       
    66     CSenSoapEnvelope2* pNew = CSenSoapEnvelope2::NewLC(aContext);
       
    67     CleanupStack::Pop(pNew); // pNew
       
    68     return pNew;    
       
    69     }
       
    70 
       
    71 EXPORT_C CSenSoapEnvelope2* CSenSoapEnvelope2::NewLC(MSenMessageContext& aContext)
       
    72     {
       
    73     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::NewLC(aContext)");    
       
    74     CSenSoapEnvelope2* pNew = new (ELeave) CSenSoapEnvelope2();
       
    75     CleanupStack::PushL(pNew);
       
    76     pNew->BaseConstructL(aContext);
       
    77     return pNew;
       
    78     }
       
    79 
       
    80 EXPORT_C CSenSoapEnvelope2* CSenSoapEnvelope2::NewL(CSenSoapEnvelope2& aEnvelope)
       
    81     {
       
    82     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::NewLC(aEnvelope)");    
       
    83     CSenSoapEnvelope2* pNew = CSenSoapEnvelope2::NewLC(aEnvelope);
       
    84     CleanupStack::Pop(pNew); // pNew
       
    85     return pNew;    
       
    86     }
       
    87 
       
    88 EXPORT_C CSenSoapEnvelope2* CSenSoapEnvelope2::NewLC(CSenSoapEnvelope2& aEnvelope)
       
    89     {
       
    90     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::NewLC(aEnvelope)");    
       
    91     CSenSoapEnvelope2* pNew = new (ELeave) CSenSoapEnvelope2();
       
    92     CleanupStack::PushL(pNew);
       
    93     pNew->BaseConstructL(aEnvelope);
       
    94     return pNew;
       
    95     }
       
    96 
       
    97 EXPORT_C void CSenSoapEnvelope2::BaseConstructL(TSOAPVersion aVersion)
       
    98     {
       
    99     if (aVersion != ESOAP12)
       
   100         {
       
   101         CSenFragmentBase::BaseConstructL(KSenSoapEnvelopeXmlns,
       
   102                                          KSenSoapEnvelopeName,
       
   103                                          KSenSoapEnvelopePrefix);
       
   104         }
       
   105     else
       
   106         {
       
   107         CSenFragmentBase::BaseConstructL(KSenSoap12EnvelopeXmlns,
       
   108                                          KSenSoapEnvelopeName,
       
   109                                          KSenSoapEnvelopePrefix);
       
   110 
       
   111         }
       
   112     }
       
   113 
       
   114 EXPORT_C void CSenSoapEnvelope2::BaseConstructL(MSenMessageContext& aContext)
       
   115     {
       
   116     ipNotOwnedContext = &aContext;
       
   117     BaseConstructL(ESOAP11);
       
   118     }
       
   119 
       
   120 EXPORT_C void CSenSoapEnvelope2::BaseConstructL(MSenMessageContext& aContext, TSOAPVersion aVersion)
       
   121     {
       
   122     ipNotOwnedContext = &aContext;
       
   123     BaseConstructL(aVersion);
       
   124     }
       
   125 
       
   126 EXPORT_C void CSenSoapEnvelope2::BaseConstructL()
       
   127     {
       
   128     BaseConstructL(ESOAP11);
       
   129     }
       
   130 
       
   131 EXPORT_C void CSenSoapEnvelope2::BaseConstructL(CSenSoapEnvelope2& aEnvelope)
       
   132     {
       
   133     CSenFragmentBase::BaseConstructL(aEnvelope.AsElementL());
       
   134     
       
   135     iTransactionId       = aEnvelope.iTransactionId;
       
   136     ipNotOwnedContext    = aEnvelope.ipNotOwnedContext;
       
   137     iFault               = aEnvelope.iFault;
       
   138     iDirection           = aEnvelope.iDirection;
       
   139     ipNotOwnedContext    = aEnvelope.ipNotOwnedContext;
       
   140     
       
   141     if ( aEnvelope.ipSoapAction )
       
   142         {
       
   143         ipSoapAction = aEnvelope.ipSoapAction->AllocL();
       
   144         }
       
   145         
       
   146     if ( aEnvelope.ipBodyFragment )
       
   147         {
       
   148         TXmlEngElement envelope = AsElementL();
       
   149         TXmlEngElement body;
       
   150 
       
   151         RXmlEngNodeList<TXmlEngElement> list;
       
   152         CleanupClosePushL(list);
       
   153         envelope.GetElementsByTagNameL(list, KSenSoapEnvelopeBodyName,
       
   154                                              NsUri());
       
   155         if ( list.Count() > 0 )
       
   156             {
       
   157             body = list.Next();
       
   158             ipBodyFragment = CSenFragmentBase::NewL(body, AsDocumentL());
       
   159             }
       
   160         
       
   161         CleanupStack::PopAndDestroy(&list);
       
   162         }
       
   163         
       
   164     if ( aEnvelope.ipHeaderFragment )
       
   165         {
       
   166         TXmlEngElement envelope = AsElementL();
       
   167         TXmlEngElement header;
       
   168         
       
   169         RXmlEngNodeList<TXmlEngElement> list;
       
   170         CleanupClosePushL(list);
       
   171         envelope.GetElementsByTagNameL(list, KSenSoapEnvelopeHeaderName,
       
   172                                              NsUri());
       
   173         if ( list.Count() > 0 )
       
   174             {
       
   175             ipHeaderFragment = CSenFragmentBase::NewL(header, AsDocumentL());
       
   176             }
       
   177         
       
   178         CleanupStack::PopAndDestroy(&list);
       
   179         }
       
   180         
       
   181     if ( aEnvelope.ipProperties )
       
   182         {
       
   183         ipProperties = aEnvelope.ipProperties->CloneL();
       
   184         }    
       
   185     }
       
   186 
       
   187 CSenSoapEnvelope2::CSenSoapEnvelope2()
       
   188 :   ipBodyFragment(NULL),
       
   189     ipHeaderFragment(NULL),
       
   190     ipSoapAction(NULL),
       
   191     iFault(EFalse)
       
   192     {
       
   193     }
       
   194 
       
   195 EXPORT_C CSenSoapEnvelope2::~CSenSoapEnvelope2()
       
   196     {
       
   197     if(ipBodyFragment)
       
   198         {
       
   199         ipBodyFragment->ExtractElement();
       
   200         delete ipBodyFragment;
       
   201         }
       
   202     if(ipHeaderFragment)
       
   203         {
       
   204         ipHeaderFragment->ExtractElement(); // // delegate's element is owned by us
       
   205         delete ipHeaderFragment;
       
   206         }
       
   207     delete ipSoapAction;
       
   208 
       
   209     if( ipProperties )
       
   210         {
       
   211         
       
   212         if ( ipProperties->IsSafeToCast( MSenProperties::ESenXmlProperties ) )
       
   213             {
       
   214             CSenXmlProperties* pFlatProps = (CSenXmlProperties*)ipProperties;
       
   215             delete pFlatProps;
       
   216             ipProperties = NULL;
       
   217             }
       
   218         else if ( ipProperties->IsSafeToCast( MSenProperties::ESenLayeredXmlProperties ) )
       
   219             {
       
   220             CSenLayeredXmlProperties* pLayeredProps = (CSenLayeredXmlProperties*)ipProperties;
       
   221             delete pLayeredProps;
       
   222             ipProperties = NULL;
       
   223             }
       
   224         // else // TLS log as fatal..
       
   225         }
       
   226     }
       
   227     
       
   228 
       
   229 EXPORT_C void CSenSoapEnvelope2::OnStartElementL(const RTagInfo& aElement,
       
   230     	                                         const RAttributeArray& aAttributes,
       
   231                                                  TInt /*aErrorCode*/)
       
   232     {
       
   233     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::OnStartElementL");    
       
   234     const TPtrC8 saxLocalName   = aElement.LocalName().DesC();
       
   235     const TPtrC8 saxNsUri       = aElement.Uri().DesC();
       
   236     const TPtrC8 saxPrefix      = aElement.Prefix().DesC();
       
   237         
       
   238     switch (iState)
       
   239         {
       
   240         case KSenStateIgnore:
       
   241             {
       
   242             // check if we encounter the start of a soap:Envelope...
       
   243             if ( iElement.IsNull() && saxNsUri == NsUri() &&
       
   244                  saxLocalName == KSenSoapEnvelopeName )
       
   245                 {
       
   246                 if ( saxNsUri == KNullDesC8 && saxPrefix == KNullDesC8 )
       
   247                     {
       
   248                     iDocument.CreateDocumentElementL(saxLocalName);
       
   249                     }
       
   250                 else
       
   251                     {
       
   252                     if ( saxPrefix == KNullDesC8 )
       
   253                         {
       
   254                         iDocument.CreateDocumentElementL(saxLocalName,
       
   255                                                          saxNsUri,
       
   256                                                          KNullDesC8);
       
   257                         }
       
   258                     else
       
   259                         {
       
   260                         iDocument.CreateDocumentElementL(saxLocalName,
       
   261                                                          saxNsUri,
       
   262                                                          saxPrefix);
       
   263                         }
       
   264                     }
       
   265                 iElement = iDocument.DocumentElement();        
       
   266                 }
       
   267                 
       
   268             if ( iElement.NotNull() && saxLocalName == KSenSoapEnvelopeName && saxNsUri != NsUri() )
       
   269                 {
       
   270                 iElement.Remove();
       
   271                 if ( saxNsUri == KNullDesC8 && saxPrefix == KNullDesC8 )
       
   272                     {
       
   273                     iDocument.CreateDocumentElementL(saxLocalName);
       
   274                     }
       
   275                 else
       
   276                     {
       
   277                     if ( saxPrefix == KNullDesC8 )
       
   278                         {
       
   279                         iDocument.CreateDocumentElementL(saxLocalName,
       
   280                                                          saxNsUri,
       
   281                                                          KNullDesC8);
       
   282                         }
       
   283                     else
       
   284                         {
       
   285                         iDocument.CreateDocumentElementL(saxLocalName,
       
   286                                                          saxNsUri,
       
   287                                                          saxPrefix);
       
   288                         }
       
   289                     }
       
   290                 iElement = iDocument.DocumentElement();        
       
   291                 }
       
   292                 
       
   293 
       
   294             if ( iElement.NotNull() && LocalName() == saxLocalName &&
       
   295                  NsUri() == saxNsUri )
       
   296                 {
       
   297                 TXmlEngElement element = AsElementL();
       
   298                 WsXmlUtils domUtils;       
       
   299                 domUtils.XmlEngRenameElementL(element, saxLocalName, saxNsUri, saxPrefix);
       
   300                 AddAttributesToElementL(element, aAttributes);
       
   301                 }
       
   302 
       
   303             else if ( saxNsUri == NsUri() )
       
   304                 {
       
   305                 // we are interested in SOAP Header
       
   306                 if ( saxLocalName == KSenSoapEnvelopeHeaderName )
       
   307                     {
       
   308                     iState = KStateParsingSoapHeader;
       
   309 
       
   310                     // Make sure that header element exists:
       
   311                     // == this ensures that we add a "Header"
       
   312                     // element to the children:
       
   313                     TXmlEngElement header = HeaderL();
       
   314                     
       
   315                     WsXmlUtils domUtils;       
       
   316                     domUtils.XmlEngRenameElementL(header, saxLocalName, saxNsUri, saxPrefix);
       
   317                     AddAttributesToElementL(header, aAttributes);
       
   318                     }
       
   319                 else if( saxLocalName == KSenSoapEnvelopeBodyName )
       
   320                     {
       
   321                     iState = KStateParsingSoapBody;
       
   322 
       
   323                     TXmlEngElement body = BodyL();
       
   324                     WsXmlUtils domUtils;
       
   325                     domUtils.XmlEngRenameElementL(body, saxLocalName, saxNsUri, saxPrefix);
       
   326                     AddAttributesToElementL(body, aAttributes);
       
   327                     }
       
   328                 //ESLI-6WEN9V
       
   329                 //This case is to handle fault which lies outside the body or without body
       
   330                 else if( saxLocalName == KSenSoapFaultName)
       
   331 	                 	{
       
   332 	                 	iFault = ETrue;
       
   333 	                	RSenDocument document = AsDocumentL();
       
   334 	                	TXmlEngElement element = BodyL();
       
   335 	                                
       
   336 	                	// delegate parsing to a SOAPFaultFragment to keep
       
   337 	                	// a structured representation.
       
   338 	                	ipBodyFragment = CSenSoapFault2::NewL(saxNsUri,
       
   339 	                                                      saxLocalName,
       
   340 	                                                      saxPrefix,
       
   341 	                                                      aAttributes,
       
   342 	                                                      element,
       
   343 	                                                      document);
       
   344 	                                                      
       
   345 	                	OnDelegateParsingL(*ipBodyFragment);	
       
   346 	                 	
       
   347 	                 	}
       
   348                 //ESLI-6WEN9V
       
   349                 }
       
   350             break;
       
   351             }
       
   352         case KStateParsingSoapHeader:
       
   353             {
       
   354             ParseHeaderL(aElement, aAttributes);
       
   355             }
       
   356             break;
       
   357         case KStateParsingSoapBody:
       
   358             {
       
   359             if ( ipBodyFragment )
       
   360                 {
       
   361                 ipBodyFragment->ExtractElement();
       
   362                 delete ipBodyFragment;
       
   363                 ipBodyFragment = NULL;
       
   364                 }
       
   365 
       
   366             // check if we encounter a Fault
       
   367             if ( saxLocalName == KSenSoapFaultName )
       
   368                 {
       
   369                 iFault = ETrue;
       
   370                 RSenDocument document = AsDocumentL();
       
   371                 TXmlEngElement element = BodyL();
       
   372                                 
       
   373                 // delegate parsing to a SOAPFaultFragment to keep
       
   374                 // a structured representation.
       
   375                 ipBodyFragment = CSenSoapFault2::NewL(saxNsUri,
       
   376                                                       saxLocalName,
       
   377                                                       saxPrefix,
       
   378                                                       aAttributes,
       
   379                                                       element,
       
   380                                                       document);
       
   381                                                       
       
   382                 OnDelegateParsingL(*ipBodyFragment);
       
   383                 }
       
   384             else
       
   385                 {
       
   386                 RSenDocument document = AsDocumentL();
       
   387                 TXmlEngElement element = BodyL();
       
   388                 
       
   389                 // Delegate uses same document
       
   390                 // Parent for delegate will be body
       
   391                 
       
   392 				ipBodyFragment = CreateBodyFragmentL(saxNsUri, 
       
   393 				                                     saxLocalName,
       
   394 					                                 saxPrefix, 
       
   395 					                                 aAttributes,
       
   396 					                                 element, 
       
   397 					                                 document);
       
   398 				
       
   399 				
       
   400                 OnDelegateParsingL(*ipBodyFragment);
       
   401                 }
       
   402             }
       
   403             break;
       
   404         default:
       
   405             break;
       
   406         }
       
   407     }
       
   408 
       
   409 EXPORT_C void CSenSoapEnvelope2::OnEndElementL(
       
   410                                             const RTagInfo& aElement,
       
   411                                             TInt /*aErrorCode*/)
       
   412     {
       
   413     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::OnEndElementL");    
       
   414     const TPtrC8 saxLocalName   = aElement.LocalName().DesC();
       
   415     const TPtrC8 saxNsUri       = aElement.Uri().DesC();
       
   416     const TPtrC8 saxPrefix      = aElement.Prefix().DesC();
       
   417     
       
   418     switch (iState)
       
   419         {
       
   420         case KSenStateIgnore:
       
   421             {
       
   422             break;
       
   423             }
       
   424         case KStateParsingSoapHeader:
       
   425             {
       
   426             if (saxNsUri == NsUri() && saxLocalName == KSenSoapEnvelopeHeaderName)
       
   427                 {
       
   428                 iState = KSenStateIgnore;
       
   429                 }
       
   430             break;
       
   431             }
       
   432         case KStateParsingSoapBody:
       
   433             {
       
   434             if (saxNsUri == NsUri() && saxLocalName == KSenSoapEnvelopeBodyName)
       
   435                 {
       
   436                 iState = KSenStateIgnore;
       
   437                 }
       
   438 /*            else
       
   439                 {
       
   440                 if(ipBodyFragment)
       
   441                     {
       
   442                     //ipBodyFragment->EnsureNamespacesL();
       
   443                     }
       
   444                 }*/
       
   445             }
       
   446             break;
       
   447         default:
       
   448             break;
       
   449         }
       
   450     }
       
   451 
       
   452 EXPORT_C TXmlEngElement CSenSoapEnvelope2::SetBodyL(TXmlEngElement aBodyElement)
       
   453     {
       
   454     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::SetBodyL(aBodyElement)");    
       
   455     if ( aBodyElement.Name() == KSenSoapFaultName &&  aBodyElement.NamespaceUri() == NsUri() )
       
   456         {
       
   457         iFault = ETrue;
       
   458         }
       
   459     
       
   460     TXmlEngElement body = BodyL();
       
   461     body.RemoveChildren();
       
   462     aBodyElement.MoveTo(body);
       
   463     return aBodyElement;
       
   464     }
       
   465     
       
   466 EXPORT_C TPtrC8 CSenSoapEnvelope2::SetBodyL(const TDesC8& aBody)
       
   467     {
       
   468     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::SetBodyL(aBody)");
       
   469     TLSLOG_ALL(KSenMessagesLogChannel, KMaxLogLevel, aBody);
       
   470     TXmlEngElement body = BodyL();
       
   471     body.SetTextNoEncL(aBody);
       
   472     return TPtrC8(aBody);
       
   473     }
       
   474     
       
   475 
       
   476 EXPORT_C TXmlEngElement CSenSoapEnvelope2::BodyL()
       
   477     {
       
   478     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::BodyL()");
       
   479     TXmlEngElement envelope = AsElementL();
       
   480     TXmlEngElement body;
       
   481 
       
   482     RXmlEngNodeList<TXmlEngElement> list;
       
   483     CleanupClosePushL(list);
       
   484     envelope.GetElementsByTagNameL(list, KSenSoapEnvelopeBodyName,
       
   485                                          NsUri());
       
   486     if ( list.Count() > 0 )
       
   487         {
       
   488         body = list.Next();
       
   489         }
       
   490     else
       
   491         {
       
   492         body = envelope.AddNewElementL(KSenSoapEnvelopeBodyName);
       
   493 
       
   494         // Check if namespace declaration
       
   495         // is already defined in envelope.
       
   496         // => Should be!
       
   497         TXmlEngNamespace ns = envelope.LookupNamespaceByUriL(NsUri());
       
   498         if ( ns.IsUndefined() )
       
   499             {
       
   500             // Namespace declaration will be added
       
   501             body.AddNamespaceDeclarationL(NsUri(), KNullDesC8);
       
   502             }
       
   503         
       
   504         WsXmlUtils domUtils;       
       
   505         domUtils.XmlEngRenameElementL(body, KSenSoapEnvelopeBodyName, NsUri(), KNullDesC8);
       
   506         }    
       
   507     
       
   508     CleanupStack::PopAndDestroy(&list);
       
   509     return body;
       
   510     }
       
   511 
       
   512 EXPORT_C TXmlEngElement CSenSoapEnvelope2::HeaderL()
       
   513     {
       
   514     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::HeaderL()");
       
   515     TXmlEngElement envelope = AsElementL();
       
   516     TXmlEngElement header;
       
   517 
       
   518     RXmlEngNodeList<TXmlEngElement> list;
       
   519     CleanupClosePushL(list);
       
   520     envelope.GetElementsByTagNameL(list, KSenSoapEnvelopeHeaderName,
       
   521                                          NsUri());
       
   522     if ( list.Count() > 0 )
       
   523         {
       
   524         header = list.Next();
       
   525         }
       
   526     else
       
   527         {
       
   528         header = envelope.AddNewElementL(KSenSoapEnvelopeHeaderName);
       
   529 
       
   530         // Check if namespace declaration
       
   531         // is already defined in envelope.
       
   532         // => Should be!
       
   533         TXmlEngNamespace ns = envelope.LookupNamespaceByPrefixL(NsPrefix());
       
   534         WsXmlUtils domUtils;       
       
   535         domUtils.XmlEngRenameElementL(header, KSenSoapEnvelopeHeaderName, ns.Uri(), ns.Prefix() );
       
   536 
       
   537         TXmlEngElement body = BodyL();
       
   538         if ( body.NotNull() )
       
   539             {
       
   540             header.SetAsFirstSibling();
       
   541             }
       
   542         }
       
   543     CleanupStack::PopAndDestroy(&list);
       
   544         
       
   545     return header;
       
   546     }
       
   547 
       
   548 EXPORT_C TXmlEngElement CSenSoapEnvelope2::AddHeaderL(TXmlEngElement aHeaderElement)
       
   549     {
       
   550     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::AddHeaderL(aHeaderElement)");
       
   551     aHeaderElement.MoveTo(HeaderL());
       
   552     return aHeaderElement;
       
   553     }
       
   554 
       
   555 EXPORT_C void CSenSoapEnvelope2::ParseHeaderL(
       
   556                                         const RTagInfo& aElement,
       
   557                                         const RAttributeArray& aAttributes)
       
   558     {
       
   559     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::ParseHeaderL");
       
   560     const TPtrC8 saxLocalName   = aElement.LocalName().DesC();
       
   561     const TPtrC8 saxNsUri       = aElement.Uri().DesC();
       
   562     const TPtrC8 saxPrefix      = aElement.Prefix().DesC();
       
   563     
       
   564     if ( ipHeaderFragment )
       
   565         {
       
   566         delete ipHeaderFragment;
       
   567         ipHeaderFragment = NULL;
       
   568         }
       
   569         
       
   570     TXmlEngElement header = HeaderL();
       
   571     RSenDocument document = AsDocumentL();
       
   572         
       
   573     ipHeaderFragment = CSenDomFragmentBase::NewL(saxNsUri,
       
   574                                                  saxLocalName,
       
   575                                                  saxPrefix,
       
   576                                                  aAttributes,
       
   577                                                  header,
       
   578                                                  document
       
   579                                                  );
       
   580 
       
   581     OnDelegateParsingL(*ipHeaderFragment);
       
   582     }
       
   583 
       
   584 
       
   585 EXPORT_C HBufC8* CSenSoapEnvelope2::BodyAsStringL()
       
   586     {
       
   587     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::BodyAsStringL");
       
   588     TXmlEngElement body = BodyL();
       
   589     
       
   590     HBufC8* bodyAsXML = NULL;
       
   591 
       
   592     // Note, that difference to Jave ref-implementation here is,
       
   593     // that in *EVERY* case, no matter if SOAP BODY has no child 
       
   594     // element at all OR if it has one or more children, the whole
       
   595     // <S:Body> element is ALWAYS returned -- [never just the only
       
   596     // child, and never a of zero-length string, even if no children]
       
   597 
       
   598     body.Unlink(); // According to documentation RDocument which
       
   599                    // was holding the body TXmlEngElement remains owner
       
   600                    // until body is linked elsewhere or destroyed.
       
   601                    // => CleanupStack usage is not needed.
       
   602     body.ReconcileNamespacesL();
       
   603     RBuf8 buffer;
       
   604     CleanupClosePushL(buffer);
       
   605     body.OuterXmlL(buffer);
       
   606     bodyAsXML = buffer.AllocL();
       
   607     CleanupStack::PopAndDestroy(&buffer);
       
   608     body.Remove(); // Destroy Body
       
   609         
       
   610     return bodyAsXML;
       
   611     }
       
   612 
       
   613 EXPORT_C TBool CSenSoapEnvelope2::IsFault()
       
   614     {
       
   615     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::IsFault()");
       
   616     return iFault;
       
   617     }
       
   618 
       
   619 // NOTE: caller takes ownership of the NEW fault element
       
   620 EXPORT_C CSenSoapFault2* CSenSoapEnvelope2::DetachFaultL()
       
   621     {
       
   622     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::DetachFaultL()");
       
   623     TXmlEngElement body = BodyL();
       
   624     RXmlEngNodeList<TXmlEngElement> list;
       
   625     CleanupClosePushL(list);
       
   626     
       
   627     TXmlEngElement fault;
       
   628     body.GetElementsByTagNameL(list, KSenSoapFaultName, NsUri());
       
   629 
       
   630     if ( list.Count() > 0 )
       
   631         {
       
   632         fault = list.Next();
       
   633             
       
   634         fault.Unlink();
       
   635 
       
   636         fault.ReconcileNamespacesL();
       
   637 
       
   638         CSenSoapFault2* pAnswer = CSenSoapFault2::NewL(fault);
       
   639         CleanupStack::PopAndDestroy(&list);
       
   640         return pAnswer;
       
   641         }
       
   642         
       
   643     CleanupStack::PopAndDestroy(&list);
       
   644     return NULL;
       
   645     }
       
   646 
       
   647 EXPORT_C CSenSoapFault2* CSenSoapEnvelope2::FaultL()
       
   648     {
       
   649     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::FaultL()");
       
   650     TXmlEngElement body = BodyL();
       
   651     TXmlEngElement fault;
       
   652 
       
   653     RXmlEngNodeList<TXmlEngElement> list;
       
   654     CleanupClosePushL(list);
       
   655     body.GetElementsByTagNameL(list, KSenSoapFaultName,  NsUri());
       
   656     if ( list.Count() > 0 )
       
   657         {
       
   658         fault = list.Next();
       
   659 
       
   660         CSenSoapFault2* pAnswer = CSenSoapFault2::NewL(fault,
       
   661                                                        AsDocumentL());
       
   662         CleanupStack::PopAndDestroy(&list);
       
   663         return pAnswer;
       
   664         }
       
   665 
       
   666     CleanupStack::PopAndDestroy(&list);
       
   667     return NULL;
       
   668     }
       
   669 
       
   670 EXPORT_C TPtrC8 CSenSoapEnvelope2::SetSoapActionL(const TDesC8& aSoapAction)
       
   671     {
       
   672     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::SetSoapActionL(aSoapAction)");
       
   673 
       
   674     _LIT8(KQuote, "\"");
       
   675     HBufC8* pTemp = HBufC8::NewLC(aSoapAction.Length()+(2*KQuote().Length()));
       
   676 
       
   677     TPtr8 temp = pTemp->Des();
       
   678 
       
   679     if(!SenXmlUtils::StartsWith(aSoapAction, KQuote))
       
   680         {
       
   681         temp.Append(KQuote);
       
   682         }
       
   683     temp.Append(aSoapAction);
       
   684 
       
   685     if(!SenXmlUtils::EndsWith(*pTemp, KQuote))
       
   686         {
       
   687         temp.Append(KQuote);
       
   688         }
       
   689 
       
   690     if(ipSoapAction)
       
   691         {
       
   692         delete ipSoapAction;
       
   693         ipSoapAction = NULL;
       
   694         }
       
   695     ipSoapAction = pTemp;
       
   696     CleanupStack::Pop(); // pTemp is now safe
       
   697     return SoapAction();
       
   698     }
       
   699 
       
   700 
       
   701 EXPORT_C TPtrC8 CSenSoapEnvelope2::SoapAction()
       
   702     {
       
   703     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::SoapAction()");
       
   704     if(ipSoapAction)
       
   705         {
       
   706         return ipSoapAction->Des();
       
   707         }
       
   708     else
       
   709         {
       
   710         // Note, that zero-length descriptor must be returned
       
   711         // if SetSoapActionL() has not been called. Otherwise,
       
   712         // when passing transport properties over IPC boundary,
       
   713         // code cannot determine whether the caller, who utilizes
       
   714         // CSenSoapEnvelope wishes to override any underlying
       
   715         // value of SOAPAction with "empty" value (== "").
       
   716         // If SOAPAction is set in CSenSoapEnvelope, it is stronger
       
   717         // than message level (SendL/SubmitL in CSenServiceConnection)
       
   718         // or session level (SetTransportPropertiesL) definitions.
       
   719         return KNullDesC8(); 
       
   720         }        
       
   721     }
       
   722 
       
   723 EXPORT_C TBool CSenSoapEnvelope2::HasHeader()
       
   724     {
       
   725     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::HasHeader()");
       
   726     TInt err( KErrNone );
       
   727     TInt count( 0 );
       
   728     RXmlEngNodeList<TXmlEngElement> list;
       
   729     TRAP(   
       
   730         err, 
       
   731         TXmlEngElement envelope = AsElementL(); 
       
   732         envelope.GetElementsByTagNameL(list, KSenSoapEnvelopeHeaderName, NsUri() );    
       
   733          )
       
   734     if( !err ) 
       
   735         {
       
   736         count = list.Count();
       
   737         }
       
   738     list.Close();
       
   739     if ( count > 0 )
       
   740         {
       
   741         return ETrue;
       
   742         }
       
   743     else
       
   744         {
       
   745         // actually, there could be some header(s), but it could not be checked, if a leave occured.       
       
   746         return EFalse;
       
   747         }
       
   748     }
       
   749 
       
   750 EXPORT_C TBool CSenSoapEnvelope2::HasBody()
       
   751     {
       
   752     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::HasBody()");
       
   753     TInt err( KErrNone );
       
   754     TInt count( 0 );
       
   755     RXmlEngNodeList<TXmlEngElement> list;
       
   756     
       
   757     TRAP( 
       
   758         err, 
       
   759         TXmlEngElement envelope = AsElementL(); 
       
   760         envelope.GetElementsByTagNameL(list, KSenSoapEnvelopeBodyName, NsUri());
       
   761         )
       
   762     if( !err )
       
   763         {
       
   764         count = list.Count();
       
   765         }
       
   766     list.Close();            
       
   767     if ( count > 0 )
       
   768         {
       
   769         return ETrue;
       
   770         }
       
   771     else
       
   772         {
       
   773         // actually, there could be body, but it could not be checked, if a leave occured.                   
       
   774         return EFalse;
       
   775         }
       
   776     }
       
   777     
       
   778 EXPORT_C TSOAPVersion CSenSoapEnvelope2::SoapVersion()
       
   779     {
       
   780     if( NsUri() == KSenSoap12EnvelopeXmlns )
       
   781         {
       
   782         return ESOAP12;
       
   783         }
       
   784     else 
       
   785         {
       
   786         return ESOAP11;
       
   787         }
       
   788     }
       
   789     
       
   790 EXPORT_C MSenMessage::TClass CSenSoapEnvelope2::Type()
       
   791     {
       
   792     return MSenMessage::ESoapEnvelope2;
       
   793     }
       
   794 
       
   795 EXPORT_C MSenMessage::TDirection CSenSoapEnvelope2::Direction()
       
   796     {
       
   797     return iDirection;
       
   798     }
       
   799 
       
   800 /*
       
   801 EXPORT_C MSenProperties& CSenSoapEnvelope2::Properties()
       
   802     {
       
   803     if ( ipContext == NULL )
       
   804         {
       
   805         return *ipNotOwnedContext->TransportProperties();
       
   806         }
       
   807 
       
   808     return *ipContext->TransportProperties();
       
   809     }
       
   810     
       
   811 EXPORT_C MSenMessageContext& CSenSoapEnvelope2::Context()    
       
   812     {
       
   813     if ( ipContext == NULL )
       
   814         {
       
   815         return *ipNotOwnedContext;
       
   816         }
       
   817 
       
   818     return *ipContext;
       
   819     }
       
   820 */
       
   821 
       
   822 EXPORT_C TInt CSenSoapEnvelope2::SetContext(MSenMessageContext* apNotOwnedContext)
       
   823     {
       
   824     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::SetContext(MSenMessageContext)");
       
   825     if( !apNotOwnedContext )
       
   826         {
       
   827         return KErrArgument;
       
   828         }
       
   829 
       
   830     // switching to NEW context always resets any existing properties(!)
       
   831     if(ipProperties)
       
   832     	{
       
   833         if ( ipProperties->IsSafeToCast(MSenProperties::ESenXmlProperties) )
       
   834             {
       
   835             CSenXmlProperties* pFlatProps = (CSenXmlProperties*)ipProperties;
       
   836             delete pFlatProps;
       
   837             ipProperties = NULL;
       
   838             }
       
   839         else if ( ipProperties->IsSafeToCast(MSenProperties::ESenLayeredXmlProperties) )
       
   840             {
       
   841             CSenLayeredXmlProperties* pLayeredProps = (CSenLayeredXmlProperties*)ipProperties;
       
   842             delete pLayeredProps;
       
   843             ipProperties = NULL;
       
   844 	        }
       
   845         }
       
   846     // else {  // TLS log as fatal  }
       
   847     ipNotOwnedContext = apNotOwnedContext;
       
   848     return KErrNone;
       
   849     }
       
   850     
       
   851 EXPORT_C MSenMessageContext* CSenSoapEnvelope2::Context()
       
   852     {
       
   853     return ipNotOwnedContext;
       
   854     }
       
   855 
       
   856 EXPORT_C TInt CSenSoapEnvelope2::SetProperties(MSenProperties* apOwnedProperties)
       
   857     {
       
   858     if( !apOwnedProperties ) 
       
   859         {
       
   860         return KErrArgument;
       
   861         }
       
   862     if( ipProperties )
       
   863         {
       
   864         // De-allocate existing, self-owned properties
       
   865         if ( ipProperties->IsSafeToCast(MSenProperties::ESenXmlProperties) )
       
   866             {
       
   867             CSenXmlProperties* pFlatProps = (CSenXmlProperties*)ipProperties;
       
   868             delete pFlatProps;
       
   869             ipProperties = NULL;
       
   870             }
       
   871         else if ( ipProperties->IsSafeToCast(MSenProperties::ESenLayeredXmlProperties) )
       
   872             {
       
   873             CSenLayeredXmlProperties* pLayeredProps = (CSenLayeredXmlProperties*)ipProperties;
       
   874             delete pLayeredProps;
       
   875             ipProperties = NULL;
       
   876             }
       
   877         // else { // Log as fatal }
       
   878         }
       
   879 
       
   880     if( ipNotOwnedContext )
       
   881         {
       
   882         // Store properties into context
       
   883         ipNotOwnedContext->SetProperties( apOwnedProperties, ETrue );
       
   884         }
       
   885     else
       
   886         {
       
   887         // Own the properties directly inside this message
       
   888         ipProperties = apOwnedProperties;
       
   889         }
       
   890     return KErrNone;
       
   891     }
       
   892     
       
   893 EXPORT_C MSenProperties* CSenSoapEnvelope2::Properties()
       
   894     {
       
   895     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::Properties()");
       
   896     if( ipNotOwnedContext )
       
   897         {
       
   898         return ipNotOwnedContext->Properties();
       
   899         }
       
   900     else if ( ipProperties )
       
   901         {
       
   902         return ipProperties;
       
   903         }
       
   904     else
       
   905         {
       
   906         return NULL;
       
   907         }        
       
   908     }
       
   909 
       
   910 
       
   911 EXPORT_C TBool CSenSoapEnvelope2::IsSafeToCast(MSenMessage::TClass aType)
       
   912     {
       
   913     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::IsSafeToCast(aType)");
       
   914     if ( aType == MSenMessage::ESoapEnvelope2 )
       
   915         {
       
   916         return ETrue;
       
   917         }
       
   918 
       
   919     return EFalse;
       
   920     }
       
   921 
       
   922 EXPORT_C TInt CSenSoapEnvelope2::TxnId()
       
   923     {
       
   924     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::TxnId()");
       
   925     return iTransactionId;
       
   926     }
       
   927     
       
   928 EXPORT_C CSenFragmentBase* CSenSoapEnvelope2::CreateBodyFragmentL(const TDesC8& aNsUri,
       
   929                                                                   const TDesC8& aLocalName,
       
   930                                                                   const TDesC8& aPrefix,
       
   931                                                                   const RAttributeArray& aAttributes,
       
   932                                                                   TXmlEngElement& aParent,
       
   933                                                                   RSenDocument& aOwnerDocument)
       
   934     {
       
   935     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::CreateBodyFragmentL");
       
   936 	return CSenDomFragmentBase::NewL(aNsUri, aLocalName, aPrefix, aAttributes, aParent, aOwnerDocument);    
       
   937     }
       
   938     
       
   939 EXPORT_C MSenMessage* CSenSoapEnvelope2::CloneL()
       
   940     {
       
   941     TLSLOG_L(KSenMessagesLogChannel, KMinLogLevel, "CSenSoapEnvelope2::CloneL()");
       
   942     CSenSoapEnvelope2* pEnvelope = CSenSoapEnvelope2::NewL(*this);
       
   943     return pEnvelope;
       
   944     }
       
   945 
       
   946 // End of File