upd: setting up structure
This commit is contained in:
@ -11,6 +11,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
class FatalError : public std::exception {
|
class FatalError : public std::exception {
|
||||||
public:
|
public:
|
||||||
FatalError(const char *__message, int __code)
|
FatalError(const char *__message, int __code)
|
||||||
@ -104,4 +105,8 @@ void debugPrint(Args... args) {
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
BookStore_ZYM::debug_Print_Mutex.unlock();
|
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
|
#endif // PROTECTOR_UTILITY_H
|
@ -22,5 +22,7 @@ class BookStoreBackEndClass {
|
|||||||
}
|
}
|
||||||
~BookStoreBackEndClass() { delete engine_ptr; }
|
~BookStoreBackEndClass() { delete engine_ptr; }
|
||||||
void Run();
|
void Run();
|
||||||
|
void PostRequest(std::string SessionToken, std::string OperationToken,
|
||||||
|
std::string AuthenticationKey, std::string cmd);
|
||||||
};
|
};
|
||||||
#endif // PROTECTOR_SCHEDULE_H
|
#endif // PROTECTOR_SCHEDULE_H
|
@ -63,3 +63,16 @@ void BlockingStringStream::unreadlock() {
|
|||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
condition.notify_all();
|
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).readlock();
|
||||||
(*output_ptr) << TempChannelID << " IinitialOpt 1\n"
|
(*output_ptr) << TempChannelID << " IinitialOpt 1\n"
|
||||||
<< new_SessionToken << ' ' << new_AuthenticationKey << '\n';
|
<< new_SessionToken << ' ' << new_AuthenticationKey << '\n';
|
||||||
// assert((*output_ptr).internalStream.peek() != EOF);
|
|
||||||
(*output_ptr).unreadlock();
|
(*output_ptr).unreadlock();
|
||||||
// assert((*output_ptr).is_writing == false);
|
|
||||||
// debugPrint("Sent Response Init");
|
|
||||||
} else if (request_data[1] == 'C') {
|
} else if (request_data[1] == 'C') {
|
||||||
;
|
;
|
||||||
} else if (request_data[1] == '_') {
|
} 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') {
|
} else if (request_data[1] == 'S') {
|
||||||
return;
|
return;
|
||||||
} else if (request_data[1] == 'R') {
|
} else if (request_data[1] == 'R') {
|
||||||
@ -51,17 +57,20 @@ void BookStoreBackEndClass::Run() {
|
|||||||
ss >> cmd >> SessionToken >> OperationToken >> OuthenticationKey;
|
ss >> cmd >> SessionToken >> OperationToken >> OuthenticationKey;
|
||||||
ss.get();
|
ss.get();
|
||||||
std::getline(ss, cmd);
|
std::getline(ss, cmd);
|
||||||
// debugPrint("SessionToken=", SessionToken,
|
PostRequest(SessionToken, OperationToken, OuthenticationKey, cmd);
|
||||||
// " 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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