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;
|
struct stat sbuf;
|
||||||
if (::fstat(file_handle_, &sbuf) == -1) return;
|
if (::fstat(file_handle_, &sbuf) == -1) return;
|
||||||
data_ = static_cast<const char*>(::mmap(
|
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;
|
if (data_ == MAP_FAILED) data_ = 0;
|
||||||
else size_ = sbuf.st_size;
|
else size_ = sbuf.st_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,5 +8,7 @@ class MediocreSimpleStaticFileHandler :public StaticFileHandler
|
||||||
public:
|
public:
|
||||||
int answer_pathreq(const char * const path, struct mg_connection *conn);
|
int answer_pathreq(const char * const path, struct mg_connection *conn);
|
||||||
std::string cleanpath(const char * const);
|
std::string cleanpath(const char * const);
|
||||||
|
MediocreSimpleStaticFileHandler() {};
|
||||||
|
~MediocreSimpleStaticFileHandler() {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
#include "MediocreSimpleStaticFileHandler.H"
|
#include "MediocreSimpleStaticFileHandler.H"
|
||||||
|
|
||||||
std::string MediocreSimpleStaticFileHandler::cleanpath (const char * const path){
|
std::string
|
||||||
|
MediocreSimpleStaticFileHandler::cleanpath (const char * const path)
|
||||||
|
{
|
||||||
//adds no security at all
|
//adds no security at all
|
||||||
return std::string(path);
|
return std::string(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
int MediocreSimpleStaticFileHandler::answer_pathreq(const char * const path,
|
int
|
||||||
|
MediocreSimpleStaticFileHandler::answer_pathreq(const char * const path,
|
||||||
struct mg_connection *conn)
|
struct mg_connection *conn)
|
||||||
{
|
{
|
||||||
mg_send_file(conn,cleanpath(path).c_str());
|
mg_send_file(conn,cleanpath(path).c_str());
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
explicit Routerin();
|
explicit Routerin();
|
||||||
StaticFileHandler sfh;
|
StaticFileHandler && sfh;
|
||||||
bool hasInstance = false;
|
bool hasInstance = false;
|
||||||
|
|
||||||
int event_request_route ( struct mg_event *event);
|
int event_request_route ( struct mg_event *event);
|
||||||
|
|
|
@ -6,6 +6,7 @@ using std::strcmp;
|
||||||
#include "Foohash.H"
|
#include "Foohash.H"
|
||||||
#include "Routerin.H"
|
#include "Routerin.H"
|
||||||
|
|
||||||
|
#include "StaticFileHandler.H"
|
||||||
#include "UltraSimpleStaticFileHandler.H"
|
#include "UltraSimpleStaticFileHandler.H"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
@ -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 << " a dynamic file is reqested!" << endl;
|
||||||
std::cerr << " path: " << reststr << endl;
|
std::cerr << " path: " << reststr << endl;
|
||||||
|
|
||||||
return 1;
|
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 ;
|
std::cerr << "requested filelist ordered by date!" << endl ;
|
||||||
return 1;
|
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 ;
|
std::cerr << "here we will get uploadish!" << endl ;
|
||||||
return 1;
|
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;
|
std::cerr << "ended request" <<endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Routerin::event_fallback_route(struct mg_event *event){
|
int Routerin::event_fallback_route(struct mg_event *event __attribute__((unused)) ){
|
||||||
//DEBUG CODE
|
//DEBUG CODE
|
||||||
std::cerr << "Got an unhandled mg_event" << endl;
|
std::cerr << "Got an unhandled mg_event" << endl;
|
||||||
std::cerr << "Its type is: " << event->type << 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
|
//DEBUG CODE
|
||||||
std::cerr << "Started new thread!" <<endl;
|
std::cerr << "Started new thread!" <<endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
class StaticFileHandler
|
class StaticFileHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~StaticFileHandler() {};
|
virtual int answer_pathreq(const char * const path,struct mg_connection *conn)=0;
|
||||||
virtual int answer_pathreq(const char * const path,struct mg_connection *conn) {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
class UltraSimpleStaticFileHandler :public StaticFileHandler
|
class UltraSimpleStaticFileHandler :public StaticFileHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
~UltraSimpleStaticFileHandler();
|
virtual ~UltraSimpleStaticFileHandler();
|
||||||
int answer_pathreq(const char * const path, struct mg_connection *conn);
|
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>
|
</body>
|
||||||
</html>)HERE";
|
</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)
|
struct mg_connection *conn)
|
||||||
{
|
{
|
||||||
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
|
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",
|
"Content-Type: text/html\r\n\r\n%s",
|
||||||
sizeof(hello_world_html),
|
sizeof(hello_world_html),
|
||||||
hello_world_html);
|
hello_world_html);
|
||||||
|
|
|
@ -109,7 +109,6 @@ int main(int argc, char **argv)
|
||||||
std::cerr << "ERROR ERROR BEEP" << std::endl;
|
std::cerr << "ERROR ERROR BEEP" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
dump_args();
|
dump_args();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue