applicationmanagement/omascomoadapter/src/omascomoadapter.cpp
changeset 0 3ce708148e4d
child 4 75a71fdb4c92
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Implementation of applicationmanagement components
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21 
       
    22  1. Remember the applications managed by Corporate Admin Role certificate
       
    23  1.1 They must be removed during rfs
       
    24  1.2 Others must be left as is (applications at least must be left)
       
    25 
       
    26  */
       
    27 
       
    28 
       
    29 #define __AM_CHECKSTATE_CHANGES // uncomment to enable dynamic acl
       
    30 #include <badesca.h>
       
    31 #include <fbs.h>
       
    32 #include <s32file.h> 
       
    33 #include "omascomoadapter.h"
       
    34 #include <implementationproxy.h> // For TImplementationProxy definition
       
    35 #include <f32file.h>
       
    36 #include "nsmldmuri.h"
       
    37 #include "nsmldmiapmatcher.h"
       
    38 #include "debug.h"
       
    39 #include "amprivateCRKeys.h"
       
    40 #include <centralrepository.h>
       
    41 #include "aminstalloptions.h"
       
    42 #include <featmgr.h>
       
    43 #include <apgtask.h>
       
    44 #include <w32std.h>
       
    45 
       
    46 #include <SyncMLClient.h>
       
    47 #include <SyncMLClientDM.h>
       
    48 #include <e32property.h>
       
    49 #include <centralrepository.h>
       
    50 #include <DevManInternalCRKeys.h>
       
    51 #include<HttpDownloadMgrCommon.h>
       
    52 
       
    53 #include "NSmlPrivateAPI.h"
       
    54 
       
    55 #include "nsmldmconst.h"
       
    56 #include "ampskeys.h"
       
    57 
       
    58 #include "nsmldmtreedbclient.h"
       
    59 #include "SyncService.h"
       
    60 #include "amprivateCRKeys.h"
       
    61 #include <e32cmn.h>
       
    62 #include <SWInstDefs.h>
       
    63 
       
    64 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
    65 #include <dmtreenode.h>
       
    66 #include <devman.h>
       
    67 #include "nsmldmuri.h"
       
    68 
       
    69 // Constants
       
    70 _LIT8( KDeployedURI, "./SCOMO/Inventory/Deployed/" );
       
    71 _LIT8( KDeliveredURI, "./SCOMO/Inventory/Delivered/" );
       
    72 _LIT8( KDownloadURI, "./SCOMO/Download/" );
       
    73 #else
       
    74 #include <nsmldmuri.h>
       
    75 
       
    76 // Constants
       
    77 _LIT8( KDeployedURI, "SCOMO/Inventory/Deployed/" );
       
    78 _LIT8( KDeliveredURI, "SCOMO/Inventory/Delivered/" );
       
    79 _LIT8( KDownloadURI, "SCOMO/Download/" );
       
    80 #endif
       
    81 
       
    82 #ifdef __NSML_DEBUG__
       
    83 #pragma message("NSml Debugging is ON!")
       
    84 #else
       
    85 #endif
       
    86 
       
    87 using namespace NApplicationManagement;
       
    88 
       
    89 _LIT8( KAMStateValueActive, "20" );
       
    90 _LIT8( KAMStateValueInactive, "10" );
       
    91 _LIT8( KAMStateValueDelivered, "10" );
       
    92 
       
    93 _LIT8( KSisxMimeType, "x-epoc/x-sisx-app" );
       
    94 _LIT8( KSisMimeType, "application/vnd.symbian.install" );
       
    95 _LIT8( KPipMimeType, "application/x-pip" );
       
    96 _LIT8( KJadMIMEType, "text/vnd.sun.j2me.app-descriptor" );
       
    97 _LIT8( KJarMIMEType, "application/java-archive" );
       
    98 _LIT8( KJavaMIMEType, "application/java" );
       
    99 
       
   100 
       
   101 
       
   102 const TUint8 KNSmlDMAMSeparatorDef = 0x2f; //forward slash
       
   103 #ifdef __AM_LASTERROR_NODE
       
   104 
       
   105 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   106 _LIT8( KAMLastErrorURI, "./SCOMO/Ext/LastError" );
       
   107 #else
       
   108 _LIT8( KAMLastErrorURI, "SCOMO/Ext/LastError" );
       
   109 #endif
       
   110 _LIT8( KStdError, "Error %d" );
       
   111 
       
   112 #define MAPERROR(x,y,z) DefaultMapError(x,y,z)
       
   113 #else
       
   114 
       
   115 #define MAPERROR(x,y,z) DefaultMapError(x,y)
       
   116 #endif
       
   117 
       
   118 
       
   119 // ------------------------------------------------------------------------------------------------
       
   120 // CSCOMOAdapter* CSCOMOAdapter::NewL( )
       
   121 // ------------------------------------------------------------------------------------------------
       
   122 CSCOMOAdapter* CSCOMOAdapter::NewL(MSmlDmCallback* aDmCallback)
       
   123     {
       
   124     RDEBUG("CSCOMOAdapter::NewL(): begin");
       
   125 
       
   126     CSCOMOAdapter* self = NewLC(aDmCallback);
       
   127     CleanupStack::Pop();
       
   128     return self;
       
   129     }
       
   130 
       
   131 // ------------------------------------------------------------------------------------------------
       
   132 // CSCOMOAdapter* CSCOMOAdapter::NewLC( )
       
   133 // ------------------------------------------------------------------------------------------------
       
   134 CSCOMOAdapter* CSCOMOAdapter::NewLC(MSmlDmCallback* aDmCallback)
       
   135     {
       
   136     CSCOMOAdapter* self = new( ELeave ) CSCOMOAdapter( aDmCallback );
       
   137     CleanupStack::PushL(self);
       
   138     self->ConstructL();
       
   139     return self;
       
   140     }
       
   141 
       
   142 // ------------------------------------------------------------------------------------------------
       
   143 // CSCOMOAdapter::CSCOMOAdapter()
       
   144 // ------------------------------------------------------------------------------------------------
       
   145 CSCOMOAdapter::CSCOMOAdapter(TAny* aEcomArguments) :
       
   146     CSmlDmAdapter(aEcomArguments), iSessionOpened(EFalse), iBuffer( 8),
       
   147             iInAtomic(EFalse), iUpdated(EFalse), iIsStreamedContent(EFalse)
       
   148     {
       
   149     }
       
   150 
       
   151 // ------------------------------------------------------------------------------------------------
       
   152 // CSCOMOAdapter::~CSCOMOAdapter()
       
   153 // ------------------------------------------------------------------------------------------------
       
   154 CSCOMOAdapter::~CSCOMOAdapter()
       
   155     {
       
   156     RDEBUG( "CSCOMOAdapter::~CSCOMOAdapter" );
       
   157     iDbSession.Close();
       
   158     iManagement.Close(); // make sure we're closed
       
   159     iSessionOpened = EFalse;
       
   160     iBuffer.Close();
       
   161 
       
   162     CloseStreaming(); // Ensures that no streams are left open and that the temporary file is removed
       
   163 
       
   164     delete iStreamedURI;
       
   165     delete iStreamedLuid;
       
   166     delete iStreamedType;
       
   167 
       
   168 #ifdef __AM_LASTERROR_NODE
       
   169     delete iLastError;
       
   170 #endif
       
   171 
       
   172     if (iAMdb)
       
   173         delete iAMdb;
       
   174 
       
   175     if (iUriDel)
       
   176         delete iUriDel;
       
   177     RDEBUG( "CSCOMOAdapter::~CSCOMOAdapter end" );
       
   178     }
       
   179 
       
   180 // ------------------------------------------------------------------------------------------------
       
   181 //  CSCOMOAdapter::DDFVersionL()
       
   182 // ------------------------------------------------------------------------------------------------
       
   183 void CSCOMOAdapter::DDFVersionL(CBufBase& aDDFVersion)
       
   184     {
       
   185     aDDFVersion.InsertL( 0, KAMDDFVersion);
       
   186     }
       
   187 
       
   188 // ------------------------------------------------------------------------------------------------
       
   189 //  CSCOMOAdapter::DDFStructureL()
       
   190 //
       
   191 // ------------------------------------------------------------------------------------------------
       
   192 void CSCOMOAdapter::DDFStructureL(MSmlDmDDFObject& aDDF)
       
   193     {
       
   194     RDEBUG( "CSCOMOAdapter::DDFStructureL(): begin" );
       
   195 
       
   196     TSmlDmAccessTypes accessTypesGet;
       
   197     accessTypesGet.SetGet();
       
   198 
       
   199     TSmlDmAccessTypes accessTypesExec;
       
   200     accessTypesExec.SetExec();
       
   201 
       
   202     TSmlDmAccessTypes accessTypesAdd;
       
   203     accessTypesAdd.SetAdd();
       
   204 
       
   205     TSmlDmAccessTypes accessTypesExecReplace = accessTypesExec;
       
   206     accessTypesExecReplace.SetReplace();
       
   207 
       
   208     TSmlDmAccessTypes accessTypesGetAdd = accessTypesGet;
       
   209     accessTypesGetAdd.SetAdd();
       
   210 
       
   211     TSmlDmAccessTypes accessTypesGetReplace = accessTypesGet;
       
   212     accessTypesGetReplace.SetGet();
       
   213 
       
   214     TSmlDmAccessTypes accessTypesGetAddReplace = accessTypesGetAdd;
       
   215     accessTypesGetAddReplace.SetReplace();
       
   216 
       
   217     TSmlDmAccessTypes accessTypesGetAddReplaceDelete =
       
   218             accessTypesGetAddReplace;
       
   219     accessTypesGetAddReplaceDelete.SetDelete();
       
   220 
       
   221     TSmlDmAccessTypes accessTypesAddReplace = 
       
   222 	    accessTypesAdd;
       
   223     accessTypesAddReplace.SetReplace();
       
   224 
       
   225     /*
       
   226      Node: ./SCOMO
       
   227      AM node is the common parent to all application management functionality nodes. 
       
   228      Support: Mandatory
       
   229      Occurs: One
       
   230      Format: Node
       
   231      Access Types: Get
       
   232      Values: N/A
       
   233      */
       
   234     //MSmlDmDDFObject& root = aDDF.AddChildObjectGroupL();
       
   235     MSmlDmDDFObject& am = aDDF.AddChildObjectL(KAMNodeName);
       
   236     FillNodeInfoL(am, accessTypesGet, MSmlDmDDFObject::EOne,
       
   237             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   238             KAMNodeDescription);
       
   239 
       
   240     /*
       
   241      Node: ./SCOMO/Inventory
       
   242      This node is start node to application inventory. 
       
   243      Support: Mandatory
       
   244      Occurs: One
       
   245      Format: Node
       
   246      Access Types: Get
       
   247      Values: N/A
       
   248      */
       
   249     MSmlDmDDFObject& inv = am.AddChildObjectL(KAMInventoryNodeName);
       
   250     FillNodeInfoL(inv, accessTypesGet, MSmlDmDDFObject::EOne,
       
   251             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   252             KAMInventoryNodeDescription);
       
   253 
       
   254     /*
       
   255      Node: ./SCOMO/Inventory/Delivered
       
   256      This is node under which applications that are delivered but not installed are found.
       
   257      Support: Mandatory
       
   258      Occurs: One
       
   259      Format: Node
       
   260      Access Types: Get, Add
       
   261      Values: N/A
       
   262      */
       
   263     MSmlDmDDFObject& del = inv.AddChildObjectL(KAMDeliveredNodeName);
       
   264     FillNodeInfoL(del, accessTypesGetAdd, MSmlDmDDFObject::EOne,
       
   265             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   266             KAMDeliveredNodeDescription);
       
   267 
       
   268     /*
       
   269      Node: ./SCOMO/Inventory/Deployed
       
   270      This is a node under which active applications are found.
       
   271      The child node descriptions are same as Delivered sibling node, except that <X> cannot be created, data node does not exist and there's no InstallOpts leaf.
       
   272      Support: Mandatory
       
   273      Occurs: One
       
   274      Format: Node
       
   275      Access Types: Get
       
   276      Values: N/A
       
   277      */
       
   278 
       
   279     MSmlDmDDFObject& ac = inv.AddChildObjectL(KAMDeployedNodeName);
       
   280     FillNodeInfoL(ac, accessTypesGet, MSmlDmDDFObject::EOne,
       
   281             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   282             KAMDeployedNodeDescription);
       
   283 
       
   284     /*
       
   285      Node: ./SCOMO/Inventory/Delivered/<X>
       
   286      This dynamic node is placeholder applications that are in Delivered state. 
       
   287      Support: Mandatory
       
   288      Occurs: ZeroOrMore
       
   289      Format: Node
       
   290      Access Types: Get, Add, Replace, Delete
       
   291      Values: N/A
       
   292      */
       
   293     MSmlDmDDFObject& deldyna = del.AddChildObjectGroupL();
       
   294     FillNodeInfoL(deldyna, accessTypesGetAddReplaceDelete,
       
   295             MSmlDmDDFObject::EZeroOrMore, MSmlDmDDFObject::EDynamic,
       
   296             MSmlDmDDFObject::ENode, KAMDeliveredDynaNodeDescription);
       
   297 
       
   298     /*
       
   299      Node: ./SCOMO/Inventory/Delivered/<X>/PkgID
       
   300      This leaf node holds an identifier for an application.
       
   301      Support: Mandatory
       
   302      Occurs: One
       
   303      Format: Chr
       
   304      Access Types: Get, Add, Replace
       
   305      Values: N/A
       
   306      */
       
   307     MSmlDmDDFObject& delid = deldyna.AddChildObjectL(KAMPkgIDNodeName);
       
   308     FillNodeInfoL(delid, accessTypesGetAddReplace, MSmlDmDDFObject::EOne,
       
   309             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   310             KAMPkgIDNodeDescription);
       
   311 
       
   312     /*
       
   313      Node: ./SCOMO/Inventory/Delivered/<X>/Name
       
   314      This leaf node holds name of an application. 
       
   315      Support: Mandatory
       
   316      Occurs: One
       
   317      Format: Chr
       
   318      Access Types: Get ( + Add, Replace access within Delivered node only)
       
   319      Values: N/A
       
   320      */
       
   321     MSmlDmDDFObject& delname = deldyna.AddChildObjectL(KAMNameNodeName);
       
   322     FillNodeInfoL(delname, accessTypesGetAddReplace,
       
   323             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   324             MSmlDmDDFObject::EChr, KAMNameNodeDescription);
       
   325 
       
   326     
       
   327     /*
       
   328      Node: ./SCM/Inventory/Delivered/<X>/Status
       
   329      This leaf node holds the status of the Delivered. The client updates the node value. 
       
   330      The values are typically error codes of Operations done on delivered node
       
   331      Support: Mandatory 
       
   332      Occurs: One
       
   333      Format: Int
       
   334      Access Types: Get
       
   335      Values: N/A
       
   336      */
       
   337     MSmlDmDDFObject& delstatus = deldyna.AddChildObjectL(KAMStatusNodeName);
       
   338     FillNodeInfoL(delstatus, accessTypesGet, MSmlDmDDFObject::EOne,
       
   339             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EInt,
       
   340             KAMStatusNodeDescription);
       
   341 
       
   342     /*
       
   343      Node: ./SCOMO/Inventory/Delivered/<X>/PkgType
       
   344      This leaf node holds an identifier for an application.
       
   345      Support: Mandatory
       
   346      Occurs: One
       
   347      Format: Chr
       
   348      Access Types: Get 
       
   349      Values: N/A
       
   350      */
       
   351     MSmlDmDDFObject& delpkgtype = deldyna.AddChildObjectL(KAMPkgTypeNodeName);
       
   352     FillNodeInfoL(delpkgtype, accessTypesGetAddReplace, MSmlDmDDFObject::EZeroOrOne,
       
   353             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   354             KAMPkgTypeNodeDescription);
       
   355     
       
   356     
       
   357     /*
       
   358      Node: ./SCOMO/Inventory/Delivered/<X>/Data
       
   359      This leaf node holds the data of an application. 
       
   360      Support: Mandatory
       
   361      Occurs: One
       
   362      Format: Bin
       
   363      Access Types: Add, Replace
       
   364      Values: N/A
       
   365      */
       
   366     MSmlDmDDFObject& delda = deldyna.AddChildObjectL(KAMDataNodeName);
       
   367     FillNodeInfoNoDefaultMimeL(delda, accessTypesAddReplace,
       
   368             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   369             MSmlDmDDFObject::EBin, KAMDataNodeDescription);
       
   370 
       
   371     delda.AddDFTypeMimeTypeL(KSisxMimeType);
       
   372     delda.AddDFTypeMimeTypeL(KSisMimeType);
       
   373     delda.AddDFTypeMimeTypeL(KPipMimeType);
       
   374 
       
   375     FeatureManager::InitializeLibL();
       
   376     if (FeatureManager::FeatureSupported(KFeatureIdJavaMIDP20) )
       
   377         {
       
   378         delda.AddDFTypeMimeTypeL(KJadMIMEType);
       
   379         delda.AddDFTypeMimeTypeL(KJarMIMEType);
       
   380         delda.AddDFTypeMimeTypeL(KJavaMIMEType);
       
   381         }
       
   382 
       
   383     FeatureManager::UnInitializeLib();
       
   384 
       
   385     /*
       
   386      Node: ./SCOMO/Inventory/Delivered/<X>/Description
       
   387      This leaf node holds the possible metadata of an application. Descriptor can be for example such a data that is required by the actual data in the Data leaf, but for some reason they cannot be bundled into same package. An example is Java JAR and JAD file combination, in which JAD file could be placed in MetaData and JAR in Data leaf.
       
   388      Support: Optional
       
   389      Occurs: One
       
   390      Format: Bin
       
   391      Access Types: Add, Get, Replace
       
   392      Values: N/A
       
   393      */
       
   394     MSmlDmDDFObject& delmd = deldyna.AddChildObjectL(KAMDescriptionNodeName);
       
   395     FillNodeInfoL(delmd, accessTypesGetAddReplace,
       
   396             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   397             MSmlDmDDFObject::EBin, KAMDescriptorNodeDescription);
       
   398 
       
   399      /*
       
   400      Node: ./SCOMO/Inventory/Delivered/<X>/State
       
   401      This leaf node holds state value of an application. 
       
   402      Support: ?
       
   403      Occurs: One
       
   404      Format: Chr
       
   405      Access Types: Get 
       
   406      Values: N/A
       
   407      */
       
   408     MSmlDmDDFObject& delstate =
       
   409             deldyna.AddChildObjectL(KAMStateValueNodeName);
       
   410     FillNodeInfoL(delstate, accessTypesGet, MSmlDmDDFObject::EOne,
       
   411             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   412             KAMStateValueNodeDescription);
       
   413     
       
   414     /*
       
   415      Node: ./SCOMO/Inventory/Delivered/<X>/Operations
       
   416      This is a node that allows vendors to extend functionality.
       
   417      Support: Optional
       
   418      Occurs: One
       
   419      Format: Node
       
   420      Access Types: Get, Replace, Add, Delete
       
   421      Values: N/A
       
   422      */
       
   423     MSmlDmDDFObject& delop = deldyna.AddChildObjectL(KAMOperationsNodeName);
       
   424     FillNodeInfoL(delop, accessTypesGet, MSmlDmDDFObject::EOne,
       
   425             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   426             KAMOperationsNodeDescription);
       
   427 
       
   428     /*
       
   429      Node: ./SCOMO/Inventory/Delivered/<X>/Operations/Install
       
   430      Exec command causes device to install a delivered application. The data inside 
       
   431      exec command refers to the application to be installed. 
       
   432      Support: Mandatory
       
   433      Occurs: One
       
   434      Format: Node
       
   435      Access Types: Exec, Replace
       
   436      Values: N/A
       
   437      */
       
   438     MSmlDmDDFObject& loinst = delop.AddChildObjectL(KAMInstallNodeName);
       
   439     FillNodeInfoL(loinst, accessTypesExecReplace, MSmlDmDDFObject::EOne,
       
   440             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   441             KAMInstallNodeDescription);
       
   442 
       
   443     /*
       
   444      Node: ./SCOMO/Inventory/Delivered/<X>/Operations/InstallInactive
       
   445      Exec command causes device to install a delivered application. The data inside 
       
   446      exec command refers to the application to be installed. 
       
   447      Support: Mandatory
       
   448      Occurs: One
       
   449      Format: Node
       
   450      Access Types: Exec, Replace
       
   451      Values: N/A
       
   452      */
       
   453     MSmlDmDDFObject& loinstact =
       
   454             delop.AddChildObjectL(KAMInstallInactiveNodeName);
       
   455     FillNodeInfoL(loinstact, accessTypesExecReplace, MSmlDmDDFObject::EOne,
       
   456             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   457             KAMInstallInactivateNodeDescription);
       
   458 
       
   459     
       
   460     /*
       
   461      Node: ./SCOMO/Inventory/Delivered/<X>/Operations/Remove
       
   462      Exec command causes device to remove an application. The data inside exec command refers to the application to be removed. The application must be in Inactive state in order for remove to be successful.
       
   463      Support: Mandatory
       
   464      Occurs: One
       
   465      Format: Node
       
   466      Access Types: Exec, Replace
       
   467      Values: N/A
       
   468      */
       
   469     MSmlDmDDFObject& lorem = delop.AddChildObjectL(KAMRemoveNodeName);
       
   470     FillNodeInfoL(lorem, accessTypesExecReplace, MSmlDmDDFObject::EOne,
       
   471             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   472             KAMRemoveNodeDescription);
       
   473 
       
   474     /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
       
   475      DEPLOYED
       
   476      *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
       
   477 
       
   478     /*
       
   479      Node: ./SCOMO/Inventory/Deployed/<X>
       
   480      This dynamic node is placeholder applications that are in Inactive state. 
       
   481      Support: Mandatory
       
   482      Occurs: ZeroOrMore
       
   483      Format: Node
       
   484      Access Types: Get, Replace
       
   485      Values: N/A
       
   486      */
       
   487     MSmlDmDDFObject& depldyna = ac.AddChildObjectGroupL();
       
   488     FillNodeInfoL(depldyna, accessTypesGetReplace,
       
   489             MSmlDmDDFObject::EZeroOrMore, MSmlDmDDFObject::EDynamic,
       
   490             MSmlDmDDFObject::ENode, KAMDeployedDynaNodeDescription);
       
   491 
       
   492     /*
       
   493      Node: ./SCOMO/Inventory/Deployed/<X>/ID
       
   494      This leaf node holds an identifier for an application. This cannot be changed.
       
   495      Support: Mandatory
       
   496      Occurs: One
       
   497      Format: Chr
       
   498      Access Types: Get
       
   499      Values: N/A
       
   500      */
       
   501     MSmlDmDDFObject& deplid = depldyna.AddChildObjectL(KAMIDNodeName);
       
   502     FillNodeInfoL(deplid, accessTypesGet, MSmlDmDDFObject::EOne,
       
   503             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   504             KAMIDNodeDescription);
       
   505 
       
   506     /*
       
   507      Node: ./SCOMO/Inventory/Deployed/<X>/Name
       
   508      This leaf node holds name of an application.
       
   509      Support: Mandatory
       
   510      Occurs: One
       
   511      Format: Chr
       
   512      Access Types: Get, Add, Replace
       
   513      Values: N/A
       
   514      */
       
   515     MSmlDmDDFObject& deplname = depldyna.AddChildObjectL(KAMNameNodeName);
       
   516     FillNodeInfoL(deplname, accessTypesGetAddReplace,
       
   517             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   518             MSmlDmDDFObject::EChr, KAMNameNodeDescription);
       
   519 
       
   520     /*
       
   521      Node: ./SCOMO/Inventory/Deployed/<X>/Version
       
   522      This leaf node holds the version of an application.
       
   523      Support: Mandatory
       
   524      Occurs: One
       
   525      Format: Chr
       
   526      Access Types: Get, Add, Replace
       
   527      Values: N/A
       
   528      */
       
   529     MSmlDmDDFObject& deplver = depldyna.AddChildObjectL(KAMVersionNodeName);
       
   530     FillNodeInfoL(deplver, accessTypesGetAddReplace,
       
   531             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   532             MSmlDmDDFObject::EChr, KAMVersionNodeDescription);
       
   533     
       
   534     /*
       
   535      Node: ./SCOMO/Inventory/Deployed/<X>/Description
       
   536      This leaf node holds the version of an application.
       
   537      Support: Mandatory
       
   538      Occurs: One
       
   539      Format: Chr
       
   540      Access Types: Get, Add, Replace
       
   541      Values: N/A
       
   542      */
       
   543     MSmlDmDDFObject& depldesc = depldyna.AddChildObjectL(KAMDescriptionNodeName);
       
   544     FillNodeInfoL(depldesc, accessTypesGetAddReplace,
       
   545             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   546             MSmlDmDDFObject::EChr, KAMDescriptionNodeDescription);        
       
   547             
       
   548     /*
       
   549      Node: ./SCOMO/Inventory/Deployed/<X>/PkgIDRef
       
   550      This leaf node holds an identifier for an application. This cannot be changed.
       
   551      Support: Mandatory
       
   552      Occurs: One
       
   553      Format: Chr
       
   554      Access Types: Get
       
   555      Values: N/A
       
   556      */
       
   557     MSmlDmDDFObject& deplidref = depldyna.AddChildObjectL(KAMPkgIDRefNodeName);
       
   558     FillNodeInfoL(deplidref, accessTypesGet, MSmlDmDDFObject::EOne,
       
   559             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   560             KAMPkgIDRefNodeDescription);
       
   561 
       
   562     /*
       
   563      Node: ./SCOMO/Inventory/Deployed/<X>/Status
       
   564      This leaf node holds the status of the Deployed. The client updates the node value. 
       
   565      The values are typically error codes of Operations done on deployed node
       
   566      Support: Mandatory 
       
   567      Occurs: One
       
   568      Format: Int
       
   569      Access Types: Get
       
   570      Values: N/A
       
   571      */
       
   572     MSmlDmDDFObject& deplstatus = depldyna.AddChildObjectL(KAMStatusNodeName);
       
   573     FillNodeInfoL(deplstatus, accessTypesGet, MSmlDmDDFObject::EOne,
       
   574             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EInt,
       
   575             KAMStatusNodeDescription);
       
   576 
       
   577     /*
       
   578      Node: ./SCOMO/Inventory/Deployed/<X>/State
       
   579      This leaf node holds state value of an application. 
       
   580      Support: ?
       
   581      Occurs: One
       
   582      Format: Chr
       
   583      Access Types: Get 
       
   584      Values: N/A
       
   585      */
       
   586     MSmlDmDDFObject& deplstate =
       
   587             depldyna.AddChildObjectL(KAMStateValueNodeName);
       
   588     FillNodeInfoL(deplstate, accessTypesGet, MSmlDmDDFObject::EOne,
       
   589             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   590             KAMStateValueNodeDescription);
       
   591 
       
   592     /*
       
   593      Node: ./SCOMO/Inventory/Deployed/<X>/Operations
       
   594      This is a node that allows vendors to extend functionality.
       
   595      Support: Optional
       
   596      Occurs: One
       
   597      Format: Node
       
   598      Access Types: Get, Replace, Add, Delete
       
   599      Values: N/A
       
   600 
       
   601      */
       
   602     MSmlDmDDFObject& deplop = depldyna.AddChildObjectL(KAMOperationsNodeName);
       
   603     FillNodeInfoL(deplop, accessTypesGet, MSmlDmDDFObject::EOne,
       
   604             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   605             KAMOperationsNodeDescription);
       
   606 
       
   607     /*
       
   608      Node: ./SCOMO/Inventory/Deployed/<X>/Operations/Remove
       
   609      Exec command causes device to remove an application. The data inside exec command 
       
   610      refers to the application to be removed. The application must be in Inactive state 
       
   611      in order for remove to be successful.
       
   612      Support: Mandatory
       
   613      Occurs: One
       
   614      Format: Node
       
   615      Access Types: Exec, Replace
       
   616      Values: N/A
       
   617      */
       
   618     MSmlDmDDFObject& deplrem = deplop.AddChildObjectL(KAMRemoveNodeName);
       
   619     FillNodeInfoL(deplrem, accessTypesExecReplace, MSmlDmDDFObject::EOne,
       
   620             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   621             KAMRemoveNodeDescription);
       
   622 
       
   623     /*
       
   624      Node: ./SCOMO/Inventory/Deployed/<X>/Operations/Activate
       
   625      Exec command causes device to activate an application. 
       
   626      Support: Mandatory
       
   627      Occurs: One
       
   628      Format: Node
       
   629      Access Types: Exec, Replace
       
   630      Values: N/A
       
   631      */
       
   632     MSmlDmDDFObject& deplac = deplop.AddChildObjectL(KAMActivateNodeName);
       
   633     FillNodeInfoL(deplac, accessTypesExecReplace, MSmlDmDDFObject::EOne,
       
   634             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   635             KAMActivateNodeDescription);
       
   636 
       
   637     /*
       
   638      Node: ./SCOMO/Inventory/Deployed/<X>/Operations/Deactivate
       
   639      Exec command causes device to deactivate an application. 
       
   640      Support: Mandatory
       
   641      Occurs: One
       
   642      Format: Node
       
   643      Access Types: Exec, Replace
       
   644      Values: N/A
       
   645      */
       
   646     MSmlDmDDFObject& depldeac = deplop.AddChildObjectL(KAMDeActivateNodeName);
       
   647     FillNodeInfoL(depldeac, accessTypesExecReplace, MSmlDmDDFObject::EOne,
       
   648             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   649             KAMDeActivateNodeDescription);
       
   650 
       
   651     /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
       
   652      DOWNLOAD
       
   653      *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
       
   654 
       
   655     /*
       
   656      Node: ./SCOMO/Download
       
   657      This node is a root node for application download functionality. In practice download 
       
   658      works so that admin adds nodes under this node, and they are automatically moved to 
       
   659      Inventory/Delivered when the download has been finished. Running get command targeting 
       
   660      to this node returns a list of pending downloads. 
       
   661      Support: Mandatory 
       
   662      Occurs: One
       
   663      Format: Node
       
   664      Access Types: Get, Add, Replace
       
   665      Values: N/A
       
   666      */
       
   667     MSmlDmDDFObject& dow = am.AddChildObjectL(KAMDownloadNodeName);
       
   668     FillNodeInfoL(dow, accessTypesGetAddReplace, MSmlDmDDFObject::EOne,
       
   669             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   670             KAMDownloadNodeDescription);
       
   671 
       
   672     /*
       
   673      Node: ./SCOMO/Download/<X>
       
   674      This node is a placeholder for identifier of an application that is to be downloaded. 
       
   675      Support: Mandatory 
       
   676      Occurs: One
       
   677      Format: Node
       
   678      Access Types: Get, Add, Replace, Delete
       
   679      Values: N/A
       
   680      */
       
   681     MSmlDmDDFObject& dowdyna = dow.AddChildObjectGroupL();
       
   682     FillNodeInfoL(dowdyna, accessTypesGetAddReplaceDelete,
       
   683             MSmlDmDDFObject::EZeroOrMore, MSmlDmDDFObject::EDynamic,
       
   684             MSmlDmDDFObject::ENode, KAMDownloadDynaNodeDescription);
       
   685 
       
   686     /*
       
   687      Node: ./SCOMO/Download/<X>/PkgID
       
   688      This leaf node holds an identifier for an application. 
       
   689      Support: Mandatory
       
   690      Occurs: One
       
   691      Format: Chr
       
   692      Access Types: Get
       
   693      Values: N/A
       
   694      */
       
   695     MSmlDmDDFObject& dowid = dowdyna.AddChildObjectL(KAMPkgIDNodeName);
       
   696     FillNodeInfoL(dowid, accessTypesGetAddReplace, MSmlDmDDFObject::EOne,
       
   697             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   698             KAMPkgIDNodeDescription);
       
   699 
       
   700     /*
       
   701      Node: ./SCOMO/Download/<X>/Name
       
   702      This leaf node holds name of an application. 
       
   703      Support: Mandatory
       
   704      Occurs: One
       
   705      Format: Chr
       
   706      Access Types: Add, Get, Replace
       
   707      Values: N/A
       
   708      */
       
   709     MSmlDmDDFObject& downame = dowdyna.AddChildObjectL(KAMNameNodeName);
       
   710     FillNodeInfoL(downame, accessTypesGetAddReplace,
       
   711             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   712             MSmlDmDDFObject::EChr, KAMNameNodeDescription);
       
   713 
       
   714     
       
   715     /*
       
   716      Node: ./SCOMO/Download/<X>/PkgURL
       
   717      This leaf node holds the URL from which the application should be downloaded.
       
   718      Support: Mandatory 
       
   719      Occurs: One
       
   720      Format: Chr
       
   721      Access Types: Add, Get, Replace
       
   722      Values: N/A
       
   723      */
       
   724     MSmlDmDDFObject& dowuri = dowdyna.AddChildObjectL(KAMURINodeName);
       
   725     FillNodeInfoL(dowuri, accessTypesGetAddReplace,
       
   726             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   727             MSmlDmDDFObject::EChr, KAMURINodeDescription);
       
   728             
       
   729     /*
       
   730      Node: /SCOMO/Download/<X>/PkgType
       
   731      This leaf node holds an identifier for an application.
       
   732      Support: Mandatory
       
   733      Occurs: One
       
   734      Format: Chr
       
   735      Access Types: Add, Get, Replace
       
   736      Values: N/A
       
   737      */
       
   738     MSmlDmDDFObject& dowpkgtype = dowdyna.AddChildObjectL(KAMPkgTypeNodeName);
       
   739     FillNodeInfoL(dowpkgtype, accessTypesGetAddReplace, MSmlDmDDFObject::EZeroOrOne,
       
   740             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   741             KAMPkgTypeNodeDescription);
       
   742 
       
   743     /*
       
   744      Node: ./SCOMO/Download/<X>/Status
       
   745      This leaf node holds the status of the download. The client updates the node value. The values are typically error codes of download protocol. Initially after the URI leaf is filled, this will get value 100, and will be replaced by one.
       
   746      Support: Optional 
       
   747      Occurs: One
       
   748      Format: Chr
       
   749      Access Types: Get
       
   750      Values: N/A
       
   751      */
       
   752     MSmlDmDDFObject& dowstat = dowdyna.AddChildObjectL(KAMStatusNodeName);
       
   753     FillNodeInfoL(dowstat, accessTypesGet, MSmlDmDDFObject::EOne,
       
   754             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   755             KAMStatusNodeDescription);
       
   756 
       
   757     /*
       
   758      Node: ./SCOMO/Download/<X>/Description
       
   759      This leaf node holds the version of an application. 
       
   760      Support: Mandatory
       
   761      Occurs: One
       
   762      Format: Chr
       
   763      Access Types: Add, Get, Replace
       
   764      Values: N/A
       
   765      */
       
   766     MSmlDmDDFObject& dowver = dowdyna.AddChildObjectL(KAMDescriptionNodeName);
       
   767     FillNodeInfoL(dowver, accessTypesGetAddReplace,
       
   768             MSmlDmDDFObject::EZeroOrOne, MSmlDmDDFObject::EPermanent,
       
   769             MSmlDmDDFObject::EChr, KAMDescriptionNodeDescription);
       
   770     
       
   771     
       
   772     /*
       
   773      Node: ./SCOMO/Download/<X>/Operations
       
   774      This is a node that holds the operation nodes.
       
   775      Support: Optional
       
   776      Occurs: One
       
   777      Format: Node
       
   778      Access Types: Get, Replace, Add, Delete
       
   779      Values: N/A
       
   780 
       
   781      */
       
   782     MSmlDmDDFObject& dowop = dowdyna.AddChildObjectL(KAMOperationsNodeName);
       
   783     FillNodeInfoL(dowop, accessTypesGet, MSmlDmDDFObject::EOne,
       
   784             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   785             KAMOperationsNodeDescription);
       
   786 
       
   787     /*
       
   788      Node: ./SCOMO/Download/<X>/Operations/Download
       
   789      Exec command causes device to download an application. The dynamic node specifies the application to be downloaded. 
       
   790      Support: Mandatory
       
   791      Occurs: One
       
   792      Format: Node
       
   793      Access Types: Exec
       
   794      Values: N/A
       
   795      */
       
   796     MSmlDmDDFObject& dowdown =
       
   797             dowop.AddChildObjectL(KAMDownloadOperationNodeName);
       
   798     FillNodeInfoL(dowdown, accessTypesExecReplace, MSmlDmDDFObject::EOne,
       
   799             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   800             KAMDownloadOperationNodeDescription);
       
   801 
       
   802     /*
       
   803      Node: ./SCOMO/Download/<X>/Operations/DownloadInstall
       
   804      Exec command causes device to download and install an application. The dynamic node specifies the application to be downloaded. 
       
   805      Support: Mandatory
       
   806      Occurs: One
       
   807      Format: Node
       
   808      Access Types: Exec
       
   809      Values: N/A
       
   810      */
       
   811     MSmlDmDDFObject& dowdowni =
       
   812             dowop.AddChildObjectL(KAMDownloadAndInstallNodeName);
       
   813     FillNodeInfoL(dowdowni, accessTypesExec, MSmlDmDDFObject::EOne,
       
   814             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   815             KAMDownloadAndInstallOperationNodeDescription);
       
   816 
       
   817     /*
       
   818      Node: ./SCOMO/Download/<X>/Operations/DownloadInstallInactive
       
   819      Exec command causes device to download and install and activate an application. The dynamic node specifies the application to be downloaded. 
       
   820      Support: Mandatory
       
   821      Occurs: One
       
   822      Format: Node
       
   823      Access Types: Exec
       
   824      Values: N/A
       
   825      */
       
   826     MSmlDmDDFObject& dowdownia =
       
   827             dowop.AddChildObjectL(KAMDownloadAndInstallAndInActivateNodeName);
       
   828     FillNodeInfoL(dowdownia, accessTypesExec, MSmlDmDDFObject::EOne,
       
   829             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   830             KAMDownloadAndInstallAndInActivateNodeName);
       
   831 
       
   832     
       
   833 #ifdef __AM_LASTERROR_NODE
       
   834     MSmlDmDDFObject& amext = am.AddChildObjectL(KAMExtNodeName);
       
   835     FillNodeInfoL(amext, accessTypesGet, MSmlDmDDFObject::EOne,
       
   836             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode,
       
   837             KAMExtNodeDescription);
       
   838 
       
   839     MSmlDmDDFObject& amerr = amext.AddChildObjectL(KAMLastErrorNodeName);
       
   840     FillNodeInfoL(amerr, accessTypesGet, MSmlDmDDFObject::EOne,
       
   841             MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::EChr,
       
   842             KAMLastErrorDescription);
       
   843 #endif
       
   844 
       
   845     // Ignore generic alert error status if any otherwise adapter fails to load 
       
   846     
       
   847     TRAP_IGNORE(SendPendingGenericAlertL());
       
   848     if (GetAdapterValue() == KAMSCOMOAdapter)
       
   849         {
       
   850         CheckStateChangesL();
       
   851         SetAdapterValue(KAMDefaultValue);
       
   852         }
       
   853     CheckAndAddPredefinedNodeL();
       
   854     RDEBUG( "CSCOMOAdapter::DDFStructureL(): end" );
       
   855     }
       
   856 
       
   857 void CSCOMOAdapter::SendPendingGenericAlertL()
       
   858     {
       
   859 
       
   860     // get information of the remote DM server
       
   861     TSmlProfileId profId = 0;
       
   862     HBufC8* serverId= NULL;
       
   863     TBuf8<KMaxSizeString> scomometatype;
       
   864     TBuf8<KMaxSizeString> scomometaformat;
       
   865     TBuf8<KMaxSizeString> scomomark;
       
   866 
       
   867     TBuf8<512> targetURIGet;
       
   868 
       
   869     TUint32 internalid = KErrNone;
       
   870     TInt finalresult = KErrNone;
       
   871     TInt i =0;
       
   872 
       
   873     // Get all the generic alert parameters from cenrep
       
   874     // to construct generic alert message
       
   875     CRepository *repository=CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys );
       
   876     repository->Get(KSCOMOMetaTypeKey,scomometatype);
       
   877     repository->Get(KSCOMOMetaFormatKey,scomometaformat);
       
   878     repository->Get(KSCOMOMark,scomomark);
       
   879     CleanupStack::PopAndDestroy();
       
   880     
       
   881     // Retrive server info of current DM Session
       
   882 
       
   883     GetServerInfoL(profId, serverId);
       
   884     CleanupStack::PushL(serverId);
       
   885 
       
   886     RPointerArray<CAMDbItem> genericalerts;
       
   887     
       
   888 
       
   889     // Get generic alert entry from Database for particular server ID.
       
   890     TRAPD(err, iAMdb->GetEntryForServerIDL(genericalerts, *serverId));
       
   891     
       
   892     
       
   893     // Send Pending generic alerts for server
       
   894     
       
   895     for(i=0; i<genericalerts.Count(); i++)
       
   896     {
       
   897     	
       
   898     if (genericalerts.Count()!= 0 && err == KErrNone)
       
   899         {  
       
   900 
       
   901 	
       
   902        
       
   903             internalid = genericalerts[i]->iLUID;
       
   904            
       
   905             // Get Target URI and Final Generic Alert result from App. Mgmt. Server 
       
   906             // database.
       
   907 
       
   908             TRAPD(err, SessionL().GetFinalResultsForGAL(internalid, finalresult,
       
   909                     targetURIGet));
       
   910                     
       
   911             // If data in SCOMO DB is inconsistent with AM Server DB or
       
   912             // if it exceeds retry count then delete that entry from adapter
       
   913             // and server database
       
   914             
       
   915             if(finalresult <= KErrNone || err!=KErrNone)
       
   916             {
       
   917             	iAMdb->DeleteFromDatabaseL(internalid);
       
   918             	User::Leave(KErrGeneral);
       
   919             }
       
   920 	         
       
   921             
       
   922             TBuf8<6> dataresult;
       
   923             dataresult.Num(finalresult);
       
   924             
       
   925             TPtrC8 mapping(NSmlDmURI::LastURISeg(targetURIGet) );
       
   926             
       
   927             
       
   928             TInt retryupdate = iAMdb->GetRetryCountForLuidL(internalid);
       
   929             
       
   930             // If retryupdate in Zero then delete its entry from 
       
   931             // database.
       
   932             
       
   933             if(retryupdate == KErrNone)
       
   934             {
       
   935             iAMdb->DeleteFromDatabaseL(internalid);
       
   936             SessionL().GenericAlertSentL(internalid);
       
   937             User::Leave(KErrCompletion);	
       
   938             }
       
   939             
       
   940             // Decrement the retry count and update in database for
       
   941             // that internalid.
       
   942             iAMdb->UpdateRetryCountForLuidL(internalid, --retryupdate);    
       
   943             
       
   944             
       
   945 
       
   946             // open handle to private api
       
   947 
       
   948             RNSmlPrivateAPI privateAPI;
       
   949             privateAPI.OpenL();
       
   950             CleanupClosePushL(privateAPI);
       
   951             
       
   952             RArray<CNSmlDMAlertItem> iItemArray;
       
   953             
       
   954 
       
   955     		CNSmlDMAlertItem* item = new (ELeave) CNSmlDMAlertItem ;
       
   956     		
       
   957     		HBufC8 *data = HBufC8::NewL(1024);
       
   958             
       
   959             TPtr8 ptr = data->Des();
       
   960             ptr.Append(KDataStart);
       
   961             ptr.Append(KResultCodeStart);
       
   962             ptr.Append(dataresult);
       
   963             ptr.Append(KResultCodeEnd);
       
   964             ptr.Append(KIdentifierStart);
       
   965             ptr.Append(mapping);
       
   966             ptr.Append(KIdentifierEnd);
       
   967             ptr.Append(KDataEnd);
       
   968 
       
   969             HBufC8 *sourceuri = genericalerts[i]->iSourceURI;
       
   970     		
       
   971     		item->iSource = sourceuri;
       
   972 
       
   973 			HBufC8 *targeturi = targetURIGet.AllocL();
       
   974     		
       
   975     		item->iTarget = targeturi;
       
   976     		
       
   977     		HBufC8 *metatype = scomometatype.AllocL();
       
   978     		            
       
   979     		item->iMetaType = metatype;
       
   980     		            
       
   981     		HBufC8 *metaformat = scomometaformat.AllocL();         
       
   982 
       
   983     		item->iMetaFormat = metaformat;
       
   984 
       
   985     		HBufC8 *metamark = scomomark.AllocL();
       
   986     		            
       
   987     		item->iMetaMark = metamark;
       
   988     
       
   989     		item->iData = data;
       
   990     
       
   991     		iItemArray.AppendL(*item);
       
   992             
       
   993             TRAP_IGNORE(privateAPI.AddDMGenericAlertRequestL(              
       
   994                     *genericalerts[i]->iCorrelator,iItemArray ));
       
   995                     
       
   996                     
       
   997             delete data;
       
   998             
       
   999             delete metamark;
       
  1000             
       
  1001             delete metaformat;
       
  1002             
       
  1003             delete metatype;
       
  1004             
       
  1005             delete targeturi;
       
  1006             delete item;
       
  1007                     
       
  1008             iItemArray.Reset();			
       
  1009 			iItemArray.Close();
       
  1010             CleanupStack::PopAndDestroy( &privateAPI);
       
  1011             }
       
  1012         }
       
  1013     genericalerts.ResetAndDestroy();
       
  1014     CleanupStack::PopAndDestroy(); //serverid
       
  1015 
       
  1016 
       
  1017     }
       
  1018 
       
  1019 // ------------------------------------------------------------------------------------------------
       
  1020 // CSCOMOAdapter::SessionL()
       
  1021 // ------------------------------------------------------------------------------------------------
       
  1022 RApplicationManagement &CSCOMOAdapter::SessionL()
       
  1023     {
       
  1024     if ( !iSessionOpened)
       
  1025         {
       
  1026         TCertInfo info;
       
  1027 
       
  1028         const TUid KCentralRepositoryUid =
       
  1029             {
       
  1030             0x10207843
       
  1031             };
       
  1032         const TInt KCertKey = 0x01;
       
  1033         CRepository *re= NULL;
       
  1034         TRAPD( errx, re = CRepository::NewL ( KCentralRepositoryUid ) );
       
  1035         if (errx == KErrNone && re)
       
  1036             {
       
  1037             TPckg<TCertInfo> pcert(info);
       
  1038             errx = re->Get(KCertKey, pcert) ;
       
  1039 
       
  1040             RDEBUG_2("aCertInfo.iFingerprint.Length() is  %u",info.iFingerprint.Length() );
       
  1041             if (errx == KErrNone)
       
  1042                 {
       
  1043                 RDEBUG("CSCOMOAdapter::SessionL() errx == KErrNone");
       
  1044                 }
       
  1045             else
       
  1046                 {
       
  1047                 if (errx != KErrNotFound)
       
  1048                     {
       
  1049                     RDEBUG("CSCOMOAdapter::SessionL() errx != KErrNotFound");
       
  1050                     }
       
  1051                 else
       
  1052                     {
       
  1053                     RDEBUG("CSCOMOAdapter::SessionL() errx == KErrNotFound");
       
  1054                     }
       
  1055 
       
  1056                 }
       
  1057             delete re;
       
  1058             }
       
  1059 
       
  1060         if (errx == KErrNotFound || !iCertRequired)
       
  1061             {
       
  1062             RDEBUG("CSCOMOAdapter::SessionL() calling iManagement.Connect()");
       
  1063             User::LeaveIfError(iManagement.Connect() );
       
  1064             iSessionOpened = ETrue;
       
  1065             iTrustAdded = EFalse;
       
  1066             }
       
  1067         else
       
  1068             {
       
  1069             RDEBUG("CSCOMOAdapter::SessionL() calling iManagement.Connect( info )");
       
  1070             User::LeaveIfError(iManagement.Connect(info) );
       
  1071             iSessionOpened = ETrue;
       
  1072             iTrustAdded = ETrue;
       
  1073             }
       
  1074         }
       
  1075     return iManagement;
       
  1076     }
       
  1077 
       
  1078 // ------------------------------------------------------------------------------------------------
       
  1079 //  CSCOMOAdapter::UpdateLeafObjectL()
       
  1080 // ------------------------------------------------------------------------------------------------
       
  1081 void CSCOMOAdapter::UpdateLeafObjectL(const TDesC8& aURI,
       
  1082         const TDesC8& aLUID, const TDesC8& aObject, const TDesC8& aType,
       
  1083         TInt aStatusRef)
       
  1084     {
       
  1085     RDEBUG8_4("CSCOMOAdapter::UpdateLeafObjectL(): begin, '%S', '%S' '%S'", &aURI, &aLUID, &aType );
       
  1086 
       
  1087     MSmlDmAdapter::TError status = EOk;
       
  1088     SetAdapterValue(KAMSCOMOAdapter);
       
  1089     _UpdateLeafObjectL(aURI, aLUID, aObject, aType, aStatusRef, status);
       
  1090 
       
  1091     SetStatusL(aStatusRef, status);
       
  1092     if (status == EOk)
       
  1093         {
       
  1094         if (iInAtomic)
       
  1095             {
       
  1096             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  1097             }
       
  1098         }
       
  1099     RDEBUG_2("CSCOMOAdapter::UpdateLeafObjectL(): end (%d)", status);
       
  1100     }
       
  1101 
       
  1102 // ------------------------------------------------------------------------------------------------
       
  1103 //  CSCOMOAdapter::UpdateLeafObjectL()
       
  1104 // ------------------------------------------------------------------------------------------------
       
  1105 void CSCOMOAdapter::_UpdateLeafObjectL(const TDesC8& aURI,
       
  1106         const TDesC8& aLUID, const TDesC8& aObject, const TDesC8& aType,
       
  1107         TInt /*aStatusRef*/, MSmlDmAdapter::TError& aStatus)
       
  1108     {
       
  1109     RDEBUG("CSCOMOAdapter::_UpdateLeafObjectL(): begin");
       
  1110 
       
  1111     CheckStateChangesL();
       
  1112 
       
  1113     TError status(EError);
       
  1114 
       
  1115 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  1116     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
  1117     TInt numSeqs( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  1118     TPtrC8 mapping( NSmlDmURI::LastURISeg( uriPtrc ) );
       
  1119     TPtrC8 parent( NSmlDmURI::RemoveLastSeg( uriPtrc ) );
       
  1120 #else
       
  1121     TInt numSeqs(NSmlDmURI::NumOfURISegs(aURI) );
       
  1122     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  1123     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  1124 #endif
       
  1125 
       
  1126     if (mapping == KAMNameNodeName)
       
  1127         {
       
  1128         if (aObject.Size() > KDeploymentComponentNameMaxLength)
       
  1129             {
       
  1130             aStatus = ETooLargeObject;
       
  1131             return;
       
  1132             }
       
  1133         }
       
  1134     else
       
  1135         if (mapping == KAMVersionNodeName)
       
  1136             {
       
  1137             if (aObject.Size() > KDeploymentComponentVersionMaxLength)
       
  1138                 {
       
  1139                 aStatus = ETooLargeObject;
       
  1140                 return;
       
  1141                 }
       
  1142             }
       
  1143         else
       
  1144 	if (mapping == KAMURINodeName)
       
  1145 	  {
       
  1146 	   if (aObject.Size() > KMaxUrlLength)
       
  1147                 {
       
  1148                 aStatus = ETooLargeObject;
       
  1149                 return;
       
  1150                 }
       
  1151 
       
  1152 	  }
       
  1153         else
       
  1154             if (mapping == KAMConRefNodeName)
       
  1155                 {
       
  1156                 if (aObject.Size() > KMaxConRef)
       
  1157                     {
       
  1158                     aStatus = ETooLargeObject;
       
  1159                     return;
       
  1160                     }
       
  1161                 }
       
  1162             else
       
  1163                 if (mapping == KAMDescriptionNodeName)
       
  1164                     {
       
  1165                     if (aObject.Size() > 512)
       
  1166                         {
       
  1167                         aStatus = ETooLargeObject;
       
  1168                         return;
       
  1169                         }
       
  1170                     }
       
  1171             else
       
  1172                if(mapping == KAMPkgIDNodeName)
       
  1173                {
       
  1174                if(aObject.Size() > 256)
       
  1175                {
       
  1176                	aStatus = ETooLargeObject;
       
  1177                         return;
       
  1178                }
       
  1179                }
       
  1180             else
       
  1181               if(mapping == KAMPkgTypeNodeName)
       
  1182               {
       
  1183                 // ADD check for PkgType MIME Type if not supported 
       
  1184                 // error status should be sent and operation should stop
       
  1185                 
       
  1186               	if(aObject.Size() >100)
       
  1187               	{
       
  1188               		aStatus = ETooLargeObject;
       
  1189                         return;
       
  1190               	}
       
  1191               }
       
  1192              
       
  1193 
       
  1194     TPtrC8 grandParent(NSmlDmURI::RemoveLastSeg(parent) );
       
  1195     TPtrC8 grandParentMapping(NSmlDmURI::LastURISeg(grandParent) );
       
  1196     RApplicationManagement &session = SessionL();
       
  1197     TDeploymentComponentState state(EDCSNone);
       
  1198     if (numSeqs == 4 || numSeqs == 5)
       
  1199         {
       
  1200         if (numSeqs == 4)
       
  1201             {
       
  1202             state = EDCSDownload;
       
  1203             }
       
  1204         else
       
  1205             {
       
  1206             if (grandParentMapping == KAMDeliveredNodeName)
       
  1207                 {
       
  1208                 state = EDCSDelivered;
       
  1209                 }
       
  1210             else
       
  1211                 if (grandParentMapping == KAMDeployedNodeName)
       
  1212                     {
       
  1213                     state = EDCSActive;
       
  1214                     }
       
  1215                 else
       
  1216                     {
       
  1217                     RDEBUG8_3( "CSCOMOAdapter::UpdateLeafObjectL(): ILLEGAL LEVEL %d NODE %S", numSeqs, &aURI );
       
  1218                     User::Leave(KErrArgument);
       
  1219                     }
       
  1220             }
       
  1221         }
       
  1222     else
       
  1223         {
       
  1224         RDEBUG8_3("CSCOMOAdapter::UpdateLeafObjectL(): ILLEGAL LEVEL %d NODE %S", numSeqs, &aURI );
       
  1225         }
       
  1226     if (state == EDCSDelivered || state == EDCSDownload ||state == EDCSActive
       
  1227             ||state == EDCSInactive)
       
  1228         {
       
  1229         if (aLUID != KNullDesC8)
       
  1230             {
       
  1231             TInt iluid(DesToIntL(aLUID) );
       
  1232             TDeploymentComponent comp;
       
  1233             TInt err(session.DeploymentComponent(iluid, comp) );
       
  1234             if (err == KErrNone)
       
  1235                 {
       
  1236                 
       
  1237                 // Set default component install options for particular iluid.
       
  1238                 TPtrC8 obj;
       
  1239                 TAMInstallOptions opts; 
       
  1240                 TAMInstallOptionsPckg optsb(opts);
       
  1241                 
       
  1242                 TBuf<KMaxSizeString> drive;
       
  1243                 
       
  1244                 CRepository *rep = CRepository::NewLC(KCRUidPrivateApplicationManagementKeys );
       
  1245                 rep->Get(KDefaultDriveForInstall,drive);
       
  1246                 CleanupStack::PopAndDestroy();
       
  1247                 
       
  1248                 //TChar KDefaultDrive = 'c';
       
  1249                 TChar KDefaultDrive = drive[0]; 
       
  1250                 
       
  1251 	 			opts.iOptions.iUpgrade = SwiUI::EPolicyAllowed;
       
  1252      			opts.iOptions.iOptionalItems = SwiUI::EPolicyAllowed;
       
  1253      			opts.iOptions.iOCSP = SwiUI::EPolicyAllowed;
       
  1254      			opts.iOptions.iIgnoreOCSPWarnings = SwiUI::EPolicyAllowed;
       
  1255 					
       
  1256      			opts.iOptions.iUntrusted = SwiUI::EPolicyAllowed;
       
  1257      			opts.iOptions.iPackageInfo = SwiUI::EPolicyAllowed;
       
  1258      			opts.iOptions.iCapabilities = SwiUI::EPolicyAllowed;
       
  1259      			opts.iOptions.iKillApp = SwiUI::EPolicyAllowed;
       
  1260      			opts.iOptions.iOverwrite = SwiUI::EPolicyAllowed;
       
  1261      			opts.iOptions.iDownload = SwiUI::EPolicyAllowed;
       
  1262      			opts.iOptions.iDrive = KDefaultDrive;
       
  1263      			opts.iOptions.iLang = ELangNone;
       
  1264      			opts.iOptions.iUsePhoneLang = EFalse ;
       
  1265      			
       
  1266      			obj.Set(optsb);
       
  1267                 
       
  1268                 TRAP_IGNORE( session.UpdateDeploymentComponentL( iluid, EDCInstallOptions, obj ) );
       
  1269                 
       
  1270                 
       
  1271                 TDeplCompAttrType fl(UpdateFlagFromMapping(mapping) );
       
  1272 
       
  1273                            
       
  1274                 if (mapping == KAMDataNodeName || mapping
       
  1275                         == KAMDescriptorNodeName)
       
  1276                     {
       
  1277                     TInt erx(KErrNone);
       
  1278                     if ((mapping == KAMDataNodeName) &&(RecognizeMimeType(aType)== EFalse))
       
  1279                         {
       
  1280                         User::Leave(EInvalidObject);
       
  1281                         }
       
  1282                     if (iIsStreamedContent)
       
  1283                         {
       
  1284                         CloseStreaming();
       
  1285                         TRAP( erx, session.UpdateDeploymentComponentStreamedDataL( iluid, fl, aType ) );
       
  1286                         }
       
  1287                     else
       
  1288                         {
       
  1289                         // 
       
  1290                         TRAP( erx, session.UpdateDeploymentComponentDataL( iluid, fl, aObject, aType ) );
       
  1291                         }
       
  1292                     MAPERROR( erx, status, _L8("Update Delivered Data or metadata %d") );
       
  1293                     }
       
  1294                 else
       
  1295                     {
       
  1296                     if (fl != EDCNone)
       
  1297                         {
       
  1298                         TPtrC8 obj;
       
  1299                         TAMInstallOptions opts;
       
  1300                         TAMInstallOptionsPckg optsb(opts);
       
  1301                         TPckgBuf<TInt> iap;
       
  1302                         if (fl == EDCInstallOptions)
       
  1303                             {
       
  1304                             }
       
  1305                         else
       
  1306                             if (fl == EDCConRef)
       
  1307                                 {
       
  1308 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  1309 
       
  1310                                 //CNSmlDMIAPMatcher* iapfinder = CNSmlDMIAPMatcher::NewLC( &Callback() );
       
  1311                                 //TInt i( iapfinder->IAPIdFromURIL( aObject ) );
       
  1312                                 //CleanupStack::PopAndDestroy( iapfinder );
       
  1313                                 //iap() = i;
       
  1314                                 CArrayFix<TSmlDmMappingInfo>* mapArray = new CArrayFixFlat<TSmlDmMappingInfo>(4);
       
  1315                                 CleanupStack::PushL(mapArray);
       
  1316 
       
  1317                                 Callback().GetMappingInfoListL( KNSmlDMMMSSlashIAPUri,*mapArray );
       
  1318 
       
  1319                                 TInt iapValue = KErrNotFound;
       
  1320                                 TSmlDmMappingInfo mapInfo;
       
  1321 
       
  1322                                 for(TInt i = 0;i<mapArray->Count();i++)
       
  1323                                     {
       
  1324                                     if(LastURISeg(opts.iConRef)==mapArray->At(i).iURISeg)
       
  1325                                         {
       
  1326                                         iapValue=DesToInt(mapArray->At(i).iURISegLUID);
       
  1327                                         break;
       
  1328                                         }
       
  1329                                     }
       
  1330                                 iap() = iapValue;
       
  1331                                 mapArray->Reset();
       
  1332                                 CleanupStack::PopAndDestroy(); //mapArray
       
  1333 
       
  1334 #else
       
  1335                                 CNSmlDMIAPMatcher
       
  1336                                         * iapfinder =
       
  1337                                                 CNSmlDMIAPMatcher::NewLC( &Callback() );
       
  1338                                 TInt i(iapfinder->IAPIdFromURIL(aObject) );
       
  1339                                 CleanupStack::PopAndDestroy(iapfinder);
       
  1340                                 iap() = i;
       
  1341 #endif
       
  1342                                 obj.Set(iap);
       
  1343                                 }
       
  1344                             else
       
  1345                                 {
       
  1346                                 obj.Set(aObject);
       
  1347                                 }
       
  1348                         TRAPD( erx, session.UpdateDeploymentComponentL( iluid, fl, obj ) )
       
  1349                         ;
       
  1350                         MAPERROR( erx, status, _L8("Update some attribute %d") );
       
  1351                         }
       
  1352                     else
       
  1353                         {
       
  1354                         status = ENotFound;
       
  1355                         RDEBUG( "CSCOMOAdapter::UpdateLeafObjectL(): Unknown Target leaf" );
       
  1356                         }
       
  1357                     }
       
  1358                 }
       
  1359             else
       
  1360                 {
       
  1361                 RDEBUG_3( "CSCOMOAdapter::UpdateLeafObjectL(): FAILED TO GET COMPONENT OF ID %d: %d" , iluid, err );
       
  1362                 status = ENotFound;
       
  1363                 }
       
  1364             }
       
  1365         else
       
  1366             {
       
  1367             RDEBUG8_2( "CSCOMOAdapter::UpdateLeafObjectL(): Faild to get luid allocation and find buffered for '%S'", &parent );
       
  1368             status = ENotFound;
       
  1369             }
       
  1370         }
       
  1371     else
       
  1372         {
       
  1373         RDEBUG8_2( "CSCOMOAdapter::UpdateLeafObjectL(): WARNING Tried to update illegal state leaf! '%S'", &grandParentMapping );
       
  1374         }
       
  1375 
       
  1376     aStatus = status;
       
  1377 
       
  1378     RDEBUG("CSCOMOAdapter::_UpdateLeafObjectL(): end");
       
  1379     }
       
  1380 
       
  1381 // ------------------------------------------------------------------------------------------------
       
  1382 // CSCOMOAdapter::UpdateLeafObjectL
       
  1383 // ------------------------------------------------------------------------------------------------
       
  1384 void CSCOMOAdapter::UpdateLeafObjectL(const TDesC8& aURI,
       
  1385         const TDesC8& aLUID, RWriteStream*& aStream, const TDesC8& aType,
       
  1386         TInt aStatusRef)
       
  1387     {
       
  1388     RDEBUG8_4("CSCOMOAdapter::UpdateLeafObjectL() aStream: begin, '%S', '%S' '%S'", &aURI, &aLUID, &aType );
       
  1389 
       
  1390     TError status(CSmlDmAdapter::EOk);
       
  1391 
       
  1392     if (iStreamedURI)
       
  1393         {
       
  1394         delete iStreamedURI;
       
  1395         iStreamedURI = NULL;
       
  1396         }
       
  1397     iStreamedURI = aURI.AllocL();
       
  1398 
       
  1399     if (iStreamedLuid)
       
  1400         {
       
  1401         delete iStreamedLuid;
       
  1402         iStreamedLuid = NULL;
       
  1403         }
       
  1404     iStreamedLuid = aLUID.AllocL();
       
  1405 
       
  1406     if (iStreamedType)
       
  1407         {
       
  1408         delete iStreamedType;
       
  1409         iStreamedType = NULL;
       
  1410         }
       
  1411     iStreamedType = aType.AllocL();
       
  1412 
       
  1413     if (!iStreamOpen)
       
  1414         {
       
  1415         RApplicationManagement &session = SessionL();
       
  1416         TDeplCompAttrType attrType;
       
  1417         TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  1418         TDeplCompAttrType fl(UpdateFlagFromMapping(mapping) );
       
  1419         if (mapping == KAMDataNodeName)
       
  1420             {
       
  1421             attrType = EDCData;
       
  1422             }
       
  1423         else
       
  1424             if (mapping == KAMDescriptorNodeName)
       
  1425                 {
       
  1426                 attrType = EDCMetaData;
       
  1427                 }
       
  1428             else
       
  1429                 {
       
  1430                 RDEBUG8_2("CSCOMOAdapter::UpdateLeafObjectL(): Unknown mapping: (%S)", &mapping);
       
  1431                 status = CSmlDmAdapter::EError;
       
  1432                 }
       
  1433 
       
  1434         if (status == CSmlDmAdapter::EOk)
       
  1435             {
       
  1436             TInt iluid(DesToIntL(aLUID) );
       
  1437             session.DeploymentComponentTempInstFileL(iluid, iStreamFile,
       
  1438                     attrType);
       
  1439             iStream.Attach(iStreamFile);
       
  1440             aStream = &iStream;
       
  1441             iStreamOpen = ETrue;
       
  1442             iIsStreamedContent = ETrue;
       
  1443             }
       
  1444         }
       
  1445     if ( !iInAtomic)
       
  1446         {
       
  1447         iStatusRef = aStatusRef;
       
  1448         Callback().SetStatusL(aStatusRef, status);
       
  1449         }
       
  1450     else
       
  1451         {
       
  1452         iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  1453         }
       
  1454 
       
  1455     RDEBUG("CSCOMOAdapter::UpdateLeafObjectL() aStream : end");
       
  1456     }
       
  1457 
       
  1458 // ------------------------------------------------------------------------------------------------
       
  1459 // CSCOMOAdapter::UpdateFlagFromMapping( const TDesC8& aMapping )
       
  1460 // ------------------------------------------------------------------------------------------------
       
  1461 TDeplCompAttrType CSCOMOAdapter::UpdateFlagFromMapping(const TDesC8& aMapping)
       
  1462     {
       
  1463 
       
  1464     TDeplCompAttrType res;
       
  1465     if (aMapping == KAMIDNodeName)
       
  1466         {
       
  1467         res = EDCId;
       
  1468         }
       
  1469     else
       
  1470         if (aMapping == KAMNameNodeName)
       
  1471             {
       
  1472             res = EDCName;
       
  1473             }
       
  1474         else
       
  1475             if (aMapping == KAMVersionNodeName)
       
  1476                 {
       
  1477                 res = EDCVersion;
       
  1478                 }
       
  1479             else
       
  1480                 if (aMapping == KAMStateValueNodeName)
       
  1481                     {
       
  1482                     res = EDCStateValue;
       
  1483                     }
       
  1484                 else
       
  1485                     if (aMapping == KAMInstallOptsNodeName)
       
  1486                         {
       
  1487                         res = EDCInstallOptions;
       
  1488                         }
       
  1489                     else
       
  1490                         if (aMapping == KAMDescriptorNodeName)
       
  1491                             {
       
  1492                             res = EDCMetaData;
       
  1493                             }
       
  1494                         else
       
  1495                             if (aMapping == KAMDataNodeName)
       
  1496                                 {
       
  1497                                 res = EDCData;
       
  1498                                 }
       
  1499                             else
       
  1500                                 if (aMapping == KAMURINodeName)
       
  1501                                     {
       
  1502                                     res = EDCDownloadURI;
       
  1503                                     }
       
  1504                                 else
       
  1505                                     if (aMapping == KAMStatusNodeName)
       
  1506                                         {
       
  1507                                          res = EDCStatus;
       
  1508                                         }
       
  1509                                     else
       
  1510                                         if (aMapping == KAMConRefNodeName)
       
  1511                                             {
       
  1512                                             res = EDCConRef;
       
  1513                                             }
       
  1514                                         else
       
  1515                                             if (aMapping
       
  1516                                                     == KAMDescriptionNodeName)
       
  1517                                                 {
       
  1518                                                 res = EDCDescriptionRef;
       
  1519                                                 }
       
  1520                                               else
       
  1521                                                 if(aMapping == KAMPkgIDNodeName)
       
  1522                                                 {
       
  1523                                                 	res = EDCPkgID;
       
  1524                                                 }
       
  1525                                                 else
       
  1526                                                 if(aMapping == KAMPkgTypeNodeName)
       
  1527                                                 {
       
  1528                                                 	res = EDCPkgType;
       
  1529                                                 }
       
  1530                                                 
       
  1531 
       
  1532                                             else
       
  1533                                                 {
       
  1534                                                 //User::Leave( KErrArgument );
       
  1535                                                 res = EDCNone;
       
  1536                                                 }
       
  1537     return res;
       
  1538     }
       
  1539 
       
  1540 // ------------------------------------------------------------------------------------------------
       
  1541 // CSCOMOAdapter::GetLuidForUserIdL( const TDesC8 &aUserId, 
       
  1542 //		const TDeploymentComponentState aState )
       
  1543 // ------------------------------------------------------------------------------------------------	
       
  1544 TUint32 CSCOMOAdapter::GetLuidForUserIdL(const TDesC8 &aUserId,
       
  1545         const TDeploymentComponentState aState)
       
  1546     {
       
  1547     TUint32 ret( 0);
       
  1548     if (aState != EDCSNone)
       
  1549         {
       
  1550         RElementIdArray array;
       
  1551         TInt err(SessionL().DeploymentComponentIdsL(array, aState) );
       
  1552         if (err == KErrNone)
       
  1553             {
       
  1554             CleanupClosePushL(array);
       
  1555             TInt count(array.Count() );
       
  1556             for (TInt i( 0); i < count && ret == 0; i++)
       
  1557                 {
       
  1558                 TUint32 el = array[i];
       
  1559                 TDCUserId dc;
       
  1560                 SessionL().DeploymentComponentUserIdL(el, dc);
       
  1561                 if (dc == aUserId)
       
  1562                     {
       
  1563                     ret = el;
       
  1564                     }
       
  1565                 }
       
  1566             CleanupStack::PopAndDestroy( &array);
       
  1567             }
       
  1568         else
       
  1569             {
       
  1570             }
       
  1571         }
       
  1572     return ret;
       
  1573     }
       
  1574 
       
  1575 // ------------------------------------------------------------------------------------------------
       
  1576 // CSCOMOAdapter::GetLuid2L( const TDesC8 &aDMLuid, const TDesC8 &aUserId, 
       
  1577 //		const TDeploymentComponentState aState, TError &aStatus )
       
  1578 // ------------------------------------------------------------------------------------------------	
       
  1579 TUint32 CSCOMOAdapter::GetLuid2L(const TDesC8 &aDMLuid,
       
  1580         const TDesC8 &aUserId, const TDeploymentComponentState aState,
       
  1581         TError &aStatus)
       
  1582     {
       
  1583     TUint32 ret(GetLuidL(aDMLuid, aUserId, aState) );
       
  1584     if ( (TInt32)ret <= 0)
       
  1585         {
       
  1586         aStatus = ENotFound;
       
  1587         }
       
  1588     return ret;
       
  1589     }
       
  1590 
       
  1591 // ------------------------------------------------------------------------------------------------
       
  1592 // CSCOMOAdapter::GetLuidL( const TDesC8 &aDMLuid, const TDesC8 &aUserId, 
       
  1593 //		const TDeploymentComponentState aState )
       
  1594 // ------------------------------------------------------------------------------------------------	
       
  1595 TUint32 CSCOMOAdapter::GetLuidL(const TDesC8 &aDMLuid, const TDesC8 &aUserId,
       
  1596         const TDeploymentComponentState aState)
       
  1597     {
       
  1598     TUint32 ret( 0);
       
  1599     if (aDMLuid == KNullDesC8)
       
  1600         {
       
  1601         ret = GetLuidForUserIdL(aUserId, aState);
       
  1602         }
       
  1603     else
       
  1604         {
       
  1605         ret = DesToIntL(aDMLuid) ;
       
  1606         }
       
  1607 
       
  1608     return ret;
       
  1609     }
       
  1610 
       
  1611 // ------------------------------------------------------------------------------------------------
       
  1612 // CSCOMOAdapter::DeleteObjectL( const TDesC8& aURI, const TDesC8& aLUID )
       
  1613 // ------------------------------------------------------------------------------------------------
       
  1614 void CSCOMOAdapter::DeleteObjectL(const TDesC8& aURI, const TDesC8& aLUID,
       
  1615         const TInt aStatusRef)
       
  1616     {
       
  1617 
       
  1618     RDEBUG8_4("CSCOMOAdapter::DeleteObjectL(): begin (%S, %S, %d)" , &aURI, &aLUID, aStatusRef );
       
  1619     SetAdapterValue(KAMSCOMOAdapter);
       
  1620     CheckStateChangesL();
       
  1621 
       
  1622     TError ret(EError);
       
  1623 
       
  1624 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
  1625     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  1626     TInt cnt( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  1627     TPtrC8 mapping( NSmlDmURI::LastURISeg( uriPtrc ) );
       
  1628 #else
       
  1629     TInt cnt(NSmlDmURI::NumOfURISegs(aURI) );
       
  1630     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  1631 #endif
       
  1632 	
       
  1633 	TBuf8<KMaxFullName> temp;
       
  1634 	GetPredefinedNodeL(temp);
       
  1635 	TInt comp = mapping.Compare( temp );
       
  1636 		if (temp.Length() && mapping.Compare( temp ) == 0)
       
  1637             {
       
  1638             MSmlDmAdapter::TError status = MSmlDmAdapter::ENotAllowed;
       
  1639             Callback().SetStatusL( aStatusRef, status );
       
  1640             return;
       
  1641             }
       
  1642     switch (cnt)
       
  1643         {
       
  1644         case 3:
       
  1645         case 4:
       
  1646             {
       
  1647 
       
  1648 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  1649             TPtrC8 which( NSmlDmURI::URISeg( uriPtrc, cnt == 4 ? 3 : 2 ) );
       
  1650 #else
       
  1651             TPtrC8 which(NSmlDmURI::URISeg(aURI, cnt == 4 ? 3 : 2) );
       
  1652 #endif
       
  1653             if (which == KAMDeliveredNodeName || which == KAMDownloadNodeName)
       
  1654                 {
       
  1655                 TUint32 luid(GetLuidL(aLUID, mapping, (which
       
  1656                         == KAMDeliveredNodeName
       
  1657                                                 ? EDCSDelivered
       
  1658                                                    : EDCSDownload)) );
       
  1659                 if (luid > 0)
       
  1660                     {
       
  1661                     TRAPD( err, SessionL().RemoveL( luid ) )
       
  1662                     ;
       
  1663                     if (err == KErrNone || err == KErrNotFound)
       
  1664                         {
       
  1665                         ret = EOk;
       
  1666                         Callback().SetMappingL(aURI, KNullDesC8);
       
  1667                         if (err == KErrNone && iInAtomic)
       
  1668                             {
       
  1669                             iBuffer.Append(TAMCommandBufferElement(
       
  1670                                     aStatusRef, aURI) );
       
  1671                             }
       
  1672                         }
       
  1673                     else
       
  1674                         {
       
  1675                         MAPERROR( err, ret, _L8("Delete %d") );
       
  1676                         }
       
  1677                     }
       
  1678                 else
       
  1679                     {
       
  1680                     RDEBUG( "CSCOMOAdapter::DeleteObjectL(): WARNING Object not found" );
       
  1681                     ret = ENotFound;
       
  1682                     }
       
  1683                 }
       
  1684             else
       
  1685                 {
       
  1686                 RDEBUG8_2( "CSCOMOAdapter::DeleteObjectL(): ERROR Removing node %S is not supported", &aURI );
       
  1687                 }
       
  1688             break;
       
  1689             }
       
  1690         default:
       
  1691             {
       
  1692             RDEBUG8_3( "CSCOMOAdapter::DeleteObjectL(): ILLEGAL LEVEL %d NODE %S", cnt, &aURI );
       
  1693             break;
       
  1694             }
       
  1695         }
       
  1696     SetStatusL(aStatusRef, ret);
       
  1697     RDEBUG( "CSCOMOAdapter::DeleteObjectL(): end" );
       
  1698     }
       
  1699 
       
  1700 // ------------------------------------------------------------------------------------------------
       
  1701 // CSCOMOAdapter::DeactivateIfInactive( const TUint aLuidi, const TDeploymentComponentState aTargetState )
       
  1702 // ------------------------------------------------------------------------------------------------
       
  1703 void CSCOMOAdapter::DeactivateIfInactive(const TUint aLuidi,
       
  1704         const TDeploymentComponentState aTargetState)
       
  1705     {
       
  1706     if (aTargetState == EDCSInactive)
       
  1707         {
       
  1708         RDEBUG( "CSCOMOAdapter::DeactivateIfInactive():  deactivating!" );
       
  1709         TRAPD( derr, iManagement.DeactivateL( aLuidi ) )
       
  1710         ;
       
  1711         if (derr != KErrNone)
       
  1712             {
       
  1713             RDEBUG_2("CSCOMOAdapter::DeactivateIfInactive(): ERROR deactivating failed %d", derr );
       
  1714             }
       
  1715         }
       
  1716     }
       
  1717 
       
  1718 void CSCOMOAdapter::InstallL(TUint aLuidi, const TDesC8& aURI,
       
  1719         const TDesC8& aLUID, const TDeploymentComponentState aTargetState,
       
  1720         TError &aRet)
       
  1721     {
       
  1722 
       
  1723 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
  1724     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  1725 #else
       
  1726     //nothing
       
  1727 #endif
       
  1728 
       
  1729     TRAPD( err, SessionL().InstallL( aLuidi, aTargetState ) )
       
  1730     ;
       
  1731     if (err == KErrNone)
       
  1732         {
       
  1733         // Update the mappings in client to reflect new
       
  1734         //		position in the management tree ( Inactive or Active..)
       
  1735         RDEBUG( "CSCOMOAdapter::InstallL(): Install success!" );
       
  1736 
       
  1737         TPtrC8 aclmapping(URISegsUpTo(aURI, 4) );
       
  1738         SetMappingL(aclmapping, aTargetState, aLUID);
       
  1739         iManagement.StateChangeComplete(aLuidi);
       
  1740 
       
  1741         DeactivateIfInactive(aLuidi, aTargetState);
       
  1742         aRet = EOk;
       
  1743         }
       
  1744     else
       
  1745         {
       
  1746         RDEBUG_2( "CSCOMOAdapter::InstallL(): INSTALL FAILED '%d'" , err);
       
  1747         MAPERROR( err, aRet, _L8("Install %d") );
       
  1748         }
       
  1749     }
       
  1750 
       
  1751 // ------------------------------------------------------------------------------------------------
       
  1752 // CSCOMOAdapter::DefaultMapError( const TInt aErr, TError &aRet )
       
  1753 // ------------------------------------------------------------------------------------------------
       
  1754 void CSCOMOAdapter::DefaultMapError(const TInt aErr, TError &aRet,
       
  1755         const TDesC8&
       
  1756 #ifdef __AM_LASTERROR_NODE
       
  1757         aDes
       
  1758 #endif
       
  1759 )
       
  1760     {
       
  1761     if (aErr == KErrNone)
       
  1762         {
       
  1763         aRet = EOk;
       
  1764         }
       
  1765     else
       
  1766         if (aErr == KErrNotFound)
       
  1767             {
       
  1768             aRet = ENotFound;
       
  1769             }
       
  1770         else
       
  1771             if (aErr == KErrArgument)
       
  1772                 {
       
  1773                 aRet = EInvalidObject;
       
  1774                 }
       
  1775             else
       
  1776                 if (aErr == KErrAlreadyExists)
       
  1777                     {
       
  1778                     aRet = EAlreadyExists;
       
  1779                     }
       
  1780                 else
       
  1781                     {
       
  1782                     aRet = EError;
       
  1783                     }
       
  1784 #ifdef __AM_LASTERROR_NODE
       
  1785     TInt err = KErrNone;
       
  1786     TRAP( err, SetErrorL( aDes, aErr ) );
       
  1787 #endif
       
  1788     }
       
  1789 
       
  1790 #ifdef __AM_LASTERROR_NODE	
       
  1791 void CSCOMOAdapter::SetErrorL(const TDesC8& aDes, const TInt aErr)
       
  1792     {
       
  1793     if (aDes != KNullDesC8)
       
  1794         {
       
  1795         SetLastErrorL(aDes, aErr);
       
  1796         }
       
  1797     else
       
  1798         {
       
  1799         SetLastErrorL(KStdError, aErr);
       
  1800         }
       
  1801     }
       
  1802 #endif	
       
  1803 
       
  1804 // ------------------------------------------------------------------------------------------------
       
  1805 // CSCOMOAdapter::ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aArgument, 
       
  1806 //	const TDesC8& aType, 
       
  1807 //	TInt aStatusRef )
       
  1808 // ------------------------------------------------------------------------------------------------
       
  1809 TDownloadTarget CSCOMOAdapter::DownloadTargetL(const TDesC8& aCommand)
       
  1810     {
       
  1811     if (aCommand == KAMDownloadOperationNodeName)
       
  1812         {
       
  1813         return EDeliver;
       
  1814         }
       
  1815     else
       
  1816         if (aCommand == KAMDownloadAndInstallNodeName)
       
  1817             {
       
  1818             return EInstallAndActivate;
       
  1819             }
       
  1820         else
       
  1821             if (aCommand == KAMDownloadAndInstallAndInActivateNodeName)
       
  1822                 {
       
  1823                 return EInstall;
       
  1824                 }
       
  1825 
       
  1826     RDEBUG8_2( "CSCOMOAdapter::DownloadTargetL(): ASKED OPERATION NOT SUPPORTED Download '%S'", &aCommand );
       
  1827     User::Leave(KErrArgument);
       
  1828     // NOTE! will not ever come here! Only to get rid of compiler warning !!
       
  1829     return EDeliver;
       
  1830     }
       
  1831 
       
  1832 // ------------------------------------------------------------------------------------------------
       
  1833 // CSCOMOAdapter::ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aArgument, 
       
  1834 //	const TDesC8& aType, 
       
  1835 //	TInt aStatusRef )
       
  1836 // ------------------------------------------------------------------------------------------------
       
  1837 void CSCOMOAdapter::ExecuteCommandL(const TDesC8& aURI, const TDesC8& aLUID,
       
  1838         const TDesC8& aArgument, const TDesC8& /*aType*/, TInt aStatusRef)
       
  1839     {
       
  1840 
       
  1841 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  1842     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  1843 #else
       
  1844     //nothing
       
  1845 #endif
       
  1846 
       
  1847     RDEBUG8_3("CSCOMOAdapter::ExecuteCommandL(): begin, '%S', '%S'", &aURI, &aLUID );
       
  1848     SetAdapterValue(KAMSCOMOAdapter);
       
  1849     CheckStateChangesL();
       
  1850     TError ret(EExecUndefError);
       
  1851 
       
  1852     if (aLUID == KNullDesC8)
       
  1853         {
       
  1854         RDEBUG("CSCOMOAdapter::ExecuteCommandL(): WARNING no valid luid provided" );
       
  1855         }
       
  1856 
       
  1857 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  1858     TInt cnt( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  1859 #else
       
  1860     TInt cnt(NSmlDmURI::NumOfURISegs(aURI) );
       
  1861 #endif	
       
  1862 
       
  1863     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  1864 
       
  1865     const TInt KDownloadMappingURILoc = 3;
       
  1866     switch (cnt)
       
  1867         {
       
  1868         case 5:
       
  1869             {
       
  1870             TUint32 iluid(GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  1871                     KDownloadMappingURILoc), EDCSDownload) );
       
  1872 
       
  1873             // Track the Newly added delivered  node to make sure that this reference
       
  1874             // of delivered node is removed from Tree DB.
       
  1875             // This delivered node is removed only if Execute command is successful
       
  1876             // by either adding Install, Install& activate etc.
       
  1877             // This Fix would be applicable in case of DM 1.2. 
       
  1878 
       
  1879 
       
  1880             TPtrC8 urival(URISegsUpTo(aURI, KDownloadMappingURILoc));
       
  1881 
       
  1882             if (iUriDel)
       
  1883                 {
       
  1884                 delete iUriDel;
       
  1885                 iUriDel = NULL;
       
  1886                 }
       
  1887 
       
  1888             iUriDel = urival.AllocL();
       
  1889 
       
  1890             RDEBUG_2("CSCOMOAdapter::ExecuteCommandL(): luid is %d", iluid );
       
  1891             if (iluid > 0)
       
  1892                 {
       
  1893                 TDownloadTarget target = DownloadTargetL(mapping);
       
  1894 
       
  1895                 TRAPD( errx, SessionL().StartDownloadL( iluid, target ) );
       
  1896                 
       
  1897 
       
  1898                 //Check If Sync is supported. Default is ASyncReporting.
       
  1899                 //If ASyncSupported is 0 mean Sync reporting is supported.  
       
  1900                 TInt ASyncSupported = -1;
       
  1901 
       
  1902                 CRepository *repository=CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys );
       
  1903                 repository->Get(KAsyncEnabled,ASyncSupported);
       
  1904                 CleanupStack::PopAndDestroy();
       
  1905                     
       
  1906 				if(errx == KErrNone)
       
  1907 				{
       
  1908                 if (ASyncSupported)
       
  1909                     ASyncReportL(iluid, aArgument, target, aURI);
       
  1910                 else
       
  1911                     SyncReportL(iluid, aArgument, target, aURI, ret);
       
  1912 				}
       
  1913 
       
  1914                 if (target == EInstall || target == EInstallAndActivate)
       
  1915                     {
       
  1916                     TInt err(iDbSession.RemoveMappingInfoL(KAMAdapterImplUid,
       
  1917                             *iUriDel, iluid) );
       
  1918                     }
       
  1919                 if (errx == KErrNone)
       
  1920                     {
       
  1921                     RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): StartDownloadL Successful " );
       
  1922                     if (ASyncSupported)
       
  1923                     {
       
  1924                        
       
  1925                        ret = EAcceptedForProcessing;
       
  1926                     }
       
  1927                         
       
  1928                     
       
  1929                     }
       
  1930                 else
       
  1931                     {
       
  1932                     RDEBUG_2( "CSCOMOAdapter::ExecuteCommandL(): StartDownloadL FAILED '%d'", errx );
       
  1933                     if (errx == KErrNotFound)
       
  1934                         {
       
  1935                         ret = ENotFound;
       
  1936                         }
       
  1937                     else
       
  1938                         if (errx == KErrArgument)
       
  1939                             {
       
  1940                             ret = EExecUndefError;
       
  1941                             }
       
  1942                         else
       
  1943                             {
       
  1944                             ret = EExecUndefError;
       
  1945                             }
       
  1946                     }
       
  1947 
       
  1948                 }
       
  1949             else
       
  1950                 {
       
  1951                 ret = EExecUndefError;
       
  1952                 RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 5 Not found node" );
       
  1953                 }
       
  1954             break;
       
  1955             }
       
  1956         case 6:
       
  1957             {
       
  1958             const TInt KInventoryMappingURILoc = 4;
       
  1959 
       
  1960             // Track the Newly added delivered  node to make sure that this reference
       
  1961             // of delivered node is removed from Tree DB.
       
  1962             // This delivered node is removed only if Execute command is successful
       
  1963             // by either adding Install, Install& activate etc.
       
  1964             // This Fix would be applicable in case of DM 1.2. 
       
  1965 
       
  1966 
       
  1967             TPtrC8 urival(URISegsUpTo(aURI, KInventoryMappingURILoc));
       
  1968 
       
  1969             if (iUriDel)
       
  1970                 {
       
  1971                 delete iUriDel;
       
  1972                 iUriDel = NULL;
       
  1973                 }
       
  1974 
       
  1975             iUriDel = urival.AllocL();
       
  1976 
       
  1977             if (mapping == KAMInstallNodeName || mapping
       
  1978                     == KAMInstallInactiveNodeName)
       
  1979                 {
       
  1980                 TUint32 iluid(GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  1981                         KInventoryMappingURILoc), EDCSDelivered) );
       
  1982                 if (iluid > 0)
       
  1983                     {
       
  1984                     TDeploymentComponentState targetstate = ((mapping
       
  1985                             == KAMInstallNodeName)
       
  1986                                                    ? EDCSActive
       
  1987                                                       : EDCSInactive);
       
  1988                     InstallL(iluid, aURI, aLUID, targetstate, ret);
       
  1989 
       
  1990                     TInt err(iDbSession.RemoveMappingInfoL(KAMAdapterImplUid,
       
  1991                             *iUriDel, iluid) );
       
  1992                     }
       
  1993                 else
       
  1994                     {
       
  1995                     ret = EExecInstallFailed;
       
  1996                     RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 6 install Not found node" );
       
  1997                     }
       
  1998                 }
       
  1999             else
       
  2000                 if (mapping == KAMRemoveNodeName)
       
  2001                     {
       
  2002                     TPtrC8 parent( NSmlDmURI::RemoveLastSeg( urival ) );
       
  2003                     TPtrC8 ParentMapping( NSmlDmURI::LastURISeg( parent ) );
       
  2004                     TUint32 iluid(0);
       
  2005                     if ( ParentMapping == KAMDeliveredNodeName )
       
  2006                         {
       
  2007                         iluid = GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  2008                                                     KInventoryMappingURILoc), EDCSDelivered) ;
       
  2009                         }
       
  2010                     
       
  2011                     else if ( ParentMapping == KAMDeployedNodeName)
       
  2012                         {
       
  2013                         iluid = GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  2014                                 KInventoryMappingURILoc), EDCSActive) ;
       
  2015                         if ( (TInt32)iluid <= 0)
       
  2016                             {
       
  2017                             iluid = GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  2018                                     KInventoryMappingURILoc), EDCSInactive) ;
       
  2019                             }
       
  2020                         }
       
  2021                     if (iluid > 0)
       
  2022                         {
       
  2023                         TRAPD( err, SessionL().RemoveL( iluid ) )
       
  2024                         ;
       
  2025                         if (err == KErrNone)
       
  2026                             {
       
  2027                             RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): Remove success!" );
       
  2028                             TPtrC8 aclmapping(URISegsUpTo(aURI, 4) );
       
  2029 
       
  2030                             // "Nullify" the mapping for argument
       
  2031                            err = iDbSession.RemoveMappingInfoL(KAMAdapterImplUid, aclmapping);
       
  2032                             if (err == KErrNone)
       
  2033                                 {
       
  2034                                 ret = EExecSuccess;
       
  2035                                 }
       
  2036                             if (iInAtomic)
       
  2037                                 {
       
  2038                                 iBuffer.Append(TAMCommandBufferElement(
       
  2039                                         aStatusRef, aURI) );
       
  2040                                 }
       
  2041                             }
       
  2042                         else
       
  2043                             {
       
  2044                             RDEBUG_2( "CSCOMOAdapter::ExecuteCommandL(): Remove FAILED '%d'", err);
       
  2045 
       
  2046                             if (err == SwiUI::KSWInstErrUserCancel)
       
  2047                                 ret = EExecUserCancelled;
       
  2048                             else
       
  2049                                 MAPERROR( err, ret, _L8("Execute Remove %d") );
       
  2050                             }
       
  2051                         }
       
  2052                     else
       
  2053                         {
       
  2054                         ret = EExecRemoveFailed;
       
  2055                         RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 6 remove Not found node" );
       
  2056                         }
       
  2057                     }
       
  2058                         else
       
  2059                             if (mapping == KAMActivateNodeName)
       
  2060                                 {
       
  2061                                 //DBG_ARGS8( "CSCOMOAdapter::ExecuteCommandL(): Activating " );
       
  2062                                 TUint32 iluid(GetLuidL(aLUID,
       
  2063                                         NSmlDmURI::URISeg(aURI,
       
  2064                                                 KInventoryMappingURILoc),
       
  2065                                         EDCSActive) );
       
  2066                                 if ( (TInt32)iluid <= 0)
       
  2067                                     {
       
  2068                                     iluid = GetLuidL(aLUID,
       
  2069                                             NSmlDmURI::URISeg(aURI,
       
  2070                                                     KInventoryMappingURILoc),
       
  2071                                             EDCSInactive) ;
       
  2072                                     }
       
  2073                                 if (iluid > 0)
       
  2074                                     {
       
  2075                                     TRAP_IGNORE( SessionL().ActivateL( iluid ) );
       
  2076                                     ret = EExecSuccess;
       
  2077 								
       
  2078                                     //MAPERROR( erx, ret, _L8("Activate %d") );
       
  2079                                     }
       
  2080                                 else
       
  2081                                     {
       
  2082                                     ret = EExecActivateFailed;
       
  2083                                     RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 6 Activate Not found node" );
       
  2084                                     }
       
  2085                                 }
       
  2086                             else
       
  2087                                 if (mapping == KAMDeActivateNodeName)
       
  2088                                     {
       
  2089                                     //DBG_ARGS8( "CSCOMOAdapter::ExecuteCommandL(): Inactivating " );
       
  2090                                     TUint32 iluid(GetLuidL(aLUID,
       
  2091                                             NSmlDmURI::URISeg(aURI,
       
  2092                                                     KInventoryMappingURILoc),
       
  2093                                             EDCSActive) );
       
  2094                                     if ( (TInt32)iluid <= 0)
       
  2095                                         {
       
  2096                                         iluid
       
  2097                                                 = GetLuidL(
       
  2098                                                         aLUID,
       
  2099                                                         NSmlDmURI::URISeg(
       
  2100                                                                 aURI,
       
  2101                                                                 KInventoryMappingURILoc),
       
  2102                                                         EDCSInactive) ;
       
  2103                                         }
       
  2104                                     if (iluid > 0)
       
  2105                                         {
       
  2106                                         TRAP_IGNORE(SessionL().DeactivateL( iluid ) )
       
  2107                                         ;
       
  2108 										ret = EExecSuccess;
       
  2109                                         //MAPERROR( erx, ret,_L8("Dectivate %d") );
       
  2110                                         }
       
  2111                                     else
       
  2112                                         {
       
  2113                                         ret = EExecDeactivateFailed;
       
  2114                                         RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 6 DeActivate Not found node" );
       
  2115                                         }
       
  2116                                     }
       
  2117                                 else
       
  2118                                     {
       
  2119                                     RDEBUG8_2( "CSCOMOAdapter::ExecuteCommandL(): ASKED NOT SUPPORTED OPERATION '%S'", &mapping );
       
  2120                                     
       
  2121                                     ret = EExecUndefError;
       
  2122                                     }
       
  2123             break;
       
  2124             }
       
  2125 
       
  2126         default:
       
  2127             {
       
  2128             RDEBUG8_3( "CSCOMOAdapter::ExecuteCommandL(): ILLEGAL LEVEL %d NODE %S", cnt, &aURI );
       
  2129             
       
  2130             ret = EExecUndefError;
       
  2131             break;
       
  2132             }
       
  2133         }
       
  2134     SetStatusL(aStatusRef, ret) ;
       
  2135     }
       
  2136 
       
  2137 void CSCOMOAdapter::ASyncReportL(TUint32 aLuid, const TDesC8& aArgument,
       
  2138         const TDownloadTarget aTarget,const TDesC8& aURI)
       
  2139     {
       
  2140 
       
  2141     // while sending generic alert
       
  2142     // adapter uses entry stored in database and constructs generic alert
       
  2143     // using SyncML framework API.
       
  2144 
       
  2145     TInt index = 0;
       
  2146 
       
  2147 	// Default max retry count is 5. It is also cenep configurable
       
  2148 	// Cenrep configuration responsible can change the max retry 
       
  2149 	// count
       
  2150     TInt retrycount = 5;
       
  2151     
       
  2152     CRepository *repository = CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys );
       
  2153     repository->Get(KMaxRetryCount,retrycount);
       
  2154     CleanupStack::PopAndDestroy(); //repository
       
  2155       
       
  2156     TSmlProfileId profId = KErrNotFound;
       
  2157     HBufC8* serverId= NULL;
       
  2158 
       
  2159     //Retrive Server Information
       
  2160 
       
  2161     GetServerInfoL(profId, serverId);
       
  2162 
       
  2163     CleanupStack::PushL(serverId);
       
  2164 
       
  2165     //Add Download entry to database
       
  2166 
       
  2167     iAMdb->SaveToDatabaseL(index, aLuid, profId, retrycount, aURI,
       
  2168             *serverId, aArgument);
       
  2169 
       
  2170     CleanupStack::PopAndDestroy(serverId);
       
  2171 
       
  2172     }
       
  2173 
       
  2174 void CSCOMOAdapter::SyncReportL(TUint32 aLuid, const TDesC8& aArgument,
       
  2175         const TDownloadTarget aTarget,const TDesC8& aURI, TError &aRet )
       
  2176     {
       
  2177     TInt status = KStatusSuccess;
       
  2178 
       
  2179     RProperty counter;
       
  2180     TInt r=counter.Attach(KUidPSApplicationManagementKeys, KSyncNotifier,
       
  2181             EOwnerThread);
       
  2182     User::LeaveIfError(r);
       
  2183 
       
  2184     CSyncService *syncService = CSyncService::NewL(NULL, KDevManServiceStart);
       
  2185     if (syncService)
       
  2186         {
       
  2187         syncService->EnableProgressNoteL(EFalse);
       
  2188         }
       
  2189 
       
  2190     delete syncService;
       
  2191 
       
  2192     // wait for the previously attached ‘counter’ property to be updated
       
  2193     TRequestStatus s;
       
  2194     counter.Subscribe(s);
       
  2195     User::WaitForRequest(s);
       
  2196     
       
  2197     CRepository *repository = CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys );
       
  2198     repository->Get(KAMSyncStatus,status);
       
  2199     CleanupStack::PopAndDestroy();
       
  2200                 		   
       
  2201 		switch(status)
       
  2202 		{
       
  2203 			case KStatusUserCancelled:
       
  2204 			{
       
  2205 				aRet = MSmlDmAdapter::EExecUserCancelled;
       
  2206 				break;
       
  2207 			}
       
  2208 			               
       
  2209 			case KStatusDowloadFailedOOM:
       
  2210 			{
       
  2211 				aRet = MSmlDmAdapter::EExecDownFailOOM;
       
  2212 				break;
       
  2213 			}
       
  2214 
       
  2215 			case KStatusAlternateDownldAuthFail:
       
  2216 			{
       
  2217 			    aRet = MSmlDmAdapter::EExecAltDwnldAuthFail;
       
  2218 			    break;	
       
  2219 			}
       
  2220 
       
  2221 			case KStatusDownloadFailed:
       
  2222 			{
       
  2223 				aRet = MSmlDmAdapter::EExecDownloadFailed;
       
  2224 				break;
       
  2225 			}
       
  2226 
       
  2227 			case KStatusPkgValidationFailed:
       
  2228 			{
       
  2229 				aRet = MSmlDmAdapter::EExecPkgValidationFail;
       
  2230 				break;
       
  2231 			}
       
  2232 
       
  2233 			case KStatusInstallFailedOOM:
       
  2234 			{
       
  2235 				aRet = MSmlDmAdapter::EExecInstallOOM;
       
  2236 				break;
       
  2237 			}
       
  2238 
       
  2239 			case KStatusInstallFailed:
       
  2240 			{
       
  2241 				aRet = MSmlDmAdapter::EExecInstallFailed;
       
  2242 				break;
       
  2243 			}
       
  2244 		
       
  2245 		  case KStatusUnSupportedEnvironment:
       
  2246 			{
       
  2247 				aRet = MSmlDmAdapter::EExecOperationReject;
       
  2248 				break;
       
  2249 			}
       
  2250 			
       
  2251 			case KStatusAltDowldUnavailable:
       
  2252 			{
       
  2253 				aRet = MSmlDmAdapter::EExecAltDwnldSrvUnavailable;
       
  2254 				break;
       
  2255 			}
       
  2256 		
       
  2257 			default:
       
  2258 			{
       
  2259 			    aRet = MSmlDmAdapter::EExecSuccess;
       
  2260 				break;
       
  2261 			}
       
  2262 		}                
       
  2263     
       
  2264 
       
  2265     }
       
  2266 
       
  2267 void CSCOMOAdapter::GetServerInfoL(TSmlProfileId& aProfId, HBufC8*& aServerId) const
       
  2268     {
       
  2269     // Open session
       
  2270     RSyncMLSession session;
       
  2271     session.OpenL();
       
  2272     CleanupClosePushL(session);
       
  2273 
       
  2274     // get current job's id (and usage type)
       
  2275     TSmlJobId jobId = KErrNotFound;
       
  2276     TSmlUsageType type = ESmlDevMan;
       
  2277     session.CurrentJobL(jobId, type);
       
  2278 
       
  2279     // open currently running job
       
  2280     RSyncMLDevManJob dmJob;
       
  2281     dmJob.OpenL(session, jobId);
       
  2282     CleanupClosePushL(dmJob);
       
  2283 
       
  2284     // get job's profile id
       
  2285     aProfId = dmJob.Profile();
       
  2286 
       
  2287     // open profile using id in read-only mode
       
  2288     RSyncMLDevManProfile dmProf;
       
  2289     dmProf.OpenL(session, aProfId, ESmlOpenRead);
       
  2290     CleanupClosePushL(dmProf);
       
  2291 
       
  2292     // get profile's server id
       
  2293     aServerId = dmProf.ServerId().AllocL();
       
  2294 
       
  2295     // close handles
       
  2296     CleanupStack::PopAndDestroy( &dmProf);
       
  2297     CleanupStack::PopAndDestroy( &dmJob);
       
  2298     CleanupStack::PopAndDestroy( &session);
       
  2299     }
       
  2300 
       
  2301 // ------------------------------------------------------------------------------------------------
       
  2302 // CSCOMOAdapter::UpdateL( 
       
  2303 // 	const TUint aLuidi, 
       
  2304 // 	const TDesC8& aURI, 
       
  2305 // 	const TDesC8& aSourceLUID,
       
  2306 // 	const TDeploymentComponentState aTargetState,
       
  2307 // 	TError &aRet
       
  2308 // ------------------------------------------------------------------------------------------------
       
  2309 void CSCOMOAdapter::UpdateL(const TUint aLuidi, const TDesC8& aURI,
       
  2310         const TDesC8& aSourceLUID,
       
  2311         const TDeploymentComponentState aTargetState, TError &aRet)
       
  2312     {
       
  2313 
       
  2314 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2315     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  2316 #else
       
  2317     //nothing
       
  2318 #endif
       
  2319 
       
  2320     CBufBase *delivered = CBufFlat::NewL( 128);
       
  2321     CleanupStack::PushL(delivered);
       
  2322 
       
  2323 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2324     TPtrC8 aclmapping( NSmlDmURI::URISeg( uriPtrc, 4 ) );
       
  2325 #else
       
  2326     TPtrC8 aclmapping(NSmlDmURI::URISeg(aURI, 4) );
       
  2327 #endif
       
  2328 
       
  2329     HBufC8 *targetURI = HBufC8::NewLC(KDeployedURI().Length() + aclmapping.Length() );
       
  2330 
       
  2331     TPtr8 targetPtr(targetURI->Des() );
       
  2332     targetPtr.Copy(KDeployedURI);
       
  2333     targetPtr.Append(aclmapping);
       
  2334 
       
  2335     HBufC8 *deployed = Callback().GetLuidAllocL(targetPtr) ;
       
  2336     CleanupStack::PushL(deployed);
       
  2337 
       
  2338     //DBG_ARGS8( "CSCOMOAdapter::UpdateL(): Updating '%S' luid: '%S'" ), &targetPtr, &(*deployed));
       
  2339     if ( *deployed == KNullDesC8)
       
  2340         {
       
  2341         //DBG_ARGS8( "CSCOMOAdapter::UpdateL(): Failed to find to update target '%S'" ), &targetPtr );
       
  2342         aRet = EError;
       
  2343         }
       
  2344     else
       
  2345         {
       
  2346         // Found delivered & active or inactive components! Do update!
       
  2347         TInt depluid(DesToIntL( *deployed ));
       
  2348         TRAPD( erx, SessionL().UpdateL( aLuidi, depluid ) )
       
  2349         ;
       
  2350         MAPERROR( erx, aRet,_L8("Update %d") );
       
  2351         if (erx == KErrNone)
       
  2352             {
       
  2353             SetMappingLC(aclmapping, aTargetState, aSourceLUID, targetURI);
       
  2354             DeactivateIfInactive(aLuidi, aTargetState);
       
  2355             }
       
  2356         }
       
  2357     CleanupStack::PopAndDestroy(deployed) ;
       
  2358     CleanupStack::PopAndDestroy(targetURI) ;
       
  2359     CleanupStack::PopAndDestroy(delivered) ;
       
  2360     }
       
  2361 
       
  2362 // ------------------------------------------------------------------------------------------------
       
  2363 //  CSCOMOAdapter::CheckStateL( const TDeploymentComponent &aComp, const TDesC8& aURI
       
  2364 // ------------------------------------------------------------------------------------------------
       
  2365 TBool CSCOMOAdapter::CheckStateL(const TDeploymentComponent &aComp,
       
  2366         const TDesC8& aURI)
       
  2367     {
       
  2368 	TBool ret;
       
  2369 	if ((aComp.iState ==  EDCSDelivered) || (aComp.iState == EDCSActive) || ( aComp.iState == EDCSInactive) || (aComp.iState == EDCSDownload))
       
  2370 	{
       
  2371         // Check for map & __TARM_SYMBIAN_CONVERGENCY also ?
       
  2372         ret = ETrue;
       
  2373     }
       
  2374 	else
       
  2375 	    ret = EFalse;
       
  2376 	return ret;
       
  2377     }
       
  2378 
       
  2379 // ------------------------------------------------------------------------------------------------
       
  2380 //  CSCOMOAdapter::StateL( const TDeploymentComponent &aComp, const TDesC8& aURI
       
  2381 // ------------------------------------------------------------------------------------------------
       
  2382 TDeploymentComponentState CSCOMOAdapter::StateL(const TDesC8& aURI)
       
  2383     {
       
  2384 
       
  2385 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2386     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  2387 #else
       
  2388     //nothing
       
  2389 #endif
       
  2390 
       
  2391     TDeploymentComponentState ret(EDCSNone);
       
  2392 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2393     TInt cnt( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  2394 #else
       
  2395     TInt cnt(NSmlDmURI::NumOfURISegs(aURI) );
       
  2396 #endif	
       
  2397     if (cnt > 2)
       
  2398         {
       
  2399 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2400         TPtrC8 map( NSmlDmURI::URISeg( uriPtrc, 2 ) );
       
  2401 #else
       
  2402         TPtrC8 map(NSmlDmURI::URISeg(aURI, 2) );
       
  2403 #endif	
       
  2404         if (map == KAMInventoryNodeName)
       
  2405             {
       
  2406 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2407             TPtrC8 map( NSmlDmURI::URISeg( uriPtrc, 2 ) );
       
  2408 #else
       
  2409             TPtrC8 map(NSmlDmURI::URISeg(aURI, 2) );
       
  2410 #endif	
       
  2411             map.Set(NSmlDmURI::URISeg(aURI, 3) );
       
  2412             if (map == KAMDeployedNodeName)
       
  2413                 {
       
  2414 
       
  2415                 }
       
  2416             else
       
  2417                 if (map == KAMDeliveredNodeName)
       
  2418                     {
       
  2419                     ret = EDCSDelivered;
       
  2420                     }
       
  2421                 else
       
  2422                     {
       
  2423                     User::Leave(KErrArgument);
       
  2424                     }
       
  2425             }
       
  2426         else
       
  2427             if (map == KAMDownloadNodeName)
       
  2428                 {
       
  2429                 ret = EDCSDownload;
       
  2430                 }
       
  2431             else
       
  2432                 {
       
  2433                 User::Leave(KErrArgument);
       
  2434                 }
       
  2435         }
       
  2436     return ret;
       
  2437     }
       
  2438 
       
  2439 // ------------------------------------------------------------------------------------------------
       
  2440 //  CSCOMOAdapter::CheckStateL( const TDesC8& aURI, const TDesC8& aLUID )
       
  2441 // ------------------------------------------------------------------------------------------------
       
  2442 TBool CSCOMOAdapter::CheckStateL(const TDesC8& aURI, const TDesC8& aLUID)
       
  2443     {
       
  2444 
       
  2445     TUint32 iluid(DesToIntL(aLUID) );
       
  2446     TDeploymentComponent comp;
       
  2447     TInt err(SessionL().DeploymentComponent(iluid, comp) );
       
  2448     TBool ret(EFalse);
       
  2449     if (err == KErrNone)
       
  2450         {
       
  2451         ret = CheckStateL(comp, aURI);
       
  2452         }
       
  2453     return ret;
       
  2454     }
       
  2455 
       
  2456 // ------------------------------------------------------------------------------------------------
       
  2457 //  CSCOMOAdapter::InstallOptionsDataL(const TUint32 iluid, const TDeplCompAttrType& aDataType, 
       
  2458 //		CBufBase &aBuf, CBufBase *aRaw/*= NULL*/)
       
  2459 // ------------------------------------------------------------------------------------------------
       
  2460 void CSCOMOAdapter::InstallOptionsDataL(const TUint32 iluid,
       
  2461         const TDeplCompAttrType& aDataType, CBufBase &aBuf, CBufBase *aRaw/*= NULL*/)
       
  2462     {
       
  2463     TAMInstallOptionsPckgBuf iop;
       
  2464     TBool pushed(EFalse);
       
  2465     if ( !aRaw)
       
  2466         {
       
  2467         aRaw = CBufFlat::NewL(32);
       
  2468         CleanupStack::PushL(aRaw);
       
  2469         pushed = ETrue;
       
  2470         SessionL().DeploymentComponentDataL(iluid, aDataType, *aRaw);
       
  2471         }
       
  2472 
       
  2473     iop.Copy(aRaw->Ptr( 0) );
       
  2474     if (pushed)
       
  2475         {
       
  2476         CleanupStack::PopAndDestroy(aRaw);
       
  2477         }
       
  2478     InstallOptionsParser::SerializeOptionsL(iop(), aBuf);
       
  2479     }
       
  2480 
       
  2481 // ------------------------------------------------------------------------------------------------
       
  2482 //  CSCOMOAdapter::GetComponentDataL( const TDesC8& parent, const TDesC8& mapping, 
       
  2483 //		const TUint32 iluid, CBufBase *currentList, CBufBase *currentMime, TError &status )
       
  2484 // ------------------------------------------------------------------------------------------------
       
  2485 void CSCOMOAdapter::GetComponentDataL(const TDesC8& parent,
       
  2486         const TDesC8& mapping, const TUint32 iluid, CBufBase &currentList,
       
  2487         CBufBase &currentMime, TError &status)
       
  2488     {
       
  2489     TDeploymentComponent comp;
       
  2490     TInt err(SessionL().DeploymentComponent(iluid, comp) );
       
  2491     if (err == KErrNone)
       
  2492         {
       
  2493         RDEBUG_3( "CSCOMOAdapter::GetComponentDataL(): DeploymentComponent response: %d, state: %d", err, comp.iState );
       
  2494         if (CheckStateL(comp, parent) )
       
  2495             {
       
  2496             if (mapping == KAMPkgIDNodeName)
       
  2497                 {
       
  2498                 currentList.InsertL( 0, comp.iPkgID);
       
  2499                 status = EOk;
       
  2500                 }
       
  2501             else
       
  2502                 if (mapping == KAMNameNodeName)
       
  2503                     {
       
  2504                     currentList.InsertL( 0, comp.iName);
       
  2505                     status = EOk;
       
  2506                     }
       
  2507                 else
       
  2508                     if (mapping == KAMVersionNodeName)
       
  2509                         {
       
  2510                         currentList.InsertL( 0, comp.iVersion);
       
  2511                         status = EOk;
       
  2512                         }
       
  2513                 else
       
  2514                    if(mapping == KAMIDNodeName)
       
  2515                    {
       
  2516                    	
       
  2517                         currentList.InsertL( 0, comp.iId);
       
  2518                         status = EOk;
       
  2519                         
       
  2520                    }
       
  2521                 else
       
  2522                    if(mapping == KAMPkgIDRefNodeName)
       
  2523                    {
       
  2524                    	
       
  2525                         currentList.InsertL( 0, comp.iPkgIDRef);
       
  2526                         status = EOk;
       
  2527                         
       
  2528                    }
       
  2529 				else
       
  2530                    if(mapping == KAMPkgIDNodeName)
       
  2531                    {
       
  2532                    	
       
  2533                         currentList.InsertL( 0, comp.iPkgID);
       
  2534                         status = EOk;
       
  2535                         
       
  2536                    }               
       
  2537 				else
       
  2538                    if(mapping == KAMPkgTypeNodeName)
       
  2539                    {
       
  2540                    	
       
  2541                         currentList.InsertL( 0, comp.iPkgType);
       
  2542                         status = EOk;
       
  2543                         
       
  2544                    }             
       
  2545                 else 
       
  2546                    if ( mapping == KAMStatusNodeName )
       
  2547                 {
       
  2548                 TDeplCompAttrType dataType( UpdateFlagFromMapping( mapping ) );
       
  2549                 SessionL().DeploymentComponentDataL( iluid, dataType, currentList );
       
  2550                 status = EOk;
       
  2551                 }			
       
  2552 
       
  2553                     else
       
  2554                         if (mapping == KAMDescriptionNodeName)
       
  2555                             {
       
  2556                             currentList.InsertL(0, comp.iDescription);
       
  2557                             status = EOk;
       
  2558                             }
       
  2559                         else
       
  2560                             {
       
  2561                             TDeplCompAttrType
       
  2562                                     dataType(UpdateFlagFromMapping(mapping) );
       
  2563                             if (comp.iState == EDCSDownload)
       
  2564                                 {
       
  2565 					if ( dataType == EDCDownloadURI )//|| dataType == EDCDownloadStatus )
       
  2566                                     {
       
  2567                                     SessionL().DeploymentComponentDataL(iluid,
       
  2568                                             dataType, currentList);
       
  2569                                     status = EOk;
       
  2570                                     }
       
  2571                                 else
       
  2572                                     if (dataType == EDCInstallOptions)
       
  2573                                         {
       
  2574                                         InstallOptionsDataL(iluid, dataType,
       
  2575                                                 currentList);
       
  2576                                         status = EOk;
       
  2577                                         }
       
  2578                                     else
       
  2579                                         if (dataType == EDCConRef)
       
  2580                                             {
       
  2581                                             CBufBase *b = CBufFlat::NewL(4);
       
  2582                                             CleanupStack::PushL(b);
       
  2583                                             SessionL().DeploymentComponentDataL(
       
  2584                                                     iluid, dataType, *b);
       
  2585                                             TPckgBuf<TInt> iap;
       
  2586                                             iap.Copy(b->Ptr( 0) );
       
  2587                                             CleanupStack::PopAndDestroy(b);
       
  2588 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  2589 
       
  2590                                             CArrayFix<TSmlDmMappingInfo>* mapArray = new CArrayFixFlat<TSmlDmMappingInfo>(4);
       
  2591                                             CleanupStack::PushL(mapArray);
       
  2592 
       
  2593                                             Callback().GetMappingInfoListL( KNSmlDMMMSSlashIAPUri,*mapArray );
       
  2594 
       
  2595                                             //TInt iap = KErrNotFound; 
       
  2596                                             TSmlDmMappingInfo mapInfo;
       
  2597                                             HBufC8 * uri = NULL;
       
  2598                                             TPtr8 tempURI(uri->Des());
       
  2599 
       
  2600                                             for(TInt i = 0;i<mapArray->Count();i++)
       
  2601                                                 {
       
  2602                                                 if(iap()==DesToInt(mapArray->At(i).iURISegLUID))
       
  2603                                                     {
       
  2604                                                     tempURI=mapArray->At(i).iURISeg;
       
  2605                                                     }
       
  2606 
       
  2607                                                 }
       
  2608                                             mapArray->Reset();
       
  2609                                             CleanupStack::PopAndDestroy(); //mapArray
       
  2610                                             if ( uri != NULL )
       
  2611                                                 {
       
  2612                                                 CleanupStack::PushL( uri );
       
  2613                                                 currentList.InsertL( 0, *uri );
       
  2614                                                 CleanupStack::PopAndDestroy( uri );
       
  2615                                                 }
       
  2616 
       
  2617 #else
       
  2618 
       
  2619                                             CNSmlDMIAPMatcher
       
  2620                                                     * iapfinder =
       
  2621                                                             CNSmlDMIAPMatcher::NewLC( &Callback() );
       
  2622                                             HBufC8
       
  2623                                                     * uri =
       
  2624                                                             iapfinder->URIFromIAPIdL(iap() ) ;
       
  2625                                             CleanupStack::PopAndDestroy(iapfinder);
       
  2626                                             if (uri != NULL)
       
  2627                                                 {
       
  2628                                                 CleanupStack::PushL(uri) ;
       
  2629                                                 currentList.InsertL( 0, *uri);
       
  2630                                                 CleanupStack::PopAndDestroy(uri) ;
       
  2631                                                 }
       
  2632 
       
  2633 #endif
       
  2634                                             status = EOk;
       
  2635                                             }
       
  2636                                         else
       
  2637                                             {
       
  2638                                             RDEBUG8_2( "CSCOMOAdapter::GetComponentDataL(): ASKED NOT SUPPORTED LEAF '%S'", &mapping );
       
  2639                                             }
       
  2640                                 }
       
  2641                             else
       
  2642                                 if (comp.iState == EDCSDelivered)
       
  2643                                     {
       
  2644                                     if(mapping == KAMStateValueNodeName)
       
  2645                                         {
       
  2646                                       currentList.InsertL( 0,KAMStateValueDelivered() );
       
  2647                                       status = EOk;
       
  2648                                         }
       
  2649                                     if (dataType == EDCData || dataType
       
  2650                                             == EDCMetaData || dataType
       
  2651                                             == EDCInstallOptions)
       
  2652                                         {
       
  2653                                         CBufBase *raw = CBufFlat::NewL( 128);
       
  2654                                         CleanupStack::PushL(raw);
       
  2655                                         SessionL().DeploymentComponentDataL(
       
  2656                                                 iluid, dataType, *raw);
       
  2657                                         TPtrC8 source(raw->Ptr(0) );
       
  2658                                         if (source.Length() > 0)
       
  2659                                             {
       
  2660                                             if (dataType == EDCData)
       
  2661                                                 {
       
  2662                                                 currentList.InsertL( 0,
       
  2663                                                         source);
       
  2664                                                 SessionL().DeploymentComponentDataL(
       
  2665                                                         iluid, EDCDataMime,
       
  2666                                                         currentMime);
       
  2667 
       
  2668                                                 }
       
  2669                                             else
       
  2670                                                 if (dataType
       
  2671                                                         == EDCInstallOptions)
       
  2672                                                     {
       
  2673                                                     InstallOptionsDataL(
       
  2674                                                             iluid, dataType,
       
  2675                                                             currentList, raw);
       
  2676                                                     }
       
  2677                                                 else
       
  2678                                                     {
       
  2679                                                     currentList.InsertL( 0,
       
  2680                                                             source);
       
  2681                                                     SessionL().DeploymentComponentDataL(
       
  2682                                                             iluid,
       
  2683                                                             EDCMetaDataMime,
       
  2684                                                             currentMime);
       
  2685                                                     }
       
  2686                                             }
       
  2687                                         else
       
  2688                                             {
       
  2689                                             // 0 data length...
       
  2690                                             }
       
  2691                                         status = EOk;
       
  2692                                         CleanupStack::PopAndDestroy(raw);
       
  2693                                         RDEBUG8_2( "CSCOMOAdapter::GetComponentDataL(): DeploymentComponentDataL called '%S'", &mapping );
       
  2694                                         }
       
  2695                                     }
       
  2696                                 else
       
  2697                                     if (dataType == EDCStateValue)
       
  2698                                         {
       
  2699                                         if (comp.iState == EDCSActive)
       
  2700                                             {
       
  2701                                             currentList.InsertL( 0,
       
  2702                                                     KAMStateValueActive() );
       
  2703                                             }
       
  2704                                         else
       
  2705                                             {
       
  2706                                             currentList.InsertL( 0,
       
  2707                                                     KAMStateValueInactive() );
       
  2708                                             }
       
  2709                                         status = EOk;
       
  2710                                         }
       
  2711                                     else
       
  2712                                         {
       
  2713                                         RDEBUG8_2( "CSCOMOAdapter::GetComponentDataL(): ERROR ASKED NOT SUPPORTED LEAF '%S'", &mapping );
       
  2714                                         }
       
  2715                             }
       
  2716             }
       
  2717         else
       
  2718             {
       
  2719             RDEBUG8_3( "CSCOMOAdapter::GetComponentDataL(): WARNING Asked illegal state leaf '%S', %d", &mapping, comp.iState );
       
  2720             status = ENotFound;
       
  2721             }
       
  2722         }
       
  2723     else
       
  2724         {
       
  2725         RDEBUG_3( "CSCOMOAdapter::GetComponentDataL(): ERROR FAILED TO GET COMPOMENT OF ID %d: %d", iluid, err );
       
  2726         MAPERROR( err, status,_L8("Get Component %d") );
       
  2727         }
       
  2728     }
       
  2729 
       
  2730 // ------------------------------------------------------------------------------------------------
       
  2731 //  CSCOMOAdapter::GetLeafLuidL(const TDesC8 &aURI, const TDesC8 & aParentMapping ) 
       
  2732 // ------------------------------------------------------------------------------------------------
       
  2733 TInt CSCOMOAdapter::GetLeafLuidL(const TDesC8 &aURI,
       
  2734         const TDesC8 & aParentMapping)
       
  2735     {
       
  2736 
       
  2737 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2738     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  2739     TInt numSeqs( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  2740 #else
       
  2741     TInt numSeqs(NSmlDmURI::NumOfURISegs(aURI) );
       
  2742 #endif
       
  2743 
       
  2744     TUint32 iluid( 0);
       
  2745     //TInt numSeqs( NSmlDmURI::NumOfURISegs( aURI ) );//Dipak
       
  2746 
       
  2747     switch (numSeqs)
       
  2748         {
       
  2749         case 4: // must be a download leaf
       
  2750             {
       
  2751             iluid = GetLuidForUserIdL(aParentMapping, EDCSDownload) ;
       
  2752             break;
       
  2753             }
       
  2754         case 5: // download operation or delivered or deployed leaf
       
  2755             {
       
  2756             if (URISegsUpTo(aURI, 2, ETrue) == KDownloadURI)
       
  2757                 {
       
  2758                 RDEBUG8_2( "CSCOMOAdapter::GetLeafLuidL(): WARNING download operation leaf '%S'", &aURI );
       
  2759                 //status = EOk; 
       
  2760                 }
       
  2761             else
       
  2762                 {
       
  2763                 TPtrC8 start(URISegsUpTo(aURI, 3, ETrue) );
       
  2764                 if (start == KDeliveredURI)
       
  2765                     {
       
  2766                     iluid = GetLuidForUserIdL(aParentMapping, EDCSDelivered) ;
       
  2767                     }
       
  2768                 else
       
  2769                     if (start == KDeployedURI)
       
  2770                         {
       
  2771                         iluid = GetLuidForUserIdL(aParentMapping, EDCSActive) ;
       
  2772                         if ( (TInt32)iluid <= 0)
       
  2773                             {
       
  2774                             iluid = GetLuidForUserIdL(aParentMapping,
       
  2775                                     EDCSInactive) ;
       
  2776                             }
       
  2777                         }
       
  2778                     else
       
  2779                         {
       
  2780                         RDEBUG8_2( "CSCOMOAdapter::GetLeafLuidL(): WARNING strange uri '%S'", &aURI );
       
  2781                         }
       
  2782                 }
       
  2783             break;
       
  2784             }
       
  2785         case 6: // delivered or deployed operation leaf
       
  2786             {
       
  2787             //iluid = GetLuidForUserIdL( parentMapping, EDCSDownload ) ;
       
  2788             //status = EOk;
       
  2789             RDEBUG8_2( "CSCOMOAdapter::GetLeafLuidL(): WARNING delivered or deployed operation leaf '%S'", &aURI );
       
  2790             break;
       
  2791             }
       
  2792         default: // illegal uri
       
  2793             {
       
  2794             RDEBUG8_2( "CSCOMOAdapter::GetLeafLuidL(): ERROR requested luid of illegal URI '%S'", &aURI );
       
  2795             break;
       
  2796             }
       
  2797         }
       
  2798     return iluid;
       
  2799     }
       
  2800 
       
  2801 // ------------------------------------------------------------------------------------------------
       
  2802 //  CSCOMOAdapter::FetchLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aType, 
       
  2803 //			CBufBase& aObject )
       
  2804 // ------------------------------------------------------------------------------------------------
       
  2805 void CSCOMOAdapter::FetchLeafObjectL(const TDesC8& aURI, const TDesC8& aLUID,
       
  2806         const TDesC8& aType, const TInt aResultsRef, TInt aStatusRef)
       
  2807     {
       
  2808 
       
  2809 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2810     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  2811 #else
       
  2812     //Nothing
       
  2813 #endif
       
  2814 
       
  2815     RDEBUG8_4("CSCOMOAdapter::FetchLeafObjectL('%S', '%S', '%S'): begin", &aURI, &aLUID, &aType );
       
  2816     SetAdapterValue(KAMSCOMOAdapter);
       
  2817     CheckStateChangesL();
       
  2818     TError status(EError);
       
  2819 
       
  2820     CBufBase *currentList = CBufFlat::NewL( 128);
       
  2821     CleanupStack::PushL(currentList);
       
  2822 
       
  2823     CBufBase *currentMime = CBufFlat::NewL( 128);
       
  2824     CleanupStack::PushL(currentMime);
       
  2825 
       
  2826     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  2827     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  2828     TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  2829 
       
  2830     HBufC8 *luid= NULL;
       
  2831     if (aLUID != KNullDesC8)
       
  2832         {
       
  2833         luid = aLUID.AllocLC();
       
  2834         }
       
  2835     else
       
  2836         { // try if we find it from download path
       
  2837         TBuf8<256> down;
       
  2838         down = KDownloadURI;
       
  2839         down.Append(parentMapping);
       
  2840         luid = Callback().GetLuidAllocL(down);
       
  2841         CleanupStack::PushL(luid);
       
  2842         if ( *luid != KNullDesC8)
       
  2843             {
       
  2844             // make it to found next time
       
  2845             DirectSetMappingL(parent, *luid);
       
  2846             MoveAclL(down, parent);
       
  2847 
       
  2848             // remove old
       
  2849             DirectSetMappingL(down, KNullDesC8);
       
  2850             }
       
  2851         }
       
  2852     if ( *luid != KNullDesC8)
       
  2853         {
       
  2854         TUint32 iluid(DesToIntL( *luid ));
       
  2855         RDEBUG8_2( "CSCOMOAdapter::FetchLeafObjectL(): Luid is : %d", iluid );
       
  2856         GetComponentDataL(parent, mapping, iluid, *currentList, *currentMime,
       
  2857                 status);
       
  2858         }
       
  2859     else
       
  2860         {
       
  2861         TUint32 iluid(GetLeafLuidL(aURI, parentMapping) );
       
  2862         if (iluid > 0)
       
  2863             {
       
  2864             HBufC8 *l = IntToDes8LC(iluid);
       
  2865             DirectSetMappingL(parent, *l);
       
  2866             CleanupStack::PopAndDestroy(l);
       
  2867             GetComponentDataL(parent, mapping, iluid, *currentList,
       
  2868                     *currentMime, status);
       
  2869             }
       
  2870         else
       
  2871             {
       
  2872             RDEBUG8_2( "CSCOMOAdapter::FetchLeafObjectL(): WARNING Faild to get luid allocation for '%S'", &parent );
       
  2873             if (aLUID == KNullDesC8)
       
  2874                 {
       
  2875 #ifdef __AM_LASTERROR_NODE
       
  2876                 if (aURI == KAMLastErrorURI)
       
  2877                     {
       
  2878                     const TDesC8& error= LastError();
       
  2879                     RDEBUG8_2( "CSCOMOAdapter::FetchLeafObjectL(): Returning last error '%S'", &error );
       
  2880                     currentList->InsertL(0, error);
       
  2881                     status = EOk;
       
  2882                     }
       
  2883                 else
       
  2884                     {
       
  2885                     status = ENotFound;
       
  2886                     }
       
  2887 #else
       
  2888                 status = ENotFound;
       
  2889 #endif
       
  2890                 }
       
  2891             }
       
  2892         }
       
  2893 
       
  2894     SetStatusL(aStatusRef, status);
       
  2895     if (status == EOk)
       
  2896         {
       
  2897         if (iInAtomic)
       
  2898             {
       
  2899             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  2900             }
       
  2901         Callback().SetResultsL(aResultsRef, *currentList,
       
  2902                 ( (currentMime->Size() > 0) ? currentMime->Ptr(0) : aType ));
       
  2903         }
       
  2904     CleanupStack::PopAndDestroy(luid);
       
  2905     CleanupStack::PopAndDestroy(currentMime); //currentMime
       
  2906     CleanupStack::PopAndDestroy(currentList); //currentList
       
  2907     RDEBUG("CSCOMOAdapter::FetchLeafObjectL: end" );
       
  2908     }
       
  2909 
       
  2910 // ------------------------------------------------------------------------------------------------
       
  2911 //  CSCOMOAdapter::IdListL( TDeploymentComponentState aState, 
       
  2912 //					CBufBase *aCurrentList, TBool aAppend /* = EFalse */)
       
  2913 // ------------------------------------------------------------------------------------------------
       
  2914 CSCOMOAdapter::TError CSCOMOAdapter::IdListL(
       
  2915         TDeploymentComponentState aState, CBufBase &aCurrentList,
       
  2916         TBool aAppend /* = EFalse */)
       
  2917     {
       
  2918 	RDEBUG_2( "CSCOMOAdapter::IdListL:Begin aState is %d", aState);
       
  2919     CSCOMOAdapter::TError ret(CSCOMOAdapter::EError);
       
  2920     RElementIdArray array;
       
  2921     TPtrC8 uriStart;
       
  2922     TBuf8<256> uri;
       
  2923 	
       
  2924     switch (aState)
       
  2925         {
       
  2926         case EDCSDelivered:
       
  2927             uriStart.Set(KDeliveredURI);
       
  2928             break;
       
  2929         case EDCSActive:
       
  2930         case EDCSInactive:
       
  2931             uriStart.Set(KDeployedURI) ;
       
  2932             break;
       
  2933         case EDCSDownload:
       
  2934             uriStart.Set(KDownloadURI) ;
       
  2935             break;
       
  2936         default:
       
  2937             break;
       
  2938 
       
  2939         }
       
  2940     TInt err(SessionL().DeploymentComponentIdsL(array, aState) );
       
  2941     if (err == KErrNone)
       
  2942         {
       
  2943         TInt count(array.Count() );
       
  2944 		RDEBUG_2( "CSCOMOAdapter::IdListL: count is %d", count);
       
  2945         if (count && aAppend && aCurrentList.Size() )
       
  2946             {
       
  2947 				RDEBUG("CSCOMOAdapter::IdListL: Inserting list size" );
       
  2948             aCurrentList.InsertL(aCurrentList.Size(), KAMSeparator8);
       
  2949             }
       
  2950         for (TInt i( 0); i < count; i++)
       
  2951             {
       
  2952             TUint32 el = array[i];
       
  2953             TDCUserId dc;
       
  2954             SessionL().DeploymentComponentUserIdL(el, dc);
       
  2955 			RDEBUG_2("CSCOMOAdapter::IdListL: Node name is %S", &dc);
       
  2956             if (uriStart == KNullDesC8() )
       
  2957                 {
       
  2958 					RDEBUG("CSCOMOAdapter::IdListL: uriStart == KNullDesC8()" );
       
  2959                 TDeploymentComponent comp;
       
  2960                 err = SessionL().DeploymentComponent(el, comp) ;
       
  2961                 if (err == KErrNone)
       
  2962                     {
       
  2963                     switch (comp.iState)
       
  2964                         {
       
  2965                         case EDCSDelivered:
       
  2966                             uriStart.Set(KDeliveredURI);
       
  2967                             break;
       
  2968                         case EDCSActive:
       
  2969                         case EDCSInactive:
       
  2970                             uriStart.Set(KDeployedURI) ;
       
  2971                             break;
       
  2972                         case EDCSDownload:
       
  2973                             uriStart.Set(KDownloadURI) ;
       
  2974                             break;
       
  2975                         default:
       
  2976                             break;
       
  2977                         }
       
  2978                     }
       
  2979                 }
       
  2980             if (uriStart != KNullDesC8() )
       
  2981                 {
       
  2982                 uri.Copy(uriStart);
       
  2983                 uri.Append(dc);
       
  2984                 HBufC8 *luid = DirectGetLuidAllocLC(uri); //Callback().GetLuidAllocL( uri );
       
  2985 				RDEBUG_2( "CSCOMOAdapter::IdListL: luid is %S", luid);
       
  2986                 if (KNullDesC8() == *luid)
       
  2987                     {
       
  2988                     RDEBUG8_3( "CSCOMOAdapter::IdListL(): WARNING updating lost luid of '%S' %d", &uri, el );
       
  2989                     HBufC8 *l = IntToDes8LC(el);
       
  2990                     if ( *luid == *l)
       
  2991                         {
       
  2992                         RDEBUG( "CSCOMOAdapter::IdListL(): WARNING CANCEL (not really updating, they're the same already" );
       
  2993                         }
       
  2994                     else
       
  2995                         {
       
  2996 							RDEBUG("CSCOMOAdapter::IdListL: DirectSetMappingL" );
       
  2997                         DirectSetMappingL(uri, *l);
       
  2998                         }
       
  2999                     CleanupStack::PopAndDestroy(l);
       
  3000                     }
       
  3001                 CleanupStack::PopAndDestroy(luid);
       
  3002 
       
  3003                 }
       
  3004             else
       
  3005                 {
       
  3006                 RDEBUG_2( "CSCOMOAdapter::IdListL(): WARNING failed to get component state of id %d, cannot check mappings ", el );
       
  3007                 }
       
  3008             aCurrentList.InsertL(aCurrentList.Size(), dc);
       
  3009             if (i + 1 < count)
       
  3010                 {
       
  3011 					RDEBUG("CSCOMOAdapter::IdListL: Adding Separator" );
       
  3012                 aCurrentList.InsertL(aCurrentList.Size(), KAMSeparator8);
       
  3013                 }
       
  3014             }
       
  3015         ret = EOk;
       
  3016         }
       
  3017     else
       
  3018         {
       
  3019         RDEBUG_2( "CSCOMOAdapter::IdListL(): Error %d", err );
       
  3020         }
       
  3021     array.Reset();
       
  3022 	RDEBUG("CSCOMOAdapter::IdListL: end" );
       
  3023     return ret;
       
  3024     }
       
  3025 
       
  3026 // ------------------------------------------------------------------------------------------------
       
  3027 //  CSCOMOAdapter::ChildURIListL( const TDesC8& aURI, const TDesC8& aParentLUID, 
       
  3028 //			const CArrayFix<TSmlDmMappingInfo>& /*aPreviousURISegmentList*/, const TInt aResultsRef, 
       
  3029 //			TInt aStatusRef );
       
  3030 // ------------------------------------------------------------------------------------------------
       
  3031 void CSCOMOAdapter::ChildURIListL(const TDesC8& aURI,
       
  3032         const TDesC8& aParentLUID,
       
  3033         const CArrayFix<TSmlDmMappingInfo>& /*aPreviousURISegmentList*/,
       
  3034         const TInt aResultsRef, TInt aStatusRef)
       
  3035     {
       
  3036 
       
  3037 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  3038     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  3039 #else
       
  3040     //Nothing
       
  3041 #endif
       
  3042 
       
  3043     RDEBUG8_3 ( "CSCOMOAdapter::ChildURIListL(): begin ('%S', '%S')" , &aURI, &aParentLUID );
       
  3044     CheckStateChangesL();
       
  3045 
       
  3046     TError ret(EError);
       
  3047 
       
  3048     CBufBase *currentList = CBufFlat::NewL( 128);
       
  3049     CleanupStack::PushL(currentList);
       
  3050 
       
  3051 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
  3052     TInt numSeqs( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  3053 #else
       
  3054     TInt numSeqs(NSmlDmURI::NumOfURISegs(aURI) );
       
  3055 #endif
       
  3056 
       
  3057     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  3058     if (numSeqs == 1)
       
  3059         {
       
  3060         currentList->InsertL( 0, KAMRootChilds);
       
  3061         ret = EOk;
       
  3062         }
       
  3063     else
       
  3064         if (numSeqs == 2)
       
  3065             {
       
  3066             if (mapping == KAMInventoryNodeName)
       
  3067                 {
       
  3068                 currentList->InsertL( 0, KAMInventoryChilds);
       
  3069                 ret = EOk;
       
  3070                 }
       
  3071             else
       
  3072                 if (mapping == KAMDownloadNodeName)
       
  3073                     {
       
  3074                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level 2 NODE %S", &aURI );
       
  3075                     TDeploymentComponentState state(EDCSDownload);
       
  3076                     ret = IdListL(state, *currentList);
       
  3077                     }
       
  3078                 else
       
  3079                     {
       
  3080                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): ILLEGAL LEVEL 2 NODE %S", &aURI );
       
  3081                     User::Leave(KErrArgument);
       
  3082                     }
       
  3083             }
       
  3084         else
       
  3085             if (numSeqs == 3)
       
  3086                 {
       
  3087                 if (mapping == KAMDeliveredNodeName)
       
  3088                     {
       
  3089                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level 3 NODE %S", &aURI );
       
  3090                     TDeploymentComponentState state(EDCSDelivered);
       
  3091                     ret = IdListL(state, *currentList);
       
  3092                     }
       
  3093                 else
       
  3094                     if (mapping == KAMDeployedNodeName)
       
  3095                         {
       
  3096                         TDeploymentComponentState state(EDCSActive);
       
  3097                         ret = IdListL(state, *currentList);
       
  3098                         if (ret == EOk)
       
  3099                             {
       
  3100                             state = EDCSInactive;
       
  3101                             ret = IdListL(state, *currentList, ETrue);
       
  3102                             }
       
  3103                         }
       
  3104                     else
       
  3105                         {
       
  3106                         if (aParentLUID != KNullDesC8)
       
  3107                             {
       
  3108                             if (CheckStateL(aURI, aParentLUID) )
       
  3109                                 {
       
  3110                                 TPtrC8
       
  3111                                         parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3112                                 TPtrC8
       
  3113                                         parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3114                                 if (parentMapping == KAMDownloadNodeName)
       
  3115                                     {
       
  3116                                     currentList->InsertL( 0,
       
  3117                                             KAMDownloadDynaChilds);
       
  3118                                     ret = EOk;
       
  3119                                     }
       
  3120                                 else
       
  3121                                     {
       
  3122                                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): ILLEGAL LEVEL 3 NODE %S", &aURI );
       
  3123                                     User::Leave(KErrArgument);
       
  3124                                     }
       
  3125                                 }
       
  3126                             else
       
  3127                                 {
       
  3128                                 RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): DC has changed state %S", &aURI );
       
  3129                                 ret = ENotFound;
       
  3130                                 }
       
  3131                             }
       
  3132                         else
       
  3133                             {
       
  3134                             RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level3 Node not found %S", &aURI );
       
  3135                             ret = ENotFound;
       
  3136                             }
       
  3137                         }
       
  3138                 }
       
  3139             else
       
  3140                 if (numSeqs == 4)
       
  3141                     {
       
  3142                     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3143                     TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3144                     if (aParentLUID == KNullDesC8)
       
  3145                         {
       
  3146                         RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): WARNING possibly a illegal level 4 node %S", &aURI );
       
  3147                         ret = ENotFound;
       
  3148                         }
       
  3149 
       
  3150                     if (parentMapping == KAMDeliveredNodeName)
       
  3151                         {
       
  3152                         if (GetLuid2L(aParentLUID, mapping, EDCSDelivered,
       
  3153                                 ret) > 0)
       
  3154                             {
       
  3155                             currentList->InsertL( 0,
       
  3156                                     KAMInventoryDeliveredDynaChilds);
       
  3157                             ret = EOk;
       
  3158                             }
       
  3159                         }
       
  3160                     else
       
  3161                         if (parentMapping == KAMDeployedNodeName)
       
  3162                             {
       
  3163                             if (GetLuid2L(aParentLUID, mapping, EDCSActive,
       
  3164                                     ret) > 0)
       
  3165                                 {
       
  3166                                 currentList->InsertL( 0,
       
  3167                                         KAMInventoryDynaChilds);
       
  3168                                 ret = EOk;
       
  3169                                 }
       
  3170                             else
       
  3171                                 if (GetLuid2L(aParentLUID, mapping,
       
  3172                                         EDCSInactive, ret) > 0)
       
  3173                                     {
       
  3174                                     currentList->InsertL( 0,
       
  3175                                             KAMInventoryDynaChilds);
       
  3176                                     ret = EOk;
       
  3177                                     }
       
  3178                             }
       
  3179                         else
       
  3180                             if (mapping == KAMOperationsNodeName)
       
  3181                                 {
       
  3182                                 if (GetLuid2L(aParentLUID, parentMapping,
       
  3183                                         EDCSDownload, ret) > 0)
       
  3184                                     {
       
  3185                                     if (CheckStateL(aURI, aParentLUID) )
       
  3186                                         {
       
  3187                                         currentList->InsertL( 0,
       
  3188                                                 KAMDownloadOperationChilds);
       
  3189                                         ret = EOk;
       
  3190                                         }
       
  3191                                     else
       
  3192                                         {
       
  3193                                         RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level3 operations DC changed state '%S'", &aURI );
       
  3194                                         ret = ENotFound;
       
  3195                                         }
       
  3196                                     }
       
  3197                                 }
       
  3198                             else
       
  3199                                 {
       
  3200                                 RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level4 Node not found '%S'", &aURI );
       
  3201                                 ret = ENotFound;
       
  3202                                 }
       
  3203                     }
       
  3204                 else
       
  3205                     if (numSeqs == 5)
       
  3206                         {
       
  3207                         if (aParentLUID == KNullDesC8)
       
  3208                             {
       
  3209                             RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): WARNING possibly a illegal level 5 node %S", &aURI );
       
  3210                             ret = ENotFound;
       
  3211                             }
       
  3212                         if (mapping == KAMOperationsNodeName)
       
  3213                             {
       
  3214                             TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3215                             TPtrC8
       
  3216                                     parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3217                             TPtrC8 gparent(NSmlDmURI::RemoveLastSeg(parent) );
       
  3218                             TPtrC8
       
  3219                                     gparentMapping(NSmlDmURI::LastURISeg(gparent) );
       
  3220                             if (gparentMapping == KAMDeliveredNodeName)
       
  3221                                 {
       
  3222                                 if (GetLuid2L(aParentLUID, parentMapping,
       
  3223                                         EDCSDelivered, ret) > 0)
       
  3224                                     {
       
  3225                                     currentList->InsertL( 0,
       
  3226                                             KAMDeliveredOperationChilds);
       
  3227                                     ret = EOk;
       
  3228                                     }
       
  3229                                 }
       
  3230                             else
       
  3231                                 if (gparentMapping == KAMDeployedNodeName)
       
  3232                                     {
       
  3233                                     if (GetLuid2L(aParentLUID, parentMapping,
       
  3234                                             EDCSActive, ret) > 0)
       
  3235                                         {
       
  3236                                         currentList->InsertL( 0,
       
  3237                                                 KAMDeployedOperationChilds);
       
  3238                                         ret = EOk;
       
  3239                                         }
       
  3240                                     else
       
  3241                                         if (GetLuid2L(aParentLUID,
       
  3242                                                 parentMapping, EDCSInactive,
       
  3243                                                 ret) > 0)
       
  3244                                             {
       
  3245                                             currentList->InsertL( 0,
       
  3246                                                     KAMDeployedOperationChilds);
       
  3247                                             ret = EOk;
       
  3248                                             }
       
  3249                                     }
       
  3250                                 else
       
  3251                                     {
       
  3252                                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level5 Node not found wrong parent '%S'", &aURI );
       
  3253                                     ret = ENotFound;
       
  3254                                     }
       
  3255                             }
       
  3256                         else
       
  3257                             {
       
  3258                             RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level5 Node not found '%S'", &aURI );
       
  3259                             ret = ENotFound;
       
  3260                             }
       
  3261                         }
       
  3262                     else
       
  3263                         {
       
  3264                         RDEBUG8_3( "CSCOMOAdapter::ChildURIListL(): ILLEGAL LEVEL %d NODE %S", numSeqs, &aURI );
       
  3265                         ret = EError;
       
  3266                         }
       
  3267 
       
  3268     SetStatusL(aStatusRef, ret);
       
  3269 
       
  3270     if (ret == EOk)
       
  3271         {
       
  3272         if (iInAtomic)
       
  3273             {
       
  3274             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  3275             }
       
  3276         Callback().SetResultsL(aResultsRef, *currentList, KNullDesC8);
       
  3277         }
       
  3278     CleanupStack::PopAndDestroy(); //currentList
       
  3279     }
       
  3280 
       
  3281 // ------------------------------------------------------------------------------------------------
       
  3282 //  CSCOMOAdapter::DeliverOrDownloadL( const TDesC8 &aUserId, const TDesC8 &aURI, TInt aCnt, 
       
  3283 //		const TDesC8 &aParentMapping, MSmlDmAdapter::TError &aStatus )
       
  3284 // ------------------------------------------------------------------------------------------------
       
  3285 void CSCOMOAdapter::DeliverOrDownloadL(const TDesC8 &aUserId,
       
  3286         const TDesC8 &aURI, TInt aCnt, const TDesC8 &aParentMapping,
       
  3287         MSmlDmAdapter::TError &aStatus)
       
  3288     {
       
  3289 
       
  3290 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  3291     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  3292 #else
       
  3293     //Nothing
       
  3294 #endif
       
  3295 
       
  3296     switch (aCnt)
       
  3297         {
       
  3298         case 3:
       
  3299             {
       
  3300             if (aParentMapping == KAMDownloadNodeName)
       
  3301                 {
       
  3302                 TUint32 luid(SessionL().DownloadL(aUserId) );
       
  3303                 Callback().SetMappingL(aURI, *IntToDes8LC(luid) );
       
  3304                 CleanupStack::PopAndDestroy();
       
  3305                 aStatus = EOk;
       
  3306                 }
       
  3307             else
       
  3308                 {
       
  3309                 RDEBUG( "CSCOMOAdapter::DeliverOrDownloadL(): ERROR Illegal parent");
       
  3310                 }
       
  3311             break;
       
  3312             }
       
  3313         case 4:
       
  3314             {
       
  3315             if (aParentMapping == KAMDeliveredNodeName)
       
  3316                 {
       
  3317                 TUint32 luid(SessionL().DeliverL(aUserId) );
       
  3318                 Callback().SetMappingL(aURI, *IntToDes8LC(luid) );
       
  3319                 CleanupStack::PopAndDestroy();
       
  3320                 aStatus = EOk;
       
  3321                 }
       
  3322             else
       
  3323                 {
       
  3324                 RDEBUG( "CSCOMOAdapter::DeliverOrDownloadL(): ERROR Illegal parent");
       
  3325                 }
       
  3326             break;
       
  3327             }
       
  3328         default:
       
  3329             {
       
  3330             RDEBUG( "CSCOMOAdapter::DeliverOrDownloadL(): ERROR Illegal URI");
       
  3331             break;
       
  3332             }
       
  3333         }
       
  3334     }
       
  3335 
       
  3336 // ------------------------------------------------------------------------------------------------
       
  3337 // CSCOMOAdapter::AddNodeObjectL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3338 // ------------------------------------------------------------------------------------------------
       
  3339 void CSCOMOAdapter::AddNodeObjectL(const TDesC8& aURI,
       
  3340         const TDesC8& aParentLUID, TInt aStatusRef)
       
  3341     {
       
  3342 
       
  3343 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  3344     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  3345     TPtrC8 mapping( NSmlDmURI::LastURISeg( uriPtrc ) );
       
  3346     TPtrC8 parent( NSmlDmURI::RemoveLastSeg( uriPtrc ) );
       
  3347     TPtrC8 parentMapping( NSmlDmURI::LastURISeg( parent ) );
       
  3348     TInt cnt( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  3349 #else
       
  3350     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  3351     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3352     TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3353     TInt cnt(NSmlDmURI::NumOfURISegs(aURI) );
       
  3354 #endif
       
  3355 
       
  3356     RDEBUG8_3( "CSCOMOAdapter::AddNodeObjectL(): begin '%S', '%S'", &aURI, &aParentLUID );
       
  3357     SetAdapterValue(KAMSCOMOAdapter);
       
  3358     CheckStateChangesL();
       
  3359     TError status(EError);
       
  3360     //	TPtrC8 mapping( NSmlDmURI::LastURISeg( aURI ) );//Dipak
       
  3361     //	TPtrC8 parent( NSmlDmURI::RemoveLastSeg( aURI ) );
       
  3362     //	TPtrC8 parentMapping( NSmlDmURI::LastURISeg( parent ) );
       
  3363     //	TInt cnt( NSmlDmURI::NumOfURISegs( aURI ) );
       
  3364 	TUint32 iluid( GetLuidL( aParentLUID, mapping, (parentMapping == KAMDeliveredNodeName ? EDCSDelivered : ( parentMapping == KAMDownloadNodeName ? EDCSDownload : EDCSNone ) ) ) ) ;
       
  3365 	if( !iluid)
       
  3366 	    {
       
  3367             // This is added for avoiding duplicate node creation in Delivered/Download only.
       
  3368 	    iluid = GetLuidL( aParentLUID, mapping, (parentMapping == KAMDeliveredNodeName ? EDCSDownload:EDCSDelivered ));
       
  3369 	    }
       
  3370     if (iluid == 0)
       
  3371         {
       
  3372         // Not found, add it ... 
       
  3373         DeliverOrDownloadL(mapping, aURI, cnt, parentMapping, status);
       
  3374         }
       
  3375     else
       
  3376         {
       
  3377         RDEBUG_2( "CSCOMOAdapter::AddNodeObjectL(): WARNING May Already exists '%d'", iluid );
       
  3378         TDeploymentComponent comp;
       
  3379         TInt err(SessionL().DeploymentComponent(iluid, comp) );
       
  3380         if (err == KErrNone)
       
  3381             {
       
  3382             RDEBUG_2( "CSCOMOAdapter::AddNodeObjectL(): ERROR Already exists '%d'", iluid );
       
  3383             if (comp.iState == StateL(aURI) )
       
  3384                 {
       
  3385                 RDEBUG( "CSCOMOAdapter::AddNodeObjectL():    (state is ok) " );
       
  3386                 }
       
  3387             else
       
  3388                 {
       
  3389                 RDEBUG( "CSCOMOAdapter::AddNodeObjectL():    (state is NOK) " );
       
  3390                 }
       
  3391             status = EAlreadyExists;
       
  3392             }
       
  3393         else
       
  3394             {
       
  3395             if (err == KErrNotFound)
       
  3396                 {
       
  3397                 RDEBUG_2( "CSCOMOAdapter::AddNodeObjectL(): WARNING Already exists but not found '%d'", iluid );
       
  3398                 DeliverOrDownloadL(mapping, aURI, cnt, parentMapping, status);
       
  3399                 }
       
  3400             else
       
  3401                 {
       
  3402 
       
  3403                 RDEBUG_2( "CSCOMOAdapter::AddNodeObjectL(): ERROR May exists, but failed to fetch get one? '%d'", err );
       
  3404                 }
       
  3405             }
       
  3406         }
       
  3407     if (status == EOk)
       
  3408         {
       
  3409         if (iInAtomic)
       
  3410             {
       
  3411             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  3412             }
       
  3413         }
       
  3414 
       
  3415     //status = EAcceptedForProcessing;
       
  3416     //TInt error = 202;
       
  3417     SetStatusL(aStatusRef, status);
       
  3418     RDEBUG( "CSCOMOAdapter::AddNodeObject(): end" );
       
  3419     }
       
  3420 
       
  3421 // ------------------------------------------------------------------------------------------------
       
  3422 // CSCOMOAdapter::GetSizeL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3423 // ------------------------------------------------------------------------------------------------
       
  3424 TInt CSCOMOAdapter::GetSizeL(const TDeplCompAttrType aDataType,
       
  3425         const TInt aLuid, TError &aRet)
       
  3426     {
       
  3427     TInt size( 0);
       
  3428     if (aDataType == EDCStateValue)
       
  3429         {
       
  3430         TDeploymentComponent comp;
       
  3431         TInt err(SessionL().DeploymentComponent(aLuid, comp) );
       
  3432         if (err == KErrNone)
       
  3433             {
       
  3434             if (comp.iState == EDCSActive)
       
  3435                 {
       
  3436                 size = KAMStateValueActive().Length();
       
  3437                 }
       
  3438             else if (comp.iState == EDCSDelivered)
       
  3439                 {
       
  3440                 size = KAMStateValueDelivered().Length();
       
  3441                 }
       
  3442             else
       
  3443                 {
       
  3444                 size = KAMStateValueInactive().Length() ;
       
  3445                 }
       
  3446             aRet = EOk;
       
  3447             }
       
  3448         }
       
  3449     else
       
  3450         {
       
  3451         size = SessionL().DeploymentComponentDataSizeL(aLuid, aDataType);
       
  3452         aRet = EOk;
       
  3453         }
       
  3454     return size;
       
  3455     }
       
  3456 
       
  3457 // ------------------------------------------------------------------------------------------------
       
  3458 // CSCOMOAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3459 // ------------------------------------------------------------------------------------------------
       
  3460 void CSCOMOAdapter::FetchLeafObjectSizeL(const TDesC8& aURI,
       
  3461         const TDesC8& aLUID, const TDesC8& aType, TInt aResultsRef,
       
  3462         TInt aStatusRef)
       
  3463     {
       
  3464 
       
  3465     RDEBUG8_4("CSCOMOAdapter::FetchLeafObjectSizeL('%S', '%S', '%S'): begin", &aURI, &aLUID, &aType );
       
  3466     CheckStateChangesL();
       
  3467     TError status(EError);
       
  3468     CBufBase *currentList = CBufFlat::NewL( 128);
       
  3469     CleanupStack::PushL(currentList);
       
  3470 
       
  3471     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  3472     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3473     TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3474     TInt size( 0);
       
  3475     HBufC8 *luid= NULL;
       
  3476     if (aLUID != KNullDesC8)
       
  3477         {
       
  3478         luid = aLUID.AllocLC();
       
  3479         }
       
  3480     else
       
  3481         { // try if we find it from download path
       
  3482         TBuf8<256> down;
       
  3483         down = KDownloadURI;
       
  3484         down.Append(parentMapping);
       
  3485         luid = Callback().GetLuidAllocL(down);
       
  3486         CleanupStack::PushL(luid);
       
  3487         if ( *luid != KNullDesC8)
       
  3488             {
       
  3489             // make it to found next time
       
  3490             DirectSetMappingL(parent, *luid);
       
  3491             MoveAclL(down, parent);
       
  3492 
       
  3493             // remove old
       
  3494             DirectSetMappingL(down, KNullDesC8);
       
  3495             }
       
  3496         }
       
  3497     TDeplCompAttrType dataType(UpdateFlagFromMapping(mapping) );
       
  3498     if ( *luid != KNullDesC8)
       
  3499         {
       
  3500         TUint32 iluid(DesToIntL( *luid ));
       
  3501         RDEBUG_2( "CSCOMOAdapter::FetchLeafObjectSizeL(): Luid is : %d", iluid );
       
  3502         size = GetSizeL(dataType, iluid, status);
       
  3503         }
       
  3504     else
       
  3505         {
       
  3506         TUint32 iluid(GetLeafLuidL(aURI, parentMapping) );
       
  3507         if (iluid > 0)
       
  3508             {
       
  3509             HBufC8 *l = IntToDes8LC(iluid);
       
  3510             DirectSetMappingL(parent, *l);
       
  3511             CleanupStack::PopAndDestroy(l);
       
  3512             size = GetSizeL(dataType, iluid, status);
       
  3513             }
       
  3514         else
       
  3515             {
       
  3516             RDEBUG8_2( "CSCOMOAdapter::FetchLeafObjectSizeL(): WARNING Faild to get luid allocation for '%S'", &parent );
       
  3517             if (aLUID == KNullDesC8)
       
  3518                 {
       
  3519                 status = ENotFound;
       
  3520                 }
       
  3521             }
       
  3522         }
       
  3523     SetStatusL(aStatusRef, status);
       
  3524     if (status == EOk && size > 0)
       
  3525         {
       
  3526         HBufC8 *hsize = IntToDes8LC(size);
       
  3527         currentList->InsertL( 0, *hsize);
       
  3528         if (iInAtomic)
       
  3529             {
       
  3530             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  3531             }
       
  3532         Callback().SetResultsL(aResultsRef, *currentList, aType);
       
  3533         CleanupStack::PopAndDestroy(hsize);
       
  3534         }
       
  3535     CleanupStack::PopAndDestroy(luid);
       
  3536     CleanupStack::PopAndDestroy(currentList); //currentList	
       
  3537     }
       
  3538 
       
  3539 // ------------------------------------------------------------------------------------------------
       
  3540 // CSCOMOAdapter::ExecuteCommandL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3541 // ------------------------------------------------------------------------------------------------
       
  3542 void CSCOMOAdapter::ExecuteCommandL(const TDesC8& /*aURI*/,
       
  3543         const TDesC8& /*aLUID*/, RWriteStream*& /*aStream*/,
       
  3544         const TDesC8& /*aType*/, TInt /*aStatusRef*/)
       
  3545     {
       
  3546     RDEBUG("CSCOMOAdapter::ExecuteCommandL(stream): begin (NOT SUPPORTED)");
       
  3547     User::Leave(KErrNotSupported);
       
  3548     }
       
  3549 
       
  3550 // ------------------------------------------------------------------------------------------------
       
  3551 // CSCOMOAdapter::CopyCommandL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3552 // ------------------------------------------------------------------------------------------------
       
  3553 void CSCOMOAdapter::CopyCommandL(const TDesC8& /*aTargetURI*/,
       
  3554         const TDesC8& /*aTargetLUID*/, const TDesC8& /*aSourceURI*/,
       
  3555         const TDesC8& /*aSourceLUID*/, const TDesC8& /*aType*/,
       
  3556         TInt aStatusRef)
       
  3557     {
       
  3558     RDEBUG("CSCOMOAdapter::CopyCommandL(): begin (NOT SUPPORTED)");
       
  3559     SetStatusL(aStatusRef, EError);
       
  3560 
       
  3561     }
       
  3562 
       
  3563 // ------------------------------------------------------------------------------------------------
       
  3564 // CSCOMOAdapter::StartAtomicL(  )
       
  3565 // ------------------------------------------------------------------------------------------------
       
  3566 void CSCOMOAdapter::StartAtomicL()
       
  3567     {
       
  3568     RDEBUG("CSCOMOAdapter::StartAtomicL(): begin (NOT properly SUPPORTED)");
       
  3569     iInAtomic = ETrue;
       
  3570     }
       
  3571 
       
  3572 // ------------------------------------------------------------------------------------------------
       
  3573 // CSCOMOAdapter::CommitAtomicL(  )
       
  3574 // ------------------------------------------------------------------------------------------------
       
  3575 void CSCOMOAdapter::CommitAtomicL()
       
  3576     {
       
  3577     RDEBUG("CSCOMOAdapter::CommitAtomicL(): begin (NOT SUPPORTED)");
       
  3578     iInAtomic = EFalse; // the initial statuses are already set
       
  3579     }
       
  3580 
       
  3581 // ------------------------------------------------------------------------------------------------
       
  3582 // CSCOMOAdapter::RollbackAtomicL(  )
       
  3583 // ------------------------------------------------------------------------------------------------
       
  3584 void CSCOMOAdapter::RollbackAtomicL()
       
  3585     {
       
  3586     RDEBUG("CSCOMOAdapter::RollbackAtomicL(): begin (NOT properly SUPPORTED)");
       
  3587     TInt count(iBuffer.Count() );
       
  3588     for (TInt i( 0); i < count; i++)
       
  3589         {
       
  3590         TAMCommandBufferElement &pm(iBuffer[i]);
       
  3591         SetStatusL(pm.iStatusRef, ERollbackFailed);
       
  3592         }
       
  3593     }
       
  3594 
       
  3595 // ------------------------------------------------------------------------------------------------
       
  3596 // CSCOMOAdapter::StreamingSupport( )
       
  3597 // ------------------------------------------------------------------------------------------------
       
  3598 TBool CSCOMOAdapter::StreamingSupport(TInt& aItemSize)
       
  3599     {
       
  3600     RDEBUG("CSCOMOAdapter::StreamingSupport(): begin");
       
  3601     //aItemSize = 1024;
       
  3602     
       
  3603     // After Generic alert is sent delete that entry from database and notify
       
  3604     // AM server to delete the appropriate entry in its database.
       
  3605     
       
  3606     if(aItemSize == KNSmlDMResetGenAlerts)
       
  3607     {
       
  3608       TSmlProfileId profId = 0;
       
  3609       HBufC8* serverId = NULL;
       
  3610       TRAP_IGNORE(GetServerInfoL( profId, serverId ));
       
  3611       
       
  3612     
       
  3613     TUint32 internalid;
       
  3614     RPointerArray<CAMDbItem> genericalerts;
       
  3615     
       
  3616 
       
  3617     // Get generic alert entry from Database for particular server ID.
       
  3618     TRAPD(err, iAMdb->GetEntryForServerIDL(genericalerts, *serverId));
       
  3619 
       
  3620     if (genericalerts.Count()!= KErrNone && err == KErrNone)
       
  3621         {
       
  3622           	for(TInt i=0; i<genericalerts.Count(); i++)
       
  3623     		{
       
  3624 			internalid = genericalerts[i]->iLUID;
       
  3625 			// Delete the all the generic alert details from SCOMO adapeter DB
       
  3626 			// Also delete the appropriate entry from AM Server DB as well.
       
  3627             TRAP_IGNORE(iAMdb->DeleteFromDatabaseL(internalid));
       
  3628             TRAP_IGNORE(SessionL().GenericAlertSentL(internalid));
       
  3629     		}
       
  3630         }
       
  3631     
       
  3632 
       
  3633     genericalerts.ResetAndDestroy();
       
  3634     delete serverId;
       
  3635 
       
  3636     _LIT(KNull,"");
       
  3637     // No monitoring required after generic alert is sent
       
  3638     TInt err_rep = KErrNone;
       
  3639     CRepository *repository1 = NULL;
       
  3640 
       
  3641     TRAP(err_rep, repository1 =CRepository::NewL ( KCRUidDeviceManagementInternalKeys ));
       
  3642   
       
  3643     if(err_rep == KErrNone)  
       
  3644     {
       
  3645     repository1 ->Set(KDevManServerIdKey ,KNull);
       
  3646     repository1 ->Set(KDevManIapIdKey, KErrNone);
       
  3647     repository1 ->Set(KDevManEnableDMNetworkMon, KErrNone);
       
  3648     }
       
  3649      
       
  3650     if(repository1)
       
  3651      delete repository1;
       
  3652       
       
  3653     }
       
  3654     aItemSize = 1024;
       
  3655     RDEBUG("CSCOMOAdapter::StreamingSupport(): end");
       
  3656     return ETrue;
       
  3657     }
       
  3658 
       
  3659 // ------------------------------------------------------------------------------------------------
       
  3660 // CSCOMOAdapter::StreamCommittedL( )
       
  3661 // ------------------------------------------------------------------------------------------------
       
  3662 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  3663 void CSCOMOAdapter::StreamCommittedL( RWriteStream& /*aStream*/)
       
  3664 #else
       
  3665 void CSCOMOAdapter::StreamCommittedL()
       
  3666 #endif
       
  3667     {
       
  3668     RDEBUG("CSCOMOAdapter::StreamCommittedL(): begin");
       
  3669 
       
  3670     if (iStreamOpen)
       
  3671         {
       
  3672         iStream.CommitL();
       
  3673         }
       
  3674 
       
  3675     MSmlDmAdapter::TError status = EOk;
       
  3676 
       
  3677     TRAPD( err, _UpdateLeafObjectL( *iStreamedURI, *iStreamedLuid, KNullDesC8(), *iStreamedType, iStatusRef, status ) )
       
  3678     ;
       
  3679 
       
  3680     if (err != KErrNone)
       
  3681         {
       
  3682         RDEBUG_2("CSCOMOAdapter::StreamCommittedL(): _UpdateLeafObjectL returned error (%d)", err);
       
  3683         }
       
  3684 
       
  3685     iIsStreamedContent = EFalse;
       
  3686     iStreamOpen = EFalse;
       
  3687 
       
  3688     Callback().SetStatusL(iStatusRef, status);
       
  3689 
       
  3690     RDEBUG("CSCOMOAdapter::StreamCommittedL(): end");
       
  3691     }
       
  3692 
       
  3693 // ------------------------------------------------------------------------------------------------
       
  3694 // CSCOMOAdapter::CloseStreaming( )
       
  3695 // ------------------------------------------------------------------------------------------------
       
  3696 void CSCOMOAdapter::CloseStreaming()
       
  3697     {
       
  3698     if (iStreamOpen)
       
  3699         {
       
  3700         RDEBUG("CSCOMOAdapter::CloseStreaming(): closing");
       
  3701         iStreamFile.Close(); // !!! Closing this will also close the iStreamRFs because it is adopted from server
       
  3702         iStreamOpen = EFalse;
       
  3703         }
       
  3704     }
       
  3705 
       
  3706 // ------------------------------------------------------------------------------------------------
       
  3707 // CSCOMOAdapter::CompleteOutstandingCmdsL()
       
  3708 // ------------------------------------------------------------------------------------------------
       
  3709 void CSCOMOAdapter::CompleteOutstandingCmdsL()
       
  3710     {
       
  3711     RDEBUG("CSCOMOAdapter::CompleteOutstandingCmdsL(): begin");
       
  3712     /*	iManagement.Close();
       
  3713      iSessionOpened = EFalse ;*/
       
  3714     iBuffer.Reset();
       
  3715     RDEBUG("CSCOMOAdapter::CompleteOutstandingCmdsL(): Management session closed");
       
  3716     }
       
  3717 
       
  3718 // ------------------
       
  3719 //
       
  3720 // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       
  3721 const TImplementationProxy ImplementationTable[] =
       
  3722     {
       
  3723     //
       
  3724             IMPLEMENTATION_PROXY_ENTRY( KAMAdapterImplUid, CSCOMOAdapter::NewL )
       
  3725     };
       
  3726 
       
  3727 // ------------------------------------------------------------------------------------------------
       
  3728 //
       
  3729 // ------------------------------------------------------------------------------------------------
       
  3730 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
  3731     {
       
  3732     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
  3733     return ImplementationTable;
       
  3734     }
       
  3735 
       
  3736 // ------------------------------------------------------------------------------------------------
       
  3737 //
       
  3738 // ------------------------------------------------------------------------------------------------
       
  3739 TInt CSCOMOAdapter::DesToIntL(const TDesC8& aLuid)
       
  3740     {
       
  3741     TLex8 lex(aLuid);
       
  3742     TInt value = 0;
       
  3743     User::LeaveIfError(lex.Val(value) );
       
  3744     return value;
       
  3745     }
       
  3746 
       
  3747 // ------------------------------------------------------------------------------------------------
       
  3748 //
       
  3749 // ------------------------------------------------------------------------------------------------
       
  3750 HBufC8* CSCOMOAdapter::IntToDes8LC(const TInt aLuid)
       
  3751     {
       
  3752     HBufC8* buf = HBufC8::NewLC( 10); //10 = max length of 32bit integer
       
  3753     TPtr8 ptrBuf = buf->Des();
       
  3754     ptrBuf.Num(aLuid);
       
  3755     return buf;
       
  3756     }
       
  3757 
       
  3758 // ------------------------------------------------------------------------------------------------
       
  3759 //
       
  3760 // ------------------------------------------------------------------------------------------------
       
  3761 void CSCOMOAdapter::ConstructL()
       
  3762     {
       
  3763     iAMdb = CSCOMOAdapterDb::NewL();
       
  3764 
       
  3765 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  3766     iDbSession.ConnectL();
       
  3767 #else
       
  3768     User::LeaveIfError(iDbSession.Connect());
       
  3769 #endif
       
  3770     }
       
  3771 
       
  3772 // ------------------------------------------------------------------------------------------------
       
  3773 // CSCOMOAdapter::SetStatusL( TInt aStatusRef, MSmlDmAdapter::TError aErrorCode ) 
       
  3774 // ------------------------------------------------------------------------------------------------
       
  3775 void CSCOMOAdapter::SetStatusL(TInt aStatusRef,
       
  3776         MSmlDmAdapter::TError aErrorCode)
       
  3777     {
       
  3778     RDEBUG_3("CSCOMOAdapter::SetStatusL( %d, %d )", aStatusRef, aErrorCode );
       
  3779     Callback().SetStatusL(aStatusRef, aErrorCode);
       
  3780     }
       
  3781 
       
  3782 // ------------------------------------------------------------------------------------------------
       
  3783 // CSCOMOAdapter::SetResultsL( TInt aResultsRef, CBufBase& aObject, const TDesC8& aType )
       
  3784 // ------------------------------------------------------------------------------------------------
       
  3785 void CSCOMOAdapter::SetResultsL(TInt aResultsRef, CBufBase& aObject,
       
  3786         const TDesC8& aType)
       
  3787     {
       
  3788     Callback().SetResultsL(aResultsRef, aObject, aType);
       
  3789 
       
  3790     }
       
  3791 
       
  3792 // -------------------------------------------------------------------------------------
       
  3793 // CSCOMOAdapter::FillNodeInfoL()
       
  3794 // Fills the node info in ddf structure
       
  3795 // -------------------------------------------------------------------------------------
       
  3796 void CSCOMOAdapter::FillNodeInfoL(MSmlDmDDFObject& aNode,
       
  3797         TSmlDmAccessTypes aAccTypes, MSmlDmDDFObject::TOccurence aOccurrence,
       
  3798         MSmlDmDDFObject::TScope aScope, MSmlDmDDFObject::TDFFormat aFormat,
       
  3799         const TDesC8& aDescription)
       
  3800     {
       
  3801     FillNodeInfoNoDefaultMimeL(aNode, aAccTypes, aOccurrence, aScope,
       
  3802             aFormat, aDescription);
       
  3803     if (aFormat!=MSmlDmDDFObject::ENode)
       
  3804         {
       
  3805         aNode.AddDFTypeMimeTypeL(KAMTextPlain);
       
  3806         }
       
  3807 
       
  3808     }
       
  3809 
       
  3810 // -------------------------------------------------------------------------------------
       
  3811 // CSCOMOAdapter::FillNodeInfoNoDefaultMimeL()
       
  3812 // Fills the node info in ddf structure, without default mime type
       
  3813 // -------------------------------------------------------------------------------------
       
  3814 void CSCOMOAdapter::FillNodeInfoNoDefaultMimeL(MSmlDmDDFObject& aNode,
       
  3815         TSmlDmAccessTypes aAccTypes, MSmlDmDDFObject::TOccurence aOccurrence,
       
  3816         MSmlDmDDFObject::TScope aScope, MSmlDmDDFObject::TDFFormat aFormat,
       
  3817         const TDesC8& aDescription)
       
  3818     {
       
  3819     aNode.SetAccessTypesL(aAccTypes);
       
  3820     aNode.SetOccurenceL(aOccurrence);
       
  3821     aNode.SetScopeL(aScope);
       
  3822     aNode.SetDFFormatL(aFormat);
       
  3823 
       
  3824     aNode.SetDescriptionL(aDescription);
       
  3825     }
       
  3826 
       
  3827 // -------------------------------------------------------------------------------------
       
  3828 // CSCOMOAdapter::CheckStateChangesInternalL()
       
  3829 // Updates the changed DC states to DM client mappings and ACLs
       
  3830 // -------------------------------------------------------------------------------------
       
  3831 void CSCOMOAdapter::CheckStateChangesInternalL()
       
  3832     {
       
  3833 
       
  3834 #ifdef __AM_CHECKSTATE_CHANGES
       
  3835     RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): begin" );
       
  3836     if ( !iUpdated)
       
  3837         {
       
  3838         RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): !iUpdated" );
       
  3839         RElementIdArray arr;
       
  3840         CleanupClosePushL(arr);
       
  3841 		SessionL().CheckStatusNodesL();
       
  3842 		RElementIdArray array;
       
  3843 		TInt err( SessionL().DeploymentComponentIdsL( array, EDCSActive ) ); //to sync with SIS/Java registry
       
  3844 		err = SessionL().DeploymentComponentIdsL( array, EDCSInactive ); //to sync with SIS/Java registry
       
  3845 		CleanupClosePushL(array);
       
  3846         err = SessionL().StateChangingDCIdsL(arr);
       
  3847         if (err == KErrNone)
       
  3848             {
       
  3849             TInt c(arr.Count() );
       
  3850             for (TInt i( 0); i < c; i++)
       
  3851                 {
       
  3852                 TDeploymentComponent comp;
       
  3853                 err = iManagement.DeploymentComponent(arr[i], comp);
       
  3854                 if (err == KErrNone)
       
  3855                     {
       
  3856                     TDCUserId dc;
       
  3857                     SessionL().DeploymentComponentUserIdL(arr[i], dc);
       
  3858                     const TInt KNSmlDmMaxUriLength = 256;
       
  3859                     HBufC8 *uri = HBufC8::NewLC(KNSmlDmMaxUriLength);
       
  3860                     TPtr8 puri(uri->Des() );
       
  3861 #ifdef __TARM_SYMBIAN_CONVERGENCY					
       
  3862                     RDmTreeNode uriNode;
       
  3863                     CleanupClosePushL(uriNode);
       
  3864 
       
  3865                     RBuf8 acl;
       
  3866                     acl.CreateL(128);
       
  3867                     CleanupClosePushL(acl);
       
  3868 
       
  3869                     HBufC8 *newUri = HBufC8::NewLC( KNSmlDmMaxUriLength );
       
  3870                     TPtr8 pnewUri( newUri->Des() );
       
  3871 
       
  3872                     RDmTreeNode newUriNode;
       
  3873                     CleanupClosePushL(newUriNode);
       
  3874 #else
       
  3875                     CBufBase* acl = CBufFlat::NewL( 128);
       
  3876                     CleanupStack::PushL(acl);
       
  3877 
       
  3878                     HBufC8 *newUri = HBufC8::NewLC(KNSmlDmMaxUriLength);
       
  3879                     TPtr8 pnewUri(newUri->Des() );
       
  3880 
       
  3881 #endif
       
  3882 
       
  3883                     switch (comp.iOldState)
       
  3884                         {
       
  3885                         case EDCSDelivered:
       
  3886                             {
       
  3887                             RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): Old State = EDCSDelivered" );
       
  3888                             puri.Copy(KDeliveredURI() );
       
  3889                             puri.Append(dc);
       
  3890 
       
  3891                             HBufC8 *luid = DirectGetLuidAllocLC(puri);
       
  3892 
       
  3893                             if ( *luid == KNullDesC8)
       
  3894                                 { // probably moved already
       
  3895                                 iManagement.StateChangeComplete(arr[i]);
       
  3896                                 }
       
  3897                             else
       
  3898                                 {
       
  3899                                 // "Nullify" the old mapping 
       
  3900 								//DirectSetMappingL( puri, KNullDesC8 );
       
  3901 								DirectRemoveMappingL(puri);
       
  3902 #ifdef __TARM_SYMBIAN_CONVERGENCY								
       
  3903                                 iDbSession.OpenNodeL(puri, uriNode, RDmTree::EReadOnly);
       
  3904                                 uriNode.DmPropertyL( DevMan::EACL, acl );
       
  3905 #else
       
  3906                                 err = iDbSession.GetAclL(puri, *acl, EFalse); // no need for inherited
       
  3907 #endif										
       
  3908                                 // Determine new uri 
       
  3909                                 switch (comp.iState)
       
  3910                                     {
       
  3911                                     case EDCSActive:
       
  3912                                     case EDCSInactive: // both have same node
       
  3913                                         {
       
  3914                                         pnewUri.Copy(KDeployedURI() );
       
  3915                                         pnewUri.Append(dc);
       
  3916                                         DirectSetMappingL(pnewUri, *luid);
       
  3917                                         if (err == KErrNone)
       
  3918                                             {
       
  3919 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  3920                                             iDbSession.OpenNodeL(pnewUri, newUriNode, RDmTree::EReadOnly);
       
  3921                                             uriNode.RemoveDmPropertyL( DevMan::EACL );
       
  3922                                             newUriNode.SetDmPropertyL( DevMan::EACL, acl );
       
  3923 #else
       
  3924                                             err = iDbSession.DeleteAclL(puri);
       
  3925 
       
  3926                                             err = iDbSession.UpdateAclL(
       
  3927                                                     pnewUri, acl->Ptr( 0) );
       
  3928 #endif
       
  3929                                             }
       
  3930                                         else
       
  3931                                             {
       
  3932                                             RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get acl from %d ", err );
       
  3933                                             }
       
  3934                                         iManagement.StateChangeComplete(arr[i]);
       
  3935                                         break;
       
  3936                                         }
       
  3937                                     default:
       
  3938                                         {
       
  3939 
       
  3940                                         RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: WARNING Illegal state change from delivered to %d ", comp.iState );
       
  3941 
       
  3942                                         break;
       
  3943                                         }
       
  3944                                     }
       
  3945                                 }
       
  3946                             CleanupStack::PopAndDestroy(luid);
       
  3947                             break;
       
  3948                             }
       
  3949                         case EDCSDownload:
       
  3950                             {
       
  3951                             RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): Old State = EDCSDownload" );
       
  3952                             puri.Copy(KDownloadURI() );
       
  3953                             //check DC contains SCOMODefault.
       
  3954                             TBuf8<256> staticnode;
       
  3955                             TInt staticnodeenabled = 0;
       
  3956                             CRepository* cenrep = CRepository::NewLC( KCRUidPrivateApplicationManagementKeys );
       
  3957                             cenrep->Get( KAMDownloadPredefinedNode, staticnode ); 
       
  3958                             cenrep->Get( KAMStaticNodeEnabled, staticnodeenabled );
       
  3959                             CleanupStack::PopAndDestroy(); //cenrep
       
  3960                             if (dc.Find(staticnode) != KErrNotFound && staticnodeenabled)
       
  3961                                 {
       
  3962                                 puri.Append(staticnode);
       
  3963                                 }
       
  3964                             else
       
  3965                                 {
       
  3966                                 puri.Append(dc);
       
  3967                                 }
       
  3968 
       
  3969 
       
  3970                             HBufC8 *luid = DirectGetLuidAllocLC(puri); //Callback().GetLuidAllocL( puri );
       
  3971                             //CleanupStack::PushL( luid );
       
  3972                             if ( *luid == KNullDesC8)
       
  3973                                 { // probably moved already
       
  3974                                 CleanupStack::PopAndDestroy(luid);
       
  3975                                 puri.Copy(KDeliveredURI() );
       
  3976                                 puri.Append(dc);
       
  3977                                 luid = DirectGetLuidAllocLC(puri); //Callback().GetLuidAllocL( puri );
       
  3978                                 if ( *luid == KNullDesC8)
       
  3979                                     { // probably moved already
       
  3980 
       
  3981                                     iManagement.StateChangeComplete(arr[i]);
       
  3982 
       
  3983                                     }
       
  3984                                 }
       
  3985                             else
       
  3986                                 {
       
  3987 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  3988                                 iDbSession.OpenNodeL(puri, uriNode, RDmTree::EReadOnly);
       
  3989                                 uriNode.DmPropertyL( DevMan::EACL, acl );
       
  3990 #else
       
  3991                                 err = iDbSession.GetAclL(puri, *acl, EFalse); // no need for inherited
       
  3992 #endif							
       
  3993                                 // "Nullify" the old mapping 
       
  3994 								//DirectSetMappingL( puri, KNullDesC8 );
       
  3995 								DirectRemoveMappingL(puri);
       
  3996                                 switch (comp.iState)
       
  3997                                     {
       
  3998                                     case EDCSActive:
       
  3999                                     case EDCSInactive: // both have same node
       
  4000                                         {
       
  4001                                         pnewUri.Copy(KDeployedURI() );
       
  4002                                         pnewUri.Append(dc);
       
  4003                                         DirectSetMappingL(pnewUri, *luid);
       
  4004                                         if (err == KErrNone)
       
  4005                                             {
       
  4006 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4007                                             iDbSession.OpenNodeL(pnewUri, newUriNode, RDmTree::EReadOnly);
       
  4008                                             uriNode.RemoveDmPropertyL( DevMan::EACL );
       
  4009                                             newUriNode.SetDmPropertyL( DevMan::EACL, acl );
       
  4010 #else											
       
  4011                                             err = iDbSession.DeleteAclL(puri);
       
  4012                                             err = iDbSession.UpdateAclL(
       
  4013                                                     pnewUri, acl->Ptr( 0) );
       
  4014 #endif
       
  4015                                             }
       
  4016                                         else
       
  4017                                             {
       
  4018                                             RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get acl from %d ", err );
       
  4019                                             }
       
  4020                                         iManagement.StateChangeComplete(arr[i]);
       
  4021                                         break;
       
  4022                                         }
       
  4023                                     case EDCSDelivered:
       
  4024                                         {
       
  4025                                         RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): Current State = EDCSDelivered" );
       
  4026                                         pnewUri.Copy(KDeliveredURI() );
       
  4027                                         pnewUri.Append(dc);
       
  4028                                         DirectSetMappingL(pnewUri, *luid);
       
  4029                                         if (err == KErrNone)
       
  4030                                             {
       
  4031 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4032                                             iDbSession.OpenNodeL(pnewUri, newUriNode, RDmTree::EReadOnly);
       
  4033                                             uriNode.RemoveDmPropertyL( DevMan::EACL );
       
  4034                                             newUriNode.SetDmPropertyL( DevMan::EACL, acl );
       
  4035 #else
       
  4036 
       
  4037                                             err = iDbSession.DeleteAclL(puri);
       
  4038                                             err = iDbSession.UpdateAclL(
       
  4039                                                     pnewUri, acl->Ptr( 0) );
       
  4040 #endif
       
  4041                                             }
       
  4042                                         else
       
  4043                                             {
       
  4044                                             RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get acl from %d ", err );
       
  4045                                             }
       
  4046                                         iManagement.StateChangeComplete(arr[i]);
       
  4047                                         break;
       
  4048                                         }
       
  4049                                     default:
       
  4050                                         {
       
  4051 
       
  4052                                         RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: WARNING Illegal state change from delivered to %d ", comp.iState );
       
  4053                                         break;
       
  4054                                         }
       
  4055                                     }
       
  4056 
       
  4057                                 }
       
  4058                             CleanupStack::PopAndDestroy(luid);
       
  4059                             break;
       
  4060                             }
       
  4061                         case EDCSActive:
       
  4062                         case EDCSInactive: // these both are in same node
       
  4063                             {
       
  4064 
       
  4065                             RDEBUG_3("CSCOMOAdapter::CheckStateChangesL: No need to move anything in change from %d to %d ", comp.iOldState, comp.iState );
       
  4066                             iManagement.StateChangeComplete(arr[i]);
       
  4067                             break;
       
  4068                             }
       
  4069                         }
       
  4070 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4071                     CleanupStack::PopAndDestroy( &newUriNode );
       
  4072                     CleanupStack::PopAndDestroy( newUri );
       
  4073                     CleanupStack::PopAndDestroy( &uriNode );
       
  4074                     CleanupStack::PopAndDestroy( &acl );
       
  4075                     CleanupStack::PopAndDestroy( uri );
       
  4076 #else
       
  4077                     CleanupStack::PopAndDestroy(newUri);
       
  4078                     CleanupStack::PopAndDestroy(acl);
       
  4079                     CleanupStack::PopAndDestroy(uri);
       
  4080 #endif
       
  4081                     }
       
  4082                 else
       
  4083                     {
       
  4084                     RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get component: %d ", err );
       
  4085                     }
       
  4086                 }
       
  4087             iUpdated = ETrue;
       
  4088             }
       
  4089         else
       
  4090             {
       
  4091             RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get state change dcs: %d ", err );
       
  4092             }
       
  4093         CleanupStack::PopAndDestroy( &array);
       
  4094         CleanupStack::PopAndDestroy( &arr);
       
  4095         }
       
  4096     else
       
  4097         {
       
  4098         RDEBUG("CSCOMOAdapter::CheckStateChangesL: Already updated! ");
       
  4099         }
       
  4100     RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): end" );
       
  4101 #else
       
  4102     DBG_ARGS8( "CSCOMOAdapter::CheckStateChangesL(): disabled" );
       
  4103 #endif
       
  4104     }
       
  4105 
       
  4106 // -------------------------------------------------------------------------------------
       
  4107 // CSCOMOAdapter::CheckStateChangesL()
       
  4108 // Updates acl and mapping trees to match state changes
       
  4109 // -------------------------------------------------------------------------------------
       
  4110 void CSCOMOAdapter::CheckStateChangesL()
       
  4111     {
       
  4112     iCertRequired = EFalse;
       
  4113     RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): iCertRequired = EFalse" );
       
  4114     TRAPD( err, CheckStateChangesInternalL() )
       
  4115     ;
       
  4116     if (err != KErrNone)
       
  4117         {
       
  4118         RDEBUG_2("CSCOMOAdapter::CheckStateChangesL(): warning failed to check state changes %d", err );
       
  4119         }
       
  4120     iCertRequired = ETrue;
       
  4121     RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): iCertRequired = ETrue" );
       
  4122     if ( !iTrustAdded)
       
  4123         {
       
  4124         RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): Adding Trust Closing Session" );
       
  4125         iManagement.Close();
       
  4126         iSessionOpened = EFalse;
       
  4127         RApplicationManagement &session = SessionL();
       
  4128         RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): Adding Trust new session started" );
       
  4129         }
       
  4130     }
       
  4131 
       
  4132 // -------------------------------------------------------------------------------------
       
  4133 // CSCOMOAdapter::URISegsUpTo(const TDesC8& aURI, TInt aUpTo)
       
  4134 // -------------------------------------------------------------------------------------
       
  4135 TPtrC8 CSCOMOAdapter::URISegsUpTo(const TDesC8& aURI, TInt aUpTo,
       
  4136         TBool aInclKeno/*=EFalse*/)
       
  4137     {
       
  4138 
       
  4139     TPtrC8 ret;
       
  4140     TInt numOfURISegs( 0);
       
  4141     for (TInt i( 0); i < aURI.Length() && ret.Ptr() == NULL; i++)
       
  4142         {
       
  4143         if (aURI[i] == KNSmlDMUriSeparator)
       
  4144             {
       
  4145             numOfURISegs++;
       
  4146             if (aUpTo == numOfURISegs)
       
  4147                 {
       
  4148                 if (aInclKeno && aURI.Length() > i+1)
       
  4149                     {
       
  4150                     ret.Set(aURI.Left(i + 1) );
       
  4151                     }
       
  4152                 else
       
  4153                     {
       
  4154                     ret.Set(aURI.Left(i) );
       
  4155                     }
       
  4156                 }
       
  4157             }
       
  4158         }
       
  4159     return ret;
       
  4160     }
       
  4161 
       
  4162 // -------------------------------------------------------------------------------------
       
  4163 // CSCOMOAdapter::DirectGetLuidAllocLC( const TDesC8 &aURI )
       
  4164 // -------------------------------------------------------------------------------------	
       
  4165 HBufC8 *CSCOMOAdapter::DirectGetLuidAllocLC(const TDesC8 &aURI)
       
  4166     {
       
  4167 
       
  4168 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4169     HBufC8 *ret = Callback().GetLuidAllocL( aURI );
       
  4170 #else
       
  4171     HBufC8* ret = iDbSession.GetLuidAllocL(KAMAdapterImplUid, aURI);
       
  4172 #endif
       
  4173 
       
  4174     CleanupStack::PushL(ret);
       
  4175     return ret;
       
  4176     }
       
  4177 
       
  4178 // -------------------------------------------------------------------------------------
       
  4179 // CSCOMOAdapter::DirectSetMappingL( const TDesC8 &aURI, const TDesC8 &aLUID )
       
  4180 // -------------------------------------------------------------------------------------		
       
  4181 TInt CSCOMOAdapter::DirectSetMappingL(const TDesC8 &aURI, const TDesC8 &aLUID)
       
  4182     {
       
  4183 
       
  4184 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4185     TRAPD( err, Callback().SetMappingL( aURI, aLUID ) );
       
  4186 #else
       
  4187     TInt err(iDbSession.AddMappingInfoL(KAMAdapterImplUid, aURI, aLUID) );
       
  4188 #endif
       
  4189     return err;
       
  4190     }
       
  4191 
       
  4192 // -------------------------------------------------------------------------------------
       
  4193 // CSCOMOAdapter::MoveAclL( const TDesC8 &aFrom, const TDesC8 &aTo )
       
  4194 // -------------------------------------------------------------------------------------		
       
  4195 void CSCOMOAdapter::MoveAclL(const TDesC8 &aFrom, const TDesC8 &aTo)
       
  4196     {
       
  4197 
       
  4198 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4199     RDmTreeNode from;
       
  4200     CleanupClosePushL(from);
       
  4201 
       
  4202     RDmTreeNode to;
       
  4203     CleanupClosePushL(to);
       
  4204 
       
  4205     RBuf8 acl;
       
  4206     acl.CreateL(128);
       
  4207     CleanupClosePushL(acl);
       
  4208 
       
  4209     iDbSession.OpenNodeL(aFrom, from, RDmTree::EReadOnly);
       
  4210     TRAPD( err, from.DmPropertyL( DevMan::EACL, acl ) );
       
  4211     if ( err == KErrNone )
       
  4212         {
       
  4213         iDbSession.OpenNodeL(aTo, to, RDmTree::EReadOnly);
       
  4214         from.RemoveDmPropertyL( DevMan::EACL );
       
  4215         to.SetDmPropertyL( DevMan::EACL, acl );
       
  4216         }
       
  4217     CleanupStack::PopAndDestroy( 3, &from );
       
  4218 #else
       
  4219     CBufBase *acl = CBufFlat::NewL( 128);
       
  4220     CleanupStack::PushL(acl);
       
  4221     TInt err(iDbSession.GetAclL(aFrom, *acl, EFalse) ); // no need for inherited
       
  4222     if (err == KErrNone)
       
  4223         {
       
  4224         err = iDbSession.DeleteAclL(aFrom);
       
  4225         err = iDbSession.UpdateAclL(aTo, acl->Ptr( 0) );
       
  4226         }
       
  4227     CleanupStack::PopAndDestroy(acl);
       
  4228 #endif
       
  4229     }
       
  4230 
       
  4231 // -------------------------------------------------------------------------------------
       
  4232 // CSCOMOAdapter::SetMappingL( const TDesC8 &aOriginalURI, 
       
  4233 //	const TDeploymentComponentState aTargetState, const TDesC8 &aLUID )
       
  4234 // -------------------------------------------------------------------------------------		
       
  4235 void CSCOMOAdapter::SetMappingL(const TDesC8 &aOriginalURI,
       
  4236         const TDeploymentComponentState aTargetState, const TDesC8 &aLUID)
       
  4237     {
       
  4238 
       
  4239     HBufC8 * targeturi= NULL;
       
  4240     SetMappingLC(aOriginalURI, aTargetState, aLUID, targeturi);
       
  4241     CleanupStack::PopAndDestroy(targeturi);
       
  4242     }
       
  4243 
       
  4244 // -------------------------------------------------------------------------------------
       
  4245 // CSCOMOAdapter::SetMappingLC( const TDesC8 &aOriginalURI, 
       
  4246 //	const TDeploymentComponentState aTargetState, const TDesC8 &aLUID, 
       
  4247 //	HBufC8 *&aNewUri )
       
  4248 // -------------------------------------------------------------------------------------		
       
  4249 void CSCOMOAdapter::SetMappingLC(const TDesC8 &aOriginalURI,
       
  4250         const TDeploymentComponentState aTargetState, const TDesC8 &aLUID,
       
  4251         HBufC8 *&aNewUri)
       
  4252     {
       
  4253 
       
  4254     // "Nullify" the mapping for argument
       
  4255     DirectSetMappingL(aOriginalURI, KNullDesC8);
       
  4256 
       
  4257     // Determine new uri for aArgument
       
  4258     TPtrC8 puri;
       
  4259     if (aNewUri == NULL)
       
  4260         {
       
  4261         TPtrC8 argMapping(NSmlDmURI::LastURISeg(aOriginalURI) );
       
  4262         TPtrC8 target;
       
  4263         if (aTargetState == EDCSInactive || aTargetState == EDCSActive)
       
  4264             {
       
  4265             target.Set(KDeployedURI() );
       
  4266             }
       
  4267         else
       
  4268             if (aTargetState == EDCSDelivered)
       
  4269                 {
       
  4270                 target.Set(KDeliveredURI() );
       
  4271                 }
       
  4272             else
       
  4273                 {
       
  4274 
       
  4275                 User::Leave(KErrArgument);
       
  4276                 }
       
  4277 
       
  4278         aNewUri = HBufC8::NewLC(target.Length() + argMapping.Length() );
       
  4279         TPtr8 p(aNewUri->Des() );
       
  4280         p.Copy(target);
       
  4281         p.Append(argMapping);
       
  4282         puri.Set(p);
       
  4283         }
       
  4284     else
       
  4285         {
       
  4286         puri.Set( *aNewUri);
       
  4287         }
       
  4288     DirectSetMappingL(puri, aLUID);
       
  4289     MoveAclL(aOriginalURI, puri);
       
  4290     }
       
  4291 
       
  4292 #ifdef __AM_LASTERROR_NODE
       
  4293 // ------------------------------------------------------------------------------------------------
       
  4294 // CSCOMOAdapter::SetLastErrorL( const TDesC8& aLastError, const TInt aError )
       
  4295 // ------------------------------------------------------------------------------------------------	
       
  4296 void CSCOMOAdapter::SetLastErrorL(const TDesC8& aLastError, const TInt aError)
       
  4297     {
       
  4298     if (iLastError)
       
  4299         {
       
  4300         TPtrC8 p(*iLastError);
       
  4301         RDEBUG8_2( "CSCOMOAdapter::SetLastErrorL: clearing last error %S", &p);
       
  4302         delete iLastError;
       
  4303         iLastError = NULL;
       
  4304         }
       
  4305     iLastError = HBufC8::NewL(aLastError.Length() + 10);
       
  4306     iLastError->Des().Format(aLastError, aError);
       
  4307     }
       
  4308 
       
  4309 const TDesC8& CSCOMOAdapter::LastError()
       
  4310     {
       
  4311     return iLastError == NULL ? KNullDesC8() : *iLastError;
       
  4312     }
       
  4313 
       
  4314 #endif
       
  4315 
       
  4316 TPtrC8 CSCOMOAdapter::LastURISeg(const TDesC8& aURI)
       
  4317     {
       
  4318     TInt i;
       
  4319     for (i=aURI.Length()-1; i>=0; i--)
       
  4320         {
       
  4321         if (aURI[i]==KNSmlDMAMSeparatorDef)
       
  4322             {
       
  4323             break;
       
  4324             }
       
  4325         }
       
  4326     if (i==0)
       
  4327         {
       
  4328         return aURI;
       
  4329         }
       
  4330     else
       
  4331         {
       
  4332         return aURI.Mid(i+1);
       
  4333         }
       
  4334     }
       
  4335 
       
  4336 TInt CSCOMOAdapter::DesToInt(const TDesC8& aLuid)
       
  4337     {
       
  4338     TLex8 lex(aLuid);
       
  4339     TInt value = 0;
       
  4340     lex.Val(value);
       
  4341     return value;
       
  4342     }
       
  4343 void CSCOMOAdapter::CheckAndAddPredefinedNodeL()
       
  4344     {
       
  4345 
       
  4346     // Check if SCOMODefault node addition is enabled.
       
  4347     TInt staticnodeenabled = 0;
       
  4348     CRepository* cenrep = CRepository::NewLC( KCRUidPrivateApplicationManagementKeys );
       
  4349     cenrep->Get( KAMStaticNodeEnabled, staticnodeenabled ); 
       
  4350     CleanupStack::PopAndDestroy(); //cenrep
       
  4351         
       
  4352     
       
  4353     if(staticnodeenabled)
       
  4354     {
       
  4355       TBuf8<KMaxFullName> temp;
       
  4356       GetPredefinedNodeL(temp);
       
  4357       if (temp.Length())
       
  4358         {
       
  4359 
       
  4360         TBuf8<KMaxFullName> temp1;
       
  4361         temp1.Zero();
       
  4362         temp1.Copy(KAMNodeName);
       
  4363         temp1.Append(KAMSeparator8);
       
  4364         temp1.Append(KAMDownloadNodeName);
       
  4365         temp1.Append(KAMSeparator8);
       
  4366         temp1.Append(temp);
       
  4367         HBufC8* luid = DirectGetLuidAllocLC(temp1);
       
  4368 
       
  4369         if (luid->Length() > 0)
       
  4370             {
       
  4371             CleanupStack::PopAndDestroy(luid);
       
  4372             return;
       
  4373             }
       
  4374         else
       
  4375             {
       
  4376             // Not found, add node and mapping ... 
       
  4377             //TError status(EError);
       
  4378             TPtrC8 mapping(NSmlDmURI::LastURISeg(temp1) );
       
  4379             TPtrC8 parent(NSmlDmURI::RemoveLastSeg(temp1) );
       
  4380             TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  4381             TInt cnt(NSmlDmURI::NumOfURISegs(temp1) );
       
  4382             TUint32 newLuid(SessionL().DownloadL(mapping));
       
  4383             //Callback().SetMappingL( temp1, *IntToDes8LC( newLuid ) );
       
  4384             //CleanupStack::PopAndDestroy();
       
  4385             DirectSetMappingL(temp1, *IntToDes8LC(newLuid) );
       
  4386             CleanupStack::PopAndDestroy(); // for IntToDes8LC()
       
  4387             CleanupStack::PopAndDestroy(luid);
       
  4388             }
       
  4389         }
       
  4390     }
       
  4391     }
       
  4392 // ---------------------------------------------------------------------------
       
  4393 // CAmAdapter::GetPredefinedNodeL()
       
  4394 // Gets  predefined node for Download object from cenrep 
       
  4395 // ---------------------------------------------------------------------------
       
  4396 //
       
  4397 void CSCOMOAdapter::GetPredefinedNodeL(TDes8& aNode)
       
  4398 	{
       
  4399 	CRepository* centrep( NULL);
       
  4400 	aNode.Zero();
       
  4401    	centrep = CRepository::NewLC( KCRUidPrivateApplicationManagementKeys );
       
  4402 
       
  4403     if ( centrep )
       
  4404 	    {
       
  4405         TBuf8<256> temp;
       
  4406 		TInt err = centrep->Get( KAMDownloadPredefinedNode, temp );
       
  4407     	if (centrep->Get( KAMDownloadPredefinedNode, temp )==KErrNone && temp.Length() )
       
  4408 			{
       
  4409 			temp.Trim();
       
  4410 			aNode.Copy(temp);
       
  4411 			}
       
  4412 		CleanupStack::PopAndDestroy(centrep);
       
  4413 	    }
       
  4414 	}
       
  4415 // -------------------------------------------------------------------------------------
       
  4416 // CAmAdapter::DirectRemoveMappingL( const TDesC8 &aURI )
       
  4417 // -------------------------------------------------------------------------------------        
       
  4418 TInt CSCOMOAdapter::DirectRemoveMappingL( const TDesC8 &aURI )
       
  4419     {
       
  4420 
       
  4421 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4422     TRAPD( err, Callback().SetMappingL( aURI, aLUID ) );
       
  4423 #else
       
  4424     TInt err( iDbSession.RemoveMappingInfoL( KAMAdapterImplUid, aURI, ETrue ) );
       
  4425 #endif
       
  4426     return err;
       
  4427     }
       
  4428 TInt CSCOMOAdapter::GetAdapterValue()
       
  4429     {
       
  4430     TInt adapterValue;
       
  4431     CRepository *repository = NULL;
       
  4432     TRAPD( err, repository = CRepository::NewL ( KCRUidPrivateApplicationManagementKeys ) );
       
  4433     if (err == KErrNone)
       
  4434         {
       
  4435         err = repository->Get(KAMAdapterValue, adapterValue);
       
  4436         }
       
  4437     delete repository;
       
  4438     repository = NULL;
       
  4439     return adapterValue;
       
  4440     }
       
  4441 
       
  4442 void CSCOMOAdapter::SetAdapterValue(TInt aAdapterValue)
       
  4443     {
       
  4444     CRepository *repository = NULL;
       
  4445     TRAPD( err, repository = CRepository::NewL ( KCRUidPrivateApplicationManagementKeys ) );
       
  4446     if (err == KErrNone)
       
  4447         {
       
  4448         err = repository->Set(KAMAdapterValue, aAdapterValue);
       
  4449         }
       
  4450     delete repository;
       
  4451     repository = NULL;
       
  4452     }
       
  4453 TBool CSCOMOAdapter::RecognizeMimeType(const TDesC8& aMimeType)
       
  4454     {
       
  4455     TBool isSupportedMimeType = EFalse;
       
  4456     if ((aMimeType == KSisxMimeType )||(aMimeType == KSisMimeType )||(aMimeType == KPipMimeType )||
       
  4457             (aMimeType == KJadMIMEType )||(aMimeType == KJarMIMEType )||(aMimeType == KJavaMIMEType ))
       
  4458         {
       
  4459         isSupportedMimeType = ETrue;
       
  4460         }
       
  4461     return isSupportedMimeType;
       
  4462     }
       
  4463 // End of File
       
  4464