diff options
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | .gitmodules | 3 | ||||
-rw-r--r-- | Makefile | 21 | ||||
m--------- | mongoose | 0 | ||||
-rw-r--r-- | src/apiHandler.cpp | 15 | ||||
-rw-r--r-- | src/apiHandler.h | 22 | ||||
-rw-r--r-- | src/server.cpp | 35 | ||||
-rw-r--r-- | www/index.html | 10 |
8 files changed, 112 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f693558 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.project +.cproject +.settings +bin +*.o +*.swp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1d5002f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "mongoose"] + path = mongoose + url = https://github.com/cesanta/mongoose diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3f4d92f --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +OBJ=src/server.o src/apiHandler.o mongoose/mongoose.o +OUT=bin/server + +CFLAGS += -Wall -DNO_CGI -DNO_POPEN -DUSE_IPV6 +CXXFLAGS += -Wall -std=c++0x -Imongoose +#LDFLAGS += + +ifdef DEBUG +CFLAGS += -g -O0 +CXXFLAGS += -g -O0 +else +CFLAGS += -O3 +CXXFLAGS += -O3 +endif + +all: build + +build: $(OBJ) + $(CXX) $(CPPFLAGS) $(OBJ) -o $(OUT) $(LDFLAGS) +clean: + rm -rf $(OUT) $(OBJ) diff --git a/mongoose b/mongoose new file mode 160000 +Subproject 41b405d7bf6e620bf0a8e34e30f135a7e81d613 diff --git a/src/apiHandler.cpp b/src/apiHandler.cpp new file mode 100644 index 0000000..231fd6c --- /dev/null +++ b/src/apiHandler.cpp @@ -0,0 +1,15 @@ +#include "apiHandler.h" + +using namespace std; + +apiHandler::apiHandler(struct mg_connection *conn) { + MyConnection = conn; +} + +apiHandler::~apiHandler(void) { } + +int apiHandler::processRequest(void) { + + return MG_FALSE; + +} diff --git a/src/apiHandler.h b/src/apiHandler.h new file mode 100644 index 0000000..6909fdd --- /dev/null +++ b/src/apiHandler.h @@ -0,0 +1,22 @@ +#ifndef _APIHANDLER_ +#define APIHANDLER + +#include <iostream> +#include <string> +#include <vector> +#include <regex> +#include "mongoose.h" + +using namespace std; + +class apiHandler { +private: + struct mg_connection *MyConnection; + +public: + apiHandler(struct mg_connection*); + ~apiHandler(void); + int processRequest(); +}; + +#endif diff --git a/src/server.cpp b/src/server.cpp new file mode 100644 index 0000000..3efb51d --- /dev/null +++ b/src/server.cpp @@ -0,0 +1,35 @@ +#include <iostream> +#include <string> +#include "mongoose.h" +#include "apiHandler.h" + +using namespace std; + +int event_handler(struct mg_connection *conn, enum mg_event ev) { + apiHandler MyApiHandler(conn); + + switch (ev) { + case MG_AUTH: return MG_TRUE; + case MG_REQUEST: return MyApiHandler.processRequest(); + default: return MG_FALSE; + } +} + +int main(int argc, char **argv) { + string server_port = "8080"; + + struct mg_server *server = mg_create_server(NULL, event_handler); + + mg_set_option(server, "document_root", "./www/"); + mg_set_option(server, "enable_directory_listing", "no"); + mg_set_option(server, "listening_port", server_port.c_str()); + + cout<<"Staring server on port "<<server_port<<"."<<endl; + while (true) { + mg_poll_server(server, 1000); + } + + mg_destroy_server(&server); + + return 0; +} diff --git a/www/index.html b/www/index.html new file mode 100644 index 0000000..a8607f4 --- /dev/null +++ b/www/index.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="UTF-8"> + +</head> +<body> + <h1>Hello World!</h1> +</body> +</html> |