webservices/wsstar/wsstarmessagehandlers/src/wsstaraddressinghandler.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2006-2006 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 
       
    26 
       
    27 
       
    28 #include "wsstaraddressinghandler.h"
       
    29 #include "wsstarmessageutils.h"
       
    30 #include "SenXmlUtils.h"
       
    31 #include "sensaxutils.h"
       
    32 #include "senlogger.h" // private Utils\inc
       
    33 
       
    34 using namespace WSStarAddressing;
       
    35 using namespace WSStarAddressingFault;
       
    36 
       
    37 // Create instance of concrete ECOM interface implementation
       
    38 CWSStarAddressingHandler* CWSStarAddressingHandler::NewL(TAny* aHandlerCtx)
       
    39     {
       
    40     MSenHandlerContext* ctx =
       
    41         reinterpret_cast<MSenHandlerContext*>( aHandlerCtx);
       
    42     CWSStarAddressingHandler* self = new (ELeave) CWSStarAddressingHandler(*ctx);
       
    43     CleanupStack::PushL (self);
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47     }
       
    48 
       
    49 TInt CWSStarAddressingHandler::InvokeL(MSenMessageContext& aCtx)
       
    50     {
       
    51     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InvokeL(MSenMessageContext& aCtx)")));
       
    52     CSenSoapEnvelope* message = 
       
    53         const_cast<CSenSoapEnvelope*>(aCtx.GetSenSoapEnvelopeL(
       
    54                                     SenContext::KSenCurrentSoapMessageCtxKey)
       
    55                                     );
       
    56     TPtrC8 txtMessage = aCtx.GetMessageL();
       
    57     InitVersionL(aCtx.GetDesC8L(WSStarContextKeys::KAddressingVersion));
       
    58     if (message)
       
    59         {
       
    60         const CSenNamespace* nmSpace = message->Namespace(KAddressingPrefix);
       
    61         if (nmSpace)
       
    62             {
       
    63             InitVersionL(&nmSpace->URI());
       
    64             }
       
    65         if (aCtx.Direction() == SenContext::EOutgoing)
       
    66             {
       
    67             return HandleOutboundL(aCtx, message);
       
    68             }
       
    69         else if (aCtx.Direction()==SenContext::EIncoming)
       
    70             {
       
    71             return HandleInboundL(aCtx, message);
       
    72             }
       
    73         else
       
    74             {
       
    75             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InvokeL(MSenMessageContext& aCtx) - \
       
    76                                 strange direction")));
       
    77             return KErrNotFound;
       
    78             }
       
    79         }
       
    80     else if (txtMessage.Length())
       
    81         {
       
    82 //---------------idea based on method
       
    83 /*    
       
    84 TInt CSenWebServiceSession::HandleBodyWithoutParsingL(CSenSoapMessage& aMessage,
       
    85                                                       const TDesC8& aResponse)
       
    86 */
       
    87         TInt ret(KErrNone);
       
    88         TInt endTagStart;
       
    89         TInt endTagEnd;
       
    90         TInt startTagStart;
       
    91         TInt startTagEnd;
       
    92         TPtrC8 prefix;
       
    93 
       
    94         ret = SenSaxUtils::SearchEndTagL(txtMessage,KSenSoapEnvelopeBodyName,
       
    95                                          endTagStart, endTagEnd, prefix);
       
    96         if ( ret != KErrNotFound )
       
    97             {
       
    98             ret = SenSaxUtils::SearchStartTagL(txtMessage,prefix,KSenSoapEnvelopeBodyName,
       
    99                                                startTagStart, startTagEnd);
       
   100             if ( ret != KErrNotFound )
       
   101                 {
       
   102                 TPtrC8 startPart(txtMessage.Ptr(),startTagEnd+1);
       
   103                 TPtrC8 endPart(txtMessage.Ptr()+endTagStart,txtMessage.Size()-endTagStart);
       
   104                 HBufC8* pXmlWithoutBody = HBufC8::NewLC(startPart.Length()+endPart.Length());
       
   105                 pXmlWithoutBody->Des().Append(startPart);
       
   106                 pXmlWithoutBody->Des().Append(endPart);
       
   107         
       
   108                 CWSStarAddressingHeaderInbound* inbound =
       
   109                         CWSStarAddressingHeaderInbound::NewLC(iVersion);
       
   110                 inbound->SetMessageContext(aCtx);
       
   111                 CSenXmlReader& reader = const_cast<CSenXmlReader&>(*aCtx.GetParser());
       
   112                 inbound->SetReader(reader);
       
   113                 inbound->BuildFrom(*pXmlWithoutBody);
       
   114                 CleanupStack::PopAndDestroy(inbound);
       
   115                 
       
   116                 
       
   117                 CleanupStack::PopAndDestroy(pXmlWithoutBody);
       
   118                 
       
   119                 }
       
   120             }
       
   121         else//case with empty body - <S:Body/>, so we can parse all
       
   122             {
       
   123              CWSStarAddressingHeaderInbound* inbound =
       
   124                     CWSStarAddressingHeaderInbound::NewLC(iVersion);
       
   125             inbound->SetMessageContext(aCtx);
       
   126             CSenXmlReader& reader = const_cast<CSenXmlReader&>(*aCtx.GetParser());
       
   127             inbound->SetReader(reader);
       
   128             inbound->BuildFrom(txtMessage);
       
   129             CleanupStack::PopAndDestroy(inbound);
       
   130             }
       
   131         
       
   132         return ret;
       
   133         }
       
   134     else
       
   135         {
       
   136         TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InvokeL(MSenMessageContext& aCtx) - \
       
   137                             Soap message in message context not exists")));
       
   138         return KErrNotFound;
       
   139         }
       
   140     }    
       
   141 TInt CWSStarAddressingHandler::HandleInboundL(MSenMessageContext& aCtx, CSenSoapEnvelope* aMessage)
       
   142     {
       
   143 /*
       
   144     CWSStarAddressingHeaderInbound* inbound =  CWSStarAddressingHeaderInbound::NewLC(iVersion);
       
   145     inbound->SetMessageContext(aCtx);
       
   146     CSenXmlReader& reader = const_cast<CSenXmlReader&>(*aCtx.GetParser());
       
   147     inbound->SetReader(reader);
       
   148     HBufC8* buf = aMessage->AsXmlL();
       
   149     CleanupStack::PushL(buf);
       
   150     inbound->BuildFrom(*buf);
       
   151 */
       
   152     CSenElement& header = aMessage->HeaderL();
       
   153 
       
   154     CSenElement* elem = NULL;
       
   155     CSenElement* addressElem = NULL;    
       
   156 
       
   157     elem = CWSStarMessageUtils::FindElementL(KToName, header);
       
   158     if (elem)
       
   159         {
       
   160         const TDesC8& nsUri = elem->NamespaceURI();
       
   161         if (!iVersion && (nsUri == KAddressingXmlns200408 ||
       
   162             nsUri == KAddressingXmlns200403 ||
       
   163             nsUri == KAddressingXmlns200412 ||
       
   164             nsUri == KAddressingXmlns200502 ||
       
   165             nsUri == KAddressingXmlns200503 ||
       
   166             nsUri == KAddressingXmlns200508))
       
   167             {
       
   168             iVersion = nsUri.AllocL();
       
   169             }
       
   170         ((MSenContext&)aCtx).Update(WSStarContextKeys::KTo, elem->Content());
       
   171         }
       
   172     elem = CWSStarMessageUtils::FindElementL(KRelatesToName, header);
       
   173     if (elem)
       
   174         {
       
   175         ((MSenContext&)aCtx).Update(WSStarContextKeys::KRelatesTo, elem->Content());
       
   176         }
       
   177     elem = CWSStarMessageUtils::FindElementL(KMessageIDName, header);
       
   178     if (elem)
       
   179         {
       
   180         ((MSenContext&)aCtx).Update(WSStarContextKeys::KMessageID, elem->Content());
       
   181         }
       
   182     elem = CWSStarMessageUtils::FindElementL(KActionName, header);
       
   183     if (elem)
       
   184         {
       
   185         ((MSenContext&)aCtx).Update(WSStarContextKeys::KAction, elem->Content());
       
   186         }
       
   187     elem = CWSStarMessageUtils::FindElementL(WSStarAddressingEPR::KDeviceAddressName, header);
       
   188     if (elem)
       
   189         {
       
   190         ((MSenContext&)aCtx).Update(WSStarContextKeys::KReplyToDeviceAddress, elem->Content());
       
   191         }
       
   192     
       
   193     elem = CWSStarMessageUtils::FindElementL(KReplyToName, header);
       
   194     if (elem)
       
   195         {
       
   196         addressElem = CWSStarMessageUtils::FindElementL(KAddressName, *elem);
       
   197         if (addressElem)
       
   198             {
       
   199             ((MSenContext&)aCtx).Update(WSStarContextKeys::KReplyTo, addressElem->Content());
       
   200             }
       
   201         }
       
   202     elem = CWSStarMessageUtils::FindElementL(KFaultToName, header);
       
   203     if (elem)
       
   204         {
       
   205         addressElem = CWSStarMessageUtils::FindElementL(KAddressName, *elem);
       
   206         if (addressElem)
       
   207             {
       
   208             ((MSenContext&)aCtx).Update(WSStarContextKeys::KFaultTo, addressElem->Content());
       
   209             }
       
   210         }
       
   211     elem = CWSStarMessageUtils::FindElementL(KFromName, header);
       
   212     if (elem)
       
   213         {
       
   214         addressElem = CWSStarMessageUtils::FindElementL(KAddressName, *elem);
       
   215         if (addressElem)
       
   216             {
       
   217             ((MSenContext&)aCtx).Update(WSStarContextKeys::KFrom, addressElem->Content());
       
   218             }
       
   219         }
       
   220     _LIT8(Kpp, "pp");
       
   221     _LIT8(KCredProperties, "credProperties");
       
   222     _LIT8(KCredProperty, "credProperty");
       
   223     _LIT8(KName, "Name");
       
   224     CWSStarMessageUtils::RArraySenElements credPropertiesElements;
       
   225     CSenElement* ppElem = CWSStarMessageUtils::FindElementL(Kpp, header);
       
   226     if(ppElem)
       
   227         {
       
   228         CSenElement* credPropertiesElem = CWSStarMessageUtils::FindElementL(KCredProperties, *ppElem);//Naga
       
   229         if(credPropertiesElem)
       
   230             {
       
   231             CWSStarMessageUtils::FindElementL(KCredProperty, *credPropertiesElem, credPropertiesElements);
       
   232             TInt count = credPropertiesElements.Count();
       
   233             for(TInt i=0; i<count; i++)
       
   234                 {
       
   235                 elem = credPropertiesElements[i];
       
   236                 const TDesC8* ptr = elem->AttrValue(WSStarContextKeys::KName);
       
   237                 if ( *ptr == WSStarContextKeys::KMainBrandID )
       
   238                     {
       
   239                     ((MSenContext&)aCtx).Update(WSStarContextKeys::KMainBrandID, elem->Content());
       
   240                     }
       
   241                 if (*ptr == WSStarContextKeys::KBrandIDList)
       
   242                     {
       
   243                     ((MSenContext&)aCtx).Update(WSStarContextKeys::KBrandIDList, elem->Content());
       
   244                     }            
       
   245                 }
       
   246             }        
       
   247         }
       
   248 
       
   249 /*
       
   250     if (!iVersion && inbound->Version())
       
   251         {
       
   252         iVersion = inbound->Version()->AllocL();
       
   253         }
       
   254 */    
       
   255     if (!aCtx.GetDesC8L(WSStarContextKeys::KRelatesTo))
       
   256         {
       
   257         TLSLOG_FORMAT((KSenFaultsLogChannel, KSenFaultsLogLevel, 
       
   258                         WSStarAddressingFault::KInvalidHeaderFormatString8,
       
   259                         &KRelatesToQName(),&WSStarAddressingFault::KMissingTag()));   
       
   260         
       
   261         }
       
   262     if (!aCtx.GetDesC8L(WSStarContextKeys::KTo))
       
   263         {
       
   264         TLSLOG_FORMAT((KSenFaultsLogChannel, KSenFaultsLogLevel, KRequiredHeaderFormatString8,
       
   265                         &KToQName()));   
       
   266         
       
   267         }
       
   268     if (!aCtx.GetDesC8L(WSStarContextKeys::KAction))
       
   269         {
       
   270         TLSLOG_FORMAT((KSenFaultsLogChannel, KSenFaultsLogLevel, KRequiredHeaderFormatString8,
       
   271                         &KActionQName()));   
       
   272         
       
   273         }
       
   274     if (aCtx.GetDesC8L(WSStarContextKeys::KReplyTo) || aCtx.GetDesC8L(WSStarContextKeys::KFaultTo))
       
   275         {
       
   276         if (!aCtx.GetDesC8L(WSStarContextKeys::KMessageID))
       
   277             {
       
   278             TLSLOG_FORMAT((KSenFaultsLogChannel, KSenFaultsLogLevel, KRequiredHeaderFormatString8,
       
   279                             &KMessageIDQName()));   
       
   280             
       
   281             }
       
   282         }
       
   283 
       
   284     //    CleanupStack::PopAndDestroy(buf);
       
   285 //    CleanupStack::PopAndDestroy(inbound);
       
   286     CSenElement& body = aMessage->BodyL();
       
   287     ShareMyLiterals(aCtx);
       
   288     if (aMessage->IsFault())
       
   289         {
       
   290         TPtrC8 errorCode(KNullDesC8);
       
   291         CSenSoapFault* faultElement = aMessage->FaultL();
       
   292         if (faultElement)
       
   293             {
       
   294             TPtrC8 code;
       
   295             if (aMessage->NsUri() == KSenSoapEnvelopeXmlns)
       
   296                 {
       
   297                 TPtrC8 code = faultElement->FaultCode();                            
       
   298                 const CSenNamespace* nmSpace = faultElement->Namespace(SenXmlUtils::NsPrefix(code),
       
   299                                                                        ETrue);
       
   300                 code.Set(SenXmlUtils::LocalName(code));
       
   301                 if (nmSpace)
       
   302                     {
       
   303                     if (!iVersion)
       
   304                         {
       
   305                         InitVersionL(&nmSpace->URI());
       
   306                         }
       
   307                     if (iVersion && 
       
   308                         nmSpace->URI() == *iVersion)
       
   309                         {
       
   310                         errorCode.Set(code);
       
   311                         }    
       
   312                     }
       
   313                 }
       
   314             else if (aMessage->NsUri() == KSenSoap12EnvelopeXmlns)
       
   315                 {
       
   316                 code.Set(faultElement->FaultCode());
       
   317                 const CSenNamespace* nmSpaceCode = 
       
   318                         faultElement->Namespace(SenXmlUtils::NsPrefix(code), ETrue);
       
   319                 code.Set(SenXmlUtils::LocalName(code));
       
   320                 if ((nmSpaceCode && 
       
   321                     nmSpaceCode->URI() == KSenSoap12EnvelopeXmlns) &&
       
   322                     (code == KSender || code == KReceiver))
       
   323                     {
       
   324                     TPtrC8 subcode = faultElement->FaultSubcode();
       
   325                     const CSenNamespace* nmSpace = 
       
   326                         faultElement->Namespace(SenXmlUtils::NsPrefix(subcode), ETrue);
       
   327                     subcode.Set(SenXmlUtils::LocalName(subcode));
       
   328                 if (nmSpace)
       
   329                     {
       
   330                     if (!iVersion)
       
   331                         {
       
   332                         InitVersionL(&nmSpace->URI());
       
   333                         }
       
   334                     if (iVersion && 
       
   335                         nmSpace->URI() == *iVersion)
       
   336                         {
       
   337                         errorCode.Set(subcode);
       
   338                         }    
       
   339                     }
       
   340                     }
       
   341                 }
       
   342             if (errorCode.Length()>0)
       
   343                 {
       
   344                 if (errorCode == WSStarAddressingFault::KInvalidHeader ||
       
   345                     errorCode == WSStarAddressingFault::KRequiredHeader ||
       
   346                     errorCode == WSStarAddressingFault::KDestinationUnreachable ||
       
   347                     errorCode == WSStarAddressingFault::KActionNotSupported )
       
   348                     {
       
   349                     ((MSenContext&)aCtx).Update(WSStarSession::KErrorLayer,
       
   350                                                 WSStarSession::EAddressing);
       
   351                     }
       
   352                 if ((errorCode == WSStarAddressingFault::KEndpointUnavailable)
       
   353                     && (code == KReceiver))
       
   354                     {
       
   355                     ((MSenContext&)aCtx).Update(WSStarSession::KErrorLayer,
       
   356                                                 WSStarSession::EAddressing);
       
   357                     CSenElement* detailElement = faultElement->Element(KFault12DetailLocalname);
       
   358                     if (detailElement)
       
   359                         {
       
   360                         CSenElement* retryElement = detailElement->Element(*iVersion,
       
   361                                                                            KRetryAfterName); 
       
   362                         if (retryElement)
       
   363                             {
       
   364                             TPtrC8 retryAfter = retryElement->Content();
       
   365                             TLex8 num;
       
   366                             TInt retryInt;
       
   367                             num.Assign(retryAfter);
       
   368                             TInt ret = num.Val(retryInt);
       
   369                             if (ret == KErrNone)
       
   370                                 ((MSenContext&)aCtx).Update(WSStarContextKeys::KRetryAfter,
       
   371                                                             retryInt);
       
   372                             }
       
   373                         }
       
   374                     }
       
   375                 }
       
   376             }
       
   377         else
       
   378             {
       
   379             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InvokeL(MSenMessageContext& aCtx) - \
       
   380                             Fault element not exists")));
       
   381             return KErrNotFound;
       
   382             }
       
   383         }
       
   384     return KErrNone;
       
   385     }
       
   386 TInt CWSStarAddressingHandler::HandleOutboundL(MSenMessageContext& aCtx, 
       
   387                                                 CSenSoapEnvelope* aMessage)
       
   388     {
       
   389     if (!iVersion)
       
   390         {
       
   391         iVersion = KAddressingXmlns200508().AllocL();
       
   392         }
       
   393     TPtrC8 anonymous(KNullDesC8);
       
   394     if (!iVersion->Compare(KAddressingXmlns200403()))
       
   395         {
       
   396         anonymous.Set(KReplyToAnonymous200403());
       
   397         }
       
   398      else if(!iVersion->Compare(KAddressingXmlns200408()))
       
   399         {
       
   400         anonymous.Set(KReplyToAnonymous200408());
       
   401         }
       
   402      else if(!iVersion->Compare(KAddressingXmlns200412()))
       
   403         {
       
   404         anonymous.Set(KReplyToAnonymous200412());
       
   405         }
       
   406      else if(!iVersion->Compare(KAddressingXmlns200502()))
       
   407         {
       
   408         anonymous.Set(KReplyToAnonymous200502());
       
   409         }
       
   410      else if(!iVersion->Compare(KAddressingXmlns200503()))
       
   411         {
       
   412         anonymous.Set(KReplyToAnonymous200503());
       
   413         }
       
   414      else if(!iVersion->Compare(KAddressingXmlns200508()))
       
   415         {
       
   416         anonymous.Set(KReplyToAnonymous200508());
       
   417         }
       
   418     CSenElement& element = aMessage->AsElement();
       
   419     element.AddNamespaceL(KAddressingPrefix, *iVersion);
       
   420     ((MSenContext&)aCtx).Update(WSStarContextKeys::KAddressingNsHolder, *iVersion);
       
   421 ///////////////    
       
   422     const TDesC8* value = NULL;
       
   423     const TInt* isPassportEnabled = aCtx.GetIntL(WSStarContextKeys::KPassportEnabled);
       
   424     value = aCtx.GetDesC8L(WSStarContextKeys::KMessageID);
       
   425     if (!value)
       
   426         {
       
   427         SetMessageIDL(aCtx);
       
   428         }
       
   429         
       
   430     if (!isPassportEnabled || (isPassportEnabled && *isPassportEnabled == FALSE))
       
   431         {
       
   432         CSenElement& header = aMessage->HeaderL();
       
   433         value = aCtx.GetDesC8L(WSStarContextKeys::KMessageID);
       
   434         if (value)
       
   435             {
       
   436             CreateElementAddressingL(header, KMessageIDName, *value, EFalse);
       
   437             }
       
   438         else
       
   439             {
       
   440             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InvokeL(MSenMessageContext& aCtx) - \
       
   441                             MessageId in message context not exists")));
       
   442             return KErrNotFound;
       
   443             }
       
   444         value = aCtx.GetDesC8L(WSStarContextKeys::KTo);
       
   445         if (value)
       
   446             {
       
   447             CreateElementAddressingL(header, KToName, *value, EFalse);
       
   448             }
       
   449         else
       
   450             {
       
   451             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InvokeL(MSenMessageContext& aCtx) - \
       
   452                             Endpoint in message context not exists")));
       
   453             return KErrNotFound;
       
   454             }
       
   455         value = aCtx.GetDesC8L(WSStarContextKeys::KAction);
       
   456         if (value)
       
   457             {
       
   458             CreateElementAddressingL(header, KActionName, *value, EFalse);
       
   459             }
       
   460         else
       
   461             {
       
   462             TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InvokeL(MSenMessageContext& aCtx) - \
       
   463                             Action in message context not exists")));
       
   464             return KErrNotFound;
       
   465             }
       
   466         value = aCtx.GetDesC8L(WSStarContextKeys::KRelatesTo);
       
   467         if (value)
       
   468             {
       
   469             CreateElementAddressingL(header, KRelatesToName, *value, EFalse);
       
   470             }
       
   471         value = aCtx.GetDesC8L(WSStarContextKeys::KFrom);
       
   472         if (value)
       
   473             {
       
   474             CreateElementAddressingL(header, KFromName, *value, ETrue);
       
   475             }
       
   476         value = aCtx.GetDesC8L(WSStarContextKeys::KReplyTo);
       
   477         if (value)
       
   478             {
       
   479             CSenElement* element = CreateElementAddressingL(header, KReplyToName, *value, ETrue);
       
   480             const TDesC8* mwsNs = NULL;
       
   481             mwsNs = aCtx.GetDesC8L(WSStarContextKeys::KMwsNamespace);
       
   482             if (mwsNs)
       
   483                 {
       
   484                 const TDesC8* deviceId = NULL;
       
   485                 deviceId = aCtx.GetDesC8L(WSStarContextKeys::KReplyToDeviceAddress);
       
   486                 if (deviceId && element)
       
   487                     {
       
   488                     ((CWSStarAddressingEPR*)element)->AddDeviceAddressL(*mwsNs,*deviceId);
       
   489                     }
       
   490                 }
       
   491             }
       
   492         else
       
   493             {
       
   494             CSenElement* element = CreateElementAddressingL(header, KReplyToName, 
       
   495                                                             anonymous, ETrue);
       
   496             ((MSenContext&)aCtx).Update(WSStarContextKeys::KReplyTo, anonymous);
       
   497             const TDesC8* mwsNs = NULL;
       
   498             mwsNs = aCtx.GetDesC8L(WSStarContextKeys::KMwsNamespace);
       
   499             if (mwsNs)
       
   500                 {
       
   501                 const TDesC8* deviceId = NULL;
       
   502                 deviceId = aCtx.GetDesC8L(WSStarContextKeys::KReplyToDeviceAddress);
       
   503                 if (deviceId && element)
       
   504                     {
       
   505                     ((CWSStarAddressingEPR*)element)->AddDeviceAddressL(*mwsNs,*deviceId);
       
   506                     }
       
   507                 }
       
   508             }
       
   509             
       
   510         value = aCtx.GetDesC8L(WSStarContextKeys::KFaultTo);
       
   511         if (value)
       
   512             {
       
   513             CreateElementAddressingL(header, KFaultToName, *value, ETrue);
       
   514             }    
       
   515         if(aCtx.GetIntL(WSStarContextKeys::KAppInfoPresent))
       
   516             {
       
   517             AddAppInfoHeaderL(aCtx,header);
       
   518             }
       
   519         }
       
   520     
       
   521     CSenElement& body = aMessage->BodyL();
       
   522     CSenElement* addressHolderEl = NULL;
       
   523     do
       
   524         {
       
   525         addressHolderEl = 
       
   526             CWSStarMessageUtils::GetMarkedElementL(body,  WSStarContextKeys::KAddressAttrMark);
       
   527         if (addressHolderEl)
       
   528             {
       
   529             value = addressHolderEl->AttrValue(WSStarContextKeys::KAddressAttrMark);
       
   530             CreateElementAddressingL(*addressHolderEl, KEndpointReferenceName,
       
   531                                      *value, ETrue);
       
   532             //removing marker
       
   533             CSenBaseAttribute* marker = 
       
   534                 SenXmlUtils::RemoveAttributeL(*addressHolderEl, WSStarContextKeys::KAddressAttrMark);
       
   535             delete marker;
       
   536             marker = NULL;
       
   537             }
       
   538             
       
   539         }while(addressHolderEl);
       
   540     HBufC8* bodyString = body.AsXmlL();
       
   541     ((MSenContext&)aCtx).Update(WSStarContextKeys::KBody, *bodyString);
       
   542     ((MSenContext&)aCtx).Remove(WSStarContextKeys::KBodyElement);
       
   543     delete bodyString;
       
   544     bodyString = NULL;
       
   545     return KErrNone;    
       
   546     }
       
   547 void CWSStarAddressingHandler::AddAppInfoHeaderL(MSenMessageContext& aCtx, 
       
   548                                                 CSenElement& aHeader)
       
   549 {
       
   550     const TDesC8* value = NULL;
       
   551 
       
   552     const TDesC8* mwsNs = NULL;
       
   553     mwsNs = aCtx.GetDesC8L(WSStarContextKeys::KMwsNamespace);
       
   554     if (mwsNs)
       
   555         {
       
   556             //CreateElementAddressingL(header, WSStarContextKeys::KApplication, *value,EFalse);
       
   557             CSenElement& aaplication = aHeader.AddElementL(*mwsNs,
       
   558                                    WSStarContextKeys::KApplication,
       
   559                                    WSStarContextKeys::KNsPApplication);
       
   560 
       
   561             value = aCtx.GetDesC8L(WSStarContextKeys::KApplicationName);
       
   562             if(value)
       
   563             {
       
   564                 CSenElement& name = aaplication.AddElementL(*mwsNs,
       
   565                                             WSStarContextKeys::KName,
       
   566                                             WSStarContextKeys::KNsPName);                       
       
   567                  name.SetContentL(*value);
       
   568             }
       
   569 
       
   570             value = aCtx.GetDesC8L(WSStarContextKeys::KApplicationVendor);
       
   571             if(value)
       
   572             {
       
   573                 CSenElement& vendor = aaplication.AddElementL(*mwsNs,
       
   574                                         WSStarContextKeys::KVendor,
       
   575                                         WSStarContextKeys::KNsPVendor);                       
       
   576                  vendor.SetContentL(*value);
       
   577             }
       
   578             value = aCtx.GetDesC8L(WSStarContextKeys::KApplicationVersion);
       
   579             if(value)
       
   580             {
       
   581                 CSenElement& version = aaplication.AddElementL(*mwsNs,
       
   582                                        WSStarContextKeys::KVersion,
       
   583                                        WSStarContextKeys::KNsPVersion);                       
       
   584                  version.SetContentL(*value);
       
   585             }
       
   586             
       
   587             CSenElement& deviceoption = aHeader.AddElementL(*mwsNs,
       
   588                                    WSStarContextKeys::KDeviceOptions,
       
   589                                    WSStarContextKeys::KNsPDeviceOptions);
       
   590             
       
   591             value = aCtx.GetDesC8L(WSStarContextKeys::KLocale);
       
   592             if(value)
       
   593             {
       
   594                 CSenElement& local = deviceoption.AddElementL(*mwsNs,
       
   595                                        WSStarContextKeys::KLocale,
       
   596                                        WSStarContextKeys::KNsPLocale);                       
       
   597                  local.SetContentL(*value);
       
   598             }
       
   599             
       
   600             CSenElement& useragent = deviceoption.AddElementL(*mwsNs,
       
   601                                      WSStarContextKeys::KUserAgent,
       
   602                                      WSStarContextKeys::KNsPUserAgent);
       
   603             
       
   604             value = aCtx.GetDesC8L(WSStarContextKeys::KManufacturer);
       
   605             if(value)
       
   606             {
       
   607                 CSenElement& manufacturer = useragent.AddElementL(*mwsNs,
       
   608                                              WSStarContextKeys::KManufacturer,
       
   609                                              WSStarContextKeys::KNsPManufacturer);                       
       
   610                  manufacturer.SetContentL(*value);
       
   611             }
       
   612             value = aCtx.GetDesC8L(WSStarContextKeys::KModel);
       
   613             if(value)
       
   614             {
       
   615                 CSenElement& model = useragent.AddElementL(*mwsNs,
       
   616                                        WSStarContextKeys::KModel,
       
   617                                        WSStarContextKeys::KNsPModel);                       
       
   618                  model.SetContentL(*value);
       
   619             }
       
   620             
       
   621             CSenElement& os = useragent.AddElementL(*mwsNs,
       
   622                                      WSStarContextKeys::KOS,
       
   623                                      WSStarContextKeys::KNsPOS);
       
   624          
       
   625            value = aCtx.GetDesC8L(WSStarContextKeys::KDeviceName);
       
   626             if(value)
       
   627             {
       
   628                 CSenElement& name = os.AddElementL(*mwsNs,
       
   629                                     WSStarContextKeys::KName,
       
   630                                     WSStarContextKeys::KNsPName);                       
       
   631                  name.SetContentL(*value);
       
   632             }
       
   633            value = aCtx.GetDesC8L(WSStarContextKeys::KDeviceVersion);
       
   634             if(value)
       
   635             {
       
   636                 CSenElement& version = os.AddElementL(*mwsNs,
       
   637                                         WSStarContextKeys::KVersion,
       
   638                                         WSStarContextKeys::KNsPVersion);                       
       
   639                 version.SetContentL(*value);
       
   640             }
       
   641 
       
   642                                                  
       
   643             value = aCtx.GetDesC8L(WSStarContextKeys::KIMSI);
       
   644             if(value)
       
   645             {
       
   646                 CSenElement& imsi = useragent.AddElementL(*mwsNs,
       
   647                                         WSStarContextKeys::KIMSI,
       
   648                                         WSStarContextKeys::KNsPIMSI);                       
       
   649                  imsi.SetContentL(*value);
       
   650             }
       
   651         }    
       
   652     return;
       
   653     }
       
   654     
       
   655 SenHandler::THandlerDirection CWSStarAddressingHandler::Direction() const
       
   656     {
       
   657     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::Direction()")));
       
   658     return SenHandler::EBoth;
       
   659     }
       
   660 SenHandler::THandlerPhase CWSStarAddressingHandler::Phase()
       
   661     {
       
   662     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::Phase()")));
       
   663     return SenHandler::EMessage;
       
   664     }
       
   665 
       
   666 // Constructor
       
   667 CWSStarAddressingHandler::CWSStarAddressingHandler(MSenHandlerContext& aCtx)
       
   668 :CSenMessageHandler(aCtx)
       
   669     {
       
   670     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::\
       
   671                         CWSStarAddressingHandler(MSenHandlerContext& aCtx)")));
       
   672     }
       
   673 
       
   674 // Destructor
       
   675 CWSStarAddressingHandler::~CWSStarAddressingHandler()
       
   676     {
       
   677     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::~CWSStarAddressingHandler()")));
       
   678     delete iVersion;
       
   679     }
       
   680 
       
   681 // Second phase construction.
       
   682 void CWSStarAddressingHandler::ConstructL()
       
   683     {
       
   684     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::ConstructL()")));
       
   685     
       
   686     InitVersionL(NULL);
       
   687     }
       
   688 void CWSStarAddressingHandler::InitVersionL(const TDesC8* aVersion)
       
   689     {
       
   690     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InitVersion()")));
       
   691     const TDesC8* version = iHandlerContext.GetDesC8L(HandlerContextKey::KVersion);
       
   692     if (aVersion && 
       
   693         (*aVersion == KAddressingXmlns200408 || 
       
   694          *aVersion == KAddressingXmlns200403 ||
       
   695          *aVersion == KAddressingXmlns200412 ||
       
   696          *aVersion == KAddressingXmlns200502 ||
       
   697          *aVersion == KAddressingXmlns200503 ||
       
   698          *aVersion == KAddressingXmlns200508))
       
   699         {
       
   700         delete iVersion;
       
   701         iVersion = NULL;
       
   702         iVersion = aVersion->AllocL();
       
   703         }
       
   704     else if(version && 
       
   705         (*version == KAddressingXmlns200408 || 
       
   706          *version == KAddressingXmlns200403 ||
       
   707          *version == KAddressingXmlns200412 ||
       
   708          *version == KAddressingXmlns200502 ||
       
   709          *version == KAddressingXmlns200503 ||
       
   710          *version == KAddressingXmlns200508))
       
   711         {
       
   712         delete iVersion;
       
   713         iVersion = NULL;
       
   714         iVersion = version->AllocL();
       
   715         }
       
   716     else
       
   717         {//no version from handler config
       
   718         //no version from user
       
   719         //so it means some default behavior (new addressing), 
       
   720         //only allocate if differen (to safe time)
       
   721         if ((!iVersion) || (*iVersion != KAddressingXmlns200508()))
       
   722             {
       
   723             delete iVersion;
       
   724             iVersion = NULL;
       
   725             //iVersion = KAddressingXmlns200508().AllocL();
       
   726             }
       
   727         //else - just leave ai it is
       
   728         }
       
   729     }
       
   730 CSenElement* CWSStarAddressingHandler::CreateElementAddressingL(CSenElement& aParentElement, const TDesC8& aLocalName,
       
   731                                                         const TDesC8& aContent, TBool aUseAddress)
       
   732     {
       
   733     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::CreateElementAddressing(CSenElement& aParentElement,\
       
   734                      const TDesC8& aLocalName, const TDesC8& aContent, TBool aUseAddress)")));
       
   735 
       
   736     CSenElement* newelement = NULL;
       
   737     if (!aUseAddress)
       
   738         {
       
   739         newelement = aParentElement.CreateElementL(KAddressingPrefix(),
       
   740                                                                 aLocalName);
       
   741         CleanupStack::PushL(newelement);
       
   742         newelement->SetContentL(aContent);
       
   743         }
       
   744     else
       
   745         {
       
   746         newelement = CWSStarAddressingEPR::NewL(aParentElement, aLocalName, aContent, *iVersion);
       
   747         CleanupStack::PushL(newelement);
       
   748         }
       
   749     if (newelement)
       
   750         {
       
   751         aParentElement.AddElementL(*newelement);
       
   752         CleanupStack::Pop(newelement);
       
   753         }
       
   754 /*
       
   755     if (aUseAddress)
       
   756         {
       
   757         CSenElement& element = *newelement;
       
   758         CreateElementAddressingL(element,KAddressName,aContent,EFalse);
       
   759         }
       
   760     else
       
   761         {
       
   762         newelement->SetContentL(aContent);                
       
   763         }*/
       
   764     return newelement;    
       
   765     }
       
   766 
       
   767 void CWSStarAddressingHandler::SetMessageIDL(MSenMessageContext& aCtx)
       
   768     {
       
   769     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::SetMessageID(MSenMessageContext& aCtx)")));
       
   770     CSenGuidGen* pGuidGenerator = CSenGuidGen::NewLC();
       
   771     HBufC8* messageId = pGuidGenerator->GetRandomGuid8LC();
       
   772     TPtr8 messageIdDes = messageId->Des();
       
   773     messageIdDes.LowerCase();
       
   774     ((MSenContext&)aCtx).Update(WSStarContextKeys::KMessageID,*messageId);
       
   775     CleanupStack::PopAndDestroy(messageId);
       
   776     CleanupStack::PopAndDestroy(pGuidGenerator);
       
   777     }
       
   778 void CWSStarAddressingHandler::ShareMyLiterals(MSenMessageContext& aCtx)
       
   779     {
       
   780     if (iVersion)
       
   781         {
       
   782         ((MSenContext&)aCtx).Update(WSStarContextKeys::KAddressingNsHolder,
       
   783                 *iVersion);
       
   784         ((MSenContext&)aCtx).Update(WSStarContextKeys::KAddressingEndpointTagHolder, KAddressName);
       
   785         }
       
   786     }
       
   787 TInt CWSStarAddressingHandler::InitL(MSenHandlerContext& aCtx)
       
   788     {
       
   789     TLSLOG(KSenCoreServiceManagerLogChannelBase  , KMinLogLevel,(_L("CWSStarAddressingHandler::InitL(MSenHandlerContext& aCtx)")));
       
   790     iHandlerContext = aCtx;
       
   791     return KErrNone;
       
   792     }
       
   793 
       
   794 RFileLogger* CWSStarAddressingHandler::Log() const
       
   795     {
       
   796     RFileLogger* pLog = NULL;
       
   797     TRAP_IGNORE( pLog = (RFileLogger*)iHandlerContext.GetAnyL(HandlerContextKey::KLogger); )
       
   798     return pLog;
       
   799     }
       
   800     
       
   801 // END OF FILE
       
   802