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

@@ -34,16 +34,16 @@
#include <system/configure_network.h> #include <system/configure_network.h>
#include <cs_api.h> #include <cs_api.h>
#include <global.h> #include <global.h>
#include "gui/plugins.h"//for relodplugins #include <gui/plugins.h>//for relodplugins
#include <neutrino.h> #include <neutrino.h>
#include <driver/screenshot.h> #include <driver/screenshot.h>
#include "gui/rc_lock.h" #include <gui/rc_lock.h>
// yhttpd // yhttpd
#include "yhttpd.h" #include <yhttpd.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "ylogging.h" #include <ylogging.h>
#include "helper.h" #include <helper.h>
// nhttpd // nhttpd
#include "neutrinoapi.h" #include "neutrinoapi.h"
#include "controlapi.h" #include "controlapi.h"
@@ -220,7 +220,6 @@ const CControlAPI::TyCgiCall CControlAPI::yCgiCallList[]=
void CControlAPI::Execute(CyhookHandler *hh) void CControlAPI::Execute(CyhookHandler *hh)
{ {
int index = -1; int index = -1;
std::string yresult;
std::string filename = hh->UrlData["filename"]; std::string filename = hh->UrlData["filename"];
log_level_printf(4,"ControlAPI.Execute filename:(%s)\n",filename.c_str()); log_level_printf(4,"ControlAPI.Execute filename:(%s)\n",filename.c_str());
@@ -892,7 +891,6 @@ void CControlAPI::ChannellistCGI(CyhookHandler *hh)
std::string CControlAPI::_GetBouquetActualEPGItem(CyhookHandler *hh, CZapitChannel * channel) { std::string CControlAPI::_GetBouquetActualEPGItem(CyhookHandler *hh, CZapitChannel * channel) {
std::string result, firstEPG, secondEPG = ""; std::string result, firstEPG, secondEPG = "";
t_channel_id current_channel = CZapit::getInstance()->GetCurrentChannelID(); t_channel_id current_channel = CZapit::getInstance()->GetCurrentChannelID();
int percentage = 100;
std::string timestr; std::string timestr;
CSectionsdClient::responseGetCurrentNextInfoChannelID currentNextInfo; CSectionsdClient::responseGetCurrentNextInfoChannelID currentNextInfo;
@@ -900,6 +898,7 @@ std::string CControlAPI::_GetBouquetActualEPGItem(CyhookHandler *hh, CZapitChann
event = NeutrinoAPI->ChannelListEvents[channel->channel_id]; event = NeutrinoAPI->ChannelListEvents[channel->channel_id];
if (event) { if (event) {
int percentage = 100;
if (event->duration > 0) if (event->duration > 0)
percentage = 100 * (time(NULL) - event->startTime) / event->duration; percentage = 100 * (time(NULL) - event->startTime) / event->duration;
CEitManager::getInstance()->getCurrentNextServiceKey(channel->channel_id, currentNextInfo); CEitManager::getInstance()->getCurrentNextServiceKey(channel->channel_id, currentNextInfo);
@@ -1366,7 +1365,7 @@ void CControlAPI::EpgCGI(CyhookHandler *hh) {
else if (hh->ParamList.empty() || hh->ParamList["1"] == "ext") { else if (hh->ParamList.empty() || hh->ParamList["1"] == "ext") {
hh->SetHeader(HTTP_OK, "text/plain; charset=UTF-8"); hh->SetHeader(HTTP_OK, "text/plain; charset=UTF-8");
bool isExt = (hh->ParamList["1"] == "ext"); bool isExt = (hh->ParamList["1"] == "ext");
CChannelEvent *event; CChannelEvent *event = NULL;
NeutrinoAPI->GetChannelEvents(); NeutrinoAPI->GetChannelEvents();
int mode = NeutrinoAPI->Zapit->getMode(); int mode = NeutrinoAPI->Zapit->getMode();
@@ -1389,7 +1388,7 @@ void CControlAPI::EpgCGI(CyhookHandler *hh) {
// query details for given eventid // query details for given eventid
else if (hh->ParamList["eventid"] != "") { else if (hh->ParamList["eventid"] != "") {
//special epg query //special epg query
uint64_t epgid; uint64_t epgid = 0;
sscanf(hh->ParamList["eventid"].c_str(), "%llu", &epgid); sscanf(hh->ParamList["eventid"].c_str(), "%llu", &epgid);
CShortEPGData epg; CShortEPGData epg;
if (CEitManager::getInstance()->getEPGidShort(epgid, &epg)) { if (CEitManager::getInstance()->getEPGidShort(epgid, &epg)) {
@@ -1400,8 +1399,8 @@ void CControlAPI::EpgCGI(CyhookHandler *hh) {
} }
else if (hh->ParamList["eventid2fsk"] != "") { else if (hh->ParamList["eventid2fsk"] != "") {
if (hh->ParamList["starttime"] != "") { if (hh->ParamList["starttime"] != "") {
uint64_t epgid; uint64_t epgid = 0;
time_t starttime; time_t starttime = 0;
sscanf(hh->ParamList["fskid"].c_str(), "%llu", &epgid); sscanf(hh->ParamList["fskid"].c_str(), "%llu", &epgid);
sscanf(hh->ParamList["starttime"].c_str(), "%lu", &starttime); sscanf(hh->ParamList["starttime"].c_str(), "%lu", &starttime);
CEPGData longepg; CEPGData longepg;
@@ -1414,7 +1413,7 @@ void CControlAPI::EpgCGI(CyhookHandler *hh) {
} }
// list EPG for channel id // list EPG for channel id
else if (!(hh->ParamList["id"].empty())) { else if (!(hh->ParamList["id"].empty())) {
t_channel_id channel_id; t_channel_id channel_id = 0;
sscanf(hh->ParamList["id"].c_str(), SCANF_CHANNEL_ID_TYPE, &channel_id); sscanf(hh->ParamList["id"].c_str(), SCANF_CHANNEL_ID_TYPE, &channel_id);
CEitManager::getInstance()->getEventsServiceKey(channel_id, NeutrinoAPI->eList); CEitManager::getInstance()->getEventsServiceKey(channel_id, NeutrinoAPI->eList);
CChannelEventList::iterator eventIterator; CChannelEventList::iterator eventIterator;
@@ -1431,7 +1430,7 @@ void CControlAPI::EpgCGI(CyhookHandler *hh) {
// list EPG for channelID 64Bit // list EPG for channelID 64Bit
else { else {
//eventlist for a chan //eventlist for a chan
t_channel_id channel_id; t_channel_id channel_id = 0;
sscanf(hh->ParamList["1"].c_str(), SCANF_CHANNEL_ID_TYPE, &channel_id); sscanf(hh->ParamList["1"].c_str(), SCANF_CHANNEL_ID_TYPE, &channel_id);
SendEventList(hh, channel_id); SendEventList(hh, channel_id);
} }
@@ -2006,10 +2005,9 @@ void CControlAPI::SendTimersXML(CyhookHandler *hh)
void CControlAPI::YWebCGI(CyhookHandler *hh) void CControlAPI::YWebCGI(CyhookHandler *hh)
{ {
bool status=true; bool status=true;
int para;
if (hh->ParamList["video_stream_pids"] != "") if (hh->ParamList["video_stream_pids"] != "")
{ {
para=0; int para=0;
sscanf( hh->ParamList["video_stream_pids"].c_str(), "%d", &para); sscanf( hh->ParamList["video_stream_pids"].c_str(), "%d", &para);
YWeb_SendVideoStreamingPids(hh, para); YWeb_SendVideoStreamingPids(hh, para);
} }
@@ -2072,7 +2070,7 @@ std::string CControlAPI::YexecuteScript(CyhookHandler *, std::string cmd)
// get file // get file
std::string fullfilename; std::string fullfilename;
script += ".sh"; //add script extention script += ".sh"; //add script extention
char cwd[255]; char cwd[255]={0};
getcwd(cwd, 254); getcwd(cwd, 254);
for (unsigned int i=0; i<PLUGIN_DIR_COUNT && !found; i++) for (unsigned int i=0; i<PLUGIN_DIR_COUNT && !found; i++)
@@ -2121,7 +2119,6 @@ void CControlAPI::doNewTimer(CyhookHandler *hh)
alarmTimeT = 0, alarmTimeT = 0,
tnull = 0; tnull = 0;
unsigned int repCount = 0; unsigned int repCount = 0;
int alHour=0;
// if alarm given then in parameters im time_t format // if alarm given then in parameters im time_t format
if(hh->ParamList["alarm"] != "") if(hh->ParamList["alarm"] != "")
@@ -2145,7 +2142,7 @@ void CControlAPI::doNewTimer(CyhookHandler *hh)
// Alarm Time - Format exact! HH:MM // Alarm Time - Format exact! HH:MM
if(hh->ParamList["alTime"] != "") if(hh->ParamList["alTime"] != "")
strptime(hh->ParamList["alTime"].c_str(), "%H:%M", alarmTime); strptime(hh->ParamList["alTime"].c_str(), "%H:%M", alarmTime);
alHour = alarmTime->tm_hour; int alHour = alarmTime->tm_hour;
correctTime(alarmTime); correctTime(alarmTime);
alarmTimeT = mktime(alarmTime); alarmTimeT = mktime(alarmTime);
@@ -2389,10 +2386,8 @@ void CControlAPI::moveBouquetCGI(CyhookHandler *hh)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
void CControlAPI::deleteBouquetCGI(CyhookHandler *hh) void CControlAPI::deleteBouquetCGI(CyhookHandler *hh)
{ {
int selected = -1;
if (hh->ParamList["selected"] != "") { if (hh->ParamList["selected"] != "") {
selected = atoi(hh->ParamList["selected"].c_str()); int selected = atoi(hh->ParamList["selected"].c_str());
NeutrinoAPI->Zapit->deleteBouquet(selected - 1); NeutrinoAPI->Zapit->deleteBouquet(selected - 1);
hh->SendOk(); hh->SendOk();
} }
@@ -2479,7 +2474,7 @@ void CControlAPI::updateBouquetCGI(CyhookHandler *hh)
// host : (optional) ip of dbox // host : (optional) ip of dbox
void CControlAPI::build_live_url(CyhookHandler *hh) void CControlAPI::build_live_url(CyhookHandler *hh)
{ {
std::string xpids,port,yresult; std::string xpids;
int mode = NeutrinoAPI->Zapit->getMode(); int mode = NeutrinoAPI->Zapit->getMode();
if ( mode == CZapitClient::MODE_TV) if ( mode == CZapitClient::MODE_TV)
@@ -2735,18 +2730,13 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
if (hh->ParamList["action"] == "list") { // directory list: action=list&path=<path> if (hh->ParamList["action"] == "list") { // directory list: action=list&path=<path>
DIR *dirp; DIR *dirp;
struct dirent*entry;
struct stat statbuf;
struct passwd *pwd;
struct group *grp;
struct tm *tm;
char datestring[256];
TOutType outType = hh->outStart(); TOutType outType = hh->outStart();
std::string path = hh->ParamList["path"]; std::string path = hh->ParamList["path"];
if ((dirp = opendir(path.c_str()))) { if ((dirp = opendir(path.c_str()))) {
bool isFirstLine = true; bool isFirstLine = true;
struct dirent *entry;
while ((entry = readdir(dirp))) { while ((entry = readdir(dirp))) {
std::string item = ""; std::string item = "";
item += hh->outPair("name", item += hh->outPair("name",
@@ -2767,6 +2757,7 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
std::string fullname = path + entry->d_name; std::string fullname = path + entry->d_name;
item += hh->outPair("fullname", hh->outValue(fullname), true); item += hh->outPair("fullname", hh->outValue(fullname), true);
struct stat statbuf;
if (stat(fullname.c_str(), &statbuf) != -1) { if (stat(fullname.c_str(), &statbuf) != -1) {
item item
+= hh->outPair( += hh->outPair(
@@ -2780,6 +2771,7 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
string_printf("%d", statbuf.st_nlink), true); string_printf("%d", statbuf.st_nlink), true);
/* Print out owner's name if it is found using getpwuid(). */ /* Print out owner's name if it is found using getpwuid(). */
struct passwd *pwd;
if ((pwd = getpwuid(statbuf.st_uid)) != NULL) { if ((pwd = getpwuid(statbuf.st_uid)) != NULL) {
item += hh->outPair("user", pwd->pw_name, true); item += hh->outPair("user", pwd->pw_name, true);
} }
@@ -2788,6 +2780,7 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
string_printf("%d", statbuf.st_uid), true); string_printf("%d", statbuf.st_uid), true);
} }
/* Print out group name if it is found using getgrgid(). */ /* Print out group name if it is found using getgrgid(). */
struct group *grp;
if ((grp = getgrgid(statbuf.st_gid)) != NULL) if ((grp = getgrgid(statbuf.st_gid)) != NULL)
item += hh->outPair("group", grp->gr_name, true); item += hh->outPair("group", grp->gr_name, true);
else { else {
@@ -2798,7 +2791,8 @@ void CControlAPI::FileCGI(CyhookHandler *hh) {
item += hh->outPair("size", item += hh->outPair("size",
string_printf("%jd", (intmax_t) statbuf.st_size), string_printf("%jd", (intmax_t) statbuf.st_size),
true); true);
tm = localtime(&statbuf.st_mtime); struct tm *tm = localtime(&statbuf.st_mtime);
char datestring[256] = {0};
/* Get localized date string. */ /* Get localized date string. */
strftime(datestring, sizeof(datestring), strftime(datestring, sizeof(datestring),
nl_langinfo(D_T_FMT), tm); nl_langinfo(D_T_FMT), tm);

View File

@@ -8,7 +8,7 @@
#include <string> #include <string>
// yhttpd // yhttpd
#include <zapit/channel.h> #include <zapit/channel.h>
#include "yhook.h" #include <yhook.h>
// forward declaration // forward declaration
class CNeutrinoAPI; class CNeutrinoAPI;

View File

@@ -50,7 +50,7 @@ extern CRemoteControl *g_RemoteControl; /* neutrino.cpp */
extern CZapitClient::SatelliteList satList; extern CZapitClient::SatelliteList satList;
// yhttpd // yhttpd
#include "ylogging.h" #include <ylogging.h>
// nhttpd // nhttpd
#include "neutrinoapi.h" #include "neutrinoapi.h"
@@ -266,7 +266,7 @@ bool CNeutrinoAPI::GetChannelEvents(void)
if (eList.begin() == eList.end()) if (eList.begin() == eList.end())
return false; return false;
for (eventIterator = eList.begin(); eventIterator != eList.end(); eventIterator++) for (eventIterator = eList.begin(); eventIterator != eList.end(); ++eventIterator)
ChannelListEvents[(*eventIterator).get_channel_id()] = &(*eventIterator); ChannelListEvents[(*eventIterator).get_channel_id()] = &(*eventIterator);
return true; return true;
@@ -457,14 +457,13 @@ std::string CNeutrinoAPI::getAudioInfoAsString(void) {
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
std::string CNeutrinoAPI::getCryptInfoAsString(void) { std::string CNeutrinoAPI::getCryptInfoAsString(void) {
unsigned short i;
std::stringstream out; std::stringstream out;
std::string casys[11]= {"Irdeto:","Betacrypt:","Seca:","Viaccess:","Nagra:","Conax: ","Cryptoworks:","Videoguard:","EBU:","XCrypt:","PowerVU:"}; std::string casys[11]= {"Irdeto:","Betacrypt:","Seca:","Viaccess:","Nagra:","Conax: ","Cryptoworks:","Videoguard:","EBU:","XCrypt:","PowerVU:"};
int caids[] = { 0x600, 0x1700, 0x0100, 0x0500, 0x1800, 0xB00, 0xD00, 0x900, 0x2600, 0x4a00, 0x0E00 }; int caids[] = { 0x600, 0x1700, 0x0100, 0x0500, 0x1800, 0xB00, 0xD00, 0x900, 0x2600, 0x4a00, 0x0E00 };
CZapitChannel * channel = CZapit::getInstance()->GetCurrentChannel(); CZapitChannel * channel = CZapit::getInstance()->GetCurrentChannel();
if(channel) { if(channel) {
for (i = 0; i < 11; i++) { for (unsigned short i = 0; i < 11; i++) {
for(casys_map_iterator_t it = channel->camap.begin(); it != channel->camap.end(); ++it) { for(casys_map_iterator_t it = channel->camap.begin(); it != channel->camap.end(); ++it) {
int caid = (*it) & 0xFF00; int caid = (*it) & 0xFF00;
if(caid == caids[i]) if(caid == caids[i])

View File

@@ -12,7 +12,7 @@
#include <zapit/client/zapitclient.h> #include <zapit/client/zapitclient.h>
// nhttpd // nhttpd
#include "helper.h" #include <helper.h>
#include "neutrinoyparser.h" #include "neutrinoyparser.h"
#include "controlapi.h" #include "controlapi.h"

View File

@@ -13,9 +13,9 @@
#include <netinet/in.h> //ntohs #include <netinet/in.h> //ntohs
#include <inttypes.h> //ntohs #include <inttypes.h> //ntohs
// yhttpd // yhttpd
#include "yhttpd.h" #include <yhttpd.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "mod_yparser.h" #include <mod_yparser.h>
// tuxbox // tuxbox
#include <zapit/client/zapittools.h> //timer list #include <zapit/client/zapittools.h> //timer list
// nhttpd // nhttpd
@@ -209,7 +209,7 @@ std::string CNeutrinoYParser::func_mount_set_values(CyhookHandler *hh, std::str
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
std::string CNeutrinoYParser::func_get_bouquets_as_dropdown(CyhookHandler *, std::string para) std::string CNeutrinoYParser::func_get_bouquets_as_dropdown(CyhookHandler *, std::string para)
{ {
std::string ynr, yresult, sel, nr_str, do_show_hidden; std::string yresult, sel, nr_str, do_show_hidden;
int nr=1; int nr=1;
ySplitString(para," ",nr_str, do_show_hidden); ySplitString(para," ",nr_str, do_show_hidden);
@@ -268,7 +268,7 @@ std::string CNeutrinoYParser::func_get_actual_bouquet_number(CyhookHandler *, s
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
std::string CNeutrinoYParser::func_get_channels_as_dropdown(CyhookHandler *, std::string para) std::string CNeutrinoYParser::func_get_channels_as_dropdown(CyhookHandler *, std::string para)
{ {
std::string abouquet, achannel_id, yresult, sel, sid; std::string abouquet, achannel_id, yresult, sel;
int bnumber = 1; int bnumber = 1;
int mode = NeutrinoAPI->Zapit->getMode(); int mode = NeutrinoAPI->Zapit->getMode();
@@ -596,7 +596,7 @@ std::string CNeutrinoYParser::func_get_audio_pids_as_dropdown(CyhookHandler *,
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
std::string CNeutrinoYParser::func_unmount_get_list(CyhookHandler *, std::string) std::string CNeutrinoYParser::func_unmount_get_list(CyhookHandler *, std::string)
{ {
std::string ysel, ymount, ylocal_dir, yfstype, ynr, yresult, mounts; std::string ysel, ymount, ylocal_dir, yfstype, yresult, mounts;
std::ifstream in; std::ifstream in;
in.open("/proc/mounts", std::ifstream::in); in.open("/proc/mounts", std::ifstream::in);
@@ -832,7 +832,7 @@ std::string CNeutrinoYParser::func_get_timer_list(CyhookHandler *, std::string
yresult += string_printf(para.c_str(), classname, zAlarmTime, zStopTime, zRep.c_str(), zRepCount.c_str(), yresult += string_printf(para.c_str(), classname, zAlarmTime, zStopTime, zRep.c_str(), zRepCount.c_str(),
zType.c_str(), sAddData.c_str(),timer->eventID,timer->eventID); zType.c_str(), sAddData.c_str(),timer->eventID,timer->eventID);
} }
classname = (i++&1)?'a':'b'; //classname = (i++&1)?'a':'b';
return yresult; return yresult;
} }

View File

@@ -9,9 +9,9 @@
// c++ // c++
#include <string> #include <string>
// yhttpd // yhttpd
#include "yhttpd.h" #include <yhttpd.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "mod_yparser.h" #include <mod_yparser.h>
// forward declaration // forward declaration
class CNeutrinoAPI; class CNeutrinoAPI;

View File

@@ -34,28 +34,28 @@ CStringList Cyhttpd::ConfigList;
//============================================================================= //=============================================================================
#ifdef Y_CONFIG_USE_AUTHHOOK #ifdef Y_CONFIG_USE_AUTHHOOK
#include "mod_auth.h" #include <mod_auth.h>
static CmAuth *auth = NULL; static CmAuth *auth = NULL;
#endif #endif
#ifdef Y_CONFIG_USE_WEBLOG #ifdef Y_CONFIG_USE_WEBLOG
#include "mod_weblog.h" #include <mod_weblog.h>
static CmWebLog *weblog = NULL; static CmWebLog *weblog = NULL;
#endif #endif
#ifdef Y_CONFIG_USE_SENDFILE #ifdef Y_CONFIG_USE_SENDFILE
#include "mod_sendfile.h" #include <mod_sendfile.h>
static CmodSendfile *mod_sendfile = NULL; static CmodSendfile *mod_sendfile = NULL;
#endif #endif
#ifdef Y_CONFIG_USE_CACHE #ifdef Y_CONFIG_USE_CACHE
#include "mod_cache.h" #include <mod_cache.h>
static CmodCache mod_cache; // static instance static CmodCache mod_cache; // static instance
#endif #endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#if defined(CONFIG_SYSTEM_TUXBOX) || defined(CONFIG_SYSTEM_TUXBOX_COOLSTREAM) #if defined(CONFIG_SYSTEM_TUXBOX) || defined(CONFIG_SYSTEM_TUXBOX_COOLSTREAM)
#include "neutrinoapi.h" #include <neutrinoapi.h>
static CNeutrinoAPI *NeutrinoAPI; static CNeutrinoAPI *NeutrinoAPI;
#endif #endif

View File

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

View File

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

View File

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

View File

@@ -51,7 +51,7 @@
#include <string> #include <string>
#include <list> #include <list>
// yhttpd // yhttpd
#include "yconfig.h" #include <yconfig.h>
#include "ytypes_globals.h" #include "ytypes_globals.h"
#include "ylogging.h" #include "ylogging.h"
// tuxbox // tuxbox
@@ -141,7 +141,7 @@ public:
CStringList HookVarList; // Variables in Hook-Handling passing to other Hooks CStringList HookVarList; // Variables in Hook-Handling passing to other Hooks
THttp_Method Method; // HTTP Method (requested) THttp_Method Method; // HTTP Method (requested)
// constructor & deconstructor // 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(){}; virtual ~CyhookHandler(){};
// hook slot handler // hook slot handler

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -6,7 +6,7 @@
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include "mod_auth.h" #include "mod_auth.h"
#include "helper.h" #include <helper.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// HOOK: response_hook // HOOK: response_hook
@@ -65,11 +65,11 @@ bool CmAuth::CheckAuth(CyhookHandler *hh) {
// decode Base64 buffer to String // decode Base64 buffer to String
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
std::string CmAuth::decodeBase64(const char *b64buffer) { std::string CmAuth::decodeBase64(const char *b64buffer) {
char *newString, *org_newString; //shorter then b64buffer char *newString; //shorter then b64buffer
std::string result; std::string result;
if ((newString = (char *) malloc(sizeof(char) * strlen(b64buffer) + 1)) if ((newString = (char *) malloc(sizeof(char) * strlen(b64buffer) + 1))
!= NULL) { != NULL) {
org_newString = newString; char *org_newString = newString;
int i = 0; int i = 0;
unsigned long c = 0; unsigned long c = 0;

View File

@@ -5,11 +5,12 @@
#ifndef __yhttpd_mod_auth_h__ #ifndef __yhttpd_mod_auth_h__
#define __yhttpd_mod_auth_h__ #define __yhttpd_mod_auth_h__
#include "yhook.h" #include <yhook.h>
class CmAuth: public Cyhook { class CmAuth: public Cyhook {
public: public:
bool authenticate; bool authenticate;
CmAuth() { CmAuth() {
authenticate = false;
} }
; ;
~CmAuth() { ~CmAuth() {

View File

@@ -8,9 +8,9 @@
#include <pthread.h> #include <pthread.h>
#include <sys/stat.h> #include <sys/stat.h>
// yhttpd // yhttpd
#include "yconfig.h" #include <yconfig.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "helper.h" #include <helper.h>
#include "mod_cache.h" #include "mod_cache.h"
//============================================================================= //=============================================================================
@@ -128,7 +128,7 @@ void CmodCache::AddToCache(CyhookHandler *, std::string url,
CacheList[url].mime_type = mime_type; CacheList[url].mime_type = mime_type;
CacheList[url].category = category; CacheList[url].category = category;
CacheList[url].created = time(NULL); CacheList[url].created = time(NULL);
std::string test = CacheList[url].filename; // std::string test = CacheList[url].filename;
} }
fflush(fd); // flush and close file fflush(fd); // flush and close file
fclose(fd); fclose(fd);
@@ -154,7 +154,7 @@ void CmodCache::RemoveCategoryFromCache(std::string category) {
do { do {
restart = false; restart = false;
TCacheList::iterator i = CacheList.begin(); TCacheList::iterator i = CacheList.begin();
for (; i != CacheList.end(); i++) { for (; i != CacheList.end(); ++i) {
TCache *item = &((*i).second); TCache *item = &((*i).second);
if (item->category == category) { if (item->category == category) {
CacheList.erase(((*i).first)); CacheList.erase(((*i).first));
@@ -198,7 +198,7 @@ void CmodCache::yshowCacheInfo(CyhookHandler *hh) {
"<tr><td>URL</td><td>Mime</td><td>Filename</td><td>Category</td><td>Created</td><td>Remove</td></tr>\n"); "<tr><td>URL</td><td>Mime</td><td>Filename</td><td>Category</td><td>Created</td><td>Remove</td></tr>\n");
pthread_mutex_lock(&mutex); pthread_mutex_lock(&mutex);
TCacheList::iterator i = CacheList.begin(); TCacheList::iterator i = CacheList.begin();
for (; i != CacheList.end(); i++) { for (; i != CacheList.end(); ++i) {
TCache *item = &((*i).second); TCache *item = &((*i).second);
char timeStr[80]; char timeStr[80];
strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&(item->created))); strftime(timeStr, sizeof(timeStr), RFC1123FMT, gmtime(&(item->created)));

View File

@@ -11,9 +11,9 @@
// c++ // c++
#include <string> #include <string>
// yhttpd // yhttpd
#include "yconfig.h" #include <yconfig.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "yhook.h" #include <yhook.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
typedef struct { typedef struct {

View File

@@ -47,9 +47,9 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
// yhttpd // yhttpd
#include "yconfig.h" #include <yconfig.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "helper.h" #include <helper.h>
#include "mod_sendfile.h" #include "mod_sendfile.h"
//============================================================================= //=============================================================================
@@ -64,7 +64,6 @@ CStringList CmodSendfile::sendfileTypes;
THandleStatus CmodSendfile::Hook_PrepareResponse(CyhookHandler *hh) { THandleStatus CmodSendfile::Hook_PrepareResponse(CyhookHandler *hh) {
hh->status = HANDLED_NONE; hh->status = HANDLED_NONE;
int filed;
log_level_printf(4, "mod_sendfile prepare hook start url:%s\n", hh->UrlData["fullurl"].c_str()); log_level_printf(4, "mod_sendfile prepare hook start url:%s\n", hh->UrlData["fullurl"].c_str());
std::string mime = sendfileTypes[hh->UrlData["fileext"]]; std::string mime = sendfileTypes[hh->UrlData["fileext"]];
if (((mime != "") || (hh->WebserverConfigList["mod_sendfile.sendAll"] == "true")) if (((mime != "") || (hh->WebserverConfigList["mod_sendfile.sendAll"] == "true"))
@@ -73,7 +72,7 @@ THandleStatus CmodSendfile::Hook_PrepareResponse(CyhookHandler *hh) {
// build filename // build filename
std::string fullfilename = GetFileName(hh, hh->UrlData["path"], std::string fullfilename = GetFileName(hh, hh->UrlData["path"],
hh->UrlData["filename"]); hh->UrlData["filename"]);
int filed;
if ((filed = OpenFile(hh, fullfilename)) != -1) //can access file? if ((filed = OpenFile(hh, fullfilename)) != -1) //can access file?
{ {
struct stat statbuf; struct stat statbuf;
@@ -180,7 +179,6 @@ std::string CmodSendfile::GetFileName(CyhookHandler *hh, std::string path, std::
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int CmodSendfile::OpenFile(CyhookHandler *, std::string fullfilename) { int CmodSendfile::OpenFile(CyhookHandler *, std::string fullfilename) {
int fd = -1; int fd = -1;
std::string tmpstring;
if (fullfilename.length() > 0) { if (fullfilename.length() > 0) {
fd = open(fullfilename.c_str(), O_RDONLY | O_LARGEFILE); fd = open(fullfilename.c_str(), O_RDONLY | O_LARGEFILE);
if (fd <= 0) { if (fd <= 0) {

View File

@@ -11,9 +11,9 @@
// c++ // c++
#include <string> #include <string>
// yhttpd // yhttpd
#include "yconfig.h" #include <yconfig.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "yhook.h" #include <yhook.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class CmodSendfile : public Cyhook class CmodSendfile : public Cyhook

View File

@@ -6,7 +6,7 @@
#define TESTHOOK_H_ #define TESTHOOK_H_
#include "yhook.h" #include <yhook.h>
class CTesthook : public Cyhook class CTesthook : public Cyhook
{ {
public: public:

View File

@@ -11,7 +11,7 @@
#include <unistd.h> #include <unistd.h>
#include "mod_weblog.h" #include "mod_weblog.h"
#include "helper.h" #include <helper.h>
//============================================================================= //=============================================================================
// Initialization of static variables // Initialization of static variables
@@ -97,8 +97,8 @@ bool CmWebLog::printf(const char *fmt, ...) {
if (!OpenLogFile()) if (!OpenLogFile())
return false; return false;
bool success = false; bool success = false;
char buffer[bufferlen];
if (WebLogFile != NULL) { if (WebLogFile != NULL) {
char buffer[bufferlen]={0};
pthread_mutex_lock(&WebLog_mutex); // yeah, its mine pthread_mutex_lock(&WebLog_mutex); // yeah, its mine
va_list arglist; va_list arglist;
va_start(arglist, fmt); va_start(arglist, fmt);
@@ -130,6 +130,8 @@ bool CmWebLog::printf(const char *fmt, ...) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CmWebLog::AddLogEntry_CLF(CyhookHandler *hh) void CmWebLog::AddLogEntry_CLF(CyhookHandler *hh)
{ {
#if 0
//never used
std::string cs_method; std::string cs_method;
switch (hh->Method) switch (hh->Method)
{ {
@@ -141,6 +143,7 @@ void CmWebLog::AddLogEntry_CLF(CyhookHandler *hh)
cs_method = "unknown"; cs_method = "unknown";
break; break;
} }
#endif
std::string c_ip = hh->UrlData["clientaddr"].c_str(); std::string c_ip = hh->UrlData["clientaddr"].c_str();
std::string request_startline = hh->UrlData["startline"].c_str(); std::string request_startline = hh->UrlData["startline"].c_str();
int s_status = hh->httpStatus; int s_status = hh->httpStatus;
@@ -315,7 +318,6 @@ void CmWebLog::AddLogEntry_ELF(CyhookHandler *hh)
std::string c_ip = hh->UrlData["clientaddr"].c_str(); std::string c_ip = hh->UrlData["clientaddr"].c_str();
std::string request_startline = hh->UrlData["startline"].c_str(); std::string request_startline = hh->UrlData["startline"].c_str();
std::string cs_uri = hh->UrlData["fullurl"]; std::string cs_uri = hh->UrlData["fullurl"];
std::string cs_uri_stem = hh->UrlData["url"];
int sc_status = hh->httpStatus; int sc_status = hh->httpStatus;
int bytes = hh->GetContentLength(); int bytes = hh->GetContentLength();
int cached = (hh->HookVarList["CacheCategory"].empty()) ? 0 : 1; int cached = (hh->HookVarList["CacheCategory"].empty()) ? 0 : 1;

View File

@@ -5,8 +5,8 @@
#ifndef __yhttpd_mod_weblog_h__ #ifndef __yhttpd_mod_weblog_h__
#define __yhttpd_mod_weblog_h__ #define __yhttpd_mod_weblog_h__
#include "yconfig.h" #include <yconfig.h>
#include "yhook.h" #include <yhook.h>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Defaults // Defaults
#ifndef LOG_FILE #ifndef LOG_FILE

View File

@@ -18,12 +18,12 @@
// tuxbox // tuxbox
#include <configfile.h> #include <configfile.h>
// yhttpd // yhttpd
#include "yconfig.h" #include <yconfig.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "helper.h" #include <helper.h>
#include "ylogging.h" #include <ylogging.h>
#include "mod_yparser.h" #include "mod_yparser.h"
#include "ylanguage.h" #include <ylanguage.h>
//============================================================================= //=============================================================================
// Initialization of static variables // Initialization of static variables
@@ -111,7 +111,7 @@ void CyParser::Execute(CyhookHandler *hh) {
if (CLogging::getInstance()->getDebug()) { if (CLogging::getInstance()->getDebug()) {
dprintf("Execute CGI : %s\n", filename.c_str()); dprintf("Execute CGI : %s\n", filename.c_str());
for (CStringList::iterator it = hh->ParamList.begin(); it for (CStringList::iterator it = hh->ParamList.begin(); it
!= hh->ParamList.end(); it++) != hh->ParamList.end(); ++it)
dprintf(" Parameter %s : %s\n", it->first.c_str(), dprintf(" Parameter %s : %s\n", it->first.c_str(),
it->second.c_str()); it->second.c_str());
} }
@@ -156,7 +156,6 @@ void CyParser::Execute(CyhookHandler *hh) {
// mini cgi Engine (Entry for ycgi) // mini cgi Engine (Entry for ycgi)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void CyParser::cgi(CyhookHandler *hh) { void CyParser::cgi(CyhookHandler *hh) {
bool ydebug = false;
std::string htmlfilename, yresult, ycmd; std::string htmlfilename, yresult, ycmd;
if ( !hh->ParamList.empty() ) { if ( !hh->ParamList.empty() ) {
@@ -164,6 +163,7 @@ void CyParser::cgi(CyhookHandler *hh) {
htmlfilename = hh->ParamList["tmpl"]; htmlfilename = hh->ParamList["tmpl"];
else else
htmlfilename = hh->ParamList["1"]; htmlfilename = hh->ParamList["1"];
bool ydebug = false;
if (hh->ParamList["debug"] != "") // switch debug on if (hh->ParamList["debug"] != "") // switch debug on
ydebug = true; ydebug = true;
@@ -171,7 +171,6 @@ void CyParser::cgi(CyhookHandler *hh) {
{ {
ycmd = hh->ParamList["execute"]; ycmd = hh->ParamList["execute"];
ycmd = YPARSER_ESCAPE_START + ycmd + YPARSER_ESCAPE_END; ycmd = YPARSER_ESCAPE_START + ycmd + YPARSER_ESCAPE_END;
ycmd = ycmd;
yresult = cgi_cmd_parsing(hh, ycmd, ydebug); // parsing engine yresult = cgi_cmd_parsing(hh, ycmd, ydebug); // parsing engine
} }
// parsing given file // parsing given file
@@ -471,7 +470,7 @@ std::string CyParser::YWeb_cgi_cmd(CyhookHandler *hh, std::string ycmd) {
pthread_mutex_unlock(&yParser_mutex); pthread_mutex_unlock(&yParser_mutex);
} }
} else if (ycmd_type == "file-action") { } else if (ycmd_type == "file-action") {
std::string filename, actionname, content, tmp, ydefault; std::string filename, actionname, content, tmp;
if (ySplitString(ycmd_name, ";", filename, tmp)) { if (ySplitString(ycmd_name, ";", filename, tmp)) {
ySplitString(tmp, ";", actionname, content); ySplitString(tmp, ";", actionname, content);
replace(content, "\r\n", "\n"); replace(content, "\r\n", "\n");
@@ -522,7 +521,6 @@ std::string CyParser::YWeb_cgi_get_ini(CyhookHandler *, std::string filename,
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
void CyParser::YWeb_cgi_set_ini(CyhookHandler *, std::string filename, void CyParser::YWeb_cgi_set_ini(CyhookHandler *, std::string filename,
std::string varname, std::string varvalue, std::string yaccess) { std::string varname, std::string varvalue, std::string yaccess) {
std::string result;
if ((yaccess == "open") || (yaccess == "")) { if ((yaccess == "open") || (yaccess == "")) {
yConfig->clear(); yConfig->clear();
yConfig->loadConfig(filename); yConfig->loadConfig(filename);
@@ -738,11 +736,11 @@ std::string CyParser::func_get_languages_as_dropdown(CyhookHandler *,
std::string para) { std::string para) {
std::string yresult, sel; std::string yresult, sel;
DIR *d; DIR *d;
struct dirent *dir;
std::string act_language = CLanguage::getInstance()->language; std::string act_language = CLanguage::getInstance()->language;
d = opendir((CLanguage::getInstance()->language_dir).c_str()); d = opendir((CLanguage::getInstance()->language_dir).c_str());
if (d != NULL) { if (d != NULL) {
struct dirent *dir;
while ((dir = readdir(d))) { while ((dir = readdir(d))) {
if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0)
continue; continue;

View File

@@ -16,10 +16,10 @@
#include <configfile.h> #include <configfile.h>
// yhttpd // yhttpd
#include "helper.h" #include <helper.h>
#include "yconfig.h" #include <yconfig.h>
#include "ytypes_globals.h" #include <ytypes_globals.h>
#include "yhook.h" #include <yhook.h>
// forward declaration // forward declaration
class CWebserverConnection; class CWebserverConnection;