connectivitymodules/SeCon/servers/pcconn/src/sconpcconnserver.cpp
branchRCL_3
changeset 43 4a793f564d72
child 48 debf68073f2f
equal deleted inserted replaced
42:0aa8cc770c8a 43:4a793f564d72
       
     1 /*
       
     2 * Copyright (c) 2005-2010 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:  PC Connectivity server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32mem.h> // For RMemReadStream
       
    20 #include <utf.h>
       
    21 #include <Etel3rdParty.h>
       
    22 #include <f32file.h>
       
    23 
       
    24 #include "sconpcconnclientserver.h"
       
    25 #include "sconpcconnserver.h"
       
    26 #include "sconpcd.h"
       
    27 #include "sconcsc.h"
       
    28 #include "sconconmlhandler.h"
       
    29 #include "sconimsireader.h"
       
    30 #include "sconoviaccounthandler.h"
       
    31 #include "sconfolderlister.h"
       
    32 #include "sconbtengine.h"
       
    33 #include "debug.h"
       
    34 
       
    35 #ifdef DEBUG_XML
       
    36 #include <s32file.h>
       
    37 _LIT8( KTimeFormat, "%02d:%02d:%02d.%03d" );
       
    38 _LIT8( KXmlBegin, "\nXML:\n" );
       
    39 #endif
       
    40 
       
    41 _LIT( KSCONGetMetadataRequest, "METADATA:" );
       
    42 _LIT8( KSCONSyncRequest, "SYNC:" );
       
    43 _LIT( KSCONReadImsi, "READIMSI");
       
    44 _LIT( KSCONReadNetworkInfo, "READNETWORKINFO");
       
    45 _LIT( KSCONReadOviAccount, "READOVIACCOUNT");
       
    46 _LIT( KSCONListPath, "LISTP:");
       
    47 _LIT( KSCONReadBtInfo, "READBTINFO" );
       
    48 _LIT( KSCONSetBtPower, "SETBTPOWER:" );
       
    49 _LIT( KSCONSetBtName, "SETBTNAME:" );
       
    50 _LIT( KSCONSetBtAuthorized, "SETBTAUTHORIZED:" );
       
    51 
       
    52 //------------------------------------------------------------
       
    53 // Global functions 
       
    54 //------------------------------------------------------------
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // E32Main()
       
    58 // Entry point 
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 TInt E32Main()
       
    62     {
       
    63     TRACE_FUNC_ENTRY;
       
    64     __UHEAP_MARK;
       
    65     TInt error( KErrNone );
       
    66     error = CSConPCConnServer::RunServer();
       
    67     __UHEAP_MARKEND;
       
    68     TRACE_FUNC_EXIT;
       
    69     return error;
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // PanicServer()
       
    74 // Panics the server with panic reason aPanic 
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 GLDEF_C void PanicServer(TPCConnServPanic aPanic)
       
    78     {
       
    79     LOGGER_WRITE_1( "CSConPCConnSession::PanicServer() : Panic code  %d", aPanic );  
       
    80     _LIT(KTxtServerPanic,"PCConn server panic");
       
    81     User::Panic(KTxtServerPanic,aPanic);
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CSConPCConnServer::CSConPCConnServer ()
       
    86 // Default constructor - can not leave
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CSConPCConnServer::CSConPCConnServer () : CServer2( EPriorityStandard)
       
    90     {
       
    91     LOGGER_WRITE( "* * * *  CSConPCConnServer  * * * *" );
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CSConPCConnServer::~CSConPCConnServer()
       
    96 // Default destructor
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C CSConPCConnServer::~CSConPCConnServer()
       
   100     {
       
   101     TRACE_FUNC;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CSConPCConnServer::NewLC()
       
   106 // Creates a new instance of CSConPCConnServer
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C CSConPCConnServer*  CSConPCConnServer::NewLC()
       
   110     {
       
   111     TRACE_FUNC_ENTRY;
       
   112     CSConPCConnServer* self  = new (ELeave) CSConPCConnServer();
       
   113     CleanupStack::PushL( self );
       
   114     self->StartL( KSConPCConnServerName );
       
   115     TRACE_FUNC_EXIT;
       
   116     return self;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CSConPCConnServer::NewSessionL()
       
   121 // Creates a new session to the client
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CSession2* CSConPCConnServer::NewSessionL( 
       
   125     const TVersion &aVersion, const RMessage2& /*aMessage*/ ) const
       
   126     {
       
   127     TRACE_FUNC_ENTRY;
       
   128     
       
   129     // check version
       
   130     TVersion version( KSConPCConnServerVersionMajor, 
       
   131                                   KSConPCConnServerVersionMinor, 
       
   132                                   KSConPCConnServerVersionBuild);
       
   133     
       
   134     if (!User::QueryVersionSupported(version, aVersion))
       
   135         {
       
   136         User::Leave(KErrNotSupported);
       
   137         }
       
   138     
       
   139     // check client identity
       
   140     RThread client;
       
   141     Message().Client( client );
       
   142     TSecureId clientId = client.SecureId();
       
   143     
       
   144     if ( clientId != KSConPCConnClientSecureId )
       
   145         {
       
   146         LOGGER_WRITE( "CSConPCConnServer::NewSessionL() : Secure ID does not match" );
       
   147 #ifndef __WINS__
       
   148         LOGGER_WRITE( "Leave KErrAccessDenied");
       
   149         User::Leave( KErrAccessDenied );
       
   150 #else
       
   151         // does not leave on WINS environment. Easier to run module tests.
       
   152         LOGGER_WRITE( "Not leaving on WINS environment" );
       
   153 #endif
       
   154         }
       
   155     
       
   156     TRACE_FUNC_EXIT;
       
   157     return CSConPCConnSession::NewL( *CONST_CAST( CSConPCConnServer*, this));
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CSConPCConnServer::RunServer()
       
   162 // Starts the server
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 TInt CSConPCConnServer::RunServer()
       
   166     {
       
   167     TRACE_FUNC_ENTRY;
       
   168     
       
   169     CTrapCleanup* cleanup = CTrapCleanup::New();
       
   170     TInt ret = KErrNoMemory;
       
   171     if( cleanup )
       
   172         {
       
   173         TRAP( ret, CSConPCConnServer::RunServerL(  ) );
       
   174         delete cleanup;
       
   175         }
       
   176     if( ret != KErrNone )
       
   177         {
       
   178         // Signal the client that server creation failed
       
   179         RProcess::Rendezvous( ret );
       
   180         }
       
   181     TRACE_FUNC_EXIT;
       
   182     return ret;
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CSConPCConnServer::RunServerL()
       
   187 // Starts the server
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CSConPCConnServer::RunServerL()
       
   191     {
       
   192     // Create and install the active scheduler we need
       
   193     TRACE_FUNC_ENTRY;
       
   194     CActiveScheduler *as=new (ELeave)CActiveScheduler;
       
   195     CleanupStack::PushL( as );
       
   196     CActiveScheduler::Install( as );
       
   197 
       
   198     // Create server
       
   199     CSConPCConnServer* server = CSConPCConnServer::NewLC();
       
   200 
       
   201     // Initialisation complete, now signal the client
       
   202     User::LeaveIfError( RThread().RenameMe( KSConPCConnServerName ) );
       
   203     RProcess::Rendezvous( KErrNone );
       
   204 
       
   205     // Ready to run
       
   206     CActiveScheduler::Start();
       
   207     
       
   208     // Cleanup the scheduler
       
   209     CleanupStack::PopAndDestroy( 2, as );
       
   210     TRACE_FUNC_EXIT;
       
   211     }
       
   212     
       
   213 // -----------------------------------------------------------------------------
       
   214 // CSConPCConnServer::IncSessionCount()
       
   215 // Increments session count
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void CSConPCConnServer::IncSessionCount()
       
   219     {
       
   220     TRACE_FUNC_ENTRY;
       
   221     iSessionCount++;
       
   222     LOGGER_WRITE_1( "There are now %d sessions", iSessionCount );
       
   223     TRACE_FUNC_EXIT;
       
   224     }    
       
   225     
       
   226 // -----------------------------------------------------------------------------
       
   227 // CSConPCConnServer::DecSessionCount()
       
   228 // Decrements session count
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CSConPCConnServer::DecSessionCount()
       
   232     {
       
   233     TRACE_FUNC_ENTRY;
       
   234     iSessionCount--;
       
   235     LOGGER_WRITE_1( "There are still %d sessions", iSessionCount );
       
   236     if ( iSessionCount < 1 )
       
   237         {
       
   238         Cancel();
       
   239         CActiveScheduler::Stop();   
       
   240         }
       
   241     TRACE_FUNC_EXIT;
       
   242     } 
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // CSConPCConnSession::CSConPCConnSession()
       
   246 // Default constructor 
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 CSConPCConnSession::CSConPCConnSession (
       
   250      CSConPCConnServer& aServer ) : iServer (aServer)
       
   251     {
       
   252     TRACE_FUNC_ENTRY;
       
   253     iServer.IncSessionCount();
       
   254     TRACE_FUNC_EXIT;
       
   255     }
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CSConPCConnSession::CSConPCConnSession()
       
   259 // Default destructor - frees resources
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 CSConPCConnSession::~CSConPCConnSession()
       
   263     {
       
   264     TRACE_FUNC_ENTRY;
       
   265     
       
   266     iServer.DecSessionCount();
       
   267 
       
   268     if ( iConMLHandler )
       
   269         {
       
   270         delete iConMLHandler;
       
   271         iConMLHandler = NULL;
       
   272         iConMLHandlerLib.Close();
       
   273         }
       
   274 
       
   275     if ( iPCDHandler )
       
   276         {
       
   277         delete iPCDHandler;
       
   278         iPCDHandler = NULL;
       
   279         iPCDlib.Close();
       
   280         }
       
   281 
       
   282     if ( iCSCHandler )
       
   283         {
       
   284         delete iCSCHandler;
       
   285         iCSCHandler = NULL;
       
   286         iCSClib.Close();
       
   287         }
       
   288     
       
   289     if ( iBuffer )
       
   290         {
       
   291         delete iBuffer;
       
   292         iBuffer = NULL;
       
   293         }
       
   294         
       
   295     iChunk.Close();
       
   296     delete iFolderLister;
       
   297     
       
   298     iFs.Close();
       
   299     
       
   300     delete iBtEngine;
       
   301      
       
   302     TRACE_FUNC_EXIT;
       
   303     }
       
   304 
       
   305 // -----------------------------------------------------------------------------
       
   306 // CSConPCConnSession::NewL()
       
   307 // Creates a new instance of CSConPCConnSession
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 EXPORT_C CSConPCConnSession *CSConPCConnSession::NewL(
       
   311     CSConPCConnServer& aServer)
       
   312     {
       
   313     TRACE_FUNC_ENTRY;
       
   314     CSConPCConnSession* self = new ( ELeave ) CSConPCConnSession(aServer);
       
   315     CleanupStack::PushL( self );
       
   316     self->ConstructL();
       
   317     CleanupStack::Pop( self );
       
   318     TRACE_FUNC_EXIT;
       
   319     return self;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CSConPCConnSession::ConstructL()
       
   324 // 2nd phase constructor
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CSConPCConnSession::ConstructL()
       
   328     {
       
   329     TRACE_FUNC_ENTRY;
       
   330     TInt ret ( KErrNone );
       
   331     iResult = KErrNone;
       
   332     
       
   333     User::LeaveIfError( iFs.Connect() );
       
   334     
       
   335 #ifdef DEBUG_XML
       
   336     // create log file 
       
   337     
       
   338     RFile file;
       
   339     TInt err = file.Create ( iFs, KSConConMLDebugFile, EFileWrite );
       
   340     if( err == KErrNone )
       
   341         {
       
   342         // file created, close it
       
   343         file.Close();
       
   344         }              
       
   345 #endif
       
   346     
       
   347     // initialize buffer
       
   348     iBuffer = CBufFlat::NewL ( KSConPCConnBufferMaxSize );
       
   349     
       
   350     // load handlers
       
   351     if ( !iPCDHandler )
       
   352         {
       
   353         TRAP( ret, LoadPCDDllL() );
       
   354         if ( ret != KErrNone) 
       
   355             {
       
   356             LOGGER_WRITE_1( "CSConPCConnSession::ConstructL() : PCD load failed with error code %d", ret );
       
   357             User::Leave( ret );
       
   358             }
       
   359         }   
       
   360     
       
   361     if ( !iCSCHandler )
       
   362         {
       
   363         TRAP( ret, LoadCSCDllL() );
       
   364         if ( ret != KErrNone) 
       
   365             {
       
   366             LOGGER_WRITE_1( "CSConPCConnSession::ConstructL() : CSC dll load failed with error code %d", ret ); 
       
   367             User::Leave ( ret );
       
   368             }
       
   369         }
       
   370 
       
   371     // Load parser
       
   372     if ( !iConMLHandler )
       
   373         {
       
   374         TRAPD( ret, LoadConMLHandlerDllL() );
       
   375         if ( ret != KErrNone)
       
   376             {
       
   377             LOGGER_WRITE_1( "CSConPCConnSession::ConstructL() : Parser dll load failed with error code %d", ret );
       
   378             User::Leave ( ret );
       
   379             }
       
   380         }
       
   381     
       
   382     iFolderLister = CSconFolderLister::NewL( iFs );
       
   383     
       
   384     TRACE_FUNC_EXIT;
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CSConPCConnSession::ServiceL()
       
   389 // Gets the client's request
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 void CSConPCConnSession::ServiceL( const RMessage2 &aMessage)
       
   393     {
       
   394     TRACE_FUNC_ENTRY;
       
   395     TRAPD(err,DispatchRequestL(aMessage) );
       
   396     if ( err != KErrNone )
       
   397         {
       
   398         LOGGER_WRITE_1( "CSConPCConnSession::ServiceL() : leave code %d", err );
       
   399         PanicServer( E_DispatchRequest );
       
   400         }
       
   401     TRACE_FUNC_EXIT;
       
   402     }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // CSConPCConnSession::DispatchRequestL()
       
   406 // Identifies an IPC command from the client 
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 void CSConPCConnSession::DispatchRequestL(const RMessage2 &aMessage)
       
   410     {
       
   411     TRACE_FUNC_ENTRY;
       
   412     
       
   413     TInt ret (KErrNone);
       
   414         
       
   415     switch (aMessage.Function())
       
   416         {
       
   417         case EPutMessage:
       
   418             LOGGER_WRITE( "CSConPCConnSession::DispatchRequestL() : EPutMessage" );
       
   419             ret = HandlePutMessageL();
       
   420             break;
       
   421         
       
   422         case EGetMessage:
       
   423             LOGGER_WRITE( "CSConPCConnSession::DispatchRequestL() : EGetMessage" );
       
   424             ret = HandleGetMessageL();
       
   425             break;
       
   426         
       
   427         case EResetMessage:
       
   428             LOGGER_WRITE( "CSConPCConnSession::DispatchRequestL() : EResetMessage" );
       
   429             ret = HandleResetMessage();
       
   430             break;
       
   431             
       
   432         case EChunkMessage:
       
   433             LOGGER_WRITE( "CSConPCConnSession::DispatchRequestL() : EChunkMessage" );
       
   434             ret = HandleChunkMessage( aMessage );
       
   435             break;
       
   436                         
       
   437         default:
       
   438             PanicServer (E_BadRequest);
       
   439             break;
       
   440         }
       
   441 
       
   442     aMessage.Complete( ret );
       
   443     TRACE_FUNC_EXIT;
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CSConPCConnSession::HandlePutMessageL()
       
   448 // Handles a PUT -type message from the client
       
   449 // -----------------------------------------------------------------------------
       
   450 //
       
   451 TInt CSConPCConnSession::HandlePutMessageL()
       
   452     {
       
   453     TRACE_FUNC_ENTRY;
       
   454     LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL() : begin : Heap count : %d", User::Heap().Count() );
       
   455     TInt ret ( KErrNone );
       
   456         
       
   457     if ( !iPCDHandler )
       
   458         {
       
   459         TRAP( ret, LoadPCDDllL() );
       
   460         if ( ret != KErrNone) 
       
   461             {
       
   462             LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL (): PCD dll load failed with error code %d", ret );    
       
   463             return ( ret );
       
   464             }
       
   465         }   
       
   466         
       
   467     if ( ! iConMLHandler )
       
   468         {
       
   469         TRAP ( ret, LoadConMLHandlerDllL() );
       
   470         if ( ret != KErrNone )
       
   471             {
       
   472             LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL (): ConML Handler dll load failed with error code %d", ret );  
       
   473             return ( ret );
       
   474             }
       
   475         }
       
   476         
       
   477     TInt length ( 0 );
       
   478     
       
   479     RMemReadStream buf( iChunk.Base(), iChunk.Size() );
       
   480 
       
   481 
       
   482     iBuffer->Reset();
       
   483 
       
   484     length = buf.ReadInt32L();
       
   485     HBufC8* name8 = HBufC8::NewLC( length );
       
   486     TPtr8 namePtr8 = name8->Des();
       
   487     buf.ReadL( namePtr8, length);
       
   488     
       
   489     const TUint8* ptr8 = namePtr8.Ptr();
       
   490     const TUint16* ptr16 = reinterpret_cast<const TUint16*>( ptr8 );
       
   491     TPtrC namePtr;
       
   492     namePtr.Set( ptr16, length/2 );
       
   493         
       
   494     length = buf.ReadInt32L();
       
   495     HBufC8* type = HBufC8::NewLC( length );
       
   496     TPtr8 typePtr = type->Des();
       
   497     buf.ReadL( typePtr, length);
       
   498    
       
   499     // WBXML Document
       
   500     length = buf.ReadInt32L();
       
   501     HBufC8* data = HBufC8::NewLC( length );
       
   502     TPtr8 dataPtr = data->Des();
       
   503     
       
   504     buf.ReadL( dataPtr, length );
       
   505     iBuffer->ResizeL( length );
       
   506     iBuffer->Write( 0, dataPtr );
       
   507             
       
   508     buf.Close();
       
   509     
       
   510 #ifdef DEBUG_XML
       
   511 
       
   512     RFile file;
       
   513     if ( file.Open( iFs, KSConConMLDebugFile, EFileWrite ) == KErrNone )
       
   514         {
       
   515         RFileWriteStream fws;
       
   516         TInt fileSize;
       
   517         file.Size( fileSize );
       
   518         
       
   519         TTime now;
       
   520         now.HomeTime();
       
   521         TDateTime time = now.DateTime();
       
   522         TBuf8<16> timeLine;
       
   523         timeLine.Format (KTimeFormat, time.Hour(), time.Minute(), 
       
   524                                     time.Second(), time.MicroSecond() );
       
   525         
       
   526         fws.Attach( file, fileSize );
       
   527         fws.PushL();
       
   528         fws.WriteL( timeLine );
       
   529         _LIT8( KPutMessage, "__________PUT-MESSAGE \nWBXML:\n" );
       
   530         fws.WriteL( KPutMessage );
       
   531         fws.WriteL( iBuffer->Ptr(0), iBuffer->Size() );
       
   532         TRAP_IGNORE( fws.CommitL() );
       
   533         fws.Close();
       
   534  
       
   535         CleanupStack::PopAndDestroy( &fws );
       
   536         }
       
   537     file.Close();
       
   538 #endif
       
   539     if ( ( ( typePtr.CompareC( KSConPCDWBXMLObjectType)== KErrNone ) || 
       
   540                  ( typePtr.CompareC( KSConPCDWBXMLObjectType2 )== KErrNone ) )
       
   541                  && namePtr8.Find(KSCONSyncRequest) == 0 )
       
   542         {
       
   543         LOGGER_WRITE_1("Sync request: %S", &namePtr);
       
   544         RBufReadStream stream( *iBuffer );
       
   545         
       
   546         CleanupClosePushL( stream );
       
   547         TRAP( ret, iPCDHandler->HandlePutSyncRequestL( namePtr8, stream ));
       
   548         if ( ret )
       
   549             {
       
   550             LOGGER_WRITE_1("HandlePutSyncRequestL() Leaved with %d", ret);
       
   551             }
       
   552         
       
   553         CleanupStack::PopAndDestroy( &stream );
       
   554         }
       
   555     else if ( ( typePtr.Compare( KSConPCDWBXMLObjectType ) == KErrNone) || 
       
   556          ( typePtr.Compare( KSConPCDWBXMLObjectType2 )== KErrNone) )
       
   557         {
       
   558         LOGGER_WRITE( "CSConPCConnSession::HandlePutMessageL() : Object type PCD " );
       
   559         TRAPD( err, ret = iConMLHandler->ParseDocumentL( *iBuffer, this ) );    
       
   560         if ( err != KErrNone )
       
   561             {
       
   562             ret = err;
       
   563             }
       
   564         if ( ret == KErrNone )
       
   565             {
       
   566             // Possible error code returned from PCCS 
       
   567             ret = iResult;
       
   568             }
       
   569         }
       
   570     else 
       
   571         {
       
   572         LOGGER_WRITE( "Object type not regognized " );
       
   573         ret = KErrNotSupported;
       
   574         }
       
   575     CleanupStack::PopAndDestroy( data );
       
   576     CleanupStack::PopAndDestroy( type );
       
   577     CleanupStack::PopAndDestroy( name8 );
       
   578     LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL() end : Heap count : %d", User::Heap().Count() );
       
   579     LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL() : returned %d", ret );    
       
   580     return ret;
       
   581     }
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CSConPCConnSession::HandleGetMessageL()
       
   585 // Handles a GET -type message from the client
       
   586 // -----------------------------------------------------------------------------
       
   587 //
       
   588 TInt CSConPCConnSession::HandleGetMessageL()
       
   589     {
       
   590     TRACE_FUNC_ENTRY;
       
   591     TInt ret ( KErrNone );
       
   592     
       
   593     if ( !iCSCHandler )
       
   594         {
       
   595         TRAP( ret, LoadCSCDllL() );
       
   596         if ( ret != KErrNone) 
       
   597             {
       
   598             LOGGER_WRITE_1( "CSConPCConnSession::HandleGetMessageL() : CSC dll load failed with error code %d", ret ); 
       
   599             return ret;
       
   600             }
       
   601         }
       
   602 
       
   603     TInt32 length ( 0 );
       
   604     RMemReadStream readBuf( iChunk.Base(), iChunk.Size() );
       
   605     iBuffer->Reset();
       
   606     
       
   607     length = readBuf.ReadInt32L();
       
   608     HBufC8* name = HBufC8::NewLC( length );
       
   609     TPtr8 namePtr8 = name->Des();
       
   610     readBuf.ReadL( namePtr8, length);
       
   611     namePtr8.SetLength( length );
       
   612     LOGGER_WRITE8_1("namePtr: %S", &namePtr8);
       
   613     
       
   614     const TUint8* ptr8 = namePtr8.Ptr();
       
   615     const TUint16* ptr16 = reinterpret_cast<const TUint16*>( ptr8 );
       
   616     TPtrC namePtr;
       
   617     namePtr.Set( ptr16, length/2 );
       
   618     
       
   619     length = readBuf.ReadInt32L();
       
   620     HBufC8* type = HBufC8::NewLC( length );
       
   621     TPtr8 typePtr = type->Des();
       
   622     readBuf.ReadL( typePtr, length);
       
   623     
       
   624     readBuf.Close();
       
   625         
       
   626     if ( typePtr.Compare( KSConCapabilityObjectType ) == KErrNone )
       
   627         {
       
   628         ret = iCSCHandler->CapabilityObject( *iBuffer );
       
   629         
       
   630 #ifdef DEBUG_XML
       
   631         
       
   632         RFile file;
       
   633         if ( file.Open(iFs, KSConConMLDebugFile, EFileWrite ) == KErrNone )
       
   634             {
       
   635             RFileWriteStream fws;
       
   636             TInt fileSize;
       
   637             file.Size ( fileSize );
       
   638             TTime now;
       
   639             now.HomeTime();
       
   640             TDateTime time = now.DateTime();
       
   641             TBuf8<16> timeLine;
       
   642             timeLine.Format( KTimeFormat, time.Hour(), time.Minute(), 
       
   643                                         time.Second(), time.MicroSecond() );
       
   644 
       
   645             fws.Attach ( file, fileSize);
       
   646             fws.PushL();
       
   647             fws.WriteL( timeLine );
       
   648             _LIT8( KGetMessage, "__________GET -MESSAGE - Capability Object \n " );
       
   649             fws.WriteL( KGetMessage );
       
   650             fws.WriteL( iBuffer->Ptr(0), iBuffer->Size() );
       
   651             TRAP_IGNORE( fws.CommitL() );
       
   652             fws.Close();
       
   653 
       
   654             CleanupStack::PopAndDestroy( &fws );
       
   655             }
       
   656         file.Close();
       
   657 #endif
       
   658 
       
   659         }
       
   660     else if (  typePtr.CompareC( KSConPCDWBXMLObjectType) == KErrNone )
       
   661         {
       
   662         if ( namePtr8.Find(KSCONSyncRequest) == 0 ) // 8-bit search
       
   663             {
       
   664             LOGGER_WRITE("Sync request");
       
   665             
       
   666             RBufWriteStream stream( *iBuffer );
       
   667                 
       
   668             CleanupClosePushL( stream );
       
   669             
       
   670             TRAP( ret, iPCDHandler->HandleGetSyncRequestL( namePtr8, stream, iChunk.MaxSize() - sizeof(TInt32) ));
       
   671             if ( ret )
       
   672                 {
       
   673                 LOGGER_WRITE_1("HandleGetSyncRequestL() Leaved with %d", ret);
       
   674                 }
       
   675             stream.CommitL();
       
   676             CleanupStack::PopAndDestroy( &stream );
       
   677             
       
   678             LOGGER_WRITE_1("iBuffer size: %d", iBuffer->Size());
       
   679             
       
   680             }
       
   681         else if ( namePtr.Find(KSCONReadImsi) == 0 ) // 16-bit search
       
   682             {
       
   683             LOGGER_WRITE("Read IMSI");
       
   684             TBuf<CTelephony::KIMSISize> imsi;
       
   685             ret = CSconImsiReader::GetImsiL( imsi );
       
   686             
       
   687             if ( ret == KErrNone )
       
   688                 {
       
   689                 TBuf8<CTelephony::KIMSISize> imsi8;
       
   690                 User::LeaveIfError( CnvUtfConverter::ConvertFromUnicodeToUtf8(imsi8,imsi) );
       
   691                 
       
   692                 iBuffer->ResizeL( imsi8.Length() );
       
   693                 iBuffer->Write( 0, imsi8 );
       
   694                 }
       
   695             else
       
   696                 {
       
   697                 // Change error code more generic
       
   698                 ret = KErrNotFound;
       
   699                 }
       
   700             }
       
   701         else if ( namePtr.Find(KSCONReadNetworkInfo) == 0 ) // 16-bit search
       
   702             {
       
   703             LOGGER_WRITE("Read NetworkInfo");
       
   704             CTelephony::TRegistrationStatus regStatus;
       
   705             ret = CSconImsiReader::GetNetworkStatusL( regStatus );
       
   706             
       
   707             if ( ret == KErrNone )
       
   708                 {
       
   709                 RBufWriteStream stream( *iBuffer );
       
   710                 CleanupClosePushL( stream );
       
   711                 stream.WriteInt8L( regStatus );
       
   712                 stream.CommitL();
       
   713                 CleanupStack::PopAndDestroy( &stream );
       
   714                 }
       
   715             else
       
   716                 {
       
   717                 // Change error code more generic
       
   718                 ret = KErrNotFound;
       
   719                 }
       
   720             }
       
   721         else if ( namePtr.Find(KSCONReadOviAccount) == 0 )
       
   722             {
       
   723             LOGGER_WRITE("Read Ovi account");
       
   724             RBufWriteStream stream( *iBuffer );
       
   725             CleanupClosePushL( stream );
       
   726             
       
   727             ret = ReadOviAccountInfoL( stream );
       
   728             stream.CommitL();
       
   729             CleanupStack::PopAndDestroy( &stream );
       
   730             
       
   731             }
       
   732         else if ( namePtr.Find(KSCONListPath) == 0 )
       
   733             {
       
   734             LOGGER_WRITE("List path");
       
   735             // LISTP:0:pathname
       
   736             if ( namePtr.Length() > KSCONListPath().Length()+2)
       
   737                 {
       
   738                 TPtrC pathname = namePtr.Mid( KSCONListPath().Length()+2 );
       
   739             
       
   740                 const TUint16 levelsChar = namePtr[ KSCONListPath().Length() ];
       
   741                 TInt level(KErrNotFound);
       
   742                 if ( levelsChar >= TChar('0') )
       
   743                     {
       
   744                     level = levelsChar - TChar('0');
       
   745                     }
       
   746                 
       
   747                 RBufWriteStream stream( *iBuffer );
       
   748                 CleanupClosePushL( stream );
       
   749                 TRAP( ret, iFolderLister->GenerateFolderListL( stream, pathname, level ));
       
   750                 LOGGER_WRITE_1("GenerateFolderListL leaved with err: %d", ret);
       
   751                 stream.CommitL();
       
   752                 CleanupStack::PopAndDestroy( &stream );
       
   753                 }
       
   754             else
       
   755                 {
       
   756                 ret = KErrArgument;
       
   757                 }
       
   758             
       
   759             }
       
   760         else if ( namePtr.Find(KSCONReadBtInfo) == 0 )
       
   761             {
       
   762             LOGGER_WRITE( "Read BT info");
       
   763             if ( !iBtEngine )
       
   764                 {
       
   765                 iBtEngine = CSconBtEngine::NewL();
       
   766                 }
       
   767             RBufWriteStream stream( *iBuffer );
       
   768             CleanupClosePushL( stream );
       
   769             TRAP( ret, iBtEngine->ReadBTInfoL( stream ) );
       
   770             LOGGER_WRITE_1("ReadBTInfoL leaved with err: %d", ret);
       
   771             stream.CommitL();
       
   772             CleanupStack::PopAndDestroy( &stream );
       
   773             }
       
   774         else if ( namePtr.Find(KSCONSetBtPower) == 0 )
       
   775             {
       
   776             LOGGER_WRITE( "Change BT Power state");
       
   777             if ( namePtr.Length() == KSCONSetBtPower().Length()+1 )
       
   778                 {
       
   779                 const TUint16 lastChar = namePtr[ KSCONSetBtPower().Length() ];
       
   780                 TBool changeBtOn;
       
   781                 if ( lastChar == TChar('0') )
       
   782                     {
       
   783                     changeBtOn = EFalse;
       
   784                     }
       
   785                 else if ( lastChar == TChar('1') )
       
   786                     {
       
   787                     changeBtOn = ETrue;
       
   788                     }
       
   789                 else
       
   790                     {
       
   791                     ret = KErrArgument;
       
   792                     }
       
   793                 
       
   794                 if ( !ret )
       
   795                     {
       
   796                     if ( !iBtEngine )
       
   797                        {
       
   798                        iBtEngine = CSconBtEngine::NewL();
       
   799                        }
       
   800                     TInt err = iBtEngine->SetBtPowerState( changeBtOn );
       
   801                     
       
   802                     RBufWriteStream stream( *iBuffer );
       
   803                     CleanupClosePushL( stream );
       
   804                     stream.WriteInt32L( err );
       
   805                     stream.CommitL();
       
   806                     CleanupStack::PopAndDestroy( &stream );
       
   807                     }
       
   808                 }
       
   809             else
       
   810                 {
       
   811                 ret = KErrArgument;
       
   812                 }
       
   813             }
       
   814         else if ( namePtr.Find(KSCONSetBtName) == 0 )
       
   815             {
       
   816             LOGGER_WRITE( "Set BT Name");
       
   817             TPtrC btName = namePtr.Mid( KSCONSetBtName().Length() );
       
   818             TInt err = iBtEngine->SetBtName( btName  );
       
   819             
       
   820             RBufWriteStream stream( *iBuffer );
       
   821             CleanupClosePushL( stream );
       
   822             stream.WriteInt32L( err );
       
   823             stream.CommitL();
       
   824             CleanupStack::PopAndDestroy( &stream );
       
   825             }
       
   826         else if ( namePtr.Find(KSCONSetBtAuthorized) == 0 )
       
   827             {
       
   828             LOGGER_WRITE( "Set BT Authorized");
       
   829             ret = KErrArgument;
       
   830             // SETBTAUTHORIZED:0:00245f8d6a26
       
   831             // 1. param = auth. state ("0"=off, "1"=true)
       
   832             // 2. param = bt address (hex string)
       
   833             
       
   834             if ( namePtr.Length() > KSCONSetBtAuthorized().Length()+2)
       
   835                 {
       
   836                 TPtrC btAddr = namePtr.Mid( KSCONSetBtAuthorized().Length()+2 );
       
   837                 
       
   838                 const TUint16 authStateChar = namePtr[ KSCONSetBtAuthorized().Length() ];
       
   839                 TBool authorize(EFalse);
       
   840                 if ( authStateChar == TChar('0') )
       
   841                     {
       
   842                     authorize = EFalse;
       
   843                     ret = KErrNone;
       
   844                     }
       
   845                 else if ( authStateChar == TChar('1') )
       
   846                     {
       
   847                     authorize = ETrue;
       
   848                     ret = KErrNone;
       
   849                     }
       
   850                 
       
   851                 if ( !iBtEngine )
       
   852                    {
       
   853                    iBtEngine = CSconBtEngine::NewL();
       
   854                    }
       
   855                 TRAPD(err, iBtEngine->SetBtAuthorizedL( btAddr, authorize ) );
       
   856                 
       
   857                 RBufWriteStream stream( *iBuffer );
       
   858                 CleanupClosePushL( stream );
       
   859                 stream.WriteInt32L( err );
       
   860                 stream.CommitL();
       
   861                 CleanupStack::PopAndDestroy( &stream );
       
   862                 }
       
   863             
       
   864             }
       
   865         else 
       
   866             {
       
   867             ret = HandleWBXMLGetRequestL( namePtr );
       
   868             }
       
   869         }
       
   870     else
       
   871         {
       
   872         LOGGER_WRITE( "CSConPCConnSession::HandleGetMessageL() : Header type not regognized " );
       
   873         ret = KErrNotSupported;
       
   874         }
       
   875     
       
   876     CleanupStack::PopAndDestroy( 2 ); // name, type
       
   877     
       
   878     if ( ret != KErrNone )
       
   879         {
       
   880         return ret;
       
   881         }
       
   882     
       
   883     length = iBuffer->Size();
       
   884     
       
   885     if ( sizeof(TInt32) + length > iChunk.Size() )
       
   886         {
       
   887         // need to resize chunk
       
   888         TInt err = iChunk.Adjust( sizeof(TInt32) + length );
       
   889         LOGGER_WRITE_2("iChunk.Adjust( %d ) err: %d", sizeof(TInt32) + length, err);
       
   890         if ( err )
       
   891             {
       
   892             iBuffer->Reset();
       
   893             LOGGER_WRITE_1( "CSConPCConnSession::HandleGetMessageL() : returned %d", ret );
       
   894             return err;
       
   895             }
       
   896         }
       
   897     
       
   898     // copy data to chunk
       
   899     RMemWriteStream writeBuf ( iChunk.Base(), iChunk.Size() );
       
   900     
       
   901     if ( length > 0 )
       
   902         {
       
   903         writeBuf.WriteInt32L( length );
       
   904         writeBuf.WriteL( iBuffer->Ptr(0), length );
       
   905         writeBuf.CommitL();
       
   906         }
       
   907     else 
       
   908         {
       
   909         writeBuf.WriteInt32L( 0 );
       
   910         }
       
   911     writeBuf.CommitL();
       
   912     writeBuf.Close();
       
   913     iBuffer->Reset();
       
   914     LOGGER_WRITE_1( "CSConPCConnSession::HandleGetMessageL() : returned %d", ret );
       
   915     return ( ret );
       
   916     }
       
   917 
       
   918 // -----------------------------------------------------------------------------
       
   919 // CSConPCConnSession::HandleWBXMLGetRequestL()
       
   920 // Handles a ConML(wbxml) Get request from the client
       
   921 // -----------------------------------------------------------------------------
       
   922 //
       
   923 TInt CSConPCConnSession::HandleWBXMLGetRequestL( const TDesC& aFileName )
       
   924     {
       
   925     TRACE_FUNC_ENTRY;
       
   926     TInt ret(KErrNone);
       
   927     if ( aFileName.Find(KSCONGetMetadataRequest) == 0 )
       
   928         {
       
   929         // ConML get metadata request --> Create metadata task
       
   930         LOGGER_WRITE( "ConML GetMetadataRequest" );
       
   931         TPtrC filename = aFileName.Mid( KSCONGetMetadataRequest().Length() );
       
   932         
       
   933         TSConMethodName method ( EGetMetadata );
       
   934         CSConTask* task = CSConTask::NewLC( method );
       
   935         
       
   936         if ( filename.Length() > task->iGetMetadataParams->iFilename.MaxLength() )
       
   937             {
       
   938             User::Leave( KErrTooBig );
       
   939             }
       
   940         task->iGetMetadataParams->iFilename = filename;
       
   941         
       
   942         ret = iPCDHandler->PutTaskL( task );
       
   943         CleanupStack::Pop( task );
       
   944         LOGGER_WRITE_1("iPCDHandler->PutTaskL ret: %d", ret);
       
   945         }
       
   946     else if ( aFileName.Length() > 0 )
       
   947         {
       
   948         LOGGER_WRITE("Error: aFilename does not match to any definitions");
       
   949         TRACE_FUNC_RET( KErrArgument );
       
   950         return KErrArgument;
       
   951         }
       
   952     
       
   953 	// Get reply
       
   954     LOGGER_WRITE( "CSConPCConnSession::HandleGetMessageL() before ConML GetReplyL" );
       
   955     CSConStatusReply* reply = iPCDHandler->GetReply();
       
   956     CleanupStack::PushL( reply );
       
   957     
       
   958     ConML_ConMLPtr_t content = new ( ELeave ) ConML_ConML_t();
       
   959     CleanupStack::PushL( content );
       
   960     
       
   961     AppendStatusL( content, reply );
       
   962     ret = iConMLHandler->GenerateDocument( content );
       
   963     
       
   964     CleanupStack::PopAndDestroy( content );
       
   965     CleanupStack::PopAndDestroy( reply );
       
   966      
       
   967     TPtrC8 ptr( iConMLHandler->WBXMLDocument() );
       
   968     LOGGER_WRITE_1("ptr.Size(): %d", ptr.Size());
       
   969     iBuffer->ResizeL( ptr.Size() );
       
   970     iBuffer->Write( 0, ptr );
       
   971 
       
   972 #ifdef DEBUG_XML
       
   973     RFile file;
       
   974     if ( file.Open( iFs, KSConConMLDebugFile, EFileWrite) == KErrNone )
       
   975         {
       
   976         RFileWriteStream fws;   
       
   977         TInt fileSize;
       
   978         file.Size ( fileSize );
       
   979         fws.Attach ( file, fileSize);
       
   980         fws.PushL();
       
   981         TTime now;
       
   982         now.HomeTime();
       
   983         TDateTime time = now.DateTime();
       
   984         TBuf8<16> timeLine;
       
   985         timeLine.Format( KTimeFormat, time.Hour(), time.Minute(), 
       
   986                          time.Second(), time.MicroSecond() );
       
   987 
       
   988         fws.WriteL( timeLine );
       
   989         _LIT8( KGetMessage, "__________GET -MESSAGE" );
       
   990         fws.WriteL( KGetMessage );
       
   991         fws.WriteL(KXmlBegin);
       
   992         fws.WriteL(iConMLHandler->XMLDocument().Ptr(), 
       
   993                           iConMLHandler->XMLDocument().Length());
       
   994         fws.WriteL(_L("\n\n"));
       
   995         TRAP_IGNORE( fws.CommitL() );
       
   996         fws.Close();
       
   997         CleanupStack::PopAndDestroy( &fws );
       
   998         }
       
   999         
       
  1000     file.Close();
       
  1001 #endif
       
  1002     TRACE_FUNC_RET(ret);
       
  1003     return ret;
       
  1004     }
       
  1005 
       
  1006 
       
  1007 // -----------------------------------------------------------------------------
       
  1008 // CSConPCConnSession::ReadOviAccountInfoL()
       
  1009 // Reads ovi account information to stream
       
  1010 // -----------------------------------------------------------------------------
       
  1011 //
       
  1012 TInt CSConPCConnSession::ReadOviAccountInfoL( RWriteStream& aAccountInfoStream )
       
  1013     {
       
  1014 	TRACE_FUNC_ENTRY;
       
  1015     RLibrary oviaccounthandlerLib;
       
  1016     CleanupClosePushL( oviaccounthandlerLib );
       
  1017     // Dynamically load DLL
       
  1018     TInt err = oviaccounthandlerLib.Load( KSconOviAccountHandlerDllName );
       
  1019     if ( err )
       
  1020         {
       
  1021         LOGGER_WRITE_1("oviaccounthandlerLib.Load err: %d", err);
       
  1022         err = KErrNotSupported;
       
  1023         }
       
  1024     else if( oviaccounthandlerLib.Type()[1] != KSconOviAccountHandlerDllUid )
       
  1025         {
       
  1026         LOGGER_WRITE_1( "KSconOviAccountHandlerDllUid incorrect... (0x%08X)",oviaccounthandlerLib.Type()[1].iUid  );
       
  1027         err = KErrNotSupported;
       
  1028         }
       
  1029     
       
  1030     if ( err == KErrNone )
       
  1031         {
       
  1032         TSConCreateCSconOviAccountHandlerFunc CreateCSconOviAccountHandlerL =
       
  1033         (TSConCreateCSconOviAccountHandlerFunc)oviaccounthandlerLib.Lookup(1);
       
  1034         
       
  1035         CSconOviAccountHandler* oviAccountHandler = (CSconOviAccountHandler*)CreateCSconOviAccountHandlerL();
       
  1036         
       
  1037         TRAP(err, oviAccountHandler->GetOviAccountDetailsL( aAccountInfoStream ) );
       
  1038         LOGGER_WRITE_1("GetOviAccountDetailsL err: %d", err);
       
  1039         
       
  1040         delete oviAccountHandler;
       
  1041         oviAccountHandler = NULL;
       
  1042         
       
  1043         if ( err )
       
  1044             {
       
  1045             // change error code
       
  1046             err = KErrNotFound;
       
  1047             }
       
  1048         }
       
  1049     else
       
  1050         {
       
  1051         err = KErrNotSupported;
       
  1052         }
       
  1053 	
       
  1054     CleanupStack::PopAndDestroy( &oviaccounthandlerLib );
       
  1055 	TRACE_FUNC_EXIT;
       
  1056     return err;
       
  1057     }
       
  1058 
       
  1059 // -----------------------------------------------------------------------------
       
  1060 // CSConPCConnSession::HandleResetMessage()
       
  1061 // Resets the PCCS service
       
  1062 // -----------------------------------------------------------------------------
       
  1063 //
       
  1064 TInt CSConPCConnSession::HandleResetMessage()   
       
  1065     {
       
  1066     TRACE_FUNC_ENTRY;
       
  1067     TInt ret ( KErrNone );
       
  1068     
       
  1069     // reset PCD
       
  1070     if ( iPCDHandler )
       
  1071         {
       
  1072         iPCDHandler->ResetPCD();
       
  1073         }
       
  1074         
       
  1075     LOGGER_WRITE_1( "CSConPCConnSession::HandleResetMessage() : ret %d", ret );
       
  1076     return ret;
       
  1077     }
       
  1078     
       
  1079 // -----------------------------------------------------------------------------
       
  1080 // CSConPCConnSession::HandleChunkMessage( const RMessage2& aMessage )
       
  1081 // Receives the chunk handle from the client
       
  1082 // -----------------------------------------------------------------------------
       
  1083 //
       
  1084 TInt CSConPCConnSession::HandleChunkMessage( const RMessage2& aMessage )    
       
  1085     {
       
  1086     TRACE_FUNC_ENTRY;
       
  1087     TInt ret ( KErrNone );
       
  1088     
       
  1089     ret = iChunk.Open( aMessage, 0, EFalse );
       
  1090         
       
  1091     LOGGER_WRITE_1( "CSConPCConnSession::HandleChunkMessageL() : ret %d", ret );
       
  1092     return ret;
       
  1093     }
       
  1094 
       
  1095 // -----------------------------------------------------------------------------
       
  1096 // CSConPCConnSession::LoadPCDDllL()
       
  1097 // Loads the PCCS service
       
  1098 // -----------------------------------------------------------------------------
       
  1099 //
       
  1100 void CSConPCConnSession::LoadPCDDllL()
       
  1101     {
       
  1102     TRACE_FUNC_ENTRY;
       
  1103     
       
  1104     // Dynamically load DLL
       
  1105     User::LeaveIfError( iPCDlib.Load( KSConPCDLibName ) );
       
  1106     if( iPCDlib.Type()[1] != KSConPCDUid )
       
  1107         {
       
  1108         LOGGER_WRITE( "CSConPCConnSession::LoadPCDDllL() : KSConPCDUidValue incorrect..." );
       
  1109         iPCDlib.Close();
       
  1110         User::Leave( KErrNotFound );
       
  1111         }   
       
  1112     TSConCreateCSConPCDFunc CreateCSConPCDL =
       
  1113     (TSConCreateCSConPCDFunc)iPCDlib.Lookup(1);
       
  1114     
       
  1115     iPCDHandler = (CSConPCD*)CreateCSConPCDL();
       
  1116     TRACE_FUNC_EXIT;
       
  1117     }
       
  1118 
       
  1119 // -----------------------------------------------------------------------------
       
  1120 // CSConPCConnSession::LoadCSCDllL()
       
  1121 // Loads the CSC service
       
  1122 // -----------------------------------------------------------------------------
       
  1123 //
       
  1124 void CSConPCConnSession::LoadCSCDllL()
       
  1125     {
       
  1126     TRACE_FUNC_ENTRY;
       
  1127     // Dynamically load DLL
       
  1128     User::LeaveIfError( iCSClib.Load( KSConCSCLibName ) );
       
  1129     if( iCSClib.Type()[1] != KSConCSCUid )
       
  1130         {
       
  1131         LOGGER_WRITE( "CSConPCConnSession::LoadCSCDllL() : KSConCSCUidValue incorrect" );
       
  1132         iCSClib.Close();
       
  1133         User::Leave( KErrNotFound );
       
  1134         }   
       
  1135     TSConCreateCSConCSCFunc CreateCSConCSCL = 
       
  1136     (TSConCreateCSConCSCFunc)iCSClib.Lookup(1);
       
  1137     
       
  1138     iCSCHandler = (CSConCSC*)CreateCSConCSCL();
       
  1139     TRACE_FUNC_EXIT;
       
  1140     }
       
  1141 
       
  1142 // -----------------------------------------------------------------------------
       
  1143 // CSConPCConnSession::LoadConMLHandlerDllL()
       
  1144 // Loads the ConML handler
       
  1145 // -----------------------------------------------------------------------------
       
  1146 //
       
  1147 void CSConPCConnSession::LoadConMLHandlerDllL()
       
  1148     {
       
  1149     TRACE_FUNC_ENTRY;
       
  1150     // Dynamically load DLL
       
  1151     User::LeaveIfError( iConMLHandlerLib.Load( KSConConMLHandlerLibName ) );
       
  1152     if ( iConMLHandlerLib.Type()[1] != KSConConMLHandlerUid )
       
  1153         {
       
  1154         LOGGER_WRITE( "CSConPCConnSession::LoadConMLHandlerDllL() : KSConConMLHandlerUidValue incorrect" );
       
  1155         iConMLHandlerLib.Close();
       
  1156         User::Leave( KErrNotFound );
       
  1157         }
       
  1158     TSConCreateCSConConMLHandlerFunc CreateCSConConMLHandlerL = 
       
  1159     (TSConCreateCSConConMLHandlerFunc)iConMLHandlerLib.Lookup(1);
       
  1160     
       
  1161     iConMLHandler = (CSConConMLHandler*)CreateCSConConMLHandlerL();
       
  1162     TRACE_FUNC_EXIT;
       
  1163     }
       
  1164 
       
  1165 // -----------------------------------------------------------------------------
       
  1166 // CSConPCConnSession::ConMLL()
       
  1167 // Callback function for ConML handler - parsed data processing starts
       
  1168 // -----------------------------------------------------------------------------
       
  1169 //
       
  1170 void CSConPCConnSession::ConMLL( ConML_ConMLPtr_t aContent )
       
  1171     {
       
  1172     TRACE_FUNC_ENTRY;
       
  1173     TInt ret ( KErrNone );
       
  1174     
       
  1175 #ifdef DEBUG_XML
       
  1176     iConMLHandler->GenerateDocument( aContent );
       
  1177     RFile file;
       
  1178     if ( file.Open(iFs, KSConConMLDebugFile, EFileWrite) == KErrNone )
       
  1179         {
       
  1180         RFileWriteStream fws;
       
  1181         TInt fileSize;
       
  1182         file.Size( fileSize );
       
  1183         fws.Attach ( file, fileSize );
       
  1184         fws.PushL();
       
  1185         
       
  1186         TTime now;
       
  1187         now.HomeTime();
       
  1188         TDateTime time = now.DateTime();
       
  1189         TBuf8<16> timeLine;
       
  1190         timeLine.Format (KTimeFormat, time.Hour(), time.Minute(), 
       
  1191                                     time.Second(), time.MicroSecond() );
       
  1192         
       
  1193         fws.WriteL( timeLine );
       
  1194         _LIT8( KPutMessage, "__________PUT-MESSAGE" );
       
  1195         fws.WriteL( KPutMessage );
       
  1196         fws.WriteL( KXmlBegin );
       
  1197         fws.WriteL( iConMLHandler->XMLDocument().Ptr(), 
       
  1198                     iConMLHandler->XMLDocument().Length());
       
  1199         fws.WriteL(_L("\n\n"));
       
  1200         TRAP_IGNORE( fws.CommitL() );
       
  1201         fws.Close();
       
  1202         CleanupStack::PopAndDestroy( &fws );
       
  1203         }
       
  1204     file.Close();
       
  1205     
       
  1206 #endif
       
  1207 
       
  1208 
       
  1209     if ( aContent )
       
  1210         {
       
  1211         if ( aContent->execute )
       
  1212             {
       
  1213             ret = OptionsFromExecuteL( aContent->execute );
       
  1214             }
       
  1215         else if ( aContent->cancel )
       
  1216             {
       
  1217             ret = TaskCancelL( aContent->cancel );
       
  1218             }
       
  1219         else if ( aContent->getStatus )
       
  1220             {
       
  1221             ret = TaskGetStatusL ( aContent->getStatus );
       
  1222             }
       
  1223         else 
       
  1224             {
       
  1225             LOGGER_WRITE( "CSConPCConnSession::ConML() : No appropriate content in ConML -element " );
       
  1226             ret = KErrArgument;
       
  1227             }
       
  1228         }
       
  1229     else 
       
  1230         {
       
  1231         ret  = KErrArgument;
       
  1232         }
       
  1233     
       
  1234     // store result for later use
       
  1235     iResult = ret;
       
  1236     TRACE_FUNC_EXIT;
       
  1237     }
       
  1238 
       
  1239 // -----------------------------------------------------------------------------
       
  1240 // CSConPCConnSession::OptionsFromExecuteL()
       
  1241 // Handles data of an execute -element
       
  1242 // -----------------------------------------------------------------------------
       
  1243 //
       
  1244 TInt CSConPCConnSession::OptionsFromExecuteL(ConML_ExecutePtr_t aContent )
       
  1245     {
       
  1246     TRACE_FUNC_ENTRY;
       
  1247     
       
  1248     TInt ret ( KErrNone );
       
  1249     if ( aContent->updateDeviceInfo )
       
  1250         {
       
  1251         ret = TaskUpdateDeviceInfoL( aContent->updateDeviceInfo);
       
  1252         }
       
  1253     else if ( aContent->listInstalledApps )
       
  1254         {
       
  1255         ret = TaskListInstalledAppsL( aContent->listInstalledApps);
       
  1256         }
       
  1257     else if ( aContent->install )
       
  1258         {
       
  1259         ret = TaskInstallL( aContent->install );
       
  1260         }       
       
  1261     else if ( aContent->unInstall )
       
  1262         {
       
  1263         ret = TaskUnInstallL( aContent->unInstall );
       
  1264         }
       
  1265     else if ( aContent->listDataOwners )
       
  1266         {
       
  1267         ret = TaskListDataOwnersL();
       
  1268         }
       
  1269     else if ( aContent->setBurMode )    
       
  1270         {
       
  1271         ret = TaskSetBURModeL( aContent->setBurMode );
       
  1272         }
       
  1273     else if ( aContent->getDataSize )
       
  1274         {
       
  1275         ret = TaskGetDataSizeL( aContent->getDataSize );
       
  1276         }
       
  1277     else if ( aContent->requestData )
       
  1278         {
       
  1279         ret = TaskRequestDataL( aContent->requestData );
       
  1280         }
       
  1281     else if ( aContent->listPublicFiles )
       
  1282         {
       
  1283         ret = TaskListPublicFilesL( aContent->listPublicFiles );
       
  1284         }
       
  1285     else if ( aContent->reboot )
       
  1286         {
       
  1287         ret = TaskRebootL();
       
  1288         }
       
  1289     else if ( aContent->getDataOwnerStatus )
       
  1290         {
       
  1291         ret = TaskGetDataOwnerStatusL( aContent->getDataOwnerStatus );      
       
  1292         }
       
  1293     else if ( aContent->supplyData )
       
  1294         {
       
  1295         ret = TaskSupplyDataL( aContent->supplyData );
       
  1296         }
       
  1297     else if ( aContent->getMetadata )
       
  1298         {
       
  1299         ret = TaskGetMetadataL( aContent->getMetadata );
       
  1300         }
       
  1301     else 
       
  1302         {
       
  1303         LOGGER_WRITE( "CSConPCConnSession::OptionsFromExecute() : No content " );
       
  1304         ret = KErrNotSupported;
       
  1305         }
       
  1306     LOGGER_WRITE_1( "CSConPCConnSession::OptionsFromExecute() : returned %d", ret );    
       
  1307     return ret;
       
  1308     }
       
  1309 
       
  1310 // -----------------------------------------------------------------------------
       
  1311 // CSConPCConnSession::TaskCancelL(ConML_CancelPtr_t aContent)
       
  1312 // Sends a Cancel -task to PCCS service
       
  1313 // -----------------------------------------------------------------------------
       
  1314 //
       
  1315 TInt CSConPCConnSession::TaskCancelL( ConML_CancelPtr_t aContent )
       
  1316     {
       
  1317     TRACE_FUNC_ENTRY;
       
  1318     TInt ret ( KErrNone );
       
  1319     TSConMethodName method ( ECancel );
       
  1320     CSConTask* task = CSConTask::NewLC( method );
       
  1321     if ( aContent->all )
       
  1322         {
       
  1323         task->iCancelTaskAll = ETrue;
       
  1324         }
       
  1325     if ( aContent->id )
       
  1326         {
       
  1327         task->iCancelTaskId = ( DesToInt( aContent->id->Data() ));
       
  1328         }
       
  1329     ret = iPCDHandler->PutTaskL( task );
       
  1330     CleanupStack::Pop( task );
       
  1331     LOGGER_WRITE_1( "CSConPCConnSession::TaskCancelL() : returned %d", ret );    
       
  1332     return ret;
       
  1333     }
       
  1334 
       
  1335 
       
  1336 // -----------------------------------------------------------------------------
       
  1337 // CSConPCConnSession::TaskGetStatusL()
       
  1338 // Sends a Get Status -task to PCCS service
       
  1339 // -----------------------------------------------------------------------------
       
  1340 //
       
  1341 TInt CSConPCConnSession::TaskGetStatusL( ConML_GetStatusPtr_t aContent )
       
  1342     {
       
  1343     TRACE_FUNC_ENTRY;
       
  1344     TInt ret ( KErrNone );
       
  1345     TSConMethodName method ( EGetStatus );
       
  1346     CSConTask* task = CSConTask::NewLC( method );
       
  1347     if ( aContent->all )
       
  1348         {
       
  1349         task->iGetStatusParams->iAll = ETrue;
       
  1350         }
       
  1351     if ( aContent->id)
       
  1352         {
       
  1353         task->iGetStatusParams->iTaskId = ( DesToInt( aContent->id->Data() ));
       
  1354         }
       
  1355     ret = iPCDHandler->PutTaskL( task );
       
  1356     CleanupStack::Pop( task );
       
  1357     LOGGER_WRITE_1( "CSConPCConnSession::TaskGetStatusL() : returned %d", ret );    
       
  1358     return ret;
       
  1359     }
       
  1360     
       
  1361 // -----------------------------------------------------------------------------
       
  1362 // CSConPCConnSession::TaskInstallL()
       
  1363 // Sends an Install -task to PCCS service
       
  1364 // -----------------------------------------------------------------------------
       
  1365 //
       
  1366 TInt CSConPCConnSession::TaskInstallL( ConML_InstallPtr_t aContent )
       
  1367     {
       
  1368     TRACE_FUNC_ENTRY;
       
  1369     TInt ret ( KErrNone );
       
  1370     TSConMethodName method ( EInstall );
       
  1371     CSConTask* task = CSConTask::NewLC( method);
       
  1372     task->iInstallParams->iMode = EUnknown;
       
  1373     if ( aContent->name )
       
  1374         {
       
  1375         // Unicode conversion from 8-bit to 16-bit
       
  1376         CnvUtfConverter::ConvertToUnicodeFromUtf8(task->iInstallParams->iPath, 
       
  1377                                                     aContent->name->Data());    
       
  1378         }
       
  1379     if ( aContent->instParams )
       
  1380         {
       
  1381         if ( aContent->instParams->param )
       
  1382             {
       
  1383             for ( ConML_ParamListPtr_t p = aContent->instParams->param; 
       
  1384                   p && p->data; p = p->next)
       
  1385                 {
       
  1386                 LOGGER_WRITE( "CSConPCConnSession::TaskInstallL() : Parameters found " );
       
  1387                 if ( p->data->name )
       
  1388                     {
       
  1389                     LOGGER_WRITE( "CSConPCConnSession::TaskInstallL() : name param found " );
       
  1390                     TPtrC8 silent(KParamNameSilent);
       
  1391                     
       
  1392                     TInt comp = Mem::Compare((TUint8*)p->data->name->content, (TInt)p->data->name->length, silent.Ptr(), silent.Length());
       
  1393                     if( comp == 0)
       
  1394                         {
       
  1395                         // "Silent"-param found
       
  1396                         LOGGER_WRITE( "CSConPCConnSession::TaskInstallL() : Silent-param found " );
       
  1397                         if ( p->data->value )
       
  1398                             {
       
  1399                             TPtrC8 dataValue((TUint8*)p->data->value->content, (TInt)p->data->value->length);
       
  1400                             TInt value = DesToInt( dataValue );
       
  1401                             if (value == 1)
       
  1402                                 {
       
  1403                                 LOGGER_WRITE( "CSConPCConnSession::TaskInstallL() : ESilentInstall " );
       
  1404                                 task->iInstallParams->iMode = ESilentInstall;
       
  1405                                 }
       
  1406                             else if( value == 0 )
       
  1407                                 {
       
  1408                                 LOGGER_WRITE( "CSConPCConnSession::TaskInstallL() : EUnsilentInstall " );
       
  1409                                 task->iInstallParams->iMode = EUnsilentInstall;
       
  1410                                 }
       
  1411                             }
       
  1412                         }
       
  1413                     }
       
  1414                 }
       
  1415             }
       
  1416         }
       
  1417     ret = iPCDHandler->PutTaskL( task );
       
  1418     CleanupStack::Pop( task );
       
  1419     LOGGER_WRITE_1( "CSConPCConnSession::TaskInstallL() : returned %d", ret );    
       
  1420     return ret;
       
  1421     }
       
  1422     
       
  1423 // -----------------------------------------------------------------------------
       
  1424 // CSConPCConnSession::TaskUnInstallL()
       
  1425 // Sends an Uninstall -task to PCCS service
       
  1426 // -----------------------------------------------------------------------------
       
  1427 //
       
  1428 TInt CSConPCConnSession::TaskUnInstallL( ConML_UnInstallPtr_t aContent )
       
  1429     {
       
  1430     TRACE_FUNC_ENTRY;
       
  1431     TInt ret ( KErrNone );
       
  1432     TSConMethodName method ( EUninstall );
       
  1433     CSConTask* task = CSConTask::NewLC( method );
       
  1434     task->iUninstallParams->iMode = EUnknown;
       
  1435     
       
  1436     if ( aContent->applications->application)       
       
  1437         {
       
  1438         for ( ConML_ApplicationListPtr_t p = 
       
  1439               aContent->applications->application; p && p->data; p = p->next )
       
  1440             {
       
  1441             if ( p->data )
       
  1442                 {
       
  1443                 if ( p->data->name )
       
  1444                     {
       
  1445                     // get application name
       
  1446                     HBufC* nameBuf = CnvUtfConverter::ConvertToUnicodeFromUtf8L( p->data->name->Data() );
       
  1447                     task->iUninstallParams->iName.Copy( nameBuf->Des() );
       
  1448                     delete nameBuf;
       
  1449                     nameBuf = NULL;
       
  1450                     }
       
  1451                 if ( p->data->uid )
       
  1452                     {
       
  1453                     // parse uid:  UID # Type # Size # Version # Vendor # Parent app. name #
       
  1454                     // only UID and Vendor are needed from whole uid-field.
       
  1455                     LOGGER_WRITE( "CSConPCConnSession::TaskUnInstallL() : start parsing uid " );
       
  1456                     
       
  1457                     TPtrC8 buf( p->data->uid->Data() );
       
  1458                     
       
  1459                     RArray<TPtrC8> arr(6);
       
  1460                     CleanupClosePushL( arr );
       
  1461                     TBuf8<1> separator(KSConAppInfoSeparator);
       
  1462                     
       
  1463                     SplitL(buf, separator[0], arr);
       
  1464                     if ( arr.Count() >= 5 )
       
  1465                     	{
       
  1466                     	task->iUninstallParams->iUid = DesToUid( arr[0] );
       
  1467                     	task->iUninstallParams->iType = (TSConAppType)DesToInt( arr[1] );
       
  1468                     	HBufC* vendorBuf = CnvUtfConverter::ConvertToUnicodeFromUtf8L( arr[4] );
       
  1469                     	task->iUninstallParams->iVendor.Copy( vendorBuf->Des() );
       
  1470                     	delete vendorBuf;
       
  1471                     	vendorBuf = NULL;
       
  1472                     	}
       
  1473                     CleanupStack::PopAndDestroy( &arr );
       
  1474                     
       
  1475                         
       
  1476                     } // endif p->data->uid
       
  1477                 }
       
  1478             }
       
  1479         }
       
  1480     
       
  1481     if ( aContent->instParams)
       
  1482         {
       
  1483         if ( aContent->instParams->param )
       
  1484             {
       
  1485             for ( ConML_ParamListPtr_t p = aContent->instParams->param; 
       
  1486                     p && p->data; p = p->next )
       
  1487                 {
       
  1488                 LOGGER_WRITE( "CSConPCConnSession::TaskUnInstallL() : Parameters found " );
       
  1489                 if ( p->data->name )
       
  1490                     {
       
  1491                     LOGGER_WRITE( "CSConPCConnSession::TaskUnInstallL() : name param found " );
       
  1492                     TPtrC8 silent(KParamNameSilent);
       
  1493                     
       
  1494                     TInt comp = Mem::Compare((TUint8*)p->data->name->content, (TInt)p->data->name->length, silent.Ptr(), silent.Length());
       
  1495                     if( comp == 0)
       
  1496                         {
       
  1497                         // "Silent"-param found
       
  1498                         LOGGER_WRITE( "CSConPCConnSession::TaskUnInstallL() : Silent-param found " );
       
  1499                         if ( p->data->value )
       
  1500                             {
       
  1501                             TPtrC8 dataValue((TUint8*)p->data->value->content, (TInt)p->data->value->length);
       
  1502                             TInt value = DesToInt( dataValue );
       
  1503                             if ( value == 1 )
       
  1504                                 {
       
  1505                                 LOGGER_WRITE( "CSConPCConnSession::TaskUnInstallL() : ESilentInstall " );
       
  1506                                 task->iUninstallParams->iMode = ESilentInstall;
       
  1507                                 }
       
  1508                             else if ( value == 0 )
       
  1509                                 {
       
  1510                                 LOGGER_WRITE( "CSConPCConnSession::TaskUnInstallL() : EUnsilentInstall " );
       
  1511                                 task->iUninstallParams->iMode = EUnsilentInstall;
       
  1512                                 }
       
  1513                             }
       
  1514                         }
       
  1515                     }
       
  1516                 }
       
  1517             }
       
  1518         }
       
  1519     ret = iPCDHandler->PutTaskL( task );
       
  1520     CleanupStack::Pop( task );
       
  1521     LOGGER_WRITE_1( "CSConPCConnSession::TaskUnInstallL() : returned %d", ret );    
       
  1522     return ret;
       
  1523     }
       
  1524 
       
  1525 // -----------------------------------------------------------------------------
       
  1526 // CSConPCConnSession::SplitL(const TDesC& aText, const TChar aSeparator, 
       
  1527 // RArray<TPtrC>& aArray)
       
  1528 // Function splits string (eg "name1, name2, name3") into substrings.
       
  1529 // -----------------------------------------------------------------------------
       
  1530 //
       
  1531 void CSConPCConnSession::SplitL(const TDesC8& aText, const TChar aSeparator, 
       
  1532                     RArray<TPtrC8>& aArray)
       
  1533     {
       
  1534     TRACE_FUNC_ENTRY;
       
  1535     TPtrC8 ptr;
       
  1536     ptr.Set(aText);
       
  1537 
       
  1538     for (;;)
       
  1539         {
       
  1540         TInt pos=ptr.Locate(aSeparator);
       
  1541         if (pos==KErrNotFound)
       
  1542             {
       
  1543             aArray.AppendL(ptr);
       
  1544             break;
       
  1545             }
       
  1546 
       
  1547         TPtrC8 subStr=ptr.Left(pos); // get pos characters starting from position 0
       
  1548         aArray.AppendL(subStr);
       
  1549 
       
  1550         if (!(ptr.Length()>pos+1))
       
  1551             {
       
  1552             break;
       
  1553             }
       
  1554             
       
  1555         ptr.Set(ptr.Mid(pos+1));// get all characters starting from position pos+1
       
  1556         }
       
  1557     TRACE_FUNC_EXIT;
       
  1558     }
       
  1559     
       
  1560 // -----------------------------------------------------------------------------
       
  1561 // CSConPCConnSession::TaskListInstalledAppsL()
       
  1562 // Sends a List installed apps -task to PCCS service
       
  1563 // -----------------------------------------------------------------------------
       
  1564 //
       
  1565 TInt CSConPCConnSession::TaskListInstalledAppsL(
       
  1566     ConML_ListInstalledAppsPtr_t aContent )
       
  1567     {
       
  1568     TRACE_FUNC_ENTRY;
       
  1569     TInt ret ( KErrNone );
       
  1570     TSConMethodName method ( EListInstalledApps );
       
  1571     CSConTask* task = CSConTask::NewLC( method );
       
  1572     if( aContent-> drives )
       
  1573         {
       
  1574         task->iListAppsParams->iDriveList = DriveList( aContent->drives->drive);
       
  1575         }
       
  1576     if ( aContent->all )
       
  1577         {
       
  1578         task->iListAppsParams->iAllApps = ETrue;
       
  1579         }
       
  1580     ret = iPCDHandler->PutTaskL( task );
       
  1581     CleanupStack::Pop( task );
       
  1582     LOGGER_WRITE_1( "CSConPCConnSession::TaskListInstalledAppsL() : returned %d", ret);
       
  1583     return ret;
       
  1584     }
       
  1585     
       
  1586 // -----------------------------------------------------------------------------
       
  1587 // CSConPCConnSession::TaskListDataOwnersL()
       
  1588 // Sends a List data owners -task to PCCS service
       
  1589 // -----------------------------------------------------------------------------
       
  1590 //
       
  1591 TInt CSConPCConnSession::TaskListDataOwnersL()
       
  1592     {
       
  1593     TRACE_FUNC_ENTRY;
       
  1594     TInt ret ( KErrNone );
       
  1595     TSConMethodName method ( EListDataOwners );
       
  1596     CSConTask* task = CSConTask::NewLC( method );
       
  1597     ret = iPCDHandler->PutTaskL( task );
       
  1598     CleanupStack::Pop( task );
       
  1599     LOGGER_WRITE_1( "CSConPCConnSession::TaskListDataOwnersL() : returned %d", ret );    
       
  1600     return ret;
       
  1601     }
       
  1602     
       
  1603 // -----------------------------------------------------------------------------
       
  1604 // CSConPCConnSession::TaskSetBURModeL()
       
  1605 // Sends a Set BUR mode -task to PCCS service
       
  1606 // -----------------------------------------------------------------------------
       
  1607 //
       
  1608 TInt CSConPCConnSession::TaskSetBURModeL(ConML_SetBURModePtr_t aContent )
       
  1609     {
       
  1610     TRACE_FUNC_ENTRY;
       
  1611     TInt ret ( KErrNone );
       
  1612     TSConMethodName method ( ESetBURMode );
       
  1613     CSConTask* task = CSConTask::NewLC( method );
       
  1614     if ( aContent->drives )
       
  1615         {
       
  1616         task->iBURModeParams->iDriveList = DriveList( aContent->drives->drive);
       
  1617         }
       
  1618     if ( aContent->partialType )
       
  1619         {
       
  1620         TInt intValue = DesToInt( aContent->partialType->Data() );
       
  1621         task->iBURModeParams->iPartialType = static_cast<TSConBurMode> (intValue) ;
       
  1622         }
       
  1623     if ( aContent->incType )
       
  1624         {
       
  1625         TInt intValue = DesToInt( aContent->incType->Data() );
       
  1626         task->iBURModeParams->iIncType = static_cast<TSConIncType> (intValue) ;
       
  1627         }
       
  1628     ret = iPCDHandler->PutTaskL( task );
       
  1629     CleanupStack::Pop( task );
       
  1630     LOGGER_WRITE_1( "CSConPCConnSession::TaskSetBURModeL() : returned %d", ret );    
       
  1631     return ret;
       
  1632     }
       
  1633     
       
  1634 // -----------------------------------------------------------------------------
       
  1635 // CSConPCConnSession::TaskGetDataSizeL()
       
  1636 // Sends a Get data size -task to PCCS service
       
  1637 // -----------------------------------------------------------------------------
       
  1638 //
       
  1639 TInt CSConPCConnSession::TaskGetDataSizeL(ConML_GetDataSizePtr_t aContent )
       
  1640     {
       
  1641     TRACE_FUNC_ENTRY;
       
  1642     TInt ret ( KErrNone );
       
  1643     TSConMethodName method ( EGetDataSize );
       
  1644     CSConTask* task = CSConTask::NewLC( method );
       
  1645     if ( aContent->dataOwners )
       
  1646         {
       
  1647         for ( ConML_SIDListPtr_t p = aContent->dataOwners->sid; 
       
  1648                 p && p->data; p=p->next )
       
  1649             {
       
  1650             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
       
  1651             CleanupStack::PushL( dataOwner );
       
  1652             if ( p->data->type )
       
  1653                 {
       
  1654                 dataOwner->iType = TSConDOType (DesToInt( 
       
  1655                     p->data->type->Data() ));
       
  1656                 }
       
  1657             if (p->data->uid )
       
  1658                 {
       
  1659                 if( !IsJavaHash( p->data->uid->Data() ) )
       
  1660                     {
       
  1661                     dataOwner->iUid = DesToUid( p->data->uid->Data() );
       
  1662                     }
       
  1663                 else
       
  1664                     {
       
  1665                     TPtr hashPtr = DesToHashLC( p->data->uid->Data() );
       
  1666                     dataOwner->iJavaHash = HBufC::NewL( hashPtr.Size() );
       
  1667                     dataOwner->iJavaHash->Des().Copy( hashPtr );
       
  1668                     CleanupStack::PopAndDestroy(); //DesToHashLC()
       
  1669                     }
       
  1670                 }
       
  1671             if ( p->data->drives )
       
  1672                 {
       
  1673                 dataOwner->iDriveList = DriveList ( p->data->drives->drive );
       
  1674                 }
       
  1675             if ( p->data->transferDataType )
       
  1676                 {
       
  1677                 TInt intValue = DesToInt( p->data->transferDataType->Data() );
       
  1678                 dataOwner->iTransDataType = static_cast<TSConTransferDataType> (intValue);
       
  1679                 }
       
  1680             task->iGetDataSizeParams->iDataOwners.AppendL( dataOwner );
       
  1681             CleanupStack::Pop( dataOwner );
       
  1682             }
       
  1683         }
       
  1684     ret = iPCDHandler->PutTaskL( task );
       
  1685     CleanupStack::Pop( task );
       
  1686     LOGGER_WRITE_1( "CSConPCConnSession::TaskGetDataSizeL() : returned %d", ret );    
       
  1687     return ret;
       
  1688     }
       
  1689     
       
  1690 // -----------------------------------------------------------------------------
       
  1691 // CSConPCConnSession::TaskRequestDataL()
       
  1692 // Sends a Request data -task to PCCS service
       
  1693 // -----------------------------------------------------------------------------
       
  1694 //
       
  1695 TInt CSConPCConnSession::TaskRequestDataL(ConML_RequestDataPtr_t aContent )
       
  1696     {
       
  1697     TRACE_FUNC_ENTRY;
       
  1698     TInt ret ( KErrNone );
       
  1699     TSConMethodName method ( ERequestData );
       
  1700     CSConTask* task = CSConTask::NewLC( method );
       
  1701     if ( aContent )
       
  1702         {
       
  1703         if ( aContent->sid )
       
  1704             {
       
  1705             for ( ConML_SIDListPtr_t p=aContent->sid; p && p->data; p=p->next )
       
  1706                 {
       
  1707                 if ( p->data->type )
       
  1708                     {
       
  1709                     task->iRequestDataParams->iDataOwner->iType = 
       
  1710                     TSConDOType ( DesToInt ( p->data->type->Data() ) );
       
  1711                     }
       
  1712                 if ( p->data->uid )
       
  1713                     {
       
  1714                     if( !IsJavaHash( p->data->uid->Data() ) )
       
  1715                         {
       
  1716                         task->iRequestDataParams->iDataOwner->iUid = DesToUid(
       
  1717                                                      p->data->uid->Data() );
       
  1718                         }
       
  1719                     else
       
  1720                         {
       
  1721                         TPtr hashPtr = DesToHashLC( p->data->uid->Data() );
       
  1722                         task->iRequestDataParams->iDataOwner->iJavaHash = HBufC::NewL( hashPtr.Size() );
       
  1723                         task->iRequestDataParams->iDataOwner->iJavaHash->Des().Copy( hashPtr );
       
  1724                         CleanupStack::PopAndDestroy(); //DesToHashLC()
       
  1725                         }                                 
       
  1726                     }
       
  1727                 if ( p->data->drives )
       
  1728                     {
       
  1729                     task->iRequestDataParams->iDataOwner->iDriveList = 
       
  1730                     DriveList ( p->data->drives->drive );
       
  1731                     }
       
  1732                 if ( p->data->transferDataType )
       
  1733                     {
       
  1734                     TInt intValue = DesToInt( p->data->transferDataType->Data() );
       
  1735                     task->iRequestDataParams->iDataOwner->iTransDataType =
       
  1736                         static_cast<TSConTransferDataType> (intValue);
       
  1737                     }
       
  1738                 }
       
  1739             }
       
  1740         }
       
  1741     ret = iPCDHandler->PutTaskL( task );
       
  1742     CleanupStack::Pop( task );
       
  1743     LOGGER_WRITE_1( "CSConPCConnSession::TaskRequestDataL() : returned %d", ret );    
       
  1744     return ret;
       
  1745     }
       
  1746 
       
  1747 // -----------------------------------------------------------------------------
       
  1748 // CSConPCConnSession::TaskUpdateDeviceInfoL()
       
  1749 // Sends a Update device info -task to PCCS service
       
  1750 // -----------------------------------------------------------------------------
       
  1751 //
       
  1752 TInt CSConPCConnSession::TaskUpdateDeviceInfoL(
       
  1753     ConML_UpdateDeviceInfoPtr_t aContent )
       
  1754     {
       
  1755     TRACE_FUNC_ENTRY;
       
  1756     TInt ret ( KErrNone );
       
  1757     TSConMethodName method ( EUpdateDeviceInfo );
       
  1758     CSConTask* task = CSConTask::NewLC( method );
       
  1759 
       
  1760     if ( aContent->deviceInfo)
       
  1761         {
       
  1762         ConML_DeviceInfoPtr_t dPtr = aContent->deviceInfo;
       
  1763         if ( dPtr->version )
       
  1764             {
       
  1765             task->iDevInfoParams->iVersion.Copy( dPtr->version->Data());
       
  1766             }
       
  1767         if ( dPtr->maxObjectSize )
       
  1768             {
       
  1769             task->iDevInfoParams->iMaxObjectSize = DesToInt(
       
  1770                                             dPtr->maxObjectSize->Data());
       
  1771             }
       
  1772         if ( dPtr->supportedMethods )
       
  1773             {
       
  1774             ConML_SupportedMethodsPtr_t smPtr = dPtr->supportedMethods;
       
  1775             if ( smPtr->install )
       
  1776                 {
       
  1777                 task->iDevInfoParams->iInstallSupp = ETrue; 
       
  1778                 }
       
  1779             if ( smPtr->unInstall )
       
  1780                 {
       
  1781                 task->iDevInfoParams->iUninstallSupp = ETrue;
       
  1782                 }
       
  1783             if ( smPtr->listInstalledApps )
       
  1784                 {
       
  1785                 task->iDevInfoParams->iInstAppsSupp = ETrue;
       
  1786                 }
       
  1787             if ( smPtr->listDataOwners )
       
  1788                 {
       
  1789                 task->iDevInfoParams->iDataOwnersSupp = ETrue;
       
  1790                 }
       
  1791             if ( smPtr->setBurMode )
       
  1792                 {
       
  1793                 task->iDevInfoParams->iSetBURModeSupp = ETrue;
       
  1794                 }
       
  1795             if ( smPtr->getDataSize )
       
  1796                 {
       
  1797                 task->iDevInfoParams->iGetSizeSupp = ETrue;
       
  1798                 }
       
  1799             if ( smPtr->requestData )
       
  1800                 {
       
  1801                 task->iDevInfoParams->iReqDataSupp = ETrue;
       
  1802                 }
       
  1803             if ( smPtr->supplyData )
       
  1804                 {
       
  1805                 task->iDevInfoParams->iSupplyDataSupp = ETrue;  
       
  1806                 }
       
  1807             if ( smPtr->reboot )
       
  1808                 {
       
  1809                 task->iDevInfoParams->iRebootSupp = ETrue;
       
  1810                 }
       
  1811             }
       
  1812         }
       
  1813     ret = iPCDHandler->PutTaskL( task );
       
  1814     CleanupStack::Pop( task );
       
  1815     LOGGER_WRITE_1( "CSConPCConnSession::TaskUpdateDeviceInfoL() : returned %d", ret );    
       
  1816     return ret;
       
  1817     }
       
  1818     
       
  1819 // -----------------------------------------------------------------------------
       
  1820 // CSConPCConnSession::TaskListPublicFilesL()
       
  1821 // Sends a List public files -task to PCCS service
       
  1822 // -----------------------------------------------------------------------------
       
  1823 //
       
  1824 TInt CSConPCConnSession::TaskListPublicFilesL(
       
  1825     ConML_ListPublicFilesPtr_t aContent )
       
  1826     {
       
  1827     TRACE_FUNC_ENTRY;
       
  1828     TInt ret ( KErrNone );
       
  1829     TSConMethodName method ( EListPublicFiles );
       
  1830     CSConTask* task = CSConTask::NewLC( method );
       
  1831     if ( aContent->sid )
       
  1832         {
       
  1833         for ( ConML_SIDListPtr_t p = aContent->sid; p && p->data; p = p->next )
       
  1834             {
       
  1835             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
       
  1836             CleanupStack::PushL( dataOwner );
       
  1837             if ( p->data->type )                
       
  1838                 {
       
  1839                 dataOwner->iType = TSConDOType ( DesToInt( 
       
  1840                                         p->data->type->Data() ) );
       
  1841                 }
       
  1842             if ( p->data->uid )
       
  1843                 {
       
  1844                 if( !IsJavaHash( p->data->uid->Data() ) )
       
  1845                     {
       
  1846                     dataOwner->iUid = DesToUid( p->data->uid->Data() );
       
  1847                     }
       
  1848                 else
       
  1849                     {
       
  1850                     TPtr hashPtr = DesToHashLC( p->data->uid->Data() );
       
  1851                     dataOwner->iJavaHash = HBufC::NewL( hashPtr.Size() );
       
  1852                     dataOwner->iJavaHash->Des().Copy( hashPtr );
       
  1853                     CleanupStack::PopAndDestroy(); //DesToHashLC()
       
  1854                     }
       
  1855                 }
       
  1856             if ( p->data->drives )
       
  1857                 {
       
  1858                 dataOwner->iDriveList = DriveList ( p->data->drives->drive );
       
  1859                 }
       
  1860             if ( p->data->packageInfo && p->data->packageInfo->name )
       
  1861                 {
       
  1862                 // Unicode conversion from 8-bit to 16-bit
       
  1863                 CnvUtfConverter::ConvertToUnicodeFromUtf8(
       
  1864                         dataOwner->iPackageName, 
       
  1865                         p->data->packageInfo->name->Data());
       
  1866                 }
       
  1867             task->iPubFilesParams->iDataOwners.AppendL( dataOwner );
       
  1868             CleanupStack::Pop( dataOwner );
       
  1869             }
       
  1870         }
       
  1871     ret = iPCDHandler->PutTaskL( task );
       
  1872     CleanupStack::Pop( task );
       
  1873     LOGGER_WRITE_1( "CSConPCConnSession::TaskListPublicFilesL() : returned %d", ret );    
       
  1874     return ret;
       
  1875     }
       
  1876         
       
  1877 // -----------------------------------------------------------------------------
       
  1878 // CSConPCConnSession::TaskSupplyDataL()
       
  1879 // Sends a Supply data -task to PCCS service
       
  1880 // -----------------------------------------------------------------------------
       
  1881 //
       
  1882 TInt CSConPCConnSession::TaskSupplyDataL ( ConML_SupplyDataPtr_t aContent )
       
  1883     {
       
  1884     TRACE_FUNC_ENTRY;
       
  1885     TInt ret ( KErrNone );
       
  1886     TSConMethodName method ( ESupplyData );
       
  1887     CSConTask* task = CSConTask::NewLC( method );
       
  1888     if (aContent )
       
  1889         {
       
  1890         for ( ConML_SIDListPtr_t p = aContent->sid; p && p->data; p = p->next )
       
  1891             {
       
  1892             if ( p->data->type )
       
  1893                 {
       
  1894                 task->iSupplyDataParams->iDataOwner->iType = 
       
  1895                 TSConDOType ( DesToInt( p->data->type->Data() ) );
       
  1896                 }
       
  1897             if ( p->data->uid )
       
  1898                 {
       
  1899                 if( !IsJavaHash( p->data->uid->Data() ) )
       
  1900                     {
       
  1901                     task->iSupplyDataParams->iDataOwner->iUid = DesToUid( 
       
  1902                                                 p->data->uid->Data() );
       
  1903                     }
       
  1904                 else
       
  1905                     {
       
  1906                     TPtr hashPtr = DesToHashLC( p->data->uid->Data() );
       
  1907                     task->iSupplyDataParams->iDataOwner->iJavaHash = HBufC::NewL( hashPtr.Size() );
       
  1908                     task->iSupplyDataParams->iDataOwner->iJavaHash->Des().Copy( hashPtr );
       
  1909                     CleanupStack::PopAndDestroy(); //DesToHashLC()
       
  1910                     }
       
  1911                 }
       
  1912             if ( p->data->drives )
       
  1913                 {
       
  1914                 task->iSupplyDataParams->iDataOwner->iDriveList = 
       
  1915                 DriveList ( p->data->drives->drive );
       
  1916                 }
       
  1917             if ( p->data->transferDataType )
       
  1918                 {
       
  1919                 TInt intValue = DesToInt ( p->data->transferDataType->Data() );
       
  1920                 task->iSupplyDataParams->iDataOwner->iTransDataType =
       
  1921                     static_cast<TSConTransferDataType> (intValue);
       
  1922                 }
       
  1923             if ( p->data->data )
       
  1924                 {
       
  1925                 task->iSupplyDataParams->iRestoreData = HBufC8::NewL(
       
  1926                                             p->data->data->Data().Size() );
       
  1927                 *task->iSupplyDataParams->iRestoreData = p->data->data->Data();
       
  1928                 }
       
  1929             if ( p->data->moreData )
       
  1930                 {
       
  1931                 task->iSupplyDataParams->iMoreData = ETrue;
       
  1932                 }
       
  1933             else
       
  1934                 {
       
  1935                 task->iSupplyDataParams->iMoreData = EFalse;
       
  1936                 }
       
  1937             }
       
  1938         }
       
  1939     ret = iPCDHandler->PutTaskL( task );
       
  1940     CleanupStack::Pop( task );
       
  1941     LOGGER_WRITE_1( "CSConPCConnSession::TaskSupplyDataL() : returned %d", ret );    
       
  1942     return ret;
       
  1943 }
       
  1944 
       
  1945 // -----------------------------------------------------------------------------
       
  1946 // CSConPCConnSession::TaskGetDataOwnerStatusL()
       
  1947 // Sends a Get data owner status -task to PCCS service
       
  1948 // -----------------------------------------------------------------------------
       
  1949 //
       
  1950 TInt CSConPCConnSession::TaskGetDataOwnerStatusL
       
  1951     ( ConML_GetDataOwnerStatusPtr_t aContent )
       
  1952     {
       
  1953     TRACE_FUNC_ENTRY;
       
  1954     TInt ret ( KErrNone );
       
  1955     TSConMethodName method ( EGetDataOwnerStatus );
       
  1956     CSConTask* task = CSConTask::NewLC( method );
       
  1957 
       
  1958     if ( aContent->dataOwners )
       
  1959         {
       
  1960         for ( ConML_SIDListPtr_t p = aContent->dataOwners->sid; 
       
  1961                 p && p->data; p=p->next )
       
  1962             {
       
  1963             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
       
  1964             CleanupStack::PushL( dataOwner );
       
  1965             if ( p->data->type )    
       
  1966                 {
       
  1967                 dataOwner->iType = TSConDOType (DesToInt(
       
  1968                                      p->data->type->Data() ));
       
  1969                 }
       
  1970             if ( p->data->uid )             
       
  1971                 {
       
  1972                 if( !IsJavaHash( p->data->uid->Data() ) )
       
  1973                     {
       
  1974                     dataOwner->iUid = DesToUid( p->data->uid->Data() );
       
  1975                     }
       
  1976                 else
       
  1977                     {
       
  1978                     TPtr hashPtr = DesToHashLC( p->data->uid->Data() );
       
  1979                     dataOwner->iJavaHash = HBufC::NewL( hashPtr.Size() );
       
  1980                     dataOwner->iJavaHash->Des().Copy( hashPtr );
       
  1981                     CleanupStack::PopAndDestroy(); //DesToHashLC()
       
  1982                     }
       
  1983                 }           
       
  1984             task->iGetDataOwnerParams->iDataOwners.AppendL( dataOwner );
       
  1985             CleanupStack::Pop( dataOwner );
       
  1986             }
       
  1987         }
       
  1988     ret = iPCDHandler->PutTaskL( task );
       
  1989     CleanupStack::Pop( task );
       
  1990     LOGGER_WRITE_1( "CSConPCConnSession::TaskGetDataOwnerStatusL() : returned %d", ret );    
       
  1991     return ret; 
       
  1992     }
       
  1993     
       
  1994 // -----------------------------------------------------------------------------
       
  1995 // CSConPCConnSession::TaskRebootL()
       
  1996 // Sends a Reboot -task to PCCS service
       
  1997 // -----------------------------------------------------------------------------
       
  1998 //
       
  1999 TInt CSConPCConnSession::TaskRebootL( )
       
  2000     {
       
  2001     TRACE_FUNC_ENTRY;
       
  2002     TInt ret ( KErrNone );
       
  2003     TSConMethodName method ( EReboot );
       
  2004     CSConTask* task = CSConTask::NewLC( method );
       
  2005     ret = iPCDHandler->PutTaskL( task );
       
  2006     CleanupStack::Pop( task );
       
  2007     LOGGER_WRITE_1( "CSConPCConnSession::TaskRebootL() : returned %d", ret );    
       
  2008     return ret;
       
  2009     }
       
  2010 
       
  2011 // -----------------------------------------------------------------------------
       
  2012 // CSConPCConnSession::TaskGetMetadataL()
       
  2013 // Sends a GetMetadata -task to PCCS service
       
  2014 // -----------------------------------------------------------------------------
       
  2015 //
       
  2016 TInt CSConPCConnSession::TaskGetMetadataL( ConML_GetMetadataPtr_t aContent )
       
  2017     {
       
  2018     TRACE_FUNC_ENTRY;
       
  2019     TInt ret ( KErrNone );
       
  2020     TSConMethodName method ( EGetMetadata );
       
  2021     CSConTask* task = CSConTask::NewLC( method );
       
  2022     if( aContent )
       
  2023         {
       
  2024         if ( aContent->filename )
       
  2025             {
       
  2026             // Unicode conversion from 8-bit to 16-bit
       
  2027             CnvUtfConverter::ConvertToUnicodeFromUtf8(task->iGetMetadataParams->iFilename, 
       
  2028                                                         aContent->filename->Data());    
       
  2029             }
       
  2030         }
       
  2031     ret = iPCDHandler->PutTaskL( task );
       
  2032     CleanupStack::Pop( task );
       
  2033     LOGGER_WRITE_1( "CSConPCConnSession::TaskGetMetadataL() : returned %d", ret );    
       
  2034     return ret;
       
  2035     }
       
  2036     
       
  2037 // -----------------------------------------------------------------------------
       
  2038 // CSConPCConnSession::TaskRebootL()
       
  2039 // Appends a status element from the reply data of PCCS
       
  2040 // -----------------------------------------------------------------------------
       
  2041 //
       
  2042 void CSConPCConnSession::AppendStatusL( 
       
  2043     ConML_ConMLPtr_t aContent, CSConStatusReply* reply )
       
  2044     {
       
  2045     TRACE_FUNC_ENTRY;
       
  2046     
       
  2047     if ( !reply )
       
  2048         {
       
  2049         LOGGER_WRITE( "CSConPCConnSession::AppendStatus() : No data in reply!" );
       
  2050         return;
       
  2051         }
       
  2052     aContent->status = new ( ELeave ) ConML_Status_t();
       
  2053         
       
  2054     if ( reply->iTasks.Count() > 0 ) 
       
  2055         {
       
  2056         for ( TInt i=0; i < reply->iTasks.Count(); i ++)
       
  2057             {
       
  2058             ConML_TaskListPtr_t task = new ( ELeave ) ConML_TaskList_t();
       
  2059             CleanupStack::PushL( task );
       
  2060             GenericListAddL ( &aContent->status->task, task );
       
  2061             CleanupStack::Pop(); // task
       
  2062             
       
  2063             task->data = new ( ELeave ) ConML_Task_t();
       
  2064             task->data->id = new ( ELeave ) pcdata_t();
       
  2065             task->data->id->SetDataL ( IntToDesLC(reply->iTasks[i]->iTaskId) );
       
  2066             CleanupStack::PopAndDestroy(); // IntToDesLC 
       
  2067             TSConMethodName method ( reply->iTasks[i]->iMethod );
       
  2068             
       
  2069             switch ( method )
       
  2070                 {
       
  2071                 case EUpdateDeviceInfo:
       
  2072                     task->data->updateDeviceInfo = 
       
  2073                         new ( ELeave ) ConML_UpdateDeviceInfo_t();
       
  2074                     task->data->updateDeviceInfo->results = 
       
  2075                         new ( ELeave ) ConML_Results_t();
       
  2076                     AppendUpdateDeviceInfoResultsL( 
       
  2077                         task->data->updateDeviceInfo->results,
       
  2078                         reply->iTasks[i]->iDevInfoParams );
       
  2079                     break;
       
  2080                 
       
  2081                 case ESetBURMode:
       
  2082                     task->data->setBurMode = 
       
  2083                         new ( ELeave ) ConML_SetBURMode_t();
       
  2084                     task->data->setBurMode->results = 
       
  2085                         new ( ELeave) ConML_Results_t();
       
  2086                     AppendSetBURModeResultsL( 
       
  2087                         task->data->setBurMode->results,
       
  2088                         reply->iTasks[i]->iBURModeParams );
       
  2089                     break;
       
  2090             
       
  2091                 case EListInstalledApps:
       
  2092                     task->data->listInstalledApps = 
       
  2093                         new ( ELeave ) ConML_ListInstalledApps_t();
       
  2094                     task->data->listInstalledApps->results = 
       
  2095                         new ( ELeave ) ConML_Results_t();
       
  2096                     AppendListInstalledAppsResultsL( 
       
  2097                         task->data->listInstalledApps->results,
       
  2098                         reply->iTasks[i]->iListAppsParams);
       
  2099                     break;
       
  2100                 
       
  2101                 case EInstall:
       
  2102                     task->data->install = new ( ELeave ) ConML_Install_t();
       
  2103                     task->data->install->results = 
       
  2104                         new ( ELeave ) ConML_Results_t();
       
  2105                     AppendInstallResultsL( 
       
  2106                         task->data->install->results, 
       
  2107                         reply->iTasks[i]->iInstallParams );
       
  2108                     break;
       
  2109             
       
  2110                 case EUninstall:
       
  2111                     task->data->unInstall = new ( ELeave ) ConML_UnInstall_t();
       
  2112                     task->data->unInstall->results = 
       
  2113                         new ( ELeave ) ConML_Results_t();
       
  2114                     AppendUninstallResultsL(
       
  2115                         task->data->unInstall->results, 
       
  2116                         reply->iTasks[i]->iUninstallParams );
       
  2117                     break;
       
  2118                 
       
  2119                 case EListDataOwners:
       
  2120                     task->data->listDataOwners = 
       
  2121                         new ( ELeave ) ConML_ListDataOwners_t();
       
  2122                     task->data->listDataOwners->results = 
       
  2123                         new ( ELeave ) ConML_Results_t();
       
  2124                     AppendListDataOwnersResultsL( 
       
  2125                         task->data->listDataOwners->results, 
       
  2126                         reply->iTasks[i]->iListDataOwnersParams );
       
  2127                     break;
       
  2128                 
       
  2129                 case EGetDataOwnerStatus:
       
  2130                     task->data->getDataOwnerStatus = 
       
  2131                         new ( ELeave ) ConML_GetDataOwnerStatus_t();
       
  2132                     task->data->getDataOwnerStatus->results = 
       
  2133                         new ( ELeave ) ConML_Results_t();
       
  2134                     AppendGetDataOwnerStatusResultsL( 
       
  2135                         task->data->getDataOwnerStatus->results,
       
  2136                         reply->iTasks[i]->iGetDataOwnerParams);
       
  2137                     break;
       
  2138                 
       
  2139                 case EGetDataSize:
       
  2140                     task->data->getDataSize = 
       
  2141                         new ( ELeave ) ConML_GetDataSize_t();
       
  2142                     task->data->getDataSize->results = 
       
  2143                         new ( ELeave ) ConML_Results_t();
       
  2144                     AppendGetDataSizeResultsL( 
       
  2145                         task->data->getDataSize->results,
       
  2146                         reply->iTasks[i]->iGetDataSizeParams );
       
  2147                     break;
       
  2148                                 
       
  2149                 case EListPublicFiles:
       
  2150                     task->data->listPublicFiles = 
       
  2151                         new ( ELeave ) ConML_ListPublicFiles_t();
       
  2152                     task->data->listPublicFiles->results = 
       
  2153                         new ( ELeave ) ConML_Results_t();
       
  2154                     AppendListPublicFilesResultsL ( 
       
  2155                         task->data->listPublicFiles->results,
       
  2156                         reply->iTasks[i]->iPubFilesParams );
       
  2157                     break;
       
  2158             
       
  2159                 case ERequestData:
       
  2160                     task->data->requestData = 
       
  2161                         new ( ELeave ) ConML_RequestData_t();
       
  2162                     task->data->requestData->results = 
       
  2163                         new ( ELeave ) ConML_Results_t();
       
  2164                     AppendRequestDataResultsL( 
       
  2165                         task->data->requestData->results, 
       
  2166                         reply->iTasks[i]->iRequestDataParams );
       
  2167                     break;
       
  2168                 
       
  2169                 case ESupplyData:
       
  2170                     task->data->supplyData = 
       
  2171                         new ( ELeave ) ConML_SupplyData_t();
       
  2172                     task->data->supplyData->results = 
       
  2173                         new ( ELeave ) ConML_Results_t();
       
  2174                     AppendSupplyDataResultsL ( 
       
  2175                         task->data->supplyData->results, 
       
  2176                         reply->iTasks[i]->iSupplyDataParams );
       
  2177                     break;
       
  2178                 
       
  2179                 case EGetMetadata:
       
  2180                     task->data->getMetadata = 
       
  2181                         new ( ELeave ) ConML_GetMetadata_t();
       
  2182                     task->data->getMetadata->results = 
       
  2183                         new ( ELeave ) ConML_Results_t();
       
  2184                     AppendGetMetadataResultsL ( 
       
  2185                         task->data->getMetadata->results, 
       
  2186                         reply->iTasks[i]->iGetMetadataParams );
       
  2187                     break;
       
  2188                     
       
  2189                 default:
       
  2190                     LOGGER_WRITE_1( "CSConPCConnSession:: AppendStatus() : Unknown method  %d ", method );
       
  2191                     break;
       
  2192                 }
       
  2193             }
       
  2194         }
       
  2195     else
       
  2196         {
       
  2197         LOGGER_WRITE( "CSConPCConnSession::AppendStatus() : No Task " );     
       
  2198         }
       
  2199     TRACE_FUNC_EXIT;
       
  2200     }
       
  2201 
       
  2202 // -----------------------------------------------------------------------------
       
  2203 // CSConPCConnSession::AppendUpdateDeviceInfoResultsL()
       
  2204 // Appends a update device info -element from the reply data of PCCS
       
  2205 // -----------------------------------------------------------------------------
       
  2206 //
       
  2207 void CSConPCConnSession::AppendUpdateDeviceInfoResultsL 
       
  2208     ( ConML_ResultsPtr_t aContent, CSConUpdateDeviceInfo* aResult )
       
  2209     {
       
  2210     TRACE_FUNC_ENTRY;
       
  2211     if ( aResult )  
       
  2212         {
       
  2213         if ( aResult->iComplete )
       
  2214             {
       
  2215             aContent->complete = new ( ELeave ) pcdata_t();
       
  2216             }
       
  2217         AppendProgressL ( aContent, aResult->iProgress );
       
  2218     
       
  2219         aContent->deviceInfo = new ( ELeave ) ConML_DeviceInfo_t();
       
  2220         aContent->deviceInfo->version = new ( ELeave ) pcdata_t();
       
  2221         aContent->deviceInfo->version->SetDataL ( aResult->iVersion );
       
  2222 
       
  2223         aContent->deviceInfo->supportedMethods = 
       
  2224             new ( ELeave ) ConML_SupportedMethods_t();
       
  2225             
       
  2226         if ( aResult->iInstallSupp )
       
  2227             {
       
  2228             aContent->deviceInfo->supportedMethods->install = 
       
  2229                 new ( ELeave ) pcdata_t();
       
  2230             }
       
  2231         if ( aResult->iUninstallSupp )
       
  2232             {
       
  2233             aContent->deviceInfo->supportedMethods->unInstall = 
       
  2234                 new ( ELeave ) pcdata_t();
       
  2235             }
       
  2236         if ( aResult->iInstAppsSupp )
       
  2237             {
       
  2238             aContent->deviceInfo->supportedMethods->listInstalledApps = 
       
  2239                 new ( ELeave ) pcdata_t();
       
  2240             }
       
  2241         if ( aResult->iDataOwnersSupp )
       
  2242             {
       
  2243             aContent->deviceInfo->supportedMethods->listDataOwners = 
       
  2244                 new ( ELeave ) pcdata_t();
       
  2245             }
       
  2246         if ( aResult->iSetBURModeSupp )
       
  2247             {
       
  2248             aContent->deviceInfo->supportedMethods->setBurMode = 
       
  2249                 new ( ELeave ) pcdata_t();
       
  2250             }
       
  2251         if ( aResult->iGetSizeSupp )
       
  2252             {
       
  2253             aContent->deviceInfo->supportedMethods->getDataSize = 
       
  2254                 new ( ELeave ) pcdata_t();
       
  2255             }
       
  2256         if ( aResult->iReqDataSupp )
       
  2257             {
       
  2258             aContent->deviceInfo->supportedMethods->requestData = 
       
  2259                 new (ELeave ) pcdata_t();
       
  2260             }
       
  2261         if ( aResult->iSupplyDataSupp )
       
  2262             {
       
  2263             aContent->deviceInfo->supportedMethods->supplyData = 
       
  2264                 new ( ELeave ) pcdata_t();
       
  2265             }
       
  2266         if ( aResult->iRebootSupp )
       
  2267             {
       
  2268             aContent->deviceInfo->supportedMethods->reboot = 
       
  2269                 new ( ELeave ) pcdata_t();
       
  2270             }
       
  2271         aContent->deviceInfo->maxObjectSize = new ( ELeave ) pcdata_t();
       
  2272         aContent->deviceInfo->maxObjectSize->SetDataL ( IntToDesLC(
       
  2273             aResult->iMaxObjectSize ));
       
  2274         CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2275         }
       
  2276     TRACE_FUNC_EXIT;
       
  2277     }
       
  2278     
       
  2279 // -----------------------------------------------------------------------------
       
  2280 // CSConPCConnSession::AppendSetBURModeResultsL()
       
  2281 // Appends a Set BUR mode -element from the reply data of PCCS
       
  2282 // -----------------------------------------------------------------------------
       
  2283 //
       
  2284 void CSConPCConnSession::AppendSetBURModeResultsL (
       
  2285     ConML_ResultsPtr_t aContent, CSConSetBURMode* aResult )
       
  2286     {
       
  2287     TRACE_FUNC_ENTRY;
       
  2288     if ( aResult )
       
  2289         {
       
  2290         if ( aResult->iComplete )
       
  2291             {
       
  2292             aContent->complete = new ( ELeave ) pcdata_t();
       
  2293             }
       
  2294         AppendProgressL ( aContent, aResult->iProgress );
       
  2295         }
       
  2296     TRACE_FUNC_EXIT;
       
  2297     }
       
  2298     
       
  2299 // -----------------------------------------------------------------------------
       
  2300 // CSConPCConnSession::AppendListInstalledAppsResultsL()
       
  2301 // Appends a List installed apps -element from the reply data of PCCS
       
  2302 // -----------------------------------------------------------------------------
       
  2303 //
       
  2304 void CSConPCConnSession::AppendListInstalledAppsResultsL ( 
       
  2305     ConML_ResultsPtr_t aContent, CSConListInstApps* aResult )
       
  2306     {
       
  2307     TRACE_FUNC_ENTRY;
       
  2308 
       
  2309     if ( aResult )
       
  2310         {
       
  2311         if ( aResult->iComplete )
       
  2312             {
       
  2313             aContent->complete = new ( ELeave ) pcdata_t();
       
  2314             }
       
  2315         AppendProgressL ( aContent, aResult->iProgress );
       
  2316         
       
  2317         if ( aResult->iApps.Count() > 0 )
       
  2318             {
       
  2319             // 6 * KMaxFileName should be enought
       
  2320             // ( 5 items of TFileName and uid + type + size + 7* "#" )
       
  2321             HBufC8* buf = HBufC8::NewLC( 6 * KMaxFileName );
       
  2322             TPtr8 ptrBuf = buf->Des();
       
  2323             
       
  2324             aContent->applications = new ( ELeave ) ConML_Applications_t();
       
  2325             for ( TInt i=0; i<aResult->iApps.Count(); i++)
       
  2326                 {
       
  2327                 ConML_ApplicationListPtr_t app = 
       
  2328                     new ( ELeave )ConML_ApplicationList_t();
       
  2329                 CleanupStack::PushL ( app );
       
  2330                 GenericListAddL ( &aContent->applications->application, app );
       
  2331                 CleanupStack::Pop(); // app
       
  2332                 
       
  2333                 app->data = new ( ELeave ) ConML_Application_t();
       
  2334                 app->data->name = new ( ELeave ) pcdata_t();
       
  2335                 app->data->name->SetDataL( BufToDesLC( 
       
  2336                     aResult->iApps[i]->iName));
       
  2337                 CleanupStack::PopAndDestroy(); // BufToDesLC
       
  2338                 
       
  2339                 // create uid: UID # Type # Size # Version # Vendor # Parent app. name # WidgetBundleId #
       
  2340                 LOGGER_WRITE( "CSConPCConnSession::AppendListInstalledAppsResultsL() : Create Uid" );
       
  2341                 
       
  2342                 ptrBuf.Copy( UidToDesLC( aResult->iApps[i]->iUid ) );
       
  2343                 CleanupStack::PopAndDestroy(); // UidToDesLC
       
  2344                 
       
  2345                 ptrBuf.Append( KSConAppInfoSeparator );
       
  2346                 
       
  2347                 ptrBuf.Append( IntToDesLC(aResult->iApps[i]->iType ));
       
  2348                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2349                 
       
  2350                 ptrBuf.Append( KSConAppInfoSeparator );
       
  2351                 
       
  2352                 ptrBuf.Append( IntToDesLC(aResult->iApps[i]->iSize ) );
       
  2353                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2354                 
       
  2355                 ptrBuf.Append( KSConAppInfoSeparator );
       
  2356                 ptrBuf.Append( aResult->iApps[i]->iVersion );
       
  2357                 
       
  2358                 ptrBuf.Append( KSConAppInfoSeparator );
       
  2359                 ptrBuf.Append( BufToDesLC( aResult->iApps[i]->iVendor ) );
       
  2360                 CleanupStack::PopAndDestroy(); // BufToDesLC
       
  2361                 
       
  2362                 ptrBuf.Append( KSConAppInfoSeparator );
       
  2363                 ptrBuf.Append( BufToDesLC( aResult->iApps[i]->iParentName ) );
       
  2364                 CleanupStack::PopAndDestroy(); // BufToDesLC
       
  2365                 
       
  2366                 ptrBuf.Append( KSConAppInfoSeparator );
       
  2367                 if (aResult->iApps[i]->iWidgetBundleId)
       
  2368                     {
       
  2369                     ptrBuf.Append( BufToDesLC( *aResult->iApps[i]->iWidgetBundleId ) );
       
  2370                     CleanupStack::PopAndDestroy(); // BufToDesLC
       
  2371                     }
       
  2372                 
       
  2373                 ptrBuf.Append( KSConAppInfoSeparator );
       
  2374                 
       
  2375                 LOGGER_WRITE( "CSConPCConnSession::AppendListInstalledAppsResultsL() : set data" );
       
  2376                 app->data->uid = new ( ELeave ) pcdata_t();
       
  2377                 app->data->uid->SetDataL( *buf );
       
  2378                     
       
  2379                 LOGGER_WRITE( "CSConPCConnSession::AppendListInstalledAppsResultsL() : Info added" );
       
  2380                 }
       
  2381             CleanupStack::PopAndDestroy(buf);       
       
  2382             }
       
  2383         }
       
  2384     TRACE_FUNC_EXIT;
       
  2385     }
       
  2386     
       
  2387 // -----------------------------------------------------------------------------
       
  2388 // CSConPCConnSession::AppendListPublicFilesResultsL()
       
  2389 // Appends a List public files -element from the reply data of PCCS
       
  2390 // -----------------------------------------------------------------------------
       
  2391 //
       
  2392 void CSConPCConnSession::AppendListPublicFilesResultsL ( 
       
  2393     ConML_ResultsPtr_t aContent, CSConListPublicFiles* aResult )
       
  2394     {
       
  2395     TRACE_FUNC_ENTRY;
       
  2396     if ( aResult )
       
  2397         {
       
  2398         if ( aResult->iComplete )
       
  2399             {
       
  2400             aContent->complete = new ( ELeave ) pcdata_t();
       
  2401             }
       
  2402         AppendProgressL ( aContent, aResult->iProgress );
       
  2403         
       
  2404         if ( aResult->iFiles.Count() > 0 )
       
  2405             {
       
  2406             aContent->files = new ( ELeave ) ConML_Files_t();
       
  2407             for ( TInt i=0;i<aResult->iFiles.Count(); i++ )
       
  2408                 {
       
  2409                 ConML_FileListPtr_t file = new ( ELeave ) ConML_FileList_t();
       
  2410                 CleanupStack::PushL( file );
       
  2411                 GenericListAddL ( &aContent->files->file, file );
       
  2412                 CleanupStack::Pop(); // file
       
  2413                 
       
  2414                 file->data = new ( ELeave ) ConML_File_t();
       
  2415                 file->data->name = new ( ELeave ) pcdata_t();
       
  2416                 file->data->name->SetDataL( BufToDesLC (
       
  2417                     aResult->iFiles[i]->iPath ) );
       
  2418                 CleanupStack::PopAndDestroy(); // BufToDesLC
       
  2419                 
       
  2420                 file->data->modified = new ( ELeave ) pcdata_t();
       
  2421                 file->data->modified->SetDataL( BufToDesLC (
       
  2422                     aResult->iFiles[i]->iModified ) );
       
  2423                 CleanupStack::PopAndDestroy(); // BufToDesLC
       
  2424                 
       
  2425                 file->data->size = new ( ELeave ) pcdata_t();
       
  2426                 file->data->size->SetDataL( IntToDesLC ( 
       
  2427                     aResult->iFiles[i]->iSize ) );
       
  2428                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2429                 
       
  2430                 file->data->userPerm = new ( ELeave ) pcdata_t();
       
  2431                 switch ( aResult->iFiles[i]->iUserPerm )
       
  2432                     {
       
  2433                     case EPermReadOnly:
       
  2434                         file->data->userPerm->SetDataL ( KSConPermReadOnly );
       
  2435                         break;
       
  2436                     
       
  2437                     case EPermNormal:
       
  2438                         file->data->userPerm->SetDataL ( KSConPermNormal );
       
  2439                         break;
       
  2440                     
       
  2441                     default:
       
  2442                         LOGGER_WRITE( "CSConPCConnSession:: AppendListPublicFilesResultsL() : Unknown userPerm! " );
       
  2443                         break;          
       
  2444                     }
       
  2445                 }
       
  2446         }
       
  2447     }
       
  2448     TRACE_FUNC_EXIT;
       
  2449     }
       
  2450     
       
  2451 // -----------------------------------------------------------------------------
       
  2452 // CSConPCConnSession::AppendRequestDataResultsL()
       
  2453 // Appends a Request data -element from the reply data of PCCS
       
  2454 // -----------------------------------------------------------------------------
       
  2455 //
       
  2456 void CSConPCConnSession::AppendRequestDataResultsL( 
       
  2457     ConML_ResultsPtr_t aContent, CSConRequestData* aResult )
       
  2458     {
       
  2459     TRACE_FUNC_ENTRY;
       
  2460     if ( aResult )
       
  2461         {
       
  2462         if ( aResult->iComplete )
       
  2463             {
       
  2464             aContent->complete = new ( ELeave ) pcdata_t();
       
  2465             }
       
  2466         AppendProgressL ( aContent, aResult->iProgress );
       
  2467         
       
  2468         if ( aResult->iMoreData )
       
  2469             {
       
  2470             aContent->moreData = new ( ELeave ) pcdata_t();
       
  2471             }
       
  2472         if ( aResult->iBackupData )
       
  2473             {
       
  2474             aContent->data = new ( ELeave ) pcdata_t();
       
  2475             aContent->data->SetDataL( aResult->iBackupData->Des() );
       
  2476             }
       
  2477         }
       
  2478     TRACE_FUNC_EXIT;
       
  2479     }
       
  2480 
       
  2481 // -----------------------------------------------------------------------------
       
  2482 // CSConPCConnSession::AppendSupplyDataResultsL()
       
  2483 // Appends a Supply data -element from the reply data of PCCS
       
  2484 // -----------------------------------------------------------------------------
       
  2485 //
       
  2486 void CSConPCConnSession::AppendSupplyDataResultsL( 
       
  2487     ConML_ResultsPtr_t aContent, CSConSupplyData* aResult )
       
  2488     {
       
  2489     TRACE_FUNC_ENTRY;
       
  2490     if ( aResult )
       
  2491         {
       
  2492         if ( aResult->iComplete )
       
  2493             {
       
  2494             aContent->complete = new ( ELeave ) pcdata_t();
       
  2495             }
       
  2496         AppendProgressL( aContent, aResult->iProgress );
       
  2497         }
       
  2498     TRACE_FUNC_EXIT;
       
  2499     }
       
  2500 
       
  2501 // -----------------------------------------------------------------------------
       
  2502 // CSConPCConnSession::AppendInstallResultsL()
       
  2503 // Appends an Install -element from the reply data of PCCS
       
  2504 // -----------------------------------------------------------------------------
       
  2505 //
       
  2506 void CSConPCConnSession::AppendInstallResultsL( 
       
  2507     ConML_ResultsPtr_t aContent, CSConInstall* aResult )
       
  2508     {
       
  2509     TRACE_FUNC_ENTRY;
       
  2510     if ( aResult )
       
  2511         {
       
  2512         if ( aResult->iComplete )
       
  2513             {
       
  2514             aContent->complete = new ( ELeave ) pcdata_t();
       
  2515             }
       
  2516         AppendProgressL( aContent, aResult->iProgress );
       
  2517         }
       
  2518     TRACE_FUNC_EXIT;
       
  2519     }
       
  2520     
       
  2521 // -----------------------------------------------------------------------------
       
  2522 // CSConPCConnSession::AppendUninstallResultsL()
       
  2523 // Appends an Uninstall -element from the reply data of PCCS
       
  2524 // -----------------------------------------------------------------------------
       
  2525 //
       
  2526 void CSConPCConnSession::AppendUninstallResultsL( 
       
  2527     ConML_ResultsPtr_t aContent, CSConUninstall* aResult )
       
  2528     {
       
  2529     TRACE_FUNC_ENTRY;
       
  2530     if ( aResult )
       
  2531         {
       
  2532         if ( aResult->iComplete )
       
  2533             {
       
  2534             LOGGER_WRITE( "CSConPCConnSession::AppendUninstallResultsL() Complete" );
       
  2535             aContent->complete = new ( ELeave ) pcdata_t();
       
  2536             }
       
  2537         LOGGER_WRITE_1( "CSConPCConnSession::AppendUninstallResultsL() iProgress: %d", aResult->iProgress );
       
  2538         AppendProgressL( aContent, aResult->iProgress );
       
  2539         }
       
  2540     TRACE_FUNC_EXIT;
       
  2541     }
       
  2542     
       
  2543 // -----------------------------------------------------------------------------
       
  2544 // CSConPCConnSession::AppendListDataOwnersResultsL()
       
  2545 // Appends a List data owners -element from the reply data of PCCS
       
  2546 // -----------------------------------------------------------------------------
       
  2547 //
       
  2548 void CSConPCConnSession::AppendListDataOwnersResultsL ( 
       
  2549     ConML_ResultsPtr_t aContent, CSConListDataOwners* aResult  )
       
  2550     {
       
  2551     TRACE_FUNC_ENTRY;
       
  2552     if ( aResult )  
       
  2553         {
       
  2554         if ( aResult->iComplete )
       
  2555             {
       
  2556             aContent->complete = new ( ELeave ) pcdata_t();
       
  2557             }
       
  2558         AppendProgressL( aContent, aResult->iProgress );
       
  2559         
       
  2560         if ( aResult->iDataOwners.Count() > 0 )
       
  2561             {
       
  2562             aContent->dataOwners = new ( ELeave ) ConML_DataOwners_t();
       
  2563             for ( TInt i=0; i < aResult->iDataOwners.Count(); i ++)
       
  2564                 {
       
  2565                 ConML_SIDListPtr_t sid = new ( ELeave ) ConML_SIDList_t();
       
  2566                 CleanupStack::PushL( sid );
       
  2567                 GenericListAddL ( &aContent->dataOwners->sid, sid );
       
  2568                 CleanupStack::Pop();
       
  2569             
       
  2570                 sid->data = new ( ELeave ) ConML_SID_t();
       
  2571                 
       
  2572                 sid->data->type = new ( ELeave ) pcdata_t();
       
  2573                 sid->data->type->SetDataL ( IntToDesLC ( 
       
  2574                     aResult->iDataOwners[i]->iType) );  
       
  2575                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2576                 
       
  2577                 sid->data->uid = new ( ELeave ) pcdata_t();
       
  2578                 
       
  2579                 if( aResult->iDataOwners[i]->iUid.iUid )
       
  2580                     {
       
  2581                     sid->data->uid->SetDataL ( UidToDesLC ( 
       
  2582                         aResult->iDataOwners[i]->iUid ) );
       
  2583                     CleanupStack::PopAndDestroy(); // UidToDesLC    
       
  2584                     }
       
  2585                     
       
  2586                 if( aResult->iDataOwners[i]->iJavaHash )
       
  2587                     {
       
  2588                     sid->data->uid->SetDataL ( HashToDesLC ( 
       
  2589                         aResult->iDataOwners[i]->iJavaHash->Des() ) );
       
  2590                     CleanupStack::PopAndDestroy(); // HashToDesLC
       
  2591                     }
       
  2592                                 
       
  2593                 if ( HasDrives ( aResult->iDataOwners[i]->iDriveList ) )
       
  2594                     {
       
  2595                     sid->data->drives = new ( ELeave ) ConML_Drives_t();
       
  2596                     AppendDrivesL ( sid->data->drives, 
       
  2597                         aResult->iDataOwners[i]->iDriveList );
       
  2598                     }       
       
  2599             
       
  2600                 if ( aResult->iDataOwners[i]->iPackageName.Length() > 0 ) 
       
  2601                     {
       
  2602                     sid->data->packageInfo = 
       
  2603                         new ( ELeave ) ConML_PackageInfo_t();
       
  2604                     sid->data->packageInfo->name = new ( ELeave ) pcdata_t();
       
  2605                     sid->data->packageInfo->name->SetDataL ( BufToDesLC ( 
       
  2606                         aResult->iDataOwners[i]->iPackageName  ) );
       
  2607 
       
  2608                     CleanupStack::PopAndDestroy(); // BufToDesLC
       
  2609                     }           
       
  2610             
       
  2611                 if ( aResult->iDataOwners[i]->iHasFiles || 
       
  2612                 aResult->iDataOwners[i]->iSupportsInc ||
       
  2613                 aResult->iDataOwners[i]->iDelayToPrep ||
       
  2614                 aResult->iDataOwners[i]->iReqReboot )
       
  2615                     {
       
  2616                     sid->data->burOptions = new ( ELeave ) ConML_BUROptions_t();
       
  2617                     if ( aResult->iDataOwners[i]->iHasFiles ) 
       
  2618                         {
       
  2619                         sid->data->burOptions->hasFiles = 
       
  2620                             new ( ELeave ) pcdata_t();
       
  2621                         sid->data->burOptions->hasFiles->SetDataL( IntToDesLC(
       
  2622                                 aResult->iDataOwners[i]->iHasFiles ));
       
  2623                                 
       
  2624                         CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2625                         }
       
  2626                     if ( aResult->iDataOwners[i]->iSupportsInc )
       
  2627                         {
       
  2628                         sid->data->burOptions->supportsInc = 
       
  2629                             new ( ELeave ) pcdata_t();
       
  2630                         }
       
  2631                     if ( aResult->iDataOwners[i]->iDelayToPrep )                        
       
  2632                         {
       
  2633                         sid->data->burOptions->delayToPrepareData = 
       
  2634                             new ( ELeave ) pcdata_t();
       
  2635                         }
       
  2636                     if ( aResult->iDataOwners[i]->iReqReboot )
       
  2637                         {
       
  2638                         sid->data->burOptions->requiresReboot = 
       
  2639                             new ( ELeave ) pcdata_t();
       
  2640                         }
       
  2641                     }
       
  2642                 }
       
  2643             }
       
  2644         }
       
  2645     TRACE_FUNC_EXIT;
       
  2646     }
       
  2647 
       
  2648 // -----------------------------------------------------------------------------
       
  2649 // CSConPCConnSession::AppendGetDataOwnerStatusResultsL()
       
  2650 // Appends a Get data owner status -element from the reply data of PCCS
       
  2651 // -----------------------------------------------------------------------------
       
  2652 //
       
  2653 void CSConPCConnSession::AppendGetDataOwnerStatusResultsL 
       
  2654     ( ConML_ResultsPtr_t aContent, CSConGetDataOwnerStatus* aResult )
       
  2655     {
       
  2656     TRACE_FUNC_ENTRY;
       
  2657     if ( aResult )
       
  2658         {
       
  2659         if ( aResult->iComplete )
       
  2660             {
       
  2661             aContent->complete = new ( ELeave ) pcdata_t();
       
  2662             }
       
  2663         AppendProgressL( aContent, aResult->iProgress );
       
  2664 
       
  2665         if ( aResult->iDataOwners.Count() > 0 )
       
  2666             {
       
  2667             aContent->dataOwners = new ( ELeave ) ConML_DataOwners_t();
       
  2668             for ( TInt i=0; i < aResult->iDataOwners.Count(); i ++)
       
  2669                 {
       
  2670                 ConML_SIDListPtr_t sid = new ( ELeave ) ConML_SIDList_t();
       
  2671                 CleanupStack::PushL( sid );
       
  2672                 GenericListAddL ( &aContent->dataOwners->sid, sid );
       
  2673                 CleanupStack::Pop();
       
  2674             
       
  2675                 sid->data = new ( ELeave ) ConML_SID_t();
       
  2676                 
       
  2677                 sid->data->type = new ( ELeave ) pcdata_t();
       
  2678                 sid->data->type->SetDataL ( IntToDesLC ( 
       
  2679                     aResult->iDataOwners[i]->iType) );  
       
  2680                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2681                 
       
  2682                 sid->data->uid = new ( ELeave ) pcdata_t();
       
  2683                 sid->data->uid->SetDataL ( UidToDesLC ( 
       
  2684                     aResult->iDataOwners[i]->iUid ) );
       
  2685                 CleanupStack::PopAndDestroy(); // UidToDesLC    
       
  2686                 
       
  2687                 sid->data->dataOwnerStatus = new ( ELeave ) pcdata_t();
       
  2688                 sid->data->dataOwnerStatus->SetDataL ( IntToDesLC( 
       
  2689                         aResult->iDataOwners[i]->iDataOwnStatus ));
       
  2690                 
       
  2691                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2692                 }
       
  2693             }
       
  2694         }
       
  2695     TRACE_FUNC_EXIT;
       
  2696     }
       
  2697 
       
  2698 // -----------------------------------------------------------------------------
       
  2699 // CSConPCConnSession::AppendGetDataSizeResultsL()
       
  2700 // Appends a Get data owner size -element from the reply data of PCCS
       
  2701 // -----------------------------------------------------------------------------
       
  2702 //
       
  2703 void CSConPCConnSession::AppendGetDataSizeResultsL ( 
       
  2704     ConML_ResultsPtr_t aContent, CSConGetDataSize* aResult )
       
  2705     {
       
  2706     TRACE_FUNC_ENTRY;
       
  2707     if ( aResult )  
       
  2708         {
       
  2709         if ( aResult->iComplete )
       
  2710             {
       
  2711             aContent->complete = new ( ELeave ) pcdata_t();
       
  2712             }
       
  2713         AppendProgressL( aContent, aResult->iProgress );
       
  2714         
       
  2715         if ( aResult->iDataOwners.Count() > 0 )
       
  2716             {
       
  2717             aContent->dataOwners = new ( ELeave ) ConML_DataOwners_t();
       
  2718                 
       
  2719             for ( TInt i=0; i< aResult->iDataOwners.Count(); i++ )      
       
  2720                 {
       
  2721                 ConML_SIDListPtr_t sid = new ( ELeave ) ConML_SIDList_t();
       
  2722                 CleanupStack::PushL( sid );
       
  2723                 GenericListAddL ( &aContent->dataOwners->sid, sid );
       
  2724                 CleanupStack::Pop();
       
  2725                 
       
  2726                 sid->data = new ( ELeave ) ConML_SID_t();
       
  2727                 
       
  2728                 sid->data->type = new ( ELeave ) pcdata_t();
       
  2729                 sid->data->type->SetDataL ( IntToDesLC ( 
       
  2730                     aResult->iDataOwners[i]->iType) );  
       
  2731                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2732                     
       
  2733                 sid->data->uid = new ( ELeave ) pcdata_t();
       
  2734                 
       
  2735                 if( aResult->iDataOwners[i]->iUid.iUid )
       
  2736                     {
       
  2737                     sid->data->uid->SetDataL ( UidToDesLC ( 
       
  2738                         aResult->iDataOwners[i]->iUid ) );
       
  2739                     CleanupStack::PopAndDestroy(); // UidToDesLC    
       
  2740                     }
       
  2741 
       
  2742                 if( aResult->iDataOwners[i]->iJavaHash )
       
  2743                     {
       
  2744                     sid->data->uid->SetDataL ( HashToDesLC ( 
       
  2745                         aResult->iDataOwners[i]->iJavaHash->Des() ) );
       
  2746                     CleanupStack::PopAndDestroy(); // HashToDesLC
       
  2747                     }
       
  2748     
       
  2749                 if ( HasDrives (  aResult->iDataOwners[i]->iDriveList ) )
       
  2750                     {
       
  2751                     sid->data->drives = new ( ELeave ) ConML_Drives_t();
       
  2752                     AppendDrivesL ( sid->data->drives, 
       
  2753                         aResult->iDataOwners[i]->iDriveList );
       
  2754                     }       
       
  2755                 
       
  2756                 sid->data->size = new ( ELeave ) pcdata_t();
       
  2757                 sid->data->size->SetDataL( IntToDesLC( 
       
  2758                     aResult->iDataOwners[i]->iSize ) );
       
  2759                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2760                 
       
  2761                 sid->data->transferDataType = new ( ELeave ) pcdata_t();
       
  2762                 sid->data->transferDataType->SetDataL( IntToDesLC( 
       
  2763                         aResult->iDataOwners[i]->iTransDataType ) );
       
  2764 
       
  2765                 CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2766                 }
       
  2767             }
       
  2768         }
       
  2769     TRACE_FUNC_EXIT;
       
  2770     }
       
  2771 
       
  2772 // -----------------------------------------------------------------------------
       
  2773 // CSConPCConnSession::AppendGetMetadataResultsL()
       
  2774 // Appends a GetMetadata -element from the reply data of PCCS
       
  2775 // -----------------------------------------------------------------------------
       
  2776 //
       
  2777 void CSConPCConnSession::AppendGetMetadataResultsL(
       
  2778     ConML_ResultsPtr_t aContent, CSConGetMetadata* aResult )
       
  2779     {
       
  2780     TRACE_FUNC_ENTRY;
       
  2781     
       
  2782     if ( aResult )
       
  2783         {
       
  2784         if ( aResult->iComplete )
       
  2785             {
       
  2786             aContent->complete = new ( ELeave ) pcdata_t();
       
  2787             
       
  2788             // add filename only if task is completed
       
  2789             aContent->filename = new ( ELeave ) pcdata_t();
       
  2790             aContent->filename->SetDataL( BufToDesLC(aResult->iFilename ) );
       
  2791             CleanupStack::PopAndDestroy(); // BufToDesLC
       
  2792             }
       
  2793         AppendProgressL( aContent, aResult->iProgress );
       
  2794         
       
  2795         if ( aResult->iData )
       
  2796             {
       
  2797             aContent->data = new ( ELeave ) pcdata_t();
       
  2798             aContent->data->SetDataL( aResult->iData->Des() );
       
  2799             }
       
  2800         
       
  2801         if ( aResult->iMoreData )
       
  2802             {
       
  2803             aContent->moreData = new ( ELeave ) pcdata_t();
       
  2804             }
       
  2805         }
       
  2806     TRACE_FUNC_EXIT;
       
  2807     }
       
  2808 
       
  2809 // -----------------------------------------------------------------------------
       
  2810 // CSConPCConnSession::AppendProgressL()
       
  2811 // Appends a Progress -element from the reply data of PCCS
       
  2812 // -----------------------------------------------------------------------------
       
  2813 //
       
  2814 void CSConPCConnSession::AppendProgressL ( 
       
  2815     ConML_ResultsPtr_t aContent, TInt progress )
       
  2816     {
       
  2817     TRACE_FUNC_ENTRY;
       
  2818     aContent->progress = new ( ELeave ) ConML_Progress_t();
       
  2819     aContent->progress->value = new ( ELeave ) pcdata_t();
       
  2820     aContent->progress->value->SetDataL ( IntToDesLC ( progress ));
       
  2821     CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2822     TRACE_FUNC_EXIT;
       
  2823     }
       
  2824 
       
  2825 // -----------------------------------------------------------------------------
       
  2826 // CSConPCConnSession::AppendDrivesL()
       
  2827 // Appends a Drives -element from the reply data of PCCS
       
  2828 // -----------------------------------------------------------------------------
       
  2829 //
       
  2830 void CSConPCConnSession::AppendDrivesL( 
       
  2831     ConML_DrivesPtr_t aContent, TDriveList aDrives )
       
  2832     {
       
  2833     TRACE_FUNC_ENTRY;
       
  2834     
       
  2835     for ( TInt i = 0; i<KMaxDrives; i++ )
       
  2836         {
       
  2837         if ( aDrives[i] )
       
  2838             {
       
  2839             ConML_DriveListPtr_t drive = new ( ELeave ) ConML_DriveList_t();
       
  2840             CleanupStack::PushL ( drive );
       
  2841             GenericListAddL ( &aContent->drive, drive );
       
  2842             CleanupStack::Pop(); // drive
       
  2843             
       
  2844             drive->data = new ( ELeave ) ConML_Drive_t();
       
  2845             drive->data->name = new ( ELeave ) pcdata_t();
       
  2846             drive->data->name->SetDataL( DriveNumToDesLC(i+KSConFirstDrive  ));
       
  2847             CleanupStack::PopAndDestroy(); // IntToDesLC
       
  2848             }
       
  2849         }
       
  2850     TRACE_FUNC_EXIT;
       
  2851     }
       
  2852 
       
  2853 // -----------------------------------------------------------------------------
       
  2854 // CSConPCConnSession::DriveList()
       
  2855 // Converts an Drives -element to TDriveList
       
  2856 // -----------------------------------------------------------------------------
       
  2857 //
       
  2858 TDriveList CSConPCConnSession::DriveList( ConML_DriveListPtr_t aContent )
       
  2859     {
       
  2860     TBuf8<KMaxDrives>  driveBuf;
       
  2861     TDriveList driveList;
       
  2862 
       
  2863     for ( ConML_DriveListPtr_t p = aContent; p && p->data; p = p->next )
       
  2864         {
       
  2865         if ( p->data->name )            
       
  2866             {
       
  2867             driveBuf.Append( p->data->name->Data() );
       
  2868             }
       
  2869         }
       
  2870 
       
  2871     for ( TInt i = 0; i<KMaxDrives; i++ )
       
  2872         {
       
  2873         if ( driveBuf.Locate ( TChar( i + KSConFirstDrive ) ) != KErrNotFound )
       
  2874             {
       
  2875             driveList.Append( KSConDriveExists );
       
  2876             }
       
  2877         else
       
  2878             {
       
  2879             driveList.Append( KSConNoDrive );
       
  2880             }
       
  2881         }
       
  2882     return driveList;
       
  2883     }
       
  2884 
       
  2885     
       
  2886 // -----------------------------------------------------------------------------
       
  2887 // CSConPCConnSession::IntToDesLC()
       
  2888 // Converts an integer to descriptor
       
  2889 // -----------------------------------------------------------------------------
       
  2890 //
       
  2891 TDesC8& CSConPCConnSession::IntToDesLC(const TInt& anInt)
       
  2892     {
       
  2893     HBufC8* buf = HBufC8::NewLC(20);
       
  2894     TPtr8 ptrBuf = buf->Des();
       
  2895     ptrBuf.Num(anInt);
       
  2896     return *buf;
       
  2897     }
       
  2898     
       
  2899 // -----------------------------------------------------------------------------
       
  2900 // CSConPCConnSession::DriveNumToDesLC()
       
  2901 // Convers a drive number to equivalent drive letter 
       
  2902 // -----------------------------------------------------------------------------
       
  2903 //
       
  2904 TDesC8& CSConPCConnSession::DriveNumToDesLC( const TInt& anInt )
       
  2905     {
       
  2906     TChar mark ( anInt );
       
  2907     HBufC8* buf = HBufC8::NewLC(1);
       
  2908     TPtr8 ptrBuf = buf->Des();
       
  2909     ptrBuf.Append(mark);
       
  2910     return *buf;
       
  2911     }
       
  2912     
       
  2913 // -----------------------------------------------------------------------------
       
  2914 // CSConPCConnSession::BufToDesLC()
       
  2915 // converts a buffer to descriptor
       
  2916 // -----------------------------------------------------------------------------
       
  2917 //
       
  2918 TDesC8& CSConPCConnSession::BufToDesLC( const TDesC& aBuf)
       
  2919     {
       
  2920     HBufC8* buf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aBuf );
       
  2921     CleanupStack::PushL( buf );
       
  2922     return *buf;
       
  2923     }
       
  2924     
       
  2925 // -----------------------------------------------------------------------------
       
  2926 // CSConPCConnSession::UidToDesLC()
       
  2927 // converts an UID to a descriptor
       
  2928 // -----------------------------------------------------------------------------
       
  2929 //
       
  2930 TDesC8& CSConPCConnSession::UidToDesLC( const TUid& aUid )
       
  2931     {
       
  2932     HBufC8* buf = HBufC8::NewLC(10);
       
  2933     TPtr8 ptrBuf = buf->Des();
       
  2934     ptrBuf.Copy (aUid.Name().Mid(1, 8) );
       
  2935     return *buf;
       
  2936     }
       
  2937     
       
  2938 // -----------------------------------------------------------------------------
       
  2939 // CSConPCConnSession::DesToUid()
       
  2940 // converts a descriptor to a UID value
       
  2941 // -----------------------------------------------------------------------------
       
  2942 //
       
  2943 TUid CSConPCConnSession::DesToUid ( const TDesC8& aDes )
       
  2944     {
       
  2945     TLex8 lex( aDes );
       
  2946     TUint32 value;
       
  2947     lex.Val( value, EHex );
       
  2948     TUid uid = TUid::Uid( value );
       
  2949     return uid;
       
  2950     }   
       
  2951     
       
  2952 // -----------------------------------------------------------------------------
       
  2953 // CSConPCConnSession::DesToInt()
       
  2954 // converts a descriptor to a integer value
       
  2955 // -----------------------------------------------------------------------------
       
  2956 //
       
  2957 TInt CSConPCConnSession::DesToInt( const TDesC8& aDes)
       
  2958     {
       
  2959     TLex8 lex(aDes);
       
  2960     TInt value = 0;
       
  2961     lex.Val(value);
       
  2962     return value;
       
  2963     }
       
  2964 
       
  2965 // -----------------------------------------------------------------------------
       
  2966 // CSConPCConnSession::HasDrives()
       
  2967 // Returns ETrue if at least one drive is found from the given TDriveList
       
  2968 // -----------------------------------------------------------------------------
       
  2969 //
       
  2970 TBool CSConPCConnSession::HasDrives( TDriveList& aDrive )
       
  2971     {
       
  2972     TBool hasDrives ( EFalse );     
       
  2973     for ( TInt i = 0; i<KMaxDrives; i++ )
       
  2974         {
       
  2975         if ( aDrive[i] )
       
  2976             {
       
  2977             hasDrives = ETrue;
       
  2978             }
       
  2979         }
       
  2980     return hasDrives;
       
  2981     }
       
  2982 // -----------------------------------------------------------------------------
       
  2983 // CSConPCConnSession::HashToDesLC()
       
  2984 // converts a Java hash to descriptor
       
  2985 // -----------------------------------------------------------------------------
       
  2986 //
       
  2987 TDesC8& CSConPCConnSession::HashToDesLC( const TDesC& aBuf)
       
  2988     {
       
  2989     HBufC8* buf = HBufC8::NewLC(aBuf.Size()+5);
       
  2990     TPtr8 ptrBuf = buf->Des();
       
  2991     // Unicode conversion from 16-bit to 8-bit
       
  2992     CnvUtfConverter::ConvertFromUnicodeToUtf8(ptrBuf, aBuf);
       
  2993     //Add JAVA_ identifier to the begining of the hash
       
  2994     ptrBuf.Insert(0, KSConJavaHashId);
       
  2995     return *buf;
       
  2996     }
       
  2997 // -----------------------------------------------------------------------------
       
  2998 // CSConPCConnSession::DesToHashLC()
       
  2999 // converts descriptor to Java hash
       
  3000 // -----------------------------------------------------------------------------
       
  3001 //    
       
  3002 TPtr CSConPCConnSession::DesToHashLC( const TDesC8& aDes )
       
  3003     {
       
  3004     HBufC* buf = HBufC::NewLC(aDes.Size());
       
  3005     TPtr ptrBuf = buf->Des();
       
  3006     // Unicode conversion from 8-bit to 16-bit
       
  3007     CnvUtfConverter::ConvertToUnicodeFromUtf8(ptrBuf, aDes);
       
  3008     //Delete JAVA_
       
  3009     ptrBuf.Delete(0, KSConJavaHashId().Length());   
       
  3010     return ptrBuf;
       
  3011     }
       
  3012 // -----------------------------------------------------------------------------
       
  3013 // CSConPCConnSession::IsJavaHash()
       
  3014 // Returns ETrue if descriptor is Java hash, else EFalse
       
  3015 // -----------------------------------------------------------------------------
       
  3016 //  
       
  3017 TBool CSConPCConnSession::IsJavaHash( const TDesC8& aDes )
       
  3018     {
       
  3019     if ( aDes.FindC(KSConJavaHashId) == 0 )
       
  3020         {
       
  3021         return ETrue;
       
  3022         }
       
  3023     else
       
  3024         {
       
  3025         return EFalse;
       
  3026         }
       
  3027     }
       
  3028