109 lines
2.2 KiB
C++
109 lines
2.2 KiB
C++
|
|
#include <cstring>
|
|
#include <iostream>
|
|
using std::strcmp;
|
|
#include "Foohash.H"
|
|
#include "routerin.H"
|
|
|
|
using std::cout;
|
|
using std::endl;
|
|
|
|
namespace routerin {
|
|
|
|
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{
|
|
virtual int handle_event() = 0;
|
|
};
|
|
|
|
|
|
class FilesEventHandler:public BaseHandler{
|
|
};
|
|
|
|
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
|
|
|
|
///files/<zahl> (index in vector<Sicccobjst>)
|
|
|
|
///date/<datestring> (files am date hochgeladen)
|
|
|
|
///static/<mööp.html> (statisches html ausliefern)
|
|
|
|
///uploadmagic/ (upload form request)
|
|
|
|
|