|
@@ -110,12 +110,21 @@ void UserIoManager::run() {
|
|
|
}
|
|
|
case CMD_PUT: {
|
|
|
|
|
|
+ if(tokens.size() < 2) {
|
|
|
+ std::cerr << "no file specified" << std::endl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
boost::asio::streambuf recvbuf;
|
|
|
Json::Value root, ackRecv;
|
|
|
|
|
|
std::fstream fs;
|
|
|
fs.open(tokens[1].c_str(), std::fstream::in | std::fstream::binary);
|
|
|
|
|
|
+ if(!fs.is_open()) {
|
|
|
+ std::cerr << "couldnt open file " << tokens[1] << std::endl;
|
|
|
+ break;
|
|
|
+ }
|
|
|
// determine file size
|
|
|
fs.seekg(0, fs.end);
|
|
|
int filelen = fs.tellg();
|
|
@@ -211,6 +220,10 @@ void UserIoManager::run() {
|
|
|
}
|
|
|
case CMD_GET: {
|
|
|
|
|
|
+ if(tokens.size() < 2) {
|
|
|
+ std::cerr << "no file specified" << std::endl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
boost::asio::streambuf recvbuf;
|
|
|
Json::Value root, recvAck;
|
|
@@ -233,8 +246,7 @@ void UserIoManager::run() {
|
|
|
}
|
|
|
if(!parseJson(&root, recvbuf)){
|
|
|
std::cerr << "received invalid JSON from server" << std::endl;
|
|
|
- keep_reading = false;
|
|
|
- continue;
|
|
|
+ continue;
|
|
|
}
|
|
|
|
|
|
std::cout << root << std::endl;
|
|
@@ -305,6 +317,62 @@ void UserIoManager::run() {
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
+ case CMD_LIST: {
|
|
|
+ boost::asio::streambuf recvbuf;
|
|
|
+ Json::Value root, recv;
|
|
|
+ // const char *recvjson;
|
|
|
+
|
|
|
+ int chunks, rec = 0;
|
|
|
+ root["command"] = "list";
|
|
|
+ if(!sendJson(root)) {
|
|
|
+ std::cerr << "couldn't send json" << std::endl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(!receiveJson(recvbuf)) {
|
|
|
+ std::cerr << "couldn't receive json" << std::endl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(!parseJson(&recv, recvbuf)) {
|
|
|
+ std::cerr << "couldn't parse json" << std::endl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(recv["accept"].asBool()) {
|
|
|
+ // ACK?
|
|
|
+ root["command"] = "list";
|
|
|
+ root["cancel"] = false;
|
|
|
+ chunks = std::numeric_limits<int>::max();
|
|
|
+ while(chunks) {
|
|
|
+ if(!receiveJson(recvbuf)) {
|
|
|
+ std::cerr << "couldn't receive json" << std::endl;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(!parseJson(&recv, recvbuf)) {
|
|
|
+ std::cerr << "couldn't parse json" << std::endl;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // dump received data
|
|
|
+ if(recv["names"].isArray()) {
|
|
|
+ for(Json::Value name : recv["names"]){
|
|
|
+ std::cout << name.asString();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ std::cerr << "should have recieved an array of files, but did not receive an array" << std::endl;
|
|
|
+ }
|
|
|
+ chunks = recv["remaining"].asInt();
|
|
|
+ root["received"] = rec;
|
|
|
+ if(!sendJson(root)) {
|
|
|
+ // couldnt ACK
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ rec++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ std::cerr << "server refused listing" << std::endl;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
case CMD_DISCONNECT: {
|
|
|
std::printf("disconnecting\n");
|
|
|
keep_reading = false;
|