servicediscoveryandcontrol/pnp/test/upnp/upnpmessage/inc/CHeaders.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 // Copyright (c) 2008-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 __CHEADERS_H__
       
    17 #define __CHEADERS_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <stringpool.h>
       
    21 
       
    22 
       
    23 class CHeaderField;
       
    24 class CHeaderFieldPart;
       
    25 class CHeaderFieldParam;
       
    26 class CHeaderCodec;
       
    27 class RHTTPHeaders;
       
    28 class THTTPHdrFieldIter;
       
    29 class THTTPHdrVal;
       
    30 
       
    31 
       
    32 /** The CHeaders class provides the internal implementation of the RHTTPHeaders interface, which is
       
    33 	documented in <http.h>.  Briefly, this interface provides a unified point at which all header data
       
    34 	can	be read and written for a given request or response.  The CHeaders object is related to an
       
    35 	instance of a specific CHTTPTransactionCodec subclass, which is used to provide on-demand decoding
       
    36 	and encoding of indivual header fields.
       
    37 	@see RHTTPHeaders
       
    38 */
       
    39 class CHeaders : public CBase
       
    40 	{
       
    41 friend class THTTPHdrFieldIter;
       
    42 public:
       
    43  	
       
    44 	// Factory construction, given a particular codec.  Ownership of the codec remains with the caller.
       
    45 	static CHeaders* NewL(CHeaderCodec& aCodec);
       
    46 
       
    47  	// Destructor. Cleans up and releases resources to the system.
       
    48 	~CHeaders();
       
    49 
       
    50 	// Creates a handle that is an abstraction of the interface
       
    51 	RHTTPHeaders Handle();
       
    52 
       
    53 public: // methods proxied from RHTTPHeaders
       
    54 
       
    55 	// Create or append a field part for the named field and assigned value
       
    56 	void SetFieldL(RStringF aFieldName, THTTPHdrVal aFieldValue);
       
    57 
       
    58 	// Create or append a field part with parameter, for the specified field, parameter and associated values
       
    59 	void SetFieldL(RStringF aFieldName, THTTPHdrVal aFieldValue,
       
    60 				   RStringF aParamName, THTTPHdrVal aParamValue);
       
    61 
       
    62 	// Create a parameter in an exisitng part
       
    63 	void SetParamL(RStringF aFieldName, RStringF aParamName,THTTPHdrVal aParamValue,  TInt aPartIdx);
       
    64 
       
    65 	// Set a named field in the header to contain the supplied OTA data. Any existing header field of
       
    66 	// this name will be lost.
       
    67 	void SetRawFieldL(RStringF aFieldName, const TDesC8& aOtaFieldData, const TDesC8& aFieldSeparator);
       
    68 
       
    69 	// Remove, entirely, the named header field from the header collection. All its parts and
       
    70 	// associated parameters (where they exist) are also removed
       
    71 	TInt RemoveField(RStringF aFieldName);
       
    72 
       
    73 	// Remove the particular part of a field. All its parameters ,where they exist, are removed. If this is the only part
       
    74 	// then the header is also removed
       
    75 	TInt RemoveFieldPartL(RStringF aFieldName, TInt aIndex);
       
    76 
       
    77 
       
    78 	// Remove all the fields in this header collection
       
    79 	void RemoveAllFields();
       
    80 
       
    81 	// Obtain the number of parts in the named header field's value, Simple headers are created with a single part
       
    82 	// following one call to SetFieldL. Subsequent calls to SetFieldL create additional parts with the field exists
       
    83 	// already
       
    84 	TInt FieldPartsL(RStringF aFieldName) const;
       
    85 
       
    86 	// Obtain the named header field's value.  Optionally, the index of a part within the field
       
    87 	// may be specified. Parts are indexed from zero
       
    88 	 TInt GetField(RStringF aFieldName, TInt aPartIdx, THTTPHdrVal& aHeaderValue) const;
       
    89 
       
    90 	// Obtain an Over-The-Air representation of the named header field's value.
       
    91 	TInt GetRawField(RStringF aFieldName, TPtrC8& aRawFieldData) const;
       
    92 
       
    93 
       
    94 	// Obtain the value of a named parameter, associated with the named header field.  An optional index to a part
       
    95 	// within the header field may be supplied, if not it is assumed that it is the first part
       
    96 	THTTPHdrVal GetParam(RStringF aFieldName, RStringF aParamName, THTTPHdrVal& aValue, TInt aPartIdx) const;
       
    97 
       
    98 	// Access the header fields via an iterator
       
    99 	THTTPHdrFieldIter Fields() const;
       
   100 
       
   101 	// Access the codec used to convert header fields between OTA and parsed format
       
   102 	CHeaderCodec& Codec() const;
       
   103 
       
   104 	static const TStringTable& Table();
       
   105 
       
   106 private:
       
   107 
       
   108 	// Structure which contains the headerfield and the associated name
       
   109 	class THeaderFieldNamePair
       
   110 		{
       
   111 	public:
       
   112 		static TInt CompareFieldNames(const THeaderFieldNamePair& aField1, const THeaderFieldNamePair& aFieldName2);
       
   113 	public:
       
   114 		RStringF iFieldName;
       
   115 		CHeaderField* iField;
       
   116 		};
       
   117 
       
   118 	
       
   119 	// Constructor; stores the supplied codec pointer
       
   120 	CHeaders(CHeaderCodec& aCodec);
       
   121 
       
   122 	// Utility to look up a given header name from the iFieldNames array and return its index.
       
   123 	TInt LocateFieldName(RStringF aHeaderName) const;
       
   124 
       
   125 	// Looks up the given header name and returns the corresponding field if it exists; if not, a new field
       
   126 	// is created and returned
       
   127 	CHeaderField& CreateOrLookupFieldL(RStringF aHeaderName);
       
   128 
       
   129 	// Obtains the indexed part of the named field
       
   130 	CHeaderFieldPart* GetFieldPartL(RStringF aFieldName, TInt aPartIdx) const;
       
   131 
       
   132 	// Obtains the index parameter of the named field's indexed part
       
   133 	CHeaderFieldParam* GetFieldParameter(RStringF aFieldName, RStringF aParamName, TInt aPartIdx) const;
       
   134 
       
   135 	// Inserts a header in the order of the name.
       
   136 	void DoInsertInNameOrderL(CHeaderField* aHeader, RStringF aHeaderName);
       
   137 
       
   138 	// Deletes all fields
       
   139 	void PurgeFields();
       
   140 	
       
   141 private:
       
   142 
       
   143 	// An array of field name pairs. Each field contains several values that is associated with a name of a field
       
   144 	RArray<THeaderFieldNamePair> iFields;
       
   145 
       
   146 	// The transaction codec associated with this header collection.
       
   147 	CHeaderCodec& iCodec;
       
   148 	};
       
   149 
       
   150 
       
   151 inline CHeaders::CHeaders(CHeaderCodec& aCodec)
       
   152 	: iCodec(aCodec)
       
   153 	{
       
   154 	}
       
   155 
       
   156 inline CHeaderCodec& CHeaders::Codec() const
       
   157 	{
       
   158 	return iCodec;
       
   159 	}
       
   160 
       
   161 #endif // CMESSAGE_H