dancing arround class stuff. virtual interface cleaned
This commit is contained in:
parent
48f43be792
commit
7b64cb5b76
|
@ -15,7 +15,9 @@ InputMemoryFile::InputMemoryFile(const char *pathname):
|
|||
struct stat sbuf;
|
||||
if (::fstat(file_handle_, &sbuf) == -1) return;
|
||||
data_ = static_cast<const char*>(::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;
|
||||
}
|
||||
|
|
|
@ -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() {};
|
||||
|
||||
};
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
}
|
||||
private:
|
||||
explicit Routerin();
|
||||
StaticFileHandler sfh;
|
||||
StaticFileHandler && sfh;
|
||||
bool hasInstance = false;
|
||||
|
||||
int event_request_route ( struct mg_event *event);
|
||||
|
|
117
src/Routerin.cc
117
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!!" <<endl;
|
||||
switch(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!!" <<endl;
|
||||
switch(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" <<endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Routerin::event_fallback_route(struct mg_event *event){
|
||||
int Routerin::event_fallback_route(struct mg_event *event __attribute__((unused)) ){
|
||||
//DEBUG CODE
|
||||
std::cerr << "Got an unhandled mg_event" << endl;
|
||||
std::cerr << "Its type is: " << event->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!" <<endl;
|
||||
return 1;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
class StaticFileHandler
|
||||
{
|
||||
public:
|
||||
virtual ~StaticFileHandler() {};
|
||||
virtual int answer_pathreq(const char * const path,struct mg_connection *conn) {};
|
||||
virtual int answer_pathreq(const char * const path,struct mg_connection *conn)=0;
|
||||
};
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
class UltraSimpleStaticFileHandler :public StaticFileHandler
|
||||
{
|
||||
public:
|
||||
~UltraSimpleStaticFileHandler();
|
||||
int answer_pathreq(const char * const path, struct mg_connection *conn);
|
||||
virtual ~UltraSimpleStaticFileHandler();
|
||||
virtual int answer_pathreq(const char * const path, struct mg_connection *conn) override;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,14 +22,14 @@ static const char * hello_world_html = u8R"HERE(
|
|||
</body>
|
||||
</html>)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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue