Skip to content

Commit

Permalink
Cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Cheel nakashima committed Jun 25, 2024
1 parent 19afaf1 commit c18adf3
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 267 deletions.
30 changes: 15 additions & 15 deletions mandatory/inc/Attributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ;
};
71 changes: 36 additions & 35 deletions mandatory/inc/CGI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,42 @@
#include <signal.h>
#include "ExtendedString.hpp"

class CGI {
private:
std::string CGIFolder;
std::string fileName;
std::string fileArgs;
bool isCGI;
std::vector <ExtendedString> args;
std::map<std::string, std::string> CGIExtensions;
class CGI
{
private:
std::string CGIFolder;
std::string fileName;
std::string fileArgs;
bool isCGI;
std::vector <ExtendedString> args;
std::map<std::string, std::string> 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 <ExtendedString> getArgs();
std::string getCGIExtension(const std::string &);
std::string getFileExtension();
std::map<std::string, std::string>::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 <ExtendedString> getArgs();
std::string getCGIExtension(const std::string &);
std::string getFileExtension();
std::map<std::string, std::string>::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);
};
86 changes: 0 additions & 86 deletions mandatory/inc/Client.hpp

This file was deleted.

118 changes: 59 additions & 59 deletions mandatory/inc/FileContent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,64 @@
//#define MAX_SENT_BYTES 8192
class FileContent : public StatusCode
{
private:
std::string fileName;
std::string indexName;
std::vector <std::string> 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 <std::string> 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();
};
48 changes: 23 additions & 25 deletions mandatory/inc/Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,27 @@ class Header
std::string contentType;
std::map<std::string, std::string> 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<std::string, std::string> 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<std::string, std::string> getAttributes();
std::string getContentType();
std::string getAttribute(std::string key);
void printReceivedHeader();
};
1 change: 0 additions & 1 deletion mandatory/inc/ListeningSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Client.hpp"
#include "Server.hpp"
#include "Receive.hpp"
#include "FileContent.hpp"
Expand Down
Loading

0 comments on commit c18adf3

Please sign in to comment.