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
d86d409d
Commit
d86d409d
authored
Jan 20, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preprocessor definitions prefixed by MONGOOSE_
parent
1109d3aa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
102 deletions
+106
-102
Embed.md
docs/Embed.md
+19
-13
mongoose.c
mongoose.c
+86
-86
unit_test.c
unit_test.c
+1
-3
No files found.
docs/Embed.md
View file @
d86d409d
...
@@ -73,19 +73,25 @@ could be enabled by setting appropriate `USE_*` flag. Bare bones Mongoose
...
@@ -73,19 +73,25 @@ could be enabled by setting appropriate `USE_*` flag. Bare bones Mongoose
is quite small, about 30 kilobytes of compiled x86 code. Each feature adds
is quite small, about 30 kilobytes of compiled x86 code. Each feature adds
a couple of kilobytes to the executable size, and also has some runtime penalty.
a couple of kilobytes to the executable size, and also has some runtime penalty.
-DNO_AUTH Disable MD5 authorization support
-DMONGOOSE_NO_AUTH Disable MD5 authorization support
-DNO_CGI Disable CGI support
-DMONGOOSE_NO_CGI Disable CGI support
-DNO_DAV Disable WebDAV support (PUT, DELETE, MKCOL, PROPFIND)
-DMONGOOSE_NO_DAV Disable WebDAV support
-DNO_DIRECTORY_LISTING Disable directory listing
(PUT, DELETE, MKCOL, PROPFIND methods)
-DNO_LOGGING Disable access/error logging
-DMONGOOSE_NO_DIRECTORY_LISTING Disable directory listing
-DNO_WEBSOCKET Disable WebSocket support
-DMONGOOSE_NO_FILESYSTEM Disables all file IO, serving from memory only
-DMONGOOSE_NO_LOGGING Disable access/error logging
-DUSE_IPV6 Enable IPv6 support
-DMONGOOSE_NO_THREADS
-DUSE_LUA Enable Lua scripting
-DMONGOOSE_NO_WEBSOCKET Disable WebSocket support
-DUSE_LUA_SQLITE3 Enable sqlite3 binding for Lua
-DUSE_SSL Enable SSL
-DMONGOOSE_USE_IDLE_TIMEOUT_SECONDS=X Idle connection timeout, default is 30
-DUSE_POST_SIZE_LIMIT=X POST requests larger than X will be rejected
-DMONGOOSE_USE_IPV6 Enable IPv6 support
-DUSE_EXTRA_HTTP_HEADERS=X Append X to the HTTP headers for static files
-DMONGOOSE_USE_LUA Enable Lua scripting
-DMONGOOSE_USE_LUA_SQLITE3 Enable sqlite3 binding for Lua
-DMONGOOSE_USE_SSL Enable SSL
-DMONGOOSE_USE_POST_SIZE_LIMIT=X POST requests larger than X will be
rejected, not set by default
-DMONGOOSE_USE_EXTRA_HTTP_HEADERS=X Append X to the HTTP headers
for static files, empty by default
Mongoose source code contains a well-commented example code, listed below:
Mongoose source code contains a well-commented example code, listed below:
...
...
mongoose.c
View file @
d86d409d
...
@@ -98,7 +98,7 @@ typedef struct _stati64 file_stat_t;
...
@@ -98,7 +98,7 @@ typedef struct _stati64 file_stat_t;
#include <signal.h>
#include <signal.h>
#include <unistd.h>
#include <unistd.h>
#include <netdb.h>
#include <netdb.h>
#include <arpa/inet.h> // For inet_pton() when USE_IPV6 is defined
#include <arpa/inet.h> // For inet_pton() when
MONGOOSE_
USE_IPV6 is defined
#include <netinet/in.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/select.h>
...
@@ -118,7 +118,7 @@ typedef struct stat file_stat_t;
...
@@ -118,7 +118,7 @@ typedef struct stat file_stat_t;
#define O_BINARY 0
#define O_BINARY 0
#endif
#endif
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
#ifdef __APPLE__
#ifdef __APPLE__
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
#endif
...
@@ -151,21 +151,21 @@ struct ll { struct ll *prev, *next; };
...
@@ -151,21 +151,21 @@ struct ll { struct ll *prev, *next; };
#define ENV_EXPORT_TO_CGI "MONGOOSE_CGI"
#define ENV_EXPORT_TO_CGI "MONGOOSE_CGI"
#define PASSWORDS_FILE_NAME ".htpasswd"
#define PASSWORDS_FILE_NAME ".htpasswd"
#ifndef USE_WEBSOCKET_PING_INTERVAL
#ifndef
MONGOOSE_
USE_WEBSOCKET_PING_INTERVAL
#define USE_WEBSOCKET_PING_INTERVAL 5
#define
MONGOOSE_
USE_WEBSOCKET_PING_INTERVAL 5
#endif
#endif
// Extra HTTP headers to send in every static file reply
// Extra HTTP headers to send in every static file reply
#if !defined(USE_EXTRA_HTTP_HEADERS)
#if !defined(
MONGOOSE_
USE_EXTRA_HTTP_HEADERS)
#define USE_EXTRA_HTTP_HEADERS ""
#define
MONGOOSE_
USE_EXTRA_HTTP_HEADERS ""
#endif
#endif
#ifndef USE_POST_SIZE_LIMIT
#ifndef
MONGOOSE_
USE_POST_SIZE_LIMIT
#define USE_POST_SIZE_LIMIT 0
#define
MONGOOSE_
USE_POST_SIZE_LIMIT 0
#endif
#endif
#ifndef USE_IDLE_TIMEOUT_SECONDS
#ifndef
MONGOOSE_
USE_IDLE_TIMEOUT_SECONDS
#define USE_IDLE_TIMEOUT_SECONDS 30
#define
MONGOOSE_
USE_IDLE_TIMEOUT_SECONDS 30
#endif
#endif
#ifdef ENABLE_DBG
#ifdef ENABLE_DBG
...
@@ -175,18 +175,18 @@ struct ll { struct ll *prev, *next; };
...
@@ -175,18 +175,18 @@ struct ll { struct ll *prev, *next; };
#define DBG(x)
#define DBG(x)
#endif
#endif
#ifdef NO_FILESYSTEM
#ifdef
MONGOOSE_
NO_FILESYSTEM
#define NO_AUTH
#define
MONGOOSE_
NO_AUTH
#define NO_CGI
#define
MONGOOSE_
NO_CGI
#define NO_DAV
#define
MONGOOSE_
NO_DAV
#define NO_DIRECTORY_LISTING
#define
MONGOOSE_
NO_DIRECTORY_LISTING
#define NO_LOGGING
#define
MONGOOSE_
NO_LOGGING
#endif
#endif
union
socket_address
{
union
socket_address
{
struct
sockaddr
sa
;
struct
sockaddr
sa
;
struct
sockaddr_in
sin
;
struct
sockaddr_in
sin
;
#ifdef USE_IPV6
#ifdef
MONGOOSE_
USE_IPV6
struct
sockaddr_in6
sin6
;
struct
sockaddr_in6
sin6
;
#endif
#endif
};
};
...
@@ -212,23 +212,23 @@ struct dir_entry {
...
@@ -212,23 +212,23 @@ struct dir_entry {
// NOTE(lsm): this enum shoulds be in sync with the config_options.
// NOTE(lsm): this enum shoulds be in sync with the config_options.
enum
{
enum
{
ACCESS_CONTROL_LIST
,
ACCESS_CONTROL_LIST
,
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
ACCESS_LOG_FILE
,
AUTH_DOMAIN
,
CGI_INTERPRETER
,
ACCESS_LOG_FILE
,
AUTH_DOMAIN
,
CGI_INTERPRETER
,
CGI_PATTERN
,
DAV_AUTH_FILE
,
DOCUMENT_ROOT
,
ENABLE_DIRECTORY_LISTING
,
CGI_PATTERN
,
DAV_AUTH_FILE
,
DOCUMENT_ROOT
,
ENABLE_DIRECTORY_LISTING
,
#endif
#endif
EXTRA_MIME_TYPES
,
EXTRA_MIME_TYPES
,
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
GLOBAL_AUTH_FILE
,
GLOBAL_AUTH_FILE
,
#endif
#endif
HIDE_FILES_PATTERN
,
HIDE_FILES_PATTERN
,
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
INDEX_FILES
,
INDEX_FILES
,
#endif
#endif
LISTENING_PORT
,
LISTENING_PORT
,
#ifndef _WIN32
#ifndef _WIN32
RUN_AS_USER
,
RUN_AS_USER
,
#endif
#endif
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
SSL_CERTIFICATE
,
SSL_CERTIFICATE
,
#endif
#endif
URL_REWRITES
,
NUM_OPTIONS
URL_REWRITES
,
NUM_OPTIONS
...
@@ -236,7 +236,7 @@ enum {
...
@@ -236,7 +236,7 @@ enum {
static
const
char
*
static_config_options
[]
=
{
static
const
char
*
static_config_options
[]
=
{
"access_control_list"
,
NULL
,
"access_control_list"
,
NULL
,
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
"access_log_file"
,
NULL
,
"access_log_file"
,
NULL
,
"auth_domain"
,
"mydomain.com"
,
"auth_domain"
,
"mydomain.com"
,
"cgi_interpreter"
,
NULL
,
"cgi_interpreter"
,
NULL
,
...
@@ -246,18 +246,18 @@ static const char *static_config_options[] = {
...
@@ -246,18 +246,18 @@ static const char *static_config_options[] = {
"enable_directory_listing"
,
"yes"
,
"enable_directory_listing"
,
"yes"
,
#endif
#endif
"extra_mime_types"
,
NULL
,
"extra_mime_types"
,
NULL
,
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
"global_auth_file"
,
NULL
,
"global_auth_file"
,
NULL
,
#endif
#endif
"hide_files_patterns"
,
NULL
,
"hide_files_patterns"
,
NULL
,
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
"index_files"
,
"index.html,index.htm,index.cgi,index.php,index.lp"
,
"index_files"
,
"index.html,index.htm,index.cgi,index.php,index.lp"
,
#endif
#endif
"listening_port"
,
NULL
,
"listening_port"
,
NULL
,
#ifndef _WIN32
#ifndef _WIN32
"run_as_user"
,
NULL
,
"run_as_user"
,
NULL
,
#endif
#endif
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
"ssl_certificate"
,
NULL
,
"ssl_certificate"
,
NULL
,
#endif
#endif
"url_rewrites"
,
NULL
,
"url_rewrites"
,
NULL
,
...
@@ -272,7 +272,7 @@ struct mg_server {
...
@@ -272,7 +272,7 @@ struct mg_server {
mg_handler_t
error_handler
;
mg_handler_t
error_handler
;
char
*
config_options
[
NUM_OPTIONS
];
char
*
config_options
[
NUM_OPTIONS
];
void
*
server_data
;
void
*
server_data
;
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
SSL_CTX
*
ssl_ctx
;
// Server SSL context
SSL_CTX
*
ssl_ctx
;
// Server SSL context
SSL_CTX
*
client_ssl_ctx
;
// Client SSL context
SSL_CTX
*
client_ssl_ctx
;
// Client SSL context
#endif
#endif
...
@@ -324,7 +324,7 @@ struct connection {
...
@@ -324,7 +324,7 @@ struct connection {
int
request_len
;
// Request length, including last \r\n after last header
int
request_len
;
// Request length, including last \r\n after last header
int
flags
;
// CONN_* flags: CONN_CLOSE, CONN_SPOOL_DONE, etc
int
flags
;
// CONN_* flags: CONN_CLOSE, CONN_SPOOL_DONE, etc
mg_handler_t
handler
;
// Callback for HTTP client
mg_handler_t
handler
;
// Callback for HTTP client
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
SSL
*
ssl
;
// SSL descriptor
SSL
*
ssl
;
// SSL descriptor
#endif
#endif
};
};
...
@@ -386,7 +386,7 @@ static const struct {
...
@@ -386,7 +386,7 @@ static const struct {
{
NULL
,
0
,
NULL
}
{
NULL
,
0
,
NULL
}
};
};
#ifndef NO_THREADS
#ifndef
MONGOOSE_
NO_THREADS
void
*
mg_start_thread
(
void
*
(
*
f
)(
void
*
),
void
*
p
)
{
void
*
mg_start_thread
(
void
*
(
*
f
)(
void
*
),
void
*
p
)
{
#ifdef _WIN32
#ifdef _WIN32
return
(
void
*
)
_beginthread
((
void
(
__cdecl
*
)(
void
*
))
f
,
0
,
p
);
return
(
void
*
)
_beginthread
((
void
(
__cdecl
*
)(
void
*
))
f
,
0
,
p
);
...
@@ -397,7 +397,7 @@ void *mg_start_thread(void *(*f)(void *), void *p) {
...
@@ -397,7 +397,7 @@ void *mg_start_thread(void *(*f)(void *), void *p) {
(
void
)
pthread_attr_init
(
&
attr
);
(
void
)
pthread_attr_init
(
&
attr
);
(
void
)
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
(
void
)
pthread_attr_setdetachstate
(
&
attr
,
PTHREAD_CREATE_DETACHED
);
#if USE_STACK_SIZE > 1
#if
MONGOOSE_
USE_STACK_SIZE > 1
// Compile-time option to control stack size, e.g. -DUSE_STACK_SIZE=16384
// Compile-time option to control stack size, e.g. -DUSE_STACK_SIZE=16384
(
void
)
pthread_attr_setstacksize
(
&
attr
,
USE_STACK_SIZE
);
(
void
)
pthread_attr_setstacksize
(
&
attr
,
USE_STACK_SIZE
);
#endif
#endif
...
@@ -408,7 +408,7 @@ void *mg_start_thread(void *(*f)(void *), void *p) {
...
@@ -408,7 +408,7 @@ void *mg_start_thread(void *(*f)(void *), void *p) {
return
(
void
*
)
thread_id
;
return
(
void
*
)
thread_id
;
#endif
#endif
}
}
#endif // NO_THREADS
#endif //
MONGOOSE_
NO_THREADS
#ifdef _WIN32
#ifdef _WIN32
// Encode 'path' which is assumed UTF-8 string, into UNICODE string.
// Encode 'path' which is assumed UTF-8 string, into UNICODE string.
...
@@ -800,7 +800,7 @@ static void discard_leading_iobuf_bytes(struct iobuf *io, int n) {
...
@@ -800,7 +800,7 @@ static void discard_leading_iobuf_bytes(struct iobuf *io, int n) {
}
}
}
}
#ifndef NO_CGI
#ifndef
MONGOOSE_
NO_CGI
#ifdef _WIN32
#ifdef _WIN32
struct
threadparam
{
struct
threadparam
{
sock_t
s
;
sock_t
s
;
...
@@ -1069,7 +1069,7 @@ static void prepare_cgi_environment(struct connection *conn,
...
@@ -1069,7 +1069,7 @@ static void prepare_cgi_environment(struct connection *conn,
addenv
(
blk
,
"SCRIPT_FILENAME=%s"
,
prog
);
addenv
(
blk
,
"SCRIPT_FILENAME=%s"
,
prog
);
addenv
(
blk
,
"PATH_TRANSLATED=%s"
,
prog
);
addenv
(
blk
,
"PATH_TRANSLATED=%s"
,
prog
);
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
addenv
(
blk
,
"HTTPS=%s"
,
conn
->
ssl
!=
NULL
?
"on"
:
"off"
);
addenv
(
blk
,
"HTTPS=%s"
,
conn
->
ssl
!=
NULL
?
"on"
:
"off"
);
#else
#else
addenv
(
blk
,
"HTTPS=%s"
,
"off"
);
addenv
(
blk
,
"HTTPS=%s"
,
"off"
);
...
@@ -1202,7 +1202,7 @@ static void forward_post_data(struct connection *conn) {
...
@@ -1202,7 +1202,7 @@ static void forward_post_data(struct connection *conn) {
int
n
=
send
(
conn
->
endpoint
.
cgi_sock
,
io
->
buf
,
io
->
len
,
0
);
int
n
=
send
(
conn
->
endpoint
.
cgi_sock
,
io
->
buf
,
io
->
len
,
0
);
discard_leading_iobuf_bytes
(
io
,
n
);
discard_leading_iobuf_bytes
(
io
,
n
);
}
}
#endif // !NO_CGI
#endif // !
MONGOOSE_
NO_CGI
// 'sa' must be an initialized address to bind to
// 'sa' must be an initialized address to bind to
static
sock_t
open_listening_socket
(
union
socket_address
*
sa
)
{
static
sock_t
open_listening_socket
(
union
socket_address
*
sa
)
{
...
@@ -1275,7 +1275,7 @@ static int check_acl(const char *acl, uint32_t remote_ip) {
...
@@ -1275,7 +1275,7 @@ static int check_acl(const char *acl, uint32_t remote_ip) {
static
void
sockaddr_to_string
(
char
*
buf
,
size_t
len
,
static
void
sockaddr_to_string
(
char
*
buf
,
size_t
len
,
const
union
socket_address
*
usa
)
{
const
union
socket_address
*
usa
)
{
buf
[
0
]
=
'\0'
;
buf
[
0
]
=
'\0'
;
#if defined(USE_IPV6)
#if defined(
MONGOOSE_
USE_IPV6)
inet_ntop
(
usa
->
sa
.
sa_family
,
usa
->
sa
.
sa_family
==
AF_INET
?
inet_ntop
(
usa
->
sa
.
sa_family
,
usa
->
sa
.
sa_family
==
AF_INET
?
(
void
*
)
&
usa
->
sin
.
sin_addr
:
(
void
*
)
&
usa
->
sin
.
sin_addr
:
(
void
*
)
&
usa
->
sin6
.
sin6_addr
,
buf
,
len
);
(
void
*
)
&
usa
->
sin6
.
sin6_addr
,
buf
,
len
);
...
@@ -1301,7 +1301,7 @@ static struct connection *accept_new_connection(struct mg_server *server) {
...
@@ -1301,7 +1301,7 @@ static struct connection *accept_new_connection(struct mg_server *server) {
closesocket
(
sock
);
closesocket
(
sock
);
}
else
if
((
conn
=
(
struct
connection
*
)
calloc
(
1
,
sizeof
(
*
conn
)))
==
NULL
)
{
}
else
if
((
conn
=
(
struct
connection
*
)
calloc
(
1
,
sizeof
(
*
conn
)))
==
NULL
)
{
closesocket
(
sock
);
closesocket
(
sock
);
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
}
else
if
(
server
->
ssl_ctx
!=
NULL
&&
}
else
if
(
server
->
ssl_ctx
!=
NULL
&&
((
conn
->
ssl
=
SSL_new
(
server
->
ssl_ctx
))
==
NULL
||
((
conn
->
ssl
=
SSL_new
(
server
->
ssl_ctx
))
==
NULL
||
SSL_set_fd
(
conn
->
ssl
,
sock
)
!=
1
))
{
SSL_set_fd
(
conn
->
ssl
,
sock
)
!=
1
))
{
...
@@ -1335,7 +1335,7 @@ static void close_conn(struct connection *conn) {
...
@@ -1335,7 +1335,7 @@ static void close_conn(struct connection *conn) {
free
(
conn
->
path_info
);
free
(
conn
->
path_info
);
free
(
conn
->
remote_iobuf
.
buf
);
free
(
conn
->
remote_iobuf
.
buf
);
free
(
conn
->
local_iobuf
.
buf
);
free
(
conn
->
local_iobuf
.
buf
);
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
if
(
conn
->
ssl
!=
NULL
)
SSL_free
(
conn
->
ssl
);
if
(
conn
->
ssl
!=
NULL
)
SSL_free
(
conn
->
ssl
);
#endif
#endif
free
(
conn
);
free
(
conn
);
...
@@ -1474,7 +1474,7 @@ const char *mg_get_header(const struct mg_connection *ri, const char *s) {
...
@@ -1474,7 +1474,7 @@ const char *mg_get_header(const struct mg_connection *ri, const char *s) {
return
NULL
;
return
NULL
;
}
}
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
// Perform case-insensitive match of string against pattern
// Perform case-insensitive match of string against pattern
static
int
match_prefix
(
const
char
*
pattern
,
int
pattern_len
,
const
char
*
str
)
{
static
int
match_prefix
(
const
char
*
pattern
,
int
pattern_len
,
const
char
*
str
)
{
const
char
*
or_str
;
const
char
*
or_str
;
...
@@ -1540,7 +1540,7 @@ static int convert_uri_to_file_name(struct connection *conn, char *buf,
...
@@ -1540,7 +1540,7 @@ static int convert_uri_to_file_name(struct connection *conn, char *buf,
if
(
stat
(
buf
,
st
)
==
0
)
return
1
;
if
(
stat
(
buf
,
st
)
==
0
)
return
1
;
#ifndef NO_CGI
#ifndef
MONGOOSE_
NO_CGI
// Support PATH_INFO for CGI scripts.
// Support PATH_INFO for CGI scripts.
for
(
p
=
buf
+
strlen
(
root
)
+
2
;
*
p
!=
'\0'
;
p
++
)
{
for
(
p
=
buf
+
strlen
(
root
)
+
2
;
*
p
!=
'\0'
;
p
++
)
{
if
(
*
p
==
'/'
)
{
if
(
*
p
==
'/'
)
{
...
@@ -1559,7 +1559,7 @@ static int convert_uri_to_file_name(struct connection *conn, char *buf,
...
@@ -1559,7 +1559,7 @@ static int convert_uri_to_file_name(struct connection *conn, char *buf,
return
0
;
return
0
;
}
}
#endif // NO_FILESYSTEM
#endif //
MONGOOSE_
NO_FILESYSTEM
static
int
should_keep_alive
(
const
struct
mg_connection
*
conn
)
{
static
int
should_keep_alive
(
const
struct
mg_connection
*
conn
)
{
const
char
*
method
=
conn
->
request_method
;
const
char
*
method
=
conn
->
request_method
;
...
@@ -1614,14 +1614,14 @@ void mg_printf_data(struct mg_connection *c, const char *fmt, ...) {
...
@@ -1614,14 +1614,14 @@ void mg_printf_data(struct mg_connection *c, const char *fmt, ...) {
va_end
(
ap
);
va_end
(
ap
);
}
}
#if !defined(NO_WEBSOCKET) || !defined(NO_AUTH)
#if !defined(NO_WEBSOCKET) || !defined(
MONGOOSE_
NO_AUTH)
static
int
is_big_endian
(
void
)
{
static
int
is_big_endian
(
void
)
{
static
const
int
n
=
1
;
static
const
int
n
=
1
;
return
((
char
*
)
&
n
)[
0
]
==
0
;
return
((
char
*
)
&
n
)[
0
]
==
0
;
}
}
#endif
#endif
#ifndef NO_WEBSOCKET
#ifndef
MONGOOSE_
NO_WEBSOCKET
// START OF SHA-1 code
// START OF SHA-1 code
// Copyright(c) By Steve Reid <steve@edmweb.com>
// Copyright(c) By Steve Reid <steve@edmweb.com>
#define SHA1HANDSOFF
#define SHA1HANDSOFF
...
@@ -1895,13 +1895,13 @@ static void send_websocket_handshake_if_requested(struct mg_connection *conn) {
...
@@ -1895,13 +1895,13 @@ static void send_websocket_handshake_if_requested(struct mg_connection *conn) {
}
}
static
void
ping_idle_websocket_connection
(
struct
connection
*
conn
,
time_t
t
)
{
static
void
ping_idle_websocket_connection
(
struct
connection
*
conn
,
time_t
t
)
{
if
(
t
-
conn
->
last_activity_time
>
USE_WEBSOCKET_PING_INTERVAL
)
{
if
(
t
-
conn
->
last_activity_time
>
MONGOOSE_
USE_WEBSOCKET_PING_INTERVAL
)
{
mg_websocket_write
(
&
conn
->
mg_conn
,
0x9
,
""
,
0
);
mg_websocket_write
(
&
conn
->
mg_conn
,
0x9
,
""
,
0
);
}
}
}
}
#else
#else
#define ping_idle_websocket_connection(conn, t)
#define ping_idle_websocket_connection(conn, t)
#endif // !NO_WEBSOCKET
#endif // !
MONGOOSE_
NO_WEBSOCKET
static
void
write_terminating_chunk
(
struct
connection
*
conn
)
{
static
void
write_terminating_chunk
(
struct
connection
*
conn
)
{
mg_write
(
&
conn
->
mg_conn
,
"0
\r\n\r\n
"
,
5
);
mg_write
(
&
conn
->
mg_conn
,
"0
\r\n\r\n
"
,
5
);
...
@@ -1921,7 +1921,7 @@ static void call_uri_handler(struct connection *conn) {
...
@@ -1921,7 +1921,7 @@ static void call_uri_handler(struct connection *conn) {
static
void
write_to_socket
(
struct
connection
*
conn
)
{
static
void
write_to_socket
(
struct
connection
*
conn
)
{
struct
iobuf
*
io
=
&
conn
->
remote_iobuf
;
struct
iobuf
*
io
=
&
conn
->
remote_iobuf
;
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
int
n
=
conn
->
ssl
==
NULL
?
send
(
conn
->
client_sock
,
io
->
buf
,
io
->
len
,
0
)
:
int
n
=
conn
->
ssl
==
NULL
?
send
(
conn
->
client_sock
,
io
->
buf
,
io
->
len
,
0
)
:
SSL_write
(
conn
->
ssl
,
io
->
buf
,
io
->
len
);
SSL_write
(
conn
->
ssl
,
io
->
buf
,
io
->
len
);
#else
#else
...
@@ -1973,7 +1973,7 @@ static struct uri_handler *find_uri_handler(struct mg_server *server,
...
@@ -1973,7 +1973,7 @@ static struct uri_handler *find_uri_handler(struct mg_server *server,
return
NULL
;
return
NULL
;
}
}
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
// Convert month to the month number. Return -1 on error, or month number
// Convert month to the month number. Return -1 on error, or month number
static
int
get_month_index
(
const
char
*
s
)
{
static
int
get_month_index
(
const
char
*
s
)
{
static
const
char
*
month_names
[]
=
{
static
const
char
*
month_names
[]
=
{
...
@@ -2174,7 +2174,7 @@ static void open_file_endpoint(struct connection *conn, const char *path,
...
@@ -2174,7 +2174,7 @@ static void open_file_endpoint(struct connection *conn, const char *path,
conn
->
mg_conn
.
status_code
,
msg
,
date
,
lm
,
etag
,
conn
->
mg_conn
.
status_code
,
msg
,
date
,
lm
,
etag
,
(
int
)
mime_vec
.
len
,
mime_vec
.
ptr
,
conn
->
cl
,
(
int
)
mime_vec
.
len
,
mime_vec
.
ptr
,
conn
->
cl
,
suggest_connection_header
(
&
conn
->
mg_conn
),
suggest_connection_header
(
&
conn
->
mg_conn
),
range
,
USE_EXTRA_HTTP_HEADERS
);
range
,
MONGOOSE_
USE_EXTRA_HTTP_HEADERS
);
spool
(
&
conn
->
remote_iobuf
,
headers
,
n
);
spool
(
&
conn
->
remote_iobuf
,
headers
,
n
);
if
(
!
strcmp
(
conn
->
mg_conn
.
request_method
,
"HEAD"
))
{
if
(
!
strcmp
(
conn
->
mg_conn
.
request_method
,
"HEAD"
))
{
...
@@ -2184,13 +2184,13 @@ static void open_file_endpoint(struct connection *conn, const char *path,
...
@@ -2184,13 +2184,13 @@ static void open_file_endpoint(struct connection *conn, const char *path,
}
}
}
}
#endif // NO_FILESYSTEM
#endif //
MONGOOSE_
NO_FILESYSTEM
static
void
call_uri_handler_if_data_is_buffered
(
struct
connection
*
conn
)
{
static
void
call_uri_handler_if_data_is_buffered
(
struct
connection
*
conn
)
{
struct
iobuf
*
loc
=
&
conn
->
local_iobuf
;
struct
iobuf
*
loc
=
&
conn
->
local_iobuf
;
struct
mg_connection
*
c
=
&
conn
->
mg_conn
;
struct
mg_connection
*
c
=
&
conn
->
mg_conn
;
#ifndef NO_WEBSOCKET
#ifndef
MONGOOSE_
NO_WEBSOCKET
if
(
conn
->
mg_conn
.
is_websocket
)
{
if
(
conn
->
mg_conn
.
is_websocket
)
{
do
{
}
while
(
deliver_websocket_frame
(
conn
));
do
{
}
while
(
deliver_websocket_frame
(
conn
));
}
else
}
else
...
@@ -2200,7 +2200,7 @@ static void call_uri_handler_if_data_is_buffered(struct connection *conn) {
...
@@ -2200,7 +2200,7 @@ static void call_uri_handler_if_data_is_buffered(struct connection *conn) {
}
}
}
}
#if !defined(NO_DIRECTORY_LISTING) || !defined(NO_DAV)
#if !defined(NO_DIRECTORY_LISTING) || !defined(
MONGOOSE_
NO_DAV)
#ifdef _WIN32
#ifdef _WIN32
struct
dirent
{
struct
dirent
{
...
@@ -2354,9 +2354,9 @@ static void mg_url_encode(const char *src, char *dst, size_t dst_len) {
...
@@ -2354,9 +2354,9 @@ static void mg_url_encode(const char *src, char *dst, size_t dst_len) {
*
dst
=
'\0'
;
*
dst
=
'\0'
;
}
}
#endif // !NO_DIRECTORY_LISTING || !NO_DAV
#endif // !NO_DIRECTORY_LISTING || !
MONGOOSE_
NO_DAV
#ifndef NO_DIRECTORY_LISTING
#ifndef
MONGOOSE_
NO_DIRECTORY_LISTING
static
void
print_dir_entry
(
const
struct
dir_entry
*
de
)
{
static
void
print_dir_entry
(
const
struct
dir_entry
*
de
)
{
char
size
[
64
],
mod
[
64
],
href
[
MAX_PATH_SIZE
*
3
],
chunk
[
MAX_PATH_SIZE
*
4
];
char
size
[
64
],
mod
[
64
],
href
[
MAX_PATH_SIZE
*
3
],
chunk
[
MAX_PATH_SIZE
*
4
];
...
@@ -2452,9 +2452,9 @@ static void send_directory_listing(struct connection *conn, const char *dir) {
...
@@ -2452,9 +2452,9 @@ static void send_directory_listing(struct connection *conn, const char *dir) {
write_terminating_chunk
(
conn
);
write_terminating_chunk
(
conn
);
close_local_endpoint
(
conn
);
close_local_endpoint
(
conn
);
}
}
#endif // NO_DIRECTORY_LISTING
#endif //
MONGOOSE_
NO_DIRECTORY_LISTING
#ifndef NO_DAV
#ifndef
MONGOOSE_
NO_DAV
static
void
print_props
(
struct
connection
*
conn
,
const
char
*
uri
,
static
void
print_props
(
struct
connection
*
conn
,
const
char
*
uri
,
file_stat_t
*
stp
)
{
file_stat_t
*
stp
)
{
char
mtime
[
64
],
buf
[
MAX_PATH_SIZE
+
200
];
char
mtime
[
64
],
buf
[
MAX_PATH_SIZE
+
200
];
...
@@ -2643,7 +2643,7 @@ static void forward_put_data(struct connection *conn) {
...
@@ -2643,7 +2643,7 @@ static void forward_put_data(struct connection *conn) {
}
}
}
}
}
}
#endif // NO_DAV
#endif //
MONGOOSE_
NO_DAV
static
void
send_options
(
struct
connection
*
conn
)
{
static
void
send_options
(
struct
connection
*
conn
)
{
static
const
char
reply
[]
=
"HTTP/1.1 200 OK
\r\n
Allow: GET, POST, HEAD, "
static
const
char
reply
[]
=
"HTTP/1.1 200 OK
\r\n
Allow: GET, POST, HEAD, "
...
@@ -2652,7 +2652,7 @@ static void send_options(struct connection *conn) {
...
@@ -2652,7 +2652,7 @@ static void send_options(struct connection *conn) {
conn
->
flags
|=
CONN_SPOOL_DONE
;
conn
->
flags
|=
CONN_SPOOL_DONE
;
}
}
#ifndef NO_AUTH
#ifndef
MONGOOSE_
NO_AUTH
void
mg_send_digest_auth_request
(
struct
mg_connection
*
c
)
{
void
mg_send_digest_auth_request
(
struct
mg_connection
*
c
)
{
struct
connection
*
conn
=
(
struct
connection
*
)
c
;
struct
connection
*
conn
=
(
struct
connection
*
)
c
;
c
->
status_code
=
401
;
c
->
status_code
=
401
;
...
@@ -2689,7 +2689,7 @@ static FILE *open_auth_file(struct connection *conn, const char *path) {
...
@@ -2689,7 +2689,7 @@ static FILE *open_auth_file(struct connection *conn, const char *path) {
return
fp
;
return
fp
;
}
}
#if !defined(HAVE_MD5) && !defined(NO_AUTH)
#if !defined(HAVE_MD5) && !defined(
MONGOOSE_
NO_AUTH)
typedef
struct
MD5Context
{
typedef
struct
MD5Context
{
uint32_t
buf
[
4
];
uint32_t
buf
[
4
];
uint32_t
bits
[
2
];
uint32_t
bits
[
2
];
...
@@ -2995,7 +2995,7 @@ static int is_dav_mutation(const struct connection *conn) {
...
@@ -2995,7 +2995,7 @@ static int is_dav_mutation(const struct connection *conn) {
return
s
&&
(
!
strcmp
(
s
,
"PUT"
)
||
!
strcmp
(
s
,
"DELETE"
)
||
return
s
&&
(
!
strcmp
(
s
,
"PUT"
)
||
!
strcmp
(
s
,
"DELETE"
)
||
!
strcmp
(
s
,
"MKCOL"
));
!
strcmp
(
s
,
"MKCOL"
));
}
}
#endif // NO_AUTH
#endif //
MONGOOSE_
NO_AUTH
int
parse_header
(
const
char
*
str
,
int
str_len
,
const
char
*
var_name
,
char
*
buf
,
int
parse_header
(
const
char
*
str
,
int
str_len
,
const
char
*
var_name
,
char
*
buf
,
size_t
buf_size
)
{
size_t
buf_size
)
{
...
@@ -3035,7 +3035,7 @@ int mg_parse_header(const char *s, const char *var_name, char *buf,
...
@@ -3035,7 +3035,7 @@ int mg_parse_header(const char *s, const char *var_name, char *buf,
return
parse_header
(
s
,
s
==
NULL
?
0
:
strlen
(
s
),
var_name
,
buf
,
buf_size
);
return
parse_header
(
s
,
s
==
NULL
?
0
:
strlen
(
s
),
var_name
,
buf
,
buf_size
);
}
}
#ifdef USE_LUA
#ifdef
MONGOOSE_
USE_LUA
#include "lua_5.2.1.h"
#include "lua_5.2.1.h"
#ifdef _WIN32
#ifdef _WIN32
...
@@ -3193,7 +3193,7 @@ static void prepare_lua_environment(struct mg_connection *ri, lua_State *L) {
...
@@ -3193,7 +3193,7 @@ static void prepare_lua_environment(struct mg_connection *ri, lua_State *L) {
int
i
;
int
i
;
luaL_openlibs
(
L
);
luaL_openlibs
(
L
);
#ifdef USE_LUA_SQLITE3
#ifdef
MONGOOSE_
USE_LUA_SQLITE3
{
extern
int
luaopen_lsqlite3
(
lua_State
*
);
luaopen_lsqlite3
(
L
);
}
{
extern
int
luaopen_lsqlite3
(
lua_State
*
);
luaopen_lsqlite3
(
L
);
}
#endif
#endif
...
@@ -3303,10 +3303,10 @@ static void handle_lsp_request(struct connection *conn, const char *path,
...
@@ -3303,10 +3303,10 @@ static void handle_lsp_request(struct connection *conn, const char *path,
if
(
p
!=
NULL
)
munmap
(
p
,
st
->
st_size
);
if
(
p
!=
NULL
)
munmap
(
p
,
st
->
st_size
);
if
(
fp
!=
NULL
)
fclose
(
fp
);
if
(
fp
!=
NULL
)
fclose
(
fp
);
}
}
#endif // USE_LUA
#endif //
MONGOOSE_
USE_LUA
static
void
open_local_endpoint
(
struct
connection
*
conn
)
{
static
void
open_local_endpoint
(
struct
connection
*
conn
)
{
#ifndef NO_FILESYSTEM
#ifndef
MONGOOSE_
NO_FILESYSTEM
static
const
char
lua_pat
[]
=
LUA_SCRIPT_PATTERN
;
static
const
char
lua_pat
[]
=
LUA_SCRIPT_PATTERN
;
file_stat_t
st
;
file_stat_t
st
;
char
path
[
MAX_PATH_SIZE
];
char
path
[
MAX_PATH_SIZE
];
...
@@ -3320,7 +3320,7 @@ static void open_local_endpoint(struct connection *conn) {
...
@@ -3320,7 +3320,7 @@ static void open_local_endpoint(struct connection *conn) {
if
(
conn
->
endpoint
.
uh
!=
NULL
)
{
if
(
conn
->
endpoint
.
uh
!=
NULL
)
{
conn
->
endpoint_type
=
EP_USER
;
conn
->
endpoint_type
=
EP_USER
;
conn
->
mg_conn
.
content
=
conn
->
local_iobuf
.
buf
;
conn
->
mg_conn
.
content
=
conn
->
local_iobuf
.
buf
;
#if USE_POST_SIZE_LIMIT > 1
#if
MONGOOSE_
USE_POST_SIZE_LIMIT > 1
{
{
const
char
*
cl
=
mg_get_header
(
&
conn
->
mg_conn
,
"Content-Length"
);
const
char
*
cl
=
mg_get_header
(
&
conn
->
mg_conn
,
"Content-Length"
);
if
(
!
strcmp
(
conn
->
mg_conn
.
request_method
,
"POST"
)
&&
if
(
!
strcmp
(
conn
->
mg_conn
.
request_method
,
"POST"
)
&&
...
@@ -3333,7 +3333,7 @@ static void open_local_endpoint(struct connection *conn) {
...
@@ -3333,7 +3333,7 @@ static void open_local_endpoint(struct connection *conn) {
return
;
return
;
}
}
#ifdef NO_FILESYSTEM
#ifdef
MONGOOSE_
NO_FILESYSTEM
send_http_error
(
conn
,
404
,
NULL
);
send_http_error
(
conn
,
404
,
NULL
);
#else
#else
exists
=
convert_uri_to_file_name
(
conn
,
path
,
sizeof
(
path
),
&
st
);
exists
=
convert_uri_to_file_name
(
conn
,
path
,
sizeof
(
path
),
&
st
);
...
@@ -3343,13 +3343,13 @@ static void open_local_endpoint(struct connection *conn) {
...
@@ -3343,13 +3343,13 @@ static void open_local_endpoint(struct connection *conn) {
send_options
(
conn
);
send_options
(
conn
);
}
else
if
(
conn
->
server
->
config_options
[
DOCUMENT_ROOT
]
==
NULL
)
{
}
else
if
(
conn
->
server
->
config_options
[
DOCUMENT_ROOT
]
==
NULL
)
{
send_http_error
(
conn
,
404
,
NULL
);
send_http_error
(
conn
,
404
,
NULL
);
#ifndef NO_AUTH
#ifndef
MONGOOSE_
NO_AUTH
}
else
if
((
!
is_dav_mutation
(
conn
)
&&
!
is_authorized
(
conn
,
path
))
||
}
else
if
((
!
is_dav_mutation
(
conn
)
&&
!
is_authorized
(
conn
,
path
))
||
(
is_dav_mutation
(
conn
)
&&
!
is_authorized_for_dav
(
conn
)))
{
(
is_dav_mutation
(
conn
)
&&
!
is_authorized_for_dav
(
conn
)))
{
mg_send_digest_auth_request
(
&
conn
->
mg_conn
);
mg_send_digest_auth_request
(
&
conn
->
mg_conn
);
close_local_endpoint
(
conn
);
close_local_endpoint
(
conn
);
#endif
#endif
#ifndef NO_DAV
#ifndef
MONGOOSE_
NO_DAV
}
else
if
(
!
strcmp
(
conn
->
mg_conn
.
request_method
,
"PROPFIND"
))
{
}
else
if
(
!
strcmp
(
conn
->
mg_conn
.
request_method
,
"PROPFIND"
))
{
handle_propfind
(
conn
,
path
,
&
st
);
handle_propfind
(
conn
,
path
,
&
st
);
}
else
if
(
!
strcmp
(
conn
->
mg_conn
.
request_method
,
"MKCOL"
))
{
}
else
if
(
!
strcmp
(
conn
->
mg_conn
.
request_method
,
"MKCOL"
))
{
...
@@ -3369,7 +3369,7 @@ static void open_local_endpoint(struct connection *conn) {
...
@@ -3369,7 +3369,7 @@ static void open_local_endpoint(struct connection *conn) {
close_local_endpoint
(
conn
);
close_local_endpoint
(
conn
);
}
else
if
(
is_directory
&&
!
find_index_file
(
conn
,
path
,
sizeof
(
path
),
&
st
))
{
}
else
if
(
is_directory
&&
!
find_index_file
(
conn
,
path
,
sizeof
(
path
),
&
st
))
{
if
(
!
mg_strcasecmp
(
dir_lst
,
"yes"
))
{
if
(
!
mg_strcasecmp
(
dir_lst
,
"yes"
))
{
#ifndef NO_DIRECTORY_LISTING
#ifndef
MONGOOSE_
NO_DIRECTORY_LISTING
send_directory_listing
(
conn
,
path
);
send_directory_listing
(
conn
,
path
);
#else
#else
send_http_error
(
conn
,
501
,
NULL
);
send_http_error
(
conn
,
501
,
NULL
);
...
@@ -3378,17 +3378,17 @@ static void open_local_endpoint(struct connection *conn) {
...
@@ -3378,17 +3378,17 @@ static void open_local_endpoint(struct connection *conn) {
send_http_error
(
conn
,
403
,
NULL
);
send_http_error
(
conn
,
403
,
NULL
);
}
}
}
else
if
(
match_prefix
(
lua_pat
,
sizeof
(
lua_pat
)
-
1
,
path
)
>
0
)
{
}
else
if
(
match_prefix
(
lua_pat
,
sizeof
(
lua_pat
)
-
1
,
path
)
>
0
)
{
#ifdef USE_LUA
#ifdef
MONGOOSE_
USE_LUA
handle_lsp_request
(
conn
,
path
,
&
st
);
handle_lsp_request
(
conn
,
path
,
&
st
);
#else
#else
send_http_error
(
conn
,
501
,
NULL
);
send_http_error
(
conn
,
501
,
NULL
);
#endif
#endif
}
else
if
(
match_prefix
(
cgi_pat
,
strlen
(
cgi_pat
),
path
)
>
0
)
{
}
else
if
(
match_prefix
(
cgi_pat
,
strlen
(
cgi_pat
),
path
)
>
0
)
{
#if !defined(NO_CGI)
#if !defined(
MONGOOSE_
NO_CGI)
open_cgi_endpoint
(
conn
,
path
);
open_cgi_endpoint
(
conn
,
path
);
#else
#else
send_http_error
(
conn
,
501
,
NULL
);
send_http_error
(
conn
,
501
,
NULL
);
#endif // !NO_CGI
#endif // !
MONGOOSE_
NO_CGI
}
else
if
(
is_not_modified
(
conn
,
&
st
))
{
}
else
if
(
is_not_modified
(
conn
,
&
st
))
{
send_http_error
(
conn
,
304
,
NULL
);
send_http_error
(
conn
,
304
,
NULL
);
}
else
if
((
conn
->
endpoint
.
fd
=
open
(
path
,
O_RDONLY
|
O_BINARY
))
!=
-
1
)
{
}
else
if
((
conn
->
endpoint
.
fd
=
open
(
path
,
O_RDONLY
|
O_BINARY
))
!=
-
1
)
{
...
@@ -3398,7 +3398,7 @@ static void open_local_endpoint(struct connection *conn) {
...
@@ -3398,7 +3398,7 @@ static void open_local_endpoint(struct connection *conn) {
}
else
{
}
else
{
send_http_error
(
conn
,
404
,
NULL
);
send_http_error
(
conn
,
404
,
NULL
);
}
}
#endif // NO_FILESYSTEM
#endif //
MONGOOSE_
NO_FILESYSTEM
}
}
static
void
send_continue_if_expected
(
struct
connection
*
conn
)
{
static
void
send_continue_if_expected
(
struct
connection
*
conn
)
{
...
@@ -3454,14 +3454,14 @@ static void process_request(struct connection *conn) {
...
@@ -3454,14 +3454,14 @@ static void process_request(struct connection *conn) {
strcmp
(
conn
->
mg_conn
.
http_version
,
"1.1"
)
!=
0
)
{
strcmp
(
conn
->
mg_conn
.
http_version
,
"1.1"
)
!=
0
)
{
send_http_error
(
conn
,
505
,
NULL
);
send_http_error
(
conn
,
505
,
NULL
);
}
else
if
(
conn
->
request_len
>
0
&&
conn
->
endpoint_type
==
EP_NONE
)
{
}
else
if
(
conn
->
request_len
>
0
&&
conn
->
endpoint_type
==
EP_NONE
)
{
#ifndef NO_WEBSOCKET
#ifndef
MONGOOSE_
NO_WEBSOCKET
send_websocket_handshake_if_requested
(
&
conn
->
mg_conn
);
send_websocket_handshake_if_requested
(
&
conn
->
mg_conn
);
#endif
#endif
send_continue_if_expected
(
conn
);
send_continue_if_expected
(
conn
);
open_local_endpoint
(
conn
);
open_local_endpoint
(
conn
);
}
}
#ifndef NO_CGI
#ifndef
MONGOOSE_
NO_CGI
if
(
conn
->
endpoint_type
==
EP_CGI
&&
io
->
len
>
0
)
{
if
(
conn
->
endpoint_type
==
EP_CGI
&&
io
->
len
>
0
)
{
forward_post_data
(
conn
);
forward_post_data
(
conn
);
}
}
...
@@ -3469,7 +3469,7 @@ static void process_request(struct connection *conn) {
...
@@ -3469,7 +3469,7 @@ static void process_request(struct connection *conn) {
if
(
conn
->
endpoint_type
==
EP_USER
)
{
if
(
conn
->
endpoint_type
==
EP_USER
)
{
call_uri_handler_if_data_is_buffered
(
conn
);
call_uri_handler_if_data_is_buffered
(
conn
);
}
}
#ifndef NO_DAV
#ifndef
MONGOOSE_
NO_DAV
if
(
conn
->
endpoint_type
==
EP_PUT
&&
io
->
len
>
0
)
{
if
(
conn
->
endpoint_type
==
EP_PUT
&&
io
->
len
>
0
)
{
forward_put_data
(
conn
);
forward_put_data
(
conn
);
}
}
...
@@ -3517,7 +3517,7 @@ static void callback_http_client_on_connect(struct connection *conn) {
...
@@ -3517,7 +3517,7 @@ static void callback_http_client_on_connect(struct connection *conn) {
if
(
getsockopt
(
conn
->
client_sock
,
SOL_SOCKET
,
SO_ERROR
,
(
char
*
)
&
ok
,
if
(
getsockopt
(
conn
->
client_sock
,
SOL_SOCKET
,
SO_ERROR
,
(
char
*
)
&
ok
,
&
len
)
==
0
&&
ok
==
0
)
{
&
len
)
==
0
&&
ok
==
0
)
{
conn
->
mg_conn
.
status_code
=
MG_CONNECT_SUCCESS
;
conn
->
mg_conn
.
status_code
=
MG_CONNECT_SUCCESS
;
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
if
(
conn
->
ssl
!=
NULL
)
{
if
(
conn
->
ssl
!=
NULL
)
{
switch
(
SSL_connect
(
conn
->
ssl
))
{
switch
(
SSL_connect
(
conn
->
ssl
))
{
case
1
:
conn
->
flags
=
CONN_SSL_HANDS_SHAKEN
;
break
;
case
1
:
conn
->
flags
=
CONN_SSL_HANDS_SHAKEN
;
break
;
...
@@ -3541,7 +3541,7 @@ static void read_from_socket(struct connection *conn) {
...
@@ -3541,7 +3541,7 @@ static void read_from_socket(struct connection *conn) {
return
;
return
;
}
}
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
if
(
conn
->
ssl
!=
NULL
)
{
if
(
conn
->
ssl
!=
NULL
)
{
if
(
conn
->
flags
&
CONN_SSL_HANDS_SHAKEN
)
{
if
(
conn
->
flags
&
CONN_SSL_HANDS_SHAKEN
)
{
n
=
SSL_read
(
conn
->
ssl
,
buf
,
sizeof
(
buf
));
n
=
SSL_read
(
conn
->
ssl
,
buf
,
sizeof
(
buf
));
...
@@ -3584,7 +3584,7 @@ int mg_connect(struct mg_server *server, const char *host, int port,
...
@@ -3584,7 +3584,7 @@ int mg_connect(struct mg_server *server, const char *host, int port,
if
(
host
==
NULL
||
(
he
=
gethostbyname
(
host
))
==
NULL
||
if
(
host
==
NULL
||
(
he
=
gethostbyname
(
host
))
==
NULL
||
(
sock
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
))
==
INVALID_SOCKET
)
return
0
;
(
sock
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
))
==
INVALID_SOCKET
)
return
0
;
#ifndef USE_SSL
#ifndef
MONGOOSE_
USE_SSL
if
(
use_ssl
)
return
0
;
if
(
use_ssl
)
return
0
;
#endif
#endif
...
@@ -3609,7 +3609,7 @@ int mg_connect(struct mg_server *server, const char *host, int port,
...
@@ -3609,7 +3609,7 @@ int mg_connect(struct mg_server *server, const char *host, int port,
conn
->
birth_time
=
conn
->
last_activity_time
=
time
(
NULL
);
conn
->
birth_time
=
conn
->
last_activity_time
=
time
(
NULL
);
conn
->
flags
=
CONN_CONNECTING
;
conn
->
flags
=
CONN_CONNECTING
;
conn
->
mg_conn
.
status_code
=
MG_CONNECT_FAILURE
;
conn
->
mg_conn
.
status_code
=
MG_CONNECT_FAILURE
;
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
if
(
use_ssl
&&
(
conn
->
ssl
=
SSL_new
(
server
->
client_ssl_ctx
))
!=
NULL
)
{
if
(
use_ssl
&&
(
conn
->
ssl
=
SSL_new
(
server
->
client_ssl_ctx
))
!=
NULL
)
{
SSL_set_fd
(
conn
->
ssl
,
sock
);
SSL_set_fd
(
conn
->
ssl
,
sock
);
}
}
...
@@ -3627,7 +3627,7 @@ int mg_connect(struct mg_server *server, const char *host, int port,
...
@@ -3627,7 +3627,7 @@ int mg_connect(struct mg_server *server, const char *host, int port,
return
1
;
return
1
;
}
}
#ifndef NO_LOGGING
#ifndef
MONGOOSE_
NO_LOGGING
static
void
log_header
(
const
struct
mg_connection
*
conn
,
const
char
*
header
,
static
void
log_header
(
const
struct
mg_connection
*
conn
,
const
char
*
header
,
FILE
*
fp
)
{
FILE
*
fp
)
{
const
char
*
header_value
;
const
char
*
header_value
;
...
@@ -3679,7 +3679,7 @@ static void close_local_endpoint(struct connection *conn) {
...
@@ -3679,7 +3679,7 @@ static void close_local_endpoint(struct connection *conn) {
default:
break
;
default:
break
;
}
}
#ifndef NO_LOGGING
#ifndef
MONGOOSE_
NO_LOGGING
if
(
conn
->
mg_conn
.
status_code
>
0
&&
conn
->
endpoint_type
!=
EP_CLIENT
&&
if
(
conn
->
mg_conn
.
status_code
>
0
&&
conn
->
endpoint_type
!=
EP_CLIENT
&&
conn
->
mg_conn
.
status_code
!=
400
)
{
conn
->
mg_conn
.
status_code
!=
400
)
{
log_access
(
conn
,
conn
->
server
->
config_options
[
ACCESS_LOG_FILE
]);
log_access
(
conn
,
conn
->
server
->
config_options
[
ACCESS_LOG_FILE
]);
...
@@ -3744,7 +3744,7 @@ unsigned int mg_poll_server(struct mg_server *server, int milliseconds) {
...
@@ -3744,7 +3744,7 @@ unsigned int mg_poll_server(struct mg_server *server, int milliseconds) {
fd_set
read_set
,
write_set
;
fd_set
read_set
,
write_set
;
sock_t
max_fd
=
-
1
;
sock_t
max_fd
=
-
1
;
time_t
current_time
=
time
(
NULL
),
expire_time
=
current_time
-
time_t
current_time
=
time
(
NULL
),
expire_time
=
current_time
-
USE_IDLE_TIMEOUT_SECONDS
;
MONGOOSE_
USE_IDLE_TIMEOUT_SECONDS
;
if
(
server
->
listening_sock
==
INVALID_SOCKET
)
return
0
;
if
(
server
->
listening_sock
==
INVALID_SOCKET
)
return
0
;
...
@@ -3793,7 +3793,7 @@ unsigned int mg_poll_server(struct mg_server *server, int milliseconds) {
...
@@ -3793,7 +3793,7 @@ unsigned int mg_poll_server(struct mg_server *server, int milliseconds) {
conn
->
last_activity_time
=
current_time
;
conn
->
last_activity_time
=
current_time
;
read_from_socket
(
conn
);
read_from_socket
(
conn
);
}
}
#ifndef NO_CGI
#ifndef
MONGOOSE_
NO_CGI
if
(
conn
->
endpoint_type
==
EP_CGI
&&
if
(
conn
->
endpoint_type
==
EP_CGI
&&
FD_ISSET
(
conn
->
endpoint
.
cgi_sock
,
&
read_set
))
{
FD_ISSET
(
conn
->
endpoint
.
cgi_sock
,
&
read_set
))
{
read_from_cgi
(
conn
);
read_from_cgi
(
conn
);
...
@@ -3850,7 +3850,7 @@ void mg_destroy_server(struct mg_server **server) {
...
@@ -3850,7 +3850,7 @@ void mg_destroy_server(struct mg_server **server) {
for
(
i
=
0
;
i
<
(
int
)
ARRAY_SIZE
(
s
->
config_options
);
i
++
)
{
for
(
i
=
0
;
i
<
(
int
)
ARRAY_SIZE
(
s
->
config_options
);
i
++
)
{
free
(
s
->
config_options
[
i
]);
// It is OK to free(NULL)
free
(
s
->
config_options
[
i
]);
// It is OK to free(NULL)
}
}
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
if
(
s
->
ssl_ctx
!=
NULL
)
SSL_CTX_free
((
*
server
)
->
ssl_ctx
);
if
(
s
->
ssl_ctx
!=
NULL
)
SSL_CTX_free
((
*
server
)
->
ssl_ctx
);
if
(
s
->
client_ssl_ctx
!=
NULL
)
SSL_CTX_free
(
s
->
client_ssl_ctx
);
if
(
s
->
client_ssl_ctx
!=
NULL
)
SSL_CTX_free
(
s
->
client_ssl_ctx
);
#endif
#endif
...
@@ -4012,7 +4012,7 @@ static void set_default_option_values(char **opts) {
...
@@ -4012,7 +4012,7 @@ static void set_default_option_values(char **opts) {
static
int
parse_port_string
(
const
char
*
str
,
union
socket_address
*
sa
)
{
static
int
parse_port_string
(
const
char
*
str
,
union
socket_address
*
sa
)
{
unsigned
int
a
,
b
,
c
,
d
,
port
;
unsigned
int
a
,
b
,
c
,
d
,
port
;
int
len
=
0
;
int
len
=
0
;
#ifdef USE_IPV6
#ifdef
MONGOOSE_
USE_IPV6
char
buf
[
100
];
char
buf
[
100
];
#endif
#endif
...
@@ -4026,7 +4026,7 @@ static int parse_port_string(const char *str, union socket_address *sa) {
...
@@ -4026,7 +4026,7 @@ static int parse_port_string(const char *str, union socket_address *sa) {
// Bind to a specific IPv4 address, e.g. 192.168.1.5:8080
// Bind to a specific IPv4 address, e.g. 192.168.1.5:8080
sa
->
sin
.
sin_addr
.
s_addr
=
htonl
((
a
<<
24
)
|
(
b
<<
16
)
|
(
c
<<
8
)
|
d
);
sa
->
sin
.
sin_addr
.
s_addr
=
htonl
((
a
<<
24
)
|
(
b
<<
16
)
|
(
c
<<
8
)
|
d
);
sa
->
sin
.
sin_port
=
htons
((
uint16_t
)
port
);
sa
->
sin
.
sin_port
=
htons
((
uint16_t
)
port
);
#if defined(USE_IPV6)
#if defined(
MONGOOSE_
USE_IPV6)
}
else
if
(
sscanf
(
str
,
"[%49[^]]]:%u%n"
,
buf
,
&
port
,
&
len
)
==
2
&&
}
else
if
(
sscanf
(
str
,
"[%49[^]]]:%u%n"
,
buf
,
&
port
,
&
len
)
==
2
&&
inet_pton
(
AF_INET6
,
buf
,
&
sa
->
sin6
.
sin6_addr
))
{
inet_pton
(
AF_INET6
,
buf
,
&
sa
->
sin6
.
sin6_addr
))
{
// IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080
// IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080
...
@@ -4079,7 +4079,7 @@ const char *mg_set_option(struct mg_server *server, const char *name,
...
@@ -4079,7 +4079,7 @@ const char *mg_set_option(struct mg_server *server, const char *name,
error_msg
=
"setuid() failed"
;
error_msg
=
"setuid() failed"
;
}
}
#endif
#endif
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
}
else
if
(
ind
==
SSL_CERTIFICATE
)
{
}
else
if
(
ind
==
SSL_CERTIFICATE
)
{
SSL_library_init
();
SSL_library_init
();
if
((
server
->
ssl_ctx
=
SSL_CTX_new
(
SSLv23_server_method
()))
==
NULL
)
{
if
((
server
->
ssl_ctx
=
SSL_CTX_new
(
SSLv23_server_method
()))
==
NULL
)
{
...
@@ -4140,7 +4140,7 @@ struct mg_server *mg_create_server(void *server_data) {
...
@@ -4140,7 +4140,7 @@ struct mg_server *mg_create_server(void *server_data) {
mg_socketpair
(
server
->
ctl
);
mg_socketpair
(
server
->
ctl
);
}
while
(
server
->
ctl
[
0
]
==
INVALID_SOCKET
);
}
while
(
server
->
ctl
[
0
]
==
INVALID_SOCKET
);
#ifdef USE_SSL
#ifdef
MONGOOSE_
USE_SSL
server
->
client_ssl_ctx
=
SSL_CTX_new
(
SSLv23_client_method
());
server
->
client_ssl_ctx
=
SSL_CTX_new
(
SSLv23_client_method
());
#endif
#endif
...
...
unit_test.c
View file @
d86d409d
// Unit test for the mongoose web server.
// Unit test for the mongoose web server.
// g++ -W -Wall -pedantic -g unit_test.c && ./a.out
// g++ -W -Wall -pedantic -g unit_test.c && ./a.out
#define USE_WEBSOCKET
#ifndef _WIN32
#ifndef _WIN32
#define USE_IPV6
#define
MONGOOSE_
USE_IPV6
#endif
#endif
// USE_* definitions must be made before #include "mongoose.c" !
// USE_* definitions must be made before #include "mongoose.c" !
...
...
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