webservices/wsoviplugin/src/wsovisessioncontext.cpp
changeset 0 62f9d29f7211
child 22 56092bff76ba
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 "wsovisessioncontext.h"
       
    26 #include "senwsdescription.h"
       
    27 #include <SenServiceConnection.h>
       
    28 #include <SenCredential.h>
       
    29 #include <SenDateUtils.h>
       
    30 #include "senlogger.h"
       
    31 #include "wsoviservicesession.h"
       
    32 #include "msenremoteservicesession.h"  
       
    33 
       
    34 using namespace WSOviContextKeys;
       
    35 using namespace WSOviContextValues;
       
    36 
       
    37 CWSOviSessionContext* CWSOviSessionContext::NewL()
       
    38     {
       
    39     CWSOviSessionContext* self = NewLC();
       
    40     CleanupStack::Pop(self);
       
    41     return self;
       
    42     }
       
    43 CWSOviSessionContext* CWSOviSessionContext::NewLC()
       
    44     {
       
    45     CWSOviSessionContext* self = new (ELeave) CWSOviSessionContext();
       
    46     CleanupStack::PushL (self);
       
    47     self->ConstructL();
       
    48     return self;
       
    49     }
       
    50 
       
    51 // Constructor
       
    52 CWSOviSessionContext::CWSOviSessionContext():
       
    53     iDescriptions(EFalse,EFalse),
       
    54     iInts(EFalse,ETrue),
       
    55     iDescs(EFalse,ETrue)
       
    56     {
       
    57     }
       
    58 
       
    59 // Constructor
       
    60 void CWSOviSessionContext::ConstructL()
       
    61     {
       
    62     }
       
    63 
       
    64 // Destructor
       
    65 CWSOviSessionContext::~CWSOviSessionContext()
       
    66     {
       
    67     iDescriptions.Reset();
       
    68     iInts.Reset();
       
    69     iDescs.Reset();
       
    70     }
       
    71 // -----------------------------------------------------------------------------
       
    72 // Sets token context keys based on RST response.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 TInt CWSOviSessionContext::SetTokenKeysL(const TDesC8& aToken)
       
    76     {
       
    77 
       
    78 //1)TOKEN
       
    79     CWSOviServiceSession* session = (CWSOviServiceSession*)
       
    80                                             GetSenRemoteServiceSessionL(KServiceSession);
       
    81     session->SetMaxValidUntil();
       
    82     ((CSenWebServiceSession*)session)->SetSecurityL(aToken);
       
    83     session->AddPropertiesFromSessionContextToCredentialL();
       
    84     session->SetStatusL();
       
    85     if (((CSenServiceSession*)session)->StatusL() == KSenConnectionStatusExpired)
       
    86         {
       
    87         return KErrNotReady;
       
    88         }
       
    89     User::LeaveIfError(Update(WSOviContextKeys::KToken,
       
    90            aToken));
       
    91     return KErrNone;
       
    92     }
       
    93 
       
    94 //-----------------------------------------------------
       
    95 //              from MSessionContext
       
    96 //-----------------------------------------------------
       
    97 const CSenWSDescription* CWSOviSessionContext::GetSession()
       
    98     {
       
    99     return NULL;
       
   100     };
       
   101 const CSenWSDescription* CWSOviSessionContext::GetInitializer()
       
   102     {
       
   103     return NULL;
       
   104     };
       
   105 
       
   106 //descriptions    
       
   107 TInt CWSOviSessionContext::Add(const TDesC8& aKey, CSenWSDescription* aValue)
       
   108     {
       
   109     return iDescriptions.Append(&aKey,aValue);
       
   110     };
       
   111 
       
   112 TInt CWSOviSessionContext::Update(const TDesC8& aKey, CSenWSDescription* aValue)
       
   113     {
       
   114     iDescriptions.RemoveByKey(aKey);
       
   115     return iDescriptions.Append(&aKey,aValue);
       
   116     };
       
   117 
       
   118 const CSenWSDescription* CWSOviSessionContext::GetSenWSDescriptionL(const TDesC8& aKey)
       
   119     {
       
   120     TInt index = iDescriptions.Find(aKey);
       
   121     if (index!=KErrNotFound)
       
   122         {
       
   123         return iDescriptions.ValueAt(index);
       
   124         }
       
   125     else
       
   126         {
       
   127         return NULL;
       
   128         };        
       
   129     };
       
   130 
       
   131 
       
   132 //sessions    
       
   133 TInt CWSOviSessionContext::Add(const TDesC8& aKey, MSenRemoteServiceSession& aValue)
       
   134     {
       
   135     return Update(aKey, aValue);
       
   136     };
       
   137 TInt CWSOviSessionContext::Update(const TDesC8& /*aKey*/, MSenRemoteServiceSession& aValue)
       
   138     {
       
   139     iSession = &aValue;
       
   140     return KErrNone;
       
   141     };
       
   142 const MSenRemoteServiceSession* CWSOviSessionContext::GetSenRemoteServiceSessionL(const TDesC8& /*aKey*/)
       
   143     {
       
   144     return iSession;
       
   145     };    
       
   146 
       
   147 
       
   148 
       
   149 //-----------------------------------------------------
       
   150 //              from MContext
       
   151 //-----------------------------------------------------
       
   152 
       
   153 SenContext::TContextType CWSOviSessionContext::Type() const  
       
   154     {
       
   155     return SenContext::ESessionContext;
       
   156     }
       
   157 
       
   158 SenContext::TContextDirection CWSOviSessionContext::Direction() const 
       
   159     {
       
   160     return SenContext::EBoth;
       
   161     }
       
   162 
       
   163 
       
   164 
       
   165 //-----------------descs
       
   166 TInt CWSOviSessionContext::Add(const TDesC8& aKey, const TDesC8& aValue)
       
   167     {   
       
   168         if (!aValue.Length()) return KErrUnderflow;
       
   169         HBufC8* newValue = NULL;
       
   170         TInt error(KErrNone);
       
   171         TRAP(error, newValue = aValue.AllocL());
       
   172         if (!error)
       
   173             {
       
   174             error = iDescs.Append(&aKey,newValue);
       
   175             }
       
   176         return 
       
   177             error;
       
   178     }
       
   179 TInt CWSOviSessionContext::Update(const TDesC8& aKey, const TDesC8& aValue)
       
   180     {
       
   181         TInt error(KErrNone);
       
   182         if (!aValue.Length())
       
   183             {
       
   184             error = Remove(aKey);
       
   185             if (error == KErrNotFound)
       
   186                 return KErrNone;
       
   187             else
       
   188                 return error;
       
   189             }
       
   190         HBufC8* newValue = NULL;
       
   191         
       
   192         TRAP(error, newValue = aValue.AllocL());
       
   193         
       
   194         if (!error)
       
   195             {
       
   196             error = iDescs.UpdateValue(&aKey,newValue);
       
   197             }
       
   198         return 
       
   199             error;
       
   200     }
       
   201 const TDesC8* CWSOviSessionContext::GetDesC8L(const TDesC8& aKey)
       
   202     {
       
   203     TInt index = iDescs.Find(aKey);
       
   204     if (index != KErrNotFound)
       
   205         {
       
   206         return iDescs.ValueAt(index);
       
   207         }
       
   208     else
       
   209         {
       
   210         return NULL;
       
   211         };        
       
   212     }
       
   213 TInt CWSOviSessionContext::Remove(const TDesC8& aKey)
       
   214     {
       
   215     return iDescs.RemoveByKey(aKey);
       
   216     }
       
   217 
       
   218 
       
   219 //-----------------TInts
       
   220 TInt CWSOviSessionContext::Add(const TDesC8& aKey, TInt aValue)
       
   221     {
       
   222     TInt* a = NULL;
       
   223     a = new TInt(aValue);
       
   224     if (a) 
       
   225         {
       
   226         return iInts.Append(&aKey, a);
       
   227         }
       
   228     else
       
   229         {
       
   230         return KErrNoMemory;
       
   231         }
       
   232         
       
   233     }
       
   234 TInt CWSOviSessionContext::Update(const TDesC8& aKey, TInt aValue)
       
   235     {
       
   236     TInt* a = NULL;
       
   237     a = new TInt(aValue);
       
   238     if (a) 
       
   239         {
       
   240         return iInts.UpdateValue(&aKey, a);
       
   241         }
       
   242     else
       
   243         {
       
   244         return KErrNoMemory;
       
   245         }
       
   246     }
       
   247 const TInt* CWSOviSessionContext::GetIntL(const TDesC8& aKey)
       
   248     {
       
   249     TInt index = iInts.Find(aKey);
       
   250     if (index!=KErrNotFound)
       
   251         {
       
   252         return iInts.ValueAt(index);
       
   253         }
       
   254     else
       
   255         {
       
   256         return NULL;
       
   257         }
       
   258     }
       
   259 
       
   260 //-----------------elements
       
   261 TInt CWSOviSessionContext::Add(const TDesC8& aKey, CSenElement* aValue)
       
   262     {
       
   263     return Update(aKey,aValue);
       
   264     }
       
   265 TInt CWSOviSessionContext::Update(const TDesC8& /*aKey*/, CSenElement* /*aValue*/)
       
   266     {
       
   267     return KErrNotSupported;
       
   268     }
       
   269 const CSenElement* CWSOviSessionContext::GetSenElementL(const TDesC8& /*aKey*/)
       
   270     {
       
   271     return NULL;
       
   272     }
       
   273 
       
   274 //-----------------TAnys
       
   275 TInt CWSOviSessionContext::Add(const TDesC8& aKey, TAny* aValue)
       
   276     {
       
   277     TInt err(KErrNone);
       
   278     if ( aKey == SenContext::KRemoteConsumer() )
       
   279         {
       
   280         if ( !ipConsumer )
       
   281             {
       
   282             ipConsumer = aValue;
       
   283             }
       
   284          else
       
   285             {
       
   286             err = KErrAlreadyExists;
       
   287             }
       
   288         }
       
   289     else 
       
   290         {
       
   291         err = KErrNotFound;
       
   292         }        
       
   293     return err;
       
   294     }
       
   295 TInt CWSOviSessionContext::Update(const TDesC8& aKey, TAny* aValue)
       
   296     {
       
   297     TInt err(KErrNone);
       
   298     if ( aKey == SenContext::KRemoteConsumer() )
       
   299         {
       
   300         ipConsumer = aValue;
       
   301         }
       
   302     else if ( aKey == WSOviContextKeys::KTP() )
       
   303         {
       
   304         iTP = aValue;
       
   305         }
       
   306     else
       
   307         {
       
   308         err = KErrNotFound;
       
   309         }
       
   310     return err;
       
   311     }
       
   312 TAny* CWSOviSessionContext::GetAnyL(const TDesC8& aKey)
       
   313     {
       
   314     if ( aKey == WSOviContextKeys::KRemoteConsumer )
       
   315         {
       
   316         return ipConsumer;
       
   317         }
       
   318     else if ( aKey == WSOviContextKeys::KTP() )
       
   319         {
       
   320         return iTP;
       
   321         }
       
   322     else
       
   323         {
       
   324         return NULL;
       
   325         }
       
   326     }
       
   327 
       
   328 
       
   329 //-----------------Rest
       
   330 const CSenXmlReader* CWSOviSessionContext::GetParser()
       
   331     {
       
   332     return NULL;
       
   333     }
       
   334 TInt CWSOviSessionContext::Count() const
       
   335     { 
       
   336     return 0;
       
   337     }
       
   338 TPtrC8 CWSOviSessionContext::KeyAtL(TInt /*aIndex*/)
       
   339     { 
       
   340     return KNullDesC8();
       
   341     }        
       
   342 void CWSOviSessionContext::Reset()
       
   343     {
       
   344     }
       
   345 //-----------------------new    
       
   346 void CWSOviSessionContext::UpdateDesC8L(CWSOviMessageContext& aMessageContext, const TDesC8& aKey)
       
   347     {
       
   348     const TDesC8* ptr =
       
   349             aMessageContext.GetDesC8L(aKey);
       
   350     if (ptr)
       
   351         {
       
   352         User::LeaveIfError(Update(aKey, *ptr));
       
   353         }
       
   354     else
       
   355         {
       
   356         Remove(aKey);
       
   357         }
       
   358     
       
   359     }
       
   360     
       
   361 void CWSOviSessionContext::UpdateFromMessageInContextL(
       
   362         CWSOviMessageContext& /*aMessageContext*/)
       
   363     {
       
   364     
       
   365     }
       
   366 
       
   367 void CWSOviSessionContext::UpdateFromMessageOutContextL(
       
   368         CWSOviMessageContext& /*aMessageContext*/)
       
   369     {
       
   370     }
       
   371 TInt CWSOviSessionContext::ShareTokenWithL(CWSOviSessionContext* aWSOviSessionCtxDst)
       
   372     {
       
   373     TInt error = KErrNone;
       
   374     const TDesC8* desc = NULL;
       
   375 
       
   376     desc = GetDesC8L(KTokenCreationTime);
       
   377     if (desc)
       
   378         {
       
   379         error = aWSOviSessionCtxDst->Update(KTokenCreationTime, *desc);
       
   380         if (error) return error;
       
   381         }
       
   382     desc = GetDesC8L(KTTL);
       
   383     if (desc)
       
   384         {
       
   385         error = aWSOviSessionCtxDst->Update(KTTL, *desc);    
       
   386         if (error) return error;
       
   387         }    
       
   388     desc = GetDesC8L(KTokenSecret);
       
   389         if (desc)
       
   390             {
       
   391             error = aWSOviSessionCtxDst->Update(KTokenSecret, *desc);    
       
   392             if (error) return error;
       
   393             }
       
   394     desc = GetDesC8L(KToken);
       
   395         if (desc)
       
   396             {
       
   397             error = aWSOviSessionCtxDst->Update(KToken, *desc);    
       
   398             if (error) return error;
       
   399             }
       
   400             
       
   401     /*desc = GetDesC8L(KSecurityTokenBackup);
       
   402     if (desc)
       
   403         {
       
   404         error = aWSStarSessionCtxDst->Update(KSecurityTokenBackup, *desc);    
       
   405         if (error) return error;
       
   406         }*/
       
   407     return error;    
       
   408     }
       
   409 // END OF FILE
       
   410