update domo
This commit is contained in:
57
src/web/handler/exit-handler.cpp
Normal file
57
src/web/handler/exit-handler.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*!
|
||||
* web-server.cpp
|
||||
*
|
||||
* Copyright (c) 2015-2019, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* @Author: NADAL Jean-Baptiste
|
||||
* @Date: 14/11/2019
|
||||
*
|
||||
*/
|
||||
|
||||
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include "exit-handler.h"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn ExitHandler
|
||||
*
|
||||
* @brief Constructor of the Exit Handler
|
||||
*/
|
||||
ExitHandler::ExitHandler(struct event_base *an_evt_loop) : m_evt_loop(an_evt_loop)
|
||||
{
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn handleGet
|
||||
*
|
||||
* @brief Exit Handler HandleGet method
|
||||
*/
|
||||
bool ExitHandler::handleGet(CivetServer *a_server, struct mg_connection *a_conn)
|
||||
{
|
||||
mg_printf(a_conn,
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: "
|
||||
"text/plain\r\nConnection: close\r\n\r\n");
|
||||
mg_printf(a_conn, "Bye!\n");
|
||||
event_base_loopbreak(m_evt_loop);
|
||||
return true;
|
||||
}
|
||||
47
src/web/handler/exit-handler.h
Normal file
47
src/web/handler/exit-handler.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*!
|
||||
* web-server.h
|
||||
*
|
||||
* Copyright (c) 2015-2019, NADAL Jean-Baptiste. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*
|
||||
* @Author: NADAL Jean-Baptiste
|
||||
* @Date: 14/11/2019
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _EXIT_HANDLER_H
|
||||
#define _EXIT_HANDLER_H
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include "CivetServer.h"
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class ExitHandler : public CivetHandler
|
||||
{
|
||||
public:
|
||||
ExitHandler(struct event_base *an_evt_loop);
|
||||
bool handleGet(CivetServer *a_server, struct mg_connection *a_conn);
|
||||
|
||||
private:
|
||||
struct event_base *m_evt_loop;
|
||||
};
|
||||
|
||||
#endif /* _EXIT_HANDLER_H */
|
||||
@@ -23,17 +23,25 @@
|
||||
*
|
||||
*/
|
||||
|
||||
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include "CivetServer.h"
|
||||
|
||||
#include "web/handler/exit-handler.h"
|
||||
|
||||
#include "web-server.h"
|
||||
|
||||
#define EXIT_URI "/exit"
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn WebServer
|
||||
*
|
||||
* @brief Constructor of the Web Server Object.
|
||||
*/
|
||||
|
||||
WebServer::WebServer(void)
|
||||
WebServer::WebServer(void) : m_server(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -45,4 +53,26 @@ WebServer::WebServer(void)
|
||||
|
||||
WebServer::~WebServer(void)
|
||||
{
|
||||
delete m_server;
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn setup
|
||||
*
|
||||
* @brief Setup the Web server
|
||||
*/
|
||||
int WebServer::setup(const char *a_document_root, const char *a_port, struct event_base *an_evt_loop)
|
||||
{
|
||||
std::vector<std::string> the_options;
|
||||
|
||||
the_options.push_back("document_root");
|
||||
the_options.push_back(a_document_root);
|
||||
the_options.push_back("listening_ports");
|
||||
the_options.push_back(a_port);
|
||||
|
||||
m_server = new CivetServer(the_options);
|
||||
|
||||
m_server->addHandler(EXIT_URI, new ExitHandler(an_evt_loop));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -28,8 +28,13 @@
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
/*---------------------------------- Deps -----------------------------------*/
|
||||
|
||||
class CivetServer;
|
||||
struct event_base;
|
||||
|
||||
/*--------------------------------- CLASS ----------------------------------*/
|
||||
|
||||
class WebServer
|
||||
@@ -38,7 +43,10 @@ public:
|
||||
WebServer(void);
|
||||
~WebServer(void);
|
||||
|
||||
int setup(const char *a_document_root, const char *a_port, struct event_base *an_evt_loop);
|
||||
|
||||
private:
|
||||
CivetServer *m_server;
|
||||
};
|
||||
|
||||
#endif /* __WEB_SERVER_H */
|
||||
|
||||
Reference in New Issue
Block a user