Skip to content

Commit c3211bb

Browse files
author
Soufiane Nouae
committed
done
1 parent fa65247 commit c3211bb

File tree

7 files changed

+62
-87
lines changed

7 files changed

+62
-87
lines changed

CGI/cgi.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ void set_headers_cgi(std::string output, Respond &res)
3232
if (pos != std::string::npos)
3333
{
3434
std::string key = line.substr(0, pos);
35+
std::cout << key << "\n";
3536
std::string value = line.substr(pos + 2);
37+
std::cout << value << "\n";
3638
res.set_header(key, value);
3739
}
3840
}

config/server.conf

+20-54
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,31 @@
11
server
2-
{
3-
listen 8001;
4-
5-
host 127.0.0.1;
6-
client_max_body_size 100;
7-
8-
9-
error_page 404 www/html/error_pages/404.html;
10-
error_page 403 www/html/error_pages/403.html;
11-
error_page 409 www/html/error_pages/409.html;
12-
error_page 400 www/html/error_pages/400.html;
13-
error_page 405 www/html/error_pages/405.html;
14-
error_page 413 www/html/error_pages/413.html;
15-
error_page 500 www/html/error_pages/500.html;
16-
17-
# index index.html;
18-
19-
location / {
20-
autoindex on;
21-
}
2+
{
223

234
location /cgi_bin
245
{
25-
root ./www/html/cgi_bin;
26-
allow_Methods GET;
27-
28-
allow_Methods POST;
29-
#index hello.html;
6+
7+
root ./www/html;
8+
allow_Methods GET POST;
9+
index hello.html;
3010
path_info .py /usr/bin/python3;
3111
path_info .php /php-cgi;
32-
# listen 8001;
33-
autoindex on;
12+
#listen 8001;
13+
#autoindex on;
3414
}
35-
36-
location /red
37-
{
38-
return 301 http://localhost:8002/;
39-
}
40-
41-
location /delete {
42-
root ./www/html/delete;
43-
allow_methods DELETE;
44-
index todelete;
45-
path_info .py /usr/bin/python3;
15+
location /{
16+
allow_Methods DELETE;
4617
}
47-
48-
location /upload{
49-
root ./www/html/upload;
50-
index upload.html;
51-
allow_methods POST GET;
52-
upload on;
53-
upload_store ./www/html/upload;
54-
#autoindex on;
55-
}
56-
57-
location /getto {
58-
root ./www/html/upload;
59-
# index video.mp4;
60-
allow_methods GET;
61-
autoindex on;
62-
}
18+
# location /cgi_bin
19+
# {
20+
21+
# root ./www/html;
22+
# allow_Methods GET POST;
23+
# index hello.html;
24+
# path_info .py /usr/bin/python3;
25+
# path_info .php /php-cgi;
26+
# #listen 8001;
27+
# #autoindex on;
28+
# }
6329
}
6430
# server
6531
# {

prs_rsc/location.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ std::string extract_path(std::string location_name)
4141

4242
location::location(Data_config data, std::string location_name) : server(data, 0)
4343
{
44+
this->_autoindex = false;
4445
this->location_name = extract_path(location_name);
4546
if(this->location_name.empty())
4647
{

prs_rsc/main.cpp

+2-14
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,8 @@ int main(int ac, char **av)
1515
std::vector<int> all_ports;
1616
servers = ft_fill_servers(av, ac);
1717
all_ports = get_all_ports(servers);
18-
// for (size_t i = 0; i < servers.size(); i++)
19-
// {
20-
// servers[i].display_sever();
21-
// std::cout << "locations :::::::::::::::::::::::::::::::::::::::::::: \n";
22-
// for (size_t j = 0; j < servers[i]._location.size(); j++)
23-
// {
24-
// std::cout << "location : " << servers[i]._location[j].location_name << std::endl;
25-
// servers[i]._location[j].display_sever();
26-
// std::cout << ":::::::::::::::::::::::::::::::::::::::::::: \n";
27-
// }
28-
// std::cout << "++++++++++++++++++++++\n";
29-
// }
30-
// for (size_t i = 0; i < all_ports.size(); i++)
31-
// std::cout << all_ports[i] << "\n";
18+
// for (size_t i = 0; i < all_ports.size(); i++)
19+
// std::cout << all_ports[i] << "\n";
3220
http::http_sever server1(servers);
3321
server1.run();
3422
return (0);

prs_rsc/server.cpp

+28-3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ server::server(Data_config data, bool check_location)
253253
is_empty_value(value, line);
254254
if (ft_numbers_value(iss) || (!isip(value) && value != "localhost"))
255255
ft_error(line, "Error");
256+
if (value == "localhost")
257+
value = "127.0.0.1";
256258
c_host++;
257259
_host = value;
258260
}
@@ -272,7 +274,7 @@ server::server(Data_config data, bool check_location)
272274
std::vector<int>::iterator it = std::find(_listen.begin(), _listen.end(), port);
273275
if(it != _listen.end())
274276
ft_error(line, "duplicate port");
275-
if (port < 1024 || port > 65535)
277+
if (port < 1|| port > 65535)
276278
ft_error(line, "Error");
277279
_listen.push_back(port);
278280
}
@@ -448,7 +450,6 @@ server::server(Data_config data, bool check_location)
448450
{
449451
Data_config location_data;
450452
std::string location_name;
451-
std::ostringstream oss;
452453
for (std::map<std::string, std::string>::iterator it = data.location.begin(); it != data.location.end(); ++it)
453454
{
454455
location_data.data_server = it->second;
@@ -466,6 +467,28 @@ server::server(Data_config data, bool check_location)
466467
_location.push_back(l);
467468
}
468469
}
470+
if(check_location)
471+
{
472+
int c = 0;
473+
for (size_t i = 0; i < _location.size(); i++)
474+
{
475+
if (_location[i].location_name == "/")
476+
{
477+
c = 1;
478+
break ;
479+
}
480+
}
481+
if(!c)
482+
{
483+
Data_config location_data ;
484+
std::string location_name = "location /{";
485+
location_data.data_server = "}";
486+
location l = location(location_data, location_name);
487+
l.fill_rest(*this);
488+
l._autoindex = true;
489+
_location.push_back(l);
490+
}
491+
}
469492
}
470493

471494
void server::display_sever()
@@ -524,7 +547,9 @@ std::vector<std::string> server::get_allow_methods() const
524547

525548
bool server::get_autoindex () const
526549
{
527-
return (_autoindex);
550+
if(!_autoindex)
551+
return (false);
552+
return (true);
528553
}
529554

530555
std::vector<int> &server::get_listen()

prs_rsc/server_utils.cpp

+7-15
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ std::vector<server> ft_fill_servers(char **av, int ac)
117117
map += line + '\n';
118118
if (search_char (line, '}'))
119119
{
120-
c -= search_char(line, '}');
120+
c -= search_char(line, '}');
121+
std::map<std::string, std::string>::const_iterator it = data.location.find(key);
122+
if (it != data.location.end())
123+
{
124+
std::cerr << "Error dupplicate location\n";
125+
exit (1);
126+
}
121127
data.location.insert(std::make_pair(key, map));
122128
map.clear();
123129
break;
@@ -162,21 +168,7 @@ std::vector<server> ft_fill_servers(char **av, int ac)
162168
}
163169
for (size_t i = 0; i < v.size(); i++)
164170
{
165-
c = 0;
166171
server s = server(v[i], 1);
167-
for (size_t i = 0; i < s._location.size(); i++)
168-
{
169-
if (s._location[i].location_name == "/")
170-
{
171-
c = 1;
172-
break ;
173-
}
174-
}
175-
if (c != 1)
176-
{
177-
std::cerr << "Error : missing location root\n";
178-
exit (1);
179-
}
180172
servers.push_back(s);
181173
}
182174
return (servers);

respond/method_utils.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ void Respond::ft_handle_error(int error_code)
202202

203203
void Respond::ft_show_autoindex(std::vector<server> server)
204204
{
205-
//std::cout << "rooted path: " << _rooted_path << std::endl;
205+
std::cout << "rooted path: " << _rooted_path << std::endl;
206+
std::cout << "get root: " << server[_server_index]._location[_location_index].get_root() << std::endl;
206207
std::string index_html = "<!DOCTYPE html>\n<html>\n<head>\n";
207208
index_html += "<meta charset=\"UTF-8\">\n";
208209
index_html += "<title>Index of " + _rooted_path + "</title>\n";

0 commit comments

Comments
 (0)