Changeset 8 in chevmsgr
- Timestamp:
- 08/30/15 00:01:12 (9 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/msg.cpp
r6 r8 4 4 json::Object _obj; \ 5 5 makeTemplate(_obj, _type); \ 6 7 #define DELIMITER "$"8 6 9 7 namespace Protocol … … 18 16 { 19 17 return get<std::string>("type"); 18 } 19 20 std::vector<SFriend> Message::getFriendList() const 21 { 22 json::Array ar = mObject[ProtocolType::FRIEND_LIST]; 23 24 std::vector<SFriend> friendList; 25 26 std::vector<json::Value>::iterator iter; 27 for (iter = ar.begin(); iter != ar.end(); iter++) 28 { 29 SFriend fr; 30 31 fr.id = (*iter)[ProtocolType::ID ]; 32 fr.name = (*iter)[ProtocolType::NAME]; 33 34 friendList.push_back(fr); 35 } 36 37 return friendList; 20 38 } 21 39 … … 33 51 void Request::makeTemplate(json::Object & obj, const std::string & type) const 34 52 { 35 obj[ProtocolType::ID 53 obj[ProtocolType::ID] = mID; 36 54 obj[ProtocolType::TYPE] = type; 37 55 } … … 50 68 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::JOIN); 51 69 52 obj[ProtocolType::ID 53 obj[ProtocolType::PW 70 obj[ProtocolType::ID] = id; 71 obj[ProtocolType::PW] = pw; 54 72 obj[ProtocolType::SMS] = sms; 55 73 … … 88 106 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::CHAT); 89 107 90 obj[ProtocolType::FROM 108 obj[ProtocolType::FROM] = mID; 91 109 obj[ProtocolType::SESSION_ID] = sessid; 92 obj[ProtocolType::MESSAGE 93 obj[ProtocolType::SENSITIVE 110 obj[ProtocolType::MESSAGE] = message; 111 obj[ProtocolType::SENSITIVE] = sensitive; 94 112 95 113 return json::Serialize(obj); … … 117 135 return json::Serialize(obj); 118 136 } 137 138 std::string Response::friendList(const std::vector<SFriend> & friendList) const 139 { 140 DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::FRIEND_LIST); 141 142 json::Array ar; 143 std::vector<SFriend>::const_iterator iter; 144 for (iter = friendList.begin() ; iter != friendList.end() ; iter++) 145 { 146 json::Object fr; 147 148 fr[ProtocolType::ID ] = iter->id; 149 fr[ProtocolType::NAME] = iter->name; 150 151 ar.push_back(fr); 152 } 153 154 obj[ProtocolType::FRIEND_LIST] = ar; 155 156 return json::Serialize(obj); 157 } 119 158 }; -
trunk/msg.hpp
r6 r8 15 15 } SFriend; 16 16 17 #define DELIMITER "$" 18 17 19 // -------------------------------------------------------------- 18 20 … … 23 25 DECLARE_KEY(ID); 24 26 DECLARE_KEY(TYPE); 27 DECLARE_KEY(NAME); 25 28 DECLARE_KEY(SMS); 26 29 DECLARE_KEY(PHONE); … … 37 40 DECLARE_KEY(SENSITIVE); 38 41 DECLARE_KEY(GET_FRIEND_LIST); 42 DECLARE_KEY(FRIEND_LIST); 39 43 DECLARE_KEY(RESULT); 40 44 } … … 55 59 return (T)mObject[key]; 56 60 } 61 62 inline std::vector<SFriend> getFriendList() const; 57 63 58 64 std::string type() const; -
trunk/msgclnt.cpp
r6 r8 2 2 #include "msgclnt.h" 3 3 #include "msg.hpp" 4 5 #include <algorithm> 4 6 5 7 #include <stdlib.h> … … 182 184 std::vector<SFriend> chev::getFriendList() 183 185 { 186 std::vector<SFriend> friendList; 187 184 188 try 185 189 { 186 190 socket.send(request.getFriendList()); 187 } 188 catch (cf::exception & e) 189 { 190 LOG(e.what()); 191 } 192 return std::vector<SFriend>(); 193 } 194 195 std::string chev::getSessionID(const std::vector<std::string> & idList) 196 { 197 try 198 { 191 192 friendList = messageQ.pop(ProtocolType::FRIEND_LIST).getFriendList(); 193 } 194 catch (cf::exception & e) 195 { 196 LOG(e.what()); 197 } 198 199 return friendList; 200 } 201 202 std::string chev::getSessionID(std::vector<std::string> & idList) 203 { 204 try 205 { 206 if (idList.size() == 2) 207 std::sort(idList.begin(), idList.end()); 208 199 209 std::string concat = idList[0]; 200 210 201 for (int iter = 1 ; iter < idList.size(); iter++)202 concat += ","+ idList[iter];211 for (int iter = 1; iter < idList.size(); iter++) 212 concat += DELIMITER + idList[iter]; 203 213 204 214 if (sessionMap.find(concat) == sessionMap.end()) … … 206 216 socket.send(request.openSession(concat)); 207 217 208 std::string response = socket.receive().toString(); 209 Protocol::Message parser; 210 parser.parse(response); 211 212 if (!parser.get<bool>("result")) 218 Protocol::Message message = messageQ.pop(ProtocolType::SESSION_ID); 219 220 if (!message.get<bool>(ProtocolType::RESULT)) 213 221 THROW_EXCEPTION("failed to open session id"); 214 222 215 sessionMap[concat] = parser.get<std::string>("sess-id");223 sessionMap[concat] = message.get<std::string>(ProtocolType::SESSION_ID); 216 224 } 217 225 … … 247 255 { 248 256 SConversation c; 249 Protocol::Message parser= messageQ.pop(ProtocolType::CHAT);250 251 c.sessid = parser.get<std::string>(ProtocolType::SESSION_ID);252 c.message = parser.get<std::string>(ProtocolType::MESSAGE);253 c.sensitive = parser.get<int>(ProtocolType::SENSITIVE);254 c.isError = parser.get<bool>(ProtocolType::RESULT);255 256 c.from = parser.get<std::string>(ProtocolType::FROM);257 Protocol::Message message = messageQ.pop(ProtocolType::CHAT); 258 259 c.sessid = message.get<std::string>(ProtocolType::SESSION_ID); 260 c.message = message.get<std::string>(ProtocolType::MESSAGE); 261 c.sensitive = message.get<int>(ProtocolType::SENSITIVE); 262 c.isError = message.get<bool>(ProtocolType::RESULT); 263 264 c.from = message.get<std::string>(ProtocolType::FROM); 257 265 258 266 return c; -
trunk/msgclnt.h
r6 r8 64 64 std::vector<SFriend> getFriendList(); 65 65 66 std::string getSessionID( conststd::vector<std::string> & idList);66 std::string getSessionID(std::vector<std::string> & idList); 67 67 68 68 bool tell(const SConversation & conversation); -
trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFC.vcxproj
r4 r8 218 218 <ImportGroup Label="ExtensionTargets"> 219 219 </ImportGroup> 220 <ProjectExtensions> 221 <VisualStudio> 222 <UserProperties RESOURCE_FILE="ChevMsgrClient_MFC.rc" /> 223 </VisualStudio> 224 </ProjectExtensions> 220 225 </Project>
Note:
See TracChangeset
for help on using the changeset viewer.