eapol/eapol_framework/wapi_common/src/ec_cs_data.cpp
changeset 18 7aac0b9e8906
parent 17 8840d3e38314
child 20 8b3129ac4c0f
equal deleted inserted replaced
17:8840d3e38314 18:7aac0b9e8906
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : ./accesssec/eapol/eapol_framework/wapi_common/src/ec_cs_data.cpp
       
     4 *  Part of     : WAPI / WAPI       *** Info from the SWAD
       
     5 *  Description : WAPI authentication
       
     6 *  Version     : %version: 8 % << Don't touch! Updated by Synergy at check-out.
       
     7 *
       
     8 *  Copyright © 2001-2009 Nokia.  All rights reserved.
       
     9 *  This material, including documentation and any related computer
       
    10 *  programs, is protected by copyright controlled by Nokia.  All
       
    11 *  rights are reserved.  Copying, including reproducing, storing,
       
    12 *  adapting or translating, any or all of this material requires the
       
    13 *  prior written consent of Nokia.  This material also contains
       
    14 *  confidential information which may not be disclosed to others
       
    15 *  without the prior written consent of Nokia.
       
    16 * ============================================================================
       
    17 * Template version: 4.1.1
       
    18 */
       
    19 
       
    20 // This is enumeration of WAPI source code.
       
    21 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    22 	#undef EAP_FILE_NUMBER_ENUM
       
    23 	#define EAP_FILE_NUMBER_ENUM 701 
       
    24 	#undef EAP_FILE_NUMBER_DATE 
       
    25 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    26 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    27 
       
    28 
       
    29 #if defined(USE_WAPI_CORE)
       
    30 
       
    31 #include "eap_automatic_variable.h"
       
    32 #include "ec_cs_types.h"
       
    33 #include "ec_cs_data.h"
       
    34 #include "ec_cs_strings.h"
       
    35 
       
    36 //----------------------------------------------------------------------------
       
    37 
       
    38 EAP_FUNC_EXPORT ec_cs_data_c::~ec_cs_data_c()
       
    39 {
       
    40 }
       
    41 
       
    42 //----------------------------------------------------------------------------
       
    43 
       
    44 EAP_FUNC_EXPORT ec_cs_data_c::ec_cs_data_c(
       
    45 	abs_eap_am_tools_c * const tools)
       
    46 	: m_am_tools(tools)
       
    47 	, m_change_status(ec_cs_data_change_status_none)
       
    48 	, m_type(ec_cs_data_type_none)
       
    49 	, m_reference(tools)
       
    50 	, m_data(tools)
       
    51 	, m_data_references_read(false)
       
    52 {
       
    53 	eap_status_e status = m_reference.set_copy_of_buffer(
       
    54 		EC_CS_ZERO_REFERENCE,
       
    55 		sizeof(EC_CS_ZERO_REFERENCE));
       
    56 	if (status != eap_status_ok)
       
    57 	{
       
    58 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    59 		(void) EAP_STATUS_RETURN(m_am_tools, status);
       
    60 		return;
       
    61 	}
       
    62 }
       
    63 
       
    64 //----------------------------------------------------------------------------
       
    65 
       
    66 EAP_FUNC_EXPORT bool ec_cs_data_c::get_is_valid() const
       
    67 {
       
    68 	return(m_reference.get_is_valid() && m_data.get_is_valid());
       
    69 }
       
    70 
       
    71 //----------------------------------------------------------------------------
       
    72 
       
    73 EAP_FUNC_EXPORT bool ec_cs_data_c::get_is_valid_data() const
       
    74 {
       
    75 	return(m_reference.get_is_valid_data() && m_data.get_is_valid_data());
       
    76 }
       
    77 
       
    78 //----------------------------------------------------------------------------
       
    79 
       
    80 EAP_FUNC_EXPORT ec_cs_data_change_status_e ec_cs_data_c::get_change_status() const
       
    81 {
       
    82 	return m_change_status;
       
    83 }
       
    84 
       
    85 //----------------------------------------------------------------------------
       
    86 
       
    87 EAP_FUNC_EXPORT void ec_cs_data_c::set_change_status(const ec_cs_data_change_status_e change_status)
       
    88 {
       
    89 	m_change_status = change_status;
       
    90 }
       
    91 
       
    92 //----------------------------------------------------------------------------
       
    93 
       
    94 EAP_FUNC_EXPORT ec_cs_data_type_e ec_cs_data_c::get_type() const
       
    95 {
       
    96 	return m_type;
       
    97 }
       
    98 
       
    99 //----------------------------------------------------------------------------
       
   100 
       
   101 EAP_FUNC_EXPORT void ec_cs_data_c::set_type(const ec_cs_data_type_e type)
       
   102 {
       
   103 	m_type = type;
       
   104 }
       
   105 
       
   106 //----------------------------------------------------------------------------
       
   107 
       
   108 EAP_FUNC_EXPORT const eap_variable_data_c * ec_cs_data_c::get_reference() const
       
   109 {
       
   110 	return &m_reference;
       
   111 }
       
   112 
       
   113 //----------------------------------------------------------------------------
       
   114 
       
   115 EAP_FUNC_EXPORT const eap_variable_data_c * ec_cs_data_c::get_data() const
       
   116 {
       
   117 	return &m_data;
       
   118 }
       
   119 
       
   120 //----------------------------------------------------------------------------
       
   121 
       
   122 EAP_FUNC_EXPORT eap_variable_data_c * ec_cs_data_c::get_writable_reference()
       
   123 {
       
   124 	return &m_reference;
       
   125 }
       
   126 
       
   127 //----------------------------------------------------------------------------
       
   128 
       
   129 EAP_FUNC_EXPORT eap_variable_data_c * ec_cs_data_c::get_writable_data()
       
   130 {
       
   131 	return &m_data;
       
   132 }
       
   133 
       
   134 //----------------------------------------------------------------------------
       
   135 
       
   136 ec_cs_data_c * ec_cs_data_c::copy() const
       
   137 {
       
   138 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   139 
       
   140 	ec_cs_data_c * const data = new ec_cs_data_c(m_am_tools);
       
   141 
       
   142 	eap_automatic_variable_c<ec_cs_data_c> automatic_data(m_am_tools, data);
       
   143 
       
   144 	if (data == 0)
       
   145 	{
       
   146 		return 0;
       
   147 	}
       
   148 
       
   149 	data->set_change_status(get_change_status());
       
   150 
       
   151 	data->set_type(get_type());
       
   152 
       
   153 	eap_status_e status = data->get_writable_data()->set_copy_of_buffer(get_data());
       
   154 	if (status != eap_status_ok)
       
   155 	{
       
   156 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   157 		(void) EAP_STATUS_RETURN(m_am_tools, status);
       
   158 		return 0;
       
   159 	}
       
   160 
       
   161 	status = data->get_writable_reference()->set_copy_of_buffer(get_reference());
       
   162 	if (status != eap_status_ok)
       
   163 	{
       
   164 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   165 		(void) EAP_STATUS_RETURN(m_am_tools, status);
       
   166 		return 0;
       
   167 	}
       
   168 
       
   169 	automatic_data.do_not_free_variable();
       
   170 
       
   171 	EAP_TRACE_DEBUG(
       
   172 		m_am_tools,
       
   173 		TRACE_FLAGS_DEFAULT,
       
   174 		(EAPL("EC-CS: ec_cs_data_c::copy(): type %d=%s, change status %d=%s\n"),
       
   175 		data->get_type(),
       
   176 		ec_cs_strings_c::get_ec_cs_store_data_string(data->get_type()),
       
   177 		data->get_change_status(),
       
   178 		ec_cs_strings_c::get_ec_cs_store_data_change_status_string(data->get_change_status())));
       
   179 
       
   180 	EAP_TRACE_DATA_DEBUG(
       
   181 		m_am_tools,
       
   182 		TRACE_FLAGS_DEFAULT,
       
   183 		(EAPL("EC-CS: ec_cs_data_c::copy(): reference"),
       
   184 		 data->get_reference()->get_data(),
       
   185 		 data->get_reference()->get_data_length()));
       
   186 
       
   187 	EAP_TRACE_DATA_DEBUG(
       
   188 		m_am_tools,
       
   189 		TRACE_FLAGS_DEFAULT,
       
   190 		(EAPL("EC-CS: ec_cs_data_c::copy(): data"),
       
   191 		 data->get_data()->get_data(),
       
   192 		 data->get_data()->get_data_length()));
       
   193 
       
   194 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   195 	return data;
       
   196 }
       
   197 
       
   198 //----------------------------------------------------------------------------
       
   199 
       
   200 EAP_FUNC_EXPORT i32_t ec_cs_data_c::compare(const ec_cs_data_c * const data) const
       
   201 {
       
   202 	return get_reference()->compare(data->get_reference());
       
   203 }
       
   204 
       
   205 //----------------------------------------------------------------------------
       
   206 
       
   207 EAP_FUNC_EXPORT eap_status_e ec_cs_data_c::reset()
       
   208 {
       
   209 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   210 
       
   211 	m_change_status = ec_cs_data_change_status_none;
       
   212 
       
   213 	m_type = ec_cs_data_type_none;
       
   214 
       
   215 	(void)m_reference.reset();
       
   216 
       
   217 	(void)m_data.reset();
       
   218 
       
   219 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   220 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   221 }
       
   222 
       
   223 //----------------------------------------------------------------------------
       
   224 
       
   225 EAP_FUNC_EXPORT eap_status_e ec_cs_data_c::set_copy_of_buffer(const ec_cs_data_c * const source)
       
   226 {
       
   227 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   228 
       
   229 	m_change_status = source->get_change_status();
       
   230 
       
   231 	m_type = source->get_type();
       
   232 
       
   233 	eap_status_e status = m_reference.set_copy_of_buffer(source->get_reference());
       
   234 	if (status != eap_status_ok)
       
   235 	{
       
   236 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   237 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   238 	}
       
   239 
       
   240 	status = m_data.set_copy_of_buffer(source->get_data());
       
   241 
       
   242 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   243 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   244 }
       
   245 
       
   246 //----------------------------------------------------------------------------
       
   247 
       
   248 EAP_FUNC_EXPORT bool ec_cs_data_c::get_data_references_read()
       
   249 {
       
   250 	return m_data_references_read;
       
   251 }
       
   252 
       
   253 //----------------------------------------------------------------------------
       
   254 
       
   255 EAP_FUNC_EXPORT void ec_cs_data_c::set_data_references_read()
       
   256 {
       
   257 	m_data_references_read = true;
       
   258 }
       
   259 
       
   260 //----------------------------------------------------------------------------
       
   261 
       
   262 #endif //#if defined(USE_WAPI_CORE)
       
   263 
       
   264 // End.