ServerCatchcopy::inputReturnType ServerCatchcopy::parseInputCurrentProtocol(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &returnList) { if(returnList.size()==0) return WrongArgumentListSize; //if is supported std::string firstArgument=returnList.front(); if(firstArgument=="protocol") { if(returnList.size()!=2) return WrongArgumentListSize; emit askProtocolCompatibility(client,orderId,returnList.back()); return Ok; } else if(firstArgument=="protocol extension") { if(returnList.size()>3 || returnList.size()<2) return WrongArgumentListSize; return ExtensionWrong; } else if(firstArgument=="client") { if(returnList.size()!=2) return WrongArgumentListSize; int index=0; int size=clientList.size(); while(index<size) { if(clientList.at(index).id==client) { clientList[index].name=returnList.back(); break; } index++; } emit clientName(client,returnList.back()); clientRegistered(client,orderId); return Replied; } else if(firstArgument=="server") { if(returnList.size()!=2) return WrongArgumentListSize; if(returnList.back()!="name?") return WrongArgument; serverName(client,orderId,name); return Replied; } else if(firstArgument=="cp") { if(returnList.size()<3) return WrongArgumentListSize; std::vector<std::string> sourceList=returnList; sourceList.erase(sourceList.cbegin()); sourceList.pop_back(); emitNewCopy(client,orderId,sourceList,returnList.back()); return Ok; } else if(firstArgument=="cp-?") { if(returnList.size()<2) return WrongArgumentListSize; std::vector<std::string> sourceList=returnList; sourceList.erase(sourceList.cbegin()); emitNewCopyWithoutDestination(client,orderId,sourceList); return Ok; } else if(firstArgument=="mv") { if(returnList.size()<3) return WrongArgumentListSize; std::vector<std::string> sourceList=returnList; sourceList.erase(sourceList.cbegin()); sourceList.pop_back(); emitNewMove(client,orderId,sourceList,returnList.back()); return Ok; } else if(firstArgument=="mv-?") { if(returnList.size()<2) return WrongArgumentListSize; std::vector<std::string> sourceList=returnList; sourceList.erase(sourceList.cbegin()); emitNewMoveWithoutDestination(client,orderId,sourceList); return Ok; } else //if is not supported return UnknowOrder; }
ServerCatchcopy::inputReturnType ServerCatchcopy::parseInputCurrentProtocol(quint32 client,quint32 orderId,QStringList returnList) { if(returnList.size()==0) return WrongArgumentListSize; //if is supported QString firstArgument=returnList.first(); if(firstArgument=="protocol") { if(returnList.size()!=2) return WrongArgumentListSize; emit askProtocolCompatibility(client,orderId,returnList.last()); return Ok; } else if(firstArgument=="protocol extension") { if(returnList.size()>3 || returnList.size()<2) return WrongArgumentListSize; if(!autoReply) { if(returnList.size()==2) emit askProtocolExtension(client,orderId,returnList.last()); else emit askProtocolExtension(client,orderId,returnList.at(1),returnList.last()); } return ExtensionWrong; } else if(firstArgument=="client") { if(returnList.size()!=2) return WrongArgumentListSize; emit clientName(client,returnList.last()); if(autoReply) { clientRegistered(client,orderId); return Replied; } else { emit clientName(client,orderId,returnList.last()); return Ok; } } else if(firstArgument=="server") { if(returnList.size()!=2) return WrongArgumentListSize; if(returnList.last()!="name?") return WrongArgument; if(autoReply) { serverName(client,orderId,name); return Replied; } else { askServerName(client,orderId); return Ok; } } else if(firstArgument=="cp") { if(returnList.size()<3) return WrongArgumentListSize; QStringList sourceList=returnList; sourceList.removeFirst(); sourceList.removeLast(); emitNewCopy(client,orderId,sourceList,returnList.last()); return Ok; } else if(firstArgument=="cp-?") { if(returnList.size()<2) return WrongArgumentListSize; QStringList sourceList=returnList; sourceList.removeFirst(); emitNewCopy(client,orderId,sourceList); return Ok; } else if(firstArgument=="mv") { if(returnList.size()<3) return WrongArgumentListSize; QStringList sourceList=returnList; sourceList.removeFirst(); sourceList.removeLast(); emitNewMove(client,orderId,sourceList,returnList.last()); return Ok; } else if(firstArgument=="mv-?") { if(returnList.size()<2) return WrongArgumentListSize; QStringList sourceList=returnList; sourceList.removeFirst(); emitNewMove(client,orderId,sourceList); return Ok; } else //if is not supported return UnknowOrder; }