Skip to content

Commit

Permalink
[Clean] Define in Common & Remove unused classes and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
unkn0wn107 committed Jul 22, 2024
1 parent 25499f0 commit 3076ea3
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 225 deletions.
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: agaley <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/15 15:51:13 by agaley #+# #+# #
# Updated: 2024/07/16 21:45:32 by mchenava ### ########.fr #
# Updated: 2024/07/22 18:45:13 by agaley ### ########lyon.fr #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -37,10 +37,9 @@ SRC = $(SRC_DIR)/Server.cpp \
$(SRC_DIR)/ConnectionHandler.cpp $(SRC_DIR)/CacheHandler.cpp \
$(SRC_DIR)/Worker.cpp $(SRC_DIR)/EventQueue.cpp $(SRC_DIR)/EventData.cpp \
$(SRC_DIR)/HTTPRequest.cpp $(SRC_DIR)/HTTPResponse.cpp $(SRC_DIR)/URI.cpp \
$(SRC_DIR)/CGIHandler.cpp \
$(SRC_DIR)/VirtualServer.cpp $(SRC_DIR)/Common.cpp \
$(SRC_DIR)/CGIHandler.cpp $(SRC_DIR)/VirtualServer.cpp \
$(SRC_DIR)/Exception.cpp $(SRC_DIR)/HTTPMethods.cpp \
$(SRC_DIR)/ErrorHandler.cpp $(SRC_DIR)/Logger.cpp $(SRC_DIR)/Utils.cpp \
$(SRC_DIR)/Logger.cpp $(SRC_DIR)/Utils.cpp \
$(SRC_DIR)/main.cpp

OBJ = $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC))
Expand Down
5 changes: 1 addition & 4 deletions src/CGIHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: agaley <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 16:11:09 by agaley #+# #+# */
/* Updated: 2024/07/22 18:07:41 by agaley ### ########lyon.fr */
/* Updated: 2024/07/22 18:38:46 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand All @@ -30,9 +30,6 @@
#include "Logger.hpp"

class CacheHandler;

#define CGI_TIMEOUT_SEC 10

struct EventData;

class CGIHandler {
Expand Down
49 changes: 0 additions & 49 deletions src/Common.cpp

This file was deleted.

19 changes: 9 additions & 10 deletions src/Common.hpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
#ifndef COMMON_HPP
#define COMMON_HPP

#include <fcntl.h>
#include <string>
#include "Config.hpp"
#include <ctime>

#define LOG_LEVEL_NONE 0
#define LOG_LEVEL_ERROR 1
#define LOG_LEVEL_WARNING 2
#define LOG_LEVEL_INFO 3

#define LOG_LEVEL LOG_LEVEL_INFO
#define LOG_FILE_PATH "./logs/"
#define LOG_FILE_NAME "webserv"
#define LOG_FILE_EXT ".log"

int set_non_blocking(int sockfd);
void signalHandler(int signum);
std::string generateSessionId(void);
#define MAX_TRIES 10
#define TIMEOUT 10
#define BUFFER_SIZE 16384
#define MAX_EVENTS 1024
#define SHUTDOWN_DELAY 200000

enum ConnectionStatus { READING, EXECUTING, CACHE_WAITING, SENDING, CLOSED };

enum CGIState {
NONE,
INIT,
CACHE_CHECK,
REGISTER_SCRIPT_FD,
RUN_SCRIPT,
SCRIPT_RUNNING,
READ_FROM_CGI,
PROCESS_OUTPUT,
FINALIZE_RESPONSE,
ADD_HEADERS,
DONE,
CGI_ERROR,
};
Expand Down
6 changes: 2 additions & 4 deletions src/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* Config.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mchenava <mchenava@student.42.fr> +#+ +:+ +#+ */
/* By: agaley <agaley@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 16:53:47 by mchenava #+# #+# */
/* Updated: 2024/06/28 14:09:26 by mchenava ### ########.fr */
/* Updated: 2024/07/22 18:40:33 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,8 +19,6 @@
#include <string>
#include <vector>

#define BUFFER_SIZE 16384

typedef struct LocationConfig {
std::string location;

Expand Down
5 changes: 1 addition & 4 deletions src/ConfigManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: agaley <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 16:11:17 by agaley #+# #+# */
/* Updated: 2024/07/02 23:48:35 by agaley ### ########lyon.fr */
/* Updated: 2024/07/22 18:30:08 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -38,9 +38,6 @@ class ConfigManager {
* @return The configuration object.
*/
Config& getConfig();
ServerConfig& getServerConfig();
const LocationConfig& getLocationConfig() const;
ListenConfig& getListenConfig();
static void printConfig();

