|
@@ -69,17 +69,17 @@ void con_handler::handle_read_version(const boost::system::error_code &err,
|
|
|
answer["accept"] = true;
|
|
|
const std::string answerString = Json::writeString(stringBuilder, answer);
|
|
|
|
|
|
- // send answer
|
|
|
- sock.async_write_some(buffer(answerString, max_length),
|
|
|
- boost::bind(&con_handler::handle_write,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
- placeholders::bytes_transferred));
|
|
|
-
|
|
|
// read next data
|
|
|
sock.async_read_some(buffer(data, max_length),
|
|
|
boost::bind(&con_handler::handle_read_login,
|
|
|
shared_from_this(), placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
+
|
|
|
+ // send answer
|
|
|
+ sock.async_write_some(buffer(answerString, max_length),
|
|
|
+ boost::bind(&con_handler::handle_write,
|
|
|
+ shared_from_this(), placeholders::error,
|
|
|
+ placeholders::bytes_transferred));
|
|
|
} else {
|
|
|
answer["accept"] = false;
|
|
|
const std::string answerString = Json::writeString(stringBuilder, answer);
|
|
@@ -125,17 +125,17 @@ void con_handler::handle_read_login(const boost::system::error_code &err,
|
|
|
answer["accept"] = true;
|
|
|
const std::string answerString = Json::writeString(stringBuilder, answer);
|
|
|
|
|
|
- // send answer
|
|
|
- sock.async_write_some(buffer(answerString, max_length),
|
|
|
- boost::bind(&con_handler::handle_write,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
- placeholders::bytes_transferred));
|
|
|
-
|
|
|
// read next data
|
|
|
sock.async_read_some(buffer(data, max_length),
|
|
|
boost::bind(&con_handler::handle_read_command,
|
|
|
shared_from_this(), placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
+
|
|
|
+ // send answer
|
|
|
+ sock.async_write_some(buffer(answerString, max_length),
|
|
|
+ boost::bind(&con_handler::handle_write,
|
|
|
+ shared_from_this(), placeholders::error,
|
|
|
+ placeholders::bytes_transferred));
|
|
|
} else {
|
|
|
answer["accept"] = false;
|
|
|
const std::string answerString = Json::writeString(stringBuilder, answer);
|
|
@@ -176,6 +176,12 @@ void con_handler::handle_read_command(const boost::system::error_code &err,
|
|
|
|
|
|
// check command
|
|
|
if (root["command"].compare("status") == 0) {
|
|
|
+ // read next data
|
|
|
+ sock.async_read_some(buffer(data, max_length),
|
|
|
+ boost::bind(&con_handler::handle_read_command,
|
|
|
+ shared_from_this(), placeholders::error,
|
|
|
+ placeholders::bytes_transferred));
|
|
|
+
|
|
|
answer["command"] = "status";
|
|
|
|
|
|
// TODO answer a real status message
|
|
@@ -187,13 +193,13 @@ void con_handler::handle_read_command(const boost::system::error_code &err,
|
|
|
boost::bind(&con_handler::handle_write,
|
|
|
shared_from_this(), placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
-
|
|
|
+ } else if (root["command"].compare("list") == 0) {
|
|
|
// read next data
|
|
|
sock.async_read_some(buffer(data, max_length),
|
|
|
boost::bind(&con_handler::handle_read_command,
|
|
|
shared_from_this(), placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
- } else if (root["command"].compare("list") == 0) {
|
|
|
+
|
|
|
answer["command"] = "list";
|
|
|
|
|
|
// TODO look for real data
|
|
@@ -211,12 +217,13 @@ void con_handler::handle_read_command(const boost::system::error_code &err,
|
|
|
shared_from_this(), placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
|
|
|
+ } else if (root["command"].compare("put") == 0) {
|
|
|
// read next data
|
|
|
sock.async_read_some(buffer(data, max_length),
|
|
|
boost::bind(&con_handler::handle_read_command,
|
|
|
shared_from_this(), placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
- } else if (root["command"].compare("put") == 0) {
|
|
|
+
|
|
|
answer["command"] = "put";
|
|
|
|
|
|
// TODO establish real connection and receive file
|
|
@@ -228,84 +235,66 @@ void con_handler::handle_read_command(const boost::system::error_code &err,
|
|
|
boost::bind(&con_handler::handle_write,
|
|
|
shared_from_this(), placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
-
|
|
|
+ } else if (root["command"].compare("get") == 0) {
|
|
|
// read next data
|
|
|
sock.async_read_some(buffer(data, max_length),
|
|
|
boost::bind(&con_handler::handle_read_command,
|
|
|
shared_from_this(), placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
- } else if (root["command"].compare("get") == 0) {
|
|
|
+
|
|
|
answer["command"] = "get";
|
|
|
|
|
|
// a get request is already being progressed
|
|
|
- if(this->getFile.is_open()) {
|
|
|
+ if (this->getFile.is_open()) {
|
|
|
answer["accept"] = false;
|
|
|
|
|
|
- const std::string answerString = Json::writeString(stringBuilder, answer);
|
|
|
+ const std::string answerString =
|
|
|
+ Json::writeString(stringBuilder, answer);
|
|
|
// send answer
|
|
|
- sock.async_write_some(buffer(answerString, max_length),
|
|
|
- boost::bind(&con_handler::handle_write,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
- placeholders::bytes_transferred));
|
|
|
-
|
|
|
- // read next data
|
|
|
- sock.async_read_some(buffer(data, max_length),
|
|
|
- boost::bind(&con_handler::handle_read_command,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
- placeholders::bytes_transferred));
|
|
|
+ sock.async_write_some(
|
|
|
+ buffer(answerString, max_length),
|
|
|
+ boost::bind(&con_handler::handle_write, shared_from_this(),
|
|
|
+ placeholders::error, placeholders::bytes_transferred));
|
|
|
} else {
|
|
|
// open file
|
|
|
const std::string filename = root["file"].asString();
|
|
|
- if(filename.find("/") != std::string::npos) {
|
|
|
+ if (filename.find("/") != std::string::npos) {
|
|
|
// slashes in file names are illegal
|
|
|
answer["accept"] = false;
|
|
|
|
|
|
- const std::string answerString = Json::writeString(stringBuilder, answer);
|
|
|
+ const std::string answerString =
|
|
|
+ Json::writeString(stringBuilder, answer);
|
|
|
// send answer
|
|
|
sock.async_write_some(buffer(answerString, max_length),
|
|
|
boost::bind(&con_handler::handle_write,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
+ shared_from_this(),
|
|
|
+ placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
-
|
|
|
- // read next data
|
|
|
- sock.async_read_some(buffer(data, max_length),
|
|
|
- boost::bind(&con_handler::handle_read_command,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
- placeholders::bytes_transferred));
|
|
|
} else {
|
|
|
std::string file = this->fileDirectory;
|
|
|
file.append(filename);
|
|
|
|
|
|
this->getFile = std::ifstream(file, std::ios::ate | std::ios::binary);
|
|
|
|
|
|
- if(this->getFile.is_open() == 0) {
|
|
|
+ if (this->getFile.is_open() == 0) {
|
|
|
// file does not exist or cannot be opened
|
|
|
answer["accept"] = false;
|
|
|
|
|
|
- const std::string answerString = Json::writeString(stringBuilder, answer);
|
|
|
+ const std::string answerString =
|
|
|
+ Json::writeString(stringBuilder, answer);
|
|
|
// send answer
|
|
|
sock.async_write_some(buffer(answerString, max_length),
|
|
|
boost::bind(&con_handler::handle_write,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
+ shared_from_this(),
|
|
|
+ placeholders::error,
|
|
|
placeholders::bytes_transferred));
|
|
|
-
|
|
|
- // read next data
|
|
|
- sock.async_read_some(buffer(data, max_length),
|
|
|
- boost::bind(&con_handler::handle_read_command,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
- placeholders::bytes_transferred));
|
|
|
} else {
|
|
|
- sock.async_read_some(buffer(data, max_length),
|
|
|
- boost::bind(&con_handler::handle_read_command,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
- placeholders::bytes_transferred));
|
|
|
-
|
|
|
// get size of file
|
|
|
size_t size = this->getFile.tellg();
|
|
|
this->getFile.seekg(std::ios::beg);
|
|
|
|
|
|
char fileBuffer[9];
|
|
|
- while(size_t read = this->getFile.readsome(fileBuffer, 8)) {
|
|
|
+ while (size_t read = this->getFile.readsome(fileBuffer, 8)) {
|
|
|
fileBuffer[read] = 0;
|
|
|
size -= read;
|
|
|
int remaining = size / 8 + (size % 8 == 0 ? 0 : 1);
|
|
@@ -313,12 +302,14 @@ void con_handler::handle_read_command(const boost::system::error_code &err,
|
|
|
answer["cancel"] = false;
|
|
|
answer["data"] = base64::encode(fileBuffer);
|
|
|
|
|
|
- const std::string answerString = Json::writeString(stringBuilder, answer);
|
|
|
+ const std::string answerString =
|
|
|
+ Json::writeString(stringBuilder, answer);
|
|
|
|
|
|
- sock.async_write_some(buffer(answerString, max_length),
|
|
|
- boost::bind(&con_handler::handle_write,
|
|
|
- shared_from_this(), placeholders::error,
|
|
|
- placeholders::bytes_transferred));
|
|
|
+ sock.async_write_some(
|
|
|
+ buffer(answerString, max_length),
|
|
|
+ boost::bind(&con_handler::handle_write, shared_from_this(),
|
|
|
+ placeholders::error,
|
|
|
+ placeholders::bytes_transferred));
|
|
|
}
|
|
|
}
|
|
|
}
|