connectivitymodules/SeCon/plugins/ftp/src/sconftpplugin.cpp
branchRCL_3
changeset 19 0aa8cc770c8a
parent 18 453dfc402455
child 20 4a793f564d72
equal deleted inserted replaced
18:453dfc402455 19:0aa8cc770c8a
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  File Transfer Profile Plug-in implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    22 #include <obexconstantsinternal.h>
       
    23 #endif
       
    24 #include "sconftpplugin.h"
       
    25 #include "sconftp.h"
       
    26 #include "sconftppluginutils.h"
       
    27 #include "sconservicetimer.h"
       
    28 #include "debug.h"
       
    29 
       
    30 
       
    31 // CONSTANTS
       
    32 _LIT(KSConFTPLibName, "sconftp.dll");
       
    33 const TInt KSConFTPUidValue = 0x10009D8D;
       
    34 const TUid KSConFTPUid = {KSConFTPUidValue};
       
    35 
       
    36 // Folder listing type from IrObex specification
       
    37 _LIT8( KSConFolderListType, "x-obex/folder-listing" );
       
    38 
       
    39 _LIT( K_C_ROOT, "C:\\" );
       
    40 const TInt KSConBufSize = 262144; // 256KB
       
    41 // Time (in milliseconds) for the timer
       
    42 const TInt KSConTimeOutValue =  60000000;
       
    43 // Flags used to indicate SetPath commands
       
    44 const TInt KSConNULLSetPath =   0x00;
       
    45 
       
    46 const TInt KSConHeaderMaxLength = 256;
       
    47 
       
    48 // ============================= MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CSConFTPplugin::NewL()
       
    52 // Two-phase constructor
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CSConFTPplugin* CSConFTPplugin::NewL()
       
    56     {
       
    57     TRACE_FUNC_ENTRY;
       
    58     CSConFTPplugin* self = new ( ELeave ) CSConFTPplugin();
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     TRACE_FUNC_EXIT;
       
    63     return( self );
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CSConFTPplugin::~CSConFTPplugin()
       
    68 // Destructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CSConFTPplugin::~CSConFTPplugin()
       
    72     {
       
    73     TRACE_FUNC_ENTRY;
       
    74     
       
    75     // Disconnect from services.
       
    76     Disconnect();
       
    77     
       
    78     if ( iFTPHandler )
       
    79         {
       
    80         delete iFTPHandler;
       
    81         iFTPHandler = NULL;
       
    82         iFTPlib.Close();
       
    83         }
       
    84     
       
    85     delete iBuffer;
       
    86     iBuffer = NULL;
       
    87     delete iObject;
       
    88     iObject = NULL;
       
    89 
       
    90     if ( iServiceTimer )
       
    91         {
       
    92         iServiceTimer->Cancel();
       
    93         }
       
    94 
       
    95     delete iServiceTimer;
       
    96     iServiceTimer = NULL;
       
    97 
       
    98     if ( iFileObject )
       
    99         {
       
   100         delete iFileObject;
       
   101         iFileObject = NULL;
       
   102         }
       
   103 
       
   104 
       
   105     delete iShutdownWatcher;
       
   106     iShutdownWatcher = NULL;
       
   107     
       
   108     TRACE_FUNC_EXIT;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CSConFTPplugin::IsOBEXActive()
       
   113 // Returns active status of OBEX session
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TBool CSConFTPplugin::IsOBEXActive()
       
   117     {
       
   118     TRACE_FUNC;
       
   119     return iSessionActive;
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CSConFTPplugin::NotifyShutdown()
       
   124 // System is shutting down
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CSConFTPplugin::NotifyShutdown()
       
   128     {
       
   129     TRACE_FUNC;
       
   130     iShutdownInProgress = ETrue;
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CSConFTPplugin::LoadFTPDllL()
       
   135 // Loads sconftp.dll module
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CSConFTPplugin::LoadFTPDllL()
       
   139     {
       
   140     TRACE_FUNC_ENTRY;
       
   141     // Dynamically load DLL
       
   142     User::LeaveIfError( iFTPlib.Load( KSConFTPLibName ) );
       
   143     if ( iFTPlib.Type()[1] != KSConFTPUid )
       
   144         {
       
   145         LOGGER_WRITE( "KSConFTPUidValue incorrect" );
       
   146         iFTPlib.Close();
       
   147         User::Leave( KErrNotFound );
       
   148         }
       
   149     TSConCreateCSConFTPFunc CreateCSConFTPL =
       
   150     (TSConCreateCSConFTPFunc)iFTPlib.Lookup(1);
       
   151     iFTPHandler = (CSConFTP*)CreateCSConFTPL();
       
   152     TRACE_FUNC_EXIT;
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // CSConFTPplugin::Disconnect()
       
   157 // Closes initialized services
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CSConFTPplugin::Disconnect()
       
   161     {
       
   162     TRACE_FUNC_ENTRY;
       
   163     
       
   164     iLinkAdapter.Close();
       
   165     iSocketServer.Close();
       
   166     
       
   167     if ( iStartTimer != EFalse )
       
   168         {
       
   169         iServiceTimer->Cancel();
       
   170         iServiceTimer->StartTimer();
       
   171         }
       
   172     
       
   173     delete iObject;
       
   174     iObject = NULL;
       
   175     
       
   176     if ( iFileObject )
       
   177         {
       
   178         delete iFileObject;
       
   179         iFileObject = NULL;
       
   180         }
       
   181     if ( iFTPHandler )
       
   182         {
       
   183         delete iFTPHandler;
       
   184         iFTPHandler = NULL;
       
   185         iFTPlib.Close();
       
   186         }
       
   187 
       
   188     TRACE_FUNC_EXIT
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // CSConFTPplugin::ErrorIndication( TInt aError )
       
   193 // MObexServerNotify implementation
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 void CSConFTPplugin::ErrorIndication( TInt aError )
       
   197     {
       
   198     TRACE_FUNC_ENTRY;
       
   199     LOGGER_WRITE_1( "aError : %d", aError );
       
   200     
       
   201     if ( iFTPHandler )
       
   202         {
       
   203         iFTPHandler->AbortFileTransfer( iObject );
       
   204         }
       
   205 
       
   206     if ( iObject )
       
   207         {
       
   208         delete iObject;
       
   209         iObject = NULL;
       
   210         }
       
   211     
       
   212     if ( iFileObject )
       
   213         {
       
   214         iFileObject->Reset();
       
   215         delete iFileObject;
       
   216         iFileObject = NULL;
       
   217         }
       
   218 
       
   219     // Keep compiler happy
       
   220     (void)aError;
       
   221     
       
   222     delete iShutdownWatcher;
       
   223     iShutdownWatcher = NULL;
       
   224     
       
   225 	if ( iLinkAdapter.IsOpen() )
       
   226         {
       
   227         // Cancel ActivateActiveRequester & allow going to low power mode
       
   228         TInt err2 = iLinkAdapter.CancelLowPowerModeRequester();
       
   229         LOGGER_WRITE_1( "iLinkAdapter.CancelLowPowerModeRequester() err: %d", err2 );
       
   230         }
       
   231     
       
   232     TRACE_FUNC_EXIT;
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CSConFTPplugin::AbortIndication()
       
   237 // MObexServerNotify implementation
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 void CSConFTPplugin::AbortIndication()
       
   241     {
       
   242     TRACE_FUNC_ENTRY;
       
   243     if ( iFTPHandler )
       
   244         {
       
   245         iFTPHandler->AbortFileTransfer( iObject );
       
   246         }
       
   247 
       
   248     if ( iObject )
       
   249         {
       
   250         delete iObject;
       
   251         iObject = NULL;
       
   252         }
       
   253     
       
   254     if ( iFileObject )
       
   255         {
       
   256         iFileObject->Reset();
       
   257         delete iFileObject;
       
   258         iFileObject = NULL;
       
   259         }
       
   260     
       
   261     delete iShutdownWatcher;
       
   262     iShutdownWatcher = NULL;
       
   263     
       
   264     if ( iLinkAdapter.IsOpen() )
       
   265         {
       
   266         // Cancel ActivateActiveRequester & allow going to low power mode
       
   267         TInt err = iLinkAdapter.CancelLowPowerModeRequester();
       
   268         LOGGER_WRITE_1( "iLinkAdapter.CancelLowPowerModeRequester() err: %d", err );
       
   269         }
       
   270     
       
   271     TRACE_FUNC_EXIT;
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CSConFTPplugin::TransportUpIndication()
       
   276 // MObexServerNotify implementation
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 void CSConFTPplugin::TransportUpIndication()
       
   280     {
       
   281     TRACE_FUNC;
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CSConFTPplugin::ObexConnectIndication( const TObexConnectInfo& aRemoteInfo,
       
   286 // const TDesC8& aInfo )
       
   287 // MObexServerNotify implementation
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 TInt CSConFTPplugin::ObexConnectIndication(
       
   291                         const TObexConnectInfo& /*aRemoteInfo*/,
       
   292                         const TDesC8& /*aInfo*/ )
       
   293     {
       
   294     TRACE_FUNC_ENTRY;
       
   295     TInt err( KErrNone );
       
   296     iStartTimer = ETrue;
       
   297     
       
   298     if ( iMediaType == ESrcsMediaBT && iObexServer )
       
   299         {
       
   300         TSockAddr remoteAddr;
       
   301         iObexServer->RemoteAddr( remoteAddr );
       
   302         
       
   303         TBTSockAddr btSockAddr( remoteAddr );
       
   304         TBTDevAddr devAddr = btSockAddr.BTAddr();
       
   305         
       
   306         err = iSocketServer.Connect();
       
   307         LOGGER_WRITE_1("iSocketServer.Connect err: %d", err );
       
   308         if ( !err )
       
   309             {
       
   310             err = iLinkAdapter.Open( iSocketServer, devAddr );
       
   311             LOGGER_WRITE_1("iLinkAdapter.Open err: %d", err );
       
   312             }
       
   313         // Ignore all BT link errors
       
   314         err = KErrNone;
       
   315         }
       
   316     
       
   317     if ( err == KErrNone && !iFTPHandler )
       
   318         {
       
   319         TRAP( err, LoadFTPDllL() );
       
   320         LOGGER_WRITE_1( "LoadFTPDllL returned : %d", err );
       
   321         }
       
   322     
       
   323     if ( err == KErrNone )
       
   324         {
       
   325         iFTPHandler->SetProfile( EStandard );
       
   326         LOGGER_WRITE( "CSConFTPplugin::ObexConnectIndication() : iServiceTimer->StopTimer()" );
       
   327         iServiceTimer->Cancel();
       
   328         iServiceTimer->StopTimer();
       
   329         }
       
   330 
       
   331     TRACE_FUNC_EXIT;
       
   332     LOGGER_WRITE_1( "CSConFTPplugin::ObexConnectIndication returned %d", err );
       
   333     return TFTPpluginUtils::ConvertFTPResponseCode( err );
       
   334     }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CSConFTPplugin::ObexDisconnectIndication( const TDesC8& )
       
   338 // MObexServerNotify implementation
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 void CSConFTPplugin::ObexDisconnectIndication( const TDesC8& )
       
   342     {
       
   343     TRACE_FUNC_ENTRY;
       
   344     Disconnect();
       
   345     TRACE_FUNC_EXIT;
       
   346     }
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CSConFTPplugin::TransportDownIndication()
       
   350 // MObexServerNotify implementation
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 void CSConFTPplugin::TransportDownIndication()
       
   354     {
       
   355     TRACE_FUNC_ENTRY;
       
   356     Disconnect();
       
   357     if ( iBuffer )
       
   358         {
       
   359         iBuffer->Reset();
       
   360         }
       
   361     TRACE_FUNC_EXIT;
       
   362     }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CSConFTPplugin::PutRequestIndication()
       
   366 // MObexServerNotify implementation
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 CObexBufObject* CSConFTPplugin::PutRequestIndication()
       
   370     {
       
   371     TRACE_FUNC_ENTRY;
       
   372     TInt ret( KErrNone );
       
   373     TInt err( KErrNone );
       
   374     iPutError = KErrNone;
       
   375 
       
   376     if ( iBuffer )
       
   377         {
       
   378         iBuffer->Reset();
       
   379         }
       
   380 
       
   381     if ( iObject )
       
   382         {
       
   383         delete iObject;
       
   384         iObject = NULL;
       
   385         }
       
   386 
       
   387     TRAP( err, iObject = CObexBufObject::NewL ( iBuffer ) );
       
   388 
       
   389     if ( err != KErrNone )
       
   390         {
       
   391         return NULL;
       
   392         }
       
   393 
       
   394     if ( !iFTPHandler )
       
   395         {
       
   396         LOGGER_WRITE( "Creating iFTPHandler has failed" );
       
   397         return NULL;
       
   398         }
       
   399 
       
   400     TRAP( err, ret = iFTPHandler->PutFileObjectInitL( iObject, iBuffer ) );
       
   401 
       
   402     if ( err != KErrNone )
       
   403         {
       
   404         LOGGER_WRITE_1( "iFTPHandler->PutFileObjectInitL() leaves: %d", err );
       
   405         return NULL;
       
   406         }
       
   407     if ( ret != KErrNone )
       
   408         {
       
   409         LOGGER_WRITE_1( "PutFileObjectInitL failed - returning error in next PutPacketIndication : %d", ret );
       
   410         iPutError = ret;
       
   411         }
       
   412     iPutPacketIndicationCalled = EFalse;
       
   413     
       
   414     if ( !iShutdownWatcher )
       
   415         {
       
   416         TRAP( err, iShutdownWatcher = CShutdownWatcher::NewL( this ) );
       
   417         if ( err == KErrNone )
       
   418             {
       
   419             iShutdownWatcher->StartShutdownWatcher();
       
   420             }
       
   421         else
       
   422             {
       
   423             LOGGER_WRITE_1( "CShutdownWatcher::NewL leaves: %d", err );
       
   424             }
       
   425         }
       
   426     
       
   427     if ( iLinkAdapter.IsOpen() )
       
   428         {
       
   429         // request active BT mode (high power mode)
       
   430         err = iLinkAdapter.ActivateActiveRequester();
       
   431         LOGGER_WRITE_1( "iLinkAdapter.ActivateActiveRequester() err: %d", err );
       
   432         }
       
   433     
       
   434     TRACE_FUNC_EXIT;
       
   435     return( iObject );
       
   436     }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CSConFTPplugin::PutPacketIndication()
       
   440 // MObexServerNotify implementation
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 TInt CSConFTPplugin::PutPacketIndication()
       
   444     {
       
   445     TRACE_FUNC_ENTRY;
       
   446     TInt ret( KErrNone );
       
   447     
       
   448     // always normal file transfer
       
   449     if ( (TInt)iObject->Length() > 0 )
       
   450         {
       
   451         if ( !iPutPacketIndicationCalled )
       
   452             {
       
   453             // This is first check, need to check only once
       
   454             TFileName path;
       
   455             iFTPHandler->GetPath( path );
       
   456             if ( path.CompareF( K_C_ROOT ) == 0 )
       
   457                 {
       
   458                 // path forbidden
       
   459                 ret = KErrAccessDenied;
       
   460                 }
       
   461             else
       
   462                 {
       
   463                 if ( iPutError != KErrNone )
       
   464                     {
       
   465                     ret = iPutError;
       
   466                     LOGGER_WRITE_1( "CSConFTPplugin::PutPacketIndication() : PutError : %d", iPutError );
       
   467                     }
       
   468                 else
       
   469                     {
       
   470                     // check required free space
       
   471                     // if filesize is small ( <65k ) it fits into one package and its already saved to filesystem.
       
   472                     // if file is larger, need to check is there enought free space in device.
       
   473                     
       
   474                     const TUint32  filesize = iObject->Length();
       
   475                     LOGGER_WRITE_1( "CSConFTPplugin::PutPacketIndication() filesize %d", filesize );
       
   476                     LOGGER_WRITE_1( "CSConFTPplugin::PutPacketIndication() iObject->BytesReceived() %d", iObject->BytesReceived() );
       
   477                     if ( filesize > iObject->BytesReceived() )
       
   478                         {
       
   479                         LOGGER_WRITE( "CSConFTPplugin::PutPacketIndication() : check freespace" );
       
   480                         // file does not fit into one obex packet, check is there enought free space in current drive
       
   481                         if ( iFTPHandler->IsCurrentDiskSpaceBelowCritical( filesize ) )
       
   482                             {
       
   483     	                    LOGGER_WRITE( "CSConFTPplugin::PutPacketIndication() : returning KErrNoMemory" );
       
   484                             ret = KErrNoMemory;
       
   485                             }
       
   486                         }
       
   487                     }
       
   488                 }
       
   489             }
       
   490         
       
   491         if ( iShutdownInProgress )
       
   492             {
       
   493             LOGGER_WRITE( "ShutdownInProgress, abort" );
       
   494             ret = KErrDisconnected;
       
   495             }
       
   496         }
       
   497     
       
   498     if ( !iPutPacketIndicationCalled )
       
   499         {
       
   500         // Need to check only once
       
   501         iPutPacketIndicationCalled = ETrue;
       
   502         
       
   503         //Check if filename is too long.
       
   504         TFileName path;
       
   505         iFTPHandler->GetPath( path );
       
   506         if ( ret == KErrNone && path.Length() + iObject->Name().Length() > KMaxFileName )
       
   507             {
       
   508             LOGGER_WRITE_1( "Name length overflow! : %d", path.Length() + iObject->Name().Length() );
       
   509             ret = KErrBadName;
       
   510             }
       
   511         }
       
   512     
       
   513     if ( ret != KErrNone )
       
   514         {
       
   515         if ( iFTPHandler )
       
   516             {
       
   517             iFTPHandler->AbortFileTransfer( iObject );
       
   518             }
       
   519         
       
   520         delete iObject;
       
   521         iObject = NULL;
       
   522         
       
   523         if ( iLinkAdapter.IsOpen() )
       
   524             {
       
   525             // Cancel ActivateActiveRequester & allow going to low power mode
       
   526             TInt err = iLinkAdapter.CancelLowPowerModeRequester();
       
   527             LOGGER_WRITE_1( "iLinkAdapter.CancelLowPowerModeRequester() err: %d", err );
       
   528             }
       
   529         }
       
   530     
       
   531     LOGGER_WRITE_1( "CSConFTPplugin::PutPacketIndication returned: %d", ret );
       
   532     return TFTPpluginUtils::ConvertFTPResponseCode( ret );
       
   533     }
       
   534 
       
   535 // -----------------------------------------------------------------------------
       
   536 // CSConFTPplugin::PutCompleteIndication()
       
   537 // MObexServerNotify implementation
       
   538 // -----------------------------------------------------------------------------
       
   539 //
       
   540 TInt CSConFTPplugin::PutCompleteIndication()
       
   541     {
       
   542     TRACE_FUNC_ENTRY;
       
   543     TInt ret( KErrNone );
       
   544     TInt err( KErrNone );
       
   545     
       
   546     if ( iLinkAdapter.IsOpen() )
       
   547         {
       
   548         // Cancel ActivateActiveRequester & allow going to low power mode
       
   549         TInt err2 = iLinkAdapter.CancelLowPowerModeRequester();
       
   550         LOGGER_WRITE_1( "iLinkAdapter.CancelLowPowerModeRequester() err: %d", err2 );
       
   551         }
       
   552     
       
   553     TObexHeaderMask validHdrs = iObject->ValidHeaders();
       
   554     TTime time = iObject->Time();
       
   555     
       
   556     // shutdownWatcher is not needed anymore
       
   557     delete iShutdownWatcher;
       
   558     iShutdownWatcher = NULL;
       
   559 
       
   560     TInt size = iObject->BytesReceived();
       
   561 
       
   562     if (!(validHdrs & KObexHdrTime))
       
   563         {
       
   564         LOGGER_WRITE( "CSConFTPplugin::PutCompleteIndication() no valid time header received - using hometime" );
       
   565         time.HomeTime();
       
   566         TRAP( ret, iObject->SetTimeL(time) );
       
   567         LOGGER_WRITE_1( "CSConFTPplugin::PutCompleteIndication SetTimeL  %d", ret );
       
   568         }
       
   569 
       
   570     if ( ( validHdrs & KObexHdrBody ) || ( validHdrs & KObexHdrEndOfBody ) )
       
   571         {
       
   572         LOGGER_WRITE_1( "CSConFTPplugin::PutCompleteIndication : number of received bytes  %d", size );
       
   573         TSConUsedMedia media( ESConNoMedia );
       
   574 
       
   575         switch ( iMediaType )
       
   576             {
       
   577             case ESrcsMediaBT:
       
   578                 media = ESConBTMedia;
       
   579                 break;
       
   580             case ESrcsMediaIrDA:
       
   581                 media = ESConIRMedia;
       
   582                 break;
       
   583             case ESrcsMediaUSB:
       
   584                 media = ESConUSBMedia;
       
   585                 break;
       
   586             default:
       
   587                 media = ESConNoMedia;
       
   588                 break;
       
   589             }
       
   590         iFTPHandler->SetUsedMedia( media );
       
   591         
       
   592         TRAP( ret, err =
       
   593         this->iFTPHandler->PutFileObjectFinalizeL( iObject ) );
       
   594         LOGGER_WRITE_1( "CSConFTPplugin::PutCompleteIndication :PutFileObjectL  %d", ret );
       
   595         }
       
   596     else
       
   597         {
       
   598         LOGGER_WRITE( "CSConFTPplugin::PutCompleteIndication() : Delete  starts" );
       
   599         TRAP( ret, err = this->iFTPHandler->DeleteObjectL( iObject->Name() ) );
       
   600         LOGGER_WRITE_1( "CSConFTPplugin::PutCompleteIndication : DeleteObjectL  %d", ret );
       
   601         }
       
   602 
       
   603     if ( iObject )
       
   604         {
       
   605         delete iObject;
       
   606         iObject = NULL;
       
   607         }
       
   608 
       
   609     iFTPHandler->DeleteTempFile();
       
   610 
       
   611     if ( ret != KErrNone )
       
   612         {
       
   613         LOGGER_WRITE_1( "CSConFTPplugin::PutCompleteIndication : returned  %d", ret );
       
   614         return TFTPpluginUtils::ConvertFTPResponseCode( ret );
       
   615         }
       
   616 
       
   617     LOGGER_WRITE_1( "CSConFTPplugin::PutCompleteIndication : returned  %d", err );
       
   618     return TFTPpluginUtils::ConvertFTPResponseCode( err );
       
   619     }
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // CSConFTPplugin::GetRequestIndication( CObexBaseObject* aRequiredObject )
       
   623 // MObexServerNotify implementation
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 CObexBufObject* CSConFTPplugin::GetRequestIndication(
       
   627                                             CObexBaseObject* aRequiredObject )
       
   628     {
       
   629     TRACE_FUNC_ENTRY;
       
   630     CObexBufObject* bufObject(NULL);
       
   631     if ( aRequiredObject->Type().Length() > KSConHeaderMaxLength )
       
   632         {
       
   633         LOGGER_WRITE("TypeHeader too big");
       
   634         return NULL;
       
   635         }
       
   636     if ( aRequiredObject->Name().Length() > KMaxFileName )
       
   637         {
       
   638         LOGGER_WRITE("NameHeader is too long");
       
   639         return NULL;
       
   640         }
       
   641     TInt ret( KErrNone );
       
   642     TInt err( KErrNone );
       
   643     TBuf8<KSConHeaderMaxLength> typeHeader( aRequiredObject->Type() );
       
   644     TrimRightSpaceAndNull( typeHeader );
       
   645     LOGGER_WRITE8_1("type: %S", &typeHeader);
       
   646     LOGGER_WRITE_1("name: %S", &aRequiredObject->Name());
       
   647 
       
   648     iBuffer->Reset();
       
   649     
       
   650     delete iObject;
       
   651     iObject = NULL;
       
   652     
       
   653     TRAP( err, iObject = CObexBufObject::NewL ( iBuffer ) );
       
   654     if ( err != KErrNone )
       
   655         {
       
   656         return NULL;
       
   657         }
       
   658     
       
   659     // Client requests folder listing
       
   660     if ( typeHeader == KSConFolderListType )
       
   661         {
       
   662         LOGGER_WRITE( "Client requests folder listning" );
       
   663         if ( !iFTPHandler )
       
   664             {
       
   665             LOGGER_WRITE( "Creating iFTPHandler has failed" );
       
   666             return NULL;
       
   667             }
       
   668 
       
   669         TRAP( err, ret = iFTPHandler->GetFolderObjectL( iObject ) );
       
   670         LOGGER_WRITE_1( "iFTPHandler->GetFolderObjectL() returned: %d", ret );
       
   671         if ( err == KErrNone && ret == KErrNone )
       
   672             {
       
   673             bufObject = iObject;
       
   674             }
       
   675         else
       
   676             {
       
   677             LOGGER_WRITE_1( "CSConFTPplugin::GetRequestIndication : Leavecode returned  %d", err );
       
   678             return NULL;
       
   679             }
       
   680         }
       
   681 
       
   682     // Client requests a file
       
   683     else
       
   684         {
       
   685         if ( iFileObject )
       
   686             {
       
   687             delete iFileObject;
       
   688             iFileObject = NULL;
       
   689             }
       
   690         
       
   691         TRAP( err, iFileObject = CObexFileObject::NewL() );
       
   692         if ( err != KErrNone )
       
   693             {
       
   694             LOGGER_WRITE( "Creating iFileObject has failed" );
       
   695             return NULL;
       
   696             }
       
   697         iFileObject->Reset();
       
   698         TRAP( err, iFileObject->SetNameL( aRequiredObject->Name() ) );
       
   699 
       
   700         if ( err == KErrNone )
       
   701             {
       
   702             if ( !iFTPHandler )
       
   703                 {
       
   704                 LOGGER_WRITE( "CSConFTPplugin::GetRequestIndication() Creating iFTPHandler has failed" );
       
   705                 return NULL;
       
   706                 }
       
   707 
       
   708             TRAP( err, ret =
       
   709             this->iFTPHandler->GetFileObjectL( iFileObject ) );
       
   710             LOGGER_WRITE_1( "CSConFTPplugin::GetRequestIndication :  GetFileObjectL returned  %d", ret );
       
   711             }
       
   712         if ( err == KErrNone && ret == KErrNone )
       
   713             {
       
   714             bufObject = (CObexBufObject*)iFileObject;
       
   715             }
       
   716         else
       
   717             {
       
   718             LOGGER_WRITE_1( "CSConFTPplugin::GetRequestIndication : Leavecode   %d", err );
       
   719             return NULL;
       
   720             }
       
   721         }
       
   722     if ( bufObject && iLinkAdapter.IsOpen() )
       
   723         {
       
   724         // request active BT mode (high power mode)
       
   725         err = iLinkAdapter.ActivateActiveRequester();
       
   726         LOGGER_WRITE_1( "iLinkAdapter.ActivateActiveRequester() err: %d", err );
       
   727         }
       
   728     return bufObject;
       
   729     }
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // CSConFTPplugin::GetPacketIndication()
       
   733 // MObexServerNotify implementation
       
   734 // -----------------------------------------------------------------------------
       
   735 //
       
   736 TInt CSConFTPplugin::GetPacketIndication()
       
   737     {
       
   738     TRACE_FUNC;
       
   739     return KErrNone;
       
   740     }
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // CSConFTPplugin::GetCompleteIndication()
       
   744 // MObexServerNotify implementation
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 TInt CSConFTPplugin::GetCompleteIndication()
       
   748     {
       
   749     TRACE_FUNC_ENTRY;
       
   750     if ( iLinkAdapter.IsOpen() )
       
   751         {
       
   752         // Cancel ActivateActiveRequester & allow going to low power mode
       
   753         TInt err = iLinkAdapter.CancelLowPowerModeRequester();
       
   754         LOGGER_WRITE_1( "iLinkAdapter.CancelLowPowerModeRequester() err: %d", err );
       
   755         }
       
   756     
       
   757     TInt ret( KErrNone );
       
   758     if ( iFileObject )
       
   759         {
       
   760         iFileObject->Reset();
       
   761         delete iFileObject;
       
   762         iFileObject = NULL;
       
   763         }
       
   764 
       
   765     LOGGER_WRITE_1( "CSConFTPplugin::GetCompleteIndication() : returned %d", ret );
       
   766     return ret;
       
   767     }
       
   768 
       
   769 // -----------------------------------------------------------------------------
       
   770 // CSConFTPplugin::SetPathIndication( const CObex::TSetPathInfo& aPathInfo,
       
   771 // const TDesC8& aInfo )
       
   772 // MObexServerNotify implementation
       
   773 // -----------------------------------------------------------------------------
       
   774 //
       
   775 TInt CSConFTPplugin::SetPathIndication( const CObex::TSetPathInfo& aPathInfo,
       
   776                                         const TDesC8& /*aInfo*/ )
       
   777     {
       
   778     TRACE_FUNC_ENTRY;
       
   779     TInt ret( KErrNone );
       
   780     TInt err( KErrNone );
       
   781 
       
   782     if ( !iFTPHandler )
       
   783         {
       
   784         LOGGER_WRITE( "Creating iFTPHandler has failed" );
       
   785         return TFTPpluginUtils::ConvertFTPResponseCode( KErrNoMemory );
       
   786         }
       
   787 
       
   788     if ( aPathInfo.iFlags == KSConNULLSetPath )
       
   789         {
       
   790         TRAP( err, ret = this->iFTPHandler->CreateFolderL( aPathInfo.iName ) );
       
   791         }
       
   792     else
       
   793         {
       
   794         TRAP( err, ret = this->iFTPHandler->SetPathL( aPathInfo.iName,
       
   795         aPathInfo.iFlags ) );
       
   796         }
       
   797     
       
   798     if ( err != KErrNone )
       
   799         {
       
   800         LOGGER_WRITE_1( "CSConFTPplugin::SetPathIndication : returned   %d", err );
       
   801         return TFTPpluginUtils::ConvertFTPResponseCode( err );
       
   802         }
       
   803     LOGGER_WRITE_1( "CSConFTPplugin::SetPathIndication : returned %d", ret );
       
   804     return TFTPpluginUtils::ConvertFTPResponseCode( ret );
       
   805     }
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // CSConFTPplugin::TrimRightSpaceAndNull( TDes8& aDes ) const
       
   809 // Removes spaces and nulls from the end of the string
       
   810 // -----------------------------------------------------------------------------
       
   811 //
       
   812 void CSConFTPplugin::TrimRightSpaceAndNull( TDes8& aDes ) const
       
   813     {
       
   814     TRACE_FUNC;
       
   815     aDes.TrimRight();
       
   816     if ( aDes.Length() > 0 )
       
   817         {
       
   818         if ( !aDes[aDes.Length() - 1] )
       
   819             {
       
   820             aDes.SetLength( aDes.Length() - 1 );
       
   821             }
       
   822         }
       
   823     }
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CSConFTPplugin::SetMediaType ( TSrcsMediaType aMediaType )
       
   827 // Current used transfer media (IR,USB,BT)
       
   828 // -----------------------------------------------------------------------------
       
   829 //
       
   830 void CSConFTPplugin::SetMediaType ( TSrcsMediaType aMediaType )
       
   831     {
       
   832     TRACE_FUNC;
       
   833     iMediaType = aMediaType;
       
   834     }
       
   835 
       
   836 // -----------------------------------------------------------------------------
       
   837 // CSConFTPplugin::CSConFTPplugin()
       
   838 // Constructor
       
   839 // -----------------------------------------------------------------------------
       
   840 //
       
   841 CSConFTPplugin::CSConFTPplugin()
       
   842     {
       
   843     TRACE_FUNC;
       
   844     iBuffer = NULL;
       
   845     iObject = NULL;
       
   846     iFileObject = NULL;
       
   847     iSessionActive = EFalse;
       
   848     }
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // CSConFTPplugin::ConstructL()
       
   852 // Initializes member data
       
   853 // -----------------------------------------------------------------------------
       
   854 //
       
   855 void CSConFTPplugin::ConstructL()
       
   856     {
       
   857     TRACE_FUNC_ENTRY;
       
   858     iBuffer = CBufFlat::NewL( KSConBufSize );
       
   859     iObject = CObexBufObject::NewL ( iBuffer );
       
   860     iServiceTimer = new (ELeave) CSConServiceTimer( this, KSConTimeOutValue );
       
   861     iServiceTimer->ConstructL();
       
   862     CActiveScheduler::Add( iServiceTimer );
       
   863     TRACE_FUNC_EXIT;
       
   864     }
       
   865 
       
   866 // -----------------------------------------------------------------------------
       
   867 // CSConFTPplugin::SetObexServer( CObexServer* aObexServer )
       
   868 // SetObexServer
       
   869 // -----------------------------------------------------------------------------
       
   870 //
       
   871 TInt CSConFTPplugin::SetObexServer( CObexServer* aObexServer )
       
   872     {
       
   873     iObexServer = aObexServer;
       
   874     TInt ret = iObexServer->Start(this);
       
   875     LOGGER_WRITE_1( "CSConFTPplugin::SetObexServer() ret: %d", ret );
       
   876     return ret;
       
   877     }
       
   878 
       
   879 // End of file
       
   880