Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .vscode/launch.json

This file was deleted.

71 changes: 71 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"files.associations": {
"string": "cpp",
"__bit_reference": "cpp",
"__config": "cpp",
"__debug": "cpp",
"__errc": "cpp",
"__functional_base": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__node_handle": "cpp",
"__nullptr": "cpp",
"__split_buffer": "cpp",
"__string": "cpp",
"__threading_support": "cpp",
"__tree": "cpp",
"__tuple": "cpp",
"algorithm": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"cmath": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"fstream": "cpp",
"functional": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stack": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp"
}
}
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SRC = main.cpp src/response.cpp
CMP = clang++ -std=c++98
FLAGS = -Wall -Wextra -Werror -g3
NAME = a.out
all : $(NAME)

$(NAME):
$(CMP) $(FLAGS) $(SRC) -o a.out

clean:
rm a.out
re: clean all
20 changes: 0 additions & 20 deletions a.out.dSYM/Contents/Info.plist

This file was deleted.

4 changes: 3 additions & 1 deletion config_files/webserv.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
server {
port 80
port 8000
host localhost
server_name bug_squash_gang_server
error_page server_files/www/error_pages/
max_file_size 123456
time_out 10
location / [
port 5000
host 0.0.0.0
root server_files/www
allowed_method GET1 POST1 Delete1
index index.html1
Expand Down
15 changes: 15 additions & 0 deletions error_pages/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>403 Forbidden</title>
</head>

<body>
<center>
<h1>403 Forbidden</h1>
</center>
<hr>
<center>nginx/1.21.4</center>
</body>

</html>
15 changes: 15 additions & 0 deletions error_pages/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>404 Not Found</title>
</head>

<body>
<center>
<h1>404 Not Found</h1>
</center>
<hr>
<center>nginx/1.21.4</center>
</body>

</html>
15 changes: 15 additions & 0 deletions error_pages/405.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>405 Not Allowed</title>
</head>

<body>
<center>
<h1>405 Not Allowed</h1>
</center>
<hr>
<center>nginx/1.21.4</center>
</body>

</html>
15 changes: 15 additions & 0 deletions error_pages/502.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html>

<head>
<title>502 Bad Gateway</title>
</head>

<body>
<center>
<h1>502 Bad Gateway</h1>
</center>
<hr>
<center>nginx/1.21.4</center>
</body>

</html>
0 test.cpp → file.html
100644 → 100755
File renamed without changes.
1 change: 1 addition & 0 deletions file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"John", "age":30, "car":null}
129 changes: 129 additions & 0 deletions fork.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <memory>


std::vector<char const*> cgi_meta_var(void)
{
std::vector<char const*> meta_var;
std::string str;
/*
* SRC = Request (we will get this info from the request headers)
* The server MUST set this meta-variable if and only if the request is accompanied by a message body entity.
* The CONTENT_LENGTH value must reflect the length of the message-body
*/
str = std::string("CONTENT_LENGHT") + '\n';
meta_var.push_back(str.c_str());
// _cgi_meta_var += "CONTENT_LENGHT=" + '\n';
/*
* SRC = Request (we will get this info from the request headers)
* The server MUST set this meta-variable if an HTTP Content-Type field is present in the client request header.
*/
str = std::string("CONTENT_TYPE=") + '\n';
meta_var.push_back(str.c_str());
/*
* SRC = Static (hard code it)
* It MUST be set to the dialect of CGI being used by the server to communicate with the script. Example: CGI/1.1
*/
str = "GATEWAY_INTERFACE=CGI/1.1\n";
meta_var.push_back(str.c_str());
/*
* SRC = Request (we will get this info from the request headers)
* Extra "path" information. It's possible to pass extra info to your script in the URL,
* after the filename of the CGI script. For example, calling the
* URL http://www.myhost.com/mypath/myscript.cgi/path/info/here will set PATH_INFO to "/path/info/here".
* Commonly used for path-like data, but you can use it for anything.
*/
str = std::string("PATH_INFO=") + '\n';
meta_var.push_back(str.c_str());
/*
* SRC = Request/Conf (we will get this info from the request headers but we should parse it as a local uri)
* the PATH_TRANSLATED variable is derived by taking the PATH_INFO value, parsing it as a local URI in its own right,
* and performing any virtual-to-physical translation appropriate to map it onto the server's document repository structure
*/
str = std::string("PATH_TRANSLATED=") + '\n';
meta_var.push_back(str.c_str());
/*
* SRC = Request
* When information is sent using a method of GET, this variable contains the information in a query that follows the "?".
* The string is coded in the standard URL format of changing spaces to "+" and encoding special characters with "%xx" hexadecimal encoding.
* The CGI program must decode this information.
*/
str = std::string("QUERY_STRING=") + '\n';
meta_var.push_back(str.c_str());
/*
* SRC = Request
* Contains the method (as specified with the METHOD attribute in an HTML form) that is
* used to send the request. Example: GET
*/
str = std::string("REQUEST_METHOD=GET") + '\n';
meta_var.push_back(str.c_str());
/*
* SRC = Request
* The path part of the URL that points to the script being executed.
* It should include the leading slash. Example: /cgi-bin/hello.pgm
*/
str = std::string("SCRIPT_NAME=") + '\n';
meta_var.push_back(str.c_str());
/*
* SRC = Conf
* Contains the server host name or IP address of the server. Example: 10.9.8.7
*/
str = std::string("SERVER_NAME=") + '\n';
meta_var.push_back(str.c_str());
/*
* Contains the port number to which the client request was sent.
*/
str = std::string("SERVER_PORT=") + '\n';
meta_var.push_back(str.c_str());
str = "SERVER_PROTOCOL=HTTP/1.1\n";
meta_var.push_back(str.c_str());
str = "SERVER_SOFTWARE=Webserv\n";
meta_var.push_back(str.c_str());
meta_var.push_back(NULL);
return meta_var;
}

int main(void)
{
int fd = open("index.php", O_RDONLY);
pid_t pid;
int pfd[2];

pipe(pfd);
if(!(pid = fork()))
{
std::vector<char const*> meta_var = cgi_meta_var();
std::vector<char const*> args;
std::string path;

args.push_back("/Users/mamoussa/Desktop/brew/bin/php-cgi");
args.push_back(NULL);
path = "/Users/mamoussa/Desktop/brew/bin/php-cgi";
close(pfd[0]);
dup2(fd, 0);
dup2(pfd[1], 1);
if (execve(path.c_str(), const_cast<char *const*>(&(*args.begin()))
, const_cast<char *const*>(&(*meta_var.begin()))) < 0)
{
meta_var.~vector();
args.~vector();
std::cout << strerror(errno) << std::endl;
exit(1);
}
}
wait(&pid);
close(pfd[1]);
std::string ans;
char buff[1024];
int ret = 1;

while ((ret = read(pfd[0], buff, 1024)))
ans += buff;
std::cout << ans << std::endl;
return 0;
}
6 changes: 6 additions & 0 deletions hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<title>hello</title>
</head>
</html>
21 changes: 21 additions & 0 deletions includes/location.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <iostream>
#include <vector>

class Location
{
public:
Location(){}
Location(std::string const& path, std::vector<std::string> const& index, std::vector<std::string> const& allowed):
_path(path), _index(index), _allowed_methods(allowed){}
std::string const& getPath(void) const { return _path; }
std::vector<std::string> getIndex(void) const { return _index; }
std::vector<std::string> getAllowedMethods(void) const { return _allowed_methods; }
std::string & getAutoIndex(void) { return _autoIndex;}
private:
std::string _path;
std::vector<std::string> _index;
std::vector<std::string> _allowed_methods;
std::string _autoIndex;
std::string _cgi_path;
};
Loading