static void loadConfig(const std::string& filepath);
Expand Down
5 changes: 1 addition & 4 deletions src/ConnectionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: agaley <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 16:11:21 by agaley #+# #+# */
/* Updated: 2024/07/22 18:03:18 by agaley ### ########lyon.fr */
/* Updated: 2024/07/22 18:38:01 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand All @@ -19,9 +19,6 @@
#include "ConnectionHandler.hpp"
#include "Utils.hpp"

const int ConnectionHandler::MAX_TRIES = 10;
const time_t ConnectionHandler::TIMEOUT = 10;

ConnectionHandler::ConnectionHandler(int clientSocket,
int epollSocket,
std::vector<VirtualServer*>& virtualServers,
Expand Down
6 changes: 1 addition & 5 deletions src/ConnectionHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: agaley <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 16:11:25 by agaley #+# #+# */
/* Updated: 2024/07/22 17:48:56 by agaley ### ########lyon.fr */
/* Updated: 2024/07/22 18:41:27 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand All @@ -29,8 +29,6 @@
#include "Logger.hpp"
#include "VirtualServer.hpp"

#define BUFFER_SIZE 16384

class VirtualServer;
class CGIHandler;

Expand All @@ -40,8 +38,6 @@ class ConnectionHandler {
std::string getStatusString() const;
int processConnection(struct epoll_event& event);
void setInternalServerError();
static const int MAX_TRIES;
static const time_t TIMEOUT;

ConnectionHandler(int clientSocket,
int epollSocket,
Expand Down
28 changes: 0 additions & 28 deletions src/ErrorHandler.cpp

This file was deleted.

46 changes: 0 additions & 46 deletions src/ErrorHandler.hpp

This file was deleted.

6 changes: 3 additions & 3 deletions src/HTTPRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* HTTPRequest.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mchenava <mchenava@student.42.fr> +#+ +:+ +#+ */
/* By: agaley <agaley@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/30 16:10:58 by agaley #+# #+# */
/* Updated: 2024/06/28 11:03:30 by mchenava ### ########.fr */
/* Updated: 2024/07/22 18:35:42 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -67,7 +67,7 @@ void HTTPRequest::_parseSession() {
sessionId = cookieHeader.substr(pos + 10, endPos - pos - 10);
}
if (sessionId.empty())
sessionId = generateSessionId();
sessionId = Utils::generateSessionId();
setSessionId(sessionId);
}

Expand Down
32 changes: 0 additions & 32 deletions src/Handler.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions src/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: agaley <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 13:21:59 by mchenava #+# #+# */
/* Updated: 2024/07/03 01:10:15 by agaley ### ########lyon.fr */
/* Updated: 2024/07/22 18:42:12 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand All @@ -22,10 +22,6 @@

#include "Config.hpp"

#define LOG_FILE_PATH "./logs/"
#define LOG_FILE_NAME "webserv"
#define LOG_FILE_EXT ".log"

class Logger {
public:
static Logger& getInstance();
Expand Down
4 changes: 2 additions & 2 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: agaley <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/28 15:34:02 by agaley #+# #+# */
/* Updated: 2024/07/04 20:47:08 by agaley ### ########lyon.fr */
/* Updated: 2024/07/22 18:35:10 by agaley ### ########lyon.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -215,7 +215,7 @@ void Server::_setupServerSockets() {
continue;
}

if (set_non_blocking(sock) < 0) {
if (Utils::set_non_blocking(sock) < 0) {
_log.error("(" + listenConfig.address + ":" + Utils::to_string(listenConfig.port) +
") Failed to set socket to non-blocking");
close(sock);
Expand Down
Loading

0 comments on commit 3076ea3

Please sign in to comment.