bool RConImpl::rcon(const str& host, siz port, const str& cmd, str& reply) const { str_vec packets; if(!aocom(cmd, packets, host, port, TIMEOUT)) return false; const str header = "\xFF\xFF\xFF\xFFprint\x0A"; if(packets.empty()) { log("Empty response."); return false; } reply.clear(); for(const str& packet: packets) { if(packet.find(header) != 0) { log("Unrecognised response."); return false; } reply.append(packet.substr(header.size())); } return true; }
void CommandProcessor::handleCmd(str& input, str& output) { // Note: HELP command cannot simply have a handler because this static handler // will not be able to access the vector of commands if(input.beginsWithWholeWordIgnoreCase(HELP_STR)) { pointToParameters(input, HELP_STR); getHelpText(input, output); } else { unsigned int i=0; for(i=0; i < mCmdHandlerVector.size(); i++) { CmdProcessorType &cp = mCmdHandlerVector[i]; // If a command matches, return the response from the attached function pointer if(input.beginsWithWholeWordIgnoreCase(cp.pCommandStr)) { pointToParameters(input, cp.pCommandStr); output.clear(); cp.pFunc(input, output, cp.pDataParam, cp.dataParamLen); break; } } if(i >= mCmdHandlerVector.size()) { output = CMD_INVALID_STR; } } }