Changeset 16 in chevmsgr
- Timestamp:
- 11/08/15 19:59:07 (9 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/msg.cpp
r14 r16 104 104 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::ADD_FRIEND); 105 105 106 obj[ProtocolType:: ID] = id;106 obj[ProtocolType::FRIEND_ID] = id; 107 107 108 108 return json::Serialize(obj); -
trunk/msg.hpp
r14 r16 44 44 DECLARE_KEY(GET_FRIEND_LIST); 45 45 DECLARE_KEY(FRIEND_LIST); 46 DECLARE_KEY(FRIEND_ID); 46 47 DECLARE_KEY(ID_LIST); 47 48 DECLARE_KEY(RESULT); -
trunk/msgclnt.cpp
r14 r16 294 294 295 295 sessionMap[concat] = message.get<std::string>(ProtocolType::SESSION_ID); 296 297 bool result = messageQ.pop(ProtocolType::OPEN_SESSION).get<bool>(ProtocolType::RESULT); 298 if (!result) 299 THROW_EXCEPTION("cannot open session for [" + concat + "]"); 296 300 } 297 301 -
trunk/msgsrv.cpp
r15 r16 37 37 int cb_getSMS(void * userArg, int argc, char ** argv, char ** colName) 38 38 { 39 std::string * SMS = (std::string *) userArg; 40 41 *SMS = argv[1]; 39 std::string * sms = (std::string *) userArg; 40 41 for (int i = 0; i < argc; i++) 42 { 43 if (stricmp(colName[i], "sms")) 44 { 45 *sms = argv[i]; 46 break; 47 } 48 } 42 49 43 50 return 0; 44 51 } 45 52 46 int cb_login(void * userArg, int argc, char ** argv, char ** colName) 47 { 53 int cb_exist(void * userArg, int argc, char ** argv, char ** colName) 54 { 55 // È£ÃâµÇ¸é Àִ°Š48 56 bool * result = (bool *)userArg; 49 57 … … 53 61 } 54 62 55 int cb_join(void * userArg, int argc, char ** argv, char ** colName)56 {57 bool * isExist = (bool *)userArg;58 59 *isExist = true;60 61 return 0;62 }63 63 64 64 //=============================================================== … … 106 106 "CREATE TABLE T_ACCOUNT" 107 107 "(" 108 " num INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," 109 " id TEXT," 110 " pw TEXT" 108 " id TEXT PRIMARY KEY," 109 " pw TEXT" 111 110 ")"; 112 111 sqlCreateAuthTable = 113 112 "CREATE TABLE T_AUTH" 114 113 "(" 115 " id TEXT PRIMARY KEY NOT NULL," 116 " sms1 TEXT," 117 " ip1 TEXT," 118 " sms2 TEXT," 119 " ip2 TEXT," 120 " sms3 TEXT," 121 " ip3 TEXT," 122 " sms4 TEXT," 123 " ip4 TEXT," 124 " sms5 TEXT," 125 " ip5 TEXT" 114 " id TEXT NOT NULL," 115 " ip TEXT NOT NULL," 116 " sms TEXT NOT NULL" 126 117 ")"; 127 118 sqlCreateFriendsTable = 128 119 "CREATE TABLE T_FRIENDS" 129 120 "(" 130 " id TEXT PRIMARY KEYNOT NULL,"131 " friend TEXT "121 " id TEXT NOT NULL," 122 " friend TEXT NOT NULL" 132 123 ")"; 133 124 … … 157 148 std::string query = "select * from T_ACCOUNT where id ='" + id + "' and pw = '" + pw + "'"; 158 149 159 this->exec(query, cb_ login, &result);150 this->exec(query, cb_exist, &result); 160 151 161 152 return result; … … 172 163 try 173 164 { 174 bool isExist = false; 175 std::string existQuery = "select * from T_ACCOUNT where id = '" + id + "'"; 176 std::string insertQuery = "insert into T_ACCOUNT(id, pw) values('" + id + "', '" + pw + "')"; 177 178 this->exec(existQuery, cb_join, &isExist); 179 180 if (!isExist) 181 this->exec(insertQuery, NULL, NULL); 165 // account 166 bool isExistAccount = false; 167 std::string existAccount = "select * from T_ACCOUNT where id = '" + id + "'"; 168 std::string insertAccount = "insert into T_ACCOUNT(id, pw) values('" + id + "', '" + pw + "')"; 169 170 // auth 171 bool isExistAuth = false; 172 std::string existAuth = "select * from T_AUTH where id = '" + id + "' and sms = '" + sms + "' and ip = '" + ip + "'"; 173 std::string insertAuth = "insert into T_AUTH(id, sms, ip) values( '" + id + "', '" + sms + "' , '" + ip + "')"; 174 175 this->exec(existAccount, cb_exist, &isExistAccount); 176 177 if (!isExistAccount) 178 { 179 this->exec(insertAccount, NULL, NULL); 180 this->exec(insertAuth, NULL, NULL); 181 } 182 else 183 { 184 this->exec(existAuth, cb_exist, &isExistAuth); 185 if (!isExistAuth) 186 this->exec(insertAuth, NULL, NULL); 187 } 182 188 } 183 189 catch (cf::exception & e) … … 189 195 } 190 196 191 std:: stringgetFriendList(std::string & id)197 std::vector<std::string> getFriendList(std::string & id) 192 198 throw(cf::exception) 193 199 { … … 207 213 } 208 214 209 int getSMS(std::string & id) 210 { 211 int result = 0; 212 std::string smsMsg; 213 215 std::string getSMS(std::string & id, std::string & ip) 216 { 214 217 try 215 218 { 216 std::string query = "select * from T_AUTH where id = '" + id + "'"; 217 218 this->exec(query, cb_getSMS, &smsMsg); 219 std::string sms; 220 std::string query = "select * from T_AUTH where id = '" + id + "' and ip = '" + ip + "'"; 221 222 this->exec(query, cb_getSMS, &sms); 223 if (sms.length() == 0) 224 THROW_EXCEPTION("sms was not found for '" + id + "' from '" + ip + "'"); 225 226 return sms; 219 227 } 220 228 catch (cf::exception & e) … … 224 232 } 225 233 226 int addFriend(std::string & id)234 bool addFriend(std::string & id, std::string & friendID) 227 235 { 228 236 try 229 237 { 230 std::string query = "insert into T_FRIENDS values('" + id + "' )";238 std::string query = "insert into T_FRIENDS values('" + id + "', '" + friendID + "')"; 231 239 232 240 this->exec(query, NULL, NULL); 241 242 return true; 233 243 } 234 244 catch (cf::exception & e) 235 245 { 236 246 FORWARD_EXCEPTION(e); 247 return false; 237 248 } 238 249 } … … 345 356 } 346 357 347 static bool login(const Protocol::Message & parser, cf::network::tcp & sock, cf::bin & key)358 static bool login(const Protocol::Message & parser, cf::network::tcp & sock, std::string & ip, std::string sms) 348 359 throw (cf::exception) 349 360 { … … 354 365 if (result) 355 366 { 367 cf::bin seed = sms + DELIMITER + ip; 368 cf::bin key = crypto().sha256(seed); 369 356 370 LoginSession loginSess; 371 357 372 loginSess.sock = &sock; 358 373 loginSess.key = key; … … 422 437 } 423 438 439 static bool addFriend(const Protocol::Message & message) 440 { 441 Protocol::Message parser = message; 442 std::string result = ""; 443 std::string id = parser.get<std::string>(ProtocolType::ID); 444 std::string friendID = parser.get<std::string>(ProtocolType::FRIEND_ID); 445 446 return dbmgr.addFriend(id, friendID); 447 } 448 424 449 static std::string keyExchange(const std::string sms, const std::string address) 425 450 { … … 456 481 else if (parser.type() == ProtocolType::LOGIN) 457 482 { 483 id = parser.get<std::string>(ProtocolType::ID); 458 484 std::string ip = sock.peer().address(); 459 cf::bin seed = sms + DELIMITER + ip; 460 cf::bin key = crypto().sha256(seed); 461 462 if (login(parser, sock, key)) 463 id = parser.get<std::string>(ProtocolType::ID); 464 465 loggedIn = true; 485 sms = dbmgr.getSMS(id, ip); 486 487 // ½ÇÆÐÇÏ¸é ¾Õ¿¡¼ exceptionÀ¸·Î ´Ù ó¸®µÊ 488 // ¿©±ä ¼º°øÇÒ ¶§¿¡¸¸ ¿È 489 if (login(parser, sock, ip, sms)) 490 loggedIn = true; 466 491 } 467 492 … … 504 529 { 505 530 result = chat(parser); 506 sock->send(response.result(parser.type(), result));507 531 } 508 532 else if (parser.type() == ProtocolType::OPEN_SESSION) … … 510 534 result = openSession(parser); 511 535 } 536 else if (parser.type() == ProtocolType::ADD_FRIEND) 537 { 538 result = addFriend(parser); 539 } 540 541 sock->send(response.result(parser.type(), result)); 512 542 } 513 543 } -
trunk/msvc14/testClient/test.cpp
r14 r16 9 9 #define CIN(v) std::cout << #v << "\t: "; std::cin >> v 10 10 11 std::string mode; 11 12 std::string ip; 12 13 std::string port; … … 56 57 std::ifstream f(ini); 57 58 59 std::getline(f, mode); 58 60 std::getline(f, ip); 59 61 std::getline(f, port); … … 74 76 T(c.connect(ip, atoi(port.c_str()))); 75 77 T(c.listen(cb)); 76 T(c.sms(phone));77 78 78 CIN(sms); 79 T(c.join(id, pw, sms)); 80 std::getline(std::cin, sms); 79 sms = "633174";// CIN(sms); 80 if (mode == "join") 81 { 82 T(c.sms(phone)); 83 T(c.join(id, pw, sms)); 84 } 85 86 //std::getline(std::cin, sms); 81 87 82 88 T(c.login(id, pw));
Note:
See TracChangeset
for help on using the changeset viewer.