diff --git a/jinhokim/Makefile b/jinhokim/Makefile
index 429f153..32aa5f8 100644
--- a/jinhokim/Makefile
+++ b/jinhokim/Makefile
@@ -1,39 +1,85 @@
-CC = c++
+# Define the compiler and flags
-CFLAGS = -std=c++98 -Wall -Wextra -Werror -pedantic
+CXX := c++
+CXXFLAGS := -Wall -Wextra -Werror -std=c++98 -pedantic -march=native -O2 -pipe
-GREEN = \033[32m
-YELLOW = \033[33m
-RESET = \033[0m
+# Define the directories
-SERVER_SRCS = src/Server.cpp \
- src/server_main.cpp
+SRC_DIR := src
+BUILD_DIR := build
+INC_DIR := include
-CLIENT_SRCS = src/Client.cpp \
- src/client_main.cpp
+# Define the source files
-all: server client
+SERVER_SRCS := $(addprefix $(SRC_DIR)/, server_main.cpp Server.cpp Response.cpp)
+CLIENT_SRCS := $(addprefix $(SRC_DIR)/, client_main.cpp Client.cpp)
+SERVER_OBJS := $(patsubst %.cpp, $(BUILD_DIR)/%.o, $(SERVER_SRCS))
+CLIENT_OBJS := $(patsubst %.cpp, $(BUILD_DIR)/%.o, $(CLIENT_SRCS))
+DEPS := $(patsubst %.cpp, $(BUILD_DIR)/%.d, $(SERVER_SRCS) $(CLIENT_SRCS))
-server:
- @echo "$(YELLOW)Building $@...$(RESET)"
- @$(CC) $(SERVER_SRCS) $(CFLAGS) -o $@ $<
- @echo "$(GREEN)Done.$(RESET)"
+# Define the variables for progress bar
-client:
- @echo "$(YELLOW)Building $@...$(RESET)"
- @$(CC) $(CLIENT_SRCS) $(CFLAGS) -o $@ $<
- @echo "$(GREEN)Done.$(RESET)"
+TOTAL_FILES := $(shell find $(SRC_DIR) -type f -name '*.cpp' | wc -l)
+COMPILED_FILES := 0
+STEP := 100
+
+# Define the name
+
+SERVER := server
+CLIENT := client
+
+# Define the rules
+
+all:
+ @$(MAKE) -j $(SERVER)
+ @$(MAKE) -j $(CLIENT)
+
+$(SERVER) : $(SERVER_OBJS)
+ @$(CXX) $(CXXFLAGS) $^ -o $@
+ @printf "\n$(MAGENTA)[WEBSERV] Linking SERVER Success\n$(DEF_COLOR)"
+
+$(CLIENT) : $(CLIENT_OBJS)
+ @$(CXX) $(CXXFLAGS) $^ -o $@
+ @printf "\n$(MAGENTA)[WEBSERV] Linking CLIENT Success\n$(DEF_COLOR)"
+
+$(BUILD_DIR)/%.o : %.cpp | dir_guard
+ @$(CXX) $(CXXFLAGS) -I $(INC_DIR) -c $^ -o $@
+ $(eval COMPILED_FILES = $(shell expr $(COMPILED_FILES) + 1))
+ $(eval PROGRESS = $(shell expr $(COMPILED_FILES) "*" $(STEP) / $(TOTAL_FILES)))
+ @printf " \r"
+ @printf "$(YELLOW)[WEBSERV] [%02d/%02d] ( %3d %%) Compiling $<\r$(DEF_COLOR)" $(COMPILED_FILES) $(TOTAL_FILES) $(PROGRESS)
+
+dir_guard:
+ @mkdir -p $(addprefix $(BUILD_DIR)/, $(SRC_DIR))
clean:
- @echo "$(YELLOW)Cleaning up...$(RESET)"
- @echo "$(GREEN)Done.$(RESET)"
+ @$(RM) -r $(BUILD_DIR)
+ @printf "$(BLUE)[WEBSERV]:\tobj. dep. files$(DEF_COLOR)$(GREEN) => Cleaned!\n$(DEF_COLOR)"
+
+fclean: clean
+ @$(RM) $(SERVER) $(CLIENT)
+ @printf "$(CYAN)[WEBSERV]:\texec. files$(DEF_COLOR)$(GREEN) => Cleaned!\n$(DEF_COLOR)"
+
+re: fclean
+ @$(MAKE) all
+ @printf "$(GREEN)[WEBSERV]Cleaned and Rebuilt everything\n$(DEF_COLOR)"
+
+.PHONY: all clean fclean re dir_guard norm
+
+norm:
+ @(norminette | grep Error) || (printf "$(GREEN)[WEBSERV]:\tNorminette Success\n$(DEF_COLOR)")
-fclean:
- make clean
- @rm -f server client
+# Colors
-re:
- make fclean
- make all
+RESET = \033[1;39m
+YELLOW = \033[1;33m
+GRAY = \033[1;90m
+RED = \033[1;91m
+GREEN = \033[1;92m
+YELLOW = \033[1;93m
+BLUE = \033[1;94m
+MAGENTA = \033[1;95m
+CYAN = \033[1;96m
+WHITE = \033[1;97m
-.PHONY: all clean fclean re
+-include $(DEPS)
diff --git a/jinhokim/favicon.ico b/jinhokim/favicon.ico
new file mode 100644
index 0000000..e69de29
diff --git a/jinhokim/html/200.png b/jinhokim/html/200.png
new file mode 100644
index 0000000..504bd49
Binary files /dev/null and b/jinhokim/html/200.png differ
diff --git a/jinhokim/html/404.html b/jinhokim/html/404.html
new file mode 100644
index 0000000..5651299
--- /dev/null
+++ b/jinhokim/html/404.html
@@ -0,0 +1,14 @@
+
+
+
+ 404 Status Page
+
+
+
+
+
404 Not Found
+ 404 cat
+
+
+
+
\ No newline at end of file
diff --git a/jinhokim/html/404.png b/jinhokim/html/404.png
new file mode 100644
index 0000000..beab571
Binary files /dev/null and b/jinhokim/html/404.png differ
diff --git a/jinhokim/html/500.html b/jinhokim/html/500.html
new file mode 100644
index 0000000..a24f305
--- /dev/null
+++ b/jinhokim/html/500.html
@@ -0,0 +1,14 @@
+
+
+
+ 500 Status Page
+
+
+
+
+
500 Internal Server Error
+ 500 cat
+
+
+
+
\ No newline at end of file
diff --git a/jinhokim/html/500.png b/jinhokim/html/500.png
new file mode 100644
index 0000000..266681f
Binary files /dev/null and b/jinhokim/html/500.png differ
diff --git a/jinhokim/html/index.html b/jinhokim/html/index.html
new file mode 100644
index 0000000..1fb1d41
--- /dev/null
+++ b/jinhokim/html/index.html
@@ -0,0 +1,15 @@
+
+
+
+ 200 Status Page
+
+
+
+
+
Webserv...
+ 200 cat
+
+
+
+
+
\ No newline at end of file
diff --git a/jinhokim/include/Client.hpp b/jinhokim/include/Client.hpp
index 7d4734a..e9df367 100644
--- a/jinhokim/include/Client.hpp
+++ b/jinhokim/include/Client.hpp
@@ -1,28 +1,28 @@
#ifndef CLIENT_HPP
-# define CLIENT_HPP
+#define CLIENT_HPP
-# include
-# include
-# include
-# include
-# include
-# include
-# include
+#include
+#include
+#include
+
+#include
class Client {
- public:
- Client(int port);
- virtual ~Client(void);
+ public:
+ Client(int port);
+ virtual ~Client(void);
+
+ int Set(void);
+ int Run(void);
- int Set(void);
- int Run(void);
- private:
- const int port_;
- int client_fd_;
- sockaddr_in server_address_;
- std::string response_;
+ private:
+ const int port_;
+ int client_fd_;
+ sockaddr_in server_address_;
+ std::string response_;
};
+void CheckArgument(int ac, char** av);
int PrintError(const std::string str);
#endif // CLIENT_HPP
diff --git a/jinhokim/include/Response.hpp b/jinhokim/include/Response.hpp
new file mode 100644
index 0000000..c05b9cb
--- /dev/null
+++ b/jinhokim/include/Response.hpp
@@ -0,0 +1,33 @@
+#ifndef RESPONSE_HPP
+#define RESPONSE_HPP
+
+#include
+#include
+#include
+
+#include
+
+#define BUFSIZE 10240
+
+class Response {
+ public:
+ Response(char *request);
+ ~Response(void);
+
+ void ResponseHandler(void);
+ std::string FindMime(std::string uri);
+ void FillHeader(int status, long len, std::string type);
+ void Handle200(int ct_len, const char *local_uri);
+ void Handle404(void);
+ void Handle500(void);
+
+ void ComposeResponse(int status, const char *status_text, int len,
+ std::string type);
+ std::string GetResponse(void);
+
+ private:
+ std::string request_;
+ std::string response_;
+};
+
+#endif // RESPONSE_HPP
diff --git a/jinhokim/include/Server.hpp b/jinhokim/include/Server.hpp
index 7369135..fffbab3 100644
--- a/jinhokim/include/Server.hpp
+++ b/jinhokim/include/Server.hpp
@@ -1,56 +1,43 @@
#ifndef SERVER_HPP
-# define SERVER_HPP
-
-# include
-# include
-# include