definitiv zu müde zum weitermachen... bup
This commit is contained in:
parent
73989650b1
commit
b2fe83dc2c
|
@ -1,15 +1,36 @@
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
using std::strcmp;
|
using std::strcmp;
|
||||||
#include "Foohash.H"
|
#include "Foohash.H"
|
||||||
|
#include "routerin.H"
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
namespace routerin {
|
namespace routerin {
|
||||||
class EventRouter {
|
|
||||||
|
|
||||||
|
int reqroute(struct mg_event *event)
|
||||||
|
{
|
||||||
|
Foohash fh;
|
||||||
|
RouterOp *blub;
|
||||||
|
unsigned int i = 0;
|
||||||
|
const char * reqstr, *tmpstr;
|
||||||
|
if (event->type == MG_REQUEST_BEGIN) {
|
||||||
|
if (! (reqstr=event->request_info->uri)){
|
||||||
|
cout << "starting with str as " << reqstr << endl;
|
||||||
|
tmpstr = strchr(reqstr,'/');
|
||||||
|
if (tmpstr) reqstr = tmpstr++;
|
||||||
|
cout <<" having reqstr as " << reqstr << " now. " << endl;
|
||||||
|
|
||||||
};
|
// blub = fh.in_word_set("/static" , sizeof("/static")-1);
|
||||||
|
//
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
std::cerr << ++i << " here be dragons!\n" ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class BaseHandler{
|
class BaseHandler{
|
||||||
virtual int handle_event() = 0;
|
virtual int handle_event() = 0;
|
||||||
|
@ -23,7 +44,56 @@ class StaticEventHandler:public BaseHandler{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
};
|
/*
|
||||||
|
*
|
||||||
|
static int event_handler(struct mg_event *event) {
|
||||||
|
|
||||||
|
if (event->type == MG_REQUEST_BEGIN) {
|
||||||
|
if (!strcmp(
|
||||||
|
event->request_info->uri,
|
||||||
|
"/handle_post_request")) {
|
||||||
|
char path[200];
|
||||||
|
FILE *fp = mg_upload(event->conn,
|
||||||
|
"/tmp",
|
||||||
|
path,
|
||||||
|
sizeof(path));
|
||||||
|
if (fp != NULL) {
|
||||||
|
fclose(fp);
|
||||||
|
mg_printf(event->conn,
|
||||||
|
"HTTP/1.0 200 OK\r\n\r\nSaved: [%s]",
|
||||||
|
path);
|
||||||
|
} else {
|
||||||
|
mg_printf(event->conn,"%s",
|
||||||
|
"HTTP/1.0 200 OK\r\n\r\nNo files sent");
|
||||||
|
}
|
||||||
|
} 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>";
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark request as processed
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// All other events left unprocessed
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}; //end of namespace routerin
|
||||||
|
|
||||||
//REST API Documentation
|
//REST API Documentation
|
||||||
|
|
||||||
|
|
|
@ -6,56 +6,12 @@
|
||||||
#include <mongoose.h>
|
#include <mongoose.h>
|
||||||
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "routerin.H"
|
||||||
//globally accessible config
|
//globally accessible config
|
||||||
static struct sic_conf args_info;
|
static struct sic_conf args_info;
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
|
||||||
static int event_handler(struct mg_event *event) {
|
|
||||||
|
|
||||||
if (event->type == MG_REQUEST_BEGIN) {
|
|
||||||
if (!strcmp(
|
|
||||||
event->request_info->uri,
|
|
||||||
"/handle_post_request")) {
|
|
||||||
char path[200];
|
|
||||||
FILE *fp = mg_upload(event->conn,
|
|
||||||
"/tmp",
|
|
||||||
path,
|
|
||||||
sizeof(path));
|
|
||||||
if (fp != NULL) {
|
|
||||||
fclose(fp);
|
|
||||||
mg_printf(event->conn,
|
|
||||||
"HTTP/1.0 200 OK\r\n\r\nSaved: [%s]",
|
|
||||||
path);
|
|
||||||
} else {
|
|
||||||
mg_printf(event->conn,"%s",
|
|
||||||
"HTTP/1.0 200 OK\r\n\r\nNo files sent");
|
|
||||||
}
|
|
||||||
} 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>";
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark request as processed
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All other events left unprocessed
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class MongooseHandler{
|
class MongooseHandler{
|
||||||
private:
|
private:
|
||||||
|
@ -76,7 +32,7 @@ class MongooseHandler{
|
||||||
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};
|
||||||
this->ctx= mg_start(options, &event_handler,nullptr);
|
this->ctx= mg_start(options, &routerin::reqroute,nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
//no copy constructor:
|
//no copy constructor:
|
||||||
|
|
Loading…
Reference in New Issue