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
|
/*
* Copyright (C) 2009-2012 Geometer Plus <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "LitResAuthenticationDataParser.h"
static const std::string TAG_AUTHORIZATION_OK = "catalit-authorization-ok";
static const std::string TAG_AUTHORIZATION_FAILED = "catalit-authorization-failed";
static const std::string TAG_PURCHASE_OK = "catalit-purchase-ok";
static const std::string TAG_PURCHASE_FAILED = "catalit-purchase-failed";
static const std::string TAG_DOWNLOAD_FAILED = "catalit-download-failed";
static const std::string TAG_REGISTRATION_FAILED = "catalit-registration-failed";
static const std::string TAG_PASSWORD_RECOVERY_OK = "catalit-pass-recover-ok";
static const std::string TAG_PASSWORD_RECOVERY_FAILED = "catalit-pass-recover-failed";
LitResAuthenticationDataParser::LitResAuthenticationDataParser() {
}
void LitResAuthenticationDataParser::startElementHandler(const char *tag, const char **attributes) {
myAttributes.clear();
while (*attributes != 0) {
std::string name(*attributes++);
if (*attributes == 0) {
break;
}
std::string value(*attributes++);
myAttributes.insert(std::make_pair(name, value));
}
processTag(tag);
}
LitResLoginDataParser::LitResLoginDataParser(std::string &firstName, std::string &lastName, std::string &sid) :
myFirstName(firstName), myLastName(lastName), mySid(sid) {
}
void LitResLoginDataParser::processTag(const std::string &tag) {
if (TAG_AUTHORIZATION_FAILED == tag) {
setErrorCode(NetworkErrors::ERROR_AUTHENTICATION_FAILED);
} else if (TAG_AUTHORIZATION_OK == tag) {
myFirstName = attributes()["first-name"];
myLastName = attributes()["first-name"];
mySid = attributes()["sid"];
}
}
LitResPurchaseDataParser::LitResPurchaseDataParser(std::string &account, std::string &bookId) :
myAccount(account), myBookId(bookId) {
}
void LitResPurchaseDataParser::processTag(const std::string &tag) {
if (TAG_AUTHORIZATION_FAILED == tag) {
setErrorCode(NetworkErrors::ERROR_AUTHENTICATION_FAILED);
} else {
myAccount = attributes()["account"];
myBookId = attributes()["art"];
if (TAG_PURCHASE_OK == tag) {
// nop
} else if (TAG_PURCHASE_FAILED == tag) {
const std::string &error = attributes()["error"];
if ("1" == error) {
setErrorCode(NetworkErrors::ERROR_PURCHASE_NOT_ENOUGH_MONEY);
} else if ("2" == error) {
setErrorCode(NetworkErrors::ERROR_PURCHASE_MISSING_BOOK);
} else if ("3" == error) {
setErrorCode(NetworkErrors::ERROR_PURCHASE_ALREADY_PURCHASED);
} else {
setErrorCode(NetworkErrors::ERROR_INTERNAL);
}
}
}
}
/*LitResDownloadErrorDataParser::LitResDownloadErrorDataParser() {
}
void LitResDownloadErrorDataParser::processTag(const std::string &tag) {
if (TAG_AUTHORIZATION_FAILED == tag) {
setErrorCode(NetworkErrors::ERROR_AUTHENTICATION_FAILED);
} else {
if (TAG_DOWNLOAD_FAILED == tag) {
const std::string &error = attributes()["error"];
if ("1" == error) {
setErrorCode(NetworkErrors::ERROR_BOOK_NOT_PURCHASED);
} else if ("2" == error) {
setErrorCode(NetworkErrors::ERROR_DOWNLOAD_LIMIT_EXCEEDED);
} else {
setErrorCode(NetworkErrors::ERROR_INTERNAL);
}
}
}
}*/
LitResRegisterUserDataParser::LitResRegisterUserDataParser(std::string &sid) : mySid(sid) {
}
void LitResRegisterUserDataParser::processTag(const std::string &tag) {
if (TAG_REGISTRATION_FAILED == tag) {
const std::string &error = attributes()["error"];
if ("1" == error) {
setErrorCode(NetworkErrors::ERROR_LOGIN_ALREADY_TAKEN);
} else if ("2" == error) {
setErrorCode(NetworkErrors::ERROR_LOGIN_WAS_NOT_SPECIFIED);
} else if ("3" == error) {
setErrorCode(NetworkErrors::ERROR_PASSWORD_WAS_NOT_SPECIFIED);
} else if ("4" == error) {
setErrorCode(NetworkErrors::ERROR_INVALID_EMAIL);
} else if ("5" == error) {
setErrorCode(NetworkErrors::ERROR_TOO_MANY_REGISTRATIONS);
} else {
setErrorCode(NetworkErrors::ERROR_INTERNAL);
}
} else if (TAG_AUTHORIZATION_OK == tag) {
mySid = attributes()["sid"];
}
}
void LitResPasswordRecoveryDataParser::processTag(const std::string &tag) {
if (TAG_PASSWORD_RECOVERY_FAILED == tag) {
const std::string &error = attributes()["error"];
if ("1" == error) {
setErrorCode(NetworkErrors::ERROR_NO_USER_EMAIL);
} else if ("2" == error) {
setErrorCode(NetworkErrors::ERROR_EMAIL_WAS_NOT_SPECIFIED);
} else {
setErrorCode(NetworkErrors::ERROR_INTERNAL);
}
} else if (TAG_PASSWORD_RECOVERY_OK == tag) {
// NOP
}
}
|