Merge branch 'master' of github.com:DDVTECH/DMS into DTSC
This commit is contained in:
commit
92b475e71b
4 changed files with 40 additions and 18 deletions
|
@ -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 <iostream>
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <fstream>
|
||||
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.
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <errno.h>
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -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){
|
||||
|
@ -169,8 +173,10 @@ pid_t Util::Procs::Start(std::string name, std::string cmd, std::string cmd2){
|
|||
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){
|
||||
|
|
Loading…
Add table
Reference in a new issue