pkiutilities/ocsp/test/t_input.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __T_INPUT_H__
       
    20 #define __T_INPUT_H__
       
    21 
       
    22 #include <e32cons.h>
       
    23 #include <f32file.h>
       
    24 #include <e32std.h>
       
    25 
       
    26 /**
       
    27  * This class provides useful functions to read and parse the input file.
       
    28  */
       
    29 class Input
       
    30 	{
       
    31 public: // static functions no object required
       
    32 	/*
       
    33 	Parses the parameters aBuf to find the section of the script within parameters aStart and aEnd
       
    34 	NB use these if you want just want to use the result temporarily, because it just points
       
    35 	to the result in aBuf
       
    36 
       
    37 	Parameters
       
    38 	const TDesC& aBuf	[IN] - Buffer to search
       
    39 	const TDesC& aStart	[IN] - Start tag t be searched for
       
    40 	const TDesC& aEnd   [IN] - (Optional)End tag t be searched for (Optional, if not supplied function will default aStart with a / i.e. if aStart <tag> aEnd will be </tag>
       
    41 	TInt& aPos			[IN/OUT]- (Optional)Position in buffer to start searching, this will be updated with the position after the search (Optional) default zero 
       
    42 	TInt& aError		[OUT]- (Optional)Returns negative number if start tag cannot be found (Optional)
       
    43 
       
    44 	Returns
       
    45 	TPtrC		- Returns a TPtr to the position in the buffer between the start and end tags
       
    46 	*/
       
    47 	// base functions for parsing tokens in scripts, but better to use functions below
       
    48 	IMPORT_C static TPtrC8 ParseElement(const TDesC8& aBuf, const TDesC8& aStart);
       
    49 	IMPORT_C static TPtrC8 ParseElement(const TDesC8& aBuf, const TDesC8& aStart, const TDesC8& aEnd);
       
    50 	IMPORT_C static TPtrC8 ParseElement(const TDesC8& aBuf, const TDesC8& aStart, const TDesC8& aEnd, TInt& aPos);
       
    51 	IMPORT_C static TPtrC8 ParseElement(const TDesC8& aBuf, const TDesC8& aStart, const TDesC8& aEnd, TInt& aPos, TInt& aError);
       
    52 	IMPORT_C static TPtrC16 ParseElement(const TDesC16& aBuf, const TDesC16& aStart, const TDesC16& aEnd);
       
    53 	IMPORT_C static TPtrC16 ParseElement(const TDesC16& aBuf, const TDesC16& aStart, const TDesC16& aEnd, TInt& aPos);
       
    54 	IMPORT_C static TPtrC16 ParseElement(const TDesC16& aBuf, const TDesC16& aStart, const TDesC16& aEnd, TInt& aPos, TInt& aError);
       
    55 	IMPORT_C static TPtrC ParseElement(const TDesC& aBuf, const TDesC& aStart);
       
    56 	IMPORT_C static TPtrC ParseElement(const TDesC& aBuf, const TDesC& aStart, TInt& aPos);
       
    57 	IMPORT_C static TPtrC ParseElement(const TDesC& aBuf,  const TDesC& aStart, TInt& aPos, TInt& aError);
       
    58 	/**
       
    59 	 * Reads the between the start and end tags assuming the data is in ASCII
       
    60 	 * hex format.  Returns an HBufC8* which is a binary representation of that
       
    61 	 * ASCII hex.  (ie a string of length 6 becomes a string of length 3)
       
    62 	 */
       
    63 	IMPORT_C static HBufC8* ParseElementHexL(const TDesC8& aBuf, const TDesC8& aStart);
       
    64 	/**
       
    65 	 * Returns ETrue if the the value was "True" or "ETrue" and returns EFalse
       
    66 	 * if the value was "False" or "EFalse" (case insensitive comparisons all
       
    67 	 * round).  Leaves if none of the above is true 
       
    68 	 */
       
    69 	IMPORT_C static TBool ParseElementBoolL(const TDesC8& aBuf, const TDesC8& aStart);
       
    70 	/**
       
    71 	 * Parses the parameters aBuf to find the section of the script within
       
    72 	 * parameters aStart and aEnd, and parses the contants as an integer.  Both
       
    73 	 * decimal ('123') and hex ('0x7b') format strings are supported.
       
    74 	 *
       
    75 	 * @param aBuf		[IN] - Buffer to search
       
    76 	 * @param aStart	[IN] - Start tag t be searched for
       
    77 	 * @param aEnd   	[IN] - (Optional)End tag t be searched for (Optional, if not supplied function will default aStart with a / i.e. if aStart <tag> aEnd will be </tag>
       
    78 	 * @param aPos		[IN/OUT]- (Optional)Position in buffer to start searching, this will be updated with the position after the search (Optional) default zero 
       
    79 	 * @param aError	[OUT]- (Optional)Returns negative number if start tag cannot be found (Optional)
       
    80 	 *
       
    81 	 * @return The parsed integer value, or zero.
       
    82 	 */
       
    83 	IMPORT_C static TUint ParseIntElement(const TDesC8& aBuf, const TDesC8& aStart, const TDesC8& aEnd);
       
    84 	IMPORT_C static TUint ParseIntElement(const TDesC8& aBuf, const TDesC8& aStart, const TDesC8& aEnd, TInt& aPos);
       
    85 	IMPORT_C static TUint ParseIntElement(const TDesC8& aBuf, const TDesC8& aStart, const TDesC8& aEnd, TInt& aPos, TInt& aError);
       
    86 	IMPORT_C static TUint ParseIntElement(const TDesC16& aBuf, const TDesC16& aStart, const TDesC16& aEnd);
       
    87 	IMPORT_C static TUint ParseIntElement(const TDesC16& aBuf, const TDesC16& aStart, const TDesC16& aEnd, TInt& aPos);
       
    88 	IMPORT_C static TUint ParseIntElement(const TDesC16& aBuf, const TDesC16& aStart, const TDesC16& aEnd, TInt& aPos, TInt& aError);
       
    89 	IMPORT_C static TUint ParseIntElement(const TDesC& aBuf, const TDesC& aStart);
       
    90 	IMPORT_C static TUint ParseIntElement(const TDesC& aBuf, const TDesC& aStart, TInt& aPos);
       
    91 	IMPORT_C static TUint ParseIntElement(const TDesC& aBuf,  const TDesC& aStart, TInt& aPos, TInt& aError);
       
    92 	/*
       
    93 	Searches the list of standard error codes (e32err.h 0 to -46) finding the matching error code for the string 
       
    94 
       
    95 	Parameters
       
    96 	const TDesC& aResult  	[IN] - Error code string to be searched from
       
    97 	TInt &aError 	 		[OUT] - Matching error code if found
       
    98 
       
    99 	Returns
       
   100 	TBool			- True if error code was found, False if it was not
       
   101 	*/
       
   102 	IMPORT_C static TBool GetExpectedResultL(const TDesC& aResult /*in*/, TInt &aError /*out*/);
       
   103 	/*
       
   104 	Searches the list of standard error codes (e32err.h 0 to -46) finding the matching text representaion of the error code
       
   105 
       
   106 	Parameters
       
   107 	 TInt &aError 	 	[IN] - Error code to return the string of
       
   108 	HBufC*& aResult   	[OUT] -Reference to a pointer, pointing to the error string of the matching error code (Dont forget to free it)
       
   109 
       
   110 	Returns
       
   111 	TBool			- True if error code was found, False if it was not
       
   112 	*/
       
   113 	IMPORT_C static TBool GetExpectedResultL(const TInt &aError /*in*/, HBufC*& aResult /*out*/);
       
   114 	/*
       
   115 	Parses the parameters aBuf to find the section of the script within parameters aStart and aEnd, 
       
   116 	then allocs the required memory and places a copy of this section in aMember
       
   117 	use these if you want the result copied into a new area of memory to use, for example when
       
   118 	stored a member data
       
   119 
       
   120 	Parameters
       
   121 	HBufC*& aMember		[OUT] - Reference to a pointer that will point to a copy of the section of aBuf 
       
   122 	const TDesC& aBuf	[IN] - Buffer to search
       
   123 	const TDesC& aStart	[IN] - Start tag t be searched for
       
   124 	const TDesC& aEnd   [IN] - (Optional) End tag t be searched for (, if not supplied function will default aStart with a / i.e. if aStart <tag> aEnd will be </tag>
       
   125 	TInt& aPos			[IN/OUT]- (Optional) Position in buffer to start searching, this will be updated with the position after the search (Optional) default zero 
       
   126 	TInt& aError		[OUT]- (Optional) Returns negative number if start tag cannot be found (Optional)
       
   127 
       
   128 	Returns
       
   129 	TPtrC		- Returns a TPtr to the position in the buffer between the start and 
       
   130 	end tags
       
   131 	*/
       
   132 	IMPORT_C static void ParseElementL(HBufC*& aMember, const TDesC& aBuf, 
       
   133 		const TDesC& aStart);
       
   134 	IMPORT_C static void ParseElementL(HBufC8*& aMember, const TDesC& aBuf, 
       
   135 		const TDesC& aStart);
       
   136 	IMPORT_C static void ParseElementL(HBufC*& aMember, const TDesC& aBuf,
       
   137 		const TDesC& aStart, TInt& aPos);
       
   138 	IMPORT_C static void ParseElementL(HBufC8*& aMember, const TDesC& aBuf,
       
   139 		const TDesC& aStart, TInt& aPos);
       
   140 	IMPORT_C static void ParseElementL(HBufC*& aMember, const TDesC& aBuf,  
       
   141 		const TDesC& aStart, TInt& aPos, TInt& aError);
       
   142 	IMPORT_C static void ParseElementL(HBufC8*& aMember, const TDesC& aBuf,  
       
   143 		const TDesC& aStart, TInt& aPos, TInt& aError);
       
   144 	/*
       
   145 	Reads an entire file into memory into a HBuf8
       
   146 
       
   147 	Parameters
       
   148 	const TDesC& aFilename 	[IN] - Name of file to read
       
   149 	const TDesC& aPath		[IN] - (Optional) Path of file, if aPath is missing the path is taken from aFilename
       
   150 	RFs &aFs				[IN] - Reference to the file system handle class
       
   151 
       
   152 	Returns
       
   153 	HBufC8*		-  Pointer to the 8 bit file data
       
   154 	*/
       
   155 	IMPORT_C static HBufC8* ReadFileL(const TDesC& aFilename, RFs& aFs);
       
   156 	IMPORT_C static HBufC8* ReadFileL(const TDesC& aFilename, const TDesC& aPath, RFs& aFs);
       
   157 	IMPORT_C static HBufC8* ReadFileLC(const TDesC& aFilename, RFs& aFs);
       
   158 	IMPORT_C static HBufC8* ReadFileLC(const TDesC& aFilename, const TDesC& aPath, RFs& aFS);
       
   159 	/*
       
   160 	Reads a ascii hex file into a binary HBufC i.e. a file containing "FFAA11" will be converted into a 3 byte buffer
       
   161 
       
   162 	Parameters
       
   163 	const TDesC& aFilename 	[IN] - Name of file including path to read
       
   164 	RFs &aFs			[IN] - Reference to the file system handle class
       
   165 
       
   166 	Returns
       
   167 	HBufC8*		-  Pointer to the 8 bit file data
       
   168 	*/
       
   169 	IMPORT_C static HBufC8* ReadHexFileLC(const TDesC& aFilename, RFs& aFs);
       
   170 	/**
       
   171 	 * This function reads an entire Unicode file and returns it as an HBufC.
       
   172 	 * This function only works for Unicode builds of EPOC.
       
   173 	 */
       
   174 	IMPORT_C static HBufC* ReadFile16LC(const TDesC& aFilename, RFs& aFS);
       
   175 	/*
       
   176 	Parses the parameters aBuf to find multiple sections of the script within parameters aStart and aEnd, then adds them to the aElements list
       
   177 	For instance, if the aBuf argument is <StartTag>abc<EndTag><StartTag>xyz<EndTag>,  then aElements will contain 2 elements: abc and xyz.
       
   178 
       
   179 	const TDesC& aBuf	[IN] - Buffer to search
       
   180 	const TDesC& aStart	[IN] - Start tag to be searched for
       
   181 	const TDesC& aEnd   [IN]- End tag t be searched for
       
   182 	RPointerArray<HBufC>& aElements [OUT] - Array of sections found
       
   183 	TInt& aPos		[IN/OUT]- Position in buffer to start searching, this will be updated with the position after the search
       
   184 
       
   185 	Returns
       
   186 	None
       
   187 	 */
       
   188 	IMPORT_C static void ParseElementListL(const TDesC& aBuf, const TDesC& aStart, const TDesC& aEnd, 
       
   189 		RPointerArray<HBufC>& aElements, TInt& aPos);
       
   190 
       
   191 	
       
   192 	/**
       
   193 	 * Parse a string containg a capability name.
       
   194 	 * @leave KErrArgument If the string is not a recognised capability name.
       
   195 	 */
       
   196 	IMPORT_C static TCapability ParseCapabilityNameL(const TDesC8& aName);
       
   197 	
       
   198 	/**
       
   199 	 * Parse a section of script file describing a capability set.
       
   200 	 * 
       
   201 	 * The script contains zero or more capabilities contained in <capability>
       
   202 	 * tags.
       
   203 	 */
       
   204 	IMPORT_C static void ParseCapabilitySetL(const TDesC8& aIn, TCapabilitySet& aOut);
       
   205 
       
   206 	/**
       
   207 	 * Parse a section of script file describing a security policy.
       
   208 	 * 
       
   209 	 * The script contains zero or more capabilities contained in <capability>
       
   210 	 * tags.
       
   211 	 */
       
   212 	IMPORT_C static void ParseSecurityPolicyL(const TDesC8& aIn, TSecurityPolicy& aOut);
       
   213 	
       
   214 	};
       
   215 
       
   216 #endif