Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Gitlab has been updated. More info
here
.
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
83a9a726
Commit
83a9a726
authored
11 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Checking path existence
parent
8ae0400b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/server.c
+26
-11
26 additions, 11 deletions
examples/server.c
with
26 additions
and
11 deletions
examples/server.c
+
26
−
11
View file @
83a9a726
...
@@ -77,6 +77,8 @@ static int exit_flag;
...
@@ -77,6 +77,8 @@ static int exit_flag;
static
char
server_name
[
50
];
// Set by init_server_name()
static
char
server_name
[
50
];
// Set by init_server_name()
static
char
config_file
[
PATH_MAX
];
// Set by process_command_line_arguments()
static
char
config_file
[
PATH_MAX
];
// Set by process_command_line_arguments()
static
struct
mg_server
*
server
;
// Set by start_mongoose()
static
struct
mg_server
*
server
;
// Set by start_mongoose()
static
const
char
*
s_default_document_root
=
"."
;
static
const
char
*
s_default_listening_port
=
"8080"
;
#if !defined(CONFIG_FILE)
#if !defined(CONFIG_FILE)
#define CONFIG_FILE "mongoose.conf"
#define CONFIG_FILE "mongoose.conf"
...
@@ -263,16 +265,18 @@ static char *get_option(char **options, const char *option_name) {
...
@@ -263,16 +265,18 @@ static char *get_option(char **options, const char *option_name) {
return
NULL
;
return
NULL
;
}
}
static
void
verify_existence
(
char
**
options
,
const
char
*
option_name
,
static
int
path_exists
(
const
char
*
path
,
int
is_dir
)
{
int
must_be_dir
)
{
file_stat_t
st
;
file_stat_t
st
;
const
char
*
path
=
get_option
(
options
,
option_name
);
return
path
==
NULL
||
(
stat
(
path
,
&
st
)
==
0
&&
((
S_ISDIR
(
st
.
st_mode
)
?
1
:
0
)
==
is_dir
));
}
if
(
path
!=
NULL
&&
(
stat
(
path
,
&
st
)
!=
0
||
static
void
verify_existence
(
char
**
options
,
const
char
*
name
,
int
is_dir
)
{
((
S_ISDIR
(
st
.
st_mode
)
?
1
:
0
)
!=
must_be_dir
)))
{
const
char
*
path
=
get_option
(
options
,
name
);
if
(
!
path_exists
(
path
,
is_dir
))
{
notify
(
"Invalid path for %s: [%s]: (%s). Make sure that path is either "
notify
(
"Invalid path for %s: [%s]: (%s). Make sure that path is either "
"absolute, or it is relative to mongoose executable."
,
"absolute, or it is relative to mongoose executable."
,
option_
name
,
path
,
strerror
(
errno
));
name
,
path
,
strerror
(
errno
));
}
}
}
}
...
@@ -396,8 +400,8 @@ static void start_mongoose(int argc, char *argv[]) {
...
@@ -396,8 +400,8 @@ static void start_mongoose(int argc, char *argv[]) {
}
}
options
[
0
]
=
NULL
;
options
[
0
]
=
NULL
;
set_option
(
options
,
"document_root"
,
"."
);
set_option
(
options
,
"document_root"
,
s_default_document_root
);
set_option
(
options
,
"listening_port"
,
"8080"
);
set_option
(
options
,
"listening_port"
,
s_default_listening_port
);
// Update config based on command line arguments
// Update config based on command line arguments
process_command_line_arguments
(
argv
,
options
);
process_command_line_arguments
(
argv
,
options
);
...
@@ -405,13 +409,19 @@ static void start_mongoose(int argc, char *argv[]) {
...
@@ -405,13 +409,19 @@ static void start_mongoose(int argc, char *argv[]) {
// Make sure we have absolute paths for files and directories
// Make sure we have absolute paths for files and directories
// https://github.com/valenok/mongoose/issues/181
// https://github.com/valenok/mongoose/issues/181
set_absolute_path
(
options
,
"document_root"
,
argv
[
0
]);
set_absolute_path
(
options
,
"document_root"
,
argv
[
0
]);
set_absolute_path
(
options
,
"
put_delete
_auth_file"
,
argv
[
0
]);
set_absolute_path
(
options
,
"
dav
_auth_file"
,
argv
[
0
]);
set_absolute_path
(
options
,
"cgi_interpreter"
,
argv
[
0
]);
set_absolute_path
(
options
,
"cgi_interpreter"
,
argv
[
0
]);
set_absolute_path
(
options
,
"access_log_file"
,
argv
[
0
]);
set_absolute_path
(
options
,
"access_log_file"
,
argv
[
0
]);
set_absolute_path
(
options
,
"error_log_file"
,
argv
[
0
]);
set_absolute_path
(
options
,
"global_auth_file"
,
argv
[
0
]);
set_absolute_path
(
options
,
"global_auth_file"
,
argv
[
0
]);
set_absolute_path
(
options
,
"ssl_certificate"
,
argv
[
0
]);
set_absolute_path
(
options
,
"ssl_certificate"
,
argv
[
0
]);
if
(
!
path_exists
(
get_option
(
options
,
"document_root"
),
1
))
{
set_option
(
options
,
"document_root"
,
s_default_document_root
);
set_absolute_path
(
options
,
"document_root"
,
argv
[
0
]);
notify
(
"Setting document_root to [%s]"
,
mg_get_option
(
server
,
"document_root"
));
}
// Make extra verification for certain options
// Make extra verification for certain options
verify_existence
(
options
,
"document_root"
,
1
);
verify_existence
(
options
,
"document_root"
,
1
);
verify_existence
(
options
,
"cgi_interpreter"
,
0
);
verify_existence
(
options
,
"cgi_interpreter"
,
0
);
...
@@ -420,7 +430,12 @@ static void start_mongoose(int argc, char *argv[]) {
...
@@ -420,7 +430,12 @@ static void start_mongoose(int argc, char *argv[]) {
for
(
i
=
0
;
options
[
i
]
!=
NULL
;
i
+=
2
)
{
for
(
i
=
0
;
options
[
i
]
!=
NULL
;
i
+=
2
)
{
const
char
*
msg
=
mg_set_option
(
server
,
options
[
i
],
options
[
i
+
1
]);
const
char
*
msg
=
mg_set_option
(
server
,
options
[
i
],
options
[
i
+
1
]);
if
(
msg
!=
NULL
)
{
if
(
msg
!=
NULL
)
{
notify
(
"Failed to set option [%s]: %s"
,
options
[
i
],
msg
);
notify
(
"Failed to set option [%s] to [%s]: %s"
,
options
[
i
],
options
[
i
+
1
],
msg
);
if
(
!
strcmp
(
options
[
i
],
"listening_port"
))
{
mg_set_option
(
server
,
"listening_port"
,
s_default_listening_port
);
notify
(
"Setting %s to [%s]"
,
options
[
i
],
s_default_listening_port
);
}
}
}
free
(
options
[
i
]);
free
(
options
[
i
]);
free
(
options
[
i
+
1
]);
free
(
options
[
i
+
1
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment