webservices/wshttpchanneltransportplugin/inc/sentxnstate.h
changeset 0 62f9d29f7211
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:    Header declaration
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 #ifndef WSF_TXN_STATE_H
       
    29 #define WSF_TXN_STATE_H
       
    30 
       
    31 //  INCLUDES
       
    32 #include <e32base.h>
       
    33 #include <http/mhttpdatasupplier.h>
       
    34 #include <flogger.h>
       
    35 #include "senresponseobserver.h"
       
    36 #include "senmultipartutils.h"
       
    37 
       
    38 // CONSTANTS
       
    39 namespace
       
    40     {
       
    41     // Panic texts
       
    42     _LIT(KRequestUriNullPanicText,   "Req URI is NULL");
       
    43     _LIT(KPostContTypeNullPanicText, "PostCntType NULL");
       
    44     _LIT8(KDownloadFolder, "SenBlobResponses"); // folder where should be created Blobs from Response
       
    45     }
       
    46 
       
    47 // FORWARD DECLARATIONS
       
    48 class CSenAsyncTimeOut;
       
    49 // CLASS DECLARATION
       
    50 /**
       
    51  * Class for handling the transaction state in the http client class.
       
    52  * Implements the MHTTPDataSupplier interface.
       
    53  *
       
    54  */
       
    55 class CSenTxnState : public CBase,
       
    56                      public MHTTPDataSupplier
       
    57     {
       
    58 public:  // Constructors and destructor
       
    59 
       
    60     /**
       
    61      * Two-phased constructor.
       
    62      *
       
    63      */
       
    64     static CSenTxnState* NewLC(MSenResponseObserver& aObserver,
       
    65                                //RFileLogger* aLog,
       
    66                                const TDesC8* aUri,
       
    67                                const TDesC8& aContentType,
       
    68                                const TDesC8* aBody = NULL);
       
    69 
       
    70     /**
       
    71      * Two-phased constructor.
       
    72      *
       
    73      */
       
    74     static CSenTxnState* NewL(MSenResponseObserver& aObserver,
       
    75                               //RFileLogger* aLog,
       
    76                               const TDesC8* aUri,
       
    77                               const TDesC8& aContentType,
       
    78                               const TDesC8* aBody = NULL);
       
    79 
       
    80     /**
       
    81      * Virtual destructor.
       
    82      *
       
    83      */
       
    84     virtual ~CSenTxnState();
       
    85 
       
    86         // New functions
       
    87 
       
    88     /**
       
    89      * Transaction state's identifier.
       
    90      * @return Id of the transaction handled in this transaction state object.
       
    91      */
       
    92     TInt Id() const;
       
    93     
       
    94     RHTTPTransaction Transaction() const;
       
    95 
       
    96     /**
       
    97      * Set transaction state's identifier.
       
    98      */
       
    99     void SetId(TInt aId);
       
   100     void SetTransaction(RHTTPTransaction aTransaction);
       
   101 
       
   102     /**
       
   103      * Collects incoming response's body.
       
   104      * @param aDataPart data chunk from response body's GetNextDataPart
       
   105      */
       
   106     void CollectResponseBodyL(const TDesC8& aDataPart);
       
   107 
       
   108     /**
       
   109      * @return URI for the message to be posted.
       
   110      */
       
   111     const TDesC8& RequestUri() const;
       
   112 
       
   113     /**
       
   114      * @return content type for the message to be posted.
       
   115      */
       
   116     const TDesC8& PostContentType() const;
       
   117 
       
   118     inline TBool HasRequestBody() { return iHasRequestBody; }
       
   119     void ResponseReceivedL(const TDesC8& aContentType);
       
   120     void ResponseErrorL(TInt aError);
       
   121 	void StateChanged(TInt aState); // In order to propagate http status codes
       
   122 
       
   123     TInt Cancel();
       
   124 
       
   125     /**
       
   126     * This transformation method appends the current
       
   127     * contents of body (if not NULL) into a tailing
       
   128     * postfix of current Uri. Method is typically 
       
   129     * called prior sending a GET transaction. Method
       
   130     * appends the "body" string (GET query string, 
       
   131     * DELETE argument) into the base URI, as it is.
       
   132     * The responsibility of the correctness for this
       
   133     * newly formed URI is on the caller SendL/SubmitL,
       
   134     * who might also has set the transport properties, too.
       
   135     * Since method temporarily allocates memory in order
       
   136     * to make a copy of the body, it may leave if system
       
   137     * runs out of heap.
       
   138     *
       
   139     * Note: this method deletes the current body owned
       
   140     * by this class instance, and sets iHasRequestBody
       
   141     * to EFalse.
       
   142     */
       
   143     void TransformBodyToUriL();
       
   144 
       
   145     /**
       
   146     * Returns the body (content) of this transaction
       
   147     */
       
   148     TPtrC8 Body();
       
   149     
       
   150     /**
       
   151     * Sets Content-Type in HTTP header
       
   152     * @param aSession
       
   153     * @param aHeaders
       
   154     */
       
   155     virtual void SetContentTypeHeaderL(const RHTTPSession aSession, RHTTPHeaders aHeaders);
       
   156 
       
   157     // Functions from base classes
       
   158 
       
   159     /**
       
   160      * From MHTTPDataSupplier::GetNextDataPart.
       
   161      * Obtain a data part from the supplier.  The data is guaranteed
       
   162      * to survive until a call is made to ReleaseData().
       
   163      * @param aDataPart The data part.
       
   164      * @return ETrue if this is the last part, EFalse otherwise.
       
   165      */
       
   166     virtual TBool GetNextDataPart(TPtrC8& aDataPart);
       
   167 
       
   168     /**
       
   169      * From MHTTPDataSupplier::ReleaseData.
       
   170      * Release the current data part being held at the data
       
   171      * supplier.  This call indicates to the supplier that the part
       
   172      * is no longer needed, and another one can be supplied, if
       
   173      * appropriate.
       
   174      */
       
   175     virtual void ReleaseData();
       
   176 
       
   177     /**
       
   178      * From MHTTPDataSupplier::OverallDataSize.
       
   179      * Obtain the overall size of the data being supplied, if known
       
   180      * to the supplier.  Where a body of data is supplied in several
       
   181      * parts this size will be the sum of all the part sizes. If
       
   182      * the size is not known, KErrNotFound is returned; in this case
       
   183      * the client must use the return code of GetNextDataPart to find
       
   184      * out when the data is complete.
       
   185      *
       
   186      * @return A size in bytes, or KErrNotFound if the size is not known.
       
   187      */
       
   188     virtual TInt OverallDataSize();
       
   189 
       
   190     /**
       
   191      * From MHTTPDataSupplier::Reset.
       
   192      * Reset the data supplier.  This indicates to the data supplier
       
   193      * that it should return to the first part of the data.
       
   194      * This could be used in a situation where the data consumer has
       
   195      * encountered an error and needs the data to be supplied afresh.
       
   196      * Even if the last part has been supplied (i.e. GetNextDataPart
       
   197      * has returned ETrue), the data supplier should reset to the
       
   198      * first part. If the supplier cannot reset it should return an
       
   199      * error code; otherwise it should return KErrNone, where the
       
   200      * reset will be assumed to have succeeded.
       
   201      *
       
   202      * @return KErrNone if successful, otherwise another error code.
       
   203      */
       
   204     virtual TInt Reset();
       
   205 	void SetSession(RHTTPSession aSession); 	 
       
   206     TInt CalculateHeadersSizeL(RHTTPHeaders aHeaders); 
       
   207 
       
   208     void SetTP(CSenHttpTransportProperties* tp);
       
   209     MSenProperties& HttpChannelPropertiesL();
       
   210     void EnableTimeOutL(TInt aTimeOutSec);
       
   211     void DisableTimeOutL();
       
   212 protected:
       
   213     /**
       
   214      * C++ default constructor.
       
   215      *
       
   216      */
       
   217     CSenTxnState(MSenResponseObserver& aObserver);//,
       
   218                  //RFileLogger* aLog);
       
   219    
       
   220     /**
       
   221      * File logger.
       
   222      *
       
   223      */
       
   224     //RFileLogger* Log() const;
       
   225 
       
   226 private:
       
   227 
       
   228     /**
       
   229      * 2nd phase constructor.
       
   230      *
       
   231      */
       
   232     void ConstructL(const TDesC8* aUri,
       
   233                     const TDesC8& aContentType,
       
   234                     const TDesC8* aBody);
       
   235 
       
   236 protected: // Data
       
   237     /**
       
   238      * Pointer to the requester's observer. Not owned.
       
   239      */
       
   240     MSenResponseObserver* iObserver;
       
   241     /**
       
   242      * Pointer to the logger. Not owned.
       
   243      */
       
   244     //RFileLogger* iLog; // Not owned
       
   245     /**
       
   246      * Request has body.
       
   247      */
       
   248     TBool iHasRequestBody;
       
   249 	
       
   250 	TBool iPostBodyReleased;
       
   251 	/**
       
   252      * URI of the request to be posted.
       
   253      */
       
   254     HBufC8* iRequestUri;
       
   255 
       
   256     RHTTPTransaction ipTransaction; // NOT OWNED
       
   257     /**
       
   258      * Id of the transaction in question.
       
   259      */
       
   260     TInt iId;
       
   261 	/**
       
   262      * Body of the incoming response.
       
   263      */
       
   264     HBufC8* iResponseBody;
       
   265     /**
       
   266      * Body of the request to be posted.
       
   267      */
       
   268     HBufC8* iPostBody;
       
   269     /**
       
   270      * Content type of the request to be posted.
       
   271      */
       
   272     HBufC8* iPostContentType;
       
   273     
       
   274     /**
       
   275      * Pointer to the Session. Not owned.
       
   276      */    
       
   277     RHTTPSession iSession; // Not owned	
       
   278     /**
       
   279      * Contains DataTraffic Details.
       
   280      */    
       
   281     TSenDataTrafficDetails iDetails; 
       
   282     CSenHttpTransportProperties* iTP;//owned
       
   283     
       
   284     CSenAsyncTimeOut* iTimeOut;
       
   285     };
       
   286 
       
   287 #endif // WSF_TXN_STATE_H
       
   288 
       
   289 // End of File