src/nhttpd: clean code

This commit is contained in:
satbaby
2012-11-28 19:03:03 +01:00
parent 3cad732b06
commit 5e4a541781
28 changed files with 106 additions and 113 deletions

View File

@@ -12,7 +12,7 @@
#include <iomanip>
// yhttpd
#include "yconfig.h"
#include <yconfig.h>
#include "ytypes_globals.h"
#include "helper.h"
#include "ylogging.h"
@@ -220,10 +220,10 @@ std::string encodeString(std::string decodedString) {
unsigned int len = sizeof(char) * decodedString.length() * 5 + 1;
std::string result(len, '\0');
char *newString = (char *) result.c_str();
char *dstring = (char *) decodedString.c_str();
char one_char;
if (len == result.length()) // got memory needed
{
char *dstring = (char *) decodedString.c_str();
while ((one_char = *dstring++)) /* use the null character as a loop terminator */
{
if (isalnum(one_char))

View File

@@ -8,7 +8,7 @@
#include <errno.h>
#include <cstring>
// yhttpd
#include "yconfig.h"
#include <yconfig.h>
#include "ytypes_globals.h"
#include "ywebserver.h"
#include "yconnection.h"
@@ -44,6 +44,7 @@ CWebserverConnection::CWebserverConnection(CWebserver *pWebserver) {
//-------------------------------------------------------------------------
CWebserverConnection::CWebserverConnection() {
// aprintf("test CWebserverConnection::CWebserverConnection()\n");
Method = M_UNKNOWN;
sock = 0;
RequestCanceled = 0;
keep_alive = 0;

View File

@@ -14,7 +14,7 @@
// c++
#include <string>
// yhttpd
#include "yconfig.h"
#include <yconfig.h>
#include "ytypes_globals.h"
#include "ywebserver.h"
#include "yrequest.h"

View File

@@ -51,7 +51,7 @@
#include <string>
#include <list>
// yhttpd
#include "yconfig.h"
#include <yconfig.h>
#include "ytypes_globals.h"
#include "ylogging.h"
// tuxbox
@@ -141,7 +141,7 @@ public:
CStringList HookVarList; // Variables in Hook-Handling passing to other Hooks
THttp_Method Method; // HTTP Method (requested)
// constructor & deconstructor
CyhookHandler(){ContentLength = 0; keep_alive = 0; _outIndent = 0;};
CyhookHandler(){ContentLength = 0; keep_alive = 0; _outIndent = 0;status = HANDLED_NONE;Method = M_UNKNOWN;httpStatus = HTTP_NIL;outType = plain;};
virtual ~CyhookHandler(){};
// hook slot handler

View File

@@ -8,7 +8,7 @@
#include <stdlib.h>
#include <configfile.h>
// yhttpd
#include "yconfig.h"
#include <yconfig.h>
#include "ytypes_globals.h"
#include "ywebserver.h"

View File

@@ -116,7 +116,7 @@ bool CWebserverRequest::HandleRequest(void) {
// Split URL into path, filename, fileext .. UrlData[]
//-----------------------------------------------------------------------------
bool CWebserverRequest::ParseStartLine(std::string start_line) {
std::string method, url, http, tmp;
std::string method, url, tmp;
log_level_printf(8, "<ParseStartLine>: line: %s\n", start_line.c_str());
if (ySplitString(start_line, " ", method, tmp)) {

View File

@@ -15,8 +15,8 @@
#include <fcntl.h>
#include <sys/socket.h>
// yhttpd
#include "yconfig.h"
#include "yhttpd.h"
#include <yconfig.h>
#include <yhttpd.h>
#include "ytypes_globals.h"
#include "ylogging.h"
#include "ywebserver.h"

View File

@@ -9,7 +9,7 @@
// c++
#include <string>
// yhttpd
#include "yconfig.h"
#include <yconfig.h>
#include "ytypes_globals.h"
#include "yhook.h"
@@ -42,8 +42,8 @@ public:
void printf(const char *fmt, ...);
bool Write(char const *text);
bool WriteLn(char const *text);
bool Write(const std::string text) { return Write(text.c_str()); }
bool WriteLn(const std::string text) { return WriteLn(text.c_str()); }
bool Write(const std::string &text) { return Write(text.c_str()); }
bool WriteLn(const std::string &text) { return WriteLn(text.c_str()); }
// Headers
void SendError(HttpResponseType responseType) {SendHeader(responseType, false, "text/html");}

View File

@@ -17,7 +17,7 @@
#include <unistd.h>
// yhttpd
#include "yhttpd.h"
#include <yhttpd.h>
#include "ysocket.h"
#include "ylogging.h"
// system
@@ -64,6 +64,7 @@ CySocket::~CySocket() {
// initialize
//-----------------------------------------------------------------------------
void CySocket::init(void) {
BytesSend = 0;
handling = false;
isOpened = false;
isValid = true;
@@ -194,8 +195,8 @@ CySocket* CySocket::accept() {
#else
set_tcp_nodelay();
#endif
new_ySocket->isOpened = true;
}
new_ySocket->isOpened = true;
// handling = true;
return new_ySocket;
}

View File

@@ -19,7 +19,7 @@
#include <configfile.h>
// yhttpd
#include "yhttpd.h"
#include <yhttpd.h>
#include "ytypes_globals.h"
#include "ywebserver.h"
#include "ylogging.h"
@@ -241,7 +241,6 @@ bool CWebserver::run(void) {
int CWebserver::AcceptNewConnectionSocket() {
int slot = -1;
CySocket *connectionSock = NULL;
int newfd;
if (!(connectionSock = listenSocket.accept())) // Blocking wait
{
@@ -265,7 +264,7 @@ int CWebserver::AcceptNewConnectionSocket() {
SocketList[slot] = connectionSock; // put it to list
fcntl(connectionSock->get_socket(), F_SETFD, O_NONBLOCK); // set non-blocking
open_connections++; // count open connectins
newfd = connectionSock->get_socket();
int newfd = connectionSock->get_socket();
if (newfd > fdmax) // keep track of the maximum fd
fdmax = newfd;
}
@@ -377,7 +376,7 @@ bool CWebserver::CheckKeepAliveAllowedByIP(std::string client_ip) {
while (it != conf_no_keep_alive_ips.end()) {
if (trim(*it) == client_ip)
do_keep_alive = false;
it++;
++it;
}
pthread_mutex_unlock(&mutex);
return do_keep_alive;