|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : WebClientEngine.h 00004 * Part of : WebClient 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2005-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 #ifndef WEBCLIENTENGINE_H 00017 #define WEBCLIENTENGINE_H 00018 00019 // INCLUDES 00020 #include <coecntrl.h> 00021 #include <http.h> 00022 #include <http\mhttpauthenticationcallback.h> 00023 00024 // CONSTANTS 00025 const TInt KMaxHeaderNameLength = 32; 00026 const TInt KMaxHeaderValueLength = 128; 00027 const TInt KMaxAuthTypeLength = 128; 00028 const TInt KMaxDateTimeStringLength = 40; 00029 const TInt KMaxStatusTextLength = 32; 00030 00031 // Used user agent for requests 00032 _LIT8( KUserAgent, "WebClient 1.0" ); 00033 00034 // This client accepts all content types. 00035 // (change to e.g. "text/plain" for plain text only) 00036 _LIT8( KAccept, "*/*" ); 00037 00038 // Format for output of data/time values 00039 _LIT( KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3" ); 00040 00041 // Some texts for header output 00042 _LIT( KColon, ": " ); 00043 _LIT( Krealm, "Realm: " ); 00044 00045 00046 // FORWARD DECLARATIONS 00047 class CWebClientAppUi; 00048 00049 // CLASS DECLARATION 00050 00051 /** 00052 * MWebClientObserver 00053 * CWebClientEngine passes events and responses body data with this interface. 00054 * An instance of this class must be provided for construction of CWebClientEngine. 00055 */ 00056 class MWebClientObserver 00057 { 00058 public: 00059 /** 00060 * ClientEvent() 00061 * Called when event occurs in CWebClientEngine. 00062 * @param aEventDescription: A event in textual format, e.g. 00063 * "Transaction Successful" 00064 */ 00065 virtual void ClientEvent( const TDesC& aEventDescription ) = 0; 00066 00067 public: 00068 /** 00069 * ClientHeaderReceived() 00070 * Called when HTTP header is received. 00071 * @param aHeaderData: Header field name and value 00072 */ 00073 virtual void ClientHeaderReceived( const TDesC& aHeaderData ) = 0; 00074 00075 /** 00076 * ClientBodyReceived() 00077 * Called when a part of the HTTP body is received. 00078 * @param aBodyData: Part of the body data received. (e.g. part of 00079 * the received HTML page) 00080 */ 00081 virtual void ClientBodyReceived( const TDesC8& aBodyData ) = 0; 00082 }; 00083 00084 /** 00085 * CWebClientEngine 00086 * Provides simple interface to HTTP Client API. 00087 */ 00088 class CWebClientEngine : public CBase, 00089 public MHTTPTransactionCallback, 00090 public MHTTPAuthenticationCallback 00091 { 00092 public: 00093 /** 00094 * NewL() 00095 * Create a CWebClientEngine object. 00096 * @param iObserver: 00097 * @return A pointer to the created instance of CWebClientEngine 00098 */ 00099 static CWebClientEngine* NewL( MWebClientObserver& aObserver ); 00100 00101 /** 00102 * NewLC() 00103 * Create a CWebClientEngine object. 00104 * @param iObserver: 00105 * @return A pointer to the created instance of CWebClientEngine 00106 */ 00107 static CWebClientEngine* NewLC( MWebClientObserver& aObserver ); 00108 00109 /** 00110 * ~CWebClientEngine() 00111 * Destroy the object 00112 */ 00113 ~CWebClientEngine(); 00114 00115 /** 00116 * IssueHTTPGetL() 00117 * Starts a new HTTP GET transaction. 00118 * @param aUri: URI to get. (e.g. http://host.org") 00119 */ 00120 void IssueHTTPGetL( const TDesC8& aUri ); 00121 00122 /** 00123 * CancelTransactionL() 00124 * Closes currently running transaction and frees resources related to it. 00125 */ 00126 void CancelTransactionL(); 00127 00128 /** 00129 * IsRunning() 00130 * Checks if the transaction is running. 00131 * @return ETrue, if transaction is currently running. 00132 */ 00133 inline TBool IsRunning() { return iRunning; }; 00134 00135 /** 00136 * SetCallBack() 00137 * Sets the callback address. 00138 * @param aCallBack: A pointer to calling instance. 00139 */ 00140 void SetCallBack( CWebClientAppUi* aCallBack ); 00141 00142 private: 00143 /** 00144 * ConstructL() 00145 * Perform the second phase construction of a CWebClientEngine object. 00146 */ 00147 void ConstructL(); 00148 00149 /** 00150 * CWebClientEngine() 00151 * Perform the first phase of two phase construction. 00152 * @param iObserver: 00153 */ 00154 CWebClientEngine( MWebClientObserver& iObserver ); 00155 00156 /** 00157 * SetHeaderL() 00158 * Sets header value of an HTTP request. 00159 * @param aHeaders: Headers of the HTTP request 00160 * @param aHdrField: Enumerated HTTP header field, e.g. HTTP::EUserAgent 00161 * @param aHdrValue: New value for header field 00162 */ 00163 void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField, 00164 const TDesC8& aHdrValue ); 00165 00166 /** 00167 * DumpRespHeadersL() 00168 * Called when HTTP header is received. 00169 * Displays HTTP header field names and values 00170 * @param aTransaction: The transaction that is processed. 00171 */ 00172 void DumpRespHeadersL( RHTTPTransaction& aTransantion ); 00173 00174 /** 00175 * HandleRunErrorL() 00176 * Called from MHFRunError() when *leave* occurs in handling of transaction event. 00177 * @param aError: The leave code that occured. 00178 */ 00179 void HandleRunErrorL( TInt aError ); 00180 00181 /** 00182 * From MHTTPSessionEventCallback 00183 */ 00184 private: 00185 /** 00186 * MHFRunL() 00187 * Called by framework to notify about transaction events. 00188 * @param aTransaction: Transaction, where the event occured. 00189 * @param aEvent: Occured event. 00190 */ 00191 void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent ); 00192 00193 /** 00194 * MHFRunError() 00195 * Called by framework when *leave* occurs in handling of transaction event. 00196 * @param aError: The leave code that occured. 00197 * @param aTransaction: The transaction that was being processed when leave occured. 00198 * @param aEvent: The event that was being processed when leave occured. 00199 * @return KErrNone, if the error was handled. Otherwise the value of aError, or 00200 * some other error value. Returning error value causes causes 00201 * HTTP-CORE 6 panic. 00202 */ 00203 TInt MHFRunError( TInt aError, 00204 RHTTPTransaction aTransaction, 00205 const THTTPEvent& aEvent ); 00206 00207 /** 00208 * From MHTTPAuthenticationCallback (needed for HTTP authentication) 00209 */ 00210 private: 00211 /** 00212 * GetCredentialsL() 00213 * Called by framework when username and password for requested URI is 00214 * needed. 00215 * @param aURI: The URI being requested (e.g. "http://host.org") 00216 * @param aRealm: The realm being requested (e.g. "user@host.org") 00217 * @param aAuthenticationType: Authentication type. (e.g. "Basic") 00218 * @param aUsername: Given user name. 00219 * @param aPassword: Given password. 00220 * @return A pointer to the created document 00221 */ 00222 TBool GetCredentialsL( const TUriC8& aUri, 00223 RString aRealm, 00224 RStringF aAuthenticationType, 00225 RString& aUsername, 00226 RString& aPassword ); 00227 00228 private: // Data 00229 RHTTPSession iSession; 00230 RHTTPTransaction iTransaction; 00231 MWebClientObserver& iObserver; // Used for passing body data and 00232 // events to UI. 00233 TBool iRunning; // ETrue, if transaction running 00234 CWebClientAppUi* iApplicationUi; // Pointer to AppUi instance 00235 }; 00236 00237 #endif // WEBCLIENTENGINE_H
|
© Nokia 2006 |