X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2Fhttpd.cxx;h=5b591b99f7e3bc7ca2e49bf81969922b9e7686e1;hb=ba840da288689d7b634581776b44846a55be579e;hp=bacb67179f7de41d444b884e7a026af5b5b5d058;hpb=432401007452f6468fa847f12d7ad8be15e6f6f9;p=flightgear.git diff --git a/src/Network/httpd.cxx b/src/Network/httpd.cxx index bacb67179..5b591b99f 100644 --- a/src/Network/httpd.cxx +++ b/src/Network/httpd.cxx @@ -34,12 +34,12 @@ #include // atoi() atof() #include STL_STRING -#include STL_STRSTREAM #include #include #include -#include +#include +#include #include
#include
@@ -47,10 +47,7 @@ #include "httpd.hxx" SG_USING_STD(string); -#if !defined(SG_HAVE_NATIVE_SGI_COMPILERS) SG_USING_STD(cout); -SG_USING_STD(istrstream); -#endif bool FGHttpd::open() { @@ -62,7 +59,7 @@ bool FGHttpd::open() { server = new HttpdServer( port ); - set_hz( 5 ); // default to processing requests @ 5Hz + set_hz( 15 ); // default to processing requests @ 15Hz set_enabled( true ); return true; @@ -97,10 +94,9 @@ void HttpdChannel::foundTerminator (void) { string request; string tmp; - unsigned int pos = rest.find( " " ); + string::size_type pos = rest.find( " " ); if ( pos != string::npos ) { request = rest.substr( 0, pos ); - request = urlDecode(request); } else { request = "/"; } @@ -112,6 +108,7 @@ void HttpdChannel::foundTerminator (void) { string args = request.substr( pos + 1 ); request = request.substr( 0, pos ); printf("'%s' '%s'\n", request.c_str(), args.c_str()); + request = urlDecode(request); // parse args looking for "value=" bool done = false; @@ -127,19 +124,38 @@ void HttpdChannel::foundTerminator (void) { } printf(" arg = %s\n", arg.c_str() ); - unsigned int apos = arg.find("="); + string::size_type apos = arg.find("="); if ( apos != string::npos ) { string a = arg.substr( 0, apos ); string b = arg.substr( apos + 1 ); printf(" a = %s b = %s\n", a.c_str(), b.c_str() ); - if ( a == "value" ) { - fgSetString( request, b ); - } + if ( request == "/run.cgi" ) { + // execute a command + if ( a == "value" ) { + SGPropertyNode args; + if ( !globals->get_commands() + ->execute(urlDecode(b).c_str(), &args) ) + { + SG_LOG( SG_GENERAL, SG_ALERT, + "Command " << urlDecode(b) + << " failed."); + } + + } + } else { + if ( a == "value" ) { + // update a property value + fgSetString( request.c_str(), + urlDecode(b).c_str() ); + } + } } } - } + } else { + request = urlDecode(request); + } - node = globals->get_props()->getNode(request); + node = globals->get_props()->getNode(request.c_str()); string response = ""; response += ""; @@ -176,17 +192,12 @@ void HttpdChannel::foundTerminator (void) { for (int i = 0; i < node->nChildren(); i++) { SGPropertyNode *child = node->getChild(i); - string name = child->getName(); - if ( node->getChild(name, 1) ) { - char buf[16]; - sprintf(buf, "[%d]", child->getIndex()); - name += buf; - } + string name = child->getDisplayName(true); string line = ""; if ( child->nChildren() > 0 ) { line += "getStringValue ( name, "" ); + string value = node->getStringValue ( name.c_str(), "" ); line += ""; line += name; line += " "; response += ""; - response += "
"; - response += "
"; + response += "
"; } response += ""; response += getTerminator(); @@ -257,7 +267,7 @@ void HttpdChannel::foundTerminator (void) { } -// encode everything but "a-zA-Z0-9_.-/" +// encode everything but "a-zA-Z0-9_.-/" (see RFC2396) string HttpdChannel::urlEncode(string s) { string r = "";