connectivitymodules/SeCon/servers/pcconn/src/sconpcconnserver.cpp
branchRCL_3
changeset 18 453dfc402455
parent 0 d0791faffa3f
equal deleted inserted replaced
17:dbd1c5e08735 18:453dfc402455
     1 /*
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <s32mem.h> // For RMemReadStream
    19 #include <s32mem.h> // For RMemReadStream
    20 #include <utf.h>
    20 #include <utf.h>
       
    21 #include <Etel3rdParty.h>
       
    22 #include <f32file.h>
    21 
    23 
    22 #include "sconpcconnclientserver.h"
    24 #include "sconpcconnclientserver.h"
    23 #include "sconpcconnserver.h"
    25 #include "sconpcconnserver.h"
    24 #include "sconpcd.h"
    26 #include "sconpcd.h"
    25 #include "sconcsc.h"
    27 #include "sconcsc.h"
    26 #include "sconconmlhandler.h"
    28 #include "sconconmlhandler.h"
       
    29 #include "sconimsireader.h"
       
    30 #include "sconoviaccounthandler.h"
       
    31 #include "sconfolderlister.h"
       
    32 #include "sconbtengine.h"
    27 #include "debug.h"
    33 #include "debug.h"
    28 
    34 
    29 #ifdef DEBUG_XML
    35 #ifdef DEBUG_XML
    30 #include <s32file.h>
    36 #include <s32file.h>
    31 _LIT8( KTimeFormat, "%02d:%02d:%02d.%03d" );
    37 _LIT8( KTimeFormat, "%02d:%02d:%02d.%03d" );
    32 _LIT8( KXmlBegin, "\nXML:\n" );
    38 _LIT8( KXmlBegin, "\nXML:\n" );
    33 #endif
    39 #endif
    34 
    40 
    35 _LIT( KSCONGetMetadataRequest, "METADATA:" );
    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:" );
    36 
    51 
    37 //------------------------------------------------------------
    52 //------------------------------------------------------------
    38 // Global functions 
    53 // Global functions 
    39 //------------------------------------------------------------
    54 //------------------------------------------------------------
    40 
    55 
   127     TSecureId clientId = client.SecureId();
   142     TSecureId clientId = client.SecureId();
   128     
   143     
   129     if ( clientId != KSConPCConnClientSecureId )
   144     if ( clientId != KSConPCConnClientSecureId )
   130         {
   145         {
   131         LOGGER_WRITE( "CSConPCConnServer::NewSessionL() : Secure ID does not match" );
   146         LOGGER_WRITE( "CSConPCConnServer::NewSessionL() : Secure ID does not match" );
       
   147 #ifndef __WINS__
       
   148         LOGGER_WRITE( "Leave KErrAccessDenied");
   132         User::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
   133         }
   154         }
   134     
   155     
   135     TRACE_FUNC_EXIT;
   156     TRACE_FUNC_EXIT;
   136     return CSConPCConnSession::NewL( *CONST_CAST( CSConPCConnServer*, this));
   157     return CSConPCConnSession::NewL( *CONST_CAST( CSConPCConnServer*, this));
   137     }
   158     }
   270         delete iBuffer;
   291         delete iBuffer;
   271         iBuffer = NULL;
   292         iBuffer = NULL;
   272         }
   293         }
   273         
   294         
   274     iChunk.Close();
   295     iChunk.Close();
   275         
   296     delete iFolderLister;
       
   297     
       
   298     iFs.Close();
       
   299     
       
   300     delete iBtEngine;
       
   301      
   276     TRACE_FUNC_EXIT;
   302     TRACE_FUNC_EXIT;
   277     }
   303     }
   278 
   304 
   279 // -----------------------------------------------------------------------------
   305 // -----------------------------------------------------------------------------
   280 // CSConPCConnSession::NewL()
   306 // CSConPCConnSession::NewL()
   302     {
   328     {
   303     TRACE_FUNC_ENTRY;
   329     TRACE_FUNC_ENTRY;
   304     TInt ret ( KErrNone );
   330     TInt ret ( KErrNone );
   305     iResult = KErrNone;
   331     iResult = KErrNone;
   306     
   332     
       
   333     User::LeaveIfError( iFs.Connect() );
       
   334     
   307 #ifdef DEBUG_XML
   335 #ifdef DEBUG_XML
   308     // create log file 
   336     // create log file 
   309     RFs fs;
       
   310     User::LeaveIfError( fs.Connect () );
       
   311     CleanupClosePushL( fs );
       
   312     
   337     
   313     RFile file;
   338     RFile file;
   314     TInt err = file.Create ( fs, KSConConMLDebugFile, EFileWrite );
   339     TInt err = file.Create ( iFs, KSConConMLDebugFile, EFileWrite );
   315     if( err == KErrNone )
   340     if( err == KErrNone )
   316         {
   341         {
   317         // file created, close it
   342         // file created, close it
   318         file.Close();
   343         file.Close();
   319         }       
   344         }              
   320     
       
   321     CleanupStack::PopAndDestroy( &fs );               
       
   322 #endif
   345 #endif
   323     
   346     
   324     // initialize buffer
   347     // initialize buffer
   325     iBuffer = CBufFlat::NewL ( KSConPCConnBufferMaxSize );
   348     iBuffer = CBufFlat::NewL ( KSConPCConnBufferMaxSize );
   326     
   349     
   353             {
   376             {
   354             LOGGER_WRITE_1( "CSConPCConnSession::ConstructL() : Parser dll load failed with error code %d", ret );
   377             LOGGER_WRITE_1( "CSConPCConnSession::ConstructL() : Parser dll load failed with error code %d", ret );
   355             User::Leave ( ret );
   378             User::Leave ( ret );
   356             }
   379             }
   357         }
   380         }
   358 
   381     
       
   382     iFolderLister = CSconFolderLister::NewL( iFs );
       
   383     
   359     TRACE_FUNC_EXIT;
   384     TRACE_FUNC_EXIT;
   360     }
   385     }
   361 
   386 
   362 // -----------------------------------------------------------------------------
   387 // -----------------------------------------------------------------------------
   363 // CSConPCConnSession::ServiceL()
   388 // CSConPCConnSession::ServiceL()
   455 
   480 
   456 
   481 
   457     iBuffer->Reset();
   482     iBuffer->Reset();
   458 
   483 
   459     length = buf.ReadInt32L();
   484     length = buf.ReadInt32L();
   460     HBufC8* name = HBufC8::NewLC( length );
   485     HBufC8* name8 = HBufC8::NewLC( length );
   461     TPtr8 namePtr = name->Des();
   486     TPtr8 namePtr8 = name8->Des();
   462     buf.ReadL( namePtr, length);
   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 );
   463         
   493         
   464     length = buf.ReadInt32L();
   494     length = buf.ReadInt32L();
   465     HBufC8* type = HBufC8::NewLC( length );
   495     HBufC8* type = HBufC8::NewLC( length );
   466     TPtr8 typePtr = type->Des();
   496     TPtr8 typePtr = type->Des();
   467     buf.ReadL( typePtr, length);
   497     buf.ReadL( typePtr, length);
   476     iBuffer->Write( 0, dataPtr );
   506     iBuffer->Write( 0, dataPtr );
   477             
   507             
   478     buf.Close();
   508     buf.Close();
   479     
   509     
   480 #ifdef DEBUG_XML
   510 #ifdef DEBUG_XML
   481     RFs fs;
       
   482     User::LeaveIfError( fs.Connect() );
       
   483     CleanupClosePushL( fs );
       
   484 
   511 
   485     RFile file;
   512     RFile file;
   486     if ( file.Open( fs, KSConConMLDebugFile, EFileWrite ) == KErrNone )
   513     if ( file.Open( iFs, KSConConMLDebugFile, EFileWrite ) == KErrNone )
   487         {
   514         {
   488         RFileWriteStream fws;
   515         RFileWriteStream fws;
   489         TInt fileSize;
   516         TInt fileSize;
   490         file.Size( fileSize );
   517         file.Size( fileSize );
   491         
   518         
   505         TRAP_IGNORE( fws.CommitL() );
   532         TRAP_IGNORE( fws.CommitL() );
   506         fws.Close();
   533         fws.Close();
   507  
   534  
   508         CleanupStack::PopAndDestroy( &fws );
   535         CleanupStack::PopAndDestroy( &fws );
   509         }
   536         }
   510     file.Close();   
   537     file.Close();
   511     CleanupStack::PopAndDestroy( &fs );
       
   512 #endif
   538 #endif
   513     
   539     if ( ( ( typePtr.CompareC( KSConPCDWBXMLObjectType)== KErrNone ) || 
   514     if ( ( typePtr.Compare( 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) || 
   515          ( typePtr.Compare( KSConPCDWBXMLObjectType2 )== KErrNone) )
   556          ( typePtr.Compare( KSConPCDWBXMLObjectType2 )== KErrNone) )
   516         {
   557         {
   517         LOGGER_WRITE( "CSConPCConnSession::HandlePutMessageL() : Object type PCD " );
   558         LOGGER_WRITE( "CSConPCConnSession::HandlePutMessageL() : Object type PCD " );
   518         TRAPD( err, ret = iConMLHandler->ParseDocumentL( *iBuffer, this ) );    
   559         TRAPD( err, ret = iConMLHandler->ParseDocumentL( *iBuffer, this ) );    
   519         if ( err != KErrNone )
   560         if ( err != KErrNone )
   531         LOGGER_WRITE( "Object type not regognized " );
   572         LOGGER_WRITE( "Object type not regognized " );
   532         ret = KErrNotSupported;
   573         ret = KErrNotSupported;
   533         }
   574         }
   534     CleanupStack::PopAndDestroy( data );
   575     CleanupStack::PopAndDestroy( data );
   535     CleanupStack::PopAndDestroy( type );
   576     CleanupStack::PopAndDestroy( type );
   536     CleanupStack::PopAndDestroy( name );
   577     CleanupStack::PopAndDestroy( name8 );
   537     LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL() end : Heap count : %d", User::Heap().Count() );
   578     LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL() end : Heap count : %d", User::Heap().Count() );
   538     LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL() : returned %d", ret );    
   579     LOGGER_WRITE_1( "CSConPCConnSession::HandlePutMessageL() : returned %d", ret );    
   539     return ret;
   580     return ret;
   540     }
   581     }
   541 
   582 
   585     if ( typePtr.Compare( KSConCapabilityObjectType ) == KErrNone )
   626     if ( typePtr.Compare( KSConCapabilityObjectType ) == KErrNone )
   586         {
   627         {
   587         ret = iCSCHandler->CapabilityObject( *iBuffer );
   628         ret = iCSCHandler->CapabilityObject( *iBuffer );
   588         
   629         
   589 #ifdef DEBUG_XML
   630 #ifdef DEBUG_XML
   590         RFs fs;
   631         
   591         User::LeaveIfError(fs.Connect());
       
   592         CleanupClosePushL(fs);
       
   593 
       
   594         RFile file;
   632         RFile file;
   595         if ( file.Open(fs, KSConConMLDebugFile, EFileWrite ) == KErrNone )
   633         if ( file.Open(iFs, KSConConMLDebugFile, EFileWrite ) == KErrNone )
   596             {
   634             {
   597             RFileWriteStream fws;
   635             RFileWriteStream fws;
   598             TInt fileSize;
   636             TInt fileSize;
   599             file.Size ( fileSize );
   637             file.Size ( fileSize );
   600             TTime now;
   638             TTime now;
   614             fws.Close();
   652             fws.Close();
   615 
   653 
   616             CleanupStack::PopAndDestroy( &fws );
   654             CleanupStack::PopAndDestroy( &fws );
   617             }
   655             }
   618         file.Close();
   656         file.Close();
   619         CleanupStack::PopAndDestroy( &fs );
       
   620 #endif
   657 #endif
   621 
   658 
   622         }
   659         }
   623     else if (  typePtr.CompareC( KSConPCDWBXMLObjectType) == KErrNone )
   660     else if (  typePtr.CompareC( KSConPCDWBXMLObjectType) == KErrNone )
   624         {
   661         {
   625         ret = HandleWBXMLGetRequestL( namePtr );
   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             }
   626         }
   869         }
   627     else
   870     else
   628         {
   871         {
   629         LOGGER_WRITE( "CSConPCConnSession::HandleGetMessageL() : Header type not regognized " );
   872         LOGGER_WRITE( "CSConPCConnSession::HandleGetMessageL() : Header type not regognized " );
   630         ret = KErrNotSupported;
   873         ret = KErrNotSupported;
   758 #endif
  1001 #endif
   759     TRACE_FUNC_RET(ret);
  1002     TRACE_FUNC_RET(ret);
   760     return ret;
  1003     return ret;
   761     }
  1004     }
   762 
  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 
   763 // -----------------------------------------------------------------------------
  1059 // -----------------------------------------------------------------------------
   764 // CSConPCConnSession::HandleResetMessage()
  1060 // CSConPCConnSession::HandleResetMessage()
   765 // Resets the PCCS service
  1061 // Resets the PCCS service
   766 // -----------------------------------------------------------------------------
  1062 // -----------------------------------------------------------------------------
   767 //
  1063 //
   876     TRACE_FUNC_ENTRY;
  1172     TRACE_FUNC_ENTRY;
   877     TInt ret ( KErrNone );
  1173     TInt ret ( KErrNone );
   878     
  1174     
   879 #ifdef DEBUG_XML
  1175 #ifdef DEBUG_XML
   880     iConMLHandler->GenerateDocument( aContent );
  1176     iConMLHandler->GenerateDocument( aContent );
   881     RFs fs;
       
   882     User::LeaveIfError(fs.Connect());
       
   883     CleanupClosePushL(fs);
       
   884     RFile file;
  1177     RFile file;
   885     
  1178     if ( file.Open(iFs, KSConConMLDebugFile, EFileWrite) == KErrNone )
   886     if ( file.Open(fs, KSConConMLDebugFile, EFileWrite) == KErrNone )
       
   887         {
  1179         {
   888         RFileWriteStream fws;
  1180         RFileWriteStream fws;
   889         TInt fileSize;
  1181         TInt fileSize;
   890         file.Size( fileSize );
  1182         file.Size( fileSize );
   891         fws.Attach ( file, fileSize );
  1183         fws.Attach ( file, fileSize );
   908         TRAP_IGNORE( fws.CommitL() );
  1200         TRAP_IGNORE( fws.CommitL() );
   909         fws.Close();
  1201         fws.Close();
   910         CleanupStack::PopAndDestroy( &fws );
  1202         CleanupStack::PopAndDestroy( &fws );
   911         }
  1203         }
   912     file.Close();
  1204     file.Close();
   913     CleanupStack::PopAndDestroy( &fs );
       
   914     
  1205     
   915 #endif
  1206 #endif
   916 
  1207 
   917 
  1208 
   918     if ( aContent )
  1209     if ( aContent )
  1355         {
  1646         {
  1356         for ( ConML_SIDListPtr_t p = aContent->dataOwners->sid; 
  1647         for ( ConML_SIDListPtr_t p = aContent->dataOwners->sid; 
  1357                 p && p->data; p=p->next )
  1648                 p && p->data; p=p->next )
  1358             {
  1649             {
  1359             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
  1650             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
       
  1651             CleanupStack::PushL( dataOwner );
  1360             if ( p->data->type )
  1652             if ( p->data->type )
  1361                 {
  1653                 {
  1362                 dataOwner->iType = TSConDOType (DesToInt( 
  1654                 dataOwner->iType = TSConDOType (DesToInt( 
  1363                     p->data->type->Data() ));
  1655                     p->data->type->Data() ));
  1364                 }
  1656                 }
  1383             if ( p->data->transferDataType )
  1675             if ( p->data->transferDataType )
  1384                 {
  1676                 {
  1385                 TInt intValue = DesToInt( p->data->transferDataType->Data() );
  1677                 TInt intValue = DesToInt( p->data->transferDataType->Data() );
  1386                 dataOwner->iTransDataType = static_cast<TSConTransferDataType> (intValue);
  1678                 dataOwner->iTransDataType = static_cast<TSConTransferDataType> (intValue);
  1387                 }
  1679                 }
  1388             task->iGetDataSizeParams->iDataOwners.Append( dataOwner );
  1680             task->iGetDataSizeParams->iDataOwners.AppendL( dataOwner );
       
  1681             CleanupStack::Pop( dataOwner );
  1389             }
  1682             }
  1390         }
  1683         }
  1391     ret = iPCDHandler->PutTaskL( task );
  1684     ret = iPCDHandler->PutTaskL( task );
  1392     CleanupStack::Pop( task );
  1685     CleanupStack::Pop( task );
  1393     LOGGER_WRITE_1( "CSConPCConnSession::TaskGetDataSizeL() : returned %d", ret );    
  1686     LOGGER_WRITE_1( "CSConPCConnSession::TaskGetDataSizeL() : returned %d", ret );    
  1538     if ( aContent->sid )
  1831     if ( aContent->sid )
  1539         {
  1832         {
  1540         for ( ConML_SIDListPtr_t p = aContent->sid; p && p->data; p = p->next )
  1833         for ( ConML_SIDListPtr_t p = aContent->sid; p && p->data; p = p->next )
  1541             {
  1834             {
  1542             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
  1835             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
  1543             
  1836             CleanupStack::PushL( dataOwner );
  1544             if ( p->data->type )                
  1837             if ( p->data->type )                
  1545                 {
  1838                 {
  1546                 dataOwner->iType = TSConDOType ( DesToInt( 
  1839                 dataOwner->iType = TSConDOType ( DesToInt( 
  1547                                         p->data->type->Data() ) );
  1840                                         p->data->type->Data() ) );
  1548                 }
  1841                 }
  1569                 // Unicode conversion from 8-bit to 16-bit
  1862                 // Unicode conversion from 8-bit to 16-bit
  1570                 CnvUtfConverter::ConvertToUnicodeFromUtf8(
  1863                 CnvUtfConverter::ConvertToUnicodeFromUtf8(
  1571                         dataOwner->iPackageName, 
  1864                         dataOwner->iPackageName, 
  1572                         p->data->packageInfo->name->Data());
  1865                         p->data->packageInfo->name->Data());
  1573                 }
  1866                 }
  1574             task->iPubFilesParams->iDataOwners.Append( dataOwner );
  1867             task->iPubFilesParams->iDataOwners.AppendL( dataOwner );
       
  1868             CleanupStack::Pop( dataOwner );
  1575             }
  1869             }
  1576         }
  1870         }
  1577     ret = iPCDHandler->PutTaskL( task );
  1871     ret = iPCDHandler->PutTaskL( task );
  1578     CleanupStack::Pop( task );
  1872     CleanupStack::Pop( task );
  1579     LOGGER_WRITE_1( "CSConPCConnSession::TaskListPublicFilesL() : returned %d", ret );    
  1873     LOGGER_WRITE_1( "CSConPCConnSession::TaskListPublicFilesL() : returned %d", ret );    
  1665         {
  1959         {
  1666         for ( ConML_SIDListPtr_t p = aContent->dataOwners->sid; 
  1960         for ( ConML_SIDListPtr_t p = aContent->dataOwners->sid; 
  1667                 p && p->data; p=p->next )
  1961                 p && p->data; p=p->next )
  1668             {
  1962             {
  1669             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
  1963             CSConDataOwner* dataOwner = new (ELeave) CSConDataOwner();
       
  1964             CleanupStack::PushL( dataOwner );
  1670             if ( p->data->type )    
  1965             if ( p->data->type )    
  1671                 {
  1966                 {
  1672                 dataOwner->iType = TSConDOType (DesToInt(
  1967                 dataOwner->iType = TSConDOType (DesToInt(
  1673                                      p->data->type->Data() ));
  1968                                      p->data->type->Data() ));
  1674                 }
  1969                 }
  1684                     dataOwner->iJavaHash = HBufC::NewL( hashPtr.Size() );
  1979                     dataOwner->iJavaHash = HBufC::NewL( hashPtr.Size() );
  1685                     dataOwner->iJavaHash->Des().Copy( hashPtr );
  1980                     dataOwner->iJavaHash->Des().Copy( hashPtr );
  1686                     CleanupStack::PopAndDestroy(); //DesToHashLC()
  1981                     CleanupStack::PopAndDestroy(); //DesToHashLC()
  1687                     }
  1982                     }
  1688                 }           
  1983                 }           
  1689             task->iGetDataOwnerParams->iDataOwners.Append( dataOwner );
  1984             task->iGetDataOwnerParams->iDataOwners.AppendL( dataOwner );
       
  1985             CleanupStack::Pop( dataOwner );
  1690             }
  1986             }
  1691         }
  1987         }
  1692     ret = iPCDHandler->PutTaskL( task );
  1988     ret = iPCDHandler->PutTaskL( task );
  1693     CleanupStack::Pop( task );
  1989     CleanupStack::Pop( task );
  1694     LOGGER_WRITE_1( "CSConPCConnSession::TaskGetDataOwnerStatusL() : returned %d", ret );    
  1990     LOGGER_WRITE_1( "CSConPCConnSession::TaskGetDataOwnerStatusL() : returned %d", ret );    
  2018             }
  2314             }
  2019         AppendProgressL ( aContent, aResult->iProgress );
  2315         AppendProgressL ( aContent, aResult->iProgress );
  2020         
  2316         
  2021         if ( aResult->iApps.Count() > 0 )
  2317         if ( aResult->iApps.Count() > 0 )
  2022             {
  2318             {
  2023             // 5 * KMaxFileName should be enought
  2319             // 6 * KMaxFileName should be enought
  2024             // ( 4 items of TFileName and uid + type + size + 6* "#" )
  2320             // ( 5 items of TFileName and uid + type + size + 7* "#" )
  2025             HBufC8* buf = HBufC8::NewLC( 5 * KMaxFileName );
  2321             HBufC8* buf = HBufC8::NewLC( 6 * KMaxFileName );
  2026             TPtr8 ptrBuf = buf->Des();
  2322             TPtr8 ptrBuf = buf->Des();
  2027             
  2323             
  2028             aContent->applications = new ( ELeave ) ConML_Applications_t();
  2324             aContent->applications = new ( ELeave ) ConML_Applications_t();
  2029             for ( TInt i=0; i<aResult->iApps.Count(); i++)
  2325             for ( TInt i=0; i<aResult->iApps.Count(); i++)
  2030                 {
  2326                 {
  2038                 app->data->name = new ( ELeave ) pcdata_t();
  2334                 app->data->name = new ( ELeave ) pcdata_t();
  2039                 app->data->name->SetDataL( BufToDesLC( 
  2335                 app->data->name->SetDataL( BufToDesLC( 
  2040                     aResult->iApps[i]->iName));
  2336                     aResult->iApps[i]->iName));
  2041                 CleanupStack::PopAndDestroy(); // BufToDesLC
  2337                 CleanupStack::PopAndDestroy(); // BufToDesLC
  2042                 
  2338                 
  2043                 // create uid: UID # Type # Size # Version # Vendor # Parent app. name #
  2339                 // create uid: UID # Type # Size # Version # Vendor # Parent app. name # WidgetBundleId #
  2044                 LOGGER_WRITE( "CSConPCConnSession::AppendListInstalledAppsResultsL() : Create Uid" );
  2340                 LOGGER_WRITE( "CSConPCConnSession::AppendListInstalledAppsResultsL() : Create Uid" );
  2045                 
  2341                 
  2046                 ptrBuf.Copy( UidToDesLC( aResult->iApps[i]->iUid ) );
  2342                 ptrBuf.Copy( UidToDesLC( aResult->iApps[i]->iUid ) );
  2047                 CleanupStack::PopAndDestroy(); // UidToDesLC
  2343                 CleanupStack::PopAndDestroy(); // UidToDesLC
  2048                 
  2344                 
  2064                 CleanupStack::PopAndDestroy(); // BufToDesLC
  2360                 CleanupStack::PopAndDestroy(); // BufToDesLC
  2065                 
  2361                 
  2066                 ptrBuf.Append( KSConAppInfoSeparator );
  2362                 ptrBuf.Append( KSConAppInfoSeparator );
  2067                 ptrBuf.Append( BufToDesLC( aResult->iApps[i]->iParentName ) );
  2363                 ptrBuf.Append( BufToDesLC( aResult->iApps[i]->iParentName ) );
  2068                 CleanupStack::PopAndDestroy(); // BufToDesLC
  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                     }
  2069                 
  2372                 
  2070                 ptrBuf.Append( KSConAppInfoSeparator );
  2373                 ptrBuf.Append( KSConAppInfoSeparator );
  2071                 
  2374                 
  2072                 LOGGER_WRITE( "CSConPCConnSession::AppendListInstalledAppsResultsL() : set data" );
  2375                 LOGGER_WRITE( "CSConPCConnSession::AppendListInstalledAppsResultsL() : set data" );
  2073                 app->data->uid = new ( ELeave ) pcdata_t();
  2376                 app->data->uid = new ( ELeave ) pcdata_t();