Fixes
This commit is contained in:
parent
dd9eb3522a
commit
3f3d6c0222
3 changed files with 34 additions and 11 deletions
|
@ -178,9 +178,12 @@ bool HTTP::Parser::parse(){
|
||||||
if (seenHeaders){
|
if (seenHeaders){
|
||||||
if (length > 0){
|
if (length > 0){
|
||||||
if (HTTPbuffer.length() >= length){
|
if (HTTPbuffer.length() >= length){
|
||||||
|
if ((method != "HTTP/1.0") && (method != "HTTP/1.1")){
|
||||||
|
body = HTTPbuffer.substr(0, length);
|
||||||
|
parseVars(body); //parse POST variables
|
||||||
|
}
|
||||||
body = HTTPbuffer.substr(0, length);
|
body = HTTPbuffer.substr(0, length);
|
||||||
HTTPbuffer.erase(0, length);
|
HTTPbuffer.erase(0, length);
|
||||||
parseVars(body); //parse POST variables
|
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -29,7 +29,7 @@ Socket::Connection::Connection(){
|
||||||
|
|
||||||
/// Close connection. The internal socket is closed and then set to -1.
|
/// Close connection. The internal socket is closed and then set to -1.
|
||||||
void Socket::Connection::close(){
|
void Socket::Connection::close(){
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 6
|
||||||
fprintf(stderr, "Socket closed.\n");
|
fprintf(stderr, "Socket closed.\n");
|
||||||
#endif
|
#endif
|
||||||
shutdown(sock, SHUT_RDWR);
|
shutdown(sock, SHUT_RDWR);
|
||||||
|
@ -81,14 +81,24 @@ Socket::Connection::Connection(std::string address, bool nonblock){
|
||||||
/// \param port String containing the port to connect to.
|
/// \param port String containing the port to connect to.
|
||||||
/// \param nonblock Whether the socket should be nonblocking.
|
/// \param nonblock Whether the socket should be nonblocking.
|
||||||
Socket::Connection::Connection(std::string host, int port, bool nonblock){
|
Socket::Connection::Connection(std::string host, int port, bool nonblock){
|
||||||
struct addrinfo *result, *rp;
|
struct addrinfo *result, *rp, hints;
|
||||||
Error = false;
|
Error = false;
|
||||||
Blocking = false;
|
Blocking = false;
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << port;
|
ss << port;
|
||||||
if (getaddrinfo(host.c_str(), ss.str().c_str(), 0, &result) != 0){
|
|
||||||
|
memset(&hints, 0, sizeof(struct addrinfo));
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
hints.ai_flags = AI_ADDRCONFIG;
|
||||||
|
hints.ai_protocol = 0;
|
||||||
|
hints.ai_canonname = NULL;
|
||||||
|
hints.ai_addr = NULL;
|
||||||
|
hints.ai_next = NULL;
|
||||||
|
int s = getaddrinfo(host.c_str(), ss.str().c_str(), &hints, &result);
|
||||||
|
if (s != 0){
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
fprintf(stderr, "Could not connect to %s:%i! Error: %s\n", host.c_str(), port, strerror(errno));
|
fprintf(stderr, "Could not connect to %s:%i! Error: %s\n", host.c_str(), port, gai_strerror(s));
|
||||||
#endif
|
#endif
|
||||||
close();
|
close();
|
||||||
return;
|
return;
|
||||||
|
@ -96,10 +106,11 @@ Socket::Connection::Connection(std::string host, int port, bool nonblock){
|
||||||
|
|
||||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||||
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
|
||||||
if (sock == -1){continue;}
|
if (sock < 0){continue;}
|
||||||
if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1){break;}
|
if (connect(sock, rp->ai_addr, rp->ai_addrlen) == 0){break;}
|
||||||
::close(sock);
|
::close(sock);
|
||||||
}
|
}
|
||||||
|
freeaddrinfo(result);
|
||||||
|
|
||||||
if (rp == 0){
|
if (rp == 0){
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
|
@ -534,18 +545,18 @@ Socket::Connection Socket::Server::accept(bool nonblock){
|
||||||
}else{
|
}else{
|
||||||
if (addrinfo.sin6_family == AF_INET6){
|
if (addrinfo.sin6_family == AF_INET6){
|
||||||
tmp.remotehost = inet_ntop(AF_INET6, &(addrinfo.sin6_addr), addrconv, INET6_ADDRSTRLEN);
|
tmp.remotehost = inet_ntop(AF_INET6, &(addrinfo.sin6_addr), addrconv, INET6_ADDRSTRLEN);
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 6
|
||||||
fprintf(stderr,"IPv6 addr: %s\n", tmp.remotehost.c_str());
|
fprintf(stderr,"IPv6 addr: %s\n", tmp.remotehost.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (addrinfo.sin6_family == AF_INET){
|
if (addrinfo.sin6_family == AF_INET){
|
||||||
tmp.remotehost = inet_ntop(AF_INET, &(((sockaddr_in*)&addrinfo)->sin_addr), addrconv, INET6_ADDRSTRLEN);
|
tmp.remotehost = inet_ntop(AF_INET, &(((sockaddr_in*)&addrinfo)->sin_addr), addrconv, INET6_ADDRSTRLEN);
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 6
|
||||||
fprintf(stderr,"IPv4 addr: %s\n", tmp.remotehost.c_str());
|
fprintf(stderr,"IPv4 addr: %s\n", tmp.remotehost.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (addrinfo.sin6_family == AF_UNIX){
|
if (addrinfo.sin6_family == AF_UNIX){
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 6
|
||||||
tmp.remotehost = ((sockaddr_un*)&addrinfo)->sun_path;
|
tmp.remotehost = ((sockaddr_un*)&addrinfo)->sun_path;
|
||||||
fprintf(stderr,"Unix socket, no address\n");
|
fprintf(stderr,"Unix socket, no address\n");
|
||||||
#endif
|
#endif
|
||||||
|
@ -557,7 +568,7 @@ Socket::Connection Socket::Server::accept(bool nonblock){
|
||||||
|
|
||||||
/// Close connection. The internal socket is closed and then set to -1.
|
/// Close connection. The internal socket is closed and then set to -1.
|
||||||
void Socket::Server::close(){
|
void Socket::Server::close(){
|
||||||
#if DEBUG >= 4
|
#if DEBUG >= 6
|
||||||
fprintf(stderr, "ServerSocket closed.\n");
|
fprintf(stderr, "ServerSocket closed.\n");
|
||||||
#endif
|
#endif
|
||||||
shutdown(sock, SHUT_RDWR);
|
shutdown(sock, SHUT_RDWR);
|
||||||
|
|
|
@ -5,7 +5,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#else
|
||||||
#include <wait.h>
|
#include <wait.h>
|
||||||
|
#endif
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -52,6 +57,7 @@ void Util::Procs::childsig_handler(int signum){
|
||||||
#if DEBUG >= 1
|
#if DEBUG >= 1
|
||||||
if (isActive(pname)){
|
if (isActive(pname)){
|
||||||
std::cerr << "Process " << pname << " half-terminated." << std::endl;
|
std::cerr << "Process " << pname << " half-terminated." << std::endl;
|
||||||
|
Stop(pname);
|
||||||
}else{
|
}else{
|
||||||
std::cerr << "Process " << pname << " fully terminated." << std::endl;
|
std::cerr << "Process " << pname << " fully terminated." << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -190,8 +196,11 @@ pid_t Util::Procs::Start(std::string name, std::string cmd, std::string cmd2){
|
||||||
/// Stops the named process, if running.
|
/// Stops the named process, if running.
|
||||||
/// \arg name (Internal) name of process to stop
|
/// \arg name (Internal) name of process to stop
|
||||||
void Util::Procs::Stop(std::string name){
|
void Util::Procs::Stop(std::string name){
|
||||||
|
int max = 5;
|
||||||
while (isActive(name)){
|
while (isActive(name)){
|
||||||
Stop(getPid(name));
|
Stop(getPid(name));
|
||||||
|
max--;
|
||||||
|
if (max <= 0){return;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue