applayerpluginsandutils/httpprotocolplugins/wspheadercodec/CWspHeaderWriter.h
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CWSPHEADERWRITER_H__
       
    17 #define __CWSPHEADERWRITER_H__
       
    18 
       
    19 // System Includes
       
    20 #include <e32std.h>
       
    21 #include <wspencoder.h>
       
    22 #include <http/framework/cheadercodec.h>
       
    23 
       
    24 // User Includes
       
    25 #include "cwspheadercodec.h"
       
    26 
       
    27 // Forward declarations
       
    28 class CHeaderFieldParam;
       
    29 
       
    30 /**
       
    31 @since			7.0
       
    32 This class provides the encoding functionality for encoding all of the supported
       
    33 headers. The single method EncodeHeaderL() is used passing in the header field
       
    34 and the particular header field is then encoded into its faw format.
       
    35 */
       
    36 //##ModelId=3C4C41A600FD
       
    37 class CWspHeaderWriter : public CHeaderWriter
       
    38 	{
       
    39 public: // methods
       
    40 
       
    41 	/**
       
    42 	Standard virtual destructor
       
    43 	@since			7.0
       
    44 	@pre 			Fully constructed object
       
    45 	@post			Object is destroyed
       
    46 	*/
       
    47 	//##ModelId=3C4C41A6027C
       
    48 	virtual ~CWspHeaderWriter();
       
    49 
       
    50 	/**
       
    51 	Standard factory 2 phase construction
       
    52 	Error Condition: Low memory conditions
       
    53 	@since			7.0
       
    54 	@param			aStrPool Handle to an opened string pool with the WSP string table already opened
       
    55 	@param			aStrTable The WSP string table to use for the header field names
       
    56 	@param			aCodec The codec that owns this header writer
       
    57 	@return			A pointer to the newly constructed class
       
    58 	@pre 			None
       
    59 	@post			Object is constructed
       
    60 	*/
       
    61 	//##ModelId=3C4C41A60272
       
    62 	static CWspHeaderWriter* NewL(RStringPool aStrPool, const TStringTable& aStrTable, CWspHeaderCodec& aCodec);
       
    63 
       
    64 	/**
       
    65 	Standard factory 2 phase construction leaving a handle on the cleanup stack.
       
    66 	Error Condition: Low memory conditions
       
    67 	@since			7.0
       
    68 	@param			aStrPool Handle to an opened string pool with the WSP string table already opened
       
    69 	@param			aStrTable The WSP string table to use for the header field names
       
    70 	@param			aCodec The codec that owns this header writer
       
    71 	@return			A pointer to the newly constructed class
       
    72 	@pre 			None
       
    73 	@post			Object is constructed with a handle on the cleanup stack
       
    74 	*/
       
    75 	//##ModelId=3C4C41A60267
       
    76 	static CWspHeaderWriter* NewLC(RStringPool aStrPool, const TStringTable& aStrTable, CWspHeaderCodec& aCodec);
       
    77 
       
    78 	/**
       
    79 	This method will encode the header field that is passed in into its raw
       
    80 					form.
       
    81 	Error Condition: Invalid or corrupt data formats and out of memeory conditions
       
    82 	@since			7.0
       
    83 	@param			aHeader The header field to encode
       
    84 	@pre 			The header field is in its parsed state
       
    85 	@post			The header field is in its raw format state
       
    86 	@leave		KErrNotSupported If the header field is not supported
       
    87 					KErrNoMemory Out of memory conditions
       
    88 					KErrCorrupt If the data is invalid or is corrupt
       
    89 	*/
       
    90 	//##ModelId=3C4C41A6025E
       
    91 	virtual void EncodeHeaderL(RHeaderField& aHeader);
       
    92 
       
    93 	/**
       
    94 	This method encodes the field name into its encoded token value. For WSP
       
    95 					transport the encoded token must be a short integer where the top bit is
       
    96 					set to 1. This method will NOT set the top bit to 1.
       
    97 	@since			7.0
       
    98 	@param			aFieldName The name of the field to encode
       
    99 	@return			The encoded token value for the header field name. This value will always be
       
   100 					between 0 and 127 inclusive or KErrNotFound if the header name does not have
       
   101 					an encoded token value.
       
   102 	*/
       
   103 	//##ModelId=3C4C41A6025C
       
   104 	TInt EncodeFieldName(RStringF aFieldName) const;
       
   105 
       
   106 protected: // methods
       
   107 
       
   108 	/**
       
   109 	Standard default constructor.
       
   110 	@since			7.0
       
   111 	@param			aStrPool Handle to an opened string pool with the WSP string table already opened
       
   112 	@param			aStrTable The WSP string table to use for the header field names
       
   113 	@param			aCodec The codec that owns this header writer
       
   114 	@pre 			None
       
   115 	@post			Object is constructed
       
   116 	*/
       
   117 	//##ModelId=3C4C41A60252
       
   118 	CWspHeaderWriter(RStringPool aStrPool, const TStringTable& aStrTable, CWspHeaderCodec& aCodec);
       
   119 
       
   120 private: // methods
       
   121 
       
   122 	/**
       
   123 	Encodes the 'Accept' header
       
   124 	*/
       
   125 	//##ModelId=3C4C41A60249
       
   126 	void EncodeAcceptL(RHeaderField& aHeader) const;
       
   127 
       
   128 	/**
       
   129 	Encodes the 'Accept-charset' header
       
   130 	*/
       
   131 	//##ModelId=3C4C41A60240
       
   132 	void EncodeAcceptCharsetL(RHeaderField& aHeader) const;
       
   133 
       
   134 	/**
       
   135 	Encodes the 'Accept-encoding' header
       
   136 	*/
       
   137 	//##ModelId=3C4C41A6023E
       
   138 	void EncodeAcceptEncodingL(RHeaderField& aHeader) const;
       
   139 
       
   140 	/**
       
   141 	Encodes the 'Accept-language' header
       
   142 	*/
       
   143 	//##ModelId=3C4C41A60235
       
   144 	void EncodeAcceptLanguageL(RHeaderField& aHeader) const;
       
   145 
       
   146 	/**
       
   147 	Encodes the 'Allow' header
       
   148 	*/
       
   149 	//##ModelId=3C4C41A6022C
       
   150 	void EncodeAllowL(RHeaderField& aHeader) const;
       
   151 
       
   152 	/**
       
   153 	Encodes the 'Authorization' header
       
   154 	*/
       
   155 	//##ModelId=3C4C41A6022A
       
   156 	void EncodeAuthorizationL(RHeaderField& aHeader) const;
       
   157 
       
   158 	/**
       
   159 	Encodes the 'Content-encoding' header
       
   160 	*/
       
   161 	//##ModelId=3C4C41A60222
       
   162 	void EncodeContentEncodingL(RHeaderField& aHeader) const;
       
   163 
       
   164 	/**
       
   165 	Encodes the 'Content-language' header
       
   166 	*/
       
   167 	//##ModelId=3C4C41A60220
       
   168 	void EncodeContentLanguageL(RHeaderField& aHeader) const;
       
   169 
       
   170 	/**
       
   171 	Encodes the 'Content-location' header
       
   172 	*/
       
   173 	//##ModelId=3C4C41A60217
       
   174 	void EncodeContentLocationL(RHeaderField& aHeader) const;
       
   175 
       
   176 	/**
       
   177 	Encodes the 'Content-MD5' header
       
   178 	*/
       
   179 	//##ModelId=3C4C41A6020E
       
   180 	void EncodeContentMD5L(RHeaderField& aHeader) const;
       
   181 
       
   182 	/**
       
   183 	Encodes the 'Content-range' header
       
   184 	*/
       
   185 	//##ModelId=3C4C41A6020C
       
   186 	void EncodeContentRangeL(RHeaderField& aHeader) const;
       
   187 
       
   188 	/**
       
   189 	Encodes the 'Content-type' header
       
   190 	*/
       
   191 	//##ModelId=3C4C41A60203
       
   192 	void EncodeContentTypeL(RHeaderField& aHeader) const;
       
   193 
       
   194 	/**
       
   195 	Encodes the 'Cookie' header
       
   196 	*/
       
   197 	//##ModelId=3C4C41A601FA
       
   198 	void EncodeCookieL(RHeaderField& aHeader) const;
       
   199 
       
   200 	/**
       
   201 	Encodes the 'Date' header
       
   202 	*/
       
   203 	//##ModelId=3C4C41A601F8
       
   204 	void EncodeDateL(RHeaderField& aHeader) const;
       
   205 
       
   206 	/**
       
   207 	Encodes the 'Encoding-version' header
       
   208 	*/
       
   209 	//##ModelId=3C4C41A601F0
       
   210 	void EncodeEncodingVersionL(RHeaderField& aHeader) const;
       
   211 
       
   212 	/**
       
   213 	Encodes the 'Expect' header
       
   214 	*/
       
   215 	//##ModelId=3C4C41A601EE
       
   216 	void EncodeExpectL(RHeaderField& aHeader) const;
       
   217 
       
   218 	/**
       
   219 	Encodes the 'From' header
       
   220 	*/
       
   221 	//##ModelId=3C4C41A601E4
       
   222 	void EncodeFromL(RHeaderField& aHeader) const;
       
   223 
       
   224 	/**
       
   225 	Encodes the 'Last-modified' header
       
   226 	*/
       
   227 	//##ModelId=3C4C41A601DA
       
   228 	void EncodeLastModifiedL(RHeaderField& aHeader) const;
       
   229 
       
   230 	/**
       
   231 	Encodes the 'Pragma' header
       
   232 	*/
       
   233 	//##ModelId=3C4C41A601D2
       
   234 	void EncodePragmaL(RHeaderField& aHeader) const;
       
   235 	
       
   236 	/**
       
   237 	Encodes the 'Profile' header
       
   238 	*/
       
   239 	void EncodeProfileL(RHeaderField& aHeader) const;
       
   240 	
       
   241 	/**
       
   242 	Encodes the 'Profile-Diff' header
       
   243 	*/
       
   244 	void EncodeProfileDiffL(RHeaderField& aHeader) const;
       
   245  
       
   246 	/**
       
   247 	Encodes the 'Range' header
       
   248 	*/
       
   249 	//##ModelId=3C4C41A601D0
       
   250 	void EncodeRangeL(RHeaderField& aHeader) const;
       
   251 
       
   252 	/**
       
   253 	Encodes the 'Referer' header
       
   254 	*/
       
   255 	//##ModelId=3C4C41A601C7
       
   256 	void EncodeRefererL(RHeaderField& aHeader) const;
       
   257 
       
   258 	/**
       
   259 	Encodes the 'TE' header
       
   260 	*/
       
   261 	//##ModelId=3C4C41A601BE
       
   262 	void EncodeTEL(RHeaderField& aHeader) const;
       
   263 
       
   264 	/**
       
   265 	Encodes the 'Trailer' header
       
   266 	*/
       
   267 	//##ModelId=3C4C41A601BC 
       
   268 	void EncodeTrailerL(RHeaderField& aHeader) const;
       
   269 
       
   270 	/**
       
   271 	Encodes the 'Upgrade' header
       
   272 	*/
       
   273 	//##ModelId=3C4C41A601B2
       
   274 	void EncodeUpgradeL(RHeaderField& aHeader) const;
       
   275  
       
   276 	/**
       
   277 	Encodes the 'User-agent' header
       
   278 	*/
       
   279 	//##ModelId=3C4C41A601A9
       
   280 	void EncodeUserAgentL(RHeaderField& aHeader) const;
       
   281 
       
   282 	/**
       
   283 	Encodes the 'Via' header
       
   284 	*/
       
   285 	//##ModelId=3C4C41A601A0
       
   286 	void EncodeViaL(RHeaderField& aHeader) const;
       
   287 
       
   288 	/**
       
   289 	Encodes the 'Warning' header
       
   290 	*/
       
   291 	//##ModelId=3C4C41A6019E
       
   292 	void EncodeWarningL(RHeaderField& aHeader) const;
       
   293 
       
   294 	/**
       
   295 	Encodes the 'X-Wap-Application-Id' header
       
   296 	*/
       
   297 	//##ModelId=3C4C41A60195
       
   298 	void EncodeXWapApplicationIdL(RHeaderField& aHeader) const;
       
   299 
       
   300 // Generic encoding methods
       
   301  
       
   302 	/**
       
   303 	Encodes generic headers that have a date value
       
   304 	*/
       
   305 	//##ModelId=3C4C41A6018C
       
   306 	void GenericEncodeDateL(RHeaderField& aHeader) const;
       
   307 
       
   308 	/**
       
   309 	Encodes generic headers that have a text string value
       
   310 	*/
       
   311 	//##ModelId=3C4C41A6018A
       
   312 	void GenericEncodeTextStringL(RHeaderField& aHeader) const;
       
   313 
       
   314 // Helper methods
       
   315 
       
   316 	/**
       
   317 	Encodes a parameter value. The method returns a heap based descriptor containing
       
   318 	the encoded buffer. The caller takes ownership of the buffer.
       
   319 	*/
       
   320 	//##ModelId=3C4C41A60180
       
   321 	void EncodeParameterL(const CHeaderFieldParam& aHeaderFieldParam, CWspHeaderEncoder& aEncoder) const;
       
   322  
       
   323 	/**
       
   324 	Encodes a single 'Q' value. The method returns a heap based descriptor containing
       
   325 	the encoded buffer. The caller takes ownership of the buffer.
       
   326 	*/
       
   327 	//##ModelId=3C4C41A60177
       
   328 	HBufC8* EncodeQValueL(RStringF aQValue) const;
       
   329 
       
   330 	/**
       
   331 	Encodes a single version value. The method returns the encoded version value of the
       
   332 	version passed in as a parameter in a string format. The method will return 0 if
       
   333 	the version should be encoded as a text-value.
       
   334 	*/
       
   335 	//##ModelId=3C4C41A6016E
       
   336 	TUint8 EncodeVersionValueL(RStringF aVersionValue) const;
       
   337 
       
   338 	/**
       
   339 	Encodes a header name. The method returns an integer value of the length of the
       
   340 	header name.
       
   341 	*/
       
   342 	//##ModelId=3C4C41A60164
       
   343 	TInt EncodeHeaderNameL(RHeaderField& aHeader) const;
       
   344 
       
   345 	/**
       
   346 	Encodes a single character set value. The method returns the encoded charset value
       
   347 	of the passed in string.
       
   348 	*/
       
   349 	//##ModelId=3C4C41A60150
       
   350 	TInt GetCharacterSetValue(RStringF aCharSet) const;
       
   351 
       
   352 	/**
       
   353 	Checks the passed in string for any invalid characters as specified in RFC2616.
       
   354 	*/
       
   355 	//##ModelId=3C4C41A6014E
       
   356 	TInt CheckTokenText(RStringF aTokenText) const;
       
   357 
       
   358 	/**
       
   359 	Checks the passed in string for any invalid characters as specified in RFC2616.
       
   360 	*/
       
   361 	//##ModelId=3C4C41A60144
       
   362 	TInt CheckTextString(RStringF aTextString) const;
       
   363 
       
   364 	/**
       
   365 	Gets encoding for content-type text value with correct WSP version control.
       
   366 	Returns KErrNotFound if no encoding is available
       
   367 	*/
       
   368 	TInt EncodeContentTypeValue(THTTPHdrVal& aContentType) const;
       
   369 
       
   370 	TInt EncodeParameterTokenValue(RStringF aParameterName) const;
       
   371 
       
   372 
       
   373 private: // attributes
       
   374 
       
   375 	//##ModelId=3C4C41A6013C
       
   376 	RStringPool iStrPool;
       
   377 
       
   378 	//##ModelId=3C4C41A60130
       
   379 	const TStringTable& iStrTable;
       
   380 
       
   381 	//##ModelId=3C4C41A6011F
       
   382 	CWspHeaderCodec& iCodec;
       
   383 	};
       
   384 
       
   385 /**
       
   386 @since			7.0
       
   387 This class provides the encoding functionality for headers that are supported
       
   388 by the WSP Header Codec. This encoder provides default functionality and 
       
   389 encodes the header field as a text-string as defined in the WSP specifications
       
   390 at www.wapforum.org.
       
   391 */
       
   392 class CWspDefaultHdrWriter : public CHeaderWriter
       
   393 	{
       
   394 public: // methods
       
   395 
       
   396 	/**
       
   397 	Standard virtual destructor
       
   398 	@since			7.0
       
   399 	@pre 			Fully constructed object
       
   400 	@post			Object is destroyed
       
   401 	*/
       
   402 	virtual ~CWspDefaultHdrWriter();
       
   403 
       
   404 	/**
       
   405 	Standard factory 2 phase construction
       
   406 	Error Condition: Low memory conditions
       
   407 	@since			7.0
       
   408 	@param			aStrPool Handle to an opened string pool with the WSP string table already opened
       
   409 	@return			A pointer to the newly constructed class
       
   410 	@pre 			None
       
   411 	@post			Object is constructed
       
   412 	*/
       
   413 	static CWspDefaultHdrWriter* NewL(RStringPool aStrPool);
       
   414 
       
   415 	/**
       
   416 	Standard factory 2 phase construction leaving a handle on the cleanup stack.
       
   417 	Error Condition: Low memory conditions
       
   418 	@since			7.0
       
   419 	@param			aStrPool Handle to an opened string pool with the WSP string table already opened
       
   420 	@return			A pointer to the newly constructed class
       
   421 	@pre 			None
       
   422 	@post			Object is constructed with a handle on the cleanup stack
       
   423 	*/
       
   424 	static CWspDefaultHdrWriter* NewLC(RStringPool aStrPool);
       
   425 
       
   426 	/**
       
   427 	This method will encode the header field that is passed in into its raw
       
   428 					form.
       
   429 	Error Condition: Invalid or corrupt data formats and out of memeory conditions
       
   430 	@since			7.0
       
   431 	@param			aHeader The header field to encode
       
   432 	@pre 			The header field is in its parsed state
       
   433 	@post			The header field is in its raw format state
       
   434 	@leave		KErrNotSupported If the header field is not supported
       
   435 					KErrNoMemory Out of memory conditions
       
   436 					KErrCorrupt If the data is invalid or is corrupt
       
   437 	*/
       
   438 	virtual void EncodeHeaderL(RHeaderField& aHeader);
       
   439 
       
   440 protected: // methods
       
   441 
       
   442 	/**
       
   443 	Standard default constructor.
       
   444 	@since			7.0
       
   445 	@param			aStrPool Handle to an opened string pool with the WSP string table already opened
       
   446 	@pre 			None
       
   447 	@post			Object is constructed
       
   448 	*/
       
   449 	CWspDefaultHdrWriter(RStringPool aStrPool);
       
   450 
       
   451 private: // attributes
       
   452 
       
   453 	RStringPool iStrPool;
       
   454 	};
       
   455 
       
   456 #endif // __CWSPHEADERWRITER_H__