Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No "using namespace" in headers #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions mongoose/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include "WebSocket.h"
#include "Sessions.h"

using namespace std;

#define addRoute(httpMethod, url, controllerType, method) \
registerRoute(httpMethod, url, new RequestHandler<controllerType, StreamResponse>(this, &controllerType::method ));

Expand Down Expand Up @@ -82,7 +80,7 @@ namespace Mongoose
*
* @param string the prefix of all urls for this controller
*/
void setPrefix(string prefix);
void setPrefix(std::string prefix);

/**
* Called when a new websocket connection is ready
Expand All @@ -97,15 +95,15 @@ namespace Mongoose
* @param WebSocket the instance of the connection
* @param string the data arriving
*/
virtual void webSocketData(WebSocket *websocket, string data);
virtual void webSocketData(WebSocket *websocket, std::string data);

/**
* Registers a route to the controller
*
* @param string the route path
* @param RequestHandlerBase the request handler for this route
*/
virtual void registerRoute(string httpMethod, string route, RequestHandlerBase *handler);
virtual void registerRoute(std::string httpMethod, std::string route, RequestHandlerBase *handler);

/**
* Initializes the route and settings
Expand All @@ -124,7 +122,7 @@ namespace Mongoose
*
* @return response a response to send, 404 will occur if NULL
*/
virtual Response *serverInternalError(string message);
virtual Response *serverInternalError(std::string message);

/**
* Gets the session for a request/response
Expand All @@ -143,15 +141,15 @@ namespace Mongoose
*/
void setSessions(Sessions *sessions);

virtual bool handles(string method, string url);
vector<string> getUrls();
virtual bool handles(std::string method, std::string url);
std::vector<std::string> getUrls();

protected:
Sessions *sessions;
Server *server;
string prefix;
map<string, RequestHandlerBase*> routes;
vector<string> urls;
std::string prefix;
std::map<std::string, RequestHandlerBase*> routes;
std::vector<std::string> urls;
};
}

Expand Down
2 changes: 0 additions & 2 deletions mongoose/JsonController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "WebController.h"
#include "JsonResponse.h"

using namespace std;

/**
* A json controller is a controller that serves JSON API
*/
Expand Down
4 changes: 1 addition & 3 deletions mongoose/JsonResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#include "Response.h"

using namespace std;

/**
* A stream response to a request
*/
Expand All @@ -25,7 +23,7 @@ namespace Mongoose
*
* @return string the response body
*/
virtual string getBody();
virtual std::string getBody();

/**
* Sets the human readability of the response
Expand Down
32 changes: 15 additions & 17 deletions mongoose/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "UploadFile.h"
#include "Response.h"

using namespace std;

/**
* Request is a wrapper for the clients requests
*/
Expand All @@ -37,15 +35,15 @@ namespace Mongoose
*
* @return bool true if the param is present, false else
*/
bool hasVariable(string key);
bool hasVariable(std::string key);

/**
* Get All variable present in GET or POST data
*
* @brief getAllVariable
* @return map<string, string> with all variables
*/
map<string, string> getAllVariable();
std::map<std::string, std::string> getAllVariable();

/**
* Get the value for a certain variable
Expand All @@ -55,7 +53,7 @@ namespace Mongoose
*
* @return string the value of the variable if it exists, fallback else
*/
string get(string key, string fallback = "");
std::string get(std::string key, std::string fallback = "");

/**
* Checks if the given cookie exists
Expand All @@ -64,7 +62,7 @@ namespace Mongoose
*
* @return bool true if the given cookie is set
*/
bool hasCookie(string key);
bool hasCookie(std::string key);

/**
* Try to get the cookie value
Expand All @@ -74,10 +72,10 @@ namespace Mongoose
*
* @retun the value of the cookie if it exists, fallback else
*/
string getCookie(string key, string fallback = "");
std::string getCookie(std::string key, std::string fallback = "");


string getHeaderKeyValue(const std::string& header_key);
std::string getHeaderKeyValue(const std::string& header_key);

/**
* Handle uploads to the target directory
Expand All @@ -87,25 +85,25 @@ namespace Mongoose
*/
void handleUploads();

string getUrl();
string getMethod();
string getData();
std::string getUrl();
std::string getMethod();
std::string getData();

#ifdef ENABLE_REGEX_URL
smatch getMatches();
bool match(string pattern);
bool match(std::string pattern);
#endif
bool readVariable(const char *data, string key, string &output);
bool readVariable(const char *data, std::string key, std::string &output);

/**
* Files uploaded in this request
*/
vector<UploadFile> uploadFiles;
std::vector<UploadFile> uploadFiles;

