rendering of mainpage starts to work
At least it seems working. No dynamic objects are created for now...
This commit is contained in:
parent
1b5b8b7413
commit
e9c7f79bc3
|
@ -12,6 +12,8 @@ siccc_SOURCES = \
|
||||||
src/options.c \
|
src/options.c \
|
||||||
src/Routerin.H \
|
src/Routerin.H \
|
||||||
src/Routerin.cc \
|
src/Routerin.cc \
|
||||||
|
src/DynamicObjects.cc \
|
||||||
|
src/DynamicObjects.H \
|
||||||
src/sicmain.cc \
|
src/sicmain.cc \
|
||||||
src/StaticFileHandler.H \
|
src/StaticFileHandler.H \
|
||||||
src/StaticFileHandler.cc \
|
src/StaticFileHandler.cc \
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mongoose.h>
|
#include <mongoose.h>
|
||||||
#include "Sicmaster.H"
|
#include "Routerin.H"
|
||||||
#include "Sicobject.H"
|
#include "Sicobject.H"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
class Routerin;
|
||||||
|
|
||||||
class DynamicObjects
|
class DynamicObjects
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::string render_object_list();
|
std::string render_object_list();
|
||||||
std::string cleanpath(const char * const);
|
std::string cleanpath(const char * const);
|
||||||
DynamicObjects(Sicmaster & sicmaster):sicmaster(sicmaster) {};
|
DynamicObjects(Routerin * merouterin) : _merouterin(merouterin){ };
|
||||||
~DynamicObjects() {};
|
~DynamicObjects() {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string _cleanpath (const char * const path);
|
std::string _cleanpath (const char * const path);
|
||||||
std::map<unsigned int, Sicobject *> _themap;
|
std::map<unsigned int, Sicobject *> _themap;
|
||||||
Sicmaster & sicmaster;
|
Routerin * _merouterin;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ std::string DynamicObjects::render_object_list(){
|
||||||
|
|
||||||
for (auto it : this->_themap){
|
for (auto it : this->_themap){
|
||||||
output += u8"<li>\n";
|
output += u8"<li>\n";
|
||||||
output += u8"<a href=\"" + it.second->get_loadurl() + u8"\">";
|
output += u8"<a href=\"" + it.second->get_loadurl() + u8"\">"; //we could include baseurl here?
|
||||||
output += it.second->get_fname();
|
output += it.second->get_fname();
|
||||||
output += u8"</a> <span class=\"size\">";
|
output += u8"</a> <span class=\"size\">";
|
||||||
output += it.second->bytesize_string();
|
output += it.second->bytesize_string();
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
#include <mongoose.h>
|
#include <mongoose.h>
|
||||||
#include "StaticFileHandler.H"
|
#include "StaticFileHandler.H"
|
||||||
|
#include "DynamicObjects.H"
|
||||||
|
|
||||||
|
class DynamicObjects;
|
||||||
|
|
||||||
class Routerin
|
class Routerin
|
||||||
{
|
{
|
||||||
|
@ -38,9 +41,14 @@ public:
|
||||||
return rouri->event_fallback_route(event);
|
return rouri->event_fallback_route(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::string & get_baseurl(){return _baseurl;}
|
||||||
|
void set_baseurl(std::string baseurl);
|
||||||
private:
|
private:
|
||||||
explicit Routerin();
|
explicit Routerin();
|
||||||
std::unique_ptr<StaticFileHandler> sfh;
|
std::unique_ptr<StaticFileHandler> sfh;
|
||||||
|
DynamicObjects * _dyn_obs;
|
||||||
|
std::string _baseurl;
|
||||||
|
|
||||||
bool hasInstance = false;
|
bool hasInstance = false;
|
||||||
|
|
||||||
int event_request_route ( struct mg_event *event);
|
int event_request_route ( struct mg_event *event);
|
||||||
|
@ -52,5 +60,6 @@ private:
|
||||||
int rq_file(char const * const reststr , struct mg_event *event);
|
int rq_file(char const * const reststr , struct mg_event *event);
|
||||||
int rq_date(char const * const reststr , struct mg_event *event);
|
int rq_date(char const * const reststr , struct mg_event *event);
|
||||||
int rq_upload(char const * const reststr , struct mg_event *event);
|
int rq_upload(char const * const reststr , struct mg_event *event);
|
||||||
|
int rq_render_mainpage(struct mg_event *event);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,21 +2,65 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using std::strcmp;
|
|
||||||
#include "Foohash.H"
|
#include "Foohash.H"
|
||||||
#include "Routerin.H"
|
#include "Routerin.H"
|
||||||
|
|
||||||
|
|
||||||
|
using std::strcmp;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
|
//put this in class ?? Util??
|
||||||
|
//FIXME:
|
||||||
|
static const std::string std_html_header= u8R"HUENERBLUBBE(<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<title>Sharing is Caring</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
|
</head>
|
||||||
|
)HUENERBLUBBE" ;
|
||||||
|
|
||||||
|
|
||||||
|
static const std::string std_mainpage= u8R"HASENBLUBBE(
|
||||||
|
<body>
|
||||||
|
<div id="page">
|
||||||
|
<h1>
|
||||||
|
<span style="color: red">Sharing</span>
|
||||||
|
<span style="color: blue">is</span>
|
||||||
|
<span style="color: green">Caring</span>
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div id="up">
|
||||||
|
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||||
|
<input id="file" name="file" type="file">
|
||||||
|
<input type="submit" value="Hochladen">
|
||||||
|
</form>
|
||||||
|
<p class="hint">
|
||||||
|
Wie wärs mit einem schicken Foto? Dem Flyer der nächsten
|
||||||
|
Party? Oder gar einem gesprochenen Kommentar?
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)HASENBLUBBE" ;
|
||||||
|
|
||||||
|
|
||||||
|
static const std::string std_footer= u8R"FISCHBLUBBE(
|
||||||
|
<p class="foot">
|
||||||
|
Eine Guerilla-Kunstaktion von <b><<</>></b>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
)FISCHBLUBBE" ;
|
||||||
|
|
||||||
|
|
||||||
Routerin::Routerin():
|
Routerin::Routerin():
|
||||||
sfh( new StaticFileHandler())
|
sfh( new StaticFileHandler())
|
||||||
{
|
|
||||||
cout << "Konstr Routering" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
{
|
||||||
|
_dyn_obs = new DynamicObjects(this);
|
||||||
|
cout << "Konstr Routering" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
int Routerin::event_request_route(struct mg_event *event){
|
int Routerin::event_request_route(struct mg_event *event){
|
||||||
const RouterOp *blub=0;
|
const RouterOp *blub=0;
|
||||||
|
@ -59,7 +103,8 @@ int Routerin::event_request_route(struct mg_event *event){
|
||||||
};
|
};
|
||||||
}else{
|
}else{
|
||||||
std::cerr << "no blub! in " << __LINE__ << endl;
|
std::cerr << "no blub! in " << __LINE__ << endl;
|
||||||
retval = rq_static("illegalurl.htm",event);
|
//retval = rq_static("illegalurl.htm",event);
|
||||||
|
retval = rq_render_mainpage(event);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,6 +119,30 @@ int Routerin::event_request_route(struct mg_event *event){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Routerin::set_baseurl(std::string baseurl){
|
||||||
|
_baseurl = baseurl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Routerin::rq_render_mainpage(struct mg_event * event){
|
||||||
|
std::cerr << "rendering main page!" << endl;
|
||||||
|
const std::string fubb =
|
||||||
|
std_html_header +
|
||||||
|
std_mainpage +
|
||||||
|
_dyn_obs->render_object_list()+
|
||||||
|
std_footer.c_str() ;
|
||||||
|
|
||||||
|
mg_printf(event->conn, "HTTP/1.0 200 OK\r\n"
|
||||||
|
"Content-Length: %lu\r\n"
|
||||||
|
"Content-Type: text/html\r\n\r\n%s",
|
||||||
|
fubb.size(),
|
||||||
|
fubb.c_str());
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int Routerin::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;
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/// Laufzeitrelevante Anwendungsdatensammlung und Signaling
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Sicmaster
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
//Sicmaster(StaticFileHandler &sfh);
|
|
||||||
|
|
||||||
~Sicmaster();
|
|
||||||
// const ???
|
|
||||||
static Sicmaster * get_instance()
|
|
||||||
{
|
|
||||||
static Sicmaster * me = nullptr;
|
|
||||||
if (!me)
|
|
||||||
return me = new Sicmaster();
|
|
||||||
return me;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string & get_baseurl(){
|
|
||||||
return _baseurl;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
explicit Sicmaster();
|
|
||||||
unsigned int _portnum;
|
|
||||||
unsigned int _filedir;
|
|
||||||
std::string _baseurl;
|
|
||||||
};
|
|
|
@ -24,12 +24,15 @@ class MongooseHandler{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//default listenport:8080
|
//default listenport:8080
|
||||||
MongooseHandler(int listenport=8080):
|
MongooseHandler(int listenport=8080,std::string baseurl="http://[::1]/"):
|
||||||
ctx(nullptr),
|
ctx(nullptr),
|
||||||
listenport(listenport)
|
listenport(listenport)
|
||||||
{
|
{
|
||||||
char portstring[8];
|
char portstring[8];
|
||||||
|
|
||||||
Routerin *routerin = Routerin::get_instance();
|
Routerin *routerin = Routerin::get_instance();
|
||||||
|
routerin->set_baseurl(baseurl);
|
||||||
|
|
||||||
std::snprintf(portstring,8,"%d",this->listenport);
|
std::snprintf(portstring,8,"%d",this->listenport);
|
||||||
const char *options[] =
|
const char *options[] =
|
||||||
{"listening_ports",portstring,nullptr};
|
{"listening_ports",portstring,nullptr};
|
||||||
|
@ -62,6 +65,7 @@ void dump_args()
|
||||||
cout << "value of listen: " <<
|
cout << "value of listen: " <<
|
||||||
args_info.listen_arg[i] <<std::endl;
|
args_info.listen_arg[i] <<std::endl;
|
||||||
|
|
||||||
|
|
||||||
// if (args_info.saveconf_given) {
|
// if (args_info.saveconf_given) {
|
||||||
// if (cmd_parser_file_save(args_info.conffile_arg,
|
// if (cmd_parser_file_save(args_info.conffile_arg,
|
||||||
// &args_info) == EXIT_FAILURE)
|
// &args_info) == EXIT_FAILURE)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user