vpnui/vpnpolins/inc/cmdfileparser.h
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2007 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:   Handles VPN command file parsing.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_VPNCOMMANDFILEPARSER_H
       
    22 #define C_VPNCOMMANDFILEPARSER_H
       
    23 
       
    24 #include <e32base.h>
       
    25 
       
    26 /**
       
    27  * Parser utility class for VPN command file (.vpn).
       
    28  * Public interface offers functions for parsing
       
    29  * and querying the parsed values. 
       
    30  * Internal implementation parses XML tree and extracts
       
    31  * found parameters to local container.
       
    32  *
       
    33  */
       
    34 class CCmdFileParser : public CBase 
       
    35     {
       
    36 // C'tors
       
    37 public:
       
    38     /**
       
    39      * No need for two-phased construction
       
    40      */
       
    41     CCmdFileParser();
       
    42     ~CCmdFileParser();
       
    43 
       
    44 // Public functions
       
    45 public:
       
    46     /**
       
    47      * Parse an XML file and store parsed variables to local
       
    48      * structures.
       
    49      *
       
    50      * @param aInputData XML file in 8bit desc buffer.
       
    51      *
       
    52      * @leave Leaves with KErrCorrupt, if the data is not in 
       
    53      *        expected format.
       
    54      */
       
    55     void    ParseL(const TDesC8& aInputData);
       
    56 
       
    57     /**
       
    58      * Returns the a parsed string value. Control of the instantiated
       
    59      * object is transferred to the caller. If no value is found,
       
    60      * returns a NULL object.
       
    61      *
       
    62      * @param aUri The "full uri" of the requested value
       
    63      *
       
    64      * @ret HBufC* A pointer to a newly allocated 16bit descriptor containing
       
    65      *      the parsed value, or NULL if none found.
       
    66      *
       
    67      * @leave Leaves in case 
       
    68      */
       
    69     HBufC*  GetParsedValueStrL(const TDesC8& aUri);
       
    70     
       
    71     /**
       
    72      * Translates a parsed value to TInt and returns it.
       
    73      * Leaves if the operation cannot be accomplished.
       
    74      *
       
    75      * @param aUri The "full uri" of the requested value
       
    76      * @param aVal Used for TInt return value (if any)
       
    77      *
       
    78      * @leave Leaves if the operation fails.
       
    79      */
       
    80     void    GetParsedValueIntL(const TDesC8& aUri, TInt& aVal);
       
    81 
       
    82     /**
       
    83      * Translates a parsed value to TBool and returns it.
       
    84      * Leaves if the operation cannot be accomplished.
       
    85      *
       
    86      * @param aUri The "full uri" of the requested value
       
    87      * @param aVal Used for TBool return value (if any)
       
    88      *
       
    89      * @leave Leaves if the operation fails.
       
    90      */
       
    91     void    GetParsedValueBoolL(const TDesC8& aUri, TBool& aVal);
       
    92 
       
    93 private:
       
    94     void    ReleaseResources();
       
    95     
       
    96     /**
       
    97      * Parse the input XML
       
    98      *
       
    99      */
       
   100     void    ParseXmlL(const TDesC8& aInputData);
       
   101 
       
   102     /**
       
   103      * Checks whether the encountered "closing" XML node is indeed 
       
   104      * the most recently opened.
       
   105      *
       
   106      * @param aName The name to check
       
   107      *
       
   108      * @return ETrue, iff the given name was found on the top 
       
   109      *         of the iParserStack
       
   110      *
       
   111      */
       
   112     TBool       IsTopmostNode(const TDesC8& aName) const;
       
   113 
       
   114     /**
       
   115      * Pushes an "opening" XML node on the parser stack. 
       
   116      * Instantiates a new stack object based on the given name.
       
   117      *
       
   118      * @param aName The name of the object to push
       
   119      *
       
   120      * @leave Leaves if OOM.
       
   121      */
       
   122     void        PushNodeL(const TDesC8& aName);
       
   123 
       
   124     /**
       
   125      * Pops the topmost node from the parser stack. 
       
   126      * No questions asked.
       
   127      *
       
   128      */
       
   129     void        PopNode();
       
   130 
       
   131     /**
       
   132      * Constructs a new string, containing the full "URI"
       
   133      * for the given text. It is assumed that the text is
       
   134      * located inside the node that is currently open (i.e.
       
   135      * on the top of the parser stack).
       
   136      * URI is of form "root/branch1/branch6/aText".
       
   137      *
       
   138      * @aText The text in the leafnode -- the last segment 
       
   139      *        of the uri
       
   140      *
       
   141      * @return Returns a new string containing the full uri
       
   142      *         of the leaf (text) node.
       
   143      *
       
   144      * @leave Leaves if OOM
       
   145      *
       
   146      */
       
   147     HBufC8*     ParseTreeUriL(const TDesC8& aText) const;
       
   148     
       
   149     /**
       
   150      * Checks whether the text segment in XML is valid. 
       
   151      * If it begins with CR/LF, it's not.
       
   152      *
       
   153      * @param aText The text to verify.
       
   154      *
       
   155      * @return ETrue only if the text is valid in that
       
   156      *         it's not a string beginning with CR/LF
       
   157      *
       
   158      */
       
   159     TBool       IsValidText(const TDesC8& aText) const;
       
   160 
       
   161     /**
       
   162      * Iterates through parsed values array and checks whether
       
   163      * the given URI is found. If it is, returns the leaf
       
   164      * value of the uri.
       
   165      * URI here must end with slash ("/"), so it must not contain
       
   166      * the related leaf node itself (representing the parameter's 
       
   167      * textual value).
       
   168      * Example: FindUri("root/node1/node2/") will return "666"
       
   169      * if there exists a URI "root/node1/node2/666" in the parsed
       
   170      * values array.
       
   171      *
       
   172      * @return A pointer to the found value or KNullDesC8 if none
       
   173      *         was found. 
       
   174      * 
       
   175      */
       
   176     TPtrC8      FindUri(const TDesC8& aUri) const;
       
   177 
       
   178 
       
   179 // Private variables
       
   180 private:
       
   181     HBufC*                          iFileName;
       
   182     HBufC*                          iFileContents;
       
   183     HBufC*                          iPKCS12Pwd;
       
   184     TInt                            iDevLockPolicy;
       
   185     TBool                           iDevLockRequired;
       
   186     TBool                           iParseReady;
       
   187 
       
   188     // Parser stack consisting of parse tree nodes
       
   189     CArrayFixFlat<HBufC8*>*         iParserStack;
       
   190 
       
   191     // Parsed stack, consisting of leaf values and their full
       
   192     // tree paths (root/branch1/branch6/leaf_value)
       
   193     CArrayFixFlat<HBufC8*>*         iParsedValuesArray;
       
   194     };
       
   195 
       
   196 #endif // C_VPNPOLICYINSTALLER_H
       
   197