voipplugins/accountcreationplugin/engine/inc/acphttphandler.h
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
child 23 755430a7d64b
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Declarition of CAcpHttpHandler
       
    15 *
       
    16 */
       
    17 
       
    18  
       
    19 #ifndef ACPHTTPHANDLER_H
       
    20 #define ACPHTTPHANDLER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <http/rhttpsession.h>
       
    24 #include <http/mhttpdatasupplier.h>
       
    25 #include <http/mhttptransactioncallback.h>
       
    26 #include <es_sock.h>
       
    27 
       
    28 class RHTTPTransaction;
       
    29 class MAcpHttpHandlerObserver;
       
    30 
       
    31 /**
       
    32  *  CAcpHttpHandler class
       
    33  *  Declarition of CAcpHttpHandler.
       
    34  *
       
    35  *  @lib accountcreationplugin.lib
       
    36  *  @since S60 v3.2
       
    37  */
       
    38 NONSHARABLE_CLASS( CAcpHttpHandler ) : public CActive,
       
    39                                        public MHTTPDataSupplier,
       
    40                                        public MHTTPTransactionCallback
       
    41     {
       
    42 public: 
       
    43 
       
    44     /**
       
    45      * Two-phased constructor.
       
    46      *
       
    47      * @param aObserver for observer
       
    48      */
       
    49     static CAcpHttpHandler* NewL( MAcpHttpHandlerObserver& aObserver );
       
    50 
       
    51     /**
       
    52      * Two-phased constructor.
       
    53      *
       
    54      * @param aObserver for observer
       
    55      */
       
    56     static CAcpHttpHandler* NewLC( MAcpHttpHandlerObserver& aObserver );
       
    57 
       
    58     /**
       
    59      * Destructor.
       
    60      */
       
    61     virtual ~CAcpHttpHandler();
       
    62 
       
    63     /**
       
    64      * Fetches data from network.
       
    65      *
       
    66      * @since S60 v3.2
       
    67      * @param aUrl Data URL.
       
    68      * @param aContentType Content type.
       
    69      * @param aBody Post data.
       
    70      * @param aMimeTypeImage Image's mime type.
       
    71      * @param aSessionId Session id to be stored in a cookie. Can be KNullDesC8.
       
    72      */
       
    73     void GetDataL( 
       
    74         const TDesC8& aUrl, 
       
    75         const TDesC8& aContentType,
       
    76         const TDesC8& aBody,
       
    77         TBool aMimeTypeImage,
       
    78         const TDesC8& aSessionId,
       
    79         TBool aGetSisFile = EFalse );
       
    80 
       
    81     /**
       
    82      * Cancels ongoing transaction and frees the resources.
       
    83      *
       
    84      * @since S60 v3.2
       
    85      */
       
    86     void CancelTransaction();
       
    87     
       
    88     /**
       
    89      * Shuts down connection (RConnection and RSocketServ).
       
    90      * 
       
    91      * @since S60 v3.2
       
    92      */
       
    93     void ShutdownConnection();
       
    94     
       
    95     /**
       
    96      * Handles known HTTP headers.
       
    97      * 
       
    98      * @since S60 v3.2
       
    99      * @param aTransaction HTTP transaction that received the headers.
       
   100      */
       
   101     void ProcessHeadersL( RHTTPTransaction& aTransaction );
       
   102     
       
   103 // from base class MHTTPTransactionCallback
       
   104 
       
   105     /**
       
   106      * From MHTTPTransactionCallback.
       
   107      * Called when the filter's registration conditions are satisfied
       
   108      * for events that occur on a transaction.
       
   109      * 
       
   110      * @since S60 v3.2
       
   111      * @param aTransaction The transaction that the event has occurred on.
       
   112      * @param aEvent The event that has occurred.
       
   113      */
       
   114     void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent );
       
   115 
       
   116     /**
       
   117      * From MHTTPTransactionCallback.
       
   118      * Called when RunL leaves from a transaction event.
       
   119      * 
       
   120      * @since S60 v3.2
       
   121      * @param aError The leave code that RunL left with.
       
   122      * @param aTransaction The transaction that was being processed.
       
   123      * @param aEvent The Event that was being processed.
       
   124      * @return KErrNone if the error has been cancelled or the code
       
   125      *         of the continuing error otherwise.
       
   126      */
       
   127     TInt MHFRunError( TInt aError, RHTTPTransaction aTransaction, 
       
   128         const THTTPEvent& aEvent );
       
   129 
       
   130 private:
       
   131 
       
   132     CAcpHttpHandler( MAcpHttpHandlerObserver& aObserver );
       
   133     void ConstructL();
       
   134 
       
   135     /**
       
   136      * Returns request method based on type.
       
   137      *
       
   138      * @since S60 v3.2
       
   139      * @param aType for type of method
       
   140      * @return request method
       
   141      */
       
   142     RStringF GetRequestMethod( TInt aType ) const;
       
   143 
       
   144     /**
       
   145      * Starts the connection asynchronously.
       
   146      *
       
   147      * @since S60 v3.2
       
   148      */
       
   149     void StartConnectionL();
       
   150 
       
   151     /**
       
   152      * Sets transaction's request headers.
       
   153      *
       
   154      * @since S60 v3.2
       
   155      * @param aHeaders for headers
       
   156      * @param aHdrField for header fields
       
   157      * @param aHdrValue for header value
       
   158      */
       
   159     void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField,  
       
   160         const TDesC8& aHdrValue );
       
   161     
       
   162     /**
       
   163      * Submits HTTP transaction.
       
   164      * 
       
   165      * @since S60 v3.2
       
   166      */
       
   167     void SubmitTransactionL();
       
   168     
       
   169 // from base class MHTTPDataSupplier
       
   170 
       
   171     /**
       
   172      * From MHTTPDataSupplier.
       
   173      * Release the current data part being held at the data
       
   174      * supplier.
       
   175      * 
       
   176      * @since S60 v3.2
       
   177      */
       
   178     void ReleaseData();
       
   179 
       
   180     /**
       
   181      * From MHTTPDataSupplier.
       
   182      * Obtain a data part from the supplier.
       
   183      * 
       
   184      * @since S60 v3.2
       
   185      * @param aDataPart The data part.
       
   186      * @return ETrue if this is the last part. EFalse otherwise
       
   187      */
       
   188     TBool GetNextDataPart( TPtrC8& aDataPart );
       
   189 
       
   190     /**
       
   191      * From MHTTPDataSupplier.
       
   192      * Reset the data supplier.
       
   193      * 
       
   194      * @since S60 v3.2
       
   195      * @return Error code.
       
   196      */
       
   197     TInt Reset();
       
   198 
       
   199     /**
       
   200      * From MHTTPDataSupplier.
       
   201      * Obtain the overall size of the data being supplied,
       
   202      * if known to the supplier.
       
   203      * 
       
   204      * @since S60 v3.2
       
   205      * @return A size in bytes, or KErrNotFound if the size is not known.
       
   206      */
       
   207     TInt OverallDataSize();
       
   208 
       
   209 // from base class CActive.
       
   210     
       
   211     /**
       
   212      * From CActive.
       
   213      * 
       
   214      * @since S60 v3.2
       
   215      */
       
   216     void RunL();
       
   217 
       
   218     /**
       
   219      * From CActive.
       
   220      *      
       
   221      * @since S60 v3.2
       
   222      */
       
   223     void DoCancel();
       
   224     
       
   225 private: // data
       
   226 
       
   227     /**
       
   228      * Reference to observer.
       
   229      * Not own.
       
   230      */
       
   231     MAcpHttpHandlerObserver& iObserver;
       
   232 
       
   233     /**
       
   234      * Handle for HTTP session.
       
   235      * Own. 
       
   236      */
       
   237     RHTTPSession iSession;
       
   238 
       
   239     /**
       
   240      * Handle for HTTP transaction.
       
   241      * Own. 
       
   242      */
       
   243     RHTTPTransaction iTransaction;
       
   244     
       
   245     /**
       
   246      * Handle for connection.
       
   247      */
       
   248     RConnection iConnection;
       
   249     
       
   250     /*
       
   251      * Handle for socket server.
       
   252      */
       
   253     RSocketServ iSocketServer;
       
   254 
       
   255     /**
       
   256      * Handle to post data.
       
   257      * Own. 
       
   258      */
       
   259     HBufC8* iPostData;
       
   260 
       
   261     /**
       
   262      * Tells if a transaction is running.
       
   263      */
       
   264     TBool iTransactionRunning;
       
   265     
       
   266     /**
       
   267      * Tells if the connection is open.
       
   268      */
       
   269     TBool iConnectionOpen;
       
   270 
       
   271     /**
       
   272      * Tells if MIME type is image.
       
   273      */
       
   274     TBool iMimeTypeImage;
       
   275     
       
   276     /**
       
   277      * Tells if connection prompt has been shown once.
       
   278      */
       
   279     TBool iPromptShown;
       
   280     
       
   281     /**
       
   282      * Selected IAP id.
       
   283      */
       
   284     TUint32 iIapId;
       
   285     
       
   286     /**
       
   287      * Selected SNAP id.
       
   288      */
       
   289     TUint32 iNetId;
       
   290     
       
   291     /**
       
   292      * Connection progress.
       
   293      */
       
   294     TNifProgress iNifProgress;
       
   295 
       
   296     // For unit testing.
       
   297 #ifdef _DEBUG
       
   298     friend class T_CAcpHttpHandler;
       
   299 #endif
       
   300     };
       
   301 
       
   302 #endif // ACPHTTPHANDLER_H
       
   303 
       
   304 // End of file.