protected:
string method;
string url;
string data;
std::string method;
std::string url;
std::string data;
struct mg_connection *connection;
};
}
Expand Down
2 changes: 1 addition & 1 deletion mongoose/RequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Mongoose
try {
controller->preProcess(request, *response);
(controller->*function)(request, *response);
} catch (string exception) {
} catch (std::string exception) {
return controller->serverInternalError(exception);
} catch (...) {
return controller->serverInternalError("Unknown error");
Expand Down
16 changes: 7 additions & 9 deletions mongoose/Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
#define HTTP_FORBIDDEN 403
#define HTTP_SERVER_ERROR 500

using namespace std;

/**
* A response to a request
*/
namespace Mongoose
{
class Response
class Response
{
public:
Response();
Expand All @@ -30,7 +28,7 @@ namespace Mongoose
*
* @return bool true if the header is set
*/
virtual bool hasHeader(string key);
virtual bool hasHeader(std::string key);

/**
* Sets the header
Expand All @@ -39,22 +37,22 @@ namespace Mongoose
*
* @param value the header value
*/
virtual void setHeader(string key, string value);
virtual void setHeader(std::string key, std::string value);

/**
* Get the data of the response, this will contain headers and
* body
*
* @return string the response data
*/
virtual string getData();
virtual std::string getData();

/**
* Gets the response body
*
* @return string the response body
*/
virtual string getBody()=0;
virtual std::string getBody()=0;

/**
* Sets the cookie, note that you can only define one cookie by request
Expand All @@ -63,7 +61,7 @@ namespace Mongoose
* @param string the key of the cookie
* @param string value the cookie value
*/
virtual void setCookie(string key, string value);
virtual void setCookie(std::string key, std::string value);

/**
* Sets the response code
Expand All @@ -72,7 +70,7 @@ namespace Mongoose

protected:
int code;
map<string, string> headers;
std::map<std::string, std::string> headers;
};
}

Expand Down
14 changes: 6 additions & 8 deletions mongoose/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "Mutex.h"
#include "Sessions.h"

using namespace std;

/**
* Wrapper for the Mongoose server
*/
Expand Down Expand Up @@ -82,7 +80,7 @@ namespace Mongoose
*
* @return int if we have to keep the connection opened
*/
int _webSocketData(struct mg_connection *conn, string data);
int _webSocketData(struct mg_connection *conn, std::string data);

/**
* Process the request by controllers
Expand All @@ -100,7 +98,7 @@ namespace Mongoose
* @param string the name of the option
* @param string the value of the option
*/
void setOption(string key, string value);
void setOption(std::string key, std::string value);

#ifndef NO_WEBSOCKET
/**
Expand All @@ -124,22 +122,22 @@ namespace Mongoose
/**
* Does the server handles url?
*/
bool handles(string method, string url);
bool handles(std::string method, std::string url);

protected:
volatile bool stopped;
volatile bool destroyed;
Sessions sessions;
Mutex mutex;
map<string, string> optionsMap;
map<struct mg_connection*, Request *> currentRequests;
std::map<std::string, std::string> optionsMap;
std::map<struct mg_connection*, Request *> currentRequests;
struct mg_server *server;

#ifndef NO_WEBSOCKET
WebSockets websockets;
#endif

vector<Controller *> controllers;
std::vector<Controller *> controllers;

// Statistics
int requests;
Expand Down
14 changes: 6 additions & 8 deletions mongoose/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
#include <map>
#include "Mutex.h"

using namespace std;

/**
* A session contains the user specific values
*/
*/
namespace Mongoose
{
class Session
Expand All @@ -22,21 +20,21 @@ namespace Mongoose
* @param string the name of the variable
* @param string the value of the variable
*/
void setValue(string key, string value);
void setValue(std::string key, std::string value);

/**
* Unset a session varaible
*
* @param string the variable name
*/
void unsetValue(string key);
void unsetValue(std::string key);

/**
* Check if the given variable exists
*
* @param string the name of the variable
*/
bool hasValue(string key);
bool hasValue(std::string key);

/**
* Try to get the value for the given variable
Expand All @@ -46,7 +44,7 @@ namespace Mongoose
*
* @return string the value of the variable if it exists, fallback else
*/
string get(string key, string fallback = "");
std::string get(std::string key, std::string fallback = "");

/**
* Pings the session, this will update the creation date to now
Expand All @@ -62,7 +60,7 @@ namespace Mongoose
int getAge();

protected:
map<string, string> values;
std::map<std::string, std::string> values;
int date;
Mutex mutex;
};
Expand Down
Loading