Changeset 25 in chevmsgr
- Timestamp:
- 11/29/15 18:04:32 (8 years ago)
- Location:
- trunk
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/msgclnt.cpp
r24 r25 217 217 { 218 218 LOG(e.what()); 219 219 error = e.stackTrace(); 220 220 return false; 221 221 } … … 236 236 { 237 237 LOG(e.what()); 238 238 error = e.stackTrace(); 239 239 return false; 240 240 } … … 271 271 { 272 272 LOG(e.what()); 273 273 error = e.stackTrace(); 274 274 return false; 275 275 } … … 285 285 { 286 286 LOG(e.what()); 287 287 error = e.stackTrace(); 288 288 return false; 289 289 } … … 301 301 { 302 302 LOG(e.what()); 303 304 return false; 305 } 306 } 307 308 std::vector<SFriend> chev::getFriendList()303 error = e.stackTrace(); 304 return false; 305 } 306 } 307 308 bool chev::getFriendList(std::vector<SFriend> & friends) 309 309 { 310 310 std::vector<SFriend> friendList; … … 314 314 secureSocket.send(request.getFriendList()); 315 315 316 friendList = messageQ.pop(ProtocolType::FRIEND_LIST).getFriendList(); 317 } 318 catch (cf::exception & e) 319 { 320 LOG(e.what()); 321 } 322 323 return friendList; 316 friends = messageQ.pop(ProtocolType::FRIEND_LIST).getFriendList(); 317 318 return messageQ.pop(ProtocolType::GET_FRIEND_LIST).get<bool>(ProtocolType::RESULT); 319 } 320 catch (cf::exception & e) 321 { 322 LOG(e.what()); 323 error = e.stackTrace(); 324 return false; 325 } 324 326 } 325 327 … … 351 353 { 352 354 LOG(e.what()); 353 355 error = e.stackTrace(); 354 356 return ""; 355 357 } … … 372 374 { 373 375 LOG(e.what()); 374 376 error = e.stackTrace(); 375 377 return false; 376 378 } -
trunk/msgclnt.h
r24 r25 76 76 bool addFriend(const std::string & id); 77 77 78 std::vector<SFriend> getFriendList();78 bool getFriendList(std::vector<SFriend> & friends); 79 79 80 80 std::string getSessionID(const std::vector<std::string> & idList); -
trunk/msgsrv.cpp
r23 r25 23 23 int cb_getFriendList(void * userArg, int argc, char ** argv, char ** colName) 24 24 { 25 std:: string * friendList = (std::string*) userArg;26 27 *friendList = argv[1];25 std::vector<std::string> * friendList = (std::vector<std::string> *) userArg; 26 27 friendList->push_back(argv[1]); 28 28 29 29 return 0; … … 195 195 { 196 196 int result = 0; 197 std:: stringfriendList;197 std::vector<std::string> friendList; 198 198 199 199 try … … 202 202 203 203 this->exec(query, cb_getFriendList, &friendList); 204 205 return friendList; 204 206 } 205 207 catch (cf::exception & e) 206 208 { 207 209 FORWARD_EXCEPTION(e); 208 } 210 } 209 211 } 210 212 … … 424 426 } 425 427 428 static std::vector<SFriend> getFriendList(const Protocol::Message & parser) 429 throw (cf::exception) 430 { 431 std::string id = parser.get<std::string>(ProtocolType::ID); 432 std::vector<std::string> fl = dbmgr.getFriendList(id); 433 std::vector<SFriend> fv; 434 435 for (size_t iter = 0; iter < fl.size(); iter++) 436 { 437 SFriend s; 438 s.id = fl[iter]; 439 s.name = fl[iter]; // username? 440 fv.push_back(s); 441 } 442 443 return fv; 444 } 445 426 446 static std::string createSessionID(std::string & idList) 427 447 { … … 484 504 { 485 505 result = false; 486 parser.parse(sock.receive().toString()); 506 std::string message = sock.receive().toString(); 507 if (message[0] != '{') 508 THROW_EXCEPTION("unknown message"); 509 510 parser.parse(message); 511 512 LOG(message); 487 513 488 514 if (parser.type() == ProtocolType::SMS) … … 535 561 { 536 562 id = authenticator(*sock); 537 538 Protocol::Response response; 539 bool result = true;540 541 while (result)542 {543 std::string message = gOnlineUsers[id].receive();563 SecureSocket * secsock = &gOnlineUsers[id]; 564 565 while (true) 566 { 567 bool result = true; 568 Protocol::Response response; 569 std::string message = secsock->receive(); 544 570 Protocol::Message parser; 545 571 parser.parse(message); … … 559 585 result = addFriend(parser); 560 586 } 561 562 gOnlineUsers[id].send(response.result(parser.type(), result)); 587 else if (parser.type() == ProtocolType::GET_FRIEND_LIST) 588 { 589 try 590 { 591 std::vector<SFriend> fl = getFriendList(parser); 592 secsock->send(response.friendList(fl)); 593 } catch (cf::exception & e) 594 { 595 LOG(e.stackTrace()); 596 result = false; 597 } 598 } 599 600 secsock->send(response.result(parser.type(), result)); 563 601 } 564 602 } -
trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFC.h
r24 r25 33 33 #include <string> 34 34 35 static std::string wstr2str(const std::wstring & wstr)35 static std::string cstr2str(const CString & cstr) 36 36 { 37 return std::string( ).assign(wstr.begin(), wstr.end());37 return std::string(CT2A(cstr)); 38 38 } 39 39 40 static std::wstring str2wstr(const std::string & str)40 static CString str2cstr(const std::string & str) 41 41 { 42 return std::wstring().assign(str.begin(), str.end());42 return CString(str.c_str()); 43 43 } -
trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFC.vcxproj
r24 r25 218 218 <ClInclude Include="..\..\msg.hpp" /> 219 219 <ClInclude Include="..\..\msgclnt.h" /> 220 <ClInclude Include="AddFriendDlg.h" /> 221 <ClInclude Include="AddGroupChat.h" /> 220 222 <ClInclude Include="ChevMsgrClient_MFC.h" /> 221 223 <ClInclude Include="ChevMsgrClient_MFCDlg.h" /> … … 246 248 <ClCompile Include="..\..\msg.cpp" /> 247 249 <ClCompile Include="..\..\msgclnt.cpp" /> 250 <ClCompile Include="AddFriendDlg.cpp" /> 251 <ClCompile Include="AddGroupChat.cpp" /> 248 252 <ClCompile Include="ChevMsgrClient_MFC.cpp" /> 249 253 <ClCompile Include="ChevMsgrClient_MFCDlg.cpp" /> -
trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFC.vcxproj.filters
r24 r25 79 79 <Filter>crypto</Filter> 80 80 </ClInclude> 81 <ClInclude Include="AddFriendDlg.h"> 82 <Filter>헤더 파일</Filter> 83 </ClInclude> 84 <ClInclude Include="AddGroupChat.h"> 85 <Filter>헤더 파일</Filter> 86 </ClInclude> 81 87 </ItemGroup> 82 88 <ItemGroup> … … 153 159 <Filter>crypto</Filter> 154 160 </ClCompile> 161 <ClCompile Include="AddFriendDlg.cpp"> 162 <Filter>소스 파일</Filter> 163 </ClCompile> 164 <ClCompile Include="AddGroupChat.cpp"> 165 <Filter>소스 파일</Filter> 166 </ClCompile> 155 167 </ItemGroup> 156 168 <ItemGroup> -
trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFCDlg.cpp
r24 r25 12 12 #include "RegisterDlg.h" 13 13 #include "SMSDlg.h" 14 #include "AddFriendDlg.h" 15 #include "AddGroupChat.h" 14 16 15 17 #ifdef _DEBUG … … 80 82 ON_WM_QUERYDRAGICON() 81 83 ON_BN_CLICKED(IDC_BTN_SEND, &CChevMsgrClient_MFCDlg::OnBnClickedBtnSend) 84 ON_BN_CLICKED(IDC_BTN_ADD_FRIEND, &CChevMsgrClient_MFCDlg::OnBnClickedBtnAddFriend) 85 ON_BN_CLICKED(IDC_BTN_ADD_CHAT, &CChevMsgrClient_MFCDlg::OnBnClickedBtnAddChat) 82 86 END_MESSAGE_MAP() 83 87 … … 116 120 // TODO: ¿©±â¿¡ Ãß°¡ ÃʱâÈ ÀÛ¾÷À» Ãß°¡ÇÕ´Ï´Ù. 117 121 122 std::ifstream f("cnct2srv.ini"); 123 if (!f) 124 { 125 AfxMessageBox(_T("¼¹ö Á¤º¸ ÆÄÀÏÀ» ãÀ» ¼ö ¾øÀ½")); 126 ::SendMessage(GetSafeHwnd(), WM_QUIT, NULL, NULL); 127 } 128 std::string ip; 129 std::string port; 130 131 std::getline(f, ip); 132 std::getline(f, port); 133 134 if (!chev.connect(ip, atoi(port.c_str()))) 135 { 136 AfxMessageBox(str2cstr(chev.getLastError())); 137 ::SendMessage(GetSafeHwnd(), WM_QUIT, NULL, NULL); 138 } 139 118 140 CLoginDlg loginDlg; 119 141 loginDlg.chev = &this->chev; 120 loginDlg.DoModal(); 121 122 std::ifstream f("cnct2srv.ini"); 123 std::string ip; 124 std::string port; 125 126 std::getline(f, ip); 127 std::getline(f, port); 128 129 if (!chev.connect(ip, atoi(port.c_str()))) 130 { 131 AfxMessageBox(_T("connect error")); 132 PostQuitMessage(1); 133 } 142 if (loginDlg.DoModal() != 0) 143 { 144 AfxMessageBox(_T("login failed")); 145 ::SendMessage(GetSafeHwnd(), WM_QUIT, NULL, NULL); 146 } 147 148 this->mId = loginDlg.mId; 134 149 135 150 SCallback cb; … … 140 155 chev.listen(cb); 141 156 142 //this->mFriendListBox.InsertString(this->mFriendListBox.GetCount(), Ä£±¸¾ÆÀ̵𸮽ºÆ®); 157 CString cstrId; 158 if (!chev.getFriendList(idList)) 159 { 160 AfxMessageBox(_T("cannot get friend list")); 161 ::SendMessage(GetSafeHwnd(), WM_QUIT, NULL, NULL); 162 } 163 164 for (size_t iter = 0; iter < idList.size(); iter++) 165 { 166 cstrId = str2cstr(idList[iter].id); 167 this->mFriendListBox.InsertString(this->mFriendListBox.GetCount(), cstrId); 168 } 143 169 144 170 return TRUE; // Æ÷Ä¿½º¸¦ ÄÁÆ®·Ñ¿¡ ¼³Á¤ÇÏÁö ¾ÊÀ¸¸é TRUE¸¦ ¹ÝȯÇÕ´Ï´Ù. … … 211 237 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. 212 238 CString chat; 213 CString sender;239 CString receiver; 214 240 SConversation conversation; 215 241 216 mFriendListBox.GetText(mFriendListBox.GetCurSel(), sender);217 conversation.from = wstr2str((std::wstring)sender);242 mFriendListBox.GetText(mFriendListBox.GetCurSel(), receiver); 243 conversation.from = this->mId; 218 244 219 245 GetDlgItemText(IDC_EDIT_INPUT, chat); 220 conversation.message = wstr2str((std::wstring)chat);246 conversation.message = cstr2str(chat); 221 247 222 248 UpdateData(TRUE); … … 226 252 //conversation.sessid = chev.getSessionID( ´ëȹæ ÃÊ´ëÇÑ ¾ÆÀ̵𸮽ºÆ® ); 227 253 228 chev.tell(conversation); 229 } 254 if (chev.tell(conversation)) 255 mChatListBox.InsertString(mChatListBox.GetCount(), chat); 256 } 257 258 void CChevMsgrClient_MFCDlg::OnBnClickedBtnAddFriend() 259 { 260 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. 261 //chev.addFriend(); 262 CAddFriendDlg AFDlg; 263 264 AFDlg.chev = &this->chev; 265 266 AFDlg.DoModal(); 267 } 268 269 270 void CChevMsgrClient_MFCDlg::OnBnClickedBtnAddChat() 271 { 272 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. 273 CAddGroupChatDlg AGCDlg; 274 275 AGCDlg.chev = &this->chev; 276 277 AGCDlg.DoModal(); 278 } -
trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFCDlg.h
r24 r25 38 38 CListBox mFriendListBox; 39 39 BOOL mCheckedSensitive; 40 std::vector<SFriend> idList; 41 std::string mId; 40 42 afx_msg void OnBnClickedBtnSend(); 43 afx_msg void OnBnClickedBtnAddFriend(); 44 afx_msg void OnBnClickedBtnAddChat(); 41 45 }; -
trunk/msvc14/ChevMsgrClient_MFC/LoginDlg.cpp
r24 r25 7 7 #include "afxdialogex.h" 8 8 #include "RegisterDlg.h" 9 #include "fstream" 10 #include "cf/codec.h" 11 #include "crypto.h" 9 12 10 13 … … 31 34 BEGIN_MESSAGE_MAP(CLoginDlg, CDialogEx) 32 35 ON_BN_CLICKED(IDC_BTN_LOGIN_REGISTER, &CLoginDlg::OnBnClickedBtnLoginRegister) 36 ON_BN_CLICKED(IDC_BTN_LOGIN_LOGIN, &CLoginDlg::OnBnClickedBtnLoginLogin) 33 37 END_MESSAGE_MAP() 34 38 … … 41 45 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. 42 46 CRegisterDlg regiDlg; 43 47 regiDlg.chev = this->chev; 44 48 regiDlg.DoModal(); 45 49 } 50 51 52 void CLoginDlg::OnBnClickedBtnLoginLogin() 53 { 54 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. 55 CString id, pw; 56 cf::bin decoded; 57 crypto c; 58 std::string str; 59 60 GetDlgItemText(IDC_EDIT_LOGIN_ID, id); 61 std::string name = cf::codec::hex::getInstance()->encode(c.sha256(cf::bin(cstr2str(id)))); 62 std::ifstream f(name); 63 if(!f) 64 { 65 AfxMessageBox(_T("FILE OPEN FAILED ( LOGIN )")); 66 EndDialog(1); 67 } 68 69 this->mId = cstr2str(id); 70 71 GetDlgItemText(IDC_EDIT_LOGIN_PW, pw); 72 f >> str; 73 decoded = cf::codec::hex::getInstance()->decode(str); 74 75 c.setKey(cf::bin(cstr2str(pw))); 76 str = c.decrypt(decoded).toString(); 77 78 if (str.size() == 6) 79 { 80 for (size_t iter = 0; iter < str.size(); iter++) 81 { 82 if (!(str[iter] >= '0' && str[iter] <= '9')) 83 { 84 AfxMessageBox(_T("Decrypt Error")); 85 EndDialog(2); 86 } 87 } 88 } 89 else 90 { 91 AfxMessageBox(_T("Decrypt Error")); 92 EndDialog(3); 93 } 94 95 if (!chev->login(cstr2str(id), cstr2str(pw), str)) 96 AfxMessageBox(_T("Login Failed")); 97 else 98 EndDialog(0); 99 } -
trunk/msvc14/ChevMsgrClient_MFC/LoginDlg.h
r24 r25 12 12 virtual ~CLoginDlg(); 13 13 chev *chev; 14 std::string mId; 14 15 15 16 // ´ëÈ »óÀÚ µ¥ÀÌÅÍÀÔ´Ï´Ù. … … 24 25 public: 25 26 afx_msg void OnBnClickedBtnLoginRegister(); 27 afx_msg void OnBnClickedBtnLoginLogin(); 26 28 }; -
trunk/msvc14/ChevMsgrClient_MFC/RegisterDlg.cpp
r24 r25 7 7 #include "afxdialogex.h" 8 8 #include "SMSDlg.h" 9 9 #include "crypto.h" 10 #include "fstream" 11 #include "cf/codec.h" 10 12 11 13 // CRegisterDlg ´ëÈ »óÀÚÀÔ´Ï´Ù. … … 39 41 { 40 42 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. 43 CString id, pw, pw2; 41 44 CSMSDlg smsDlg; 45 crypto c; 46 cf::bin key; 47 48 smsDlg.chev = this->chev; 49 if (smsDlg.DoModal() != 0) 50 { 51 AfxMessageBox(_T("no sms")); 52 return; 53 } 54 this->authsms = cstr2str(smsDlg.sms); 55 GetDlgItemText(IDC_EDIT_REG_ID, id); 56 GetDlgItemText(IDC_EDIT_REG_PW, pw); 57 GetDlgItemText(IDC_EDIT_REG_PW2, pw2); 42 58 43 smsDlg.DoModal(); 59 std::ofstream f(cf::codec::hex::getInstance()->encode(c.sha256(cf::bin(cstr2str(id))))); 60 61 if (pw != pw2) 62 { 63 AfxMessageBox(_T("Æнº¿öµå¸¦ È®ÀÎÇØÁÖ¼¼¿ä.")); 64 } 65 else 66 { 67 if (chev->join(cstr2str(id), cstr2str(pw), this->authsms)) 68 { 69 AfxMessageBox(_T("ȸ¿ø°¡ÀÔ ¼º°ø")); 70 c.setKey(cf::bin(cstr2str(pw))); 71 f << cf::codec::hex::getInstance()->encode(c.encrypt(cf::bin(authsms))); 72 f.close(); 73 EndDialog(0); 74 } 75 else 76 AfxMessageBox(_T("ȸ¿ø°¡ÀÔ ½ÇÆÐ")); 77 } 44 78 } -
trunk/msvc14/ChevMsgrClient_MFC/RegisterDlg.h
r24 r25 1 1 #pragma once 2 2 #include "msgclnt.h" 3 3 4 4 // CRegisterDlg ´ëÈ »óÀÚÀÔ´Ï´Ù. … … 11 11 CRegisterDlg(CWnd* pParent = NULL); // Ç¥ÁØ »ý¼ºÀÚÀÔ´Ï´Ù. 12 12 virtual ~CRegisterDlg(); 13 chev *chev; 14 std::string authsms; 13 15 14 16 // ´ëÈ »óÀÚ µ¥ÀÌÅÍÀÔ´Ï´Ù. -
trunk/msvc14/ChevMsgrClient_MFC/SMSDlg.cpp
r24 r25 17 17 , sms(_T("")) 18 18 { 19 20 19 } 21 20 … … 45 44 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. 46 45 GetDlgItemText(IDC_EDIT_SMS_PHONE, phone); 47 48 46 if (!chev->sms(cstr2str(phone))) 47 AfxMessageBox(_T("cannot request sms")); 49 48 } 50 49 … … 54 53 // TODO: ¿©±â¿¡ ÄÁÆ®·Ñ ¾Ë¸² 󸮱â Äڵ带 Ãß°¡ÇÕ´Ï´Ù. 55 54 GetDlgItemText(IDC_EDIT_SMS_SMS, sms); 55 EndDialog(0); 56 56 } -
trunk/msvc14/ChevMsgrClient_MFC/SMSDlg.h
r24 r25 1 1 #pragma once 2 2 #include "msgclnt.h" 3 3 4 4 // CSMSDlg ´ëÈ »óÀÚÀÔ´Ï´Ù. … … 11 11 CSMSDlg(CWnd* pParent = NULL); // Ç¥ÁØ »ý¼ºÀÚÀÔ´Ï´Ù. 12 12 virtual ~CSMSDlg(); 13 chev *chev; 13 14 14 15 // ´ëÈ »óÀÚ µ¥ÀÌÅÍÀÔ´Ï´Ù.
Note:
See TracChangeset
for help on using the changeset viewer.