Skip to content

Commit

Permalink
Merge pull request #46 from samih713/main
Browse files Browse the repository at this point in the history
Updating kqueue
  • Loading branch information
Taanviir authored Apr 16, 2024
2 parents 2fe5b48 + b3438ce commit 0fb6196
Show file tree
Hide file tree
Showing 35 changed files with 131 additions and 133 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/compile-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ name: Compilation Check
on:
push:
branches:
- main
- server/*
- conf-parser
- CGI-Parser
- handle_connection
- parsing
- '**'

jobs:
build-linux:
Expand Down
16 changes: 4 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ NAME:= webserv

### MODULES & INCLUDES ###
MODULES:= $(PARSER_DIR) $(HTTP_DIR) $(SERVER_DIR) $(CGI_DIR)
INCLUDES:= -I./includes/ $(patsubst %,-I./%,$(MODULES))
SUB_DIRS:= $(shell find $(SRCS_DIR) -type d -name $(TESTS_DIR) -prune -o -type d -print)
INCLUDES:= -I./includes/ $(patsubst %,-I./%,$(MODULES)) $(patsubst %,-I./%,$(SUB_DIRS))

### SOURCES ###
SRCS:= $(SRCS_DIR)/main.cpp

### OBJECTS & SUBDIRS ###
include $(patsubst %,%/module.mk,$(MODULES))
OBJS += $(patsubst $(SRCS_DIR)%.cpp,$(OBJS_DIR)%.o,$(SRCS))
SUB_DIRS:= $(patsubst $(SRCS_DIR)%,$(OBJS_DIR)%,$(shell find $(SRCS_DIR) -type d))

all: $(NAME)

Expand All @@ -56,7 +56,7 @@ $(OBJS_DIR)/%.o: $(SRCS_DIR)/%.cpp | $(OBJS_DIR)
@echo "$(GREEN)[ COMPILE ]$(RESET) $<."

$(OBJS_DIR):
@mkdir -p $@ $(SUB_DIRS)
@mkdir -p $@ $(patsubst $(SRCS_DIR)%,$(OBJS_DIR)%,$(SUB_DIRS))

run: re
./$(NAME) configs/webserv.conf
Expand Down Expand Up @@ -90,7 +90,7 @@ test_parser:
@echo "$(BLUE)[ TEST ]$(RESET) Parser ready for testing."

test_http:
@$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEBUGFLAGS) $(HTTP_SRCS) $(TEST_HTTP_SRC) -o $(TEST_HTTP)
@$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEBUGFLAGS) $(CGI_SRCS) $(HTTP_SRCS) $(TEST_HTTP_SRC) -o $(TEST_HTTP)
@echo "$(BLUE)[ TEST ]$(RESET) HTTP ready for testing."

#! SOCKET_main.cpp has a compile error so this test has been commented out
Expand All @@ -103,14 +103,6 @@ test_cgi:
@$(CXX) $(CXXFLAGS) $(INCLUDES) $(DEBUGFLAGS) $(SANITIZE) $(HTTP_SRCS) $(CGI_SRCS) $(TEST_CGI_SRC) -o $(TEST_CGI)
@echo "$(BLUE)[ TEST ]$(RESET) CGI ready for testing."

format:
@echo "$(BLUE)[ FORMAT ]$(RESET) Formatting code..."
@find ./$(SRCS_DIR) -name "*.cpp" -o -name "*.hpp" \
-exec clang-format -i {} +
@find ./includes -name "*.hpp" \
-exec clang-format -i {} +
@echo "$(BLUE)[ FORMAT ]$(RESET) Code has been formatted."

-include $(OBJS:.o=.d)

.PHONY: clean fclean all re debug run test_parser test_http test_socket test_cgi
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# webserv

### References:
- [Why Recursive Makefiles Are Harmful](https://accu.org/journals/overload/14/71/miller_2004/)
7 changes: 7 additions & 0 deletions includes/webserv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ typedef vector<pair<string, string> > vsp;
// socket_descriptor type
typedef int fd;
/* ----------------------------- ERROR MESSAGES ----------------------------- */
#define THROW_EXCEPTION_WITH_INFO(msg) \
do { \
std::ostringstream oss; \
oss << __FILE__ << ":" << __LINE__ << ": " << R << "error: " << RE << (msg); \
throw std::runtime_error(oss.str()); \
} while (0)

