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