webservices/wsstar/wsstarplugin/src/wsstarmessagecontext.cpp
changeset 0 62f9d29f7211
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 "SenSoapEnvelope.h"
       
    29 #include "wsstarmessagecontext.h"
       
    30 #include "wsstarsessioncontext.h"
       
    31 #include "SenXmlReader.h"
       
    32 
       
    33 #include "senlogger.h"
       
    34 
       
    35 
       
    36 CWSStarMessageContext* CWSStarMessageContext::NewL(SenContext::TContextDirection aDirection, CSenXmlReader*& aParser)
       
    37     {
       
    38     CWSStarMessageContext* self = NewLC(aDirection, aParser);
       
    39     CleanupStack::Pop(self);
       
    40     return self;
       
    41     }
       
    42 
       
    43 CWSStarMessageContext* CWSStarMessageContext::NewLC(SenContext::TContextDirection aDirection, CSenXmlReader*& aParser)
       
    44     {
       
    45     CWSStarMessageContext* self = new (ELeave) CWSStarMessageContext(aDirection, aParser);
       
    46     CleanupStack::PushL (self);
       
    47     self->ConstructL();
       
    48     return self;
       
    49     }
       
    50 
       
    51 CWSStarMessageContext* CWSStarMessageContext::NewLC(
       
    52         SenContext::TContextDirection aDirection, CSenXmlReader*& aParser,
       
    53         CWSStarSessionContext& aSessionContext)
       
    54     {
       
    55     CWSStarMessageContext* self =
       
    56             new (ELeave) CWSStarMessageContext(aDirection, aParser);
       
    57     CleanupStack::PushL (self);
       
    58     self->ConstructL(aSessionContext);
       
    59     return self;
       
    60     }
       
    61 
       
    62 // Constructor
       
    63 CWSStarMessageContext::CWSStarMessageContext(SenContext::TContextDirection aDirection, CSenXmlReader*& aParser)
       
    64     :iDirection(aDirection),
       
    65     iOwnedEnvelope(EFalse),
       
    66     iParser(aParser),
       
    67     iDescs(EFalse, ETrue),
       
    68     iInts(EFalse, ETrue)
       
    69     {
       
    70     }
       
    71 
       
    72 // Constructor
       
    73 void CWSStarMessageContext::ConstructL()
       
    74     {
       
    75     }
       
    76 
       
    77 void CWSStarMessageContext::ConstructL(CWSStarSessionContext& aSessionContext)
       
    78     {
       
    79     UpdateFromSessionContextL(aSessionContext);
       
    80     }
       
    81 
       
    82 // Destructor
       
    83 CWSStarMessageContext::~CWSStarMessageContext()
       
    84     {
       
    85     if (iOwnedEnvelope)
       
    86         {
       
    87         delete iCurrentEnvelope;
       
    88         }
       
    89     iDescs.Reset();
       
    90     iInts.Reset();
       
    91     }
       
    92     
       
    93 //from SessionContext 
       
    94 
       
    95 CSenSoapMessage* CWSStarMessageContext::GetCurrentSoapMessage()
       
    96     {
       
    97     if (iCurrentEnvelope)
       
    98         {
       
    99         return (CSenSoapMessage*)iCurrentEnvelope;
       
   100         }
       
   101     else
       
   102         {
       
   103         return NULL;
       
   104         }
       
   105 };
       
   106 TPtrC8 CWSStarMessageContext::GetMessageL()
       
   107     {
       
   108     return iCurrentEnvelopeTxt;
       
   109     };
       
   110 void CWSStarMessageContext::UpdateDesC8L(CWSStarSessionContext& aSessionContext, const TDesC8& aKey)
       
   111     {
       
   112     const TDesC8* ptr =
       
   113             aSessionContext.GetDesC8L(aKey);
       
   114     if (ptr && !GetDesC8L(aKey))
       
   115         {
       
   116         User::LeaveIfError(Update(aKey, *ptr));
       
   117         }
       
   118     }
       
   119 void CWSStarMessageContext::UpdateIntL(CWSStarSessionContext& aSessionContext, const TDesC8& aKey)
       
   120     {
       
   121     const TInt* ptr =
       
   122             aSessionContext.GetIntL(aKey);
       
   123     if (ptr &&!GetIntL(aKey))
       
   124         {
       
   125         User::LeaveIfError(Update(aKey, *ptr));    
       
   126         } 
       
   127     }
       
   128     
       
   129 void CWSStarMessageContext::UpdateFromSessionContextL( CWSStarSessionContext& aSessionContext )
       
   130     {
       
   131     //becouse of resending we need keep veen message specific stuff inside session ctx
       
   132     // (see ASYNC handkleerror)
       
   133     if (Direction() == SenContext::EOutgoing)
       
   134         {
       
   135         const TDesC8* ptr =
       
   136         aSessionContext.GetDesC8L( WSStarContextKeys::KTo );
       
   137         if ( ptr )
       
   138             {
       
   139             TInt error = Remove( WSStarContextKeys::KTo );
       
   140             if( error )
       
   141                 {
       
   142                 TLSLOG_L( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, "CWSStarMessageContext::UpdateFromSessionContextL( CWSStarSessionContext& aSessionContext ):" );
       
   143                 TLSLOG_FORMAT(( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, _L8("- Remove( WSStarContextKeys::KTo ) returned an error(!): %d => going to 'throw a LEAVE'"), error ));
       
   144                 User::LeaveIfError( error );
       
   145                 }
       
   146             }        
       
   147         UpdateDesC8L(aSessionContext, WSStarContextKeys::KTo);
       
   148         UpdateDesC8L(aSessionContext, WSStarContextKeys::KAction);
       
   149         UpdateDesC8L(aSessionContext, WSStarContextKeys::KAddressingVersion);
       
   150         UpdateDesC8L(aSessionContext, WSStarContextKeys::KTimestampExpires);
       
   151         UpdateDesC8L(aSessionContext, WSStarContextKeys::KTimestampCreated);
       
   152         UpdateDesC8L(aSessionContext, WSStarContextKeys::KPhoneTimeWhenMTResolved);
       
   153         UpdateDesC8L(aSessionContext, WSStarContextKeys::KPOPBase64);
       
   154         UpdateDesC8L(aSessionContext, WSStarContextKeys::KBinaryType);
       
   155         UpdateIntL(aSessionContext, WSStarContextKeys::KSoapVersion);
       
   156         UpdateIntL(aSessionContext, WSStarContextKeys::KPassportEnabled);
       
   157         UpdateIntL(aSessionContext, WSStarContextKeys::KMTIsReplacedBySCT);
       
   158         UpdateDesC8L(aSessionContext, WSStarContextKeys::KSecurityToken);
       
   159         UpdateDesC8L(aSessionContext, WSStarContextKeys::KBody);
       
   160         iBody = aSessionContext.GetSenElementL(WSStarContextKeys::KBodyElement);
       
   161         UpdateDesC8L(aSessionContext, WSStarContextKeys::KSTR);
       
   162         ipSignedParts = (RPointerArray<HBufC8>*)aSessionContext.GetAnyL( WSStarContextKeys::KSignedPartsArray );
       
   163               
       
   164 #ifdef _SENDEBUG                
       
   165         if( !ipSignedParts ) // ipSignedParts == NULL!
       
   166             {
       
   167             TLSLOG_L( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, "CWSStarMessageContext::UpdateFromSessionContextL( CWSStarSessionContext& aSessionContext ):" );
       
   168             TLSLOG_L( KSenCoreServiceManagerLogChannelBase, KMinLogLevel, "- aSessionContext.GetAnyL( WSStarContextKeys::KSignedPartsArray ) returned NULL(!)" );
       
   169             }
       
   170 #endif // _SENDEBUG            
       
   171         
       
   172         UpdateIntL(aSessionContext, WSStarContextKeys::KAppInfoPresent);
       
   173         UpdateDesC8L(aSessionContext, WSStarContextKeys::KApplicationName);
       
   174         UpdateDesC8L(aSessionContext, WSStarContextKeys::KApplicationVendor);
       
   175         UpdateDesC8L(aSessionContext, WSStarContextKeys::KApplicationVersion);
       
   176         UpdateDesC8L(aSessionContext, WSStarContextKeys::KLocale);
       
   177         UpdateDesC8L(aSessionContext, WSStarContextKeys::KManufacturer);
       
   178         UpdateDesC8L(aSessionContext, WSStarContextKeys::KModel);
       
   179         UpdateDesC8L(aSessionContext, WSStarContextKeys::KDeviceName);
       
   180         UpdateDesC8L(aSessionContext, WSStarContextKeys::KDeviceVersion);
       
   181         UpdateDesC8L(aSessionContext, WSStarContextKeys::KIMSI);
       
   182         }
       
   183     else
       
   184         {
       
   185         UpdateIntL(aSessionContext, WSStarContextKeys::KPassportEnabled);
       
   186         }
       
   187     }
       
   188 
       
   189 TInt CWSStarMessageContext::Add(const TDesC8& aKey, CSenSoapEnvelope* aValue)
       
   190     {
       
   191     TInt results = KErrNone;
       
   192     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey())
       
   193         {
       
   194         if (!iCurrentEnvelope)
       
   195             {
       
   196             iCurrentEnvelope = aValue;
       
   197             }
       
   198         else
       
   199             {
       
   200             results = KErrAlreadyExists;
       
   201             }
       
   202         
       
   203         }
       
   204     return results;
       
   205     };
       
   206 TInt CWSStarMessageContext::Update(const TDesC8& aKey, CSenSoapEnvelope* aValue)
       
   207     {
       
   208     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey())
       
   209         {
       
   210         if (iOwnedEnvelope)
       
   211             {
       
   212             delete iCurrentEnvelope;
       
   213             }
       
   214         iCurrentEnvelope = aValue;
       
   215         }
       
   216     return KErrNone;
       
   217     };
       
   218 const CSenSoapEnvelope* CWSStarMessageContext::GetSenSoapEnvelopeL(const TDesC8& aKey)
       
   219     {
       
   220     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey)
       
   221         {
       
   222         return iCurrentEnvelope;
       
   223         }
       
   224     else
       
   225         {
       
   226         return NULL;
       
   227         }
       
   228     };
       
   229 
       
   230 
       
   231 
       
   232 //from MContext       
       
   233 SenContext::TContextType CWSStarMessageContext::Type() const
       
   234     {
       
   235     return SenContext::EMessageContext;
       
   236     }
       
   237     
       
   238 SenContext::TContextDirection CWSStarMessageContext::Direction() const
       
   239     {
       
   240     return iDirection;
       
   241     }
       
   242 //-----------------descs        
       
   243 TInt CWSStarMessageContext::Add(const TDesC8& aKey, const TDesC8& aValue)
       
   244     {
       
   245     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey())
       
   246         {
       
   247         if (! iCurrentEnvelopeTxt.Length())
       
   248             {
       
   249             iCurrentEnvelopeTxt.Set(aValue);
       
   250             return KErrNone;
       
   251             }
       
   252         else
       
   253             {
       
   254             return KErrAlreadyExists;
       
   255             }
       
   256         }
       
   257         //version without copy
       
   258         //return iDescs.Append(&aKey,&aValue);
       
   259         
       
   260         //version with making of copy
       
   261         if (!aValue.Length()) return KErrUnderflow;
       
   262         HBufC8* newValue = NULL;
       
   263         TInt error(KErrNone);
       
   264         TRAP(error, newValue = aValue.AllocL());
       
   265         if (!error)
       
   266             {
       
   267             error = iDescs.Append(&aKey,newValue);
       
   268             }            
       
   269         return error;
       
   270     }
       
   271 
       
   272 //it add(if not exist) or update. So , it is like Set
       
   273 TInt CWSStarMessageContext::Update(const TDesC8& aKey, const TDesC8& aValue)
       
   274     {
       
   275     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey())
       
   276         {
       
   277         iCurrentEnvelopeTxt.Set(aValue);
       
   278         return KErrNone;
       
   279         }
       
   280     
       
   281     //version with makeing of copy
       
   282     TInt error(KErrNone);
       
   283     if (!aValue.Length()) 
       
   284         {
       
   285         error = Remove(aKey);
       
   286         if (error == KErrNotFound)
       
   287                 return KErrNone;
       
   288             else
       
   289                 return error;
       
   290         }
       
   291     HBufC8* newValue = NULL;
       
   292     TRAP(error, newValue = aValue.AllocL());
       
   293     
       
   294     if (!error)
       
   295         {
       
   296         error = iDescs.UpdateValue(&aKey,newValue);
       
   297         }
       
   298     return error;
       
   299     }
       
   300 
       
   301 const TDesC8* CWSStarMessageContext::GetDesC8L(const TDesC8& aKey)
       
   302     {
       
   303     if (aKey == SenContext::KSenCurrentSoapMessageCtxKey())
       
   304         {
       
   305         return NULL;
       
   306         }
       
   307     TInt index = iDescs.Find(aKey);
       
   308     if (index != KErrNotFound)
       
   309         {
       
   310         return iDescs.ValueAt(index);
       
   311         }
       
   312     else
       
   313         {
       
   314         return NULL;
       
   315         }
       
   316     }
       
   317 
       
   318 TInt CWSStarMessageContext::Remove(const TDesC8& aKey)
       
   319     {
       
   320     if (aKey == WSStarContextKeys::KBodyElement)
       
   321         {
       
   322         iBody = NULL;
       
   323         return KErrNone;
       
   324         }
       
   325     else
       
   326         {
       
   327         return iDescs.RemoveByKey(aKey);
       
   328         }
       
   329     }
       
   330 //-------------Ints
       
   331 TInt CWSStarMessageContext::Add(const TDesC8& aKey, TInt aValue)
       
   332     {
       
   333     TInt* a = NULL;
       
   334     a = new TInt(aValue);
       
   335     if (a)
       
   336         {
       
   337         return iInts.Append(&aKey, a);
       
   338         }
       
   339     else
       
   340         {
       
   341         return KErrNoMemory;
       
   342         }
       
   343     }
       
   344 
       
   345 TInt CWSStarMessageContext::Update(const TDesC8& aKey, TInt aValue)
       
   346     {
       
   347     TInt* a = NULL;
       
   348     a = new TInt(aValue);
       
   349     if (a)
       
   350         {
       
   351         return iInts.UpdateValue(&aKey, a);
       
   352         }
       
   353     else
       
   354         {
       
   355         return KErrNoMemory;
       
   356         }
       
   357     }
       
   358 
       
   359 const TInt* CWSStarMessageContext::GetIntL(const TDesC8& aKey)
       
   360     {
       
   361     TInt index = iInts.Find(aKey);
       
   362     if (index!=KErrNotFound)
       
   363         {
       
   364         return iInts.ValueAt(index);
       
   365         }
       
   366     else
       
   367         {
       
   368         return NULL;
       
   369         };        
       
   370     }
       
   371 
       
   372 //-----------------elements
       
   373 TInt CWSStarMessageContext::Add(const TDesC8& aKey, CSenElement* aValue)
       
   374     {
       
   375     return Update(aKey,aValue);
       
   376     }
       
   377 
       
   378 TInt CWSStarMessageContext::Update(const TDesC8& aKey, CSenElement* aValue)
       
   379     {
       
   380     if (aKey == WSStarContextKeys::KBodyElement)
       
   381         {
       
   382         iBody = aValue;
       
   383         return KErrNone;
       
   384         }
       
   385     return KErrNotFound;
       
   386     }
       
   387 
       
   388 const CSenElement* CWSStarMessageContext::GetSenElementL(const TDesC8& aKey)
       
   389     {
       
   390     if (aKey == WSStarContextKeys::KBodyElement)
       
   391         {
       
   392         return iBody;
       
   393         }
       
   394     return NULL;
       
   395     }
       
   396 //-----------------TAnys
       
   397 TInt CWSStarMessageContext::Add(const TDesC8& /*aKey*/, TAny* /*aValue*/)
       
   398     {
       
   399     return KErrNotSupported;
       
   400     }
       
   401 
       
   402 TInt CWSStarMessageContext::Update(const TDesC8& /*aKey*/, TAny* /*aValue*/)
       
   403     {
       
   404     return KErrNotSupported;
       
   405     }
       
   406 
       
   407 TAny* CWSStarMessageContext::GetAnyL(const TDesC8& aKey)	//codescannerwarnings
       
   408     {
       
   409     if(aKey == WSStarContextKeys::KSignedPartsArray)
       
   410         {
       
   411         return ipSignedParts;
       
   412         }
       
   413      else
       
   414         {
       
   415         return NULL;
       
   416         }
       
   417     }
       
   418 
       
   419 const CSenXmlReader* CWSStarMessageContext::GetParser()
       
   420     {
       
   421     return iParser;
       
   422     }
       
   423 
       
   424 TInt CWSStarMessageContext::Count() const
       
   425     {
       
   426     return KErrNotSupported;
       
   427     }
       
   428 
       
   429 TPtrC8 CWSStarMessageContext::KeyAtL(TInt /*aIndex*/)
       
   430     {
       
   431     return KNullDesC8();
       
   432     }
       
   433         
       
   434 void CWSStarMessageContext::Reset() 
       
   435     {
       
   436     }
       
   437     
       
   438 MSenMessage* CWSStarMessageContext::MessageL()	//codescannerwarnigs
       
   439     {
       
   440     return NULL;
       
   441     }
       
   442     
       
   443 TInt CWSStarMessageContext::SetMessage(MSenMessage* /* apMessage */, TBool /* aOwned */)
       
   444     {
       
   445     return KErrNotSupported;
       
   446     }
       
   447     
       
   448 TInt CWSStarMessageContext::SetProperties(MSenProperties* /* apTransportProperties */, TBool /* aOwned */)
       
   449     {
       
   450     return KErrNotSupported;
       
   451     }
       
   452     
       
   453 MSenProperties* CWSStarMessageContext::Properties()
       
   454     {
       
   455     return NULL;    
       
   456     }
       
   457     
       
   458 TInt CWSStarMessageContext::Add(const TDesC8& /* aKey */, MSenMessage* /* apMessage */, TBool /* aOwned */)
       
   459     {
       
   460     return KErrNotSupported;
       
   461     }
       
   462     
       
   463 TInt CWSStarMessageContext::Update(const TDesC8& /* aKey */, MSenMessage* /* apMessage */, TBool /* aOwned */)
       
   464     {
       
   465     return KErrNotSupported;
       
   466     }
       
   467     
       
   468 MSenMessage* CWSStarMessageContext::GetMessageL(const TDesC8& /* aKey */)	// codescannerwarnings
       
   469     {
       
   470     return NULL;
       
   471     }
       
   472     
       
   473     
       
   474 CSenChunk* CWSStarMessageContext::ChunkL()	//codescannerwarnings
       
   475     {
       
   476     return NULL;
       
   477     }
       
   478     
       
   479 TInt CWSStarMessageContext::SetChunk(CSenChunk* /* apMsgAsChunk */, TBool /* aOwned */)
       
   480     {
       
   481     return KErrNotSupported;
       
   482     }
       
   483     
       
   484 TInt CWSStarMessageContext::SetDirection( SenContext::TContextDirection /* aDirection */ ) 
       
   485     {
       
   486     return KErrNotSupported; 
       
   487     }
       
   488     
       
   489    
       
   490 // END OF FILE
       
   491