klassenhierarchie aufräumung
This commit is contained in:
parent
67f49d96eb
commit
959c8b134c
|
@ -0,0 +1,20 @@
|
||||||
|
#include "MediocreSimpleStaticFileHandler.H"
|
||||||
|
//#include "InputMemmoryFile.H"
|
||||||
|
class MediocreSimpleStaticFileHandler :StaticFileHandler
|
||||||
|
{
|
||||||
|
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).to_cstring());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
class Routerin
|
class Routerin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Routerin()=delete;
|
Routerin();
|
||||||
Routerin(StaticFileHandler &sfh);
|
//Routerin(StaticFileHandler &sfh);
|
||||||
|
|
||||||
int event_route(struct mg_event *event);
|
int event_route(struct mg_event *event);
|
||||||
|
|
||||||
|
|
199
src/Routerin.cc
199
src/Routerin.cc
|
@ -9,33 +9,32 @@ using std::strcmp;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
class Routerin {
|
|
||||||
|
|
||||||
Routerin():
|
Routerin::Routerin():
|
||||||
sfh(new UltraSimpleStaticFileHandler())
|
sfh(new UltraSimpleStaticFileHandler())
|
||||||
{
|
{
|
||||||
cout << "Konstr Routering" << std::endl;
|
cout << "Konstr Routering" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int event_route(struct mg_event *event)
|
int Routerin::event_route(struct mg_event *event)
|
||||||
{
|
{
|
||||||
// Foohash fh;
|
// Foohash fh;
|
||||||
switch(event->type){
|
switch(event->type){
|
||||||
case MG_REQUEST_BEGIN:
|
case MG_REQUEST_BEGIN:
|
||||||
return event_request_route(event);
|
return event_request_route(event);
|
||||||
case MG_THREAD_BEGIN :
|
case MG_THREAD_BEGIN :
|
||||||
return event_newthread_route(event);
|
return event_newthread_route(event);
|
||||||
case MG_REQUEST_END:
|
case MG_REQUEST_END:
|
||||||
return event_requend_route(event);
|
return event_requend_route(event);
|
||||||
case MG_HTTP_ERROR:
|
case MG_HTTP_ERROR:
|
||||||
case MG_EVENT_LOG :
|
case MG_EVENT_LOG :
|
||||||
case MG_THREAD_END:
|
case MG_THREAD_END:
|
||||||
default:
|
default:
|
||||||
return event_fallback_route(event);
|
return event_fallback_route(event);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int event_request_route(struct mg_event *event){
|
int Routerin::event_request_route(struct mg_event *event){
|
||||||
const RouterOp *blub=0;
|
const RouterOp *blub=0;
|
||||||
Foohash fh;
|
Foohash fh;
|
||||||
const char *reqstr=0;
|
const char *reqstr=0;
|
||||||
|
@ -90,112 +89,108 @@ class Routerin {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int rq_static(char const * const reststr , struct mg_event *event)
|
int Routerin::rq_static(char const * const reststr , struct mg_event *event)
|
||||||
{
|
{
|
||||||
std::cerr << " a static file is reqested!" << endl;
|
std::cerr << " a static file is reqested!" << endl;
|
||||||
std::cerr << " path: " << reststr << endl;
|
std::cerr << " path: " << reststr << endl;
|
||||||
|
sfh->answer_pathreq(reststr,event->conn);
|
||||||
|
return 1;
|
||||||
return 1;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int rq_file(char const * const reststr , struct mg_event *event)
|
int Routerin::rq_file(char const * const reststr , struct mg_event *event)
|
||||||
{
|
{
|
||||||
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 rq_date(char const * const reststr , struct mg_event *event)
|
int Routerin::rq_date(char const * const reststr , struct mg_event *event)
|
||||||
{
|
{
|
||||||
std::cerr << "requested filelist ordered by date!" << endl ;
|
std::cerr << "requested filelist ordered by date!" << endl ;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rq_upload(char const * const reststr, struct mg_event *event)
|
int Routerin::rq_upload(char const * const reststr, struct mg_event *event)
|
||||||
{
|
{
|
||||||
std::cerr << "here we will get uploadish!" << endl ;
|
std::cerr << "here we will get uploadish!" << endl ;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int event_requend_route(struct mg_event *event){
|
int Routerin::event_requend_route(struct mg_event *event){
|
||||||
std::cerr << "ended request" <<endl;
|
std::cerr << "ended request" <<endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int event_fallback_route(struct mg_event *event){
|
int Routerin::event_fallback_route(struct mg_event *event){
|
||||||
//DEBUG CODE
|
|
||||||
std::cerr << "Got an unhandled mg_event" << endl;
|
|
||||||
std::cerr << "Its type is: " << event->type << endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int event_newthread_route(struct mg_event *event){
|
|
||||||
//DEBUG CODE
|
//DEBUG CODE
|
||||||
std::cerr << "Started new thread!" <<endl;
|
std::cerr << "Got an unhandled mg_event" << endl;
|
||||||
return 1;
|
std::cerr << "Its type is: " << event->type << endl;
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Routerin::event_newthread_route(struct mg_event *event){
|
||||||
|
//DEBUG CODE
|
||||||
|
std::cerr << "Started new thread!" <<endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
static int event_handler(struct mg_event *event) {
|
static int event_handler(struct mg_event *event) {
|
||||||
|
|
||||||
if (event->type == MG_REQUEST_BEGIN) {
|
if (event->type == MG_REQUEST_BEGIN) {
|
||||||
if (!strcmp(
|
if (!strcmp(
|
||||||
event->request_info->uri,
|
event->request_info->uri,
|
||||||
"/handle_post_request")) {
|
"/handle_post_request")) {
|
||||||
char path[200];
|
char path[200];
|
||||||
FILE *fp = mg_upload(event->conn,
|
FILE *fp = mg_upload(event->conn,
|
||||||
"/tmp",
|
"/tmp",
|
||||||
path,
|
path,
|
||||||
sizeof(path));
|
sizeof(path));
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
mg_printf(event->conn,
|
mg_printf(event->conn,
|
||||||
"HTTP/1.0 200 OK\r\n\r\nSaved: [%s]",
|
"HTTP/1.0 200 OK\r\n\r\nSaved: [%s]",
|
||||||
path);
|
path);
|
||||||
} else {
|
|
||||||
mg_printf(event->conn,"%s",
|
|
||||||
"HTTP/1.0 200 OK\r\n\r\nNo files sent");
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Show HTML form. Make sure it has enctype="multipart/form-data" attr.
|
mg_printf(event->conn,"%s",
|
||||||
static const char *html_form =
|
"HTTP/1.0 200 OK\r\n\r\nNo files sent");
|
||||||
"<html><body>Upload example."
|
|
||||||
"<form method=\"POST\" action=\"/handle_post_request\" "
|
|
||||||
" enctype=\"multipart/form-data\">"
|
|
||||||
"<input type=\"file\" name=\"file\" /> <br/>"
|
|
||||||
"<input type=\"submit\" value=\"Upload\" />"
|
|
||||||
"</form></body></html>";
|
|
||||||
|
|
||||||
mg_printf(event->conn, "HTTP/1.0 200 OK\r\n"
|
|
||||||
"Content-Length: %d\r\n"
|
|
||||||
"Content-Type: text/html\r\n\r\n%s",
|
|
||||||
(int) strlen(html_form), html_form);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Show HTML form. Make sure it has enctype="multipart/form-data" attr.
|
||||||
|
static const char *html_form =
|
||||||
|
"<html><body>Upload example."
|
||||||
|
"<form method=\"POST\" action=\"/handle_post_request\" "
|
||||||
|
" enctype=\"multipart/form-data\">"
|
||||||
|
"<input type=\"file\" name=\"file\" /> <br/>"
|
||||||
|
"<input type=\"submit\" value=\"Upload\" />"
|
||||||
|
"</form></body></html>";
|
||||||
|
|
||||||
// Mark request as processed
|
mg_printf(event->conn, "HTTP/1.0 200 OK\r\n"
|
||||||
return 1;
|
"Content-Length: %d\r\n"
|
||||||
|
"Content-Type: text/html\r\n\r\n%s",
|
||||||
|
(int) strlen(html_form), html_form);
|
||||||
}
|
}
|
||||||
|
|
||||||
// All other events left unprocessed
|
// Mark request as processed
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
// All other events left unprocessed
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}; //end of class Routerin
|
|
||||||
|
|
||||||
//REST API Documentation
|
//REST API Documentation
|
||||||
|
|
||||||
///files/<zahl> (index in vector<Sicccobjst>)
|
///files/<zahl> (index in vector<Sicccobjst>)
|
||||||
|
|
|
@ -8,7 +8,3 @@ class 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class UltraSimpleStaticFileHandler;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
#include "SimpleStaticFileHandler.h"
|
||||||
|
|
||||||
|
class UltraSimpleStaticFileHandler : StaticFileHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int answer_pathreq(const char * const path, struct mg_connection *conn);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "StaticFileHandler.H"
|
|
||||||
//#include "InputMemmoryFile.H"
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "UltraSimpleStaticFileHandler.H"
|
||||||
|
#include <mongoose.h>
|
||||||
|
|
||||||
static const char * hello_world_html = u8R"HERE(
|
static const char * hello_world_html = u8R"HERE(
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -38,21 +38,4 @@ class UltraSimpleStaticFileHandler : StaticFileHandler
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MediocreSimpleStaticFileHandler :StaticFileHandler
|
|
||||||
{
|
|
||||||
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).to_cstring());
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue