webservices/wsoviplugin/src/wsovimessagecontext.cpp
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2008 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 "SenSoapEnvelope.h"
       
    26 #include "wsovimessagecontext.h"
       
    27 #include "wsovisessioncontext.h"
       
    28 #include "SenXmlReader.h"
       
    29 
       
    30 
       
    31 CWSOviMessageContext* CWSOviMessageContext::NewL(SenContext::TContextDirection aDirection)
       
    32     {
       
    33     CWSOviMessageContext* self = NewLC(aDirection);
       
    34     CleanupStack::Pop(self);
       
    35     return self;
       
    36     }
       
    37 
       
    38 CWSOviMessageContext* CWSOviMessageContext::NewLC(SenContext::TContextDirection aDirection)
       
    39     {
       
    40     CWSOviMessageContext* self = new (ELeave) CWSOviMessageContext(aDirection);
       
    41     CleanupStack::PushL (self);
       
    42     self->ConstructL();
       
    43     return self;
       
    44     }
       
    45 
       
    46 CWSOviMessageContext* CWSOviMessageContext::NewLC(
       
    47         SenContext::TContextDirection aDirection,
       
    48         CWSOviSessionContext& aSessionContext)
       
    49     {
       
    50     CWSOviMessageContext* self =
       
    51             new (ELeave) CWSOviMessageContext(aDirection);
       
    52     CleanupStack::PushL (self);
       
    53     self->ConstructL(aSessionContext);
       
    54     return self;
       
    55     }
       
    56 
       
    57 // Constructor
       
    58 CWSOviMessageContext::CWSOviMessageContext(SenContext::TContextDirection aDirection)
       
    59     :iDirection(aDirection),
       
    60     iDescs(EFalse, ETrue),
       
    61     iOAuthProperties(EFalse, ETrue),
       
    62     iInts(EFalse, ETrue)
       
    63     {
       
    64     }
       
    65 
       
    66 // Constructor
       
    67 void CWSOviMessageContext::ConstructL()
       
    68     {
       
    69     }
       
    70 
       
    71 void CWSOviMessageContext::ConstructL(CWSOviSessionContext& aSessionContext)
       
    72     {
       
    73     UpdateFromSessionContextL(aSessionContext);
       
    74     }
       
    75 
       
    76 // Destructor
       
    77 CWSOviMessageContext::~CWSOviMessageContext()
       
    78     {
       
    79     iDescs.Reset();
       
    80     iInts.Reset();
       
    81     iOAuthProperties.Reset();
       
    82     }
       
    83     
       
    84 //from SessionContext 
       
    85 
       
    86 CSenSoapMessage* CWSOviMessageContext::GetCurrentSoapMessage()
       
    87     {
       
    88     return NULL;
       
    89     };
       
    90 TPtrC8 CWSOviMessageContext::GetMessageL()
       
    91     {
       
    92     return KNullDesC8();
       
    93     };
       
    94 void CWSOviMessageContext::UpdateDesC8L(CWSOviSessionContext& aSessionContext, const TDesC8& aKey)
       
    95     {
       
    96     const TDesC8* ptr =
       
    97             aSessionContext.GetDesC8L(aKey);
       
    98     if (ptr && !GetDesC8L(aKey))
       
    99         {
       
   100         User::LeaveIfError(Update(aKey, *ptr));
       
   101         }
       
   102     }
       
   103 void CWSOviMessageContext::UpdateIntL(CWSOviSessionContext& aSessionContext, const TDesC8& aKey)
       
   104     {
       
   105     const TInt* ptr =
       
   106             aSessionContext.GetIntL(aKey);
       
   107     if (ptr &&!GetIntL(aKey))
       
   108         {
       
   109         User::LeaveIfError(Update(aKey, *ptr));    
       
   110         } 
       
   111     }
       
   112     
       
   113 void CWSOviMessageContext::UpdateFromSessionContextL(
       
   114         CWSOviSessionContext& aSessionContext)
       
   115     {
       
   116     //because of resending, we need keep message specific info within session ctx
       
   117     // (see ASYNC handleerror)
       
   118     if (Direction() == SenContext::EOutgoing)
       
   119         {
       
   120         UpdateDesC8L(aSessionContext, WSOviContextKeys::KToken);
       
   121         UpdateDesC8L(aSessionContext, WSOviContextKeys::KTokenSecret);
       
   122         UpdateIntL(aSessionContext, WSOviContextKeys::KRetryNeeded);
       
   123         }
       
   124     }
       
   125 
       
   126 TInt CWSOviMessageContext::Add(const TDesC8& /*aKey*/, CSenSoapEnvelope* /*aValue*/)
       
   127     {
       
   128     return KErrNotSupported;
       
   129     };
       
   130 TInt CWSOviMessageContext::Update(const TDesC8& /*aKey*/, CSenSoapEnvelope* /*aValue*/)
       
   131     {
       
   132     return KErrNotSupported;
       
   133     };
       
   134 const CSenSoapEnvelope* CWSOviMessageContext::GetSenSoapEnvelopeL(const TDesC8& /*aKey*/)
       
   135     {
       
   136     return NULL;
       
   137     };
       
   138 
       
   139 
       
   140 
       
   141 //from MContext       
       
   142 SenContext::TContextType CWSOviMessageContext::Type() const
       
   143     {
       
   144     return SenContext::EMessageContext;
       
   145     }
       
   146     
       
   147 SenContext::TContextDirection CWSOviMessageContext::Direction() const
       
   148     {
       
   149     return iDirection;
       
   150     }
       
   151 const CSenXmlReader* CWSOviMessageContext::GetParser()
       
   152     {
       
   153     return NULL;
       
   154     }
       
   155 
       
   156 //-----------------descs        
       
   157 TInt CWSOviMessageContext::Add(const TDesC8& aKey, const TDesC8& aValue)
       
   158     {
       
   159     if (!aValue.Length()) return KErrUnderflow;
       
   160     HBufC8* newValue = NULL;
       
   161     TInt error(KErrNone);
       
   162     TRAP(error, newValue = aValue.AllocL());
       
   163     if (!error)
       
   164         {
       
   165         error = iDescs.Append(&aKey,newValue);
       
   166         }            
       
   167     return error;
       
   168     }
       
   169 
       
   170 //it add(if not exist) or update. So , it is like Set
       
   171 TInt CWSOviMessageContext::Update(const TDesC8& aKey, const TDesC8& aValue)
       
   172     {
       
   173     TInt error(KErrNone);
       
   174     if (!aValue.Length()) 
       
   175         {
       
   176         error = Remove(aKey);
       
   177         if (error == KErrNotFound)
       
   178                 return KErrNone;
       
   179             else
       
   180                 return error;
       
   181         }
       
   182     HBufC8* newValue = NULL;
       
   183     TRAP(error, newValue = aValue.AllocL());
       
   184     
       
   185     if (!error)
       
   186         {
       
   187         error = iDescs.UpdateValue(&aKey,newValue);
       
   188         }
       
   189     return error;
       
   190     }
       
   191 
       
   192 const TDesC8* CWSOviMessageContext::GetDesC8L(const TDesC8& aKey)
       
   193     {
       
   194     TInt index = iDescs.Find(aKey);
       
   195     if (index != KErrNotFound)
       
   196         {
       
   197         return iDescs.ValueAt(index);
       
   198         }
       
   199     else
       
   200         {
       
   201         return NULL;
       
   202         }
       
   203     }
       
   204 
       
   205 TInt CWSOviMessageContext::Remove(const TDesC8& aKey)
       
   206     {
       
   207     return iDescs.RemoveByKey(aKey);
       
   208     }
       
   209 //-------------Ints
       
   210 TInt CWSOviMessageContext::Add(const TDesC8& aKey, TInt aValue)
       
   211     {
       
   212     TInt* a = NULL;
       
   213     a = new TInt(aValue);
       
   214     if (a)
       
   215         {
       
   216         return iInts.Append(&aKey, a);
       
   217         }
       
   218     else
       
   219         {
       
   220         return KErrNoMemory;
       
   221         }
       
   222     }
       
   223 
       
   224 TInt CWSOviMessageContext::Update(const TDesC8& aKey, TInt aValue)
       
   225     {
       
   226     TInt* a = NULL;
       
   227     a = new TInt(aValue);
       
   228     if (a)
       
   229         {
       
   230         return iInts.UpdateValue(&aKey, a);
       
   231         }
       
   232     else
       
   233         {
       
   234         return KErrNoMemory;
       
   235         }
       
   236     }
       
   237 
       
   238 const TInt* CWSOviMessageContext::GetIntL(const TDesC8& aKey)
       
   239     {
       
   240     TInt index = iInts.Find(aKey);
       
   241     if (index!=KErrNotFound)
       
   242         {
       
   243         return iInts.ValueAt(index);
       
   244         }
       
   245     else
       
   246         {
       
   247         return NULL;
       
   248         };        
       
   249     }
       
   250 
       
   251 //-----------------elements
       
   252 TInt CWSOviMessageContext::Add(const TDesC8& aKey, CSenElement* aValue)
       
   253     {
       
   254     return Update(aKey,aValue);
       
   255     }
       
   256 
       
   257 TInt CWSOviMessageContext::Update(const TDesC8& /*aKey*/, CSenElement* /*aValue*/)
       
   258     {
       
   259     return KErrNotSupported;
       
   260     }
       
   261 
       
   262 const CSenElement* CWSOviMessageContext::GetSenElementL(const TDesC8& /*aKey*/)
       
   263     {
       
   264     return NULL;
       
   265     }
       
   266 //-----------------TAnys
       
   267 TInt CWSOviMessageContext::Add(const TDesC8& /*aKey*/, TAny* /*aValue*/)
       
   268     {
       
   269     return KErrNotSupported;
       
   270     }
       
   271 
       
   272 TInt CWSOviMessageContext::Update(const TDesC8& /*aKey*/, TAny* /*aValue*/)
       
   273     {
       
   274     return KErrNotSupported;
       
   275     }
       
   276 
       
   277 TAny* CWSOviMessageContext::GetAnyL(const TDesC8& /*aKey*/)	//codescannerwarnings
       
   278     {
       
   279     return NULL;
       
   280     }
       
   281 
       
   282 TInt CWSOviMessageContext::Count() const
       
   283     {
       
   284     return KErrNotSupported;
       
   285     }
       
   286 
       
   287 TPtrC8 CWSOviMessageContext::KeyAtL(TInt /*aIndex*/)
       
   288     {
       
   289     return KNullDesC8();
       
   290     }
       
   291         
       
   292 void CWSOviMessageContext::Reset() 
       
   293     {
       
   294     }
       
   295     
       
   296 MSenMessage* CWSOviMessageContext::MessageL()	//codescannerwarnigs
       
   297     {
       
   298     return NULL;
       
   299     }
       
   300     
       
   301 TInt CWSOviMessageContext::SetMessage(MSenMessage* /* apMessage */, TBool /* aOwned */)
       
   302     {
       
   303     return KErrNotSupported;
       
   304     }
       
   305     
       
   306 TInt CWSOviMessageContext::SetProperties(MSenProperties* /* apTransportProperties */, TBool /* aOwned */)
       
   307     {
       
   308     return KErrNotSupported;
       
   309     }
       
   310     
       
   311 MSenProperties* CWSOviMessageContext::Properties()
       
   312     {
       
   313     return NULL;    
       
   314     }
       
   315     
       
   316 TInt CWSOviMessageContext::Add(const TDesC8& /* aKey */, MSenMessage* /* apMessage */, TBool /* aOwned */)
       
   317     {
       
   318     return KErrNotSupported;
       
   319     }
       
   320     
       
   321 TInt CWSOviMessageContext::Update(const TDesC8& /* aKey */, MSenMessage* /* apMessage */, TBool /* aOwned */)
       
   322     {
       
   323     return KErrNotSupported;
       
   324     }
       
   325 TInt CWSOviMessageContext::UpdateTP(CSenTransportProperties*& aTP)
       
   326     {
       
   327     iTP = aTP;
       
   328     return KErrNone;
       
   329     }
       
   330 RMapDescriptors& CWSOviMessageContext::OAuthProperies()
       
   331     {
       
   332     return iOAuthProperties;
       
   333     }
       
   334 CSenTransportProperties* CWSOviMessageContext::TP()
       
   335     {
       
   336     return iTP;
       
   337     }   
       
   338 MSenMessage* CWSOviMessageContext::GetMessageL(const TDesC8& /* aKey */)	// codescannerwarnings
       
   339     {
       
   340     return NULL;
       
   341     }
       
   342     
       
   343     
       
   344 CSenChunk* CWSOviMessageContext::ChunkL()	//codescannerwarnings
       
   345     {
       
   346     return NULL;
       
   347     }
       
   348     
       
   349 TInt CWSOviMessageContext::SetChunk(CSenChunk* /* apMsgAsChunk */, TBool /* aOwned */)
       
   350     {
       
   351     return KErrNotSupported;
       
   352     }
       
   353     
       
   354 TInt CWSOviMessageContext::SetDirection( SenContext::TContextDirection /* aDirection */ ) 
       
   355     {
       
   356     return KErrNotSupported; 
       
   357     }
       
   358     
       
   359    
       
   360 // END OF FILE
       
   361