implement consistent use of virtual class

This commit is contained in:
blastmaster 2014-01-23 02:19:33 +01:00
parent b035f4b923
commit 55fb0d0b0f
4 changed files with 35 additions and 31 deletions

View File

@ -0,0 +1,12 @@
#pragma once
#include "StaticFileHandler.H"
#include <string>
class MediocreSimpleStaticFileHandler :public StaticFileHandler
{
public:
int answer_pathreq(const char * const path, struct mg_connection *conn);
std::string cleanpath(const char * const);
};

View File

@ -1,20 +1,14 @@
#include "MediocreSimpleStaticFileHandler.H"
//#include "InputMemmoryFile.H"
class MediocreSimpleStaticFileHandler :StaticFileHandler
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,
struct mg_connection *conn)
{
private:
std::string cleanpath (const char * const path){
//adds no security at all
return std::string(path);
}
public:
int answer_pathreq(const char * const path,
struct mg_connection *conn)
{
mg_send_file(conn,cleanpath(path).c_str());
return 0;
}
mg_send_file(conn,cleanpath(path).c_str());
return 0;
}

View File

@ -4,7 +4,8 @@
class UltraSimpleStaticFileHandler :public StaticFileHandler
{
public:
int answer_pathreq(const char * const path, struct mg_connection *conn);
~UltraSimpleStaticFileHandler();
int answer_pathreq(const char * const path, struct mg_connection *conn);
};

View File

@ -22,20 +22,17 @@ static const char * hello_world_html = u8R"HERE(
</body>
</html>)HERE";
UltraSimpleStaticFileHandler::~UltraSimpleStaticFileHandler() {}
class UltraSimpleStaticFileHandler : StaticFileHandler
int
UltraSimpleStaticFileHandler::answer_pathreq(const char * const path,
struct mg_connection *conn)
{
public:
int 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-Type: text/html\r\n\r\n%s",
hello_world_html.size(),
hello_world_html.c_str());
return 0;
}
};
mg_printf(conn, "HTTP/1.0 200 OK\r\n"
"Content-Length: %d\r\n"
"Content-Type: text/html\r\n\r\n%s",
sizeof(hello_world_html),
hello_world_html);
return 0;
}