eapol/eapol_framework/eapol_common/am/include/eap_file_config.h
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 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 the License "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:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef _FILECONFIG_H
       
    21 #define _FILECONFIG_H
       
    22 
       
    23 #include "eap_core_map.h"
       
    24 #include "eap_configuration_field.h"
       
    25 #include "abs_eap_am_file_input.h"
       
    26 
       
    27 
       
    28 template <class Type>
       
    29 Type minimum( Type a, Type b )
       
    30 {
       
    31 	return a < b ? a : b;
       
    32 }
       
    33 
       
    34 
       
    35 class eap_config_value_c
       
    36 {
       
    37 private:
       
    38 
       
    39 	abs_eap_am_tools_c* const m_am_tools;
       
    40 
       
    41 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * m_subsection_map;
       
    42 
       
    43 	eap_variable_data_c m_data;
       
    44 
       
    45 	eap_configure_type_e m_type;
       
    46 
       
    47 	bool m_is_valid;
       
    48 
       
    49 public:
       
    50 
       
    51 	virtual ~eap_config_value_c();
       
    52 
       
    53 	eap_config_value_c(
       
    54 		abs_eap_am_tools_c* const tools);
       
    55 
       
    56 	void set_subsection(
       
    57 		eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const subsection_map);
       
    58 
       
    59 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * get_subsection();
       
    60 
       
    61 	eap_variable_data_c * get_data();
       
    62 
       
    63 	void set_type(const eap_configure_type_e type);
       
    64 
       
    65 	eap_configure_type_e get_type();
       
    66 
       
    67 	void object_increase_reference_count();
       
    68 
       
    69 	bool get_is_valid();
       
    70 
       
    71 };
       
    72 
       
    73 const u32_t MAX_LINE_LENGTH = 1024;
       
    74 const u32_t MAX_CONFIG_TYPE_LENGTH = 32;
       
    75 
       
    76 
       
    77 struct eap_configure_type
       
    78 {
       
    79 	char id[MAX_CONFIG_TYPE_LENGTH];
       
    80 	u32_t id_length;
       
    81 	eap_configure_type_e type;
       
    82 };
       
    83 
       
    84 
       
    85 const char * const EAP_FILECONFIG_TRUE = "true";
       
    86 const char * const EAP_FILECONFIG_FALSE = "false";
       
    87 
       
    88 
       
    89 const char EAP_FILECONFIG_SECTION[] = "section:";
       
    90 const u32_t EAP_FILECONFIG_SECTION_LENGTH = (sizeof(EAP_FILECONFIG_SECTION)-1ul);
       
    91 
       
    92 const char EAP_FILECONFIG_SECTION_START[] = "{";
       
    93 const u32_t EAP_FILECONFIG_SECTION_START_LENGTH = (sizeof(EAP_FILECONFIG_SECTION_START)-1ul);
       
    94 
       
    95 const char EAP_FILECONFIG_SECTION_END[] = "}";
       
    96 const u32_t EAP_FILECONFIG_SECTION_END_LENGTH = (sizeof(EAP_FILECONFIG_SECTION_END)-1ul);
       
    97 
       
    98 
       
    99 /// Keep this on the same order as eap_configure_type_e.
       
   100 const eap_configure_type eap_configure_type_id[] =
       
   101 {
       
   102 	{
       
   103 		"none:", 
       
   104 		5u, 
       
   105 		eap_configure_type_none
       
   106 	},
       
   107 	{
       
   108 		"u32_t:", 
       
   109 		6u, 
       
   110 		eap_configure_type_u32_t
       
   111 	},
       
   112 	{
       
   113 		"bool:", 
       
   114 		5u, 
       
   115 		eap_configure_type_boolean
       
   116 	},
       
   117 	{
       
   118 		"string:", 
       
   119 		7u, 
       
   120 		eap_configure_type_string
       
   121 	},
       
   122 	{
       
   123 		"hex:", 
       
   124 		4u, 
       
   125 		eap_configure_type_hex_data
       
   126 	},
       
   127 	{
       
   128 		"u32array:", 
       
   129 		9u, 
       
   130 		eap_configure_type_u32array
       
   131 	},
       
   132 };
       
   133 
       
   134 
       
   135 class EAP_EXPORT eap_file_config_c
       
   136 : public abs_eap_core_map_c
       
   137 {
       
   138   
       
   139  private:
       
   140 	abs_eap_am_tools_c* const m_am_tools;
       
   141 
       
   142 	/// This stores eap_config_value_c objects using eap_variable_data selector.
       
   143 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> m_config_map;
       
   144 
       
   145 	bool m_is_valid;
       
   146 
       
   147 	EAP_FUNC_IMPORT eap_status_e expand_environment_variables(
       
   148 		eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
       
   149 		const eap_variable_data_c * const value,
       
   150 		eap_variable_data_c * const expanded_value
       
   151 		);
       
   152 
       
   153 	EAP_FUNC_IMPORT eap_status_e remove_spaces(eap_variable_data_c * const buffer);
       
   154 
       
   155 	EAP_FUNC_IMPORT eap_status_e remove_leading_spaces(eap_variable_data_c * const line);
       
   156 
       
   157 	EAP_FUNC_IMPORT eap_status_e read_section(
       
   158 		abs_eap_am_file_input_c * const file,
       
   159 		eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map);
       
   160 
       
   161 	EAP_FUNC_IMPORT eap_status_e  read_subsections(
       
   162 		abs_eap_am_file_input_c * const file,
       
   163 		eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map);
       
   164 
       
   165 	EAP_FUNC_IMPORT eap_status_e get_subsect(
       
   166 		abs_eap_am_file_input_c * const file,
       
   167 		eap_variable_data_c * const line);
       
   168 
       
   169 	EAP_FUNC_IMPORT eap_status_e convert_value(
       
   170 		eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
       
   171 		const eap_variable_data_c * const value_buffer,
       
   172 		const eap_configure_type_e type,
       
   173 		eap_variable_data_c * const value_data);
       
   174 
       
   175 	EAP_FUNC_IMPORT eap_status_e store_configure(
       
   176 		abs_eap_am_file_input_c * const file,
       
   177 		const eap_variable_data_c * const line,
       
   178 		eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map);
       
   179 
       
   180 	EAP_FUNC_IMPORT eap_status_e cnf_parse_value(
       
   181 		const eap_variable_data_c * const found_type_value,
       
   182 		const eap_variable_data_c * const found_type_name,
       
   183 		eap_configure_type_e * const parsed_type,
       
   184 		eap_variable_data_c * const parsed_type_value,
       
   185 		const bool is_environment_variable);
       
   186 
       
   187 	EAP_FUNC_IMPORT eap_status_e cnf_get_string(
       
   188 		const eap_variable_data_c * const param,
       
   189 		eap_variable_data_c * const param_name,
       
   190 		eap_variable_data_c * const param_value,
       
   191 		eap_configure_type_e * const type);
       
   192 
       
   193 	EAP_FUNC_IMPORT eap_status_e find_rvalue(
       
   194 		const eap_variable_data_c * const config_param,
       
   195 		bool * const read_env_value,
       
   196 		eap_variable_data_c * const param_name,
       
   197 		eap_variable_data_c * const param_value
       
   198 		);
       
   199 
       
   200 	EAP_FUNC_IMPORT u8_t * read_hex_byte(u8_t * cursor, const u8_t * const end, u8_t * const hex_byte);
       
   201 
       
   202 	EAP_FUNC_IMPORT u8_t * read_u32_t(u8_t * cursor, const u8_t * const end, u32_t * const hex_byte);
       
   203 
       
   204 	EAP_FUNC_IMPORT eap_status_e read_configure(
       
   205 		eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
       
   206 		const eap_configuration_field_c * const field,
       
   207 		eap_variable_data_c* const data,
       
   208 		eap_configure_type_e * const configuration_data_type,
       
   209 		const bool existence_test);
       
   210 
       
   211 	EAP_FUNC_IMPORT eap_status_e file_read_line(
       
   212 		abs_eap_am_file_input_c * const file,
       
   213 		eap_variable_data_c * const line);
       
   214 
       
   215 	EAP_FUNC_IMPORT eap_status_e read_configure(
       
   216 		const eap_configuration_field_c * const field,
       
   217 		eap_variable_data_c* const data,
       
   218 		eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
       
   219 		const bool check_subsection_when_true);
       
   220 
       
   221  public:
       
   222 
       
   223 	EAP_FUNC_IMPORT eap_file_config_c(
       
   224 		abs_eap_am_tools_c* const tools);
       
   225 
       
   226 	EAP_FUNC_IMPORT virtual ~eap_file_config_c();
       
   227 
       
   228 	EAP_FUNC_IMPORT eap_status_e configure(
       
   229 		abs_eap_am_file_input_c * const file);
       
   230 
       
   231 	EAP_FUNC_IMPORT eap_status_e read_configure(
       
   232 		const eap_configuration_field_c * const field,
       
   233 		eap_variable_data_c* const data);
       
   234 
       
   235 	bool get_is_valid() const
       
   236 	{
       
   237 		return m_is_valid;
       
   238 	}
       
   239 
       
   240 	void set_is_valid()
       
   241 	{
       
   242 		m_is_valid = true;
       
   243 	}
       
   244 };
       
   245 
       
   246 #endif /* #ifndef _FILECONFIG_H */
       
   247