Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
c658a54d
Commit
c658a54d
authored
Mar 20, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changed set_absolute_path() signature
parent
a514e143
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
17 deletions
+31
-17
server.c
examples/server.c
+31
-17
No files found.
examples/server.c
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment