upd: setting up structure
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
class FatalError : public std::exception {
|
||||
public:
|
||||
FatalError(const char *__message, int __code)
|
||||
@ -104,4 +105,8 @@ void debugPrint(Args... args) {
|
||||
std::cerr << std::endl;
|
||||
BookStore_ZYM::debug_Print_Mutex.unlock();
|
||||
}
|
||||
|
||||
void Respond(BlockingStringStream *output_ptr, std::string SessionToken,
|
||||
std::string OperationToken, std::string AuthenticationKey,
|
||||
const std::vector<std::string> &ret);
|
||||
#endif // PROTECTOR_UTILITY_H
|
@ -22,5 +22,7 @@ class BookStoreBackEndClass {
|
||||
}
|
||||
~BookStoreBackEndClass() { delete engine_ptr; }
|
||||
void Run();
|
||||
void PostRequest(std::string SessionToken, std::string OperationToken,
|
||||
std::string AuthenticationKey, std::string cmd);
|
||||
};
|
||||
#endif // PROTECTOR_SCHEDULE_H
|
@ -62,4 +62,17 @@ void BlockingStringStream::unreadlock() {
|
||||
is_writing = false;
|
||||
mutex.unlock();
|
||||
condition.notify_all();
|
||||
}
|
||||
|
||||
void Respond(BlockingStringStream *output_ptr, std::string SessionToken,
|
||||
std::string OperationToken, std::string AuthenticationKey,
|
||||
const std::vector<std::string> & ret) {
|
||||
static std::mutex output_mutex;
|
||||
output_mutex.lock();
|
||||
(*output_ptr).readlock();
|
||||
(*output_ptr) << SessionToken << ' ' << OperationToken << " " << ret.size()
|
||||
<< '\n';
|
||||
for (int i = 0; i < ret.size(); i++) (*output_ptr) << ret[i] << '\n';
|
||||
(*output_ptr).unreadlock();
|
||||
output_mutex.unlock();
|
||||
}
|
@ -32,14 +32,20 @@ void BookStoreBackEndClass::Run() {
|
||||
(*output_ptr).readlock();
|
||||
(*output_ptr) << TempChannelID << " IinitialOpt 1\n"
|
||||
<< new_SessionToken << ' ' << new_AuthenticationKey << '\n';
|
||||
// assert((*output_ptr).internalStream.peek() != EOF);
|
||||
(*output_ptr).unreadlock();
|
||||
// assert((*output_ptr).is_writing == false);
|
||||
// debugPrint("Sent Response Init");
|
||||
} else if (request_data[1] == 'C') {
|
||||
;
|
||||
} else if (request_data[1] == '_') {
|
||||
;
|
||||
std::stringstream ss(request_data);
|
||||
std::string SessionToken;
|
||||
std::string OperationToken;
|
||||
std::string OuthenticationKey;
|
||||
std::string cmd;
|
||||
ss >> cmd >> SessionToken >> OperationToken >> OuthenticationKey;
|
||||
(*output_ptr).readlock();
|
||||
(*output_ptr) << SessionToken << ' ' << OperationToken << " 1\n"
|
||||
<< "[Internal Error] This API shouldn't be called\n";
|
||||
(*output_ptr).unreadlock();
|
||||
} else if (request_data[1] == 'S') {
|
||||
return;
|
||||
} else if (request_data[1] == 'R') {
|
||||
@ -51,17 +57,20 @@ void BookStoreBackEndClass::Run() {
|
||||
ss >> cmd >> SessionToken >> OperationToken >> OuthenticationKey;
|
||||
ss.get();
|
||||
std::getline(ss, cmd);
|
||||
// debugPrint("SessionToken=", SessionToken,
|
||||
// " OperationToken=", OperationToken,
|
||||
// " OuthenticationKey=", OuthenticationKey, " cmd=", cmd);
|
||||
(*output_ptr).readlock();
|
||||
(*output_ptr) << SessionToken << ' ' << OperationToken << " 1\n"
|
||||
<< cmd << '\n';
|
||||
// assert((*output_ptr).internalStream.peek() != EOF);
|
||||
(*output_ptr).unreadlock();
|
||||
// assert((*output_ptr).is_writing == false);
|
||||
// debugPrint("Sent Response id=", OperationToken);
|
||||
// debugPrint(SessionToken, ' ', OperationToken, " 1\n", cmd);
|
||||
PostRequest(SessionToken, OperationToken, OuthenticationKey, cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookStoreBackEndClass::PostRequest(std::string SessionToken,
|
||||
std::string OperationToken,
|
||||
std::string AuthenticationKey,
|
||||
std::string cmd) {
|
||||
if (session_map[SessionToken].OuthorizationKey != AuthenticationKey) {
|
||||
Respond(output_ptr, SessionToken, OperationToken, AuthenticationKey,
|
||||
std::vector<std::string>({"[Error] AuthenticationKey is wrong"}));
|
||||
return;
|
||||
}
|
||||
Respond(output_ptr, SessionToken, OperationToken, AuthenticationKey,
|
||||
std::vector<std::string>({cmd}));
|
||||
}
|
Reference in New Issue
Block a user