From d691b2cc91f3ba698487e16a158ce07eb99ed78f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Mon, 20 Oct 2014 17:30:16 -0300 Subject: [PATCH 01/17] corrige bug of encoder parameters --- mongoose/Request.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoose/Request.cpp b/mongoose/Request.cpp index 2c529e1404..6aba97b02d 100644 --- a/mongoose/Request.cpp +++ b/mongoose/Request.cpp @@ -161,7 +161,7 @@ namespace Mongoose string param; while(std::getline(ss, param, '&')){ //block for '&' const string& key = param.substr(0, param.find('=')); - const string& value = param.substr(param.find('=')+1); + const string& value = get(key); mapKeyValue[key] = value; // insert map } return mapKeyValue; From fd973e4397ae3d99402abce380b3711d9201c57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Tue, 11 Nov 2014 14:41:20 -0300 Subject: [PATCH 02/17] Corrigindo o getAllVariable e criando getOptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getAllVariable agora para POST e GET dados getOptions no server para os controladores pegar opções passadas ao server --- mongoose.h | 1 + mongoose/Request.cpp | 16 +++++++++------- mongoose/Request.h | 2 +- mongoose/Server.cpp | 9 +++++++++ mongoose/Server.h | 8 ++++++++ mongoose/Utils.cpp | 26 ++++++++++++++++++++++++-- mongoose/Utils.h | 2 ++ 7 files changed, 54 insertions(+), 10 deletions(-) diff --git a/mongoose.h b/mongoose.h index 014eee1b30..ec1ed5dd22 100644 --- a/mongoose.h +++ b/mongoose.h @@ -100,6 +100,7 @@ void *mg_start_thread(void *(*func)(void *), void *param); char *mg_md5(char buf[33], ...); int mg_authorize_digest(struct mg_connection *c, FILE *fp); void mg_send_digest_auth_request(struct mg_connection *conn); +int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded); void mg_server_do_i_handle(struct mg_server *server, mg_handler_t handler); diff --git a/mongoose/Request.cpp b/mongoose/Request.cpp index 6aba97b02d..040825a4e6 100644 --- a/mongoose/Request.cpp +++ b/mongoose/Request.cpp @@ -3,6 +3,7 @@ #include #include #include "Request.h" +#include "Utils.h" using namespace std; @@ -153,16 +154,17 @@ namespace Mongoose return false; } - - map Request::getAllVariable() + + multimap Request::getAllVariable() { - map mapKeyValue; - stringstream ss(data); + multimap mapKeyValue; + stringstream ss(data + '&' + (connection->query_string ? connection->query_string:"")); //POST + GET string param; while(std::getline(ss, param, '&')){ //block for '&' - const string& key = param.substr(0, param.find('=')); - const string& value = get(key); - mapKeyValue[key] = value; // insert map + const size_t& delimitPos = param.find('='); + const string& key = param.substr(0, delimitPos); + const string& value = param.substr(delimitPos+1); + mapKeyValue.insert(make_pair(key, Utils::urlDecode(value) ) ); // insert map } return mapKeyValue; } diff --git a/mongoose/Request.h b/mongoose/Request.h index 622b141dec..902c307539 100644 --- a/mongoose/Request.h +++ b/mongoose/Request.h @@ -45,7 +45,7 @@ namespace Mongoose * @brief getAllVariable * @return map with all variables */ - map getAllVariable(); + multimap getAllVariable(); /** * Get the value for a certain variable diff --git a/mongoose/Server.cpp b/mongoose/Server.cpp index 4dd0389708..95258c9bca 100644 --- a/mongoose/Server.cpp +++ b/mongoose/Server.cpp @@ -256,6 +256,15 @@ namespace Mongoose optionsMap[key] = value; } + string Server::getOption(const string& key) + { + map::iterator it = optionsMap.find(key); + if (it != optionsMap.end()) + return it->second; + + return ""; + } + #ifndef NO_WEBSOCKET WebSockets &Server::getWebSockets() { diff --git a/mongoose/Server.h b/mongoose/Server.h index 82f876f4df..7f09c45fe9 100644 --- a/mongoose/Server.h +++ b/mongoose/Server.h @@ -102,6 +102,14 @@ namespace Mongoose */ void setOption(string key, string value); + /** + * Get a mongoose extra option + * + * @param string the name of the option + * @return string the value of the option + */ + string getOption(const string& key); + #ifndef NO_WEBSOCKET /** * Returns the WebSockets container diff --git a/mongoose/Utils.cpp b/mongoose/Utils.cpp index d808e909e6..24f3827ce9 100644 --- a/mongoose/Utils.cpp +++ b/mongoose/Utils.cpp @@ -1,10 +1,10 @@ #include #include #include "Utils.h" -#ifndef WIN32 +#ifndef _MSC_VER #include #endif -#ifdef WIN32 +#ifdef _MSC_VER #include #endif @@ -39,4 +39,26 @@ namespace Mongoose usleep(1000 * ms); #endif } + + + string Utils::urlDecode(const string &SRC) { + string ret; + char ch; + int ii; + for (int i = 0; i(ii); + ret += ch; + i = i + 2; + } + else if (SRC[i] == '+'){ + ret += ' '; + } + else { + ret += SRC[i]; + } + } + return (ret); + } } diff --git a/mongoose/Utils.h b/mongoose/Utils.h index d8a36eca72..d9e8cd92ef 100644 --- a/mongoose/Utils.h +++ b/mongoose/Utils.h @@ -2,6 +2,7 @@ #define _MONGOOSE_UTILS_H #include +#include using namespace std; @@ -12,6 +13,7 @@ namespace Mongoose public: static string htmlEntities(string data); static void sleep(int ms); + static string urlDecode(const string &SRC); }; } From 6b732530de945590e3cd7a4749acf964c4fa5c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Fri, 21 Nov 2014 08:51:44 -0300 Subject: [PATCH 03/17] ajustes fino --- CMakeLists.txt | 6 +- CMakeLists.txt.user | 186 ++++++++++++++++++++++++++++++++++++++++++++ mongoose/Utils.cpp | 1 + 3 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt b/CMakeLists.txt index f03cc00124..de525e6eaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,8 @@ if (ENABLE_REGEX_URL) SET (CMAKE_CXX_FLAGS "-std=c++11") endif (ENABLE_REGEX_URL) +SET (CMAKE_CXX_FLAGS "-g") + if (CPP_BINDING) set (SOURCES ${SOURCES} @@ -84,9 +86,9 @@ if (NOT WEBSOCKET) add_definitions("-DNO_WEBSOCKET") endif (NOT WEBSOCKET) -# Adding dl +# Adding dl and pthread if (NOT WIN32) - set (EXTRA_LIBS ${EXTRA_LIBS} dl) + set (EXTRA_LIBS ${EXTRA_LIBS} dl pthread) endif (NOT WIN32) # Adding sockets for Win32 diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 0000000000..bb09397ab9 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,186 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {c412eda5-5517-45a5-851c-cfa70e03576b} + 0 + 0 + 0 + + false + /home/ubuntu/Downloads/mongoose-cpp/build + + + + + false + false + true + Make + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + clean + + true + false + true + Make + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Default + Default + CMakeProjectManager.CMakeBuildConfiguration + + 1 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + /home/ubuntu/workspace/EstoqueLabQuimica/build/EstoqueLabQuimica + false + /home/ubuntu/workspace/EstoqueLabQuimica + Run /home/ubuntu/workspace/EstoqueLabQuimica/build/EstoqueLabQuimica + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {dfa16868-42b0-42df-8d89-3b3d26842e66} + + + ProjectExplorer.Project.Updater.FileVersion + 15 + + diff --git a/mongoose/Utils.cpp b/mongoose/Utils.cpp index 24f3827ce9..29cdb70c07 100644 --- a/mongoose/Utils.cpp +++ b/mongoose/Utils.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "Utils.h" #ifndef _MSC_VER #include From 462c43893a5e1ec4ea91b556e0131d5cd1afff13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Fri, 21 Nov 2014 16:22:12 -0300 Subject: [PATCH 04/17] Compilation on MinGW add ifdef MINGW --- mongoose.c | 4 +++- mongoose/Server.cpp | 8 ++++---- mongoose/Utils.cpp | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mongoose.c b/mongoose.c index 93721f9bc7..b1da4e3a01 100644 --- a/mongoose.c +++ b/mongoose.c @@ -51,7 +51,9 @@ #include // For _lseeki64 #include // For _mkdir typedef int socklen_t; -typedef HANDLE pid_t; +#ifndef __MINGW32__ + typedef HANDLE pid_t; +#endif typedef SOCKET sock_t; typedef unsigned char uint8_t; typedef unsigned int uint32_t; diff --git a/mongoose/Server.cpp b/mongoose/Server.cpp index 95258c9bca..b5c4500102 100644 --- a/mongoose/Server.cpp +++ b/mongoose/Server.cpp @@ -1,10 +1,10 @@ #ifndef _MSC_VER -#include +# include #else -#include -#include -#include +# include +# include #endif +#include #include #include #include diff --git a/mongoose/Utils.cpp b/mongoose/Utils.cpp index 29cdb70c07..011abca497 100644 --- a/mongoose/Utils.cpp +++ b/mongoose/Utils.cpp @@ -34,7 +34,7 @@ namespace Mongoose void Utils::sleep(int ms) { -#ifdef WIN32 +#ifdef _MSC_VER Sleep(ms); #else usleep(1000 * ms); From da4179219075e061cda0ec979b2ef71542e62f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Fri, 21 Nov 2014 16:25:34 -0300 Subject: [PATCH 05/17] dell file for qtcreator --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 378eac25d3..43f91bca8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build +/CMakeLists.txt.user From de4e0cfd2db935227af114bbf769b3069160528f Mon Sep 17 00:00:00 2001 From: d3roch4 Date: Mon, 13 Apr 2015 11:09:51 -0300 Subject: [PATCH 06/17] Add cath in Response *process(Request &request) for trate std::exception --- .gitignore | 2 +- mongoose/RequestHandler.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 43f91bca8a..e7f8a12fa7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ build -/CMakeLists.txt.user +CMakeLists.txt.user diff --git a/mongoose/RequestHandler.h b/mongoose/RequestHandler.h index cad5f03a69..c1aacfc355 100644 --- a/mongoose/RequestHandler.h +++ b/mongoose/RequestHandler.h @@ -33,6 +33,8 @@ namespace Mongoose (controller->*function)(request, *response); } catch (string exception) { return controller->serverInternalError(exception); + } catch (const std::exception& exception) { + return controller->serverInternalError(exception.what()); } catch (...) { return controller->serverInternalError("Unknown error"); } From e577e8c5794276552b0d94427d774f80d849bb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Wed, 2 Sep 2015 14:21:21 -0300 Subject: [PATCH 07/17] Delete CMakeLists.txt.user file desnecessary --- CMakeLists.txt.user | 186 -------------------------------------------- 1 file changed, 186 deletions(-) delete mode 100644 CMakeLists.txt.user diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index bb09397ab9..0000000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop - {c412eda5-5517-45a5-851c-cfa70e03576b} - 0 - 0 - 0 - - false - /home/ubuntu/Downloads/mongoose-cpp/build - - - - - false - false - true - Make - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - clean - - true - false - true - Make - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Default - Default - CMakeProjectManager.CMakeBuildConfiguration - - 1 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 2 - - - /home/ubuntu/workspace/EstoqueLabQuimica/build/EstoqueLabQuimica - false - /home/ubuntu/workspace/EstoqueLabQuimica - Run /home/ubuntu/workspace/EstoqueLabQuimica/build/EstoqueLabQuimica - - ProjectExplorer.CustomExecutableRunConfiguration - 3768 - false - true - false - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.EnvironmentId - {dfa16868-42b0-42df-8d89-3b3d26842e66} - - - ProjectExplorer.Project.Updater.FileVersion - 15 - - From 52336433681cad8569ad562fdda53c4b5b5d6727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Tue, 27 Oct 2015 16:16:44 -0300 Subject: [PATCH 08/17] Enable session values with boost any --- CMakeLists.txt | 10 ++++++++++ mongoose/Session.cpp | 6 +++--- mongoose/Session.h | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de525e6eaa..5310fdbfff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,9 @@ option (ENABLE_STATS option (ENABLE_REGEX_URL "Enable url regex matching dispatcher" OFF) + +option (ENABLE_SESSION_BOOST_ANY + "Enable session values with boost any" OFF) set (JSONCPP_DIR "${PROJECT_SOURCE_DIR}/../jsoncpp" CACHE STRING "Json C++ directory") @@ -43,6 +46,13 @@ if (ENABLE_REGEX_URL) SET (CMAKE_CXX_FLAGS "-std=c++11") endif (ENABLE_REGEX_URL) +if (ENABLE_SESSION_BOOST_ANY) + find_package(Boost REQUIRED COMPONENTS program_options system) + include_directories(${Boost_INCLUDE_DIRS}) + set (EXTRA_LIBS ${EXTRA_LIBS} ${Boost_LIBRARIES}) + add_definitions("-DENABLE_SESSION_BOOST_ANY") +endif (ENABLE_SESSION_BOOST_ANY) + SET (CMAKE_CXX_FLAGS "-g") if (CPP_BINDING) diff --git a/mongoose/Session.cpp b/mongoose/Session.cpp index bf546f6352..7f71c8c65b 100644 --- a/mongoose/Session.cpp +++ b/mongoose/Session.cpp @@ -19,7 +19,7 @@ namespace Mongoose mutex.unlock(); } - void Session::setValue(string key, string value) + void Session::setValue(string key, Session::TypeValue value) { mutex.lock(); values[key] = value; @@ -38,11 +38,11 @@ namespace Mongoose return values.find(key) != values.end(); } - string Session::get(string key, string fallback) + Session::TypeValue Session::get(string key, Session::TypeValue fallback) { mutex.lock(); if (hasValue(key)) { - string value = values[key]; + TypeValue value = values[key]; mutex.unlock(); return value; diff --git a/mongoose/Session.h b/mongoose/Session.h index a1b830e727..a9d8b9a126 100644 --- a/mongoose/Session.h +++ b/mongoose/Session.h @@ -3,9 +3,13 @@ #include #include "Mutex.h" +#ifdef ENABLE_SESSION_BOOST_ANY +# include +#endif using namespace std; + /** * A session contains the user specific values */ @@ -13,6 +17,11 @@ namespace Mongoose { class Session { +#ifdef ENABLE_SESSION_BOOST_ANY + typedef boost::any TypeValue; +#else + typedef std::string TypeValue; +#endif public: Session(); @@ -20,9 +29,9 @@ namespace Mongoose * Sets the value of a session variable * * @param string the name of the variable - * @param string the value of the variable + * @param Session::TypeValue the value of the variable */ - void setValue(string key, string value); + void setValue(string key, Session::TypeValue value); /** * Unset a session varaible @@ -46,7 +55,7 @@ namespace Mongoose * * @return string the value of the variable if it exists, fallback else */ - string get(string key, string fallback = ""); + TypeValue get(string key, Session::TypeValue fallback = Session::TypeValue()); /** * Pings the session, this will update the creation date to now @@ -62,7 +71,7 @@ namespace Mongoose int getAge(); protected: - map values; + map values; int date; Mutex mutex; }; From 9a9a58b89107d46ee0d95e3b443273a508054286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Tue, 27 Oct 2015 17:16:38 -0300 Subject: [PATCH 09/17] ajustes for Enable session values with boost any --- mongoose/Session.cpp | 1 + mongoose/Session.h | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mongoose/Session.cpp b/mongoose/Session.cpp index 7f71c8c65b..d0621efd13 100644 --- a/mongoose/Session.cpp +++ b/mongoose/Session.cpp @@ -56,4 +56,5 @@ namespace Mongoose { return time(NULL)-date; } + } diff --git a/mongoose/Session.h b/mongoose/Session.h index a9d8b9a126..183ffe7e91 100644 --- a/mongoose/Session.h +++ b/mongoose/Session.h @@ -51,12 +51,32 @@ namespace Mongoose * Try to get the value for the given variable * * @pram string the name of the variable - * @param string the fallback value + * @param Session::TypeValue the fallback value * - * @return string the value of the variable if it exists, fallback else + * @return Session::TypeValue the value of the variable if it exists, fallback else */ TypeValue get(string key, Session::TypeValue fallback = Session::TypeValue()); +#ifdef ENABLE_SESSION_BOOST_ANY + /** + * Try to get the value for the given variable + * + * @pram string the name of the variable + * @param TypeValue the fallback value + * + * @return Type the value of the variable if it exists, fallback else + */ + template + Type get(const string& key, Type fallback = Type()) + { + TypeValue any = get(key); + if(any.empty()) + return boost::any_cast(any); + else + return fallback; + } +#endif + /** * Pings the session, this will update the creation date to now * and "keeping it alive" From 8dfdab821983c004f67423d2850f032f7bd4b38a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Tue, 27 Oct 2015 17:21:09 -0300 Subject: [PATCH 10/17] configure boost correct --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5310fdbfff..d4038cb563 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ if (ENABLE_REGEX_URL) endif (ENABLE_REGEX_URL) if (ENABLE_SESSION_BOOST_ANY) - find_package(Boost REQUIRED COMPONENTS program_options system) + find_package(Boost REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) set (EXTRA_LIBS ${EXTRA_LIBS} ${Boost_LIBRARIES}) add_definitions("-DENABLE_SESSION_BOOST_ANY") From 11abc8b31348d675cf7804c220b25e55e5aab04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Fri, 30 Oct 2015 15:23:09 -0300 Subject: [PATCH 11/17] momory leak corrections --- mongoose/Controller.cpp | 10 ---------- mongoose/Controller.h | 9 --------- mongoose/RequestHandler.h | 21 ++++++++++++++++++--- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/mongoose/Controller.cpp b/mongoose/Controller.cpp index 92a2c291d5..b1cd067ef4 100644 --- a/mongoose/Controller.cpp +++ b/mongoose/Controller.cpp @@ -109,16 +109,6 @@ namespace Mongoose } - Response *Controller::serverInternalError(string message) - { - StreamResponse *response = new StreamResponse; - - response->setCode(HTTP_SERVER_ERROR); - *response << "[500] Server internal error: " << message; - - return response; - } - vector Controller::getUrls() { return urls; diff --git a/mongoose/Controller.h b/mongoose/Controller.h index 9d2537dd23..d5a02430c0 100644 --- a/mongoose/Controller.h +++ b/mongoose/Controller.h @@ -117,15 +117,6 @@ namespace Mongoose */ void dumpRoutes(); - /** - * Called when an exception occur during the rendering - * - * @param string the error message - * - * @return response a response to send, 404 will occur if NULL - */ - virtual Response *serverInternalError(string message); - /** * Gets the session for a request/response * diff --git a/mongoose/RequestHandler.h b/mongoose/RequestHandler.h index c1aacfc355..abf66ca47f 100644 --- a/mongoose/RequestHandler.h +++ b/mongoose/RequestHandler.h @@ -24,6 +24,21 @@ namespace Mongoose { } + /** + * Called when an exception occur during the rendering + * + * @param string the error message + * + * @return response a response to send, 404 will occur if NULL + */ + virtual Response *serverInternalError(Request& request, Response& response, string message) + { + response.setCode(HTTP_SERVER_ERROR); + std::cerr << "Request: " << request.getUrl() << "Method: " << request.getMethod() << std::endl; + std::cerr << "[500] Server internal error: " << message; + return response; + } + Response *process(Request &request) { R *response = new R; @@ -32,11 +47,11 @@ namespace Mongoose controller->preProcess(request, *response); (controller->*function)(request, *response); } catch (string exception) { - return controller->serverInternalError(exception); + serverInternalError(request, *response, exception); } catch (const std::exception& exception) { - return controller->serverInternalError(exception.what()); + serverInternalError(request, *response, exception.what()); } catch (...) { - return controller->serverInternalError("Unknown error"); + serverInternalError(request, *response, "Unknown error"); } return response; From 6fd50a7916906bb77b8190eda7f5824af4e218fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Wed, 4 Nov 2015 17:29:31 -0300 Subject: [PATCH 12/17] =?UTF-8?q?Melhoria=20no=20tratamento=20de=20exce?= =?UTF-8?q?=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mongoose/RequestHandler.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mongoose/RequestHandler.h b/mongoose/RequestHandler.h index abf66ca47f..eb1ea37de7 100644 --- a/mongoose/RequestHandler.h +++ b/mongoose/RequestHandler.h @@ -31,12 +31,11 @@ namespace Mongoose * * @return response a response to send, 404 will occur if NULL */ - virtual Response *serverInternalError(Request& request, Response& response, string message) + virtual void serverInternalError(Request& request, Response& response, string message) { response.setCode(HTTP_SERVER_ERROR); std::cerr << "Request: " << request.getUrl() << "Method: " << request.getMethod() << std::endl; std::cerr << "[500] Server internal error: " << message; - return response; } Response *process(Request &request) From 50716253255ebbdd1d688fb2197da9ec4fc2bed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Tue, 10 Nov 2015 08:31:51 -0300 Subject: [PATCH 13/17] =?UTF-8?q?melhoria=20no=20tratamento=20de=20exce?= =?UTF-8?q?=C3=A7=C3=A3o=20e=20corre=C3=A7=C3=A3o=20do=20Session::get=20na?= =?UTF-8?q?=20verifica=C3=A7=C3=A3o=20do=20boost::any=20se=20esta=20vazio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mongoose/RequestHandler.h | 2 +- mongoose/Session.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mongoose/RequestHandler.h b/mongoose/RequestHandler.h index eb1ea37de7..8c2089e9ce 100644 --- a/mongoose/RequestHandler.h +++ b/mongoose/RequestHandler.h @@ -34,7 +34,7 @@ namespace Mongoose virtual void serverInternalError(Request& request, Response& response, string message) { response.setCode(HTTP_SERVER_ERROR); - std::cerr << "Request: " << request.getUrl() << "Method: " << request.getMethod() << std::endl; + std::cerr << "Request: " << request.getUrl() << " Method: " << request.getMethod() << std::endl; std::cerr << "[500] Server internal error: " << message; } diff --git a/mongoose/Session.h b/mongoose/Session.h index 183ffe7e91..a926f37e1a 100644 --- a/mongoose/Session.h +++ b/mongoose/Session.h @@ -70,7 +70,7 @@ namespace Mongoose Type get(const string& key, Type fallback = Type()) { TypeValue any = get(key); - if(any.empty()) + if( ! any.empty() ) return boost::any_cast(any); else return fallback; From 3a618425461e0540b37ae6feb6add3d314266740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Fri, 11 Dec 2015 10:11:20 -0300 Subject: [PATCH 14/17] Update Server.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resulve o problema de ficar travado quando não se starta e depois stopa --- mongoose/Server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mongoose/Server.cpp b/mongoose/Server.cpp index b5c4500102..11686b6901 100644 --- a/mongoose/Server.cpp +++ b/mongoose/Server.cpp @@ -77,7 +77,7 @@ namespace Mongoose Server::Server(int port, const char *documentRoot) : stopped(false), - destroyed(false), + destroyed(true), server(NULL) #ifndef NO_WEBSOCKET ,websockets(NULL) From 0590df289f6b9ae1115141db67927a3aacc38bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Wed, 16 Dec 2015 17:36:37 -0300 Subject: [PATCH 15/17] =?UTF-8?q?pega=20variavel=20tambem=20do=20cabe?= =?UTF-8?q?=C3=A7alho?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mongoose/Request.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mongoose/Request.cpp b/mongoose/Request.cpp index 040825a4e6..ef63e03e33 100644 --- a/mongoose/Request.cpp +++ b/mongoose/Request.cpp @@ -212,6 +212,19 @@ namespace Mongoose return output; } + // Looking on the header + output = mg_get_header(this->connection, "Referer"); + stringstream ss(output.substr(output.find('?')+1)); + string param; + while(std::getline(ss, param, '&')){ //block for '&' + const size_t& delimitPos = param.find('='); + const string& name = param.substr(0, delimitPos); + if(name == key){ + const string& value = param.substr(delimitPos+1); + return value; + } + } + return fallback; } From 2b457fc6fdd2351ef59bc721242329613c757e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Mon, 22 Feb 2016 15:50:22 -0300 Subject: [PATCH 16/17] update CMAKE_CXX_FLAGS --- CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4038cb563..3f33dde989 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ endif (ENABLE_STATS) if (ENABLE_REGEX_URL) add_definitions("-DENABLE_REGEX_URL") - SET (CMAKE_CXX_FLAGS "-std=c++11") + SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") endif (ENABLE_REGEX_URL) if (ENABLE_SESSION_BOOST_ANY) @@ -53,8 +53,6 @@ if (ENABLE_SESSION_BOOST_ANY) add_definitions("-DENABLE_SESSION_BOOST_ANY") endif (ENABLE_SESSION_BOOST_ANY) -SET (CMAKE_CXX_FLAGS "-g") - if (CPP_BINDING) set (SOURCES ${SOURCES} From c83133bec03e41a29d5269af5c639edc01c21550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Mon, 22 Feb 2016 21:03:52 -0300 Subject: [PATCH 17/17] get referer return null, verify if null --- mongoose/Request.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mongoose/Request.cpp b/mongoose/Request.cpp index ef63e03e33..b9b7b7e02c 100644 --- a/mongoose/Request.cpp +++ b/mongoose/Request.cpp @@ -213,15 +213,18 @@ namespace Mongoose } // Looking on the header - output = mg_get_header(this->connection, "Referer"); - stringstream ss(output.substr(output.find('?')+1)); - string param; - while(std::getline(ss, param, '&')){ //block for '&' - const size_t& delimitPos = param.find('='); - const string& name = param.substr(0, delimitPos); - if(name == key){ - const string& value = param.substr(delimitPos+1); - return value; + const char* referer = mg_get_header(this->connection, "Referer"); + if(referer){ + output = referer; + stringstream ss(output.substr(output.find('?')+1)); + string param; + while(std::getline(ss, param, '&')){ //block for '&' + const size_t& delimitPos = param.find('='); + const string& name = param.substr(0, delimitPos); + if(name == key){ + const string& value = param.substr(delimitPos+1); + return value; + } } }