00001 #include "headers.h"
00002
00003 HttpTestInterfaceParser::HttpTestInterfaceParser(CommandProcessor* cp) : CommandParser(cp)
00004 {}
00005
00006
00007 Command*
00008 HttpTestInterfaceParser::parse(string input) {
00009 stringstream s(input);
00010
00011
00012 s >> m_method;
00013
00014
00015 string hostUrl;
00016 s >> hostUrl;
00017
00018 Command* command;
00019
00020 if (hostUrl == "/") {
00021
00022 return m_commandProcessor->matchCommand(SummaryScreenCommand::commandString);
00023 }
00024
00025
00026 string cgiString;
00027 int locArgBegin = hostUrl.find_first_of("?") + 1;
00028 int locArgEnd = hostUrl.find_first_of(" \n\r", locArgBegin);
00029 cgiString = hostUrl.substr(locArgBegin, locArgEnd - locArgBegin + 1);
00030
00031
00032 if (cgiString.substr(0, 3) == "cmd") {
00033 locArgBegin = 4;
00034
00035 locArgEnd = cgiString.find_first_of(" &", locArgBegin) - 1;
00036
00037 string name = cgiString.substr(4, locArgEnd - locArgBegin + 1);
00038
00039
00040 command = m_commandProcessor->matchCommand(name);
00041 if (command == NULL) {
00042 return NULL;
00043 }
00044
00045 int i = 1;
00046 while (locArgEnd > 0) {
00047
00048
00049 locArgBegin = cgiString.find("=", locArgEnd + 2) + 1;
00050
00051 locArgEnd = cgiString.find_first_of(" &\n\r", locArgBegin) - 1;
00052
00053 string arg = cgiString.substr(locArgBegin, locArgEnd - locArgBegin + 1);
00054 command->setArg(i, arg);
00055 i++;
00056 }
00057 return command;
00058
00059 }
00060 else {
00061 return NULL;
00062 }
00063 }