applicationmanagement/omascomoadapter/src/omascomoadapter.cpp
changeset 18 7d11f9a6646f
parent 4 75a71fdb4c92
child 21 c707676bf59f
equal deleted inserted replaced
4:75a71fdb4c92 18:7d11f9a6646f
     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("CSCOMOAdapter::SessionL() aCertInfo");
       
  1041 
       
  1042             //RDEBUG_2("aCertInfo.iFingerprint.Length() is  %u",info.iFingerprint.Length() );
       
  1043             if (errx == KErrNone)
       
  1044                 {
       
  1045                 RDEBUG("CSCOMOAdapter::SessionL() errx == KErrNone");
       
  1046                 }
       
  1047             else
       
  1048                 {
       
  1049                 if (errx != KErrNotFound)
       
  1050                     {
       
  1051                     RDEBUG("CSCOMOAdapter::SessionL() errx != KErrNotFound");
       
  1052                     }
       
  1053                 else
       
  1054                     {
       
  1055                     RDEBUG("CSCOMOAdapter::SessionL() errx == KErrNotFound");
       
  1056                     }
       
  1057 
       
  1058                 }
       
  1059             delete re;
       
  1060             }
       
  1061 
       
  1062         if (errx == KErrNotFound || !iCertRequired)
       
  1063             {
       
  1064             RDEBUG("CSCOMOAdapter::SessionL() calling iManagement.Connect()");
       
  1065             User::LeaveIfError(iManagement.Connect() );
       
  1066             iSessionOpened = ETrue;
       
  1067             iTrustAdded = EFalse;
       
  1068             }
       
  1069         else
       
  1070             {
       
  1071             RDEBUG("CSCOMOAdapter::SessionL() calling iManagement.Connect( info )");
       
  1072             User::LeaveIfError(iManagement.Connect(info) );
       
  1073             iSessionOpened = ETrue;
       
  1074             iTrustAdded = ETrue;
       
  1075             }
       
  1076         }
       
  1077     return iManagement;
       
  1078     }
       
  1079 
       
  1080 // ------------------------------------------------------------------------------------------------
       
  1081 //  CSCOMOAdapter::UpdateLeafObjectL()
       
  1082 // ------------------------------------------------------------------------------------------------
       
  1083 void CSCOMOAdapter::UpdateLeafObjectL(const TDesC8& aURI,
       
  1084         const TDesC8& aLUID, const TDesC8& aObject, const TDesC8& aType,
       
  1085         TInt aStatusRef)
       
  1086     {
       
  1087     RDEBUG8_4("CSCOMOAdapter::UpdateLeafObjectL(): begin, '%S', '%S' '%S'", &aURI, &aLUID, &aType );
       
  1088 
       
  1089     MSmlDmAdapter::TError status = EOk;
       
  1090     SetAdapterValue(KAMSCOMOAdapter);
       
  1091     _UpdateLeafObjectL(aURI, aLUID, aObject, aType, aStatusRef, status);
       
  1092 
       
  1093     SetStatusL(aStatusRef, status);
       
  1094     if (status == EOk)
       
  1095         {
       
  1096         if (iInAtomic)
       
  1097             {
       
  1098             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  1099             }
       
  1100         }
       
  1101     RDEBUG_2("CSCOMOAdapter::UpdateLeafObjectL(): end (%d)", status);
       
  1102     }
       
  1103 
       
  1104 // ------------------------------------------------------------------------------------------------
       
  1105 //  CSCOMOAdapter::UpdateLeafObjectL()
       
  1106 // ------------------------------------------------------------------------------------------------
       
  1107 void CSCOMOAdapter::_UpdateLeafObjectL(const TDesC8& aURI,
       
  1108         const TDesC8& aLUID, const TDesC8& aObject, const TDesC8& aType,
       
  1109         TInt /*aStatusRef*/, MSmlDmAdapter::TError& aStatus)
       
  1110     {
       
  1111     RDEBUG("CSCOMOAdapter::_UpdateLeafObjectL(): begin");
       
  1112 
       
  1113     CheckStateChangesL();
       
  1114 
       
  1115     TError status(EError);
       
  1116 
       
  1117 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  1118     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash( aURI );
       
  1119     TInt numSeqs( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  1120     TPtrC8 mapping( NSmlDmURI::LastURISeg( uriPtrc ) );
       
  1121     TPtrC8 parent( NSmlDmURI::RemoveLastSeg( uriPtrc ) );
       
  1122 #else
       
  1123     TInt numSeqs(NSmlDmURI::NumOfURISegs(aURI) );
       
  1124     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  1125     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  1126 #endif
       
  1127 
       
  1128     if (mapping == KAMNameNodeName)
       
  1129         {
       
  1130         if (aObject.Size() > KDeploymentComponentNameMaxLength)
       
  1131             {
       
  1132             aStatus = ETooLargeObject;
       
  1133             return;
       
  1134             }
       
  1135         }
       
  1136     else
       
  1137         if (mapping == KAMVersionNodeName)
       
  1138             {
       
  1139             if (aObject.Size() > KDeploymentComponentVersionMaxLength)
       
  1140                 {
       
  1141                 aStatus = ETooLargeObject;
       
  1142                 return;
       
  1143                 }
       
  1144             }
       
  1145         else
       
  1146 	if (mapping == KAMURINodeName)
       
  1147 	  {
       
  1148 	   if (aObject.Size() > KMaxUrlLength)
       
  1149                 {
       
  1150                 aStatus = ETooLargeObject;
       
  1151                 return;
       
  1152                 }
       
  1153 
       
  1154 	  }
       
  1155         else
       
  1156             if (mapping == KAMConRefNodeName)
       
  1157                 {
       
  1158                 if (aObject.Size() > KMaxConRef)
       
  1159                     {
       
  1160                     aStatus = ETooLargeObject;
       
  1161                     return;
       
  1162                     }
       
  1163                 }
       
  1164             else
       
  1165                 if (mapping == KAMDescriptionNodeName)
       
  1166                     {
       
  1167                     if (aObject.Size() > 512)
       
  1168                         {
       
  1169                         aStatus = ETooLargeObject;
       
  1170                         return;
       
  1171                         }
       
  1172                     }
       
  1173             else
       
  1174                if(mapping == KAMPkgIDNodeName)
       
  1175                {
       
  1176                if(aObject.Size() > 256)
       
  1177                {
       
  1178                	aStatus = ETooLargeObject;
       
  1179                         return;
       
  1180                }
       
  1181                }
       
  1182             else
       
  1183               if(mapping == KAMPkgTypeNodeName)
       
  1184               {
       
  1185                 // ADD check for PkgType MIME Type if not supported 
       
  1186                 // error status should be sent and operation should stop
       
  1187                 
       
  1188               	if(aObject.Size() >100)
       
  1189               	{
       
  1190               		aStatus = ETooLargeObject;
       
  1191                         return;
       
  1192               	}
       
  1193               }
       
  1194              
       
  1195 
       
  1196     TPtrC8 grandParent(NSmlDmURI::RemoveLastSeg(parent) );
       
  1197     TPtrC8 grandParentMapping(NSmlDmURI::LastURISeg(grandParent) );
       
  1198     RApplicationManagement &session = SessionL();
       
  1199     TDeploymentComponentState state(EDCSNone);
       
  1200     if (numSeqs == 4 || numSeqs == 5)
       
  1201         {
       
  1202         if (numSeqs == 4)
       
  1203             {
       
  1204             state = EDCSDownload;
       
  1205             }
       
  1206         else
       
  1207             {
       
  1208             if (grandParentMapping == KAMDeliveredNodeName)
       
  1209                 {
       
  1210                 state = EDCSDelivered;
       
  1211                 }
       
  1212             else
       
  1213                 if (grandParentMapping == KAMDeployedNodeName)
       
  1214                     {
       
  1215                     state = EDCSActive;
       
  1216                     }
       
  1217                 else
       
  1218                     {
       
  1219                     RDEBUG8_3( "CSCOMOAdapter::UpdateLeafObjectL(): ILLEGAL LEVEL %d NODE %S", numSeqs, &aURI );
       
  1220                     User::Leave(KErrArgument);
       
  1221                     }
       
  1222             }
       
  1223         }
       
  1224     else
       
  1225         {
       
  1226         RDEBUG8_3("CSCOMOAdapter::UpdateLeafObjectL(): ILLEGAL LEVEL %d NODE %S", numSeqs, &aURI );
       
  1227         }
       
  1228     if (state == EDCSDelivered || state == EDCSDownload ||state == EDCSActive
       
  1229             ||state == EDCSInactive)
       
  1230         {
       
  1231         if (aLUID != KNullDesC8)
       
  1232             {
       
  1233             TInt iluid(DesToIntL(aLUID) );
       
  1234             TDeploymentComponent comp;
       
  1235             TInt err(session.DeploymentComponent(iluid, comp) );
       
  1236             if (err == KErrNone)
       
  1237                 {
       
  1238                 
       
  1239                 // Set default component install options for particular iluid.
       
  1240                 TPtrC8 obj;
       
  1241                 TAMInstallOptions opts; 
       
  1242                 TAMInstallOptionsPckg optsb(opts);
       
  1243                 
       
  1244                 TBuf<KMaxSizeString> drive;
       
  1245                 
       
  1246                 CRepository *rep = CRepository::NewLC(KCRUidPrivateApplicationManagementKeys );
       
  1247                 rep->Get(KDefaultDriveForInstall,drive);
       
  1248                 CleanupStack::PopAndDestroy();
       
  1249                 
       
  1250                 //TChar KDefaultDrive = 'c';
       
  1251                 TChar KDefaultDrive = drive[0]; 
       
  1252                 
       
  1253 	 			opts.iOptions.iUpgrade = SwiUI::EPolicyAllowed;
       
  1254      			opts.iOptions.iOptionalItems = SwiUI::EPolicyAllowed;
       
  1255      			opts.iOptions.iOCSP = SwiUI::EPolicyAllowed;
       
  1256      			opts.iOptions.iIgnoreOCSPWarnings = SwiUI::EPolicyAllowed;
       
  1257 					
       
  1258      			opts.iOptions.iUntrusted = SwiUI::EPolicyAllowed;
       
  1259      			opts.iOptions.iPackageInfo = SwiUI::EPolicyAllowed;
       
  1260      			opts.iOptions.iCapabilities = SwiUI::EPolicyAllowed;
       
  1261      			opts.iOptions.iKillApp = SwiUI::EPolicyAllowed;
       
  1262      			opts.iOptions.iOverwrite = SwiUI::EPolicyAllowed;
       
  1263      			opts.iOptions.iDownload = SwiUI::EPolicyAllowed;
       
  1264      			opts.iOptions.iDrive = KDefaultDrive;
       
  1265      			opts.iOptions.iLang = ELangNone;
       
  1266      			opts.iOptions.iUsePhoneLang = EFalse ;
       
  1267      			
       
  1268      			obj.Set(optsb);
       
  1269                 
       
  1270                 TRAP_IGNORE( session.UpdateDeploymentComponentL( iluid, EDCInstallOptions, obj ) );
       
  1271                 
       
  1272                 
       
  1273                 TDeplCompAttrType fl(UpdateFlagFromMapping(mapping) );
       
  1274 
       
  1275                            
       
  1276                 if (mapping == KAMDataNodeName || mapping
       
  1277                         == KAMDescriptorNodeName)
       
  1278                     {
       
  1279                     TInt erx(KErrNone);
       
  1280                     if ((mapping == KAMDataNodeName) &&(RecognizeMimeType(aType)== EFalse))
       
  1281                         {
       
  1282                         User::Leave(EInvalidObject);
       
  1283                         }
       
  1284                     if (iIsStreamedContent)
       
  1285                         {
       
  1286                         CloseStreaming();
       
  1287                         TRAP( erx, session.UpdateDeploymentComponentStreamedDataL( iluid, fl, aType ) );
       
  1288                         }
       
  1289                     else
       
  1290                         {
       
  1291                         // 
       
  1292                         TRAP( erx, session.UpdateDeploymentComponentDataL( iluid, fl, aObject, aType ) );
       
  1293                         }
       
  1294                     MAPERROR( erx, status, _L8("Update Delivered Data or metadata %d") );
       
  1295                     }
       
  1296                 else
       
  1297                     {
       
  1298                     if (fl != EDCNone)
       
  1299                         {
       
  1300                         TPtrC8 obj;
       
  1301                         TAMInstallOptions opts;
       
  1302                         TAMInstallOptionsPckg optsb(opts);
       
  1303                         TPckgBuf<TInt> iap;
       
  1304                         if (fl == EDCInstallOptions)
       
  1305                             {
       
  1306                             }
       
  1307                         else
       
  1308                             if (fl == EDCConRef)
       
  1309                                 {
       
  1310 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  1311 
       
  1312                                 //CNSmlDMIAPMatcher* iapfinder = CNSmlDMIAPMatcher::NewLC( &Callback() );
       
  1313                                 //TInt i( iapfinder->IAPIdFromURIL( aObject ) );
       
  1314                                 //CleanupStack::PopAndDestroy( iapfinder );
       
  1315                                 //iap() = i;
       
  1316                                 CArrayFix<TSmlDmMappingInfo>* mapArray = new CArrayFixFlat<TSmlDmMappingInfo>(4);
       
  1317                                 CleanupStack::PushL(mapArray);
       
  1318 
       
  1319                                 Callback().GetMappingInfoListL( KNSmlDMMMSSlashIAPUri,*mapArray );
       
  1320 
       
  1321                                 TInt iapValue = KErrNotFound;
       
  1322                                 TSmlDmMappingInfo mapInfo;
       
  1323 
       
  1324                                 for(TInt i = 0;i<mapArray->Count();i++)
       
  1325                                     {
       
  1326                                     if(LastURISeg(opts.iConRef)==mapArray->At(i).iURISeg)
       
  1327                                         {
       
  1328                                         iapValue=DesToInt(mapArray->At(i).iURISegLUID);
       
  1329                                         break;
       
  1330                                         }
       
  1331                                     }
       
  1332                                 iap() = iapValue;
       
  1333                                 mapArray->Reset();
       
  1334                                 CleanupStack::PopAndDestroy(); //mapArray
       
  1335 
       
  1336 #else
       
  1337                                 CNSmlDMIAPMatcher
       
  1338                                         * iapfinder =
       
  1339                                                 CNSmlDMIAPMatcher::NewLC( &Callback() );
       
  1340                                 TInt i(iapfinder->IAPIdFromURIL(aObject) );
       
  1341                                 CleanupStack::PopAndDestroy(iapfinder);
       
  1342                                 iap() = i;
       
  1343 #endif
       
  1344                                 obj.Set(iap);
       
  1345                                 }
       
  1346                             else
       
  1347                                 {
       
  1348                                 obj.Set(aObject);
       
  1349                                 }
       
  1350                         TRAPD( erx, session.UpdateDeploymentComponentL( iluid, fl, obj ) )
       
  1351                         ;
       
  1352                         MAPERROR( erx, status, _L8("Update some attribute %d") );
       
  1353                         }
       
  1354                     else
       
  1355                         {
       
  1356                         status = ENotFound;
       
  1357                         RDEBUG( "CSCOMOAdapter::UpdateLeafObjectL(): Unknown Target leaf" );
       
  1358                         }
       
  1359                     }
       
  1360                 }
       
  1361             else
       
  1362                 {
       
  1363                 RDEBUG_3( "CSCOMOAdapter::UpdateLeafObjectL(): FAILED TO GET COMPONENT OF ID %d: %d" , iluid, err );
       
  1364                 status = ENotFound;
       
  1365                 }
       
  1366             }
       
  1367         else
       
  1368             {
       
  1369             RDEBUG8_2( "CSCOMOAdapter::UpdateLeafObjectL(): Faild to get luid allocation and find buffered for '%S'", &parent );
       
  1370             status = ENotFound;
       
  1371             }
       
  1372         }
       
  1373     else
       
  1374         {
       
  1375         RDEBUG8_2( "CSCOMOAdapter::UpdateLeafObjectL(): WARNING Tried to update illegal state leaf! '%S'", &grandParentMapping );
       
  1376         }
       
  1377 
       
  1378     aStatus = status;
       
  1379 
       
  1380     RDEBUG("CSCOMOAdapter::_UpdateLeafObjectL(): end");
       
  1381     }
       
  1382 
       
  1383 // ------------------------------------------------------------------------------------------------
       
  1384 // CSCOMOAdapter::UpdateLeafObjectL
       
  1385 // ------------------------------------------------------------------------------------------------
       
  1386 void CSCOMOAdapter::UpdateLeafObjectL(const TDesC8& aURI,
       
  1387         const TDesC8& aLUID, RWriteStream*& aStream, const TDesC8& aType,
       
  1388         TInt aStatusRef)
       
  1389     {
       
  1390     RDEBUG8_4("CSCOMOAdapter::UpdateLeafObjectL() aStream: begin, '%S', '%S' '%S'", &aURI, &aLUID, &aType );
       
  1391 
       
  1392     TError status(CSmlDmAdapter::EOk);
       
  1393 
       
  1394     if (iStreamedURI)
       
  1395         {
       
  1396         delete iStreamedURI;
       
  1397         iStreamedURI = NULL;
       
  1398         }
       
  1399     iStreamedURI = aURI.AllocL();
       
  1400 
       
  1401     if (iStreamedLuid)
       
  1402         {
       
  1403         delete iStreamedLuid;
       
  1404         iStreamedLuid = NULL;
       
  1405         }
       
  1406     iStreamedLuid = aLUID.AllocL();
       
  1407 
       
  1408     if (iStreamedType)
       
  1409         {
       
  1410         delete iStreamedType;
       
  1411         iStreamedType = NULL;
       
  1412         }
       
  1413     iStreamedType = aType.AllocL();
       
  1414 
       
  1415     if (!iStreamOpen)
       
  1416         {
       
  1417         RApplicationManagement &session = SessionL();
       
  1418         TDeplCompAttrType attrType;
       
  1419         TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  1420         TDeplCompAttrType fl(UpdateFlagFromMapping(mapping) );
       
  1421         if (mapping == KAMDataNodeName)
       
  1422             {
       
  1423             attrType = EDCData;
       
  1424             }
       
  1425         else
       
  1426             if (mapping == KAMDescriptorNodeName)
       
  1427                 {
       
  1428                 attrType = EDCMetaData;
       
  1429                 }
       
  1430             else
       
  1431                 {
       
  1432                 RDEBUG8_2("CSCOMOAdapter::UpdateLeafObjectL(): Unknown mapping: (%S)", &mapping);
       
  1433                 status = CSmlDmAdapter::EError;
       
  1434                 }
       
  1435 
       
  1436         if (status == CSmlDmAdapter::EOk)
       
  1437             {
       
  1438             TInt iluid(DesToIntL(aLUID) );
       
  1439             session.DeploymentComponentTempInstFileL(iluid, iStreamFile,
       
  1440                     attrType);
       
  1441             iStream.Attach(iStreamFile);
       
  1442             aStream = &iStream;
       
  1443             iStreamOpen = ETrue;
       
  1444             iIsStreamedContent = ETrue;
       
  1445             }
       
  1446         }
       
  1447     if ( !iInAtomic)
       
  1448         {
       
  1449         iStatusRef = aStatusRef;
       
  1450         Callback().SetStatusL(aStatusRef, status);
       
  1451         }
       
  1452     else
       
  1453         {
       
  1454         iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  1455         }
       
  1456 
       
  1457     RDEBUG("CSCOMOAdapter::UpdateLeafObjectL() aStream : end");
       
  1458     }
       
  1459 
       
  1460 // ------------------------------------------------------------------------------------------------
       
  1461 // CSCOMOAdapter::UpdateFlagFromMapping( const TDesC8& aMapping )
       
  1462 // ------------------------------------------------------------------------------------------------
       
  1463 TDeplCompAttrType CSCOMOAdapter::UpdateFlagFromMapping(const TDesC8& aMapping)
       
  1464     {
       
  1465 
       
  1466     TDeplCompAttrType res;
       
  1467     if (aMapping == KAMIDNodeName)
       
  1468         {
       
  1469         res = EDCId;
       
  1470         }
       
  1471     else
       
  1472         if (aMapping == KAMNameNodeName)
       
  1473             {
       
  1474             res = EDCName;
       
  1475             }
       
  1476         else
       
  1477             if (aMapping == KAMVersionNodeName)
       
  1478                 {
       
  1479                 res = EDCVersion;
       
  1480                 }
       
  1481             else
       
  1482                 if (aMapping == KAMStateValueNodeName)
       
  1483                     {
       
  1484                     res = EDCStateValue;
       
  1485                     }
       
  1486                 else
       
  1487                     if (aMapping == KAMInstallOptsNodeName)
       
  1488                         {
       
  1489                         res = EDCInstallOptions;
       
  1490                         }
       
  1491                     else
       
  1492                         if (aMapping == KAMDescriptorNodeName)
       
  1493                             {
       
  1494                             res = EDCMetaData;
       
  1495                             }
       
  1496                         else
       
  1497                             if (aMapping == KAMDataNodeName)
       
  1498                                 {
       
  1499                                 res = EDCData;
       
  1500                                 }
       
  1501                             else
       
  1502                                 if (aMapping == KAMURINodeName)
       
  1503                                     {
       
  1504                                     res = EDCDownloadURI;
       
  1505                                     }
       
  1506                                 else
       
  1507                                     if (aMapping == KAMStatusNodeName)
       
  1508                                         {
       
  1509                                          res = EDCStatus;
       
  1510                                         }
       
  1511                                     else
       
  1512                                         if (aMapping == KAMConRefNodeName)
       
  1513                                             {
       
  1514                                             res = EDCConRef;
       
  1515                                             }
       
  1516                                         else
       
  1517                                             if (aMapping
       
  1518                                                     == KAMDescriptionNodeName)
       
  1519                                                 {
       
  1520                                                 res = EDCDescriptionRef;
       
  1521                                                 }
       
  1522                                               else
       
  1523                                                 if(aMapping == KAMPkgIDNodeName)
       
  1524                                                 {
       
  1525                                                 	res = EDCPkgID;
       
  1526                                                 }
       
  1527                                                 else
       
  1528                                                 if(aMapping == KAMPkgTypeNodeName)
       
  1529                                                 {
       
  1530                                                 	res = EDCPkgType;
       
  1531                                                 }
       
  1532                                                 
       
  1533 
       
  1534                                             else
       
  1535                                                 {
       
  1536                                                 //User::Leave( KErrArgument );
       
  1537                                                 res = EDCNone;
       
  1538                                                 }
       
  1539     return res;
       
  1540     }
       
  1541 
       
  1542 // ------------------------------------------------------------------------------------------------
       
  1543 // CSCOMOAdapter::GetLuidForUserIdL( const TDesC8 &aUserId, 
       
  1544 //		const TDeploymentComponentState aState )
       
  1545 // ------------------------------------------------------------------------------------------------	
       
  1546 TUint32 CSCOMOAdapter::GetLuidForUserIdL(const TDesC8 &aUserId,
       
  1547         const TDeploymentComponentState aState)
       
  1548     {
       
  1549     TUint32 ret( 0);
       
  1550     if (aState != EDCSNone)
       
  1551         {
       
  1552         RElementIdArray array;
       
  1553         TInt err(SessionL().DeploymentComponentIdsL(array, aState) );
       
  1554         if (err == KErrNone)
       
  1555             {
       
  1556             CleanupClosePushL(array);
       
  1557             TInt count(array.Count() );
       
  1558             for (TInt i( 0); i < count && ret == 0; i++)
       
  1559                 {
       
  1560                 TUint32 el = array[i];
       
  1561                 TDCUserId dc;
       
  1562                 SessionL().DeploymentComponentUserIdL(el, dc);
       
  1563                 if (dc == aUserId)
       
  1564                     {
       
  1565                     ret = el;
       
  1566                     }
       
  1567                 }
       
  1568             CleanupStack::PopAndDestroy( &array);
       
  1569             }
       
  1570         else
       
  1571             {
       
  1572             }
       
  1573         }
       
  1574     return ret;
       
  1575     }
       
  1576 
       
  1577 // ------------------------------------------------------------------------------------------------
       
  1578 // CSCOMOAdapter::GetLuid2L( const TDesC8 &aDMLuid, const TDesC8 &aUserId, 
       
  1579 //		const TDeploymentComponentState aState, TError &aStatus )
       
  1580 // ------------------------------------------------------------------------------------------------	
       
  1581 TUint32 CSCOMOAdapter::GetLuid2L(const TDesC8 &aDMLuid,
       
  1582         const TDesC8 &aUserId, const TDeploymentComponentState aState,
       
  1583         TError &aStatus)
       
  1584     {
       
  1585     TUint32 ret(GetLuidL(aDMLuid, aUserId, aState) );
       
  1586     if ( (TInt32)ret <= 0)
       
  1587         {
       
  1588         aStatus = ENotFound;
       
  1589         }
       
  1590     return ret;
       
  1591     }
       
  1592 
       
  1593 // ------------------------------------------------------------------------------------------------
       
  1594 // CSCOMOAdapter::GetLuidL( const TDesC8 &aDMLuid, const TDesC8 &aUserId, 
       
  1595 //		const TDeploymentComponentState aState )
       
  1596 // ------------------------------------------------------------------------------------------------	
       
  1597 TUint32 CSCOMOAdapter::GetLuidL(const TDesC8 &aDMLuid, const TDesC8 &aUserId,
       
  1598         const TDeploymentComponentState aState)
       
  1599     {
       
  1600     TUint32 ret( 0);
       
  1601     if (aDMLuid == KNullDesC8)
       
  1602         {
       
  1603         ret = GetLuidForUserIdL(aUserId, aState);
       
  1604         }
       
  1605     else
       
  1606         {
       
  1607         ret = DesToIntL(aDMLuid) ;
       
  1608         }
       
  1609 
       
  1610     return ret;
       
  1611     }
       
  1612 
       
  1613 // ------------------------------------------------------------------------------------------------
       
  1614 // CSCOMOAdapter::DeleteObjectL( const TDesC8& aURI, const TDesC8& aLUID )
       
  1615 // ------------------------------------------------------------------------------------------------
       
  1616 void CSCOMOAdapter::DeleteObjectL(const TDesC8& aURI, const TDesC8& aLUID,
       
  1617         const TInt aStatusRef)
       
  1618     {
       
  1619 
       
  1620     RDEBUG8_4("CSCOMOAdapter::DeleteObjectL(): begin (%S, %S, %d)" , &aURI, &aLUID, aStatusRef );
       
  1621     SetAdapterValue(KAMSCOMOAdapter);
       
  1622     CheckStateChangesL();
       
  1623 
       
  1624     TError ret(EError);
       
  1625 
       
  1626 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
  1627     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  1628     TInt cnt( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  1629     TPtrC8 mapping( NSmlDmURI::LastURISeg( uriPtrc ) );
       
  1630 #else
       
  1631     TInt cnt(NSmlDmURI::NumOfURISegs(aURI) );
       
  1632     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  1633 #endif
       
  1634 	
       
  1635 	TBuf8<KMaxFullName> temp;
       
  1636 	GetPredefinedNodeL(temp);
       
  1637 	TInt comp = mapping.Compare( temp );
       
  1638 		if (temp.Length() && mapping.Compare( temp ) == 0)
       
  1639             {
       
  1640             MSmlDmAdapter::TError status = MSmlDmAdapter::ENotAllowed;
       
  1641             Callback().SetStatusL( aStatusRef, status );
       
  1642             return;
       
  1643             }
       
  1644     switch (cnt)
       
  1645         {
       
  1646         case 3:
       
  1647         case 4:
       
  1648             {
       
  1649 
       
  1650 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  1651             TPtrC8 which( NSmlDmURI::URISeg( uriPtrc, cnt == 4 ? 3 : 2 ) );
       
  1652 #else
       
  1653             TPtrC8 which(NSmlDmURI::URISeg(aURI, cnt == 4 ? 3 : 2) );
       
  1654 #endif
       
  1655             if (which == KAMDeliveredNodeName || which == KAMDownloadNodeName)
       
  1656                 {
       
  1657                 TUint32 luid(GetLuidL(aLUID, mapping, (which
       
  1658                         == KAMDeliveredNodeName
       
  1659                                                 ? EDCSDelivered
       
  1660                                                    : EDCSDownload)) );
       
  1661                 if (luid > 0)
       
  1662                     {
       
  1663                     TRAPD( err, SessionL().RemoveL( luid ) )
       
  1664                     ;
       
  1665                     if (err == KErrNone || err == KErrNotFound)
       
  1666                         {
       
  1667                         ret = EOk;
       
  1668                         Callback().SetMappingL(aURI, KNullDesC8);
       
  1669                         if (err == KErrNone && iInAtomic)
       
  1670                             {
       
  1671                             iBuffer.Append(TAMCommandBufferElement(
       
  1672                                     aStatusRef, aURI) );
       
  1673                             }
       
  1674                         }
       
  1675                     else
       
  1676                         {
       
  1677                         MAPERROR( err, ret, _L8("Delete %d") );
       
  1678                         }
       
  1679                     }
       
  1680                 else
       
  1681                     {
       
  1682                     RDEBUG( "CSCOMOAdapter::DeleteObjectL(): WARNING Object not found" );
       
  1683                     ret = ENotFound;
       
  1684                     }
       
  1685                 }
       
  1686             else
       
  1687                 {
       
  1688                 RDEBUG8_2( "CSCOMOAdapter::DeleteObjectL(): ERROR Removing node %S is not supported", &aURI );
       
  1689                 }
       
  1690             break;
       
  1691             }
       
  1692         default:
       
  1693             {
       
  1694             RDEBUG8_3( "CSCOMOAdapter::DeleteObjectL(): ILLEGAL LEVEL %d NODE %S", cnt, &aURI );
       
  1695             break;
       
  1696             }
       
  1697         }
       
  1698     SetStatusL(aStatusRef, ret);
       
  1699     RDEBUG( "CSCOMOAdapter::DeleteObjectL(): end" );
       
  1700     }
       
  1701 
       
  1702 // ------------------------------------------------------------------------------------------------
       
  1703 // CSCOMOAdapter::DeactivateIfInactive( const TUint aLuidi, const TDeploymentComponentState aTargetState )
       
  1704 // ------------------------------------------------------------------------------------------------
       
  1705 void CSCOMOAdapter::DeactivateIfInactive(const TUint aLuidi,
       
  1706         const TDeploymentComponentState aTargetState)
       
  1707     {
       
  1708     if (aTargetState == EDCSInactive)
       
  1709         {
       
  1710         RDEBUG( "CSCOMOAdapter::DeactivateIfInactive():  deactivating!" );
       
  1711         TRAPD( derr, iManagement.DeactivateL( aLuidi ) )
       
  1712         ;
       
  1713         if (derr != KErrNone)
       
  1714             {
       
  1715             RDEBUG_2("CSCOMOAdapter::DeactivateIfInactive(): ERROR deactivating failed %d", derr );
       
  1716             }
       
  1717         }
       
  1718     }
       
  1719 
       
  1720 void CSCOMOAdapter::InstallL(TUint aLuidi, const TDesC8& aURI,
       
  1721         const TDesC8& aLUID, const TDeploymentComponentState aTargetState,
       
  1722         TError &aRet)
       
  1723     {
       
  1724 
       
  1725 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
  1726     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  1727 #else
       
  1728     //nothing
       
  1729 #endif
       
  1730 
       
  1731     TRAPD( err, SessionL().InstallL( aLuidi, aTargetState ) )
       
  1732     ;
       
  1733     if (err == KErrNone)
       
  1734         {
       
  1735         // Update the mappings in client to reflect new
       
  1736         //		position in the management tree ( Inactive or Active..)
       
  1737         RDEBUG( "CSCOMOAdapter::InstallL(): Install success!" );
       
  1738 
       
  1739         TPtrC8 aclmapping(URISegsUpTo(aURI, 4) );
       
  1740         SetMappingL(aclmapping, aTargetState, aLUID);
       
  1741         iManagement.StateChangeComplete(aLuidi);
       
  1742 
       
  1743         DeactivateIfInactive(aLuidi, aTargetState);
       
  1744         aRet = EOk;
       
  1745         }
       
  1746     else
       
  1747         {
       
  1748         RDEBUG_2( "CSCOMOAdapter::InstallL(): INSTALL FAILED '%d'" , err);
       
  1749         MAPERROR( err, aRet, _L8("Install %d") );
       
  1750         }
       
  1751     }
       
  1752 
       
  1753 // ------------------------------------------------------------------------------------------------
       
  1754 // CSCOMOAdapter::DefaultMapError( const TInt aErr, TError &aRet )
       
  1755 // ------------------------------------------------------------------------------------------------
       
  1756 void CSCOMOAdapter::DefaultMapError(const TInt aErr, TError &aRet,
       
  1757         const TDesC8&
       
  1758 #ifdef __AM_LASTERROR_NODE
       
  1759         aDes
       
  1760 #endif
       
  1761 )
       
  1762     {
       
  1763     if (aErr == KErrNone)
       
  1764         {
       
  1765         aRet = EOk;
       
  1766         }
       
  1767     else
       
  1768         if (aErr == KErrNotFound)
       
  1769             {
       
  1770             aRet = ENotFound;
       
  1771             }
       
  1772         else
       
  1773             if (aErr == KErrArgument)
       
  1774                 {
       
  1775                 aRet = EInvalidObject;
       
  1776                 }
       
  1777             else
       
  1778                 if (aErr == KErrAlreadyExists)
       
  1779                     {
       
  1780                     aRet = EAlreadyExists;
       
  1781                     }
       
  1782                 else
       
  1783                     {
       
  1784                     aRet = EError;
       
  1785                     }
       
  1786 #ifdef __AM_LASTERROR_NODE
       
  1787     TInt err = KErrNone;
       
  1788     TRAP( err, SetErrorL( aDes, aErr ) );
       
  1789 #endif
       
  1790     }
       
  1791 
       
  1792 #ifdef __AM_LASTERROR_NODE	
       
  1793 void CSCOMOAdapter::SetErrorL(const TDesC8& aDes, const TInt aErr)
       
  1794     {
       
  1795     if (aDes != KNullDesC8)
       
  1796         {
       
  1797         SetLastErrorL(aDes, aErr);
       
  1798         }
       
  1799     else
       
  1800         {
       
  1801         SetLastErrorL(KStdError, aErr);
       
  1802         }
       
  1803     }
       
  1804 #endif	
       
  1805 
       
  1806 // ------------------------------------------------------------------------------------------------
       
  1807 // CSCOMOAdapter::ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aArgument, 
       
  1808 //	const TDesC8& aType, 
       
  1809 //	TInt aStatusRef )
       
  1810 // ------------------------------------------------------------------------------------------------
       
  1811 TDownloadTarget CSCOMOAdapter::DownloadTargetL(const TDesC8& aCommand)
       
  1812     {
       
  1813     if (aCommand == KAMDownloadOperationNodeName)
       
  1814         {
       
  1815         return EDeliver;
       
  1816         }
       
  1817     else
       
  1818         if (aCommand == KAMDownloadAndInstallNodeName)
       
  1819             {
       
  1820             return EInstallAndActivate;
       
  1821             }
       
  1822         else
       
  1823             if (aCommand == KAMDownloadAndInstallAndInActivateNodeName)
       
  1824                 {
       
  1825                 return EInstall;
       
  1826                 }
       
  1827 
       
  1828     RDEBUG8_2( "CSCOMOAdapter::DownloadTargetL(): ASKED OPERATION NOT SUPPORTED Download '%S'", &aCommand );
       
  1829     User::Leave(KErrArgument);
       
  1830     // NOTE! will not ever come here! Only to get rid of compiler warning !!
       
  1831     return EDeliver;
       
  1832     }
       
  1833 
       
  1834 // ------------------------------------------------------------------------------------------------
       
  1835 // CSCOMOAdapter::ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aArgument, 
       
  1836 //	const TDesC8& aType, 
       
  1837 //	TInt aStatusRef )
       
  1838 // ------------------------------------------------------------------------------------------------
       
  1839 void CSCOMOAdapter::ExecuteCommandL(const TDesC8& aURI, const TDesC8& aLUID,
       
  1840         const TDesC8& aArgument, const TDesC8& /*aType*/, TInt aStatusRef)
       
  1841     {
       
  1842 
       
  1843 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  1844     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  1845 #else
       
  1846     //nothing
       
  1847 #endif
       
  1848 
       
  1849     RDEBUG8_3("CSCOMOAdapter::ExecuteCommandL(): begin, '%S', '%S'", &aURI, &aLUID );
       
  1850     SetAdapterValue(KAMSCOMOAdapter);
       
  1851     CheckStateChangesL();
       
  1852     TError ret(EExecUndefError);
       
  1853 
       
  1854     if (aLUID == KNullDesC8)
       
  1855         {
       
  1856         RDEBUG("CSCOMOAdapter::ExecuteCommandL(): WARNING no valid luid provided" );
       
  1857         }
       
  1858 
       
  1859 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  1860     TInt cnt( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  1861 #else
       
  1862     TInt cnt(NSmlDmURI::NumOfURISegs(aURI) );
       
  1863 #endif	
       
  1864 
       
  1865     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  1866 
       
  1867     const TInt KDownloadMappingURILoc = 3;
       
  1868     switch (cnt)
       
  1869         {
       
  1870         case 5:
       
  1871             {
       
  1872             TUint32 iluid(GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  1873                     KDownloadMappingURILoc), EDCSDownload) );
       
  1874 
       
  1875             // Track the Newly added delivered  node to make sure that this reference
       
  1876             // of delivered node is removed from Tree DB.
       
  1877             // This delivered node is removed only if Execute command is successful
       
  1878             // by either adding Install, Install& activate etc.
       
  1879             // This Fix would be applicable in case of DM 1.2. 
       
  1880 
       
  1881 
       
  1882             TPtrC8 urival(URISegsUpTo(aURI, KDownloadMappingURILoc));
       
  1883 
       
  1884             if (iUriDel)
       
  1885                 {
       
  1886                 delete iUriDel;
       
  1887                 iUriDel = NULL;
       
  1888                 }
       
  1889 
       
  1890             iUriDel = urival.AllocL();
       
  1891 
       
  1892             RDEBUG_2("CSCOMOAdapter::ExecuteCommandL(): luid is %d", iluid );
       
  1893             if (iluid > 0)
       
  1894                 {
       
  1895                 TDownloadTarget target = DownloadTargetL(mapping);
       
  1896 
       
  1897                 TRAPD( errx, SessionL().StartDownloadL( iluid, target ) );
       
  1898                 
       
  1899 
       
  1900                 //Check If Sync is supported. Default is ASyncReporting.
       
  1901                 //If ASyncSupported is 0 mean Sync reporting is supported.  
       
  1902                 TInt ASyncSupported = -1;
       
  1903 
       
  1904                 CRepository *repository=CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys );
       
  1905                 repository->Get(KAsyncEnabled,ASyncSupported);
       
  1906                 CleanupStack::PopAndDestroy();
       
  1907                     
       
  1908 				if(errx == KErrNone)
       
  1909 				{
       
  1910                 if (ASyncSupported)
       
  1911                     ASyncReportL(iluid, aArgument, target, aURI);
       
  1912                 else
       
  1913                     SyncReportL(iluid, aArgument, target, aURI, ret);
       
  1914 				}
       
  1915 
       
  1916                 if (target == EInstall || target == EInstallAndActivate)
       
  1917                     {
       
  1918                     TInt err(iDbSession.RemoveMappingInfoL(KAMAdapterImplUid,
       
  1919                             *iUriDel, iluid) );
       
  1920                     }
       
  1921                 if (errx == KErrNone)
       
  1922                     {
       
  1923                     RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): StartDownloadL Successful " );
       
  1924                     if (ASyncSupported)
       
  1925                     {
       
  1926                        
       
  1927                        ret = EAcceptedForProcessing;
       
  1928                     }
       
  1929                         
       
  1930                     
       
  1931                     }
       
  1932                 else
       
  1933                     {
       
  1934                     RDEBUG_2( "CSCOMOAdapter::ExecuteCommandL(): StartDownloadL FAILED '%d'", errx );
       
  1935                     if (errx == KErrNotFound)
       
  1936                         {
       
  1937                         ret = ENotFound;
       
  1938                         }
       
  1939                     else
       
  1940                         if (errx == KErrArgument)
       
  1941                             {
       
  1942                             ret = EExecUndefError;
       
  1943                             }
       
  1944                         else
       
  1945                             {
       
  1946                             ret = EExecUndefError;
       
  1947                             }
       
  1948                     }
       
  1949 
       
  1950                 }
       
  1951             else
       
  1952                 {
       
  1953                 ret = EExecUndefError;
       
  1954                 RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 5 Not found node" );
       
  1955                 }
       
  1956             break;
       
  1957             }
       
  1958         case 6:
       
  1959             {
       
  1960             const TInt KInventoryMappingURILoc = 4;
       
  1961 
       
  1962             // Track the Newly added delivered  node to make sure that this reference
       
  1963             // of delivered node is removed from Tree DB.
       
  1964             // This delivered node is removed only if Execute command is successful
       
  1965             // by either adding Install, Install& activate etc.
       
  1966             // This Fix would be applicable in case of DM 1.2. 
       
  1967 
       
  1968 
       
  1969             TPtrC8 urival(URISegsUpTo(aURI, KInventoryMappingURILoc));
       
  1970 
       
  1971             if (iUriDel)
       
  1972                 {
       
  1973                 delete iUriDel;
       
  1974                 iUriDel = NULL;
       
  1975                 }
       
  1976 
       
  1977             iUriDel = urival.AllocL();
       
  1978 
       
  1979             if (mapping == KAMInstallNodeName || mapping
       
  1980                     == KAMInstallInactiveNodeName)
       
  1981                 {
       
  1982                 TUint32 iluid(GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  1983                         KInventoryMappingURILoc), EDCSDelivered) );
       
  1984                 if (iluid > 0)
       
  1985                     {
       
  1986                     TDeploymentComponentState targetstate = ((mapping
       
  1987                             == KAMInstallNodeName)
       
  1988                                                    ? EDCSActive
       
  1989                                                       : EDCSInactive);
       
  1990                     InstallL(iluid, aURI, aLUID, targetstate, ret);
       
  1991 
       
  1992                     TInt err(iDbSession.RemoveMappingInfoL(KAMAdapterImplUid,
       
  1993                             *iUriDel, iluid) );
       
  1994                     }
       
  1995                 else
       
  1996                     {
       
  1997                     ret = EExecInstallFailed;
       
  1998                     RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 6 install Not found node" );
       
  1999                     }
       
  2000                 }
       
  2001             else
       
  2002                 if (mapping == KAMRemoveNodeName)
       
  2003                     {
       
  2004                     TPtrC8 parent( NSmlDmURI::RemoveLastSeg( urival ) );
       
  2005                     TPtrC8 ParentMapping( NSmlDmURI::LastURISeg( parent ) );
       
  2006                     TUint32 iluid(0);
       
  2007                     if ( ParentMapping == KAMDeliveredNodeName )
       
  2008                         {
       
  2009                         iluid = GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  2010                                                     KInventoryMappingURILoc), EDCSDelivered) ;
       
  2011                         }
       
  2012                     
       
  2013                     else if ( ParentMapping == KAMDeployedNodeName)
       
  2014                         {
       
  2015                         iluid = GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  2016                                 KInventoryMappingURILoc), EDCSActive) ;
       
  2017                         if ( (TInt32)iluid <= 0)
       
  2018                             {
       
  2019                             iluid = GetLuidL(aLUID, NSmlDmURI::URISeg(aURI,
       
  2020                                     KInventoryMappingURILoc), EDCSInactive) ;
       
  2021                             }
       
  2022                         }
       
  2023                     if (iluid > 0)
       
  2024                         {
       
  2025                         TRAPD( err, SessionL().RemoveL( iluid ) )
       
  2026                         ;
       
  2027                         if (err == KErrNone)
       
  2028                             {
       
  2029                             RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): Remove success!" );
       
  2030                             TPtrC8 aclmapping(URISegsUpTo(aURI, 4) );
       
  2031 
       
  2032                             // "Nullify" the mapping for argument
       
  2033                            err = iDbSession.RemoveMappingInfoL(KAMAdapterImplUid, aclmapping);
       
  2034                             if (err == KErrNone)
       
  2035                                 {
       
  2036                                 ret = EExecSuccess;
       
  2037                                 }
       
  2038                             if (iInAtomic)
       
  2039                                 {
       
  2040                                 iBuffer.Append(TAMCommandBufferElement(
       
  2041                                         aStatusRef, aURI) );
       
  2042                                 }
       
  2043                             }
       
  2044                         else
       
  2045                             {
       
  2046                             RDEBUG_2( "CSCOMOAdapter::ExecuteCommandL(): Remove FAILED '%d'", err);
       
  2047 
       
  2048                             if (err == SwiUI::KSWInstErrUserCancel)
       
  2049                                 ret = EExecUserCancelled;
       
  2050                             else
       
  2051                                 MAPERROR( err, ret, _L8("Execute Remove %d") );
       
  2052                             }
       
  2053                         }
       
  2054                     else
       
  2055                         {
       
  2056                         ret = EExecRemoveFailed;
       
  2057                         RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 6 remove Not found node" );
       
  2058                         }
       
  2059                     }
       
  2060                         else
       
  2061                             if (mapping == KAMActivateNodeName)
       
  2062                                 {
       
  2063                                 //DBG_ARGS8( "CSCOMOAdapter::ExecuteCommandL(): Activating " );
       
  2064                                 TUint32 iluid(GetLuidL(aLUID,
       
  2065                                         NSmlDmURI::URISeg(aURI,
       
  2066                                                 KInventoryMappingURILoc),
       
  2067                                         EDCSActive) );
       
  2068                                 if ( (TInt32)iluid <= 0)
       
  2069                                     {
       
  2070                                     iluid = GetLuidL(aLUID,
       
  2071                                             NSmlDmURI::URISeg(aURI,
       
  2072                                                     KInventoryMappingURILoc),
       
  2073                                             EDCSInactive) ;
       
  2074                                     }
       
  2075                                 if (iluid > 0)
       
  2076                                     {
       
  2077                                     TRAP_IGNORE( SessionL().ActivateL( iluid ) );
       
  2078                                     ret = EExecSuccess;
       
  2079 								
       
  2080                                     //MAPERROR( erx, ret, _L8("Activate %d") );
       
  2081                                     }
       
  2082                                 else
       
  2083                                     {
       
  2084                                     ret = EExecActivateFailed;
       
  2085                                     RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 6 Activate Not found node" );
       
  2086                                     }
       
  2087                                 }
       
  2088                             else
       
  2089                                 if (mapping == KAMDeActivateNodeName)
       
  2090                                     {
       
  2091                                     //DBG_ARGS8( "CSCOMOAdapter::ExecuteCommandL(): Inactivating " );
       
  2092                                     TUint32 iluid(GetLuidL(aLUID,
       
  2093                                             NSmlDmURI::URISeg(aURI,
       
  2094                                                     KInventoryMappingURILoc),
       
  2095                                             EDCSActive) );
       
  2096                                     if ( (TInt32)iluid <= 0)
       
  2097                                         {
       
  2098                                         iluid
       
  2099                                                 = GetLuidL(
       
  2100                                                         aLUID,
       
  2101                                                         NSmlDmURI::URISeg(
       
  2102                                                                 aURI,
       
  2103                                                                 KInventoryMappingURILoc),
       
  2104                                                         EDCSInactive) ;
       
  2105                                         }
       
  2106                                     if (iluid > 0)
       
  2107                                         {
       
  2108                                         TRAP_IGNORE(SessionL().DeactivateL( iluid ) )
       
  2109                                         ;
       
  2110 										ret = EExecSuccess;
       
  2111                                         //MAPERROR( erx, ret,_L8("Dectivate %d") );
       
  2112                                         }
       
  2113                                     else
       
  2114                                         {
       
  2115                                         ret = EExecDeactivateFailed;
       
  2116                                         RDEBUG( "CSCOMOAdapter::ExecuteCommandL(): case 6 DeActivate Not found node" );
       
  2117                                         }
       
  2118                                     }
       
  2119                                 else
       
  2120                                     {
       
  2121                                     RDEBUG8_2( "CSCOMOAdapter::ExecuteCommandL(): ASKED NOT SUPPORTED OPERATION '%S'", &mapping );
       
  2122                                     
       
  2123                                     ret = EExecUndefError;
       
  2124                                     }
       
  2125             break;
       
  2126             }
       
  2127 
       
  2128         default:
       
  2129             {
       
  2130             RDEBUG8_3( "CSCOMOAdapter::ExecuteCommandL(): ILLEGAL LEVEL %d NODE %S", cnt, &aURI );
       
  2131             
       
  2132             ret = EExecUndefError;
       
  2133             break;
       
  2134             }
       
  2135         }
       
  2136     SetStatusL(aStatusRef, ret) ;
       
  2137     }
       
  2138 
       
  2139 void CSCOMOAdapter::ASyncReportL(TUint32 aLuid, const TDesC8& aArgument,
       
  2140         const TDownloadTarget aTarget,const TDesC8& aURI)
       
  2141     {
       
  2142 
       
  2143     // while sending generic alert
       
  2144     // adapter uses entry stored in database and constructs generic alert
       
  2145     // using SyncML framework API.
       
  2146 
       
  2147     TInt index = 0;
       
  2148 
       
  2149 	// Default max retry count is 5. It is also cenep configurable
       
  2150 	// Cenrep configuration responsible can change the max retry 
       
  2151 	// count
       
  2152     TInt retrycount = 5;
       
  2153     
       
  2154     CRepository *repository = CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys );
       
  2155     repository->Get(KMaxRetryCount,retrycount);
       
  2156     CleanupStack::PopAndDestroy(); //repository
       
  2157       
       
  2158     TSmlProfileId profId = KErrNotFound;
       
  2159     HBufC8* serverId= NULL;
       
  2160 
       
  2161     //Retrive Server Information
       
  2162 
       
  2163     GetServerInfoL(profId, serverId);
       
  2164 
       
  2165     CleanupStack::PushL(serverId);
       
  2166 
       
  2167     //Add Download entry to database
       
  2168 
       
  2169     iAMdb->SaveToDatabaseL(index, aLuid, profId, retrycount, aURI,
       
  2170             *serverId, aArgument);
       
  2171 
       
  2172     CleanupStack::PopAndDestroy(serverId);
       
  2173 
       
  2174     }
       
  2175 
       
  2176 void CSCOMOAdapter::SyncReportL(TUint32 aLuid, const TDesC8& aArgument,
       
  2177         const TDownloadTarget aTarget,const TDesC8& aURI, TError &aRet )
       
  2178     {
       
  2179     TInt status = KStatusSuccess;
       
  2180 
       
  2181     RProperty counter;
       
  2182     TInt r=counter.Attach(KUidPSApplicationManagementKeys, KSyncNotifier,
       
  2183             EOwnerThread);
       
  2184     User::LeaveIfError(r);
       
  2185 
       
  2186     CSyncService *syncService = CSyncService::NewL(NULL, KDevManServiceStart);
       
  2187     if (syncService)
       
  2188         {
       
  2189         syncService->EnableProgressNoteL(EFalse);
       
  2190         }
       
  2191 
       
  2192     delete syncService;
       
  2193 
       
  2194     // wait for the previously attached ‘counter’ property to be updated
       
  2195     TRequestStatus s;
       
  2196     counter.Subscribe(s);
       
  2197     User::WaitForRequest(s);
       
  2198     
       
  2199     CRepository *repository = CRepository::NewLC ( KCRUidPrivateApplicationManagementKeys );
       
  2200     repository->Get(KAMSyncStatus,status);
       
  2201     CleanupStack::PopAndDestroy();
       
  2202                 		   
       
  2203 		switch(status)
       
  2204 		{
       
  2205 			case KStatusUserCancelled:
       
  2206 			{
       
  2207 				aRet = MSmlDmAdapter::EExecUserCancelled;
       
  2208 				break;
       
  2209 			}
       
  2210 			               
       
  2211 			case KStatusDowloadFailedOOM:
       
  2212 			{
       
  2213 				aRet = MSmlDmAdapter::EExecDownFailOOM;
       
  2214 				break;
       
  2215 			}
       
  2216 
       
  2217 			case KStatusAlternateDownldAuthFail:
       
  2218 			{
       
  2219 			    aRet = MSmlDmAdapter::EExecAltDwnldAuthFail;
       
  2220 			    break;	
       
  2221 			}
       
  2222 
       
  2223 			case KStatusDownloadFailed:
       
  2224 			{
       
  2225 				aRet = MSmlDmAdapter::EExecDownloadFailed;
       
  2226 				break;
       
  2227 			}
       
  2228 
       
  2229 			case KStatusPkgValidationFailed:
       
  2230 			{
       
  2231 				aRet = MSmlDmAdapter::EExecPkgValidationFail;
       
  2232 				break;
       
  2233 			}
       
  2234 
       
  2235 			case KStatusInstallFailedOOM:
       
  2236 			{
       
  2237 				aRet = MSmlDmAdapter::EExecInstallOOM;
       
  2238 				break;
       
  2239 			}
       
  2240 
       
  2241 			case KStatusInstallFailed:
       
  2242 			{
       
  2243 				aRet = MSmlDmAdapter::EExecInstallFailed;
       
  2244 				break;
       
  2245 			}
       
  2246 		
       
  2247 		  case KStatusUnSupportedEnvironment:
       
  2248 			{
       
  2249 				aRet = MSmlDmAdapter::EExecOperationReject;
       
  2250 				break;
       
  2251 			}
       
  2252 			
       
  2253 			case KStatusAltDowldUnavailable:
       
  2254 			{
       
  2255 				aRet = MSmlDmAdapter::EExecAltDwnldSrvUnavailable;
       
  2256 				break;
       
  2257 			}
       
  2258 		
       
  2259 			default:
       
  2260 			{
       
  2261 			    aRet = MSmlDmAdapter::EExecSuccess;
       
  2262 				break;
       
  2263 			}
       
  2264 		}                
       
  2265     
       
  2266 
       
  2267     }
       
  2268 
       
  2269 void CSCOMOAdapter::GetServerInfoL(TSmlProfileId& aProfId, HBufC8*& aServerId) const
       
  2270     {
       
  2271     // Open session
       
  2272     RSyncMLSession session;
       
  2273     session.OpenL();
       
  2274     CleanupClosePushL(session);
       
  2275 
       
  2276     // get current job's id (and usage type)
       
  2277     TSmlJobId jobId = KErrNotFound;
       
  2278     TSmlUsageType type = ESmlDevMan;
       
  2279     session.CurrentJobL(jobId, type);
       
  2280 
       
  2281     // open currently running job
       
  2282     RSyncMLDevManJob dmJob;
       
  2283     dmJob.OpenL(session, jobId);
       
  2284     CleanupClosePushL(dmJob);
       
  2285 
       
  2286     // get job's profile id
       
  2287     aProfId = dmJob.Profile();
       
  2288 
       
  2289     // open profile using id in read-only mode
       
  2290     RSyncMLDevManProfile dmProf;
       
  2291     dmProf.OpenL(session, aProfId, ESmlOpenRead);
       
  2292     CleanupClosePushL(dmProf);
       
  2293 
       
  2294     // get profile's server id
       
  2295     aServerId = dmProf.ServerId().AllocL();
       
  2296 
       
  2297     // close handles
       
  2298     CleanupStack::PopAndDestroy( &dmProf);
       
  2299     CleanupStack::PopAndDestroy( &dmJob);
       
  2300     CleanupStack::PopAndDestroy( &session);
       
  2301     }
       
  2302 
       
  2303 // ------------------------------------------------------------------------------------------------
       
  2304 // CSCOMOAdapter::UpdateL( 
       
  2305 // 	const TUint aLuidi, 
       
  2306 // 	const TDesC8& aURI, 
       
  2307 // 	const TDesC8& aSourceLUID,
       
  2308 // 	const TDeploymentComponentState aTargetState,
       
  2309 // 	TError &aRet
       
  2310 // ------------------------------------------------------------------------------------------------
       
  2311 void CSCOMOAdapter::UpdateL(const TUint aLuidi, const TDesC8& aURI,
       
  2312         const TDesC8& aSourceLUID,
       
  2313         const TDeploymentComponentState aTargetState, TError &aRet)
       
  2314     {
       
  2315 
       
  2316 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2317     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  2318 #else
       
  2319     //nothing
       
  2320 #endif
       
  2321 
       
  2322     CBufBase *delivered = CBufFlat::NewL( 128);
       
  2323     CleanupStack::PushL(delivered);
       
  2324 
       
  2325 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2326     TPtrC8 aclmapping( NSmlDmURI::URISeg( uriPtrc, 4 ) );
       
  2327 #else
       
  2328     TPtrC8 aclmapping(NSmlDmURI::URISeg(aURI, 4) );
       
  2329 #endif
       
  2330 
       
  2331     HBufC8 *targetURI = HBufC8::NewLC(KDeployedURI().Length() + aclmapping.Length() );
       
  2332 
       
  2333     TPtr8 targetPtr(targetURI->Des() );
       
  2334     targetPtr.Copy(KDeployedURI);
       
  2335     targetPtr.Append(aclmapping);
       
  2336 
       
  2337     HBufC8 *deployed = Callback().GetLuidAllocL(targetPtr) ;
       
  2338     CleanupStack::PushL(deployed);
       
  2339 
       
  2340     //DBG_ARGS8( "CSCOMOAdapter::UpdateL(): Updating '%S' luid: '%S'" ), &targetPtr, &(*deployed));
       
  2341     if ( *deployed == KNullDesC8)
       
  2342         {
       
  2343         //DBG_ARGS8( "CSCOMOAdapter::UpdateL(): Failed to find to update target '%S'" ), &targetPtr );
       
  2344         aRet = EError;
       
  2345         }
       
  2346     else
       
  2347         {
       
  2348         // Found delivered & active or inactive components! Do update!
       
  2349         TInt depluid(DesToIntL( *deployed ));
       
  2350         TRAPD( erx, SessionL().UpdateL( aLuidi, depluid ) )
       
  2351         ;
       
  2352         MAPERROR( erx, aRet,_L8("Update %d") );
       
  2353         if (erx == KErrNone)
       
  2354             {
       
  2355             SetMappingLC(aclmapping, aTargetState, aSourceLUID, targetURI);
       
  2356             DeactivateIfInactive(aLuidi, aTargetState);
       
  2357             }
       
  2358         }
       
  2359     CleanupStack::PopAndDestroy(deployed) ;
       
  2360     CleanupStack::PopAndDestroy(targetURI) ;
       
  2361     CleanupStack::PopAndDestroy(delivered) ;
       
  2362     }
       
  2363 
       
  2364 // ------------------------------------------------------------------------------------------------
       
  2365 //  CSCOMOAdapter::CheckStateL( const TDeploymentComponent &aComp, const TDesC8& aURI
       
  2366 // ------------------------------------------------------------------------------------------------
       
  2367 TBool CSCOMOAdapter::CheckStateL(const TDeploymentComponent &aComp,
       
  2368         const TDesC8& aURI)
       
  2369     {
       
  2370 	TBool ret;
       
  2371 	if ((aComp.iState ==  EDCSDelivered) || (aComp.iState == EDCSActive) || ( aComp.iState == EDCSInactive) || (aComp.iState == EDCSDownload))
       
  2372 	{
       
  2373         // Check for map & __TARM_SYMBIAN_CONVERGENCY also ?
       
  2374         ret = ETrue;
       
  2375     }
       
  2376 	else
       
  2377 	    ret = EFalse;
       
  2378 	return ret;
       
  2379     }
       
  2380 
       
  2381 // ------------------------------------------------------------------------------------------------
       
  2382 //  CSCOMOAdapter::StateL( const TDeploymentComponent &aComp, const TDesC8& aURI
       
  2383 // ------------------------------------------------------------------------------------------------
       
  2384 TDeploymentComponentState CSCOMOAdapter::StateL(const TDesC8& aURI)
       
  2385     {
       
  2386 
       
  2387 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2388     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  2389 #else
       
  2390     //nothing
       
  2391 #endif
       
  2392 
       
  2393     TDeploymentComponentState ret(EDCSNone);
       
  2394 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2395     TInt cnt( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  2396 #else
       
  2397     TInt cnt(NSmlDmURI::NumOfURISegs(aURI) );
       
  2398 #endif	
       
  2399     if (cnt > 2)
       
  2400         {
       
  2401 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2402         TPtrC8 map( NSmlDmURI::URISeg( uriPtrc, 2 ) );
       
  2403 #else
       
  2404         TPtrC8 map(NSmlDmURI::URISeg(aURI, 2) );
       
  2405 #endif	
       
  2406         if (map == KAMInventoryNodeName)
       
  2407             {
       
  2408 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2409             TPtrC8 map( NSmlDmURI::URISeg( uriPtrc, 2 ) );
       
  2410 #else
       
  2411             TPtrC8 map(NSmlDmURI::URISeg(aURI, 2) );
       
  2412 #endif	
       
  2413             map.Set(NSmlDmURI::URISeg(aURI, 3) );
       
  2414             if (map == KAMDeployedNodeName)
       
  2415                 {
       
  2416 
       
  2417                 }
       
  2418             else
       
  2419                 if (map == KAMDeliveredNodeName)
       
  2420                     {
       
  2421                     ret = EDCSDelivered;
       
  2422                     }
       
  2423                 else
       
  2424                     {
       
  2425                     User::Leave(KErrArgument);
       
  2426                     }
       
  2427             }
       
  2428         else
       
  2429             if (map == KAMDownloadNodeName)
       
  2430                 {
       
  2431                 ret = EDCSDownload;
       
  2432                 }
       
  2433             else
       
  2434                 {
       
  2435                 User::Leave(KErrArgument);
       
  2436                 }
       
  2437         }
       
  2438     return ret;
       
  2439     }
       
  2440 
       
  2441 // ------------------------------------------------------------------------------------------------
       
  2442 //  CSCOMOAdapter::CheckStateL( const TDesC8& aURI, const TDesC8& aLUID )
       
  2443 // ------------------------------------------------------------------------------------------------
       
  2444 TBool CSCOMOAdapter::CheckStateL(const TDesC8& aURI, const TDesC8& aLUID)
       
  2445     {
       
  2446 
       
  2447     TUint32 iluid(DesToIntL(aLUID) );
       
  2448     TDeploymentComponent comp;
       
  2449     TInt err(SessionL().DeploymentComponent(iluid, comp) );
       
  2450     TBool ret(EFalse);
       
  2451     if (err == KErrNone)
       
  2452         {
       
  2453         ret = CheckStateL(comp, aURI);
       
  2454         }
       
  2455     return ret;
       
  2456     }
       
  2457 
       
  2458 // ------------------------------------------------------------------------------------------------
       
  2459 //  CSCOMOAdapter::InstallOptionsDataL(const TUint32 iluid, const TDeplCompAttrType& aDataType, 
       
  2460 //		CBufBase &aBuf, CBufBase *aRaw/*= NULL*/)
       
  2461 // ------------------------------------------------------------------------------------------------
       
  2462 void CSCOMOAdapter::InstallOptionsDataL(const TUint32 iluid,
       
  2463         const TDeplCompAttrType& aDataType, CBufBase &aBuf, CBufBase *aRaw/*= NULL*/)
       
  2464     {
       
  2465     TAMInstallOptionsPckgBuf iop;
       
  2466     TBool pushed(EFalse);
       
  2467     if ( !aRaw)
       
  2468         {
       
  2469         aRaw = CBufFlat::NewL(32);
       
  2470         CleanupStack::PushL(aRaw);
       
  2471         pushed = ETrue;
       
  2472         SessionL().DeploymentComponentDataL(iluid, aDataType, *aRaw);
       
  2473         }
       
  2474 
       
  2475     iop.Copy(aRaw->Ptr( 0) );
       
  2476     if (pushed)
       
  2477         {
       
  2478         CleanupStack::PopAndDestroy(aRaw);
       
  2479         }
       
  2480     InstallOptionsParser::SerializeOptionsL(iop(), aBuf);
       
  2481     }
       
  2482 
       
  2483 // ------------------------------------------------------------------------------------------------
       
  2484 //  CSCOMOAdapter::GetComponentDataL( const TDesC8& parent, const TDesC8& mapping, 
       
  2485 //		const TUint32 iluid, CBufBase *currentList, CBufBase *currentMime, TError &status )
       
  2486 // ------------------------------------------------------------------------------------------------
       
  2487 void CSCOMOAdapter::GetComponentDataL(const TDesC8& parent,
       
  2488         const TDesC8& mapping, const TUint32 iluid, CBufBase &currentList,
       
  2489         CBufBase &currentMime, TError &status)
       
  2490     {
       
  2491     TDeploymentComponent comp;
       
  2492     TInt err(SessionL().DeploymentComponent(iluid, comp) );
       
  2493     if (err == KErrNone)
       
  2494         {
       
  2495         RDEBUG_3( "CSCOMOAdapter::GetComponentDataL(): DeploymentComponent response: %d, state: %d", err, comp.iState );
       
  2496         if (CheckStateL(comp, parent) )
       
  2497             {
       
  2498             if (mapping == KAMPkgIDNodeName)
       
  2499                 {
       
  2500                 currentList.InsertL( 0, comp.iPkgID);
       
  2501                 status = EOk;
       
  2502                 }
       
  2503             else
       
  2504                 if (mapping == KAMNameNodeName)
       
  2505                     {
       
  2506                     currentList.InsertL( 0, comp.iName);
       
  2507                     status = EOk;
       
  2508                     }
       
  2509                 else
       
  2510                     if (mapping == KAMVersionNodeName)
       
  2511                         {
       
  2512                         currentList.InsertL( 0, comp.iVersion);
       
  2513                         status = EOk;
       
  2514                         }
       
  2515                 else
       
  2516                    if(mapping == KAMIDNodeName)
       
  2517                    {
       
  2518                    	
       
  2519                         currentList.InsertL( 0, comp.iId);
       
  2520                         status = EOk;
       
  2521                         
       
  2522                    }
       
  2523                 else
       
  2524                    if(mapping == KAMPkgIDRefNodeName)
       
  2525                    {
       
  2526                    	
       
  2527                         currentList.InsertL( 0, comp.iPkgIDRef);
       
  2528                         status = EOk;
       
  2529                         
       
  2530                    }
       
  2531 				else
       
  2532                    if(mapping == KAMPkgIDNodeName)
       
  2533                    {
       
  2534                    	
       
  2535                         currentList.InsertL( 0, comp.iPkgID);
       
  2536                         status = EOk;
       
  2537                         
       
  2538                    }               
       
  2539 				else
       
  2540                    if(mapping == KAMPkgTypeNodeName)
       
  2541                    {
       
  2542                    	
       
  2543                         currentList.InsertL( 0, comp.iPkgType);
       
  2544                         status = EOk;
       
  2545                         
       
  2546                    }             
       
  2547                 else 
       
  2548                    if ( mapping == KAMStatusNodeName )
       
  2549                 {
       
  2550                 TDeplCompAttrType dataType( UpdateFlagFromMapping( mapping ) );
       
  2551                 SessionL().DeploymentComponentDataL( iluid, dataType, currentList );
       
  2552                 status = EOk;
       
  2553                 }			
       
  2554 
       
  2555                     else
       
  2556                         if (mapping == KAMDescriptionNodeName)
       
  2557                             {
       
  2558                             currentList.InsertL(0, comp.iDescription);
       
  2559                             status = EOk;
       
  2560                             }
       
  2561                         else
       
  2562                             {
       
  2563                             TDeplCompAttrType
       
  2564                                     dataType(UpdateFlagFromMapping(mapping) );
       
  2565                             if (comp.iState == EDCSDownload)
       
  2566                                 {
       
  2567 					if ( dataType == EDCDownloadURI )//|| dataType == EDCDownloadStatus )
       
  2568                                     {
       
  2569                                     SessionL().DeploymentComponentDataL(iluid,
       
  2570                                             dataType, currentList);
       
  2571                                     status = EOk;
       
  2572                                     }
       
  2573                                 else
       
  2574                                     if (dataType == EDCInstallOptions)
       
  2575                                         {
       
  2576                                         InstallOptionsDataL(iluid, dataType,
       
  2577                                                 currentList);
       
  2578                                         status = EOk;
       
  2579                                         }
       
  2580                                     else
       
  2581                                         if (dataType == EDCConRef)
       
  2582                                             {
       
  2583                                             CBufBase *b = CBufFlat::NewL(4);
       
  2584                                             CleanupStack::PushL(b);
       
  2585                                             SessionL().DeploymentComponentDataL(
       
  2586                                                     iluid, dataType, *b);
       
  2587                                             TPckgBuf<TInt> iap;
       
  2588                                             iap.Copy(b->Ptr( 0) );
       
  2589                                             CleanupStack::PopAndDestroy(b);
       
  2590 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  2591 
       
  2592                                             CArrayFix<TSmlDmMappingInfo>* mapArray = new CArrayFixFlat<TSmlDmMappingInfo>(4);
       
  2593                                             CleanupStack::PushL(mapArray);
       
  2594 
       
  2595                                             Callback().GetMappingInfoListL( KNSmlDMMMSSlashIAPUri,*mapArray );
       
  2596 
       
  2597                                             //TInt iap = KErrNotFound; 
       
  2598                                             TSmlDmMappingInfo mapInfo;
       
  2599                                             HBufC8 * uri = NULL;
       
  2600                                             TPtr8 tempURI(uri->Des());
       
  2601 
       
  2602                                             for(TInt i = 0;i<mapArray->Count();i++)
       
  2603                                                 {
       
  2604                                                 if(iap()==DesToInt(mapArray->At(i).iURISegLUID))
       
  2605                                                     {
       
  2606                                                     tempURI=mapArray->At(i).iURISeg;
       
  2607                                                     }
       
  2608 
       
  2609                                                 }
       
  2610                                             mapArray->Reset();
       
  2611                                             CleanupStack::PopAndDestroy(); //mapArray
       
  2612                                             if ( uri != NULL )
       
  2613                                                 {
       
  2614                                                 CleanupStack::PushL( uri );
       
  2615                                                 currentList.InsertL( 0, *uri );
       
  2616                                                 CleanupStack::PopAndDestroy( uri );
       
  2617                                                 }
       
  2618 
       
  2619 #else
       
  2620 
       
  2621                                             CNSmlDMIAPMatcher
       
  2622                                                     * iapfinder =
       
  2623                                                             CNSmlDMIAPMatcher::NewLC( &Callback() );
       
  2624                                             HBufC8
       
  2625                                                     * uri =
       
  2626                                                             iapfinder->URIFromIAPIdL(iap() ) ;
       
  2627                                             CleanupStack::PopAndDestroy(iapfinder);
       
  2628                                             if (uri != NULL)
       
  2629                                                 {
       
  2630                                                 CleanupStack::PushL(uri) ;
       
  2631                                                 currentList.InsertL( 0, *uri);
       
  2632                                                 CleanupStack::PopAndDestroy(uri) ;
       
  2633                                                 }
       
  2634 
       
  2635 #endif
       
  2636                                             status = EOk;
       
  2637                                             }
       
  2638                                         else
       
  2639                                             {
       
  2640                                             RDEBUG8_2( "CSCOMOAdapter::GetComponentDataL(): ASKED NOT SUPPORTED LEAF '%S'", &mapping );
       
  2641                                             }
       
  2642                                 }
       
  2643                             else
       
  2644                                 if (comp.iState == EDCSDelivered)
       
  2645                                     {
       
  2646                                     if(mapping == KAMStateValueNodeName)
       
  2647                                         {
       
  2648                                       currentList.InsertL( 0,KAMStateValueDelivered() );
       
  2649                                       status = EOk;
       
  2650                                         }
       
  2651                                     if (dataType == EDCData || dataType
       
  2652                                             == EDCMetaData || dataType
       
  2653                                             == EDCInstallOptions)
       
  2654                                         {
       
  2655                                         CBufBase *raw = CBufFlat::NewL( 128);
       
  2656                                         CleanupStack::PushL(raw);
       
  2657                                         SessionL().DeploymentComponentDataL(
       
  2658                                                 iluid, dataType, *raw);
       
  2659                                         TPtrC8 source(raw->Ptr(0) );
       
  2660                                         if (source.Length() > 0)
       
  2661                                             {
       
  2662                                             if (dataType == EDCData)
       
  2663                                                 {
       
  2664                                                 currentList.InsertL( 0,
       
  2665                                                         source);
       
  2666                                                 SessionL().DeploymentComponentDataL(
       
  2667                                                         iluid, EDCDataMime,
       
  2668                                                         currentMime);
       
  2669 
       
  2670                                                 }
       
  2671                                             else
       
  2672                                                 if (dataType
       
  2673                                                         == EDCInstallOptions)
       
  2674                                                     {
       
  2675                                                     InstallOptionsDataL(
       
  2676                                                             iluid, dataType,
       
  2677                                                             currentList, raw);
       
  2678                                                     }
       
  2679                                                 else
       
  2680                                                     {
       
  2681                                                     currentList.InsertL( 0,
       
  2682                                                             source);
       
  2683                                                     SessionL().DeploymentComponentDataL(
       
  2684                                                             iluid,
       
  2685                                                             EDCMetaDataMime,
       
  2686                                                             currentMime);
       
  2687                                                     }
       
  2688                                             }
       
  2689                                         else
       
  2690                                             {
       
  2691                                             // 0 data length...
       
  2692                                             }
       
  2693                                         status = EOk;
       
  2694                                         CleanupStack::PopAndDestroy(raw);
       
  2695                                         RDEBUG8_2( "CSCOMOAdapter::GetComponentDataL(): DeploymentComponentDataL called '%S'", &mapping );
       
  2696                                         }
       
  2697                                     }
       
  2698                                 else
       
  2699                                     if (dataType == EDCStateValue)
       
  2700                                         {
       
  2701                                         if (comp.iState == EDCSActive)
       
  2702                                             {
       
  2703                                             currentList.InsertL( 0,
       
  2704                                                     KAMStateValueActive() );
       
  2705                                             }
       
  2706                                         else
       
  2707                                             {
       
  2708                                             currentList.InsertL( 0,
       
  2709                                                     KAMStateValueInactive() );
       
  2710                                             }
       
  2711                                         status = EOk;
       
  2712                                         }
       
  2713                                     else
       
  2714                                         {
       
  2715                                         RDEBUG8_2( "CSCOMOAdapter::GetComponentDataL(): ERROR ASKED NOT SUPPORTED LEAF '%S'", &mapping );
       
  2716                                         }
       
  2717                             }
       
  2718             }
       
  2719         else
       
  2720             {
       
  2721             RDEBUG8_3( "CSCOMOAdapter::GetComponentDataL(): WARNING Asked illegal state leaf '%S', %d", &mapping, comp.iState );
       
  2722             status = ENotFound;
       
  2723             }
       
  2724         }
       
  2725     else
       
  2726         {
       
  2727         RDEBUG_3( "CSCOMOAdapter::GetComponentDataL(): ERROR FAILED TO GET COMPOMENT OF ID %d: %d", iluid, err );
       
  2728         MAPERROR( err, status,_L8("Get Component %d") );
       
  2729         }
       
  2730     }
       
  2731 
       
  2732 // ------------------------------------------------------------------------------------------------
       
  2733 //  CSCOMOAdapter::GetLeafLuidL(const TDesC8 &aURI, const TDesC8 & aParentMapping ) 
       
  2734 // ------------------------------------------------------------------------------------------------
       
  2735 TInt CSCOMOAdapter::GetLeafLuidL(const TDesC8 &aURI,
       
  2736         const TDesC8 & aParentMapping)
       
  2737     {
       
  2738 
       
  2739 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2740     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  2741     TInt numSeqs( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  2742 #else
       
  2743     TInt numSeqs(NSmlDmURI::NumOfURISegs(aURI) );
       
  2744 #endif
       
  2745 
       
  2746     TUint32 iluid( 0);
       
  2747     //TInt numSeqs( NSmlDmURI::NumOfURISegs( aURI ) );//Dipak
       
  2748 
       
  2749     switch (numSeqs)
       
  2750         {
       
  2751         case 4: // must be a download leaf
       
  2752             {
       
  2753             iluid = GetLuidForUserIdL(aParentMapping, EDCSDownload) ;
       
  2754             break;
       
  2755             }
       
  2756         case 5: // download operation or delivered or deployed leaf
       
  2757             {
       
  2758             if (URISegsUpTo(aURI, 2, ETrue) == KDownloadURI)
       
  2759                 {
       
  2760                 RDEBUG8_2( "CSCOMOAdapter::GetLeafLuidL(): WARNING download operation leaf '%S'", &aURI );
       
  2761                 //status = EOk; 
       
  2762                 }
       
  2763             else
       
  2764                 {
       
  2765                 TPtrC8 start(URISegsUpTo(aURI, 3, ETrue) );
       
  2766                 if (start == KDeliveredURI)
       
  2767                     {
       
  2768                     iluid = GetLuidForUserIdL(aParentMapping, EDCSDelivered) ;
       
  2769                     }
       
  2770                 else
       
  2771                     if (start == KDeployedURI)
       
  2772                         {
       
  2773                         iluid = GetLuidForUserIdL(aParentMapping, EDCSActive) ;
       
  2774                         if ( (TInt32)iluid <= 0)
       
  2775                             {
       
  2776                             iluid = GetLuidForUserIdL(aParentMapping,
       
  2777                                     EDCSInactive) ;
       
  2778                             }
       
  2779                         }
       
  2780                     else
       
  2781                         {
       
  2782                         RDEBUG8_2( "CSCOMOAdapter::GetLeafLuidL(): WARNING strange uri '%S'", &aURI );
       
  2783                         }
       
  2784                 }
       
  2785             break;
       
  2786             }
       
  2787         case 6: // delivered or deployed operation leaf
       
  2788             {
       
  2789             //iluid = GetLuidForUserIdL( parentMapping, EDCSDownload ) ;
       
  2790             //status = EOk;
       
  2791             RDEBUG8_2( "CSCOMOAdapter::GetLeafLuidL(): WARNING delivered or deployed operation leaf '%S'", &aURI );
       
  2792             break;
       
  2793             }
       
  2794         default: // illegal uri
       
  2795             {
       
  2796             RDEBUG8_2( "CSCOMOAdapter::GetLeafLuidL(): ERROR requested luid of illegal URI '%S'", &aURI );
       
  2797             break;
       
  2798             }
       
  2799         }
       
  2800     return iluid;
       
  2801     }
       
  2802 
       
  2803 // ------------------------------------------------------------------------------------------------
       
  2804 //  CSCOMOAdapter::FetchLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, const TDesC8& aType, 
       
  2805 //			CBufBase& aObject )
       
  2806 // ------------------------------------------------------------------------------------------------
       
  2807 void CSCOMOAdapter::FetchLeafObjectL(const TDesC8& aURI, const TDesC8& aLUID,
       
  2808         const TDesC8& aType, const TInt aResultsRef, TInt aStatusRef)
       
  2809     {
       
  2810 
       
  2811 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  2812     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  2813 #else
       
  2814     //Nothing
       
  2815 #endif
       
  2816 
       
  2817     RDEBUG8_4("CSCOMOAdapter::FetchLeafObjectL('%S', '%S', '%S'): begin", &aURI, &aLUID, &aType );
       
  2818     SetAdapterValue(KAMSCOMOAdapter);
       
  2819     CheckStateChangesL();
       
  2820     TError status(EError);
       
  2821 
       
  2822     CBufBase *currentList = CBufFlat::NewL( 128);
       
  2823     CleanupStack::PushL(currentList);
       
  2824 
       
  2825     CBufBase *currentMime = CBufFlat::NewL( 128);
       
  2826     CleanupStack::PushL(currentMime);
       
  2827 
       
  2828     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  2829     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  2830     TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  2831 
       
  2832     HBufC8 *luid= NULL;
       
  2833     if (aLUID != KNullDesC8)
       
  2834         {
       
  2835         luid = aLUID.AllocLC();
       
  2836         }
       
  2837     else
       
  2838         { // try if we find it from download path
       
  2839         TBuf8<256> down;
       
  2840         down = KDownloadURI;
       
  2841         down.Append(parentMapping);
       
  2842         luid = Callback().GetLuidAllocL(down);
       
  2843         CleanupStack::PushL(luid);
       
  2844         if ( *luid != KNullDesC8)
       
  2845             {
       
  2846             // make it to found next time
       
  2847             DirectSetMappingL(parent, *luid);
       
  2848             MoveAclL(down, parent);
       
  2849 
       
  2850             // remove old
       
  2851             DirectSetMappingL(down, KNullDesC8);
       
  2852             }
       
  2853         }
       
  2854     if ( *luid != KNullDesC8)
       
  2855         {
       
  2856         TUint32 iluid(DesToIntL( *luid ));
       
  2857         RDEBUG8_2( "CSCOMOAdapter::FetchLeafObjectL(): Luid is : %d", iluid );
       
  2858         GetComponentDataL(parent, mapping, iluid, *currentList, *currentMime,
       
  2859                 status);
       
  2860         }
       
  2861     else
       
  2862         {
       
  2863         TUint32 iluid(GetLeafLuidL(aURI, parentMapping) );
       
  2864         if (iluid > 0)
       
  2865             {
       
  2866             HBufC8 *l = IntToDes8LC(iluid);
       
  2867             DirectSetMappingL(parent, *l);
       
  2868             CleanupStack::PopAndDestroy(l);
       
  2869             GetComponentDataL(parent, mapping, iluid, *currentList,
       
  2870                     *currentMime, status);
       
  2871             }
       
  2872         else
       
  2873             {
       
  2874             RDEBUG8_2( "CSCOMOAdapter::FetchLeafObjectL(): WARNING Faild to get luid allocation for '%S'", &parent );
       
  2875             if (aLUID == KNullDesC8)
       
  2876                 {
       
  2877 #ifdef __AM_LASTERROR_NODE
       
  2878                 if (aURI == KAMLastErrorURI)
       
  2879                     {
       
  2880                     const TDesC8& error= LastError();
       
  2881                     RDEBUG8_2( "CSCOMOAdapter::FetchLeafObjectL(): Returning last error '%S'", &error );
       
  2882                     currentList->InsertL(0, error);
       
  2883                     status = EOk;
       
  2884                     }
       
  2885                 else
       
  2886                     {
       
  2887                     status = ENotFound;
       
  2888                     }
       
  2889 #else
       
  2890                 status = ENotFound;
       
  2891 #endif
       
  2892                 }
       
  2893             }
       
  2894         }
       
  2895 
       
  2896     SetStatusL(aStatusRef, status);
       
  2897     if (status == EOk)
       
  2898         {
       
  2899         if (iInAtomic)
       
  2900             {
       
  2901             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  2902             }
       
  2903         Callback().SetResultsL(aResultsRef, *currentList,
       
  2904                 ( (currentMime->Size() > 0) ? currentMime->Ptr(0) : aType ));
       
  2905         }
       
  2906     CleanupStack::PopAndDestroy(luid);
       
  2907     CleanupStack::PopAndDestroy(currentMime); //currentMime
       
  2908     CleanupStack::PopAndDestroy(currentList); //currentList
       
  2909     RDEBUG("CSCOMOAdapter::FetchLeafObjectL: end" );
       
  2910     }
       
  2911 
       
  2912 // ------------------------------------------------------------------------------------------------
       
  2913 //  CSCOMOAdapter::IdListL( TDeploymentComponentState aState, 
       
  2914 //					CBufBase *aCurrentList, TBool aAppend /* = EFalse */)
       
  2915 // ------------------------------------------------------------------------------------------------
       
  2916 CSCOMOAdapter::TError CSCOMOAdapter::IdListL(
       
  2917         TDeploymentComponentState aState, CBufBase &aCurrentList,
       
  2918         TBool aAppend /* = EFalse */)
       
  2919     {
       
  2920 	RDEBUG_2( "CSCOMOAdapter::IdListL:Begin aState is %d", aState);
       
  2921     CSCOMOAdapter::TError ret(CSCOMOAdapter::EError);
       
  2922     RElementIdArray array;
       
  2923     TPtrC8 uriStart;
       
  2924     TBuf8<256> uri;
       
  2925 	
       
  2926     switch (aState)
       
  2927         {
       
  2928         case EDCSDelivered:
       
  2929             uriStart.Set(KDeliveredURI);
       
  2930             break;
       
  2931         case EDCSActive:
       
  2932         case EDCSInactive:
       
  2933             uriStart.Set(KDeployedURI) ;
       
  2934             break;
       
  2935         case EDCSDownload:
       
  2936             uriStart.Set(KDownloadURI) ;
       
  2937             break;
       
  2938         default:
       
  2939             break;
       
  2940 
       
  2941         }
       
  2942     TInt err(SessionL().DeploymentComponentIdsL(array, aState) );
       
  2943     if (err == KErrNone)
       
  2944         {
       
  2945         TInt count(array.Count() );
       
  2946 		RDEBUG_2( "CSCOMOAdapter::IdListL: count is %d", count);
       
  2947         if (count && aAppend && aCurrentList.Size() )
       
  2948             {
       
  2949 				RDEBUG("CSCOMOAdapter::IdListL: Inserting list size" );
       
  2950             aCurrentList.InsertL(aCurrentList.Size(), KAMSeparator8);
       
  2951             }
       
  2952         for (TInt i( 0); i < count; i++)
       
  2953             {
       
  2954             TUint32 el = array[i];
       
  2955             TDCUserId dc;
       
  2956             SessionL().DeploymentComponentUserIdL(el, dc);
       
  2957 			RDEBUG_2("CSCOMOAdapter::IdListL: Node name is %S", &dc);
       
  2958             if (uriStart == KNullDesC8() )
       
  2959                 {
       
  2960 					RDEBUG("CSCOMOAdapter::IdListL: uriStart == KNullDesC8()" );
       
  2961                 TDeploymentComponent comp;
       
  2962                 err = SessionL().DeploymentComponent(el, comp) ;
       
  2963                 if (err == KErrNone)
       
  2964                     {
       
  2965                     switch (comp.iState)
       
  2966                         {
       
  2967                         case EDCSDelivered:
       
  2968                             uriStart.Set(KDeliveredURI);
       
  2969                             break;
       
  2970                         case EDCSActive:
       
  2971                         case EDCSInactive:
       
  2972                             uriStart.Set(KDeployedURI) ;
       
  2973                             break;
       
  2974                         case EDCSDownload:
       
  2975                             uriStart.Set(KDownloadURI) ;
       
  2976                             break;
       
  2977                         default:
       
  2978                             break;
       
  2979                         }
       
  2980                     }
       
  2981                 }
       
  2982             if (uriStart != KNullDesC8() )
       
  2983                 {
       
  2984                 uri.Copy(uriStart);
       
  2985                 uri.Append(dc);
       
  2986                 HBufC8 *luid = DirectGetLuidAllocLC(uri); //Callback().GetLuidAllocL( uri );
       
  2987 				RDEBUG_2( "CSCOMOAdapter::IdListL: luid is %S", luid);
       
  2988                 if (KNullDesC8() == *luid)
       
  2989                     {
       
  2990                     RDEBUG8_3( "CSCOMOAdapter::IdListL(): WARNING updating lost luid of '%S' %d", &uri, el );
       
  2991                     HBufC8 *l = IntToDes8LC(el);
       
  2992                     if ( *luid == *l)
       
  2993                         {
       
  2994                         RDEBUG( "CSCOMOAdapter::IdListL(): WARNING CANCEL (not really updating, they're the same already" );
       
  2995                         }
       
  2996                     else
       
  2997                         {
       
  2998 							RDEBUG("CSCOMOAdapter::IdListL: DirectSetMappingL" );
       
  2999                         DirectSetMappingL(uri, *l);
       
  3000                         }
       
  3001                     CleanupStack::PopAndDestroy(l);
       
  3002                     }
       
  3003                 CleanupStack::PopAndDestroy(luid);
       
  3004 
       
  3005                 }
       
  3006             else
       
  3007                 {
       
  3008                 RDEBUG_2( "CSCOMOAdapter::IdListL(): WARNING failed to get component state of id %d, cannot check mappings ", el );
       
  3009                 }
       
  3010             aCurrentList.InsertL(aCurrentList.Size(), dc);
       
  3011             if (i + 1 < count)
       
  3012                 {
       
  3013 					RDEBUG("CSCOMOAdapter::IdListL: Adding Separator" );
       
  3014                 aCurrentList.InsertL(aCurrentList.Size(), KAMSeparator8);
       
  3015                 }
       
  3016             }
       
  3017         ret = EOk;
       
  3018         }
       
  3019     else
       
  3020         {
       
  3021         RDEBUG_2( "CSCOMOAdapter::IdListL(): Error %d", err );
       
  3022         }
       
  3023     array.Reset();
       
  3024 	RDEBUG("CSCOMOAdapter::IdListL: end" );
       
  3025     return ret;
       
  3026     }
       
  3027 
       
  3028 // ------------------------------------------------------------------------------------------------
       
  3029 //  CSCOMOAdapter::ChildURIListL( const TDesC8& aURI, const TDesC8& aParentLUID, 
       
  3030 //			const CArrayFix<TSmlDmMappingInfo>& /*aPreviousURISegmentList*/, const TInt aResultsRef, 
       
  3031 //			TInt aStatusRef );
       
  3032 // ------------------------------------------------------------------------------------------------
       
  3033 void CSCOMOAdapter::ChildURIListL(const TDesC8& aURI,
       
  3034         const TDesC8& aParentLUID,
       
  3035         const CArrayFix<TSmlDmMappingInfo>& /*aPreviousURISegmentList*/,
       
  3036         const TInt aResultsRef, TInt aStatusRef)
       
  3037     {
       
  3038 
       
  3039 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  3040     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  3041 #else
       
  3042     //Nothing
       
  3043 #endif
       
  3044 
       
  3045     RDEBUG8_3 ( "CSCOMOAdapter::ChildURIListL(): begin ('%S', '%S')" , &aURI, &aParentLUID );
       
  3046     CheckStateChangesL();
       
  3047 
       
  3048     TError ret(EError);
       
  3049 
       
  3050     CBufBase *currentList = CBufFlat::NewL( 128);
       
  3051     CleanupStack::PushL(currentList);
       
  3052 
       
  3053 #ifdef __TARM_SYMBIAN_CONVERGENCY	
       
  3054     TInt numSeqs( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  3055 #else
       
  3056     TInt numSeqs(NSmlDmURI::NumOfURISegs(aURI) );
       
  3057 #endif
       
  3058 
       
  3059     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  3060     if (numSeqs == 1)
       
  3061         {
       
  3062         currentList->InsertL( 0, KAMRootChilds);
       
  3063         ret = EOk;
       
  3064         }
       
  3065     else
       
  3066         if (numSeqs == 2)
       
  3067             {
       
  3068             if (mapping == KAMInventoryNodeName)
       
  3069                 {
       
  3070                 currentList->InsertL( 0, KAMInventoryChilds);
       
  3071                 ret = EOk;
       
  3072                 }
       
  3073             else
       
  3074                 if (mapping == KAMDownloadNodeName)
       
  3075                     {
       
  3076                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level 2 NODE %S", &aURI );
       
  3077                     TDeploymentComponentState state(EDCSDownload);
       
  3078                     ret = IdListL(state, *currentList);
       
  3079                     }
       
  3080                 else
       
  3081                     {
       
  3082                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): ILLEGAL LEVEL 2 NODE %S", &aURI );
       
  3083                     User::Leave(KErrArgument);
       
  3084                     }
       
  3085             }
       
  3086         else
       
  3087             if (numSeqs == 3)
       
  3088                 {
       
  3089                 if (mapping == KAMDeliveredNodeName)
       
  3090                     {
       
  3091                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level 3 NODE %S", &aURI );
       
  3092                     TDeploymentComponentState state(EDCSDelivered);
       
  3093                     ret = IdListL(state, *currentList);
       
  3094                     }
       
  3095                 else
       
  3096                     if (mapping == KAMDeployedNodeName)
       
  3097                         {
       
  3098                         TDeploymentComponentState state(EDCSActive);
       
  3099                         ret = IdListL(state, *currentList);
       
  3100                         if (ret == EOk)
       
  3101                             {
       
  3102                             state = EDCSInactive;
       
  3103                             ret = IdListL(state, *currentList, ETrue);
       
  3104                             }
       
  3105                         }
       
  3106                     else
       
  3107                         {
       
  3108                         if (aParentLUID != KNullDesC8)
       
  3109                             {
       
  3110                             if (CheckStateL(aURI, aParentLUID) )
       
  3111                                 {
       
  3112                                 TPtrC8
       
  3113                                         parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3114                                 TPtrC8
       
  3115                                         parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3116                                 if (parentMapping == KAMDownloadNodeName)
       
  3117                                     {
       
  3118                                     currentList->InsertL( 0,
       
  3119                                             KAMDownloadDynaChilds);
       
  3120                                     ret = EOk;
       
  3121                                     }
       
  3122                                 else
       
  3123                                     {
       
  3124                                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): ILLEGAL LEVEL 3 NODE %S", &aURI );
       
  3125                                     User::Leave(KErrArgument);
       
  3126                                     }
       
  3127                                 }
       
  3128                             else
       
  3129                                 {
       
  3130                                 RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): DC has changed state %S", &aURI );
       
  3131                                 ret = ENotFound;
       
  3132                                 }
       
  3133                             }
       
  3134                         else
       
  3135                             {
       
  3136                             RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level3 Node not found %S", &aURI );
       
  3137                             ret = ENotFound;
       
  3138                             }
       
  3139                         }
       
  3140                 }
       
  3141             else
       
  3142                 if (numSeqs == 4)
       
  3143                     {
       
  3144                     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3145                     TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3146                     if (aParentLUID == KNullDesC8)
       
  3147                         {
       
  3148                         RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): WARNING possibly a illegal level 4 node %S", &aURI );
       
  3149                         ret = ENotFound;
       
  3150                         }
       
  3151 
       
  3152                     if (parentMapping == KAMDeliveredNodeName)
       
  3153                         {
       
  3154                         if (GetLuid2L(aParentLUID, mapping, EDCSDelivered,
       
  3155                                 ret) > 0)
       
  3156                             {
       
  3157                             currentList->InsertL( 0,
       
  3158                                     KAMInventoryDeliveredDynaChilds);
       
  3159                             ret = EOk;
       
  3160                             }
       
  3161                         }
       
  3162                     else
       
  3163                         if (parentMapping == KAMDeployedNodeName)
       
  3164                             {
       
  3165                             if (GetLuid2L(aParentLUID, mapping, EDCSActive,
       
  3166                                     ret) > 0)
       
  3167                                 {
       
  3168                                 currentList->InsertL( 0,
       
  3169                                         KAMInventoryDynaChilds);
       
  3170                                 ret = EOk;
       
  3171                                 }
       
  3172                             else
       
  3173                                 if (GetLuid2L(aParentLUID, mapping,
       
  3174                                         EDCSInactive, ret) > 0)
       
  3175                                     {
       
  3176                                     currentList->InsertL( 0,
       
  3177                                             KAMInventoryDynaChilds);
       
  3178                                     ret = EOk;
       
  3179                                     }
       
  3180                             }
       
  3181                         else
       
  3182                             if (mapping == KAMOperationsNodeName)
       
  3183                                 {
       
  3184                                 if (GetLuid2L(aParentLUID, parentMapping,
       
  3185                                         EDCSDownload, ret) > 0)
       
  3186                                     {
       
  3187                                     if (CheckStateL(aURI, aParentLUID) )
       
  3188                                         {
       
  3189                                         currentList->InsertL( 0,
       
  3190                                                 KAMDownloadOperationChilds);
       
  3191                                         ret = EOk;
       
  3192                                         }
       
  3193                                     else
       
  3194                                         {
       
  3195                                         RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level3 operations DC changed state '%S'", &aURI );
       
  3196                                         ret = ENotFound;
       
  3197                                         }
       
  3198                                     }
       
  3199                                 }
       
  3200                             else
       
  3201                                 {
       
  3202                                 RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level4 Node not found '%S'", &aURI );
       
  3203                                 ret = ENotFound;
       
  3204                                 }
       
  3205                     }
       
  3206                 else
       
  3207                     if (numSeqs == 5)
       
  3208                         {
       
  3209                         if (aParentLUID == KNullDesC8)
       
  3210                             {
       
  3211                             RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): WARNING possibly a illegal level 5 node %S", &aURI );
       
  3212                             ret = ENotFound;
       
  3213                             }
       
  3214                         if (mapping == KAMOperationsNodeName)
       
  3215                             {
       
  3216                             TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3217                             TPtrC8
       
  3218                                     parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3219                             TPtrC8 gparent(NSmlDmURI::RemoveLastSeg(parent) );
       
  3220                             TPtrC8
       
  3221                                     gparentMapping(NSmlDmURI::LastURISeg(gparent) );
       
  3222                             if (gparentMapping == KAMDeliveredNodeName)
       
  3223                                 {
       
  3224                                 if (GetLuid2L(aParentLUID, parentMapping,
       
  3225                                         EDCSDelivered, ret) > 0)
       
  3226                                     {
       
  3227                                     currentList->InsertL( 0,
       
  3228                                             KAMDeliveredOperationChilds);
       
  3229                                     ret = EOk;
       
  3230                                     }
       
  3231                                 }
       
  3232                             else
       
  3233                                 if (gparentMapping == KAMDeployedNodeName)
       
  3234                                     {
       
  3235                                     if (GetLuid2L(aParentLUID, parentMapping,
       
  3236                                             EDCSActive, ret) > 0)
       
  3237                                         {
       
  3238                                         currentList->InsertL( 0,
       
  3239                                                 KAMDeployedOperationChilds);
       
  3240                                         ret = EOk;
       
  3241                                         }
       
  3242                                     else
       
  3243                                         if (GetLuid2L(aParentLUID,
       
  3244                                                 parentMapping, EDCSInactive,
       
  3245                                                 ret) > 0)
       
  3246                                             {
       
  3247                                             currentList->InsertL( 0,
       
  3248                                                     KAMDeployedOperationChilds);
       
  3249                                             ret = EOk;
       
  3250                                             }
       
  3251                                     }
       
  3252                                 else
       
  3253                                     {
       
  3254                                     RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level5 Node not found wrong parent '%S'", &aURI );
       
  3255                                     ret = ENotFound;
       
  3256                                     }
       
  3257                             }
       
  3258                         else
       
  3259                             {
       
  3260                             RDEBUG8_2( "CSCOMOAdapter::ChildURIListL(): Level5 Node not found '%S'", &aURI );
       
  3261                             ret = ENotFound;
       
  3262                             }
       
  3263                         }
       
  3264                     else
       
  3265                         {
       
  3266                         RDEBUG8_3( "CSCOMOAdapter::ChildURIListL(): ILLEGAL LEVEL %d NODE %S", numSeqs, &aURI );
       
  3267                         ret = EError;
       
  3268                         }
       
  3269 
       
  3270     SetStatusL(aStatusRef, ret);
       
  3271 
       
  3272     if (ret == EOk)
       
  3273         {
       
  3274         if (iInAtomic)
       
  3275             {
       
  3276             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  3277             }
       
  3278         Callback().SetResultsL(aResultsRef, *currentList, KNullDesC8);
       
  3279         }
       
  3280     CleanupStack::PopAndDestroy(); //currentList
       
  3281     }
       
  3282 
       
  3283 // ------------------------------------------------------------------------------------------------
       
  3284 //  CSCOMOAdapter::DeliverOrDownloadL( const TDesC8 &aUserId, const TDesC8 &aURI, TInt aCnt, 
       
  3285 //		const TDesC8 &aParentMapping, MSmlDmAdapter::TError &aStatus )
       
  3286 // ------------------------------------------------------------------------------------------------
       
  3287 void CSCOMOAdapter::DeliverOrDownloadL(const TDesC8 &aUserId,
       
  3288         const TDesC8 &aURI, TInt aCnt, const TDesC8 &aParentMapping,
       
  3289         MSmlDmAdapter::TError &aStatus)
       
  3290     {
       
  3291 
       
  3292 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  3293     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  3294 #else
       
  3295     //Nothing
       
  3296 #endif
       
  3297 
       
  3298     switch (aCnt)
       
  3299         {
       
  3300         case 3:
       
  3301             {
       
  3302             if (aParentMapping == KAMDownloadNodeName)
       
  3303                 {
       
  3304                 TUint32 luid(SessionL().DownloadL(aUserId) );
       
  3305                 Callback().SetMappingL(aURI, *IntToDes8LC(luid) );
       
  3306                 CleanupStack::PopAndDestroy();
       
  3307                 aStatus = EOk;
       
  3308                 }
       
  3309             else
       
  3310                 {
       
  3311                 RDEBUG( "CSCOMOAdapter::DeliverOrDownloadL(): ERROR Illegal parent");
       
  3312                 }
       
  3313             break;
       
  3314             }
       
  3315         case 4:
       
  3316             {
       
  3317             if (aParentMapping == KAMDeliveredNodeName)
       
  3318                 {
       
  3319                 TUint32 luid(SessionL().DeliverL(aUserId) );
       
  3320                 Callback().SetMappingL(aURI, *IntToDes8LC(luid) );
       
  3321                 CleanupStack::PopAndDestroy();
       
  3322                 aStatus = EOk;
       
  3323                 }
       
  3324             else
       
  3325                 {
       
  3326                 RDEBUG( "CSCOMOAdapter::DeliverOrDownloadL(): ERROR Illegal parent");
       
  3327                 }
       
  3328             break;
       
  3329             }
       
  3330         default:
       
  3331             {
       
  3332             RDEBUG( "CSCOMOAdapter::DeliverOrDownloadL(): ERROR Illegal URI");
       
  3333             break;
       
  3334             }
       
  3335         }
       
  3336     }
       
  3337 
       
  3338 // ------------------------------------------------------------------------------------------------
       
  3339 // CSCOMOAdapter::AddNodeObjectL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3340 // ------------------------------------------------------------------------------------------------
       
  3341 void CSCOMOAdapter::AddNodeObjectL(const TDesC8& aURI,
       
  3342         const TDesC8& aParentLUID, TInt aStatusRef)
       
  3343     {
       
  3344 
       
  3345 #ifdef __TARM_SYMBIAN_CONVERGENCY	//Done by Dipak
       
  3346     TPtrC8 uriPtrc = NSmlDmURI::RemoveDotSlash(aURI);
       
  3347     TPtrC8 mapping( NSmlDmURI::LastURISeg( uriPtrc ) );
       
  3348     TPtrC8 parent( NSmlDmURI::RemoveLastSeg( uriPtrc ) );
       
  3349     TPtrC8 parentMapping( NSmlDmURI::LastURISeg( parent ) );
       
  3350     TInt cnt( NSmlDmURI::NumOfURISegs( uriPtrc ) );
       
  3351 #else
       
  3352     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  3353     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3354     TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3355     TInt cnt(NSmlDmURI::NumOfURISegs(aURI) );
       
  3356 #endif
       
  3357 
       
  3358     RDEBUG8_3( "CSCOMOAdapter::AddNodeObjectL(): begin '%S', '%S'", &aURI, &aParentLUID );
       
  3359     SetAdapterValue(KAMSCOMOAdapter);
       
  3360     CheckStateChangesL();
       
  3361     TError status(EError);
       
  3362     //	TPtrC8 mapping( NSmlDmURI::LastURISeg( aURI ) );//Dipak
       
  3363     //	TPtrC8 parent( NSmlDmURI::RemoveLastSeg( aURI ) );
       
  3364     //	TPtrC8 parentMapping( NSmlDmURI::LastURISeg( parent ) );
       
  3365     //	TInt cnt( NSmlDmURI::NumOfURISegs( aURI ) );
       
  3366 	TUint32 iluid( GetLuidL( aParentLUID, mapping, (parentMapping == KAMDeliveredNodeName ? EDCSDelivered : ( parentMapping == KAMDownloadNodeName ? EDCSDownload : EDCSNone ) ) ) ) ;
       
  3367 	if( !iluid)
       
  3368 	    {
       
  3369             // This is added for avoiding duplicate node creation in Delivered/Download only.
       
  3370 	    iluid = GetLuidL( aParentLUID, mapping, (parentMapping == KAMDeliveredNodeName ? EDCSDownload:EDCSDelivered ));
       
  3371 	    }
       
  3372     if (iluid == 0)
       
  3373         {
       
  3374         // Not found, add it ... 
       
  3375         DeliverOrDownloadL(mapping, aURI, cnt, parentMapping, status);
       
  3376         }
       
  3377     else
       
  3378         {
       
  3379         RDEBUG_2( "CSCOMOAdapter::AddNodeObjectL(): WARNING May Already exists '%d'", iluid );
       
  3380         TDeploymentComponent comp;
       
  3381         TInt err(SessionL().DeploymentComponent(iluid, comp) );
       
  3382         if (err == KErrNone)
       
  3383             {
       
  3384             RDEBUG_2( "CSCOMOAdapter::AddNodeObjectL(): ERROR Already exists '%d'", iluid );
       
  3385             if (comp.iState == StateL(aURI) )
       
  3386                 {
       
  3387                 RDEBUG( "CSCOMOAdapter::AddNodeObjectL():    (state is ok) " );
       
  3388                 }
       
  3389             else
       
  3390                 {
       
  3391                 RDEBUG( "CSCOMOAdapter::AddNodeObjectL():    (state is NOK) " );
       
  3392                 }
       
  3393             status = EAlreadyExists;
       
  3394             }
       
  3395         else
       
  3396             {
       
  3397             if (err == KErrNotFound)
       
  3398                 {
       
  3399                 RDEBUG_2( "CSCOMOAdapter::AddNodeObjectL(): WARNING Already exists but not found '%d'", iluid );
       
  3400                 DeliverOrDownloadL(mapping, aURI, cnt, parentMapping, status);
       
  3401                 }
       
  3402             else
       
  3403                 {
       
  3404 
       
  3405                 RDEBUG_2( "CSCOMOAdapter::AddNodeObjectL(): ERROR May exists, but failed to fetch get one? '%d'", err );
       
  3406                 }
       
  3407             }
       
  3408         }
       
  3409     if (status == EOk)
       
  3410         {
       
  3411         if (iInAtomic)
       
  3412             {
       
  3413             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  3414             }
       
  3415         }
       
  3416 
       
  3417     //status = EAcceptedForProcessing;
       
  3418     //TInt error = 202;
       
  3419     SetStatusL(aStatusRef, status);
       
  3420     RDEBUG( "CSCOMOAdapter::AddNodeObject(): end" );
       
  3421     }
       
  3422 
       
  3423 // ------------------------------------------------------------------------------------------------
       
  3424 // CSCOMOAdapter::GetSizeL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3425 // ------------------------------------------------------------------------------------------------
       
  3426 TInt CSCOMOAdapter::GetSizeL(const TDeplCompAttrType aDataType,
       
  3427         const TInt aLuid, TError &aRet)
       
  3428     {
       
  3429     TInt size( 0);
       
  3430     if (aDataType == EDCStateValue)
       
  3431         {
       
  3432         TDeploymentComponent comp;
       
  3433         TInt err(SessionL().DeploymentComponent(aLuid, comp) );
       
  3434         if (err == KErrNone)
       
  3435             {
       
  3436             if (comp.iState == EDCSActive)
       
  3437                 {
       
  3438                 size = KAMStateValueActive().Length();
       
  3439                 }
       
  3440             else if (comp.iState == EDCSDelivered)
       
  3441                 {
       
  3442                 size = KAMStateValueDelivered().Length();
       
  3443                 }
       
  3444             else
       
  3445                 {
       
  3446                 size = KAMStateValueInactive().Length() ;
       
  3447                 }
       
  3448             aRet = EOk;
       
  3449             }
       
  3450         }
       
  3451     else
       
  3452         {
       
  3453         size = SessionL().DeploymentComponentDataSizeL(aLuid, aDataType);
       
  3454         aRet = EOk;
       
  3455         }
       
  3456     return size;
       
  3457     }
       
  3458 
       
  3459 // ------------------------------------------------------------------------------------------------
       
  3460 // CSCOMOAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3461 // ------------------------------------------------------------------------------------------------
       
  3462 void CSCOMOAdapter::FetchLeafObjectSizeL(const TDesC8& aURI,
       
  3463         const TDesC8& aLUID, const TDesC8& aType, TInt aResultsRef,
       
  3464         TInt aStatusRef)
       
  3465     {
       
  3466 
       
  3467     RDEBUG8_4("CSCOMOAdapter::FetchLeafObjectSizeL('%S', '%S', '%S'): begin", &aURI, &aLUID, &aType );
       
  3468     CheckStateChangesL();
       
  3469     TError status(EError);
       
  3470     CBufBase *currentList = CBufFlat::NewL( 128);
       
  3471     CleanupStack::PushL(currentList);
       
  3472 
       
  3473     TPtrC8 mapping(NSmlDmURI::LastURISeg(aURI) );
       
  3474     TPtrC8 parent(NSmlDmURI::RemoveLastSeg(aURI) );
       
  3475     TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  3476     TInt size( 0);
       
  3477     HBufC8 *luid= NULL;
       
  3478     if (aLUID != KNullDesC8)
       
  3479         {
       
  3480         luid = aLUID.AllocLC();
       
  3481         }
       
  3482     else
       
  3483         { // try if we find it from download path
       
  3484         TBuf8<256> down;
       
  3485         down = KDownloadURI;
       
  3486         down.Append(parentMapping);
       
  3487         luid = Callback().GetLuidAllocL(down);
       
  3488         CleanupStack::PushL(luid);
       
  3489         if ( *luid != KNullDesC8)
       
  3490             {
       
  3491             // make it to found next time
       
  3492             DirectSetMappingL(parent, *luid);
       
  3493             MoveAclL(down, parent);
       
  3494 
       
  3495             // remove old
       
  3496             DirectSetMappingL(down, KNullDesC8);
       
  3497             }
       
  3498         }
       
  3499     TDeplCompAttrType dataType(UpdateFlagFromMapping(mapping) );
       
  3500     if ( *luid != KNullDesC8)
       
  3501         {
       
  3502         TUint32 iluid(DesToIntL( *luid ));
       
  3503         RDEBUG_2( "CSCOMOAdapter::FetchLeafObjectSizeL(): Luid is : %d", iluid );
       
  3504         size = GetSizeL(dataType, iluid, status);
       
  3505         }
       
  3506     else
       
  3507         {
       
  3508         TUint32 iluid(GetLeafLuidL(aURI, parentMapping) );
       
  3509         if (iluid > 0)
       
  3510             {
       
  3511             HBufC8 *l = IntToDes8LC(iluid);
       
  3512             DirectSetMappingL(parent, *l);
       
  3513             CleanupStack::PopAndDestroy(l);
       
  3514             size = GetSizeL(dataType, iluid, status);
       
  3515             }
       
  3516         else
       
  3517             {
       
  3518             RDEBUG8_2( "CSCOMOAdapter::FetchLeafObjectSizeL(): WARNING Faild to get luid allocation for '%S'", &parent );
       
  3519             if (aLUID == KNullDesC8)
       
  3520                 {
       
  3521                 status = ENotFound;
       
  3522                 }
       
  3523             }
       
  3524         }
       
  3525     SetStatusL(aStatusRef, status);
       
  3526     if (status == EOk && size > 0)
       
  3527         {
       
  3528         HBufC8 *hsize = IntToDes8LC(size);
       
  3529         currentList->InsertL( 0, *hsize);
       
  3530         if (iInAtomic)
       
  3531             {
       
  3532             iBuffer.Append(TAMCommandBufferElement(aStatusRef, aURI) );
       
  3533             }
       
  3534         Callback().SetResultsL(aResultsRef, *currentList, aType);
       
  3535         CleanupStack::PopAndDestroy(hsize);
       
  3536         }
       
  3537     CleanupStack::PopAndDestroy(luid);
       
  3538     CleanupStack::PopAndDestroy(currentList); //currentList	
       
  3539     }
       
  3540 
       
  3541 // ------------------------------------------------------------------------------------------------
       
  3542 // CSCOMOAdapter::ExecuteCommandL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3543 // ------------------------------------------------------------------------------------------------
       
  3544 void CSCOMOAdapter::ExecuteCommandL(const TDesC8& /*aURI*/,
       
  3545         const TDesC8& /*aLUID*/, RWriteStream*& /*aStream*/,
       
  3546         const TDesC8& /*aType*/, TInt /*aStatusRef*/)
       
  3547     {
       
  3548     RDEBUG("CSCOMOAdapter::ExecuteCommandL(stream): begin (NOT SUPPORTED)");
       
  3549     User::Leave(KErrNotSupported);
       
  3550     }
       
  3551 
       
  3552 // ------------------------------------------------------------------------------------------------
       
  3553 // CSCOMOAdapter::CopyCommandL( const TDesC8& aURI, const TDesC& aParentLUID )
       
  3554 // ------------------------------------------------------------------------------------------------
       
  3555 void CSCOMOAdapter::CopyCommandL(const TDesC8& /*aTargetURI*/,
       
  3556         const TDesC8& /*aTargetLUID*/, const TDesC8& /*aSourceURI*/,
       
  3557         const TDesC8& /*aSourceLUID*/, const TDesC8& /*aType*/,
       
  3558         TInt aStatusRef)
       
  3559     {
       
  3560     RDEBUG("CSCOMOAdapter::CopyCommandL(): begin (NOT SUPPORTED)");
       
  3561     SetStatusL(aStatusRef, EError);
       
  3562 
       
  3563     }
       
  3564 
       
  3565 // ------------------------------------------------------------------------------------------------
       
  3566 // CSCOMOAdapter::StartAtomicL(  )
       
  3567 // ------------------------------------------------------------------------------------------------
       
  3568 void CSCOMOAdapter::StartAtomicL()
       
  3569     {
       
  3570     RDEBUG("CSCOMOAdapter::StartAtomicL(): begin (NOT properly SUPPORTED)");
       
  3571     iInAtomic = ETrue;
       
  3572     }
       
  3573 
       
  3574 // ------------------------------------------------------------------------------------------------
       
  3575 // CSCOMOAdapter::CommitAtomicL(  )
       
  3576 // ------------------------------------------------------------------------------------------------
       
  3577 void CSCOMOAdapter::CommitAtomicL()
       
  3578     {
       
  3579     RDEBUG("CSCOMOAdapter::CommitAtomicL(): begin (NOT SUPPORTED)");
       
  3580     iInAtomic = EFalse; // the initial statuses are already set
       
  3581     }
       
  3582 
       
  3583 // ------------------------------------------------------------------------------------------------
       
  3584 // CSCOMOAdapter::RollbackAtomicL(  )
       
  3585 // ------------------------------------------------------------------------------------------------
       
  3586 void CSCOMOAdapter::RollbackAtomicL()
       
  3587     {
       
  3588     RDEBUG("CSCOMOAdapter::RollbackAtomicL(): begin (NOT properly SUPPORTED)");
       
  3589     TInt count(iBuffer.Count() );
       
  3590     for (TInt i( 0); i < count; i++)
       
  3591         {
       
  3592         TAMCommandBufferElement &pm(iBuffer[i]);
       
  3593         SetStatusL(pm.iStatusRef, ERollbackFailed);
       
  3594         }
       
  3595     }
       
  3596 
       
  3597 // ------------------------------------------------------------------------------------------------
       
  3598 // CSCOMOAdapter::StreamingSupport( )
       
  3599 // ------------------------------------------------------------------------------------------------
       
  3600 TBool CSCOMOAdapter::StreamingSupport(TInt& aItemSize)
       
  3601     {
       
  3602     RDEBUG("CSCOMOAdapter::StreamingSupport(): begin");
       
  3603     //aItemSize = 1024;
       
  3604     
       
  3605     // After Generic alert is sent delete that entry from database and notify
       
  3606     // AM server to delete the appropriate entry in its database.
       
  3607     
       
  3608     if(aItemSize == KNSmlDMResetGenAlerts)
       
  3609     {
       
  3610       TSmlProfileId profId = 0;
       
  3611       HBufC8* serverId = NULL;
       
  3612       TRAP_IGNORE(GetServerInfoL( profId, serverId ));
       
  3613       
       
  3614     
       
  3615     TUint32 internalid;
       
  3616     RPointerArray<CAMDbItem> genericalerts;
       
  3617     
       
  3618 
       
  3619     // Get generic alert entry from Database for particular server ID.
       
  3620     TRAPD(err, iAMdb->GetEntryForServerIDL(genericalerts, *serverId));
       
  3621 
       
  3622     if (genericalerts.Count()!= KErrNone && err == KErrNone)
       
  3623         {
       
  3624           	for(TInt i=0; i<genericalerts.Count(); i++)
       
  3625     		{
       
  3626 			internalid = genericalerts[i]->iLUID;
       
  3627 			// Delete the all the generic alert details from SCOMO adapeter DB
       
  3628 			// Also delete the appropriate entry from AM Server DB as well.
       
  3629             TRAP_IGNORE(iAMdb->DeleteFromDatabaseL(internalid));
       
  3630             TRAP_IGNORE(SessionL().GenericAlertSentL(internalid));
       
  3631     		}
       
  3632         }
       
  3633     
       
  3634 
       
  3635     genericalerts.ResetAndDestroy();
       
  3636     delete serverId;
       
  3637 
       
  3638     _LIT(KNull,"");
       
  3639     // No monitoring required after generic alert is sent
       
  3640     TInt err_rep = KErrNone;
       
  3641     CRepository *repository1 = NULL;
       
  3642 
       
  3643     TRAP(err_rep, repository1 =CRepository::NewL ( KCRUidDeviceManagementInternalKeys ));
       
  3644   
       
  3645     if(err_rep == KErrNone)  
       
  3646     {
       
  3647     repository1 ->Set(KDevManServerIdKey ,KNull);
       
  3648     repository1 ->Set(KDevManIapIdKey, KErrNone);
       
  3649     repository1 ->Set(KDevManEnableDMNetworkMon, KErrNone);
       
  3650     }
       
  3651      
       
  3652     if(repository1)
       
  3653      delete repository1;
       
  3654       
       
  3655     }
       
  3656     aItemSize = 1024;
       
  3657     RDEBUG("CSCOMOAdapter::StreamingSupport(): end");
       
  3658     return ETrue;
       
  3659     }
       
  3660 
       
  3661 // ------------------------------------------------------------------------------------------------
       
  3662 // CSCOMOAdapter::StreamCommittedL( )
       
  3663 // ------------------------------------------------------------------------------------------------
       
  3664 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  3665 void CSCOMOAdapter::StreamCommittedL( RWriteStream& /*aStream*/)
       
  3666 #else
       
  3667 void CSCOMOAdapter::StreamCommittedL()
       
  3668 #endif
       
  3669     {
       
  3670     RDEBUG("CSCOMOAdapter::StreamCommittedL(): begin");
       
  3671 
       
  3672     if (iStreamOpen)
       
  3673         {
       
  3674         iStream.CommitL();
       
  3675         }
       
  3676 
       
  3677     MSmlDmAdapter::TError status = EOk;
       
  3678 
       
  3679     TRAPD( err, _UpdateLeafObjectL( *iStreamedURI, *iStreamedLuid, KNullDesC8(), *iStreamedType, iStatusRef, status ) )
       
  3680     ;
       
  3681 
       
  3682     if (err != KErrNone)
       
  3683         {
       
  3684         RDEBUG_2("CSCOMOAdapter::StreamCommittedL(): _UpdateLeafObjectL returned error (%d)", err);
       
  3685         }
       
  3686 
       
  3687     iIsStreamedContent = EFalse;
       
  3688     iStreamOpen = EFalse;
       
  3689 
       
  3690     Callback().SetStatusL(iStatusRef, status);
       
  3691 
       
  3692     RDEBUG("CSCOMOAdapter::StreamCommittedL(): end");
       
  3693     }
       
  3694 
       
  3695 // ------------------------------------------------------------------------------------------------
       
  3696 // CSCOMOAdapter::CloseStreaming( )
       
  3697 // ------------------------------------------------------------------------------------------------
       
  3698 void CSCOMOAdapter::CloseStreaming()
       
  3699     {
       
  3700     if (iStreamOpen)
       
  3701         {
       
  3702         RDEBUG("CSCOMOAdapter::CloseStreaming(): closing");
       
  3703         iStreamFile.Close(); // !!! Closing this will also close the iStreamRFs because it is adopted from server
       
  3704         iStreamOpen = EFalse;
       
  3705         }
       
  3706     }
       
  3707 
       
  3708 // ------------------------------------------------------------------------------------------------
       
  3709 // CSCOMOAdapter::CompleteOutstandingCmdsL()
       
  3710 // ------------------------------------------------------------------------------------------------
       
  3711 void CSCOMOAdapter::CompleteOutstandingCmdsL()
       
  3712     {
       
  3713     RDEBUG("CSCOMOAdapter::CompleteOutstandingCmdsL(): begin");
       
  3714     /*	iManagement.Close();
       
  3715      iSessionOpened = EFalse ;*/
       
  3716     iBuffer.Reset();
       
  3717     RDEBUG("CSCOMOAdapter::CompleteOutstandingCmdsL(): Management session closed");
       
  3718     }
       
  3719 
       
  3720 // ------------------
       
  3721 //
       
  3722 // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
       
  3723 const TImplementationProxy ImplementationTable[] =
       
  3724     {
       
  3725     //
       
  3726             IMPLEMENTATION_PROXY_ENTRY( KAMAdapterImplUid, CSCOMOAdapter::NewL )
       
  3727     };
       
  3728 
       
  3729 // ------------------------------------------------------------------------------------------------
       
  3730 //
       
  3731 // ------------------------------------------------------------------------------------------------
       
  3732 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
  3733     {
       
  3734     aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy );
       
  3735     return ImplementationTable;
       
  3736     }
       
  3737 
       
  3738 // ------------------------------------------------------------------------------------------------
       
  3739 //
       
  3740 // ------------------------------------------------------------------------------------------------
       
  3741 TInt CSCOMOAdapter::DesToIntL(const TDesC8& aLuid)
       
  3742     {
       
  3743     TLex8 lex(aLuid);
       
  3744     TInt value = 0;
       
  3745     User::LeaveIfError(lex.Val(value) );
       
  3746     return value;
       
  3747     }
       
  3748 
       
  3749 // ------------------------------------------------------------------------------------------------
       
  3750 //
       
  3751 // ------------------------------------------------------------------------------------------------
       
  3752 HBufC8* CSCOMOAdapter::IntToDes8LC(const TInt aLuid)
       
  3753     {
       
  3754     HBufC8* buf = HBufC8::NewLC( 10); //10 = max length of 32bit integer
       
  3755     TPtr8 ptrBuf = buf->Des();
       
  3756     ptrBuf.Num(aLuid);
       
  3757     return buf;
       
  3758     }
       
  3759 
       
  3760 // ------------------------------------------------------------------------------------------------
       
  3761 //
       
  3762 // ------------------------------------------------------------------------------------------------
       
  3763 void CSCOMOAdapter::ConstructL()
       
  3764     {
       
  3765     iAMdb = CSCOMOAdapterDb::NewL();
       
  3766 
       
  3767 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  3768     iDbSession.ConnectL();
       
  3769 #else
       
  3770     User::LeaveIfError(iDbSession.Connect());
       
  3771 #endif
       
  3772     }
       
  3773 
       
  3774 // ------------------------------------------------------------------------------------------------
       
  3775 // CSCOMOAdapter::SetStatusL( TInt aStatusRef, MSmlDmAdapter::TError aErrorCode ) 
       
  3776 // ------------------------------------------------------------------------------------------------
       
  3777 void CSCOMOAdapter::SetStatusL(TInt aStatusRef,
       
  3778         MSmlDmAdapter::TError aErrorCode)
       
  3779     {
       
  3780     RDEBUG_3("CSCOMOAdapter::SetStatusL( %d, %d )", aStatusRef, aErrorCode );
       
  3781     Callback().SetStatusL(aStatusRef, aErrorCode);
       
  3782     }
       
  3783 
       
  3784 // ------------------------------------------------------------------------------------------------
       
  3785 // CSCOMOAdapter::SetResultsL( TInt aResultsRef, CBufBase& aObject, const TDesC8& aType )
       
  3786 // ------------------------------------------------------------------------------------------------
       
  3787 void CSCOMOAdapter::SetResultsL(TInt aResultsRef, CBufBase& aObject,
       
  3788         const TDesC8& aType)
       
  3789     {
       
  3790     Callback().SetResultsL(aResultsRef, aObject, aType);
       
  3791 
       
  3792     }
       
  3793 
       
  3794 // -------------------------------------------------------------------------------------
       
  3795 // CSCOMOAdapter::FillNodeInfoL()
       
  3796 // Fills the node info in ddf structure
       
  3797 // -------------------------------------------------------------------------------------
       
  3798 void CSCOMOAdapter::FillNodeInfoL(MSmlDmDDFObject& aNode,
       
  3799         TSmlDmAccessTypes aAccTypes, MSmlDmDDFObject::TOccurence aOccurrence,
       
  3800         MSmlDmDDFObject::TScope aScope, MSmlDmDDFObject::TDFFormat aFormat,
       
  3801         const TDesC8& aDescription)
       
  3802     {
       
  3803     FillNodeInfoNoDefaultMimeL(aNode, aAccTypes, aOccurrence, aScope,
       
  3804             aFormat, aDescription);
       
  3805     if (aFormat!=MSmlDmDDFObject::ENode)
       
  3806         {
       
  3807         aNode.AddDFTypeMimeTypeL(KAMTextPlain);
       
  3808         }
       
  3809 
       
  3810     }
       
  3811 
       
  3812 // -------------------------------------------------------------------------------------
       
  3813 // CSCOMOAdapter::FillNodeInfoNoDefaultMimeL()
       
  3814 // Fills the node info in ddf structure, without default mime type
       
  3815 // -------------------------------------------------------------------------------------
       
  3816 void CSCOMOAdapter::FillNodeInfoNoDefaultMimeL(MSmlDmDDFObject& aNode,
       
  3817         TSmlDmAccessTypes aAccTypes, MSmlDmDDFObject::TOccurence aOccurrence,
       
  3818         MSmlDmDDFObject::TScope aScope, MSmlDmDDFObject::TDFFormat aFormat,
       
  3819         const TDesC8& aDescription)
       
  3820     {
       
  3821     aNode.SetAccessTypesL(aAccTypes);
       
  3822     aNode.SetOccurenceL(aOccurrence);
       
  3823     aNode.SetScopeL(aScope);
       
  3824     aNode.SetDFFormatL(aFormat);
       
  3825 
       
  3826     aNode.SetDescriptionL(aDescription);
       
  3827     }
       
  3828 
       
  3829 // -------------------------------------------------------------------------------------
       
  3830 // CSCOMOAdapter::CheckStateChangesInternalL()
       
  3831 // Updates the changed DC states to DM client mappings and ACLs
       
  3832 // -------------------------------------------------------------------------------------
       
  3833 void CSCOMOAdapter::CheckStateChangesInternalL()
       
  3834     {
       
  3835 
       
  3836 #ifdef __AM_CHECKSTATE_CHANGES
       
  3837     RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): begin" );
       
  3838     if ( !iUpdated)
       
  3839         {
       
  3840         RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): !iUpdated" );
       
  3841         RElementIdArray arr;
       
  3842         CleanupClosePushL(arr);
       
  3843 		SessionL().CheckStatusNodesL();
       
  3844 		RElementIdArray array;
       
  3845 		TInt err( SessionL().DeploymentComponentIdsL( array, EDCSActive ) ); //to sync with SIS/Java registry
       
  3846 		err = SessionL().DeploymentComponentIdsL( array, EDCSInactive ); //to sync with SIS/Java registry
       
  3847 		CleanupClosePushL(array);
       
  3848         err = SessionL().StateChangingDCIdsL(arr);
       
  3849         if (err == KErrNone)
       
  3850             {
       
  3851             TInt c(arr.Count() );
       
  3852             for (TInt i( 0); i < c; i++)
       
  3853                 {
       
  3854                 TDeploymentComponent comp;
       
  3855                 err = iManagement.DeploymentComponent(arr[i], comp);
       
  3856                 if (err == KErrNone)
       
  3857                     {
       
  3858                     TDCUserId dc;
       
  3859                     SessionL().DeploymentComponentUserIdL(arr[i], dc);
       
  3860                     const TInt KNSmlDmMaxUriLength = 256;
       
  3861                     HBufC8 *uri = HBufC8::NewLC(KNSmlDmMaxUriLength);
       
  3862                     TPtr8 puri(uri->Des() );
       
  3863 #ifdef __TARM_SYMBIAN_CONVERGENCY					
       
  3864                     RDmTreeNode uriNode;
       
  3865                     CleanupClosePushL(uriNode);
       
  3866 
       
  3867                     RBuf8 acl;
       
  3868                     acl.CreateL(128);
       
  3869                     CleanupClosePushL(acl);
       
  3870 
       
  3871                     HBufC8 *newUri = HBufC8::NewLC( KNSmlDmMaxUriLength );
       
  3872                     TPtr8 pnewUri( newUri->Des() );
       
  3873 
       
  3874                     RDmTreeNode newUriNode;
       
  3875                     CleanupClosePushL(newUriNode);
       
  3876 #else
       
  3877                     CBufBase* acl = CBufFlat::NewL( 128);
       
  3878                     CleanupStack::PushL(acl);
       
  3879 
       
  3880                     HBufC8 *newUri = HBufC8::NewLC(KNSmlDmMaxUriLength);
       
  3881                     TPtr8 pnewUri(newUri->Des() );
       
  3882 
       
  3883 #endif
       
  3884 
       
  3885                     switch (comp.iOldState)
       
  3886                         {
       
  3887                         case EDCSDelivered:
       
  3888                             {
       
  3889                             RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): Old State = EDCSDelivered" );
       
  3890                             puri.Copy(KDeliveredURI() );
       
  3891                             puri.Append(dc);
       
  3892 
       
  3893                             HBufC8 *luid = DirectGetLuidAllocLC(puri);
       
  3894 
       
  3895                             if ( *luid == KNullDesC8)
       
  3896                                 { // probably moved already
       
  3897                                 iManagement.StateChangeComplete(arr[i]);
       
  3898                                 }
       
  3899                             else
       
  3900                                 {
       
  3901                                 // "Nullify" the old mapping 
       
  3902 								//DirectSetMappingL( puri, KNullDesC8 );
       
  3903 								DirectRemoveMappingL(puri);
       
  3904 #ifdef __TARM_SYMBIAN_CONVERGENCY								
       
  3905                                 iDbSession.OpenNodeL(puri, uriNode, RDmTree::EReadOnly);
       
  3906                                 uriNode.DmPropertyL( DevMan::EACL, acl );
       
  3907 #else
       
  3908                                 err = iDbSession.GetAclL(puri, *acl, EFalse); // no need for inherited
       
  3909 #endif										
       
  3910                                 // Determine new uri 
       
  3911                                 switch (comp.iState)
       
  3912                                     {
       
  3913                                     case EDCSActive:
       
  3914                                     case EDCSInactive: // both have same node
       
  3915                                         {
       
  3916                                         pnewUri.Copy(KDeployedURI() );
       
  3917                                         pnewUri.Append(dc);
       
  3918                                         DirectSetMappingL(pnewUri, *luid);
       
  3919                                         if (err == KErrNone)
       
  3920                                             {
       
  3921 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  3922                                             iDbSession.OpenNodeL(pnewUri, newUriNode, RDmTree::EReadOnly);
       
  3923                                             uriNode.RemoveDmPropertyL( DevMan::EACL );
       
  3924                                             newUriNode.SetDmPropertyL( DevMan::EACL, acl );
       
  3925 #else
       
  3926                                             err = iDbSession.DeleteAclL(puri);
       
  3927 
       
  3928                                             err = iDbSession.UpdateAclL(
       
  3929                                                     pnewUri, acl->Ptr( 0) );
       
  3930 #endif
       
  3931                                             }
       
  3932                                         else
       
  3933                                             {
       
  3934                                             RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get acl from %d ", err );
       
  3935                                             }
       
  3936                                         iManagement.StateChangeComplete(arr[i]);
       
  3937                                         break;
       
  3938                                         }
       
  3939                                     default:
       
  3940                                         {
       
  3941 
       
  3942                                         RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: WARNING Illegal state change from delivered to %d ", comp.iState );
       
  3943 
       
  3944                                         break;
       
  3945                                         }
       
  3946                                     }
       
  3947                                 }
       
  3948                             CleanupStack::PopAndDestroy(luid);
       
  3949                             break;
       
  3950                             }
       
  3951                         case EDCSDownload:
       
  3952                             {
       
  3953                             RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): Old State = EDCSDownload" );
       
  3954                             puri.Copy(KDownloadURI() );
       
  3955                             //check DC contains SCOMODefault.
       
  3956                             TBuf8<256> staticnode;
       
  3957                             TInt staticnodeenabled = 0;
       
  3958                             CRepository* cenrep = CRepository::NewLC( KCRUidPrivateApplicationManagementKeys );
       
  3959                             cenrep->Get( KAMDownloadPredefinedNode, staticnode ); 
       
  3960                             cenrep->Get( KAMStaticNodeEnabled, staticnodeenabled );
       
  3961                             CleanupStack::PopAndDestroy(); //cenrep
       
  3962                             if (dc.Find(staticnode) != KErrNotFound && staticnodeenabled)
       
  3963                                 {
       
  3964                                 puri.Append(staticnode);
       
  3965                                 }
       
  3966                             else
       
  3967                                 {
       
  3968                                 puri.Append(dc);
       
  3969                                 }
       
  3970 
       
  3971 
       
  3972                             HBufC8 *luid = DirectGetLuidAllocLC(puri); //Callback().GetLuidAllocL( puri );
       
  3973                             //CleanupStack::PushL( luid );
       
  3974                             if ( *luid == KNullDesC8)
       
  3975                                 { // probably moved already
       
  3976                                 CleanupStack::PopAndDestroy(luid);
       
  3977                                 puri.Copy(KDeliveredURI() );
       
  3978                                 puri.Append(dc);
       
  3979                                 luid = DirectGetLuidAllocLC(puri); //Callback().GetLuidAllocL( puri );
       
  3980                                 if ( *luid == KNullDesC8)
       
  3981                                     { // probably moved already
       
  3982 
       
  3983                                     iManagement.StateChangeComplete(arr[i]);
       
  3984 
       
  3985                                     }
       
  3986                                 }
       
  3987                             else
       
  3988                                 {
       
  3989 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  3990                                 iDbSession.OpenNodeL(puri, uriNode, RDmTree::EReadOnly);
       
  3991                                 uriNode.DmPropertyL( DevMan::EACL, acl );
       
  3992 #else
       
  3993                                 err = iDbSession.GetAclL(puri, *acl, EFalse); // no need for inherited
       
  3994 #endif							
       
  3995                                 // "Nullify" the old mapping 
       
  3996 								//DirectSetMappingL( puri, KNullDesC8 );
       
  3997 								DirectRemoveMappingL(puri);
       
  3998                                 switch (comp.iState)
       
  3999                                     {
       
  4000                                     case EDCSActive:
       
  4001                                     case EDCSInactive: // both have same node
       
  4002                                         {
       
  4003                                         pnewUri.Copy(KDeployedURI() );
       
  4004                                         pnewUri.Append(dc);
       
  4005                                         DirectSetMappingL(pnewUri, *luid);
       
  4006                                         if (err == KErrNone)
       
  4007                                             {
       
  4008 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4009                                             iDbSession.OpenNodeL(pnewUri, newUriNode, RDmTree::EReadOnly);
       
  4010                                             uriNode.RemoveDmPropertyL( DevMan::EACL );
       
  4011                                             newUriNode.SetDmPropertyL( DevMan::EACL, acl );
       
  4012 #else											
       
  4013                                             err = iDbSession.DeleteAclL(puri);
       
  4014                                             err = iDbSession.UpdateAclL(
       
  4015                                                     pnewUri, acl->Ptr( 0) );
       
  4016 #endif
       
  4017                                             }
       
  4018                                         else
       
  4019                                             {
       
  4020                                             RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get acl from %d ", err );
       
  4021                                             }
       
  4022                                         iManagement.StateChangeComplete(arr[i]);
       
  4023                                         break;
       
  4024                                         }
       
  4025                                     case EDCSDelivered:
       
  4026                                         {
       
  4027                                         RDEBUG( "CSCOMOAdapter::CheckStateChangesLInternal(): Current State = EDCSDelivered" );
       
  4028                                         pnewUri.Copy(KDeliveredURI() );
       
  4029                                         pnewUri.Append(dc);
       
  4030                                         DirectSetMappingL(pnewUri, *luid);
       
  4031                                         if (err == KErrNone)
       
  4032                                             {
       
  4033 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4034                                             iDbSession.OpenNodeL(pnewUri, newUriNode, RDmTree::EReadOnly);
       
  4035                                             uriNode.RemoveDmPropertyL( DevMan::EACL );
       
  4036                                             newUriNode.SetDmPropertyL( DevMan::EACL, acl );
       
  4037 #else
       
  4038 
       
  4039                                             err = iDbSession.DeleteAclL(puri);
       
  4040                                             err = iDbSession.UpdateAclL(
       
  4041                                                     pnewUri, acl->Ptr( 0) );
       
  4042 #endif
       
  4043                                             }
       
  4044                                         else
       
  4045                                             {
       
  4046                                             RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get acl from %d ", err );
       
  4047                                             }
       
  4048                                         iManagement.StateChangeComplete(arr[i]);
       
  4049                                         break;
       
  4050                                         }
       
  4051                                     default:
       
  4052                                         {
       
  4053 
       
  4054                                         RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: WARNING Illegal state change from delivered to %d ", comp.iState );
       
  4055                                         break;
       
  4056                                         }
       
  4057                                     }
       
  4058 
       
  4059                                 }
       
  4060                             CleanupStack::PopAndDestroy(luid);
       
  4061                             break;
       
  4062                             }
       
  4063                         case EDCSActive:
       
  4064                         case EDCSInactive: // these both are in same node
       
  4065                             {
       
  4066 
       
  4067                             RDEBUG_3("CSCOMOAdapter::CheckStateChangesL: No need to move anything in change from %d to %d ", comp.iOldState, comp.iState );
       
  4068                             iManagement.StateChangeComplete(arr[i]);
       
  4069                             break;
       
  4070                             }
       
  4071                         }
       
  4072 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4073                     CleanupStack::PopAndDestroy( &newUriNode );
       
  4074                     CleanupStack::PopAndDestroy( newUri );
       
  4075                     CleanupStack::PopAndDestroy( &uriNode );
       
  4076                     CleanupStack::PopAndDestroy( &acl );
       
  4077                     CleanupStack::PopAndDestroy( uri );
       
  4078 #else
       
  4079                     CleanupStack::PopAndDestroy(newUri);
       
  4080                     CleanupStack::PopAndDestroy(acl);
       
  4081                     CleanupStack::PopAndDestroy(uri);
       
  4082 #endif
       
  4083                     }
       
  4084                 else
       
  4085                     {
       
  4086                     RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get component: %d ", err );
       
  4087                     }
       
  4088                 }
       
  4089             iUpdated = ETrue;
       
  4090             }
       
  4091         else
       
  4092             {
       
  4093             RDEBUG_2("CSCOMOAdapter::CheckStateChangesL: ERROR Failed to get state change dcs: %d ", err );
       
  4094             }
       
  4095         CleanupStack::PopAndDestroy( &array);
       
  4096         CleanupStack::PopAndDestroy( &arr);
       
  4097         }
       
  4098     else
       
  4099         {
       
  4100         RDEBUG("CSCOMOAdapter::CheckStateChangesL: Already updated! ");
       
  4101         }
       
  4102     RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): end" );
       
  4103 #else
       
  4104     DBG_ARGS8( "CSCOMOAdapter::CheckStateChangesL(): disabled" );
       
  4105 #endif
       
  4106     }
       
  4107 
       
  4108 // -------------------------------------------------------------------------------------
       
  4109 // CSCOMOAdapter::CheckStateChangesL()
       
  4110 // Updates acl and mapping trees to match state changes
       
  4111 // -------------------------------------------------------------------------------------
       
  4112 void CSCOMOAdapter::CheckStateChangesL()
       
  4113     {
       
  4114     iCertRequired = EFalse;
       
  4115     RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): iCertRequired = EFalse" );
       
  4116     TRAPD( err, CheckStateChangesInternalL() )
       
  4117     ;
       
  4118     if (err != KErrNone)
       
  4119         {
       
  4120         RDEBUG_2("CSCOMOAdapter::CheckStateChangesL(): warning failed to check state changes %d", err );
       
  4121         }
       
  4122     iCertRequired = ETrue;
       
  4123     RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): iCertRequired = ETrue" );
       
  4124     if ( !iTrustAdded)
       
  4125         {
       
  4126         RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): Adding Trust Closing Session" );
       
  4127         iManagement.Close();
       
  4128         iSessionOpened = EFalse;
       
  4129         RApplicationManagement &session = SessionL();
       
  4130         RDEBUG( "CSCOMOAdapter::CheckStateChangesL(): Adding Trust new session started" );
       
  4131         }
       
  4132     }
       
  4133 
       
  4134 // -------------------------------------------------------------------------------------
       
  4135 // CSCOMOAdapter::URISegsUpTo(const TDesC8& aURI, TInt aUpTo)
       
  4136 // -------------------------------------------------------------------------------------
       
  4137 TPtrC8 CSCOMOAdapter::URISegsUpTo(const TDesC8& aURI, TInt aUpTo,
       
  4138         TBool aInclKeno/*=EFalse*/)
       
  4139     {
       
  4140 
       
  4141     TPtrC8 ret;
       
  4142     TInt numOfURISegs( 0);
       
  4143     for (TInt i( 0); i < aURI.Length() && ret.Ptr() == NULL; i++)
       
  4144         {
       
  4145         if (aURI[i] == KNSmlDMUriSeparator)
       
  4146             {
       
  4147             numOfURISegs++;
       
  4148             if (aUpTo == numOfURISegs)
       
  4149                 {
       
  4150                 if (aInclKeno && aURI.Length() > i+1)
       
  4151                     {
       
  4152                     ret.Set(aURI.Left(i + 1) );
       
  4153                     }
       
  4154                 else
       
  4155                     {
       
  4156                     ret.Set(aURI.Left(i) );
       
  4157                     }
       
  4158                 }
       
  4159             }
       
  4160         }
       
  4161     return ret;
       
  4162     }
       
  4163 
       
  4164 // -------------------------------------------------------------------------------------
       
  4165 // CSCOMOAdapter::DirectGetLuidAllocLC( const TDesC8 &aURI )
       
  4166 // -------------------------------------------------------------------------------------	
       
  4167 HBufC8 *CSCOMOAdapter::DirectGetLuidAllocLC(const TDesC8 &aURI)
       
  4168     {
       
  4169 
       
  4170 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4171     HBufC8 *ret = Callback().GetLuidAllocL( aURI );
       
  4172 #else
       
  4173     HBufC8* ret = iDbSession.GetLuidAllocL(KAMAdapterImplUid, aURI);
       
  4174 #endif
       
  4175 
       
  4176     CleanupStack::PushL(ret);
       
  4177     return ret;
       
  4178     }
       
  4179 
       
  4180 // -------------------------------------------------------------------------------------
       
  4181 // CSCOMOAdapter::DirectSetMappingL( const TDesC8 &aURI, const TDesC8 &aLUID )
       
  4182 // -------------------------------------------------------------------------------------		
       
  4183 TInt CSCOMOAdapter::DirectSetMappingL(const TDesC8 &aURI, const TDesC8 &aLUID)
       
  4184     {
       
  4185 
       
  4186 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4187     TRAPD( err, Callback().SetMappingL( aURI, aLUID ) );
       
  4188 #else
       
  4189     TInt err(iDbSession.AddMappingInfoL(KAMAdapterImplUid, aURI, aLUID) );
       
  4190 #endif
       
  4191     return err;
       
  4192     }
       
  4193 
       
  4194 // -------------------------------------------------------------------------------------
       
  4195 // CSCOMOAdapter::MoveAclL( const TDesC8 &aFrom, const TDesC8 &aTo )
       
  4196 // -------------------------------------------------------------------------------------		
       
  4197 void CSCOMOAdapter::MoveAclL(const TDesC8 &aFrom, const TDesC8 &aTo)
       
  4198     {
       
  4199 
       
  4200 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4201     RDmTreeNode from;
       
  4202     CleanupClosePushL(from);
       
  4203 
       
  4204     RDmTreeNode to;
       
  4205     CleanupClosePushL(to);
       
  4206 
       
  4207     RBuf8 acl;
       
  4208     acl.CreateL(128);
       
  4209     CleanupClosePushL(acl);
       
  4210 
       
  4211     iDbSession.OpenNodeL(aFrom, from, RDmTree::EReadOnly);
       
  4212     TRAPD( err, from.DmPropertyL( DevMan::EACL, acl ) );
       
  4213     if ( err == KErrNone )
       
  4214         {
       
  4215         iDbSession.OpenNodeL(aTo, to, RDmTree::EReadOnly);
       
  4216         from.RemoveDmPropertyL( DevMan::EACL );
       
  4217         to.SetDmPropertyL( DevMan::EACL, acl );
       
  4218         }
       
  4219     CleanupStack::PopAndDestroy( 3, &from );
       
  4220 #else
       
  4221     CBufBase *acl = CBufFlat::NewL( 128);
       
  4222     CleanupStack::PushL(acl);
       
  4223     TInt err(iDbSession.GetAclL(aFrom, *acl, EFalse) ); // no need for inherited
       
  4224     if (err == KErrNone)
       
  4225         {
       
  4226         err = iDbSession.DeleteAclL(aFrom);
       
  4227         err = iDbSession.UpdateAclL(aTo, acl->Ptr( 0) );
       
  4228         }
       
  4229     CleanupStack::PopAndDestroy(acl);
       
  4230 #endif
       
  4231     }
       
  4232 
       
  4233 // -------------------------------------------------------------------------------------
       
  4234 // CSCOMOAdapter::SetMappingL( const TDesC8 &aOriginalURI, 
       
  4235 //	const TDeploymentComponentState aTargetState, const TDesC8 &aLUID )
       
  4236 // -------------------------------------------------------------------------------------		
       
  4237 void CSCOMOAdapter::SetMappingL(const TDesC8 &aOriginalURI,
       
  4238         const TDeploymentComponentState aTargetState, const TDesC8 &aLUID)
       
  4239     {
       
  4240 
       
  4241     HBufC8 * targeturi= NULL;
       
  4242     SetMappingLC(aOriginalURI, aTargetState, aLUID, targeturi);
       
  4243     CleanupStack::PopAndDestroy(targeturi);
       
  4244     }
       
  4245 
       
  4246 // -------------------------------------------------------------------------------------
       
  4247 // CSCOMOAdapter::SetMappingLC( const TDesC8 &aOriginalURI, 
       
  4248 //	const TDeploymentComponentState aTargetState, const TDesC8 &aLUID, 
       
  4249 //	HBufC8 *&aNewUri )
       
  4250 // -------------------------------------------------------------------------------------		
       
  4251 void CSCOMOAdapter::SetMappingLC(const TDesC8 &aOriginalURI,
       
  4252         const TDeploymentComponentState aTargetState, const TDesC8 &aLUID,
       
  4253         HBufC8 *&aNewUri)
       
  4254     {
       
  4255 
       
  4256     // "Nullify" the mapping for argument
       
  4257     DirectSetMappingL(aOriginalURI, KNullDesC8);
       
  4258 
       
  4259     // Determine new uri for aArgument
       
  4260     TPtrC8 puri;
       
  4261     if (aNewUri == NULL)
       
  4262         {
       
  4263         TPtrC8 argMapping(NSmlDmURI::LastURISeg(aOriginalURI) );
       
  4264         TPtrC8 target;
       
  4265         if (aTargetState == EDCSInactive || aTargetState == EDCSActive)
       
  4266             {
       
  4267             target.Set(KDeployedURI() );
       
  4268             }
       
  4269         else
       
  4270             if (aTargetState == EDCSDelivered)
       
  4271                 {
       
  4272                 target.Set(KDeliveredURI() );
       
  4273                 }
       
  4274             else
       
  4275                 {
       
  4276 
       
  4277                 User::Leave(KErrArgument);
       
  4278                 }
       
  4279 
       
  4280         aNewUri = HBufC8::NewLC(target.Length() + argMapping.Length() );
       
  4281         TPtr8 p(aNewUri->Des() );
       
  4282         p.Copy(target);
       
  4283         p.Append(argMapping);
       
  4284         puri.Set(p);
       
  4285         }
       
  4286     else
       
  4287         {
       
  4288         puri.Set( *aNewUri);
       
  4289         }
       
  4290     DirectSetMappingL(puri, aLUID);
       
  4291     MoveAclL(aOriginalURI, puri);
       
  4292     }
       
  4293 
       
  4294 #ifdef __AM_LASTERROR_NODE
       
  4295 // ------------------------------------------------------------------------------------------------
       
  4296 // CSCOMOAdapter::SetLastErrorL( const TDesC8& aLastError, const TInt aError )
       
  4297 // ------------------------------------------------------------------------------------------------	
       
  4298 void CSCOMOAdapter::SetLastErrorL(const TDesC8& aLastError, const TInt aError)
       
  4299     {
       
  4300     if (iLastError)
       
  4301         {
       
  4302         TPtrC8 p(*iLastError);
       
  4303         RDEBUG8_2( "CSCOMOAdapter::SetLastErrorL: clearing last error %S", &p);
       
  4304         delete iLastError;
       
  4305         iLastError = NULL;
       
  4306         }
       
  4307     iLastError = HBufC8::NewL(aLastError.Length() + 10);
       
  4308     iLastError->Des().Format(aLastError, aError);
       
  4309     }
       
  4310 
       
  4311 const TDesC8& CSCOMOAdapter::LastError()
       
  4312     {
       
  4313     return iLastError == NULL ? KNullDesC8() : *iLastError;
       
  4314     }
       
  4315 
       
  4316 #endif
       
  4317 
       
  4318 TPtrC8 CSCOMOAdapter::LastURISeg(const TDesC8& aURI)
       
  4319     {
       
  4320     TInt i;
       
  4321     for (i=aURI.Length()-1; i>=0; i--)
       
  4322         {
       
  4323         if (aURI[i]==KNSmlDMAMSeparatorDef)
       
  4324             {
       
  4325             break;
       
  4326             }
       
  4327         }
       
  4328     if (i==0)
       
  4329         {
       
  4330         return aURI;
       
  4331         }
       
  4332     else
       
  4333         {
       
  4334         return aURI.Mid(i+1);
       
  4335         }
       
  4336     }
       
  4337 
       
  4338 TInt CSCOMOAdapter::DesToInt(const TDesC8& aLuid)
       
  4339     {
       
  4340     TLex8 lex(aLuid);
       
  4341     TInt value = 0;
       
  4342     lex.Val(value);
       
  4343     return value;
       
  4344     }
       
  4345 void CSCOMOAdapter::CheckAndAddPredefinedNodeL()
       
  4346     {
       
  4347 
       
  4348     // Check if SCOMODefault node addition is enabled.
       
  4349     TInt staticnodeenabled = 0;
       
  4350     CRepository* cenrep = CRepository::NewLC( KCRUidPrivateApplicationManagementKeys );
       
  4351     cenrep->Get( KAMStaticNodeEnabled, staticnodeenabled ); 
       
  4352     CleanupStack::PopAndDestroy(); //cenrep
       
  4353         
       
  4354     
       
  4355     if(staticnodeenabled)
       
  4356     {
       
  4357       TBuf8<KMaxFullName> temp;
       
  4358       GetPredefinedNodeL(temp);
       
  4359       if (temp.Length())
       
  4360         {
       
  4361 
       
  4362         TBuf8<KMaxFullName> temp1;
       
  4363         temp1.Zero();
       
  4364         temp1.Copy(KAMNodeName);
       
  4365         temp1.Append(KAMSeparator8);
       
  4366         temp1.Append(KAMDownloadNodeName);
       
  4367         temp1.Append(KAMSeparator8);
       
  4368         temp1.Append(temp);
       
  4369         HBufC8* luid = DirectGetLuidAllocLC(temp1);
       
  4370 
       
  4371         if (luid->Length() > 0)
       
  4372             {
       
  4373             CleanupStack::PopAndDestroy(luid);
       
  4374             return;
       
  4375             }
       
  4376         else
       
  4377             {
       
  4378             // Not found, add node and mapping ... 
       
  4379             //TError status(EError);
       
  4380             TPtrC8 mapping(NSmlDmURI::LastURISeg(temp1) );
       
  4381             TPtrC8 parent(NSmlDmURI::RemoveLastSeg(temp1) );
       
  4382             TPtrC8 parentMapping(NSmlDmURI::LastURISeg(parent) );
       
  4383             TInt cnt(NSmlDmURI::NumOfURISegs(temp1) );
       
  4384             TUint32 newLuid(SessionL().DownloadL(mapping));
       
  4385             //Callback().SetMappingL( temp1, *IntToDes8LC( newLuid ) );
       
  4386             //CleanupStack::PopAndDestroy();
       
  4387             DirectSetMappingL(temp1, *IntToDes8LC(newLuid) );
       
  4388             CleanupStack::PopAndDestroy(); // for IntToDes8LC()
       
  4389             CleanupStack::PopAndDestroy(luid);
       
  4390             }
       
  4391         }
       
  4392     }
       
  4393     }
       
  4394 // ---------------------------------------------------------------------------
       
  4395 // CAmAdapter::GetPredefinedNodeL()
       
  4396 // Gets  predefined node for Download object from cenrep 
       
  4397 // ---------------------------------------------------------------------------
       
  4398 //
       
  4399 void CSCOMOAdapter::GetPredefinedNodeL(TDes8& aNode)
       
  4400 	{
       
  4401 	CRepository* centrep( NULL);
       
  4402 	aNode.Zero();
       
  4403    	centrep = CRepository::NewLC( KCRUidPrivateApplicationManagementKeys );
       
  4404 
       
  4405     if ( centrep )
       
  4406 	    {
       
  4407         TBuf8<256> temp;
       
  4408 		TInt err = centrep->Get( KAMDownloadPredefinedNode, temp );
       
  4409     	if (centrep->Get( KAMDownloadPredefinedNode, temp )==KErrNone && temp.Length() )
       
  4410 			{
       
  4411 			temp.Trim();
       
  4412 			aNode.Copy(temp);
       
  4413 			}
       
  4414 		CleanupStack::PopAndDestroy(centrep);
       
  4415 	    }
       
  4416 	}
       
  4417 // -------------------------------------------------------------------------------------
       
  4418 // CAmAdapter::DirectRemoveMappingL( const TDesC8 &aURI )
       
  4419 // -------------------------------------------------------------------------------------        
       
  4420 TInt CSCOMOAdapter::DirectRemoveMappingL( const TDesC8 &aURI )
       
  4421     {
       
  4422 
       
  4423 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
  4424     TRAPD( err, Callback().SetMappingL( aURI, aLUID ) );
       
  4425 #else
       
  4426     TInt err( iDbSession.RemoveMappingInfoL( KAMAdapterImplUid, aURI, ETrue ) );
       
  4427 #endif
       
  4428     return err;
       
  4429     }
       
  4430 TInt CSCOMOAdapter::GetAdapterValue()
       
  4431     {
       
  4432     TInt adapterValue;
       
  4433     CRepository *repository = NULL;
       
  4434     TRAPD( err, repository = CRepository::NewL ( KCRUidPrivateApplicationManagementKeys ) );
       
  4435     if (err == KErrNone)
       
  4436         {
       
  4437         err = repository->Get(KAMAdapterValue, adapterValue);
       
  4438         }
       
  4439     delete repository;
       
  4440     repository = NULL;
       
  4441     return adapterValue;
       
  4442     }
       
  4443 
       
  4444 void CSCOMOAdapter::SetAdapterValue(TInt aAdapterValue)
       
  4445     {
       
  4446     CRepository *repository = NULL;
       
  4447     TRAPD( err, repository = CRepository::NewL ( KCRUidPrivateApplicationManagementKeys ) );
       
  4448     if (err == KErrNone)
       
  4449         {
       
  4450         err = repository->Set(KAMAdapterValue, aAdapterValue);
       
  4451         }
       
  4452     delete repository;
       
  4453     repository = NULL;
       
  4454     }
       
  4455 TBool CSCOMOAdapter::RecognizeMimeType(const TDesC8& aMimeType)
       
  4456     {
       
  4457     TBool isSupportedMimeType = EFalse;
       
  4458     if ((aMimeType == KSisxMimeType )||(aMimeType == KSisMimeType )||(aMimeType == KPipMimeType )||
       
  4459             (aMimeType == KJadMIMEType )||(aMimeType == KJarMIMEType )||(aMimeType == KJavaMIMEType ))
       
  4460         {
       
  4461         isSupportedMimeType = ETrue;
       
  4462         }
       
  4463     return isSupportedMimeType;
       
  4464     }
       
  4465 // End of File
       
  4466