File: CardSIS.cpp

package info (click to toggle)
beid 3.5.2.dfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 147,240 kB
  • ctags: 34,507
  • sloc: cpp: 149,944; ansic: 41,577; java: 8,927; cs: 6,528; sh: 2,426; perl: 1,866; xml: 805; python: 463; makefile: 263; lex: 92
file content (223 lines) | stat: -rw-r--r-- 6,026 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* ****************************************************************************

 * eID Middleware Project.
 * Copyright (C) 2008-2009 FedICT.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version
 * 3.0 as published by the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, see
 * http://www.gnu.org/licenses/.

**************************************************************************** */
#include <stdlib.h>
#include "APLCardSIS.h"
#include "CardSIS.h"
#include "CardSISDef.h"
#include "Util.h"

namespace eIDMW
{
/*****************************************************************************************
---------------------------------------- APL_SisFile_ID -----------------------------------------
*****************************************************************************************/
APL_SisFile_ID::APL_SisFile_ID(APL_Card *card):APL_CardFile(card,SIS_FILE_ID)
{
}

APL_SisFile_ID::~APL_SisFile_ID()
{
}

tCardFileStatus APL_SisFile_ID::VerifyFile()
{
	if(m_data.Size()!=SIS_FILE_ID_SIZE)
		return CARDFILESTATUS_ERROR_FORMAT;

	return CARDFILESTATUS_OK;
}
void APL_SisFile_ID::EmptyFields()
{
	m_Name.clear();
	m_Surname.clear();
	m_Initials.clear();
	m_Gender.clear();
	m_DateOfBirth.clear();
	m_SocialSecurityNumber.clear();
	m_LogicalNumber.clear();
	m_DateOfIssue.clear();
	m_ValidityBeginDate.clear();
	m_ValidityEndDate.clear();
}

bool APL_SisFile_ID::MapFields()
{
	CByteArray baBuffer;
	std::string sTemp;
	char buffer[11];
	char *stop;

	std::string in_utf8;

	//Surname
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_Surname,SIS_FIELD_ID_LEN_Surname);
	baBuffer.TrimRight(' ');
	m_Surname.assign((char*)baBuffer.GetBytes(),baBuffer.Size());

	in_utf8 = IBM850_toUtf8(m_Surname);
	m_Surname = in_utf8;

	//Name
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_Name,SIS_FIELD_ID_LEN_Name);
	baBuffer.TrimRight(' ');
	m_Name.assign((char*)(baBuffer.GetBytes()),baBuffer.Size());
	
	in_utf8 = IBM850_toUtf8(m_Name);
	m_Name = in_utf8;

	//Initials
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_Initials,SIS_FIELD_ID_LEN_Initials);
	baBuffer.TrimRight(' ');
	m_Initials.assign((char*)baBuffer.GetBytes(),baBuffer.Size());

	//Gender
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_Gender,SIS_FIELD_ID_LEN_Gender);
	baBuffer.TrimRight(' ');
	m_Gender.assign((char*)baBuffer.GetBytes(),baBuffer.Size());

	//DateOfBirth
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_DateOfBirth,SIS_FIELD_ID_LEN_DateOfBirth);
	if (baBuffer.Size() < 4)
		return false;
    sprintf_s(buffer, sizeof(buffer),"%02x/%02x/%02x%02x", baBuffer.GetByte(3), baBuffer.GetByte(2), baBuffer.GetByte(0), baBuffer.GetByte(1));
	m_DateOfBirth.assign(buffer);

	//SocialSecurityNumber
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_SocialSecurityNumber,SIS_FIELD_ID_LEN_SocialSecurityNumber);
	sTemp=baBuffer.ToString(false);
	sTemp.insert(7," ");
	sTemp.insert(11," ");
	if(sTemp.c_str()[0]=='0')
		m_SocialSecurityNumber=&sTemp.c_str()[1];
	else
		m_SocialSecurityNumber=sTemp;

	//LogicalNumber
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_LogicalNumber,SIS_FIELD_ID_LEN_LogicalNumber);
	sTemp=baBuffer.ToString(false);
	unsigned long ulLogicalNumber=strtoul(sTemp.c_str(),&stop,16);
    sprintf_s(buffer, sizeof(buffer),"%u", ulLogicalNumber);
	m_LogicalNumber.assign(buffer);

	//DateOfIssue
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_DateOfIssue,SIS_FIELD_ID_LEN_DateOfIssue);
	if (baBuffer.Size() < 4)
		return false;
    sprintf_s(buffer, sizeof(buffer),"%02x/%02x/%02x%02x", baBuffer.GetByte(3), baBuffer.GetByte(2), baBuffer.GetByte(0), baBuffer.GetByte(1));
	m_DateOfIssue.assign(buffer);

	//ValidityBeginDate
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_ValidityBeginDate,SIS_FIELD_ID_LEN_ValidityBeginDate);
	if (baBuffer.Size() < 4)
		return false;
    sprintf_s(buffer, sizeof(buffer),"%02x/%02x/%02x%02x", baBuffer.GetByte(3), baBuffer.GetByte(2), baBuffer.GetByte(0), baBuffer.GetByte(1));
	m_ValidityBeginDate.assign(buffer);

	//ValidityEndDate
	baBuffer=m_data.GetBytes(SIS_FIELD_ID_POS_ValidityEndDate,SIS_FIELD_ID_LEN_ValidityEndDate);
	if (baBuffer.Size() < 4)
		return false;
    sprintf_s(buffer, sizeof(buffer),"%02x/%02x/%02x%02x", baBuffer.GetByte(3), baBuffer.GetByte(2), baBuffer.GetByte(0), baBuffer.GetByte(1));
	m_ValidityEndDate.assign(buffer);

	return true;
}

const char *APL_SisFile_ID::getName()
{
	if(ShowData())
		return m_Name.c_str();

	return "";
}

const char *APL_SisFile_ID::getSurname()
{
	if(ShowData())
		return m_Surname.c_str();

	return "";
}

const char *APL_SisFile_ID::getInitials()
{
	if(ShowData())
		return m_Initials.c_str();

	return "";
}

const char *APL_SisFile_ID::getGender()
{
	if(ShowData())
		return m_Gender.c_str();

	return "";
}

const char *APL_SisFile_ID::getDateOfBirth()
{
	if(ShowData())
		return m_DateOfBirth.c_str();

	return "";
}

const char *APL_SisFile_ID::getSocialSecurityNumber()
{
	if(ShowData())
		return m_SocialSecurityNumber.c_str();

	return "";
}

const char *APL_SisFile_ID::getLogicalNumber()
{
	if(ShowData())
		return m_LogicalNumber.c_str();

	return "";
}

const char *APL_SisFile_ID::getDateOfIssue()
{
	if(ShowData())
		return m_DateOfIssue.c_str();

	return "";
}

const char *APL_SisFile_ID::getValidityBeginDate()
{
	if(ShowData())
		return m_ValidityBeginDate.c_str();

	return "";
}

const char *APL_SisFile_ID::getValidityEndDate()
{
	if(ShowData())
		return m_ValidityEndDate.c_str();

	return "";
}

}