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
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
c658a54d
Commit
c658a54d
authored
11 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
changed set_absolute_path() signature
parent
a514e143
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/server.c
+31
-17
31 additions, 17 deletions
examples/server.c
with
31 additions
and
17 deletions
examples/server.c
+
31
−
17
View file @
c658a54d
...
...
@@ -67,6 +67,11 @@ typedef struct _stat file_stat_t;
typedef
struct
stat
file_stat_t
;
#include
<sys/wait.h>
#include
<unistd.h>
#ifdef IOS
#include
<ifaddrs.h>
#endif
#define DIRSEP '/'
#define __cdecl
#define abs_path(rel, abs, abs_size) realpath((rel), (abs))
...
...
@@ -75,6 +80,10 @@ typedef struct stat file_stat_t;
#define MAX_OPTIONS 100
#define MAX_CONF_FILE_LINE_SIZE (8 * 1024)
#ifndef MVER
#define MVER MONGOOSE_VERSION
#endif
static
int
exit_flag
;
static
char
server_name
[
50
];
// Set by init_server_name()
static
char
config_file
[
PATH_MAX
];
// Set by process_command_line_arguments()
...
...
@@ -131,7 +140,7 @@ static void show_usage_and_exit(void) {
int
i
;
fprintf
(
stderr
,
"Mongoose version %s (c) Sergey Lyubka, built on %s
\n
"
,
M
ONGOOSE_VERSION
,
__DATE__
);
M
VER
,
__DATE__
);
fprintf
(
stderr
,
"Usage:
\n
"
);
#ifndef MONGOOSE_NO_AUTH
fprintf
(
stderr
,
" mongoose -A <htpasswd_file> <realm> <user> <passwd>
\n
"
);
...
...
@@ -246,7 +255,7 @@ static void process_command_line_arguments(char *argv[], char **options) {
static
void
init_server_name
(
void
)
{
const
char
*
descr
=
""
;
snprintf
(
server_name
,
sizeof
(
server_name
),
"Mongoose web server v.%s%s"
,
M
ONGOOSE_VERSION
,
descr
);
M
VER
,
descr
);
}
static
int
is_path_absolute
(
const
char
*
path
)
{
...
...
@@ -269,6 +278,14 @@ static char *get_option(char **options, const char *option_name) {
return
NULL
;
}
static
void
*
serving_thread_func
(
void
*
param
)
{
struct
mg_server
*
srv
=
(
struct
mg_server
*
)
param
;
while
(
exit_flag
==
0
)
{
mg_poll_server
(
srv
,
1000
);
}
return
NULL
;
}
static
int
path_exists
(
const
char
*
path
,
int
is_dir
)
{
file_stat_t
st
;
return
path
==
NULL
||
(
stat
(
path
,
&
st
)
==
0
&&
...
...
@@ -284,8 +301,7 @@ static void verify_existence(char **options, const char *name, int is_dir) {
}
}
static
void
set_absolute_path
(
char
*
options
[],
const
char
*
option_name
,
const
char
*
path_to_mongoose_exe
)
{
static
void
set_absolute_path
(
char
*
options
[],
const
char
*
option_name
)
{
char
path
[
PATH_MAX
],
abs
[
PATH_MAX
],
*
option_value
;
const
char
*
p
;
...
...
@@ -298,11 +314,11 @@ static void set_absolute_path(char *options[], const char *option_name,
// Not absolute. Use the directory where mongoose executable lives
// be the relative directory for everything.
// Extract mongoose executable directory into path.
if
((
p
=
strrchr
(
path_to_mongoose_ex
e
,
DIRSEP
))
==
NULL
)
{
if
((
p
=
strrchr
(
config_fil
e
,
DIRSEP
))
==
NULL
)
{
getcwd
(
path
,
sizeof
(
path
));
}
else
{
snprintf
(
path
,
sizeof
(
path
),
"%.*s"
,
(
int
)
(
p
-
path_to_mongoose_ex
e
),
path_to_mongoose_ex
e
);
snprintf
(
path
,
sizeof
(
path
),
"%.*s"
,
(
int
)
(
p
-
config_fil
e
),
config_fil
e
);
}
strncat
(
path
,
"/"
,
sizeof
(
path
)
-
1
);
...
...
@@ -412,16 +428,16 @@ static void start_mongoose(int argc, char *argv[]) {
// Make sure we have absolute paths for files and directories
// https://github.com/valenok/mongoose/issues/181
set_absolute_path
(
options
,
"document_root"
,
argv
[
0
]
);
set_absolute_path
(
options
,
"dav_auth_file"
,
argv
[
0
]
);
set_absolute_path
(
options
,
"cgi_interpreter"
,
argv
[
0
]
);
set_absolute_path
(
options
,
"access_log_file"
,
argv
[
0
]
);
set_absolute_path
(
options
,
"global_auth_file"
,
argv
[
0
]
);
set_absolute_path
(
options
,
"ssl_certificate"
,
argv
[
0
]
);
set_absolute_path
(
options
,
"document_root"
);
set_absolute_path
(
options
,
"dav_auth_file"
);
set_absolute_path
(
options
,
"cgi_interpreter"
);
set_absolute_path
(
options
,
"access_log_file"
);
set_absolute_path
(
options
,
"global_auth_file"
);
set_absolute_path
(
options
,
"ssl_certificate"
);
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
]
);
set_absolute_path
(
options
,
"document_root"
);
notify
(
"Setting document_root to [%s]"
,
mg_get_option
(
server
,
"document_root"
));
}
...
...
@@ -472,9 +488,7 @@ int main(int argc, char *argv[]) {
server_name
,
mg_get_option
(
server
,
"document_root"
),
mg_get_option
(
server
,
"listening_port"
));
fflush
(
stdout
);
// Needed, Windows terminals might not be line-buffered
while
(
exit_flag
==
0
)
{
mg_poll_server
(
server
,
1000
);
}
serving_thread_func
(
server
);
printf
(
"Exiting on signal %d ..."
,
exit_flag
);
fflush
(
stdout
);
mg_destroy_server
(
&
server
);
...
...
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