diff --git a/mandatory/inc/Attributes.hpp b/mandatory/inc/Attributes.hpp index 2402eaa..1ffc60b 100644 --- a/mandatory/inc/Attributes.hpp +++ b/mandatory/inc/Attributes.hpp @@ -24,19 +24,19 @@ class Attributes { -private: - std::string name; - struct stat attributes; -public: - Attributes(); - Attributes(const std::string& filename); - ~Attributes(); - void setAttributesFromFile(const std::string& filename); - - std::string getName() ; - bool getIsDir() ; - std::string getSize() ; - std::string getDevice() ; - std::string getCreated() ; - std::string getModified() ; + private: + std::string name; + struct stat attributes; + public: + Attributes(); + Attributes(const std::string& filename); + ~Attributes(); + void setAttributesFromFile(const std::string& filename); + + std::string getName() ; + bool getIsDir() ; + std::string getSize() ; + std::string getDevice() ; + std::string getCreated() ; + std::string getModified() ; }; \ No newline at end of file diff --git a/mandatory/inc/CGI.hpp b/mandatory/inc/CGI.hpp index 31e1243..7ea9076 100644 --- a/mandatory/inc/CGI.hpp +++ b/mandatory/inc/CGI.hpp @@ -13,41 +13,42 @@ #include #include "ExtendedString.hpp" -class CGI { -private: - std::string CGIFolder; - std::string fileName; - std::string fileArgs; - bool isCGI; - std::vector args; - std::map CGIExtensions; +class CGI +{ + private: + std::string CGIFolder; + std::string fileName; + std::string fileArgs; + bool isCGI; + std::vector args; + std::map CGIExtensions; -public: - CGI(); - CGI(const std::string &, const std::string &); - CGI(const CGI &); - ~CGI(); - //------ Setters and Getters ------// - //setters - void setCGIFolder(const std::string &); - void setFileName(const std::string&, const std::string&); - void setIsCGI(bool); - bool setIdentifyCGIFromFileName(const std::string &str); - bool getIsCGI(); - //bool setIsCGI(const std::string &str); - void setArgs(const std::string &); - void setCGIMapExtensions(std::string const &cgi_extension); - //getters - std::string getFileName(); - std::string getCGIFolder(); - std::vector getArgs(); - std::string getCGIExtension(const std::string &); - std::string getFileExtension(); - std::map::iterator findCGIExtension(const std::string &); - //------ OTHER Methods ------// - std::string execute(); - CGI *clone(); + public: + CGI(); + CGI(const std::string &, const std::string &); + CGI(const CGI &); + ~CGI(); + //------ Setters and Getters ------// + //setters + void setCGIFolder(const std::string &); + void setFileName(const std::string&, const std::string&); + void setIsCGI(bool); + bool setIdentifyCGIFromFileName(const std::string &str); + bool getIsCGI(); + //bool setIsCGI(const std::string &str); + void setArgs(const std::string &); + void setCGIMapExtensions(std::string const &cgi_extension); + //getters + std::string getFileName(); + std::string getCGIFolder(); + std::vector getArgs(); + std::string getCGIExtension(const std::string &); + std::string getFileExtension(); + std::map::iterator findCGIExtension(const std::string &); + //------ OTHER Methods ------// + std::string execute(); + CGI *clone(); - static int ChildPID; - static void alarm_handler(int); + static int ChildPID; + static void alarm_handler(int); }; diff --git a/mandatory/inc/Client.hpp b/mandatory/inc/Client.hpp deleted file mode 100644 index 923acf6..0000000 --- a/mandatory/inc/Client.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include "utils.hpp" -#include -#include - -#include "../inc/colors.h" - -#define REQ_TYPE "Type" -#define REQ_FILE "File" -#define REQ_VER "Version" -#define REQ_CONTENT "Content-Type" - -#include "Header.hpp" -#include "Receive.hpp" - -class FileContent; -#include "../inc/FileContent.hpp" - - - -// enum LocationStatus -// { -// /* Correct */ -// NO_LOCATION, -// OK, -// NOT_ALLOWED, -// NOT_FOUND, -// NOT_IMPLEMENTED, -// REQUEST_ENTITY_TOO_LARGE, -// REQUEST_URI_TOO_LONG, -// INTERNAL_SERVER_ERROR, -// NOT_MODIFIED, -// REDIRECT, - -// }; - -class FileContent; -#include "../inc/FileContent.hpp" -class Server; -#include "../inc/Server.hpp" - -class Client:public FileContent { -private: - // std::map Request; - FileContent *fileContent; - Server *server; - Header response; - Header request; -public: - Client(Receive *, Server *); - Client(Server *); - Client &operator=(Client const &); - ~Client(); - void addKeyReq(std::string const &, std::string const &); - void addKeyType(std::string const &); - void addKeyFile(std::string const &); - void addKeyVers(std::string const &); - // std::map::iterator findClient(std::string const &); - // std::map::iterator getBeginClient(); - // std::map::iterator getEndClient(); - // void clearClient(); - // void deleteClient(std::string const &); - // void updateClient(std::string const &, std::string const &); - void setRequestHeader(std::string ); - // void setResponseHeader(Header); - void setServer(Server *); - - std::string getAnswerToSend(); - std::string getFilePath(); - std::string normalizePath(std::string path); - std::string getFileContent(); - bool isSendComplete(); - void loadCompleteClient(Receive *receiver, std::vector servers); - void matchServerName(std::vector servers); - void loadDataHeader(Receive *receiver); - int matchingLocation(); - int isAllowedMethod(Location *location); -}; - diff --git a/mandatory/inc/FileContent.hpp b/mandatory/inc/FileContent.hpp index f694850..ab1cda7 100644 --- a/mandatory/inc/FileContent.hpp +++ b/mandatory/inc/FileContent.hpp @@ -20,64 +20,64 @@ //#define MAX_SENT_BYTES 8192 class FileContent : public StatusCode { -private: - std::string fileName; - std::string indexName; - std::vector args; - ExtendedString content; - std::ifstream file; - bool isFistFragment; - bool isFileOpen; - bool sendComplete; - bool isAutoIndex; - std::string homeFolder; - struct stat fileStat; - long long startRange; - long long currentSendingPosition; - long long lastSendingPosition; - CGI *cgiModule; - ListDir *listDir; - //Server *server; - size_t completeContentSize; - std::string splitFileFromArgs(const std::string &); - bool FileOrFolerExtists(const std::string &); - size_t endRange; -// bool isCgi; -public: - // FileContent(Server *); - FileContent(); - // FileContent(const std::string &, Server *); - ~FileContent(); - int openFile(); - bool setFileName(const std::string &, const std::string &); - void setIsCGI(bool isCgi); - void setStartRange(long long); - void setEndRange(long long); - long long getStartRange(); - std::string getFileName(); - std::string getContent(); - void setIsFileOpen(bool); - void setIsSendComplete(bool); - bool getIsSendComplete(); - void setIsCgi(bool ); - bool getIsCgi(); + private: + std::string fileName; + std::string indexName; + std::vector args; + ExtendedString content; + std::ifstream file; + bool isFistFragment; + bool isFileOpen; + bool sendComplete; + bool isAutoIndex; + std::string homeFolder; + struct stat fileStat; + long long startRange; + long long currentSendingPosition; + long long lastSendingPosition; + CGI *cgiModule; + ListDir *listDir; + //Server *server; + size_t completeContentSize; + std::string splitFileFromArgs(const std::string &); + bool FileOrFolerExtists(const std::string &); + size_t endRange; + // bool isCgi; + public: + // FileContent(Server *); + FileContent(); + // FileContent(const std::string &, Server *); + ~FileContent(); + int openFile(); + bool setFileName(const std::string &, const std::string &); + void setIsCGI(bool isCgi); + void setStartRange(long long); + void setEndRange(long long); + long long getStartRange(); + std::string getFileName(); + std::string getContent(); + void setIsFileOpen(bool); + void setIsSendComplete(bool); + bool getIsSendComplete(); + void setIsCgi(bool ); + bool getIsCgi(); - bool getIsFileOpen(); - void setFirstFragment(bool); - bool getFirstFragment(); - std::string getLastModified(); - size_t getCompleteContentSize(); - void setCompleteContentSize(size_t); - bool isInputDirectory(); - void setRange(size_t ); - void setIsAutoIndex(bool); - bool getIsAutoIndex(); - void setIndexName(const std::string &); - std::string getIndexName(); - void setHomeFolder(const std::string &); - std::string getHomeFolder(); - void setCGIModule(CGI *); - long long getFileSize(); - long long getCurrentSendingPosition(); - long long getLastSendingPosition(); + bool getIsFileOpen(); + void setFirstFragment(bool); + bool getFirstFragment(); + std::string getLastModified(); + size_t getCompleteContentSize(); + void setCompleteContentSize(size_t); + bool isInputDirectory(); + void setRange(size_t ); + void setIsAutoIndex(bool); + bool getIsAutoIndex(); + void setIndexName(const std::string &); + std::string getIndexName(); + void setHomeFolder(const std::string &); + std::string getHomeFolder(); + void setCGIModule(CGI *); + long long getFileSize(); + long long getCurrentSendingPosition(); + long long getLastSendingPosition(); }; diff --git a/mandatory/inc/Header.hpp b/mandatory/inc/Header.hpp index 92f88e7..d7d8b77 100644 --- a/mandatory/inc/Header.hpp +++ b/mandatory/inc/Header.hpp @@ -23,29 +23,27 @@ class Header std::string contentType; std::map attributes; -public: - Header(); - Header(std::string receiveHeader); - ~Header(); - std::string generateHeader() const; - void setVersion(std::string version); - void setStatus(std::string status); - void setServer(std::string server); - void setDate(); - void setLastModified(std::string lastModified); - void setContentLength(size_t contentLength); - void setContentType(std::string contentType); - void setAttribute(std::string key, std::string value); - void setMethod(std::string method); - void setPath(std::string path); - void setProtocol(std::string protocol); - std::string getMethod(); - ExtendedString getPath(); - std::string getProtocol(); - std::map getAttributes(); - std::string getContentType(); - std::string getAttribute(std::string key); - void printReceivedHeader(); - - + public: + Header(); + Header(std::string receiveHeader); + ~Header(); + std::string generateHeader() const; + void setVersion(std::string version); + void setStatus(std::string status); + void setServer(std::string server); + void setDate(); + void setLastModified(std::string lastModified); + void setContentLength(size_t contentLength); + void setContentType(std::string contentType); + void setAttribute(std::string key, std::string value); + void setMethod(std::string method); + void setPath(std::string path); + void setProtocol(std::string protocol); + std::string getMethod(); + ExtendedString getPath(); + std::string getProtocol(); + std::map getAttributes(); + std::string getContentType(); + std::string getAttribute(std::string key); + void printReceivedHeader(); }; diff --git a/mandatory/inc/ListeningSocket.hpp b/mandatory/inc/ListeningSocket.hpp index fe5e469..29a0d55 100644 --- a/mandatory/inc/ListeningSocket.hpp +++ b/mandatory/inc/ListeningSocket.hpp @@ -23,7 +23,6 @@ #include #include #include -#include "Client.hpp" #include "Server.hpp" #include "Receive.hpp" #include "FileContent.hpp" diff --git a/mandatory/inc/WebServer.hpp b/mandatory/inc/WebServer.hpp index ca29cc3..47bbaf2 100644 --- a/mandatory/inc/WebServer.hpp +++ b/mandatory/inc/WebServer.hpp @@ -1,28 +1,19 @@ #pragma once -#pragma once -# include -# include -# include -# include -# include #ifdef __APPLE__ - # include "Server.hpp" - # include "Location.hpp" - # include "ListeningSocket.hpp" - # include # include # include #endif #ifdef __linux__ - # include "Server.hpp" - # include "Location.hpp" - # include "ListeningSocket.hpp" - # include # include # include #endif +# include +# include +# include +# include +# include # include # include # include @@ -31,14 +22,12 @@ # include # include # include "colors.h" -# include "Parser.hpp" +# include "Server.hpp" +# include "ListeningSocket.hpp" #define BACKLOG 10 #define MAX_CLIENTS 100 #define MAX_EVENTS 200 -// The backlog parameter defines the maximum length for the queue of pending -// connections. If a connection request arrives with the queue full, the -// client may receive an error with an indication of ECONNREFUSED class WebServer { private: @@ -77,7 +66,7 @@ class WebServer { static bool ExitFlag; static void exit_handler(int signum); bool checkVariables(Server *server); -#ifdef __APPLE__ + #ifdef __APPLE__ int waitEvent(struct kevent *evList); void modifEvent(struct kevent eventList, int typeRem, int typeAdd); #elif __linux__ diff --git a/mandatory/inc/toString.hpp b/mandatory/inc/toString.hpp deleted file mode 100644 index e9832fd..0000000 --- a/mandatory/inc/toString.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* toString.hpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: eavedill +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/04/21 13:55:21 by eavedill #+# #+# */ -/* Updated: 2024/05/20 13:50:25 by eavedill ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#pragma once -#include -#include - -template -std::string toString (T n) -{ - std::string str; - std::stringstream ss; - - ss << n; - ss >> str; - - return str; -}