diff --git a/util/http_parser.cpp b/util/http_parser.cpp index d2b2ac89..7a087f70 100644 --- a/util/http_parser.cpp +++ b/util/http_parser.cpp @@ -109,7 +109,10 @@ void HTTP::Parser::SetHeader(std::string i, int v){ void HTTP::Parser::SetVar(std::string i, std::string v){ Trim(i); Trim(v); - vars[i] = v; + //only set if there is actually a key + if(!i.empty()){ + vars[i] = v; + } } /// Attempt to read a whole HTTP request or response from Socket::Connection. @@ -201,23 +204,36 @@ void HTTP::Parser::SendResponse(Socket::Connection & conn, std::string code, std conn.write(tmp); } +#include /// Parses GET or POST-style variable data. /// Saves to internal variable structure using HTTP::Parser::SetVar. void HTTP::Parser::parseVars(std::string data){ std::string varname; std::string varval; - while (data.find('=') != std::string::npos){ - size_t found = data.find('='); - varname = urlunescape(data.substr(0, found)); - data.erase(0, found+1); - found = data.find('&'); - varval = urlunescape(data.substr(0, found)); - SetVar(varname, varval); - if (found == std::string::npos){ - data.clear(); - }else{ - data.erase(0, found+1); + // position where a part start (e.g. after &) + size_t pos = 0; + while (pos < data.length()){ + size_t nextpos = data.find('&', pos); + if (nextpos == std::string::npos){ + nextpos = data.length(); } + size_t eq_pos = data.find('=', pos); + if (eq_pos < nextpos){ + // there is a key and value + varname = data.substr(pos, eq_pos - pos); + varval = data.substr(eq_pos + 1, nextpos - eq_pos - 1); + }else{ + // no value, only a key + varname = data.substr(pos, nextpos - pos); + varval.clear(); + } + SetVar(urlunescape(varname), urlunescape(varval)); + if (nextpos == std::string::npos){ + // in case the string is gigantic + break; + } + // erase & + pos = nextpos + 1; } } diff --git a/util/json/json_value.cpp b/util/json/json_value.cpp index f418af26..21996f4a 100644 --- a/util/json/json_value.cpp +++ b/util/json/json_value.cpp @@ -1312,14 +1312,14 @@ Value::isString() const bool Value::isArray() const { - return type_ == nullValue || type_ == arrayValue; + return type_ == arrayValue; } bool Value::isObject() const { - return type_ == nullValue || type_ == objectValue; + return type_ == objectValue; } diff --git a/util/server_setup.cpp b/util/server_setup.cpp index 75ac19fe..ae15ff87 100644 --- a/util/server_setup.cpp +++ b/util/server_setup.cpp @@ -27,7 +27,7 @@ #include #include #include -Socket::Server server_socket(-1); ///< Placeholder for the server socket +Socket::Server server_socket; ///< Placeholder for the server socket /// Basic signal handler. Disconnects the server_socket if it receives /// a SIGINT, SIGHUP or SIGTERM signal, but does nothing for SIGPIPE. diff --git a/util/util.cpp b/util/util.cpp index d599c0d0..773248f7 100644 --- a/util/util.cpp +++ b/util/util.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -147,11 +148,14 @@ pid_t Util::Procs::Start(std::string name, std::string cmd, std::string cmd2){ return 0; } + int devnull = open("/dev/null", O_RDWR); pid_t ret = fork(); if (ret == 0){ close(pfildes[0]); - dup2(pfildes[1],1); + dup2(pfildes[1],STDOUT_FILENO); close(pfildes[1]); + dup2(devnull, STDIN_FILENO); + dup2(devnull, STDERR_FILENO); runCmd(cmd); }else{ if (ret > 0){ @@ -165,12 +169,14 @@ pid_t Util::Procs::Start(std::string name, std::string cmd, std::string cmd2){ return 0; } } - + pid_t ret2 = fork(); if (ret2 == 0){ close(pfildes[1]); - dup2(pfildes[0],0); + dup2(pfildes[0],STDIN_FILENO); close(pfildes[0]); + dup2(devnull, STDOUT_FILENO); + dup2(devnull, STDERR_FILENO); runCmd(cmd2); }else{ if (ret2 > 0){