diff --git a/src/routerin.cc b/src/routerin.cc index 06e9c99..4440ad5 100644 --- a/src/routerin.cc +++ b/src/routerin.cc @@ -1,15 +1,36 @@ #include - +#include using std::strcmp; #include "Foohash.H" +#include "routerin.H" + +using std::cout; +using std::endl; 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{ 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 = + "Upload example." + "
" + "
" + "" + "
"; + + 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 diff --git a/src/sicmain.cc b/src/sicmain.cc index 5b1208f..e0f86f3 100644 --- a/src/sicmain.cc +++ b/src/sicmain.cc @@ -6,56 +6,12 @@ #include #include "options.h" - +#include "routerin.H" //globally accessible config static struct sic_conf args_info; 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 = - "Upload example." - "
" - "
" - "" - "
"; - - 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{ private: @@ -76,7 +32,7 @@ class MongooseHandler{ std::snprintf(portstring,8,"%d",this->listenport); const char *options[] = {"listening_ports",portstring,nullptr}; - this->ctx= mg_start(options, &event_handler,nullptr); + this->ctx= mg_start(options, &routerin::reqroute,nullptr); } //no copy constructor: