@@ -16,18 +16,18 @@ std::string toUpper(std::string str) {
16
16
return str;
17
17
}
18
18
19
- bool isIpAddress (const std::string& ip) {
20
- int numDots = 0 ;
19
+ bool isip (const std::string& ip) {
20
+ int d = 0 ;
21
21
std::string temp = " " ;
22
22
23
23
for (size_t i = 0 ; i < ip.size (); i++)
24
24
{
25
25
if (ip[i] == ' .' )
26
26
{
27
- numDots ++;
28
- if (numDots > 3 )
27
+ d ++;
28
+ if (d > 3 )
29
29
return 0 ;
30
- if (temp.size () == 0 || std::stoi (temp) > 255 )
30
+ if (temp.size () == 0 || std::stod (temp) > 255 )
31
31
return 0 ;
32
32
temp = " " ;
33
33
}
@@ -36,7 +36,7 @@ bool isIpAddress(const std::string& ip) {
36
36
else
37
37
temp += ip[i];
38
38
}
39
- if (temp.size () == 0 || std::stoi (temp) > 255 || numDots != 3 )
39
+ if (temp.size () == 0 || std::stod (temp) > 255 || d != 3 )
40
40
return 0 ;
41
41
return 1 ;
42
42
}
@@ -75,36 +75,18 @@ int search_char(std::string str, char c)
75
75
int is_number (const std::string& str)
76
76
{
77
77
size_t i = 0 ;
78
- int exp = 0 ;
79
- int digit = 0 ;
80
- int flag = 0 ;
81
78
82
79
for (i = 0 ; i < str.size (); i++)
83
80
{
84
- if (i == 0 && (str[i] == ' +' || str[i] == ' - ' )) {
81
+ if (i == 0 && (str[i] == ' +' )) {
85
82
i++;
86
83
continue ;
87
84
}
88
- if (str[i] == ' e' || str[i] == ' E' ) {
89
- if (exp || !digit) {
90
- return 0 ;
91
- }
92
- exp = 1 ;
93
- if (i + 1 < str.size () && (str[i + 1 ] == ' +' || str[i + 1 ] == ' -' )) {
94
- if (str[i + 1 ] == ' -' )
95
- flag = 1 ;
96
- i++;
97
- }
98
- continue ;
99
- }
100
85
if (!isdigit (str[i]))
101
86
return (0 );
102
- digit = 1 ;
103
87
}
104
- if (i == 1 && (str[0 ] == ' +' || str[ 0 ] == ' - ' ))
88
+ if (i == 1 && (str[0 ] == ' +' ))
105
89
return (0 );
106
- if (flag)
107
- return (-1 );
108
90
return (1 );
109
91
}
110
92
@@ -199,8 +181,7 @@ int is_world(std::string str, std::string tmp)
199
181
}
200
182
201
183
202
- server::server (Data_config data, bool check_location)
203
- : _client_max_body_size(1048576 )
184
+ server::server (Data_config data, bool check_location)
204
185
{
205
186
std::istringstream ss (data.data_server );
206
187
std::string line;
@@ -216,6 +197,7 @@ server::server(Data_config data, bool check_location)
216
197
int c_redirection = 0 ;
217
198
int c_upload = 0 ;
218
199
int c_upload_store = 0 ;
200
+ _client_max_body_size = 0 ;
219
201
while (getline (ss, line))
220
202
{
221
203
if (line.empty () || line[0 ] == ' #' )
@@ -246,23 +228,30 @@ server::server(Data_config data, bool check_location)
246
228
key = toLower (key);
247
229
if (key == " server_name" && check_location)
248
230
{
249
- // if(c_server_name)
250
- // ft_error(line, "Duplicated");
251
231
is_empty_value (value, line);
252
- if (ft_numbers_value (iss) || !isValidServerName (value))
232
+ if (!isValidServerName (value))
253
233
ft_error (line, " Error" );
254
234
std::vector<std::string>::iterator it = std::find (_server_name.begin (), _server_name.end (), value);
255
235
if (it != _server_name.end ())
256
236
ft_error (line, " duplicate server_name" );
257
- c_server_name++;
258
237
_server_name.push_back (value);
238
+ while (iss >> value)
239
+ {
240
+ if (!isValidServerName (value))
241
+ ft_error (line, " Error" );
242
+ std::vector<std::string>::iterator it = std::find (_server_name.begin (), _server_name.end (), value);
243
+ if (it != _server_name.end ())
244
+ ft_error (line, " duplicate server_name" );
245
+ _server_name.push_back (value);
246
+ }
247
+ c_server_name++;
259
248
}
260
249
else if (key == " host" && check_location)
261
250
{
262
251
if (c_host)
263
252
ft_error (line, " Duplicated" );
264
253
is_empty_value (value, line);
265
- if (ft_numbers_value (iss) || (!isIpAddress (value) && value != " localhost" ))
254
+ if (ft_numbers_value (iss) || (!isip (value) && value != " localhost" ))
266
255
ft_error (line, " Error" );
267
256
c_host++;
268
257
_host = value;
@@ -280,6 +269,9 @@ server::server(Data_config data, bool check_location)
280
269
while (iss >> value)
281
270
{
282
271
int port = ft_number (value, line);
272
+ std::vector<int >::iterator it = std::find (_listen.begin (), _listen.end (), port);
273
+ if (it != _listen.end ())
274
+ ft_error (line, " duplicate port" );
283
275
if (port < 1024 || port > 65535 )
284
276
ft_error (line, " Error" );
285
277
_listen.push_back (port);
@@ -433,7 +425,7 @@ server::server(Data_config data, bool check_location)
433
425
if (!c_allow_method && !check_location)
434
426
_allow_methods.push_back (" GET" );
435
427
if (!c_listen && check_location)
436
- _listen.push_back (80 );
428
+ _listen.push_back (8001 );
437
429
if (!c_host && check_location)
438
430
_host = " 127.0.0.1" ;
439
431
if (!c_error_page && check_location)
@@ -450,7 +442,8 @@ server::server(Data_config data, bool check_location)
450
442
_server_name.push_back (" hostname" );
451
443
if (!c_root && check_location)
452
444
_root = " www/html" ;
453
-
445
+ if (!c_client_max_body_size && check_location)
446
+ _client_max_body_size = 1048576 ;
454
447
if (data.location .size ())
455
448
{
456
449
Data_config location_data;
0 commit comments