diff --git a/Makefile b/Makefile
deleted file mode 100644
index b143ff1..0000000
--- a/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-NAME = Server
-SRCS = main.cpp parse_conf.cpp Classes.cpp
-
-OBJ = $(SRCS:.cpp=.o)
-
-CXXFLAGS = -Wall -Wextra -Werror -std=c++98 -fsanitize=address -g
-CXX = c++
-rm = rm -rf
-
-all : $(NAME)
-
-$(NAME): $(OBJ)
- $(CXX) $(CXXFLAGS) $(OBJ) -o $(NAME)
-
-clean:
- $(RM) $(OBJ)
-
-fclean: clean
- $(RM) $(NAME)
-
-re: fclean all
-
-.PHONY: re bonus clean fclean all
\ No newline at end of file
diff --git a/README.md b/README.md
index 7f9eea9..6813a02 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,3 @@
# 42_webserv
-Chere Lxu-Wu
-Si on termine pas ds une semaine, cela veut dire que tu as menti :)
-
-mushumartial
+ON VA LE FAIRE TODAY I FINISH CGI
diff --git a/a.out b/a.out
new file mode 100755
index 0000000..33f9eb6
Binary files /dev/null and b/a.out differ
diff --git a/a.out.dSYM/Contents/Info.plist b/a.out.dSYM/Contents/Info.plist
new file mode 100644
index 0000000..3679a65
--- /dev/null
+++ b/a.out.dSYM/Contents/Info.plist
@@ -0,0 +1,20 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ English
+ CFBundleIdentifier
+ com.apple.xcode.dsym.a.out
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundlePackageType
+ dSYM
+ CFBundleSignature
+ ????
+ CFBundleShortVersionString
+ 1.0
+ CFBundleVersion
+ 1
+
+
diff --git a/a.out.dSYM/Contents/Resources/DWARF/a.out b/a.out.dSYM/Contents/Resources/DWARF/a.out
new file mode 100644
index 0000000..03d0f7e
Binary files /dev/null and b/a.out.dSYM/Contents/Resources/DWARF/a.out differ
diff --git a/cgi.cpp b/cgi.cpp
new file mode 100644
index 0000000..262d328
--- /dev/null
+++ b/cgi.cpp
@@ -0,0 +1,208 @@
+#include "cgi.hpp"
+
+std::string fileExtent(std::string filePwd)
+{
+ size_t i = 0;
+
+ while (filePwd[i])
+ i++;
+ while(i && filePwd[i] != '.')
+ i--;
+ if (!strcmp(&filePwd[i], ".py"))
+ return "/usr/bin/python2.7";
+ if (!strcmp(&filePwd[i], ".pl"))
+ return "/usr/bin/perl";
+ return "";
+}
+
+std::string searchExec(std::string filePwd, char **envp)
+{
+ (void)envp;
+ std::string path;
+ std::string token;
+ std::string const exec = fileExtent(filePwd);
+
+ if (exec == "")
+ {
+ std::cerr << "uncompatible CGI-script" << std::endl;
+ return (0);
+ }
+
+ if (!access(exec.c_str(), X_OK))
+ return exec;
+ return (0);
+}
+
+std::vector newEnv(std::string filePwd, char **envp, Requete req)
+{
+ std::vector my_env;
+
+ size_t i = 0;
+
+ while (envp[i])
+ i++;
+
+ i = 0;
+ while (envp[i])
+ {
+ my_env.push_back(envp[i]);
+ i++;
+ }
+ my_env.push_back("CONTENT_TYPE=" + req.getType());
+ my_env.push_back("GATEWAY_INTERFACE=CGI/1.1");
+ // my_env.push_back("PATH_TRANSLATED=" + req.getPath());
+ // my_env.push_back("QUERY_STRING=" + req.getQS);//getQS pour querry string
+ my_env.push_back("REMOTE_ADDR=127.0.0.1");
+ my_env.push_back("REQUEST_METHOD=" + req.getMethod());
+ my_env.push_back("CONTENT_LENGTH=" + std::to_string(req.getLen()));
+ my_env.push_back("SERVER_SOFTWARE=" + req.getProtocol());
+ my_env.push_back("SERVER_NAME=127.0.0.1");
+ my_env.push_back("HTTP_ACCEPT=" + req.getHeader()["Accept:"]);
+ my_env.push_back("HTTP_ACCEPT_LANGUAGE=" + req.getHeader()["Accept-Language:"]);
+ my_env.push_back("HTTP_USER_AGENT=" + req.getHeader()["User-Agent:"]);
+ my_env.push_back("SCRIPT_NAME=" + filePwd);
+ return (my_env);
+}
+
+char **vecToTab(std::vector vec)
+{
+ char **tab;
+ int i = 0;
+
+ tab = (char **)malloc(sizeof(char *) * (vec.size() + 1));
+ if (!tab)
+ {
+ perror("malloc vecToTab");
+ exit(1);
+ }
+
+ for (std::vector::iterator it = vec.begin(); it != vec.end(); it++)
+ {
+ tab[i++] = (char *)(*it).c_str();
+ }
+ tab[i] = 0;
+ return tab;
+}
+
+std::string execCGI(std::string filePwd, char **envp, Requete req)
+{
+ filePwd = "." + filePwd;
+ std::string execPwd = searchExec(filePwd, envp);
+ if (execPwd == "")
+ {
+ std::cerr << "Bad file" << std::endl;
+ return (0);
+ }
+
+ int fdIn;
+ int fd_in[2];
+ int fd_out[2];
+ char *tab[3];
+
+ tab[0] = (char *)execPwd.c_str();
+ tab[1] = (char *)filePwd.c_str();
+ tab[2] = 0;
+
+ char **my_env;
+
+ my_env = vecToTab(newEnv(filePwd, envp, req));
+
+ pipe(fd_in);
+ pipe(fd_out);
+ pid_t pid = fork();
+
+ if (pid == -1)
+ {
+ perror("fork()");
+ exit(1);
+ }
+
+
+
+ if (pid == 0)
+ {
+ if (dup2(fd_in[0], 0) == -1)
+ {
+ perror("dup2");
+ exit(1);
+ }
+ if (dup2(fd_out[1], 1) == -1)
+ {
+ perror("dup2");
+ exit(1);
+ }
+ close(fd_out[0]);
+ close(fd_in[1]);
+ execve(tab[0], tab, my_env);
+ perror("execve");
+ close(fd_out[1]);
+ close(fd_in[0]);
+ exit(1);
+ }
+
+
+
+
+ else
+ {
+ fdIn = dup(0);
+ if (fdIn == 0)
+ {
+ perror("dup");
+ exit(1);
+ }
+ if (dup2(fd_in[0], 0) == -1)
+ {
+ perror("dup2");
+ exit(1);
+ }
+ // if (!req.getBody().empty())
+ // {
+ // write(fd_in[0], req.getBody().c_str(), req.getLen());//req.getBody ou req.getBodyComplet
+ // }
+ write(fd_in[1], "bon", 3);
+ waitpid(pid, 0, 0);
+ close(fd_in[0]);
+ close(fd_in[1]);
+ if (dup2(fdIn, 0) == -1)
+ {
+ perror("dup2");
+ exit(1);
+ }
+ free(my_env);
+
+
+ char buff[32768] = {0};
+ std::string ret = "";
+ int i;
+
+
+
+
+ close(fd_out[1]);
+ i = read(fd_out[0], buff, 32767);
+ if (i == -1)
+ {
+ perror("read");
+ exit(1);
+ }
+ ret += std::string(buff);
+ while (i < 0)
+ {
+ i = read(fd_out[0], buff, 32767);
+ if (i == -1)
+ {
+ perror("read");
+ exit(1);
+
+ }
+ buff[i] = 0;
+ ret += std::string(buff);
+ }
+ close(fd_out[0]);
+ std::cout << ret << "\n" ;
+ return ret;
+ }
+ return "";
+
+}
diff --git a/cgi.hpp b/cgi.hpp
new file mode 100644
index 0000000..f2bdf87
--- /dev/null
+++ b/cgi.hpp
@@ -0,0 +1,14 @@
+#ifndef CGI_HPP
+# define CGI_HPP
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+
+#endif
\ No newline at end of file
diff --git a/john/Classes.cpp b/john/Classes.cpp
deleted file mode 100644
index c5782c7..0000000
--- a/john/Classes.cpp
+++ /dev/null
@@ -1,370 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* Classes.cpp :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: tmartial +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2022/08/13 14:48:09 by tmartial #+# #+# */
-/* Updated: 2022/08/19 18:22:02 by tmartial ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "webserv.hpp"
-
-/* ---------------------------------------------------- */
-/* */
-/* SERVER */
-/* */
-/* ---------------------------------------------------- */
-
-Servers::Servers()
-{
-
-}
-
-Servers::~Servers()
-{
- for (size_t i = 0; i < _locations.size(); i++)
- {
- delete _locations[i];
- }
- _locations.clear();
-}
-
-/* Functions */
-
-/* Check methods are correct in one server and it locations */
-bool Servers::check_method()
-{
- for (size_t j = 0; j < _method.size(); j++)
- {
- if ( _method[j] != "POST" && _method[j] != "GET" && _method[j] != "DELETE" )
- return false;
- }
- for (size_t i = 0; i < _locations.size(); i++)
- {
- for (size_t j = 0; j < _locations[i]->getMethod().size(); j++)
- {
- if (_locations[i]->getMethod()[j] != "POST" && _locations[i]->getMethod()[j] != "GET"
- && _locations[i]->getMethod()[j] != "DELETE" )
- return false;
- }
- }
- return true;
-}
-
-/* Check if error pages are good with nums and .html */
-bool Servers::check_error_page()
-{
- std::map::iterator it = _error.begin();
- std::map::iterator it_end = _error.end();
- while (it != it_end)
- {
- if (!my_atoi(it->first) || (it->second).find(".html") == std::string::npos)
- return false;
- it++;
- }
- return true;
-}
-
-/* Stock location */
-void Servers::stock_location(std::string line, int pos)
-{
- std::string word = ft_first_word(line);
- std::string last = ft_last_word(line);
-
- if (word == "location")
- _locations[pos]->setDir(last);
- else if (word == "root")
- {
- if (!_locations[pos]->getRoot().empty())
- throw DirTwice();
- _locations[pos]->setRoot(last);
- }
- else if (word == "index")
- {
- if (!_locations[pos]->getIndex().empty())
- throw DirTwice();
- _locations[pos]->setIndex(last);
- }
- else if (word == "allowed_methods")
- _locations[pos]->setMethod(last);
-
-}
-
-/* ---------------------------------------------------- */
-/* */
-/* CONF */
-/* */
-/* ---------------------------------------------------- */
-
-Conf::Conf()
-{
- _directives.push_back("server");
- _directives.push_back("listen");
- _directives.push_back("server_name");
- _directives.push_back("allowed_methods");
- _directives.push_back("root");
- _directives.push_back("error_page");
- _directives.push_back("index");
- _directives.push_back("client_max_body_size");
- _directives.push_back("location");
-}
-
-Conf::~Conf()
-{
- for (size_t i = 0; i < _servers.size(); i++)
- {
- delete _servers[i];
- }
- _servers.clear();
-}
-
-
-/* --- FUNCTIONS --- */
-
-/* Check all data is correct */
-/*
- - root is a path
- - index is a html file
- - ERROR PAGE MISSING = 404 default
-*/
-void Conf::check_data()
-{
- for (size_t i = 0; i < _servers.size(); i++)
- {
- if (_servers[i]->getName().empty() || _servers[i]->getListen().empty() || _servers[i]->getRoot().empty()
- || _servers[i]->getIndex().empty() || _servers[i]->getMethod().empty() || _servers[i]->getBody().empty())
- throw DirMissing();
- if (!my_atoi(_servers[i]->getListen()) || !my_atoi(_servers[i]->getBody()))
- throw NotINT();
- if (!_servers[i]->check_error_page())
- throw ErrorPage();
- if (!_servers[i]->check_method())
- throw MethWrong();
- }
-
-}
-
-
-/* Print all data in conf */
-void Conf::print_all_data()
-{
- for (size_t i = 0; i < _servers.size(); i++)
- {
- cout << "--- server "<< i << ":" << endl;
- cout << "name = " << _servers[i]->getName() << endl;
- cout << "listen = " << _servers[i]->getListen() << endl;
- cout << "root = " << _servers[i]->getRoot() << endl;
- cout << "index = " << _servers[i]->getIndex() << endl;
- cout << "body = " << _servers[i]->getBody() << endl;
- cout << "methods = ";
- for (size_t len = 0; len < _servers[i]->getMethod().size(); len++)
- cout << _servers[i]->getMethod()[len] << " ";
- cout << endl;
- cout << "error pages:" << endl;
- std::map copy = _servers[i]->getError();
- std::map::iterator it = copy.begin();
- for (size_t len = 0; len < _servers[i]->getError().size(); len++)
- {
- cout << "error " << it->first << " = " << it->second << endl;
- it++;
- }
-
- for (size_t x = 0; x < _servers[i]->getLocation().size(); x++)
- {
- cout << "- location "<< x << ":" << endl;
- cout << "dir = " << _servers[i]->getLocation()[x]->getDir() << endl;
- cout << "root = " << _servers[i]->getLocation()[x]->getRoot() << endl;
- cout << "index = " << _servers[i]->getLocation()[x]->getIndex() << endl;
- cout << "methods = ";
- for (size_t len = 0; len < _servers[i]->getLocation()[x]->getMethod().size(); len++)
- cout << _servers[i]->getLocation()[x]->getMethod()[len] << " ";
- cout << endl;
- }
- }
-}
-
-/* Vector with pos of directive if location or server */
-void Conf::init_file_pos()
-{
- //0 = server; 1 = location;
- size_t len =_file.size(), pos = 0;
- std::string word;
-
- for (size_t i = 0; i < len; i++)
- {
- word = ft_first_word(_file[i]);
- if (i == 0 && word != "server")
- throw DirMissing();
- if (word == "server")
- pos = 0;
- else if (word == "location")
- pos = 1;
- _file_pos.push_back(pos);
- }
-}
-
-/* Check if all lines are directive */
-void Conf::check_directive()
-{
- std::size_t len = _file.size();
-
- for (size_t i = 0; i < len; i++)
- this->is_directive(_file[i], i);
-}
-
-/* Stock all the datas */
-void Conf::stock_data()
-{
- std::size_t len = _file.size();
- int nb_server = -1, nb_locations = -1;
-
- for (size_t i = 0; i < len; i++)
- {
- if (_file_pos[i] == 0)
- {
- if (ft_first_word(_file[i]) == "server")
- {
- setServers();//New server
- nb_server++;
- nb_locations = -1;
- }
- else
- {
- stock_server(_file[i], _servers[nb_server]);
- }
- }
- else
- {
- if (ft_first_word(_file[i]) == "location")
- {
- _servers[nb_server]->setLocation();//New locations
- nb_locations++;
- }
- _servers[nb_server]->stock_location(_file[i], nb_locations);
- }
- }
-}
-
-/* Stock directive in server */
-void Conf::stock_server(std::string line, Servers* server)
-{
- std::size_t count = count_words(line);
- std::string word = ft_first_word(line), last;
-
- if (count == 2)
- {
- last = ft_last_word(line);
- if (word == "listen")
- {
- if (!server->getListen().empty())
- throw DirTwice();
- server->setListen(last);
- }
- else if (word == "server_name")
- {
- if (!server->getName().empty())
- throw DirTwice();
- server->setName(last);
- }
- else if (word == "root")
- {
- if (!server->getRoot().empty())
- throw DirTwice();
- server->setRoot(last);
- }
- else if (word == "index")
- {
- if (!server->getIndex().empty())
- throw DirTwice();
- server->setIndex(last);
- }
- else if (word == "client_max_body_size")
- {
- if (!server->getBody().empty())
- throw DirTwice();
- server->setBody(last);
- }
- else if (word == "allowed_methods")
- server->setMethod(last);
- }
- else if (count >= 3)
- {
- std::stringstream ss(line);
- std::string token;
- last = ft_last_word(line);
-
- while (ss >> token)
- {
- if (token != last && token != word)
- server->setError(token, last);
- }
- }
-
-}
-
-/* Check if word is a directive */
-void Conf::is_directive(std::string line, int pos)
-{
- std::size_t count = count_words(line), len = _directives.size();
- std::string word = ft_first_word(line);
-
- for (size_t i = 0; i < len; i++)
- {
- if (word == _directives[i])
- {
- if (count == 1 && word != "server")
- throw MissingArgv();
- else if (count >= 3 && word != "error_page")
- throw TooMuchArgv();
- else if (count == 2 && word == "error_page")
- throw MissingArgv();
- else if (_file_pos[pos] == 1 && (word == "listen" || word == "client_max_body_size" || word == "server_name")) //0 == server, 1 == location
- throw DirWrongPlace();
- return ;
- }
- }
- throw DirWrong();
-}
-
-/* Fill data will all read lines Insert in _file all lines except empty line */
-void Conf::read_file(std::string name)
-{
- std::ifstream file(name);
- std::string output;
-
- while (std::getline(file, output))
- {
- std::size_t len = output.length();
-
- for (std::size_t i = 0; i < len; i++)
- {
- if (!isspace(output[i]))
- {
- _file.push_back(output);
- break;
- }
- }
- }
-}
-
-
-/* ---------------------------------------------------- */
-/* */
-/* LOCATION */
-/* */
-/* ---------------------------------------------------- */
-
-Location::Location()
-{
-
-}
-
-Location::~Location()
-{
-
-}
-
-/* Functions */
diff --git a/john/a.out b/john/a.out
deleted file mode 100755
index 1398cc2..0000000
Binary files a/john/a.out and /dev/null differ
diff --git a/john/chunk_stress.sh b/john/chunk_stress.sh
deleted file mode 100755
index d384228..0000000
--- a/john/chunk_stress.sh
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/bin/bash
-
-echo "- existing file deletion -"
-
-printf "DELETE /my_ego.db HTTP/1.1\r\n" > /tmp/delete
-printf "Host: example.com\r\n\r\n" >> /tmp/delete
-
-cat /tmp/delete | nc localhost 8080
-
-echo "- chunk creation -"
-# CHUNK CREATION
-rm -f /tmp/chunk
-j=0
-while (( $j < 5000 ))
-do
- echo -n "zzzzzzzzzz" >> /tmp/chunk
- ((j++))
-done
-
-echo "- header creation -"
-# HEADER CREATION
-printf "POST /directory/youpi.bla HTTP/1.1\r\n" > /tmp/my_ego.db
-printf "Host: example.com\r\n" >> /tmp/my_ego.db
-printf "Transfer-Encoding: chunked\r\n" >> /tmp/my_ego.db
-printf "\r\n" >> /tmp/my_ego.db
-
-echo "- body creation -"
-# BODY CREATION
-i=0
-while (( $i < 2000 ))
-do
- printf "C350\r\n" >> /tmp/my_ego.db
- cat /tmp/chunk >> /tmp/my_ego.db
- printf "\r\n" >> /tmp/my_ego.db
- ((i++))
-done
-printf "0\r\n" >> /tmp/my_ego.db
-printf "\r\n" >> /tmp/my_ego.db
-
-echo "- request sending creation -"
-cat /tmp/my_ego.db | nc localhost 8080 | head
diff --git a/john/client.cpp b/john/client.cpp
deleted file mode 100644
index b834b70..0000000
--- a/john/client.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-#include "client.hpp"
-
diff --git a/john/client.hpp b/john/client.hpp
deleted file mode 100644
index 4531d0f..0000000
--- a/john/client.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef CLIENT_HPP
-#define CLIENT_HPP
-
-class Client
-{
- public :
- void setSocketClient(int sock) { clientSocket = sock; }
- int getClientSocket() { return clientSocket; }
- int getNServer() { return n_server; }
- void setNServer(int n) { n_server = n; }
-
- int requestSize;
- char request[2049];
-
- private :
- int clientSocket;
- int n_server;
-
-};
-
-#endif
\ No newline at end of file
diff --git a/john/colors.hpp b/john/colors.hpp
deleted file mode 100644
index 1beffcd..0000000
--- a/john/colors.hpp
+++ /dev/null
@@ -1,467 +0,0 @@
-#ifndef COLORS_HPP_
-#define COLORS_HPP_
-
-#include
-
-#if defined(_WIN32) || defined(_WIN64)
-# define COLORS_TARGET_WINDOWS
-#elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
-# define COLORS_TARGET_POSIX
-#endif
-
-#if !defined(COLORS_USE_ANSI_ESCAPE) && !defined(COLORS_USE_WINDOWS_API)
-# if defined(COLORS_TARGET_POSIX)
-# define COLORS_USE_ANSI_ESCAPE
-# elif defined(COLORS_TARGET_WINDOWS)
-# define COLORS_USE_WINDOWS_API
-# endif
-#endif
-
-#if defined(COLORS_USE_WINDOWS_API)
-# include
-#endif
-
-namespace colors {
-
- #if defined(COLORS_USE_WINDOWS_API)
- inline void wset_attributes(std::ostream& stream, int foreground, int background = -1) {
- // some comments because its windows :/
-
- // for save default attributes of output
- static WORD defaultAttributes = 0;
-
- // get the terminal handle
- HANDLE handleTerminal = GetStdHandle(STD_OUTPUT_HANDLE);
-
- // save default attributes
- if (!defaultAttributes) {
- CONSOLE_SCREEN_BUFFER_INFO info;
- if (!GetConsoleScreenBufferInfo(handleTerminal, &info)) return;
- defaultAttributes = info.wAttributes;
- }
-
- // restore all to the default settings
- if (foreground == -1 && background == -1) {
- SetConsoleTextAttribute(handleTerminal, defaultAttributes);
- return;
- }
-
- // get the current settings
- CONSOLE_SCREEN_BUFFER_INFO info;
- if (!GetConsoleScreenBufferInfo(handleTerminal, &info)) return;
-
- if (foreground != -1) {
- info.wAttributes &= ~(info.wAttributes & 0x0F);
- info.wAttributes |= static_cast(foreground);
- }
-
- if (background != -1) {
- info.wAttributes &= ~(info.wAttributes & 0xF0);
- info.wAttributes |= static_cast(background);
- }
-
- SetConsoleTextAttribute(handleTerminal, info.wAttributes);
- }
- #endif
-
- inline std::ostream& reset(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[00m";
- #else
- wset_attributes(stream, -1, -1);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bold(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[1m";
- #endif
-
- return stream;
- }
-
- inline std::ostream& faint(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[2m";
- #endif
-
- return stream;
- }
-
- inline std::ostream& italic(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[3m";
- #endif
-
- return stream;
- }
-
- inline std::ostream& underline(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[4m";
- #endif
-
- return stream;
- }
-
- inline std::ostream& blink(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[5m";
- #endif
-
- return stream;
- }
-
- inline std::ostream& reverse(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[7m";
- #endif
-
- return stream;
- }
-
- inline std::ostream& invisible(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[8m";
- #endif
-
- return stream;
- }
-
- inline std::ostream& strikethrough(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[9m";
- #endif
-
- return stream;
- }
-
- inline std::ostream& grey(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[30m";
- #else
- wset_attributes(stream, 0);
- #endif
-
- return stream;
- }
-
- inline std::ostream& red(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[31m";
- #else
- wset_attributes(stream, FOREGROUND_RED);
- #endif
-
- return stream;
- }
-
- inline std::ostream& green(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[32m";
- #else
- wset_attributes(stream, FOREGROUND_GREEN);
- #endif
-
- return stream;
- }
-
- inline std::ostream& yellow(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[33m";
- #else
- wset_attributes(stream, FOREGROUND_RED | FOREGROUND_GREEN);
- #endif
-
- return stream;
- }
-
- inline std::ostream& blue(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[34m";
- #else
- wset_attributes(stream, FOREGROUND_BLUE);
- #endif
-
- return stream;
- }
-
- inline std::ostream& magenta(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[35m";
- #else
- wset_attributes(stream, FOREGROUND_RED | FOREGROUND_BLUE);
- #endif
-
- return stream;
- }
-
- inline std::ostream& cyan(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[36m";
- #else
- wset_attributes(stream, FOREGROUND_BLUE | FOREGROUND_GREEN);
- #endif
-
- return stream;
- }
-
- inline std::ostream& white(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[37m";
- #else
- wset_attributes(stream, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bright_grey(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[90m";
- #else
- wset_attributes(stream, 0 | FOREGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bright_red(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[91m";
- #else
- wset_attributes(stream, FOREGROUND_RED | FOREGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bright_green(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[92m";
- #else
- wset_attributes(stream, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bright_yellow(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[93m";
- #else
- wset_attributes(stream, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bright_blue(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[94m";
- #else
- wset_attributes(stream, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bright_magenta(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[95m";
- #else
- wset_attributes(stream, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bright_cyan(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[96m";
- #else
- wset_attributes(stream, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& bright_white(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[97m";
- #else
- wset_attributes(stream, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_grey(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[40m";
- #else
- wset_attributes(stream, -1, 0);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_red(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[41m";
- #else
- wset_attributes(stream, -1, BACKGROUND_RED);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_green(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[42m";
- #else
- wset_attributes(stream, -1, BACKGROUND_GREEN);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_yellow(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[43m";
- #else
- wset_attributes(stream, -1, BACKGROUND_RED | BACKGROUND_GREEN);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_blue(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[44m";
- #else
- wset_attributes(stream, -1, BACKGROUND_BLUE);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_magenta(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[45m";
- #else
- wset_attributes(stream, -1, BACKGROUND_RED | BACKGROUND_BLUE);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_cyan(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[46m";
- #else
- wset_attributes(stream, -1, BACKGROUND_BLUE | BACKGROUND_GREEN);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_white(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[47m";
- #else
- wset_attributes(stream, -1, BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_bright_grey(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[100m";
- #else
- wset_attributes(stream, -1, 0 | BACKGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_bright_red(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[101m";
- #else
- wset_attributes(stream, -1, BACKGROUND_RED | BACKGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_bright_green(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[102m";
- #else
- wset_attributes(stream, -1, BACKGROUND_GREEN | BACKGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_bright_yellow(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[103m";
- #else
- wset_attributes(stream, -1, BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_bright_blue(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[104m";
- #else
- wset_attributes(stream, -1, BACKGROUND_BLUE | BACKGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_bright_magenta(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[105m";
- #else
- wset_attributes(stream, -1, BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_bright_cyan(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[106m";
- #else
- wset_attributes(stream, -1, BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-
- inline std::ostream& on_bright_white(std::ostream& stream) {
- #if defined(COLORS_USE_ANSI_ESCAPE)
- stream << "\033[107m";
- #else
- wset_attributes(stream, -1, BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
- #endif
-
- return stream;
- }
-}
-
-#undef COLORS_TARGET_POSIX
-#undef COLORS_TARGET_WINDOWS
-#undef COLORS_USE_ANSI_ESCAPE
-#undef COLORS_USE_WINDOWS_API
-
-#endif
\ No newline at end of file
diff --git a/john/index.html b/john/index.html
deleted file mode 100755
index 9655bf3..0000000
--- a/john/index.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-Page Title
-
-
-
-My First Heading
-My first paragraph.
-
-
-
diff --git a/john/main.cpp b/john/main.cpp
deleted file mode 100755
index 2dcdfc2..0000000
--- a/john/main.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-#include /* Voir NOTES */
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "webserv.hpp"
-#include "server.hpp"
-
-void deleteallfd(Server serv)
-{
- for(int i = 0; i < serv.getSocketList().size(); i++)
- {
- close(serv.getSocketList()[i]->getServerSocket());
- }
- for(int i = 0; i < serv.getClientsList().size(); i++)
- {
- close(serv.getClientsList()[i].getClientSocket());
- }
-}
-
-
-int main(int ac, char **av)
-{
- if(ac != 2)
- {
- std::cerr << "Usage : ./Webserv " << std::endl;
- return 0;
- }
- Server serv;
- Conf data;
- try
- {
- parsing(ac, av, data);
- }
- catch(const std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- return (1);
- }
- serv.info = data;
- serv.info.print_all_data(); // ! For test
-
- serv.listAllSockets();
- while(1)
- {
- serv.waitClient();
- serv.acceptClient();
- serv.handleRequest();
- }
-
-}
diff --git a/john/nginx.conf b/john/nginx.conf
deleted file mode 100644
index 6a7e395..0000000
--- a/john/nginx.conf
+++ /dev/null
@@ -1,38 +0,0 @@
-server
-server_name hello
-listen 4040
-allowed_methods POST
-allowed_methods GET
-error_page 404 505 error404.html
-error_page 606 error405.html
-root ./website/ressources
-index index.html
-client_max_body_size 9000000
-allowed_methods DELETE
-
-location /loc
-root ./website/bla
-index foo.html
-allowed_methods GET
-
-location /loc2
-root ./website/bla
-index foo.html
-allowed_methods GET
-
-server
-server_name hello
-listen 4041
-allowed_methods POST
-allowed_methods GET
-root ./website/ressources
-error_page 404 505 error404.html
-error_page 606 error606.html
-index index.html
-client_max_body_size 900000
-allowed_methods DELETE
-
-location /loc3
-root ./website/bla
-index foo.html
-allowed_methods GET
\ No newline at end of file
diff --git a/john/parse_conf.cpp b/john/parse_conf.cpp
deleted file mode 100644
index 03dbfa0..0000000
--- a/john/parse_conf.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* parse_conf.cpp :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: tmartial +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2022/08/11 15:14:35 by tmartial #+# #+# */
-/* Updated: 2022/08/19 17:54:56 by tmartial ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-# include "webserv.hpp"
-
-void parsing(int argc, char **argv, Conf &data)
-{
- parse_basic(argc, argv);
- data.read_file(argv[1]);
- data.init_file_pos();
- data.check_directive();
- data.stock_data();
- data.check_data();
-}
-
-/* Check if file is good to use */
-void parse_basic(int argc, char **argv)
-{
- if (argc != 2)
- throw ArgvErr();
-
- std::ifstream file(argv[1]);
-
- if (!file)
- throw ArgvErr();
- else
- {
- std::string name = std::string(argv[1]);
-
- if (name.find(".conf") == std::string::npos) //npos == -1 in size_t
- throw ArgvErr();
- }
-}
-
-/* Count words in a sentence */
-int count_words(std::string sentence)
-{
- int ret = 0, i = 0;
-
- while (sentence[i + 1])
- {
- if (!isspace(sentence[i]) && isspace(sentence[i + 1]))
- ret++;
- i++;
- }
- if (!isspace(sentence[i]))
- ret++;
- return (ret);
-}
-
-/* Check is str is int */
-bool my_atoi(std::string word)
-{
- int i = 0;
- while (word[i])
- {
- if (!isdigit(word[i]))
- return false;
- i++;
- }
- return true;
-}
-
-/* Retun first word from line */
-std::string ft_first_word(std::string line)
-{
- int i = 0, j = 0;
- while (isspace(line[i]) && line[i])
- i++;
- j = i;
- while (!isspace(line[j]) && line[j])
- j++;
- return (line.substr(i, j - i));
-}
-
-/* Return last word from line */
-std::string ft_last_word(std::string line)
-{
- int i = line.length() - 1, j = 0;
- while (isspace(line[i]) && line[i])
- i--;
- j = i;
- while (j > 0 && !isspace(line[j]))
- j--;
- return (line.substr(j + 1, i - j));
-}
-
-/* Return last part from line starting fron first word */
-std::string ft_last_part(std::string line)
-{
- std::string first = ft_first_word(line);
- int pos = line.find(first), i = pos + 1;
-
- while (line[i])
- i++;
- return (line.substr(pos, i - pos));
-}
diff --git a/john/server.cpp b/john/server.cpp
deleted file mode 100755
index 46d764a..0000000
--- a/john/server.cpp
+++ /dev/null
@@ -1,251 +0,0 @@
-#include "server.hpp"
-#include "tim_requete.hpp"
-#include "webserv.hpp"
-#include
-
-#define NUM_SOCKS 3
-
-void Server::listAllSockets()
-{
- for(int i = 0; i < info.getServers().size(); i++)
- {
- Socket *socket = new Socket;
- socket->setup(stoi(info.getServers()[i]->getListen()));
- sockets.push_back(socket);
- }
- errors.insert(std::make_pair(200, "200 OK"));
- errors.insert(std::make_pair(201, "201 Created"));
- errors.insert(std::make_pair(204, "204 No Content"));
- errors.insert(std::make_pair(300, "300 Multiple Choices"));
- errors.insert(std::make_pair(301, "301 Moved Permanently"));
- errors.insert(std::make_pair(302, "302 Found"));
- errors.insert(std::make_pair(303, "303 See Other"));
- errors.insert(std::make_pair(307, "307 Temporary Redirect"));
- errors.insert(std::make_pair(400, "400 Bad Request"));
- errors.insert(std::make_pair(404, "404 Not Found"));
- errors.insert(std::make_pair(405, "405 Method Not Allowed"));
- errors.insert(std::make_pair(408, "408 Request Timeout"));
- errors.insert(std::make_pair(411, "411 Length Required"));
- errors.insert(std::make_pair(413, "413 Request Entity Too Large"));
- errors.insert(std::make_pair(414, "414 Request-URI Too Long"));
- errors.insert(std::make_pair(500, "500 Internal Server Error"));
- errors.insert(std::make_pair(502, "502 Bad Gateway"));
- errors.insert(std::make_pair(505, "505 HTTP Version Not Supported"));
-}
-
-
-void Server::showError(int err, Client &client)
-{
- std::map::iterator it = errors.find(err);
- if(it != errors.end())
- {
- std::cout << colors::on_bright_red << "Show error : " << it->first << " : " << it->second << " !" << colors::on_grey << std::endl;
- std::string msg = "HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: " + std::to_string(it->second.size()) + "\n\n" + it->second + "\n";
- send(client.getClientSocket() , msg.c_str(), msg.size(), 0);
- }
-}
-
-void Server::waitClient()
-{
- fd_set readSet;
- fd_set writeSet;
- int max_fd = 0;
-
- FD_ZERO(&readSet);
- FD_ZERO(&writeSet);
- for(int i = 0; i < sockets.size(); i++) // Set fd of server
- {
- FD_SET(sockets[i]->getServerSocket(), &readSet);
- if(sockets[i]->getServerSocket() > max_fd)
- max_fd = sockets[i]->getServerSocket();
- }
- for(int i = 0; i < clients.size(); i++) // Set fd of server
- {
- FD_SET(clients[i].getClientSocket(), &readSet);
- if(clients[i].getClientSocket() > max_fd)
- max_fd = clients[i].getClientSocket();
- }
- if(select(max_fd + 1, &readSet, &writeSet, 0, 0) < 0)
- exit(-1);
- _write = writeSet;
- _read = readSet;
-}
-
-
-void Server::acceptClient()
-{
- sockaddr_in addrclient;
- socklen_t clientSize = sizeof(addrclient);
-
- for(int i = 0; i < sockets.size(); i++)
- {
- if(FD_ISSET(sockets[i]->getServerSocket(), &_read))
- {
- Client tmp;
- tmp.setNServer(i);
- bzero(tmp.request, 2048);
- tmp.requestSize = 0;
- tmp.setSocketClient(accept(sockets[i]->getServerSocket(), (sockaddr *)&addrclient, &clientSize));
- clients.push_back(tmp);
- if(sockets[i]->getServerSocket() < 0)
- {
- perror("Connect");
- exit(-1);
- }
- std::cout << colors::green << "New connection !" << std::endl;
- }
- }
-}
-
-
-bool Server::kill_client(Client client)
-{
- close(client.getClientSocket());
-
- for(int i = 0; i < clients.size(); i++)
- {
- if(clients[i].getClientSocket() == client.getClientSocket())
- {
- clients.erase(clients.begin() + i);
- return true;
- }
- }
- exit(1);
-}
-
-
-
-void Server::handleRequest()
-{
- for(int i = 0; i < clients.size(); i++)
- {
- if(FD_ISSET(clients[i].getClientSocket(), &_read))
- {
- std::cout << colors::bright_cyan << "New Request ! : ";
- int Reqsize = recv(clients[i].getClientSocket() , clients[i].request + clients[i].requestSize,
- MAX_REQUEST - clients[i].requestSize, 0);
- clients[i].requestSize += Reqsize;
-
-
- if(clients[i].requestSize > MAX_REQUEST)
- {
- std::cout << colors::on_bright_red << "out of range" << std::endl;
- showError(413, clients[i]);
- if(kill_client(clients[i]))
- i--;
- continue;
- }
- if(Reqsize == 0)
- {
- std::cout << colors::on_bright_red << "Connection is closed !" << std::endl;
- kill_client(clients[i]);
- i--;
- }
- else if (Reqsize < 0)
- {
- std::cout << "Connection is closed !" << std::endl;
- showError(500, clients[i]);
- kill_client(clients[i]);
- i--;
- }
- else
- {
- Tim_requete requete(clients[i].request);
- if(!is_allowed(info.getServers()[clients[i].getNServer()]->getMethod(), requete.getMethod()))
- {
- std::cout << "Unautorised Method " << requete.getMethod() << " !" << std::endl;
- showError(405, clients[i]);
- kill_client(clients[i]);
- i--;
- continue;
- }
- if (!requete.check_tim())
- throw RequestErr();
- std::cout << colors::yellow << requete.getMethod() << " " << requete.getUrl() << std::endl;
- std::cout << colors::grey << clients[i].request << std::endl;
-
-
-
-
-
-
- if (requete.getMethod() == "GET") {
- std::cout << clients[i].getNServer() << std::endl;
- getMethod(clients[i], requete.getUrl());
- }
- else if (requete.getMethod() == "POST") {
-
- }
- else if (requete.getMethod() == "DELETE") {
-
- }
- }
- if(kill_client(clients[i]))
- i--;
- clients[i].requestSize = 0;
- bzero(clients[i].request, 2048);
- }
- }
- usleep(500);
-}
-
-void Server::showPage(int socket, std::string dir)
-{
- FILE *fd = fopen(dir.c_str(), "rb");
- if(fd == NULL)
- {
- std::cout << colors::on_bright_red << "Error: Couldn't open " << dir << std::endl;
- return ;
- }
-
- fseek (fd , 0 , SEEK_END);
- int lSize = ftell (fd);
- rewind (fd);
-
- char file[lSize];
- size_t len = fread(file, 1, lSize, fd);
-
- std::string data(file, len);
- std::string hello = "HTTP/1.1 200 OK\n" + data;
- send(socket , hello.c_str(), hello.size(), 0);
-
-}
-
-void Server::getMethod(Client &client, std::string url)
-{
- url = url.substr(1, url.end() - url.begin());
- std::cout << colors::bright_yellow << "GET Method !" << std::endl;
- FILE *fd = fopen(url.c_str(), "rb");
- struct stat path_stat;
- stat(url.c_str(), &path_stat);
- if(fd == NULL)
- {
- std::cout << colors::on_bright_red << "ERROR: Could not open "<< url << colors::on_grey << std::endl;
- showError(404, client);
- }
- else
- {
- if(S_ISDIR(path_stat.st_mode))
- std::cout << colors::on_bright_red << "File is a directory !" << colors::on_grey << std::endl;
- else
- {
- showPage(client.getClientSocket(), url);
- }
- }
-
-}
-
-bool Server::is_allowed(std::vector methodlist, std::string methodreq)
-{
- for(int i = 0; i < methodlist.size(); i++)
- {
- if(methodlist[i] == methodreq)
- return true;
- }
- return false;
-}
-
-// std::string getRootPatch(std::string url)
-// {
-// info.getServers()[i]
-// }
\ No newline at end of file
diff --git a/john/server.hpp b/john/server.hpp
deleted file mode 100755
index 78d1f5f..0000000
--- a/john/server.hpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef SERVER_HPP
-#define SERVER_HPP
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
'; ?>
-
-
\ No newline at end of file
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..8cfd8e1
--- /dev/null
+++ b/test.c
@@ -0,0 +1,7 @@
+#include
+
+int main()
+{
+ printf("Content-Type: text/html\r\n\r\n");
+ return (0);
+}
\ No newline at end of file
diff --git a/test.cpp b/test.cpp
new file mode 100644
index 0000000..608391c
--- /dev/null
+++ b/test.cpp
@@ -0,0 +1,8 @@
+#include
+
+int main()
+{
+ std::string a;
+
+ std::cout << "manger" + a + "\n";
+}
\ No newline at end of file
diff --git a/test.php b/test.php
new file mode 100644
index 0000000..7be4721
--- /dev/null
+++ b/test.php
@@ -0,0 +1,8 @@
+
+
+ Test PHP
+
+
+ Bonjour le monde'; ?>
+
+
\ No newline at end of file
diff --git a/test.pl b/test.pl
new file mode 100644
index 0000000..e9a39f8
--- /dev/null
+++ b/test.pl
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+
+# print "Content-type: text/html\n\n";
+# print <<"TAG";
+#
+#
+#
+#
+#
+# Your e-mail has been sent...
+# Thank you for use this page realised by Moi.
+#
+# Tschuss!
+#
+#
+# TAG
+
+
+
+use CGI;
+
+my $q = CGI->new;
+
+my $lightweight_fh = $q->upload('file1');
+my $filename = $q->param('file1');
+
+my $dir = 'server/uploads/';
+
+my $msg;
+
+mkdir($dir) unless (-d $dir);
+
+# undef may be returned if it's not a valid file handle
+if (defined $lightweight_fh) {
+ # Upgrade the handle to one compatible with IO::Handle:
+ my $io_handle = $lightweight_fh->handle;
+
+ open (OUTFILE,'>', $dir . $filename);
+ while ($bytesread = $io_handle->read($buffer,1024)) {
+ print OUTFILE $buffer;
+ }
+ $msg = 'The file \'' . $filename . '\' was uploaded successfully with perl';
+}
+else {
+ $msg = 'No file was uploaded';
+}
+
+print '' . $msg . '
';
\ No newline at end of file
diff --git a/test.py b/test.py
new file mode 100644
index 0000000..38f9387
--- /dev/null
+++ b/test.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+# import os
+
+# a = os.getenv('AUTH_TYPE')
+
+# print "Content-type:text/html\r\n\r\n"
+# print ''
+# print ''
+# print 'Hello World - First CGI Program'
+# print ''
+# print ''
+# print 'Hello World! This'
+# print a
+# print 'is my first CGI program
'
+# print ''
+# print ''
+
+import cgi, os
+
+form = cgi.FieldStorage()
+
+fileitem = form['file1']
+
+path = "./dossier"
+
+isExist = os.path.exists(path)
+
+if not isExist:
+ os.makedirs(path)
+
+if fileitem.filename:
+ fn = os.path.basename(fileitem.filename)
+ open(path + fn, 'wb').write(fileitem.file.read())
+ message = "The file '" + fn + "' was uploaded successfully with python"
+
+else:
+ message = "No file was uploaded"
+
+print """\
+
+%s
+
+""" % (message, )
\ No newline at end of file
diff --git a/tim/Classes.cpp b/tim/Classes.cpp
deleted file mode 100644
index c5782c7..0000000
--- a/tim/Classes.cpp
+++ /dev/null
@@ -1,370 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* Classes.cpp :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: tmartial +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2022/08/13 14:48:09 by tmartial #+# #+# */
-/* Updated: 2022/08/19 18:22:02 by tmartial ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "webserv.hpp"
-
-/* ---------------------------------------------------- */
-/* */
-/* SERVER */
-/* */
-/* ---------------------------------------------------- */
-
-Servers::Servers()
-{
-
-}
-
-Servers::~Servers()
-{
- for (size_t i = 0; i < _locations.size(); i++)
- {
- delete _locations[i];
- }
- _locations.clear();
-}
-
-/* Functions */
-
-/* Check methods are correct in one server and it locations */
-bool Servers::check_method()
-{
- for (size_t j = 0; j < _method.size(); j++)
- {
- if ( _method[j] != "POST" && _method[j] != "GET" && _method[j] != "DELETE" )
- return false;
- }
- for (size_t i = 0; i < _locations.size(); i++)
- {
- for (size_t j = 0; j < _locations[i]->getMethod().size(); j++)
- {
- if (_locations[i]->getMethod()[j] != "POST" && _locations[i]->getMethod()[j] != "GET"
- && _locations[i]->getMethod()[j] != "DELETE" )
- return false;
- }
- }
- return true;
-}
-
-/* Check if error pages are good with nums and .html */
-bool Servers::check_error_page()
-{
- std::map::iterator it = _error.begin();
- std::map::iterator it_end = _error.end();
- while (it != it_end)
- {
- if (!my_atoi(it->first) || (it->second).find(".html") == std::string::npos)
- return false;
- it++;
- }
- return true;
-}
-
-/* Stock location */
-void Servers::stock_location(std::string line, int pos)
-{
- std::string word = ft_first_word(line);
- std::string last = ft_last_word(line);
-
- if (word == "location")
- _locations[pos]->setDir(last);
- else if (word == "root")
- {
- if (!_locations[pos]->getRoot().empty())
- throw DirTwice();
- _locations[pos]->setRoot(last);
- }
- else if (word == "index")
- {
- if (!_locations[pos]->getIndex().empty())
- throw DirTwice();
- _locations[pos]->setIndex(last);
- }
- else if (word == "allowed_methods")
- _locations[pos]->setMethod(last);
-
-}
-
-/* ---------------------------------------------------- */
-/* */
-/* CONF */
-/* */
-/* ---------------------------------------------------- */
-
-Conf::Conf()
-{
- _directives.push_back("server");
- _directives.push_back("listen");
- _directives.push_back("server_name");
- _directives.push_back("allowed_methods");
- _directives.push_back("root");
- _directives.push_back("error_page");
- _directives.push_back("index");
- _directives.push_back("client_max_body_size");
- _directives.push_back("location");
-}
-
-Conf::~Conf()
-{
- for (size_t i = 0; i < _servers.size(); i++)
- {
- delete _servers[i];
- }
- _servers.clear();
-}
-
-
-/* --- FUNCTIONS --- */
-
-/* Check all data is correct */
-/*
- - root is a path
- - index is a html file
- - ERROR PAGE MISSING = 404 default
-*/
-void Conf::check_data()
-{
- for (size_t i = 0; i < _servers.size(); i++)
- {
- if (_servers[i]->getName().empty() || _servers[i]->getListen().empty() || _servers[i]->getRoot().empty()
- || _servers[i]->getIndex().empty() || _servers[i]->getMethod().empty() || _servers[i]->getBody().empty())
- throw DirMissing();
- if (!my_atoi(_servers[i]->getListen()) || !my_atoi(_servers[i]->getBody()))
- throw NotINT();
- if (!_servers[i]->check_error_page())
- throw ErrorPage();
- if (!_servers[i]->check_method())
- throw MethWrong();
- }
-
-}
-
-
-/* Print all data in conf */
-void Conf::print_all_data()
-{
- for (size_t i = 0; i < _servers.size(); i++)
- {
- cout << "--- server "<< i << ":" << endl;
- cout << "name = " << _servers[i]->getName() << endl;
- cout << "listen = " << _servers[i]->getListen() << endl;
- cout << "root = " << _servers[i]->getRoot() << endl;
- cout << "index = " << _servers[i]->getIndex() << endl;
- cout << "body = " << _servers[i]->getBody() << endl;
- cout << "methods = ";
- for (size_t len = 0; len < _servers[i]->getMethod().size(); len++)
- cout << _servers[i]->getMethod()[len] << " ";
- cout << endl;
- cout << "error pages:" << endl;
- std::map copy = _servers[i]->getError();
- std::map::iterator it = copy.begin();
- for (size_t len = 0; len < _servers[i]->getError().size(); len++)
- {
- cout << "error " << it->first << " = " << it->second << endl;
- it++;
- }
-
- for (size_t x = 0; x < _servers[i]->getLocation().size(); x++)
- {
- cout << "- location "<< x << ":" << endl;
- cout << "dir = " << _servers[i]->getLocation()[x]->getDir() << endl;
- cout << "root = " << _servers[i]->getLocation()[x]->getRoot() << endl;
- cout << "index = " << _servers[i]->getLocation()[x]->getIndex() << endl;
- cout << "methods = ";
- for (size_t len = 0; len < _servers[i]->getLocation()[x]->getMethod().size(); len++)
- cout << _servers[i]->getLocation()[x]->getMethod()[len] << " ";
- cout << endl;
- }
- }
-}
-
-/* Vector with pos of directive if location or server */
-void Conf::init_file_pos()
-{
- //0 = server; 1 = location;
- size_t len =_file.size(), pos = 0;
- std::string word;
-
- for (size_t i = 0; i < len; i++)
- {
- word = ft_first_word(_file[i]);
- if (i == 0 && word != "server")
- throw DirMissing();
- if (word == "server")
- pos = 0;
- else if (word == "location")
- pos = 1;
- _file_pos.push_back(pos);
- }
-}
-
-/* Check if all lines are directive */
-void Conf::check_directive()
-{
- std::size_t len = _file.size();
-
- for (size_t i = 0; i < len; i++)
- this->is_directive(_file[i], i);
-}
-
-/* Stock all the datas */
-void Conf::stock_data()
-{
- std::size_t len = _file.size();
- int nb_server = -1, nb_locations = -1;
-
- for (size_t i = 0; i < len; i++)
- {
- if (_file_pos[i] == 0)
- {
- if (ft_first_word(_file[i]) == "server")
- {
- setServers();//New server
- nb_server++;
- nb_locations = -1;
- }
- else
- {
- stock_server(_file[i], _servers[nb_server]);
- }
- }
- else
- {
- if (ft_first_word(_file[i]) == "location")
- {
- _servers[nb_server]->setLocation();//New locations
- nb_locations++;
- }
- _servers[nb_server]->stock_location(_file[i], nb_locations);
- }
- }
-}
-
-/* Stock directive in server */
-void Conf::stock_server(std::string line, Servers* server)
-{
- std::size_t count = count_words(line);
- std::string word = ft_first_word(line), last;
-
- if (count == 2)
- {
- last = ft_last_word(line);
- if (word == "listen")
- {
- if (!server->getListen().empty())
- throw DirTwice();
- server->setListen(last);
- }
- else if (word == "server_name")
- {
- if (!server->getName().empty())
- throw DirTwice();
- server->setName(last);
- }
- else if (word == "root")
- {
- if (!server->getRoot().empty())
- throw DirTwice();
- server->setRoot(last);
- }
- else if (word == "index")
- {
- if (!server->getIndex().empty())
- throw DirTwice();
- server->setIndex(last);
- }
- else if (word == "client_max_body_size")
- {
- if (!server->getBody().empty())
- throw DirTwice();
- server->setBody(last);
- }
- else if (word == "allowed_methods")
- server->setMethod(last);
- }
- else if (count >= 3)
- {
- std::stringstream ss(line);
- std::string token;
- last = ft_last_word(line);
-
- while (ss >> token)
- {
- if (token != last && token != word)
- server->setError(token, last);
- }
- }
-
-}
-
-/* Check if word is a directive */
-void Conf::is_directive(std::string line, int pos)
-{
- std::size_t count = count_words(line), len = _directives.size();
- std::string word = ft_first_word(line);
-
- for (size_t i = 0; i < len; i++)
- {
- if (word == _directives[i])
- {
- if (count == 1 && word != "server")
- throw MissingArgv();
- else if (count >= 3 && word != "error_page")
- throw TooMuchArgv();
- else if (count == 2 && word == "error_page")
- throw MissingArgv();
- else if (_file_pos[pos] == 1 && (word == "listen" || word == "client_max_body_size" || word == "server_name")) //0 == server, 1 == location
- throw DirWrongPlace();
- return ;
- }
- }
- throw DirWrong();
-}
-
-/* Fill data will all read lines Insert in _file all lines except empty line */
-void Conf::read_file(std::string name)
-{
- std::ifstream file(name);
- std::string output;
-
- while (std::getline(file, output))
- {
- std::size_t len = output.length();
-
- for (std::size_t i = 0; i < len; i++)
- {
- if (!isspace(output[i]))
- {
- _file.push_back(output);
- break;
- }
- }
- }
-}
-
-
-/* ---------------------------------------------------- */
-/* */
-/* LOCATION */
-/* */
-/* ---------------------------------------------------- */
-
-Location::Location()
-{
-
-}
-
-Location::~Location()
-{
-
-}
-
-/* Functions */
diff --git a/tim/Makefile b/tim/Makefile
deleted file mode 100644
index b143ff1..0000000
--- a/tim/Makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-NAME = Server
-SRCS = main.cpp parse_conf.cpp Classes.cpp
-
-OBJ = $(SRCS:.cpp=.o)
-
-CXXFLAGS = -Wall -Wextra -Werror -std=c++98 -fsanitize=address -g
-CXX = c++
-rm = rm -rf
-
-all : $(NAME)
-
-$(NAME): $(OBJ)
- $(CXX) $(CXXFLAGS) $(OBJ) -o $(NAME)
-
-clean:
- $(RM) $(OBJ)
-
-fclean: clean
- $(RM) $(NAME)
-
-re: fclean all
-
-.PHONY: re bonus clean fclean all
\ No newline at end of file
diff --git a/tim/main.cpp b/tim/main.cpp
deleted file mode 100644
index 0424527..0000000
--- a/tim/main.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* main.cpp :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: tmartial +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2022/08/11 14:39:34 by tmartial #+# #+# */
-/* Updated: 2022/08/19 14:58:42 by tmartial ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "webserv.hpp"
-
-int main(int argc, char **argv)
-{
- Conf data;
-
- try
- {
- parsing(argc, argv, data);
- }
- catch(const std::exception& e)
- {
- std::cerr << e.what() << endl;
- return (1);
- }
- data.print_all_data();
-
- return 0;
-}
diff --git a/tim/nginx.conf b/tim/nginx.conf
deleted file mode 100644
index 79566de..0000000
--- a/tim/nginx.conf
+++ /dev/null
@@ -1,38 +0,0 @@
-server
-server_name hello
-listen 4040
-allowed_methods POST
-allowed_methods GET
-error_page 404 505 error404.html
-error_page 606 error405.html
-root ./website/ressources
-index index.html
-client_max_body_size 9000000
-allowed_methods DELETE
-
-location /loc
-root ./website/bla
-index foo.html
-allowed_methods GET
-
-location /loc2
-root ./website/bla
-index foo.html
-allowed_methods GET
-
-server
-server_name hello
-listen 4040
-allowed_methods POST
-allowed_methods GET
-root ./website/ressources
-error_page 404 505 error404.html
-error_page 606 error606.html
-index index.html
-client_max_body_size 900000
-allowed_methods DELETE
-
-location /loc3
-root ./website/bla
-index foo.html
-allowed_methods GET
\ No newline at end of file
diff --git a/tim/parse_conf.cpp b/tim/parse_conf.cpp
deleted file mode 100644
index 03dbfa0..0000000
--- a/tim/parse_conf.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* parse_conf.cpp :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: tmartial +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2022/08/11 15:14:35 by tmartial #+# #+# */
-/* Updated: 2022/08/19 17:54:56 by tmartial ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-# include "webserv.hpp"
-
-void parsing(int argc, char **argv, Conf &data)
-{
- parse_basic(argc, argv);
- data.read_file(argv[1]);
- data.init_file_pos();
- data.check_directive();
- data.stock_data();
- data.check_data();
-}
-
-/* Check if file is good to use */
-void parse_basic(int argc, char **argv)
-{
- if (argc != 2)
- throw ArgvErr();
-
- std::ifstream file(argv[1]);
-
- if (!file)
- throw ArgvErr();
- else
- {
- std::string name = std::string(argv[1]);
-
- if (name.find(".conf") == std::string::npos) //npos == -1 in size_t
- throw ArgvErr();
- }
-}
-
-/* Count words in a sentence */
-int count_words(std::string sentence)
-{
- int ret = 0, i = 0;
-
- while (sentence[i + 1])
- {
- if (!isspace(sentence[i]) && isspace(sentence[i + 1]))
- ret++;
- i++;
- }
- if (!isspace(sentence[i]))
- ret++;
- return (ret);
-}
-
-/* Check is str is int */
-bool my_atoi(std::string word)
-{
- int i = 0;
- while (word[i])
- {
- if (!isdigit(word[i]))
- return false;
- i++;
- }
- return true;
-}
-
-/* Retun first word from line */
-std::string ft_first_word(std::string line)
-{
- int i = 0, j = 0;
- while (isspace(line[i]) && line[i])
- i++;
- j = i;
- while (!isspace(line[j]) && line[j])
- j++;
- return (line.substr(i, j - i));
-}
-
-/* Return last word from line */
-std::string ft_last_word(std::string line)
-{
- int i = line.length() - 1, j = 0;
- while (isspace(line[i]) && line[i])
- i--;
- j = i;
- while (j > 0 && !isspace(line[j]))
- j--;
- return (line.substr(j + 1, i - j));
-}
-
-/* Return last part from line starting fron first word */
-std::string ft_last_part(std::string line)
-{
- std::string first = ft_first_word(line);
- int pos = line.find(first), i = pos + 1;
-
- while (line[i])
- i++;
- return (line.substr(pos, i - pos));
-}
diff --git a/tim/webserv.hpp b/tim/webserv.hpp
deleted file mode 100644
index c2c091c..0000000
--- a/tim/webserv.hpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* webserv.hpp :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: tmartial +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2022/08/09 15:53:02 by tmartial #+# #+# */
-/* Updated: 2022/08/19 18:09:01 by tmartial ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#ifndef WEBSERV_HPP
-# define WEBSERV_HPP
-
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-# include
-
-/* john */
-#include
-#include
-
-using std::cout;
-using std::endl;
-using std::cerr;
-
-class Location;
-class Servers;
-class Conf;
-
-/* REQUEST
-GET / HTTP/1.1
-Host: localhost:8080
-Connection: keep-alive
-Cache-Control: max-age=0
-sec-ch-ua: "Opera";v="89", "Chromium";v="103", "_Not:A-Brand";v="24"
-sec-ch-ua-mobile: ?0
-sec-ch-ua-platform: "macOS"
-Upgrade-Insecure-Requests: 1
-User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 OPR/89.0.4447.83
-Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9
-Sec-Fetch-Site: none
-Sec-Fetch-Mode: navigate
-Sec-Fetch-User: ?1
-Sec-Fetch-Dest: document
-Accept-Encoding: gzip, deflate, br
-Accept-Language: en-US,en;q=0.9
-*/
-
-/* cmd f */
-/* PARSE_CONF */
-void parsing(int argc, char **argv, Conf &data);
-void parse_basic(int argc, char **argv);
-int count_words(std::string line);
-std::string ft_first_word(std::string line);
-std::string ft_last_word(std::string line);
-std::string ft_last_part(std::string line);
-bool my_atoi(std::string word);
-
-
-class Location
-{
- public:
- Location();
- ~Location();
-
- /* Setteres */
- void setDir(std::string word) {_dir = word;};
- void setRoot(std::string word) {_root = word;};
- void setIndex(std::string word) {_index = word;};
- void setMethod(std::string word) {_method.push_back(word);};
-
- /* Getters */
- std::string getDir() {return _dir;};
- std::vector getMethod() {return _method;};
- std::string getRoot() {return _root;};
- std::string getIndex() {return _index;};
-
- private:
- std::string _dir;
- std::vector _method;
- std::string _root;
- std::string _index;
-};
-
-class Servers
-{
- public:
- Servers();
- ~Servers();
-
- /* Setters */
- void setListen(std::string word) {_listen = word;};
- void setName(std::string word) {_name = word;};
- void setMethod(std::string word) {_method.push_back(word);};
- void setRoot(std::string word) {_root = word;};
- void setError(std::string error, std::string page) {_error.insert(std::pair(error, page));};
- void setIndex(std::string word) {_index = word;};
- void setBody(std::string word) {_body_size = word;};
- void setLocation() {_locations.push_back(new Location());};
-
- /* Getters */
- std::string getListen() {return _listen;};
- std::string getName() {return _name;};
- std::vector getMethod() {return _method;};
- std::string getRoot() {return _root;};
- std::map getError() {return _error;};
- std::string getIndex() {return _index;};
- std::string getBody() {return _body_size;};
- std::vector getLocation() {return _locations;};
-
- /* Functions */
- void stock_location(std::string line, int pos);
- bool check_method();
- bool check_error_page();
-
- private:
- std::string _listen;
- std::string _name;
- std::vector _method;
- std::string _root;
- std::map _error;
- std::string _index;
- std::string _body_size;
- std::vector _locations;
-
-};
-
-class Conf
-{
- public:
- Conf();
- ~Conf();
-
- /* Getters */
- std::vector get_file() const {return (this->_file);};
-
- /* Setters */
- void setServers() {_servers.push_back(new Servers());};
-
- /* Functions */
- void read_file(std::string name);
- void is_directive(std::string line, int pos);
- void check_directive();
- void stock_server(std::string line, Servers *server);
- void init_file_pos();
- void stock_data();
- void print_all_data();
- void check_data();
-
- private:
- std::vector _servers;
- std::vector _file;
- std::vector _file_pos;
- std::vector _directives;
-};
-
-
-/* Errors */
-/* Dont FORGET CHECK MAX INT */
-#define EXCEPTION public std::exception
-#define WHAT const char * what () const
-
-class ArgvErr : EXCEPTION {WHAT throw () { return ("Error: Arguments incorrect"); }};
-class MissingArgv : EXCEPTION {WHAT throw () { return ("Error: Missing argument after a directive"); }};
-class TooMuchArgv : EXCEPTION {WHAT throw () { return ("Error: Too much arguments after a directive"); }};
-class DirWrongPlace : EXCEPTION {WHAT throw () { return ("Error: Directive is in wrong place"); }};
-class DirWrong : EXCEPTION {WHAT throw () { return ("Error: Directive doesn't exist"); }};
-class DirMissing : EXCEPTION {WHAT throw () { return ("Error: Missing a directive"); }};
-class NotINT : EXCEPTION {WHAT throw () { return ("Error: Argument needs to be a number"); }};
-class MethWrong : EXCEPTION {WHAT throw () { return ("Error: Method is wrong"); }};
-class ErrorPage : EXCEPTION {WHAT throw () { return ("Error: Error page is wrong"); }};
-class DirTwice : EXCEPTION {WHAT throw () { return ("Error: Two times the same directive"); }};
-
-#endif
\ No newline at end of file
diff --git a/tmp b/tmp
new file mode 100644
index 0000000..dadc38b
--- /dev/null
+++ b/tmp
@@ -0,0 +1,61 @@
+this->env["AUTH_TYPE"] = "";
+this->env["CONTENT_TYPE"] = request.headers["Content-Type"];
+this->env["GATEWAY_INTERFACE"] = "CGI/1.1";
+this->env["PATH_INFO"] = request.get_path();
+this->env["PATH_TRANSLATED"] = this->get_target_file_fullpath(request, loc);
+this->env["QUERY_STRING"] = request.get_query();
+this->env["REMOTE_HOST"] = request.headers["Host"];
+this->env["REMOTE_ADDR"] = get_ip(request.get_client_fd());
+this->env["REQUEST_METHOD"] = request.method;
+
+this->env["REMOTE_USER"] = "";
+this->env["REMOTE_IDENT"] = "";
+this->env["REQUEST_METHOD"] = request.method;
+this->env["REQUEST_URI"] = request.get_path();
+this->env["SCRIPT_NAME"] = request.get_path();
+this->env["SCRIPT_FILENAME"] = this->get_target_file_fullpath(request, loc);
+this->env["SERVER_NAME"] = request.headers["Host"];
+this->env["SERVER_PROTOCOL"] = "HTTP/1.1";
+this->env["SERVER_PORT"] = request.get_port();
+this->env["SERVER_SOFTWARE"] = "webserv/1.0";
+this->env["CONTENT_LENGTH"] = "-1";
+
+
+class Requete
+{
+ public:
+ Requete(std::string requete);
+ ~Requete() {};
+
+ /* Getters */
+ std::string getMethod() const {return _method;};
+ std::string getUrl() const {return _url;};
+ std::string getProtocol() const {return _protocol;};
+ std::string getBoundary() const {return _boundary;};
+ std::string getName() const {return _boundary;};
+ std::string getFileName() const {return _file_name;};
+ std::string getType() const {return _type;};
+ std::string getBody() const {return _body;};
+ size_t getLen() const {return _len;};
+ std::string getFullBody() const {return _full_body;};
+ std::map getHeader() const {return _header;};
+ std::map getText() const {return _text;};
+
+ /* Functions */
+ bool check_tim();
+ void make_body(std::stringstream& ss, std::string token);
+
+ protected:
+ std::string _method;
+ std::string _url;
+ std::string _protocol;
+ std::string _boundary;
+ std::string _name;//content name
+ std::string _file_name;
+ std::string _type;//content type
+ std::string _body;//content body without boundary
+ size_t _len;
+ std::string _full_body;//for LXU WU
+ std::map _header;//
+ std::map _text;//if more than 1 request + no content type first arg = name && second = body
+};
\ No newline at end of file