webservices/wshttpchanneltransportplugin/src/senrfiletxnstate.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <http.h>
       
    23 #include "senrfiletxnstate.h"
       
    24 #include "senhttpchannel.h"
       
    25 #include "sendebug.h"
       
    26 #include "senlogger.h"
       
    27 #include "senasynctimeout.h"
       
    28 
       
    29 
       
    30 // MACROS
       
    31 const TInt KDataPartLength = 1024;
       
    32 // =========================== MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // CSenRfileTxnState::CSenRfileTxnState
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // ----------------------------------------------------------------------------
       
    39 //
       
    40 
       
    41 CSenRfileTxnState::CSenRfileTxnState(MSenResponseObserver& aObserver)//,
       
    42                            //RFileLogger* aLog)
       
    43     : CSenTxnState (aObserver/*, iLog(aLog)*/)
       
    44     {
       
    45     }
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // CSenRfileTxnState::NewLC
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 
       
    52 CSenRfileTxnState* CSenRfileTxnState::NewLC(MSenResponseObserver& aObserver,
       
    53                                   //RFileLogger* aLog,
       
    54                                   const TDesC8* aUri,
       
    55                                   CSenHttpChannelImpl* aHttpClient,
       
    56                                   const TDesC8& aContentType,
       
    57                                   const RFile& aContent)
       
    58     {
       
    59     CSenRfileTxnState* pNew = new (ELeave) CSenRfileTxnState(aObserver);//, aLog);
       
    60     CleanupStack::PushL(pNew);
       
    61     pNew->ConstructL(aUri, aHttpClient,aContentType, aContent);
       
    62     return pNew;
       
    63     }
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 // CSenRfileTxnState::NewL
       
    67 // ----------------------------------------------------------------------------
       
    68 //
       
    69 
       
    70 CSenRfileTxnState* CSenRfileTxnState::NewL(MSenResponseObserver& aObserver,
       
    71                                  //RFileLogger* aLog,
       
    72                                  const TDesC8* aUri,
       
    73                                  CSenHttpChannelImpl* aHttpClient,
       
    74                                  const TDesC8& aContentType,
       
    75                                  const RFile& aContent)
       
    76     {
       
    77     CSenRfileTxnState* pNew = NewLC( aObserver, /*aLog,*/ aUri,
       
    78                                 aHttpClient,aContentType, aContent );
       
    79     CleanupStack::Pop(pNew);
       
    80     return pNew;
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CSenRfileTxnState::ConstructL
       
    85 // ----------------------------------------------------------------------------
       
    86 //
       
    87 
       
    88 void CSenRfileTxnState::ConstructL(const TDesC8* aUri,
       
    89                               CSenHttpChannelImpl* aHttpClient,
       
    90                               const TDesC8& aContentType,
       
    91                               const RFile& aContent)
       
    92     {
       
    93     __ASSERT_ALWAYS(aUri != NULL,
       
    94                     User::Panic(KRequestUriNullPanicText,
       
    95                                 CSenHttpChannel::ERequestUriNull));
       
    96     iRequestUri = aUri->AllocL();
       
    97     iFile = aContent;
       
    98     iHttpClient = aHttpClient ;
       
    99     iSize = 0 ;
       
   100     TInt err = iFile.Size(iSize) ;
       
   101     if(iSize >0)
       
   102         {
       
   103             iHasRequestBody = ETrue;
       
   104             iPostContentType = aContentType.AllocL();
       
   105         }    
       
   106     }
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // CSenRfileTxnState::~CSenRfileTxnState
       
   110 // ----------------------------------------------------------------------------
       
   111 //
       
   112 CSenRfileTxnState::~CSenRfileTxnState()
       
   113     {
       
   114     iFile.Close();
       
   115     }
       
   116 
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // CSenRfileTxnState::GetNextDataPart
       
   120 // Implementation of the pure virtual method from MHTTPDataSupplier
       
   121 // ----------------------------------------------------------------------------
       
   122 //
       
   123 TBool CSenRfileTxnState::GetNextDataPart(TPtrC8& aDataPart)
       
   124     {
       
   125     TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("CSenRfileTxnState::GetNextDataPart")));
       
   126     TBool noMoreData = ETrue;   // No more data
       
   127     
       
   128     if ( iFile.SubSessionHandle() )    // Send in a chunked mode from file
       
   129         {        
       
   130         if ( !iReadData )
       
   131             {
       
   132             TRAPD(retVal,
       
   133 		            iReadData = HBufC8::NewL( KDataPartLength );  
       
   134 		            TPtr8 ptr = iReadData->Des();
       
   135 		            User::LeaveIfError( iFile.Read( ptr, KDataPartLength ) );
       
   136             		);
       
   137             
       
   138             // More content remains if buffer is full
       
   139             // If buffer is not full (!EOF) => no more data
       
   140             if (iReadData->Length() == KDataPartLength)
       
   141 	            {
       
   142 	            iMoreContent = ETrue ;	
       
   143 	            }
       
   144 	            else
       
   145 	            {
       
   146 	            iMoreContent = EFalse ;
       
   147 	            }
       
   148             }
       
   149         
       
   150         // Check if more content to be send (false = more data)  
       
   151         noMoreData = !MoreBody();        
       
   152         }
       
   153     
       
   154     aDataPart.Set( *iReadData );
       
   155     return noMoreData;
       
   156     }
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // CSenRfileTxnState::ReleaseData
       
   160 // Implementation of the pure virtual method from MHTTPDataSupplier
       
   161 // ----------------------------------------------------------------------------
       
   162 //
       
   163 void CSenRfileTxnState::ReleaseData()
       
   164     {
       
   165     TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("CSenRfileTxnState::ReleaseData")));
       
   166     if ( MoreBody() )    // More data
       
   167         {
       
   168         TRAP_IGNORE( iHttpClient->NotifyMoreBodyL() );
       
   169         }
       
   170     
       
   171     delete iReadData;
       
   172     iReadData = NULL;   
       
   173     }
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CSenRfileTxnState::OverallDataSize
       
   177 // Implementation of the pure virtual method from MHTTPDataSupplier
       
   178 // ----------------------------------------------------------------------------
       
   179 //
       
   180 TInt CSenRfileTxnState::OverallDataSize()
       
   181     {
       
   182 	// File is uploaded in chunked mode.
       
   183     TLSLOG_FORMAT((KSenHttpChannelLogChannelBase , KNormalLogLevel, _L8("CSenRfileTxnState::OverallDataSize() [%d]"), iSize));	
       
   184 	    if(iFile.SubSessionHandle())
       
   185 		    {
       
   186 		    return iSize;	
       
   187 		    }
       
   188 	    else
       
   189 			{
       
   190 			return KErrNotFound;	
       
   191 			}
       
   192     }
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // CSenRfileTxnState::Reset
       
   196 // Implementation of the pure virtual method from MHTTPDataSupplier
       
   197 // ----------------------------------------------------------------------------
       
   198 //
       
   199 TInt CSenRfileTxnState::Reset()
       
   200     {
       
   201     TLSLOG(KSenHttpChannelLogChannelBase , KMinLogLevel,(_L("CSenRfileTxnState::Reset")));
       
   202     if ( iFile.SubSessionHandle() )
       
   203         {
       
   204         TInt pos;
       
   205         return iFile.Seek( ESeekStart, pos );   // Go to
       
   206         }
       
   207     
       
   208     return KErrNone;     // KErrNone if reset succeeded
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // Return flag if more body exist to be send in chunked mode.
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 TBool CSenRfileTxnState::MoreBody() const
       
   216     {
       
   217     // File == chunked mode
       
   218     return ( iFile.SubSessionHandle() && iMoreContent );
       
   219     }
       
   220 //  End of File