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){
|
void HTTP::Parser::SetVar(std::string i, std::string v){
|
||||||
Trim(i);
|
Trim(i);
|
||||||
Trim(v);
|
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.
|
/// 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);
|
conn.write(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
/// Parses GET or POST-style variable data.
|
/// Parses GET or POST-style variable data.
|
||||||
/// Saves to internal variable structure using HTTP::Parser::SetVar.
|
/// Saves to internal variable structure using HTTP::Parser::SetVar.
|
||||||
void HTTP::Parser::parseVars(std::string data){
|
void HTTP::Parser::parseVars(std::string data){
|
||||||
std::string varname;
|
std::string varname;
|
||||||
std::string varval;
|
std::string varval;
|
||||||
while (data.find('=') != std::string::npos){
|
// position where a part start (e.g. after &)
|
||||||
size_t found = data.find('=');
|
size_t pos = 0;
|
||||||
varname = urlunescape(data.substr(0, found));
|
while (pos < data.length()){
|
||||||
data.erase(0, found+1);
|
size_t nextpos = data.find('&', pos);
|
||||||
found = data.find('&');
|
if (nextpos == std::string::npos){
|
||||||
varval = urlunescape(data.substr(0, found));
|
nextpos = data.length();
|
||||||
SetVar(varname, varval);
|
|
||||||
if (found == std::string::npos){
|
|
||||||
data.clear();
|
|
||||||
}else{
|
|
||||||
data.erase(0, found+1);
|
|
||||||
}
|
}
|
||||||
|
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
|
bool
|
||||||
Value::isArray() const
|
Value::isArray() const
|
||||||
{
|
{
|
||||||
return type_ == nullValue || type_ == arrayValue;
|
return type_ == arrayValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Value::isObject() const
|
Value::isObject() const
|
||||||
{
|
{
|
||||||
return type_ == nullValue || type_ == objectValue;
|
return type_ == objectValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <fstream>
|
#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
|
/// Basic signal handler. Disconnects the server_socket if it receives
|
||||||
/// a SIGINT, SIGHUP or SIGTERM signal, but does nothing for SIGPIPE.
|
/// a SIGINT, SIGHUP or SIGTERM signal, but does nothing for SIGPIPE.
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -147,11 +148,14 @@ pid_t Util::Procs::Start(std::string name, std::string cmd, std::string cmd2){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int devnull = open("/dev/null", O_RDWR);
|
||||||
pid_t ret = fork();
|
pid_t ret = fork();
|
||||||
if (ret == 0){
|
if (ret == 0){
|
||||||
close(pfildes[0]);
|
close(pfildes[0]);
|
||||||
dup2(pfildes[1],1);
|
dup2(pfildes[1],STDOUT_FILENO);
|
||||||
close(pfildes[1]);
|
close(pfildes[1]);
|
||||||
|
dup2(devnull, STDIN_FILENO);
|
||||||
|
dup2(devnull, STDERR_FILENO);
|
||||||
runCmd(cmd);
|
runCmd(cmd);
|
||||||
}else{
|
}else{
|
||||||
if (ret > 0){
|
if (ret > 0){
|
||||||
|
@ -165,12 +169,14 @@ pid_t Util::Procs::Start(std::string name, std::string cmd, std::string cmd2){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t ret2 = fork();
|
pid_t ret2 = fork();
|
||||||
if (ret2 == 0){
|
if (ret2 == 0){
|
||||||
close(pfildes[1]);
|
close(pfildes[1]);
|
||||||
dup2(pfildes[0],0);
|
dup2(pfildes[0],STDIN_FILENO);
|
||||||
close(pfildes[0]);
|
close(pfildes[0]);
|
||||||
|
dup2(devnull, STDOUT_FILENO);
|
||||||
|
dup2(devnull, STDERR_FILENO);
|
||||||
runCmd(cmd2);
|
runCmd(cmd2);
|
||||||
}else{
|
}else{
|
||||||
if (ret2 > 0){
|
if (ret2 > 0){
|
||||||
|
|
Loading…
Add table
Reference in a new issue