examples/AppProts/exampleclient/httpexampleclient.h

00001 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // HTTPEXAMPLECLIENT is a simple text based http client. 
00015 // It is intended as an example and introduction to the HTTP Client API's available in 
00016 // The Symbian Platform Release 6.2
00017 // Users should have a brief understanding of HTTP and the different types of requests and responses you can get
00018 // from servers. They should also be familiar with setting up a communications database (cdbv2.dat) with suitable settings
00019 // for modems/NTRas and ISP's.
00020 //
00021 
00022 
00023 
00024 #include <e32test.h>
00025 #include <f32file.h>
00026 #include <http/mhttpauthenticationcallback.h>
00027 
00028 // Maximum size of buffer to hold content-type data
00029 //
00030 const TInt KMaxContentTypeSize = 64;
00031 
00032 
00033 //
00034 // Definition of CHttpClient
00035 //
00036 class CHttpEventHandler;
00037 class CHttpExampleUtils;
00038 
00039 
00048 class CHttpClient : public CBase, public MHTTPDataSupplier, 
00049                                         public MHTTPAuthenticationCallback
00050         {
00051 public:
00052         virtual ~CHttpClient();
00053         static CHttpClient* NewLC();
00054         static CHttpClient* NewL();
00055         void StartClientL();
00056 // methods inherited from MHTTPDataSupplier
00057         virtual TBool GetNextDataPart(TPtrC8& aDataPart);
00058         virtual void ReleaseData();
00059         virtual TInt OverallDataSize();
00060         virtual TInt Reset();
00061 
00062 // methods inherited from MHTTPAuthenticationCallback
00063         virtual TBool GetCredentialsL(const TUriC8& aURI, RString aRealm, 
00064                                                                  RStringF aAuthenticationType,
00065                                                                  RString& aUsername, 
00066                                                                  RString& aPassword);
00067 
00068 protected:
00069         CHttpClient();
00070         void ConstructL();
00071 private:
00072 
00073         enum TMenuItems
00074                 {
00075                 EGet,
00076                 EPost,
00077                 EHead,
00078                 ETrace,
00079                 EToggleVerbosity,
00080                 EQuit
00081                 };
00082 
00083         void ResetTimeElapsed();
00084         void DisplayTimeElapsed();
00085         //
00086         void InvokeHttpMethodL(const TDesC8& aUri, RStringF aMethod);
00087         void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue);
00088         void GetRequestBodyL(RStringF& aMethod);
00089         void GetPostBodyManuallyL();
00090 
00091 private:
00092         TTime iLastTimeStamp;
00093         TInt iDataChunkCount;
00094         RHTTPSession iSess;
00095         RHTTPTransaction iTrans;
00096         TBool iHasARequestBody;
00097         RFs iFileServ;
00098         RFile iReqBodyFile;
00099         TFileName iReqBodyFileName;
00100         TParse iParsedFileName;
00101         TBuf<KMaxContentTypeSize> iReqBodyContentType;
00102         CHttpEventHandler* iTransObs;
00103         HBufC8* iReqBodySubmitBuffer;
00104         TPtr8 iReqBodySubmitBufferPtr;
00105         CHTTPFormEncoder* iFormEncoder;         // used for manual post submissions
00106         TBool iManualPost;
00107         CHttpExampleUtils* iUtils;
00108         };
00109 
00110 
00111 
00114 class CHttpEventHandler : public CBase, public MHTTPTransactionCallback
00115         {
00116 public:
00117         virtual ~CHttpEventHandler();
00118         static CHttpEventHandler* NewLC(CHttpExampleUtils& aUtils);
00119         static CHttpEventHandler* NewL(CHttpExampleUtils& aUtils);
00120         void SetVerbose(TBool aVerbose);
00121         TBool Verbose() const;
00122         //
00123         // methods from MHTTPTransactionCallback
00124         //
00125         virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
00126         virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
00127 
00128 protected:
00129         CHttpEventHandler(CHttpExampleUtils& aUtils);
00130         void ConstructL();
00131 private:
00132         void DumpRespHeadersL(RHTTPTransaction& aTrans);
00133         void DumpRespBody(RHTTPTransaction& aTrans);
00134         void DumpIt(const TDesC8& aData);
00135         TBool iVerbose;
00136         TBool iSavingResponseBody;
00137         RFs iFileServ;
00138         RFile iRespBodyFile;
00139         TFileName iRespBodyFileName;
00140         TParse iParsedFileName;
00141         MHTTPDataSupplier* iRespBody;
00142         CHttpExampleUtils& iUtils; // not owned
00143         };
00144 

Generated on Thu Jan 21 10:32:55 2010 for TB10.1 Example Applications by  doxygen 1.5.3