Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

HttpTestInterfaceParser.cpp

Go to the documentation of this file.
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         // read the GET/POST/etc...
00012     s >> m_method;
00013 
00014     // read the URL
00015     string hostUrl;
00016     s >> hostUrl;
00017 
00018     Command* command;
00019 
00020     if (hostUrl == "/") {
00021         // return the default page
00022         return m_commandProcessor->matchCommand(SummaryScreenCommand::commandString);
00023     }
00024 
00025         // grab everything after the "?"
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     // see if "cmd" is first thing after the "?"
00032     if (cgiString.substr(0, 3) == "cmd") {
00033         locArgBegin = 4;
00034         // find the location end of the command
00035         locArgEnd = cgiString.find_first_of(" &", locArgBegin) - 1;
00036         // get the command
00037         string name = cgiString.substr(4, locArgEnd - locArgBegin + 1);
00038 
00039         // get the object matching this command
00040         command = m_commandProcessor->matchCommand(name);
00041         if (command == NULL) {
00042             return NULL;
00043         }
00044 
00045         int i = 1;
00046         while (locArgEnd > 0) {
00047             // Now go through and get the rest of the args and assign them to the command object
00048             // start right after the command
00049             locArgBegin = cgiString.find("=", locArgEnd + 2) + 1;
00050             // find the end of the argument feild
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 } // fn parse

Generated at Thu Jul 11 13:31:50 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001