diff --git a/src/InputMemmoryFile.cc b/src/InputMemmoryFile.cc index 6973755..bbe2027 100644 --- a/src/InputMemmoryFile.cc +++ b/src/InputMemmoryFile.cc @@ -15,7 +15,9 @@ InputMemoryFile::InputMemoryFile(const char *pathname): struct stat sbuf; if (::fstat(file_handle_, &sbuf) == -1) return; data_ = static_cast(::mmap( - 0, sbuf.st_size, PROT_READ, MAP_SHARED, file_handle_, 0)); + 0, sbuf.st_size, + PROT_READ, MAP_SHARED, + file_handle_, 0)); if (data_ == MAP_FAILED) data_ = 0; else size_ = sbuf.st_size; } diff --git a/src/MediocreSimpleStaticFileHandler.H b/src/MediocreSimpleStaticFileHandler.H index d13510b..a8251b6 100644 --- a/src/MediocreSimpleStaticFileHandler.H +++ b/src/MediocreSimpleStaticFileHandler.H @@ -8,5 +8,7 @@ class MediocreSimpleStaticFileHandler :public StaticFileHandler public: int answer_pathreq(const char * const path, struct mg_connection *conn); std::string cleanpath(const char * const); + MediocreSimpleStaticFileHandler() {}; + ~MediocreSimpleStaticFileHandler() {}; }; diff --git a/src/MediocreSimpleStaticFileHandler.cc b/src/MediocreSimpleStaticFileHandler.cc index e00bb8d..0fe150b 100644 --- a/src/MediocreSimpleStaticFileHandler.cc +++ b/src/MediocreSimpleStaticFileHandler.cc @@ -1,11 +1,14 @@ #include "MediocreSimpleStaticFileHandler.H" -std::string MediocreSimpleStaticFileHandler::cleanpath (const char * const path){ +std::string +MediocreSimpleStaticFileHandler::cleanpath (const char * const path) +{ //adds no security at all return std::string(path); } -int MediocreSimpleStaticFileHandler::answer_pathreq(const char * const path, +int +MediocreSimpleStaticFileHandler::answer_pathreq(const char * const path, struct mg_connection *conn) { mg_send_file(conn,cleanpath(path).c_str()); diff --git a/src/Routerin.H b/src/Routerin.H index bae4c72..45f5915 100644 --- a/src/Routerin.H +++ b/src/Routerin.H @@ -38,7 +38,7 @@ public: } private: explicit Routerin(); - StaticFileHandler sfh; + StaticFileHandler && sfh; bool hasInstance = false; int event_request_route ( struct mg_event *event); diff --git a/src/Routerin.cc b/src/Routerin.cc index 5076f5f..1c90854 100644 --- a/src/Routerin.cc +++ b/src/Routerin.cc @@ -6,6 +6,7 @@ using std::strcmp; #include "Foohash.H" #include "Routerin.H" +#include "StaticFileHandler.H" #include "UltraSimpleStaticFileHandler.H" using std::cout; @@ -26,56 +27,56 @@ Routerin::~Routerin() } int Routerin::event_request_route(struct mg_event *event){ - const RouterOp *blub=0; - Foohash fh; - const char *reqstr=0; - char *tmpstr = 0,*pntrstr=0; - int retval=-1; - reqstr=event->request_info->uri; - if (reqstr){ - tmpstr = strdup(reqstr); - std::cerr << "starting with str as " - << tmpstr << endl; //DEBUG CODE - pntrstr = strchrnul((tmpstr+1),'/'); - if (pntrstr) { - *pntrstr = 0; - std::cerr <<" having reqstr as " << tmpstr - << " now. " << endl; - std::cerr <<"len of reqstr is " << - ( pntrstr - tmpstr) << endl; - blub = fh.in_word_set(tmpstr,((pntrstr++)-tmpstr) ); - if (blub){ - std::cerr << "me has blub!!" <op){ - case RouterOpCode::FILES: - retval = rq_file(pntrstr ,event); - break; - case RouterOpCode::DATE: - retval = rq_date(pntrstr, event); - break; - case RouterOpCode::UPLOAD: - retval = rq_upload(pntrstr, event); - break; - case RouterOpCode::STATIC: - std::cerr << "(/static/ given)"; - retval = rq_static((pntrstr),event); - break; - default: - std::cerr << "fallback "; - retval = rq_static((pntrstr),event); - }; - }else{ - std::cerr << "no blub! in " << __LINE__ << endl; - } - } - std::free(tmpstr); - tmpstr=0; - return retval; - } else { - std::cerr << "event request without uri? ?? hu? [" << - event->request_info->uri << "]" << endl; - } - return 0; + const RouterOp *blub=0; + Foohash fh; + const char *reqstr=0; + char *tmpstr = 0,*pntrstr=0; + int retval=-1; + reqstr=event->request_info->uri; + if (reqstr){ + tmpstr = strdup(reqstr); + std::cerr << "starting with str as " + << tmpstr << endl; //DEBUG CODE + pntrstr = strchrnul((tmpstr+1),'/'); + if (pntrstr) { + *pntrstr = 0; + std::cerr <<" having reqstr as " << tmpstr + << " now. " << endl; + std::cerr <<"len of reqstr is " << + ( pntrstr - tmpstr) << endl; + blub = fh.in_word_set(tmpstr,((pntrstr++)-tmpstr) ); + if (blub){ + std::cerr << "me has blub!!" <op){ + case RouterOpCode::FILES: + retval = rq_file(pntrstr ,event); + break; + case RouterOpCode::DATE: + retval = rq_date(pntrstr, event); + break; + case RouterOpCode::UPLOAD: + retval = rq_upload(pntrstr, event); + break; + case RouterOpCode::STATIC: + std::cerr << "(/static/ given)"; + retval = rq_static((pntrstr),event); + break; + default: + std::cerr << "fallback "; + retval = rq_static((pntrstr),event); + }; + }else{ + std::cerr << "no blub! in " << __LINE__ << endl; + } + } + std::free(tmpstr); + tmpstr=0; + return retval; + } else { + std::cerr << "event request without uri? ?? hu? [" << + event->request_info->uri << "]" << endl; + } + return 0; } @@ -90,32 +91,34 @@ int Routerin::rq_static(char const * const reststr , struct mg_event *event) -int Routerin::rq_file(char const * const reststr , struct mg_event *event) +int Routerin::rq_file(char const * const reststr , + struct mg_event *event __attribute__((unused))) { std::cerr << " a dynamic file is reqested!" << endl; std::cerr << " path: " << reststr << endl; - return 1; } -int Routerin::rq_date(char const * const reststr , struct mg_event *event) +int Routerin::rq_date(char const * const reststr __attribute__((unused)), + struct mg_event *event __attribute__((unused)) ) { std::cerr << "requested filelist ordered by date!" << endl ; return 1; } -int Routerin::rq_upload(char const * const reststr, struct mg_event *event) +int Routerin::rq_upload(char const * const reststr __attribute__((unused)), + struct mg_event *event __attribute__((unused))) { std::cerr << "here we will get uploadish!" << endl ; return 1; } -int Routerin::event_requend_route(struct mg_event *event){ +int Routerin::event_requend_route(struct mg_event *event __attribute__((unused)) ){ std::cerr << "ended request" <type << endl; @@ -123,7 +126,7 @@ int Routerin::event_fallback_route(struct mg_event *event){ } -int Routerin::event_newthread_route(struct mg_event *event){ +int Routerin::event_newthread_route(struct mg_event *event __attribute__((unused)) ){ //DEBUG CODE std::cerr << "Started new thread!" < )HERE"; -UltraSimpleStaticFileHandler::~UltraSimpleStaticFileHandler() {} +UltraSimpleStaticFileHandler::~UltraSimpleStaticFileHandler(){}; -int -UltraSimpleStaticFileHandler::answer_pathreq(const char * const path, + +int UltraSimpleStaticFileHandler::answer_pathreq(const char * const path, struct mg_connection *conn) { mg_printf(conn, "HTTP/1.0 200 OK\r\n" - "Content-Length: %d\r\n" + "Content-Length: %lu\r\n" "Content-Type: text/html\r\n\r\n%s", sizeof(hello_world_html), hello_world_html); diff --git a/src/sicmain.cc b/src/sicmain.cc index 03831a2..4aaf8bd 100644 --- a/src/sicmain.cc +++ b/src/sicmain.cc @@ -15,10 +15,10 @@ using std::cout; class MongooseHandler{ private: - struct mg_context *ctx; - //const char *options[]; - unsigned short listenport; - // = {"listening_ports", "8080", NULL}; + struct mg_context *ctx; + //const char *options[]; + unsigned short listenport; + // = {"listening_ports", "8080", NULL}; public: @@ -26,14 +26,14 @@ class MongooseHandler{ MongooseHandler(int listenport=8080): ctx(nullptr), listenport(listenport) - { - char portstring[8]; - Routerin *routerin = Routerin::get_instance(); - std::snprintf(portstring,8,"%d",this->listenport); - const char *options[] = - {"listening_ports",portstring,nullptr}; - this->ctx= mg_start(options, routerin->event_route, nullptr); - } + { + char portstring[8]; + Routerin *routerin = Routerin::get_instance(); + std::snprintf(portstring,8,"%d",this->listenport); + const char *options[] = + {"listening_ports",portstring,nullptr}; + this->ctx= mg_start(options, routerin->event_route, nullptr); + } //no copy constructor: MongooseHandler( const MongooseHandler &) = delete; @@ -81,44 +81,43 @@ bool configfile_parsing_action(int& argc, char **argv) //initialize the parameters structure params = cmd_parser_params_create(); - params->check_required = 0; + params->check_required = 0; if (cmd_parser_config_file("./siccc.conf", &args_info, params) != 0) { - cmd_parser_free(&args_info); - free(params); - return false; + cmd_parser_free(&args_info); + free(params); + return false; } params->initialize = 0; params->override = 1; - params->check_required = 1; + params->check_required = 1; //call the command line parser if (cmd_parser(argc, argv, &args_info) != 0) { - cmd_parser_free(&args_info); - free(params); - return false; + cmd_parser_free(&args_info); + free(params); + return false; } - return true; + return true; } int main(int argc, char **argv) { - if ( !configfile_parsing_action(argc, argv) ) { - std::cerr << "ERROR ERROR BEEP" << std::endl; - exit(1); - } - + if ( !configfile_parsing_action(argc, argv) ) { + std::cerr << "ERROR ERROR BEEP" << std::endl; + exit(1); + } #ifdef DEBUG - dump_args(); + dump_args(); #endif MongooseHandler m(args_info.port_arg); - if (!args_info.daemonize_flag) { - while(1) - getchar(); - } + if (!args_info.daemonize_flag) { + while(1) + getchar(); + } return 0; }