williamr@2: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@2: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // Purpose: This file provides the definition of the CHTTPResponse class. williamr@2: // The HTTP Response class encodes HTTP response headers only. It williamr@2: // contains the methods used to transcode from WSP->HTTP fields williamr@2: // williamr@2: // williamr@2: williamr@2: #ifndef __CHTTPRESPONSE_H__ williamr@2: #define __CHTTPRESPONSE_H__ williamr@2: williamr@2: // System includes williamr@2: // williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: williamr@2: // Forward class declarations williamr@2: // williamr@2: class CPushMessage; williamr@2: williamr@2: // Class definition for CHTTPResponse williamr@2: // williamr@2: //##ModelId=3B712B9A0231 williamr@2: class CHTTPResponse : public CBase williamr@2: /** williamr@2: @publishedAll williamr@2: @deprecated williamr@2: */ williamr@2: { williamr@2: public: // Methods williamr@2: williamr@2: // Factory method to construct this class. williamr@2: // williamr@2: // Rtn: a new CHTTPResponse object, by ptr. Ownership is transferred to the williamr@2: // caller. williamr@2: // williamr@2: //##ModelId=3B712B9B000A williamr@2: IMPORT_C static CHTTPResponse* NewL(); williamr@2: williamr@2: // Destructor for this class. Removes this object and releases memory held williamr@2: // by it williamr@2: // williamr@2: //##ModelId=3B712B9B0000 williamr@2: IMPORT_C virtual ~CHTTPResponse(); williamr@2: williamr@2: // Clean out the fields buffer williamr@2: // williamr@2: //##ModelId=3B712B9A03D6 williamr@2: IMPORT_C void Reset(); williamr@2: williamr@2: // Set the fields buffer with the response received from the WAP Stack williamr@2: // williamr@2: // In: williamr@2: // aResponse - an 8-bit descriptor field containing the origin server's williamr@2: // WSP-encoded response header. Ownership is transferred to williamr@2: // this class. williamr@2: // williamr@2: //##ModelId=3B712B9A03D4 williamr@2: IMPORT_C void AddResponse(HBufC8* aResponse); williamr@2: williamr@2: // Accessor to the HTTP response fields buffer williamr@2: // williamr@2: // Rtn: a reference to the response. Ownership is _NOT_ transferred williamr@2: // williamr@2: // NOTE THIS SHOULD RETURN CONST - BUT CAN'T BE CHANGED SINCE IT WOULD williamr@2: // BREAK BC. williamr@2: //##ModelId=3B712B9A03CA williamr@2: IMPORT_C HBufC8& Response() const; williamr@2: williamr@2: // Accessor to the HTTP status code (e.g. 400, 300, 200, 500) williamr@2: // williamr@2: // Rtn: the status code - series number only. williamr@2: // williamr@2: //##ModelId=3B712B9A03C1 williamr@2: IMPORT_C THttpStatusCode StatusCode() const; williamr@2: williamr@2: // Accessor to the HTTP detailed status code (e.g. 404, 304, 200, 501) williamr@2: // williamr@2: // Rtn: the status code - series and specific code value williamr@2: // williamr@2: //##ModelId=3B712B9A03C0 williamr@2: IMPORT_C THttpStatusCode DetailedStatusCode() const; williamr@2: williamr@2: // Accessor to set the HTTP response status. williamr@2: // williamr@2: // In: williamr@2: // aCode - the WSP-encoded status code williamr@2: // williamr@2: //##ModelId=3B712B9A03B6 williamr@2: IMPORT_C void SetStatusCode(TInt aCode); williamr@2: williamr@2: // Method to find a named field, that returns null terminated williamr@2: // WSP text strings. williamr@2: // williamr@2: // In: williamr@2: // aField - the field type williamr@2: // aStartIndex - the index to search from (defaults to the buffer start) williamr@2: // williamr@2: // Out: williamr@2: // aDesc - a pointer-type descriptor into the response buffer at the williamr@2: // position where the field was located. The caller must NOT williamr@2: // modify the descriptor contents williamr@2: // williamr@2: // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise williamr@2: // williamr@2: //##ModelId=3B712B9A0390 williamr@2: IMPORT_C TBool FindField(THttpHeaderField aField williamr@2: , TPtrC8& aDesc williamr@2: , TInt aStartIndex = 0) const; williamr@2: williamr@2: // Method to find a named field, that returns 8-bit octet data (binary williamr@2: // or strings - not stipulated which). williamr@2: // williamr@2: // In: williamr@2: // aField - the field type williamr@2: // aStartIndex - the index to search from (defaults to the buffer start) williamr@2: // williamr@2: // Out: williamr@2: // aDesc - a pointer-type descriptor into the response buffer at the williamr@2: // position where the field was located. The caller must NOT williamr@2: // modify the descriptor contents williamr@2: // williamr@2: // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise williamr@2: // williamr@2: //##ModelId=3B712B9A0384 williamr@2: IMPORT_C TBool FindBinaryDescField(THttpHeaderField aField williamr@2: , TPtrC8& aDesc williamr@2: , TInt aStartIndex = 0) const; williamr@2: williamr@2: // Method to find a named field, that returns an EPOC date/time structure. williamr@2: // williamr@2: // In: williamr@2: // aField - the field type williamr@2: // aStartIndex - the index to search from (defaults to the buffer start) williamr@2: // williamr@2: // Out: williamr@2: // aTime - a structure containing the time (and date) found in the header williamr@2: // williamr@2: // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise williamr@2: // williamr@2: //##ModelId=3B712B9A03A2 williamr@2: IMPORT_C TBool FindField(THttpHeaderField aField williamr@2: , TTime& aTime williamr@2: , TInt aStartIndex = 0) const; williamr@2: williamr@2: // Method to find a named field within the Cache Control header williamr@2: // williamr@2: // In: williamr@2: // aField - the field type williamr@2: // williamr@2: // Out: williamr@2: // williamr@2: // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise williamr@2: // williamr@2: //##ModelId=3B712B9A0370 williamr@2: IMPORT_C TInt FindCacheControlFieldValue(TCacheControlFieldValue aField) const; williamr@2: williamr@2: // Method to find a named field within the Cache Control header, williamr@2: // that returns an EPOC date/time structure. williamr@2: // williamr@2: // In: williamr@2: // aField - the field type williamr@2: // williamr@2: // Out: williamr@2: // aTime - a structure containing the time (and date) found in the header field williamr@2: // williamr@2: // Rtn: TBool - set to ETrue if the field was found, EFalse otherwise williamr@2: // williamr@2: //##ModelId=3B712B9A035C williamr@2: IMPORT_C TBool ExtractCacheControlTime(TCacheControlFieldValue aField, TTime& aTime) const; williamr@2: williamr@2: // Method to search for the content type encoded in the response header williamr@2: // williamr@2: // Out: williamr@2: // aDesc - a pointer-type descriptor into the appropriate element of an williamr@2: // array prefilled with all the content types that have WSP williamr@2: // encodings. e.g. "text/vnd.wap.wml". The contents of the williamr@2: // descriptor must NOT be modified. williamr@2: // williamr@2: //##ModelId=3B712B9A0348 williamr@2: IMPORT_C void ContentType(TPtrC8& aDesc) const; williamr@2: williamr@2: // Method to search for the realm encoded in the response header, when the williamr@2: // response challenges the client for HTTP authentication (code 401) williamr@2: // williamr@2: // Out: williamr@2: // aDesc - a pointer-type descriptor into the response header buffer williamr@2: // positioned at the realm string within the challenge. The williamr@2: // contents of the descriptor must NOT be modified. williamr@2: // williamr@2: // Rtn: TBool - set to ETrue if a www-authenticate realm was found, EFalse williamr@2: // otherwise williamr@2: // williamr@2: //##ModelId=3B712B9A033F williamr@2: IMPORT_C TBool FindRealm(TPtrC8& aRealm) const; williamr@2: williamr@2: // Method to search for the character set encoded in the Content-Type williamr@2: // field ofthe response header williamr@2: // williamr@2: // Out: williamr@2: // aDesc - a pointer-type descriptor into the appropriate element of an williamr@2: // array prefilled with all the character sets that have WSP williamr@2: // encodings. e.g. "utf-8". The contents of the descriptor must williamr@2: // NOT be modified. williamr@2: // williamr@2: // Rtn: TBool - set to ETrue if a character set was found, EFalse if not williamr@2: // williamr@2: //##ModelId=3B712B9A032A williamr@2: IMPORT_C TBool CharSet(TPtrC8& aDesc) const; williamr@2: williamr@2: protected: // Methods williamr@2: williamr@2: // Normal constructor - do non-allocating creation of this class williamr@2: // williamr@2: IMPORT_C CHTTPResponse(); williamr@2: williamr@2: // Second phase construction - any allocation for this class must take place williamr@2: // here. Sets up the resources required by an HTTP Response. williamr@2: // williamr@2: //##ModelId=3B712B9A0322 williamr@2: IMPORT_C void ConstructL(); williamr@2: williamr@2: //friend class declaration - only need the following function williamr@2: friend class CPushMessage; williamr@2: // Method to locate a named field in the response header, starting at the williamr@2: // specified index position. williamr@2: // williamr@2: // In: williamr@2: // aField - the header field type williamr@2: // aStartIndex - the (optional) position in the header to start searching williamr@2: // williamr@2: // Rtn: TInt - the index position of the required field _value_ (not the williamr@2: // field name), or KErrNotFound otherwise. williamr@2: // williamr@2: //##ModelId=3B712B9A030D williamr@2: IMPORT_C TInt LocateField(THttpHeaderField aField, TInt aStartIndex = 0) const; williamr@2: williamr@2: // Perform a look-up of content type given a WSP encoding value, used as williamr@2: // an index. williamr@2: // williamr@2: // In: williamr@2: // aIndex - the WSP encoding value williamr@2: // williamr@2: // Rtn: const TText8* - the required content type text - NOT to be changed williamr@2: // williamr@2: //##ModelId=3B712B9A0352 williamr@2: IMPORT_C const TText8* ContentType(TInt aContentTypeCode) const; williamr@2: williamr@2: // Perform a look-up of character set given a WSP encoding value, used as williamr@2: // an index. williamr@2: // williamr@2: // In: williamr@2: // aCharsetCode - the index into the content types table/ williamr@2: // williamr@2: // Rtn: const TText8* - the required 8-bit character set text - NOT to be williamr@2: // changed by the caller williamr@2: // williamr@2: //##ModelId=3B712B9A0334 williamr@2: IMPORT_C const TText8* CharSet(TInt aCharsetCode) const; williamr@2: williamr@2: private: // Attributes williamr@2: williamr@2: // The 8-bit buffer used to store the HTTP response fields williamr@2: // williamr@2: //##ModelId=3B712B9A02AA williamr@2: HBufC8* iResponse; williamr@2: williamr@2: // The HTTP Status code (coarse - ie. series only, e.g. 100, 200 etc.) williamr@2: // williamr@2: //##ModelId=3B712B9A0296 williamr@2: THttpStatusCode iStatusCode; williamr@2: williamr@2: // The detailed HTTP Status code (within series, e.g. 102, 204, 401 etc.) williamr@2: // williamr@2: //##ModelId=3B712B9A0282 williamr@2: THttpStatusCode iDetailedStatusCode; williamr@2: williamr@2: // Declare the CLogClient pointer williamr@2: __DECLARE_LOG williamr@2: williamr@2: private: // Methods williamr@2: williamr@2: // Do a conversion from 32-bit UIntVar encoding into 32-bit integer williamr@2: // williamr@2: TInt ParseUIntVar(const TDesC8& aBuffer, TInt& aVal) const; williamr@2: williamr@2: // Extract a WSP encoded MultiOctet Integer encoding into 32-bit integer williamr@2: // williamr@2: // In: williamr@2: // aSource - the source Multi-Octet integer williamr@2: // williamr@2: // Out: williamr@2: // aInt - the 32-bit resulting integer williamr@2: // williamr@2: //##ModelId=3B712B9A02F8 williamr@2: void ExtractMultiOctetInteger(TInt& aInt, const TPtrC8& aSource) const; williamr@2: williamr@2: // Method to find a named field within the Cache Control header williamr@2: // williamr@2: // In: williamr@2: // aSource - the descriptor containing the date value williamr@2: // aFrom - The position in the descriptor to start from williamr@2: // williamr@2: // Out: williamr@2: // aTime - a structure containing the time (and date) found in the descriptor williamr@2: // williamr@2: //##ModelId=3B712B9A02E4 williamr@2: void ExtractFieldDateValue(const TPtrC8& aSource, TInt aFrom, TTime& aTime) const; williamr@2: williamr@2: // Method to find a named field within the Cache Control header williamr@2: // williamr@2: // In: williamr@2: // aField - the field type williamr@2: // williamr@2: // Out: williamr@2: // the found aCacheControl string williamr@2: // williamr@2: // Rtn: TInt - set to KErrNotFound if the field was not found, williamr@2: // otherwise the position in the cache control descriptor that the field was found williamr@2: // williamr@2: //##ModelId=3B712B9A0372 williamr@2: TInt FindCacheControlFieldValue(TCacheControlFieldValue aField,TPtrC8& aCacheControl) const; williamr@2: williamr@2: //##ModelId=3B712B9A02DA williamr@2: void Panic(THttpPanicCode aPanicCode) const; williamr@2: williamr@2: // Spare methods for future BC. Const- and non-const versions to assist williamr@2: // the caller in preserving const-ness. IMPORT_C ensures they reserve a williamr@2: // slot in the vtbl, which is essential to preseve future BC. williamr@2: // williamr@2: //##ModelId=3B712B9A02D0 williamr@2: IMPORT_C virtual TAny* Extend_CHTTPResponse(TAny* aArgs); williamr@2: //##ModelId=3B712B9A02C6 williamr@2: IMPORT_C virtual TAny* Extend_CHTTPResponse_const(TAny* aArgs) const; williamr@2: williamr@2: #if defined _DEBUG williamr@2: // Debug method definition to allow class invariant testing williamr@2: // Called by the standard macro __TEST_INVARIANT williamr@2: // williamr@2: //##ModelId=3B712B9A02BD williamr@2: void __DbgTestInvariant() const; williamr@2: williamr@2: //##ModelId=3B712B9A02B2 williamr@2: void DumpToLog(const TDesC8& aData) const; williamr@2: #endif williamr@2: williamr@2: }; williamr@2: williamr@2: #endif // __CHTTPRESPONSE_H__ williamr@4: