Skip to content

Commit

Permalink
sync vog
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugothms committed Jan 21, 2022
1 parent 9548e2d commit 1dad612
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 108 deletions.
15 changes: 5 additions & 10 deletions config/base.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
server {
listen 4343
server_name localhost test.com
root www
index index.html
error_page 404 /404.html
error_page 405 /405.html
max_client_body_size 400
listen 4343;
root www/site0;
index index.html;
location / {
allow GET POST DELETE
index index.html
allow GET;
}
}
}
57 changes: 29 additions & 28 deletions config/locations.conf
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
server {
listen 4343;
server_name localhost test.com;
root www/;
cgi .py /usr/bin/python2.7;
cgi .php ./www/cgi-bin/php-cgi;
cgi .php ./cgis/php-cgi;
root www;
index index.html;
error_page 405 /405.html;
max_client_body_size 4096;

max_client_body_size 10;
location / {
allow GET HEAD POST DELETE;
allow GET POST DELETE;
root first;
# index page.html;
}
location /first/ {
allow GET HEAD;
location /one/ {
allow GET DELETE POST;
autoindex 1;
# index page.html;
}
location /demo/ {
allow GET HEAD POST DELETE;
index index.html;
root /site1;
}
# location /first/second/ {
# allow GET;
# # index page.html;
# }
location /blabla/ {
location /two {
allow GET;
# index page.html;
root site2/;
index hello.html;
}
location /three {
allow GET POST DELETE;
root site3/;
index index.html;
}
location /first_redirect/ {
}

server {
listen 6969;
root www;
index index.html;
max_client_body_size 10;
location / {
allow GET;
root first/;
index page.html;
autoindex 1;
}
location /form/ {
allow GET POST;
return 301 http://localhost/form.html;
# index page.html;
location /data/ {
allow GET DELETE;
autoindex 1;
root uploads;
}
}
32 changes: 32 additions & 0 deletions config/servers.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
server {
listen 4344;
server_name foo;
root www/first;
index page.html;
cgi .php ./cgis/php-cgi;
location / {
allow GET;
}
}

server {
listen 4343;
server_name foo;
root www/site1;
index index.html;
cgi .php ./cgis/php-cgi;
location / {
allow GET;
}
}

server {
listen 4343;
server_name bar;
root www/site2;
index index.html;
cgi .php ./cgis/php-cgi;
location / {
allow GET;
}
}
28 changes: 28 additions & 0 deletions config/tricks.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
server {
listen 6969;
cgi .php /usr/bin/php-cgi;
cgi .py /usr/bin/python;
root www;
index index.html;
max_client_body_size -1;
location / {
allow GET;
autoindex 0;
index trick.html;
}
location /php {
allow GET POST;
autoindex 1;
root /site1;
}
location /py {
allow GET POST;
autoindex 1;
root /site2;
}
location /downloads {
allow GET DELETE;
autoindex 1;
root /uploads;
}
}
4 changes: 2 additions & 2 deletions incl/location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Location
string get_path(void) const;
unsigned int get_HTTP_redirection_type(void) const;
string get_HTTP_redirection(void) const;
string get_location_root(void) const;
string get_root(void) const;
string get_index(void) const;
bool get_autoindex(void) const;

Expand All @@ -50,7 +50,7 @@ class Location
void set_path(const string location);
void set_HTTP_redirection_type(const unsigned int type);
void set_HTTP_redirection(const string HTTP_redirection);
void set_location_root(const string location_root);
void set_root(const string location_root);
void set_index(const string index);
void set_autoindex(const bool autoindex);
};
Expand Down
23 changes: 1 addition & 22 deletions srcs/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: edal--ce <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/26 12:07:35 by edal--ce #+# #+# */
/* Updated: 2022/01/20 14:57:24 by edal--ce ### ########.fr */
/* Updated: 2022/01/21 17:41:57 by edal--ce ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -73,40 +73,19 @@ void Client::set_response(void)

if (req && req->get_type() == "POST" && req->get_s_header("Content-Type").find("multipart") != string::npos)
{
// DEBUG("We are in the mode");
// DEBUG("|" << req->get_s_header("Body")<< "|");
if (req->get_s_header("Body").size() != static_cast<unsigned int>(atoi(req->get_s_header("Content-Length").c_str())))
{
// DEBUG("rcb is " << rec_buffer);
// req->get_s_header("Body") += rec_buffer;
// rec_buffer.clear();
// Log("NEED TO GET MORE DATA");
_status = 4;
// DEBUG("We are in the WTF");
return;
}
else
_status = 1;
}

unsigned int ctlen = atoi(req->get_s_header("Content-Length").c_str());
// DEBUG("CTLEN IS " << ctlen);
// DEBUG("CODE IS " << req->get_code());


req->body_size_ok(ctlen);
// todo:
// if (req && ctlen > req->get_max_body() )
// {
// DEBUG("DATA IS TOO BIG");
// r
// req->code = 413;

// // exit(0);
// }
// DEBUG("MAX BODY OK");
// if (req->get_s_header("Content-Length"))

req->set_filepath();
int operation_status = req->get_file_status(_file_fd);
DEBUG("OPSTAT IS " << operation_status);
Expand Down
8 changes: 4 additions & 4 deletions srcs/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: hthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/28 14:04:40 by edal--ce #+# #+# */
/* Updated: 2022/01/19 15:50:08 by hthomas ### ########.fr */
/* Updated: 2022/01/21 16:15:37 by hthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -28,7 +28,7 @@ bool Location::is_valid(string &error) const
list<string> allow = get_allow();
if (allow.size() == 0)
error = (get_path() + " location: allowed method(s) are not set");
if (get_location_root() == "")
if (get_root() == "")
error = (get_path() + " location: location_root is not set");
return (error.length() == 0);
}
Expand Down Expand Up @@ -58,7 +58,7 @@ string Location::get_HTTP_redirection() const
return (this->HTTP_redirection);
}

string Location::get_location_root() const
string Location::get_root() const
{
return (this->location_root);
}
Expand Down Expand Up @@ -102,7 +102,7 @@ void Location::set_HTTP_redirection(const string HTTP_redirection)
this->HTTP_redirection = HTTP_redirection;
}

void Location::set_location_root(const string location_root)
void Location::set_root(const string location_root)
{
this->location_root = location_root;
}
Expand Down
8 changes: 4 additions & 4 deletions srcs/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: hthomas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/05 16:55:59 by hthomas #+# #+# */
/* Updated: 2022/01/20 18:05:02 by hthomas ### ########.fr */
/* Updated: 2022/01/21 16:15:37 by hthomas ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -84,7 +84,7 @@ Location parse_location(const vector<string> &config, size_t *line_count, Server
tmp = '/' + tmp;
if (tmp.size() > 1 && tmp[tmp.size() - 1] == '/')
tmp.resize(tmp.size() - 1);
location.set_location_root(tmp);
location.set_root(tmp);
DEBUG("\t\t\t" << tmp);
}
else if (line[0] == "index")
Expand Down Expand Up @@ -118,8 +118,8 @@ Location parse_location(const vector<string> &config, size_t *line_count, Server
exit(EXIT_FAILURE);
}
DEBUG("\t}");
if (location.get_location_root().size() == 0)
location.set_location_root(location.get_path());
if (location.get_root().size() == 0)
location.set_root(location.get_path());
location.set_server(server);
return location;
}
Expand Down
Loading

0 comments on commit 1dad612

Please sign in to comment.