static std::string ERR_NULL("Socket: null ptr error");
static std::string ERR_CREAT("Socket: creation failed");
static std::string ERR_BIND("Socket: binding failed");
Expand Down
2 changes: 1 addition & 1 deletion sources/CGI/.tests/test_cgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// # include <sys/stat.h>
// # include <sys/wait.h>
// # include <stdexcept>
#include "../Cgi.hpp"
#include "Cgi.hpp"


//using namespace webserv::http;
Expand Down
3 changes: 1 addition & 2 deletions sources/CGI/Cgi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
#ifndef CGI_HPP
#define CGI_HPP

//#include "../../includes/webserv.hpp"
#include <iostream>
#include <cstring>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "webserv.hpp"
#include "../sources/http/request/Request.hpp"
#include "Request.hpp"

class Cgi {
public:
Expand Down
6 changes: 3 additions & 3 deletions sources/http/.tests/test_http.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../request/Request.hpp"
#include "../response/Response.hpp"
#include "../includes/webserv.hpp"
#include "Request.hpp"
#include "Response.hpp"
#include "webserv.hpp"

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion sources/http/FileType.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../includes/webserv.hpp"
#include "webserv.hpp"

#ifndef FILETYPE_HPP
#define FILETYPE_HPP
Expand Down
2 changes: 1 addition & 1 deletion sources/http/FindHeaderKey.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../includes/webserv.hpp"
#include "webserv.hpp"

#ifndef FINDHEADERKEY_HPP
#define FINDHEADERKEY_HPP
Expand Down
2 changes: 1 addition & 1 deletion sources/http/Message.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../../includes/webserv.hpp"
#include "webserv.hpp"

#ifndef MESSAGE_HPP
#define MESSAGE_HPP
Expand Down
8 changes: 4 additions & 4 deletions sources/http/handler/GetRequestHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "./GetRequestHandler.hpp"
#include "../../../includes/debug.hpp"
#include "../FileType.hpp"
#include "../server/CachedPages.hpp"
#include "GetRequestHandler.hpp"
#include "debug.hpp"
#include "FileType.hpp"
#include "CachedPages.hpp"

GetRequestHandler::GetRequestHandler()
{
Expand Down
10 changes: 5 additions & 5 deletions sources/http/handler/GetRequestHandler.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "../request/Request.hpp"
#include "./RequestHandlerBase.hpp"
#include "../response/Response.hpp"
#include "../../server/Server.hpp"
#include "../../../includes/webserv.hpp"
#include "Request.hpp"
#include "RequestHandlerBase.hpp"
#include "Response.hpp"
#include "Server.hpp"
#include "webserv.hpp"

#ifndef GETREQUESTHANDLER_HPP
#define GETREQUESTHANDLER_HPP
Expand Down
4 changes: 2 additions & 2 deletions sources/http/handler/IRequestHandler.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "../response/Response.hpp"
#include "../../server/Server.hpp"
#include "Response.hpp"
#include "Server.hpp"

#ifndef IRequestHandler_HPP
#define IRequestHandler_HPP
Expand Down
2 changes: 1 addition & 1 deletion sources/http/handler/RequestHandlerBase.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "./IRequestHandler.hpp"
#include "IRequestHandler.hpp"

#ifndef REQUESTHANDLERBASE_HPP
#define REQUESTHANDLERBASE_HPP
Expand Down
8 changes: 4 additions & 4 deletions sources/http/handler/RequestHandlerFactory.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../FindHeaderKey.hpp"
#include "./GetRequestHandler.hpp"
#include "./IRequestHandler.hpp"
#include "FindHeaderKey.hpp"
#include "GetRequestHandler.hpp"
#include "IRequestHandler.hpp"

#ifndef REQUESTHANDLERFACTORY_HPP
#define REQUESTHANDLERFACTORY_HPP
Expand All @@ -20,7 +20,7 @@ class RequestHandlerFactory
switch (m)
{
case GET: return new GetRequestHandler;
default: throw runtime_error("Request Method not implemented\n");
default: THROW_EXCEPTION_WITH_INFO("Request Method not implemented\n");
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions sources/http/request/Request.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "./Request.hpp"
#include "../../../includes/debug.hpp"
#include "../../../includes/enum_utils.hpp"
#include "Request.hpp"
#include "debug.hpp"
#include "enum_utils.hpp"

Request::Request(const string &rawRequest)
: rawRequest(rawRequest)
Expand All @@ -11,7 +11,7 @@ Request::Request(const string &rawRequest)
}
catch (std::ios_base::failure &f)
{
throw runtime_error("Invalid request\n");
THROW_EXCEPTION_WITH_INFO("Invalid request\n");
}
}

Expand Down
4 changes: 2 additions & 2 deletions sources/http/request/Request.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "../Message.hpp"
#include "../../../includes/webserv.hpp"
#include "Message.hpp"
#include "webserv.hpp"

#ifndef REQUEST_HPP
#define REQUEST_HPP
Expand Down
6 changes: 3 additions & 3 deletions sources/http/request/parse_request.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../Message.hpp"
#include "./Request.hpp"
#include "../../../includes/enum_utils.hpp"
#include "Message.hpp"
#include "Request.hpp"
#include "enum_utils.hpp"

// defining the char * array
#define X(a) ws_tostr(a), // stringify the enum
Expand Down
8 changes: 4 additions & 4 deletions sources/http/response/Response.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Response.hpp"
#include "../../../includes/debug.hpp"
#include "../../../includes/enum_utils.hpp"
#include "../../server/Server.hpp"
#include "debug.hpp"
#include "enum_utils.hpp"
#include "Server.hpp"

/**
* This constant string represents the HTTP version "HTTP/1.1" that is used in the
Expand Down Expand Up @@ -115,7 +115,7 @@ void Response::send_response(fd recv_socket) const
{
result = send(recv_socket, &message[bytesSent], message.size() - bytesSent, 0);
if (result == -1)
throw runtime_error(ERR_SEND_FAIL + strerror(errno));
THROW_EXCEPTION_WITH_INFO(ERR_SEND_FAIL + strerror(errno));
bytesSent += result;
}
}
Expand Down
6 changes: 3 additions & 3 deletions sources/http/response/Response.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../../../includes/webserv.hpp"
#include "../Message.hpp"
#include "../request/Request.hpp"
#include "webserv.hpp"
#include "Message.hpp"
#include "Request.hpp"

#ifndef RESPONSE_HPP
#define RESPONSE_HPP
Expand Down
17 changes: 9 additions & 8 deletions sources/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "./server/Server.hpp"
#include "./parser/ConfigParser.hpp"
#include "./server/ServerConfig.hpp"
#include "../includes/webserv.hpp"
#include "Server.hpp"
#include "ConfigParser.hpp"
#include "ServerConfig.hpp"
#include "webserv.hpp"

int main(int argc, char **argv) {
if (argc > 2) {
std::cerr << "Usage: " << argv[0] << " [<config_file>]" << std::endl;
if (argc > 2)
{
cerr << "Usage: " << argv[0] << " [<config_file>]" << endl;
exit(1);
}

Expand All @@ -18,8 +19,8 @@ int main(int argc, char **argv) {
Server &webserv = Server::get_instance(configs[0], 10);
webserv.start(SELECT);
}
catch (std::exception &e)
catch (std::exception &error)
{
std::cerr << e.what();
cerr << error.what() << endl;
}
}
2 changes: 1 addition & 1 deletion sources/parser/.tests/test_parser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../ConfigParser.hpp"
#include "ConfigParser.hpp"

int main(int argc, char **argv) {
if (argc != 2) {
Expand Down
Loading

0 comments on commit 0fb6196

Please sign in to comment.