vpnengine/dmadpki/src/dmadadapter.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2000-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:   PKI OMA DM Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <implementationproxy.h>
       
    22 
       
    23 #include "dmadadapter.h"
       
    24 #include "dmadadapterimplconst.h"
       
    25 #include "dmadengine.h"
       
    26 #include "DmAdStore.h"
       
    27 #include "dmadddf.h"
       
    28 #include "dmadrtnodedataapic.h"
       
    29 #include "vpnlogger.h"
       
    30 
       
    31 #if defined(_DEBUG)
       
    32 _LIT(KDmAdLogFolder,"vpn");
       
    33 _LIT(KDmAdLogFile,"dmadpki.log");
       
    34 #endif
       
    35 
       
    36 //===================================================================================================
       
    37 
       
    38 
       
    39 #ifndef IMPLEMENTATION_PROXY_ENTRY
       
    40 #define IMPLEMENTATION_PROXY_ENTRY(aUid, aFuncPtr)  {{aUid},(aFuncPtr)}
       
    41 #endif
       
    42 
       
    43 const TImplementationProxy ImplementationTable[] = 
       
    44     {
       
    45     IMPLEMENTATION_PROXY_ENTRY(KDmAdImplUid, CDmAdAdapter::NewL)
       
    46     };
       
    47 
       
    48 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    49     {
       
    50     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    51     return ImplementationTable;
       
    52     }
       
    53 
       
    54 
       
    55 //===================================================================================================
       
    56 
       
    57 CDmAdAdapter* CDmAdAdapter::NewL(MSmlDmCallback* aDmCallback)
       
    58     {       
       
    59     CDmAdAdapter* self = NewLC(aDmCallback);
       
    60     CleanupStack::Pop(self);
       
    61     return self;
       
    62     }
       
    63 
       
    64 CDmAdAdapter* CDmAdAdapter::NewLC(MSmlDmCallback* aDmCallback)
       
    65     {
       
    66     INITIALIZE_DEBUG_LOG_L(KDmAdLogFolder, KDmAdLogFile);    
       
    67     DEBUG_LOG(_L("LOGGING INITIALIZED"));     
       
    68                                   
       
    69     CDmAdAdapter* self = new (ELeave) CDmAdAdapter(aDmCallback);
       
    70     CleanupStack::PushL(self);
       
    71     self->ConstructL(aDmCallback);
       
    72     return self;
       
    73     }
       
    74     
       
    75 void CDmAdAdapter::ConstructL(MSmlDmCallback* aDmCallback)
       
    76     {
       
    77     TRACE("CDmAdAdapter::ConstructL");
       
    78     
       
    79     DEBUG_LOG(_L("ConstructL - CallBack (PKI)"));
       
    80     iCallBack = CDmAdCallBack::NewL(aDmCallback, KDmAdOwnAdUriForGetLuidAllocLFix);
       
    81     
       
    82     iStore = CDmAdStore::NewL(iCallBack);    
       
    83     iDdf = CDmAdDdf::NewL(iCallBack, iStore);
       
    84     
       
    85     DEBUG_LOG(_L("ConstructL - RtNodeDataApi"));
       
    86     iRtNodeDataApi = CDmAdRtNodeDataApi::NewL();
       
    87     DEBUG_LOG(_L("ConstructL - Engine"));
       
    88     iEngine = CDmAdEngine::NewL(iCallBack, iStore, iDdf, iRtNodeDataApi);
       
    89     
       
    90     }
       
    91 
       
    92 CDmAdAdapter::CDmAdAdapter(MSmlDmCallback* aDmCallback) : 
       
    93    CSmlDmAdapter(aDmCallback)
       
    94     {
       
    95     }
       
    96 
       
    97 CDmAdAdapter::~CDmAdAdapter()
       
    98     {
       
    99     DEBUG_LOG(_L("~CDmAdAdapter (PKI)"));
       
   100     
       
   101     delete iEngine;   
       
   102     delete iRtNodeDataApi;
       
   103     delete iDdf;
       
   104     delete iStore;    
       
   105     delete iCallBack;
       
   106     
       
   107     DEBUG_LOG(_L("FINALIZING LOGGING"));
       
   108     FINALIZE_DEBUG_LOG;
       
   109     }
       
   110     
       
   111 //===================================================================================================
       
   112 
       
   113 void CDmAdAdapter::DDFVersionL(CBufBase& aDDFVersion)
       
   114     {
       
   115     TRACE("CDmAdAdapter::DDFVersionL");   
       
   116     iDdf->BuildDDFVersionL(aDDFVersion);
       
   117     }
       
   118 
       
   119 void CDmAdAdapter::DDFStructureL(MSmlDmDDFObject& aDDF)
       
   120     {
       
   121     TRACE("CDmAdAdapter::DDFStructureL");
       
   122     iDdf->BuildDDFStructureL(aDDF);
       
   123     }
       
   124 
       
   125 
       
   126 void CDmAdAdapter::ChildURIListL(const TDesC8& aUri, const TDesC8& aParentLuid, const CArrayFix<TSmlDmMappingInfo>& aPreviousUriSegmentList, TInt aResultsRef, TInt aStatusRef)
       
   127     {
       
   128     TRACE("CDmAdAdapter::ChildURIListL");
       
   129     iEngine->ChildURIListL(aUri, aParentLuid, aPreviousUriSegmentList, aResultsRef, aStatusRef);
       
   130     }
       
   131 
       
   132 void CDmAdAdapter::AddNodeObjectL(const TDesC8& aUri, const TDesC8& aParentLuid, TInt aStatusRef)
       
   133     {
       
   134     TRACE("CDmAdAdapter::AddNodeObjectL");
       
   135     
       
   136     DEBUG_LOG1(_L8("aUri = %S"), &aUri);
       
   137     DEBUG_LOG1(_L8("aParentLuid = %S"), &aParentLuid);
       
   138     DEBUG_LOG1(_L("aStatusRef = %d"), aStatusRef);
       
   139     
       
   140     // PKCS#12 check here
       
   141     TInt status = CheckNodeStatus(aUri);
       
   142 
       
   143     if (status == KErrNone) 
       
   144         {
       
   145         iEngine->AddNodeObjectL(aUri, aParentLuid, aStatusRef);
       
   146         }
       
   147     else 
       
   148         {
       
   149         // Most probable reason for error code is that the
       
   150         // PKCS#12 node already exists in the LUID mapping
       
   151         DEBUG_LOG2(_L("Setting status ref %d to %d"), aStatusRef, status);
       
   152         iCallBack->SetStatusL(aStatusRef, status);
       
   153         }
       
   154     }
       
   155 
       
   156 TInt CDmAdAdapter::CheckNodeStatus(const TDesC8& aUri) 
       
   157     {
       
   158     TRACE("CDmAdAdapter::CheckNodeStatusL");
       
   159 
       
   160     // Check whether the object is a PKCS#12 one
       
   161     TInt ret = aUri.Find(KDmAdOwnAdUriForPKCS12);
       
   162 
       
   163     // If ret is >= 0, pkcs12 uri was identified
       
   164     if (ret >= 0) 
       
   165         {
       
   166         // See whether the given PKCS#12 object
       
   167         // already exists
       
   168         TRAP(ret, CheckPKCS12ExistenceL(aUri));
       
   169         }
       
   170     else 
       
   171         {
       
   172         // Wasn't a PKCS#12 node, no further checks needed
       
   173         ret = KErrNone;
       
   174         }
       
   175 
       
   176     DEBUG_LOG1(_L(" Returning with value %d"), ret);
       
   177 
       
   178     return ret;
       
   179     }
       
   180 
       
   181 void CDmAdAdapter::CheckPKCS12ExistenceL(const TDesC8& aUri)
       
   182     {
       
   183     TRACE("CDmAdAdapter::CheckPKCS12Existence");
       
   184     DEBUG_LOG1(_L8(" Testing with URI: '%S'"), &aUri);
       
   185 
       
   186     HBufC8* foundUri(NULL);
       
   187 
       
   188     // Check whether the "LUID" (actually, just the full URI) 
       
   189     // already exists...
       
   190     DEBUG_LOG(_L(" Comparing LUID/URI to see whether PKCS#12 node exists"));
       
   191     foundUri = iCallBack->GetLuidAllocL(aUri);
       
   192     CleanupStack::PushL(foundUri);
       
   193 
       
   194     if (foundUri->Length() > 0) 
       
   195         {
       
   196         DEBUG_LOG1(_L8(" Found URI: '%S'"), foundUri);
       
   197         DEBUG_LOG(_L(" PKCS#12 node already exists, no need to add, leaving"));
       
   198         User::Leave(KErrAlreadyExists);
       
   199         }
       
   200     else 
       
   201         {
       
   202         DEBUG_LOG(_L8(" Found URI: (empty)"));
       
   203         DEBUG_LOG(_L(" PKCS#12 node is a new one, proceeding with add"));
       
   204         }
       
   205 
       
   206     CleanupStack::PopAndDestroy(foundUri);
       
   207     }
       
   208 
       
   209 
       
   210 void CDmAdAdapter::UpdateLeafObjectL(const TDesC8& aUri, const TDesC8& aLuid, 
       
   211                                      const TDesC8& aObject, const TDesC8& aType, 
       
   212                                      TInt aStatusRef)
       
   213     {
       
   214     TRACE("CDmAdAdapter::UpdateLeafObjectL");
       
   215     
       
   216     DEBUG_LOG1(_L8("aUri = %S"), &aUri);
       
   217     DEBUG_LOG1(_L8("aLuid = %S"), &aLuid);
       
   218     DEBUG_LOG(_L8("aObject:"));
       
   219     DEBUG_LOG_HEX(aObject);
       
   220     DEBUG_LOG1(_L8("aType = %S"), &aType);
       
   221     DEBUG_LOG1(_L("aStatusRef = %d"), aStatusRef);
       
   222 
       
   223     TInt err = CheckNodeStatus(aUri);
       
   224 
       
   225     if (err == KErrNone) 
       
   226         {
       
   227         iEngine->UpdateLeafObjectL(aUri, aLuid, aObject, aType, aStatusRef);
       
   228         }
       
   229     else 
       
   230         {
       
   231         // If this PKCS#12 object already existed, do nothing
       
   232         iCallBack->SetStatusL(aStatusRef, err);
       
   233         }
       
   234     }
       
   235 
       
   236 void CDmAdAdapter::FetchLeafObjectL(const TDesC8& aUri, const TDesC8& aLuid, const TDesC8& aType, TInt aResultsRef, TInt aStatusRef)
       
   237     {
       
   238     TRACE("CDmAdAdapter::FetchLeafObjectL");
       
   239     iEngine->FetchLeafObjectL(aUri, aLuid, aType, aResultsRef, aStatusRef);
       
   240     }
       
   241 
       
   242 void CDmAdAdapter::DeleteObjectL(const TDesC8& aUri, const TDesC8& aLuid, TInt aStatusRef)
       
   243     {
       
   244     TRACE("CDmAdAdapter::DeleteObjectL");
       
   245     iEngine->DeleteObjectL(aUri, aLuid, aStatusRef);
       
   246     }
       
   247 
       
   248 void CDmAdAdapter::CompleteOutstandingCmdsL()
       
   249     {
       
   250     TRACE("CDmAdAdapter::CompleteOutstandingCmdsL");
       
   251     iEngine->CompleteOutstandingCmdsL();
       
   252     }
       
   253     
       
   254 void CDmAdAdapter::UpdateLeafObjectL(const TDesC8& aUri,
       
   255                                      const TDesC8& aLuid,
       
   256                                      RWriteStream*& aStream,
       
   257                                      const TDesC8& aType,
       
   258                                      TInt aStatusRef)
       
   259     {
       
   260     TRACE("CDmAdAdapter::UpdateLeafObjectL");
       
   261     iEngine->UpdateLeafObjectL(aUri, aLuid, aStream, aType, aStatusRef);
       
   262     }
       
   263     
       
   264 void CDmAdAdapter::FetchLeafObjectSizeL(const TDesC8& aUri,
       
   265                                         const TDesC8& aLuid,
       
   266                                         const TDesC8& aType,
       
   267                                         TInt aResultsRef,
       
   268                                         TInt aStatusRef)
       
   269     {
       
   270     TRACE("CDmAdAdapter::FetchLeafObjectSizeL");
       
   271     iEngine->FetchLeafObjectSizeL(aUri, aLuid, aType, aResultsRef, aStatusRef);
       
   272     }
       
   273     
       
   274 void CDmAdAdapter::ExecuteCommandL(const TDesC8& aUri,
       
   275                                    const TDesC8& aLuid,
       
   276                                    const TDesC8& aArgument,
       
   277                                    const TDesC8& aType,
       
   278                                    TInt aStatusRef)
       
   279     {
       
   280     TRACE("CDmAdAdapter::ExecuteCommandL");
       
   281     iEngine->ExecuteCommandL(aUri, aLuid, aArgument, aType, aStatusRef);
       
   282     }
       
   283     
       
   284 void CDmAdAdapter::ExecuteCommandL(const TDesC8& aUri,
       
   285                                    const TDesC8& aLuid,
       
   286                                    RWriteStream*& aStream,
       
   287                                    const TDesC8& aType,
       
   288                                    TInt aStatusRef)
       
   289     {
       
   290     TRACE("CDmAdAdapter::ExecuteCommandL");
       
   291     iEngine->ExecuteCommandL(aUri, aLuid, aStream, aType, aStatusRef);
       
   292     }
       
   293     
       
   294 void CDmAdAdapter::CopyCommandL(const TDesC8& aTargetUri,
       
   295                                 const TDesC8& aTargetLuid,
       
   296                                 const TDesC8& aSourceUri,
       
   297                                 const TDesC8& aSourceLuid,
       
   298                                 const TDesC8& aType,
       
   299                                 TInt aStatusRef)
       
   300     {
       
   301     TRACE("CDmAdAdapter::CopyCommandL");
       
   302     iEngine->CopyCommandL(aTargetUri, aTargetLuid, aSourceUri, aSourceLuid, aType, aStatusRef);
       
   303     }
       
   304     
       
   305 void CDmAdAdapter::StartAtomicL()
       
   306     {
       
   307     TRACE("CDmAdAdapter::StartAtomicL");
       
   308     iEngine->StartAtomicL();
       
   309     }
       
   310     
       
   311 void CDmAdAdapter::CommitAtomicL()
       
   312     {
       
   313     TRACE("CDmAdAdapter::CommitAtomicL");
       
   314     iEngine->CommitAtomicL();
       
   315     }
       
   316     
       
   317 void CDmAdAdapter::RollbackAtomicL()
       
   318     {
       
   319     TRACE("CDmAdAdapter::RollbackAtomicL");
       
   320     iEngine->RollbackAtomicL();
       
   321     }
       
   322     
       
   323 TBool CDmAdAdapter::StreamingSupport(TInt& aItemSize)
       
   324     {
       
   325     TRACE("CDmAdAdapter::StreamingSupport");
       
   326     return iEngine->StreamingSupport(aItemSize);
       
   327     }
       
   328     
       
   329 void CDmAdAdapter::StreamCommittedL()
       
   330     {
       
   331     TRACE("CDmAdAdapter::StreamCommittedL");
       
   332     iEngine->StreamCommittedL();
       
   333     }
       
   334