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
cd7e1b9e
Commit
cd7e1b9e
authored
Sep 30, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved more ssl defs to internal.h
parent
226d4768
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
220 additions
and
226 deletions
+220
-226
Makefile
build/Makefile
+1
-1
internal.h
build/src/internal.h
+101
-0
mongoose.c
build/src/mongoose.c
+40
-144
mongoose.c
mongoose.c
+78
-81
No files found.
build/Makefile
View file @
cd7e1b9e
...
@@ -57,7 +57,7 @@ endif
...
@@ -57,7 +57,7 @@ endif
all
:
all
:
@
echo
"make (unix|windows|macos)"
@
echo
"make (unix|windows|macos)"
../mongoose.c
:
mod_lua.c ../mongoose.h Makefile $(SOURCES)
../mongoose.c
:
mod_lua.c ../mongoose.h Makefile
src/internal.h
$(SOURCES)
cat
src/internal.h src/mongoose.c |
sed
'/#include "internal.h"/d'
>
$@
cat
src/internal.h src/mongoose.c |
sed
'/#include "internal.h"/d'
>
$@
unix_unit_test
:
$(LUA_SOURCES) Makefile ../test/unit_test.c
unix_unit_test
:
$(LUA_SOURCES) Makefile ../test/unit_test.c
...
...
build/src/internal.h
View file @
cd7e1b9e
...
@@ -323,6 +323,8 @@ struct ssl_func {
...
@@ -323,6 +323,8 @@ struct ssl_func {
void
(
*
ptr
)(
void
);
// Function pointer
void
(
*
ptr
)(
void
);
// Function pointer
};
};
static
struct
ssl_func
ssl_sw
[];
#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr)
#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr)
#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr)
#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr)
#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr)
#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr)
...
@@ -356,4 +358,103 @@ struct ssl_func {
...
@@ -356,4 +358,103 @@ struct ssl_func {
(
*
(
void
(
*
)(
unsigned
long
(
*
)(
void
)))
crypto_sw
[
2
].
ptr
)
(
*
(
void
(
*
)(
unsigned
long
(
*
)(
void
)))
crypto_sw
[
2
].
ptr
)
#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr)
#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr)
#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr)
#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr)
#endif // NO_SSL_DL
// Unified socket address. For IPv6 support, add IPv6 address structure
// in the union u.
union
usa
{
struct
sockaddr
sa
;
struct
sockaddr_in
sin
;
#if defined(USE_IPV6)
struct
sockaddr_in6
sin6
;
#endif
};
// Describes a string (chunk of memory).
struct
vec
{
const
char
*
ptr
;
size_t
len
;
};
struct
file
{
int
is_directory
;
time_t
modification_time
;
int64_t
size
;
// set to 1 if the content is gzipped
// in which case we need a content-encoding: gzip header
int
gzipped
;
};
#define STRUCT_FILE_INITIALIZER { 0, 0, 0, 0 }
// Describes listening socket, or socket which was accept()-ed by the master
// thread and queued for future handling by the worker thread.
struct
socket
{
SOCKET
sock
;
// Listening socket
union
usa
lsa
;
// Local socket address
union
usa
rsa
;
// Remote socket address
unsigned
is_ssl
:
1
;
// Is port SSL-ed
unsigned
ssl_redir
:
1
;
// Is port supposed to redirect everything to SSL port
};
// NOTE(lsm): this enum shoulds be in sync with the config_options.
enum
{
CGI_EXTENSIONS
,
CGI_ENVIRONMENT
,
PUT_DELETE_PASSWORDS_FILE
,
CGI_INTERPRETER
,
PROTECT_URI
,
AUTHENTICATION_DOMAIN
,
SSI_EXTENSIONS
,
THROTTLE
,
ACCESS_LOG_FILE
,
ENABLE_DIRECTORY_LISTING
,
ERROR_LOG_FILE
,
GLOBAL_PASSWORDS_FILE
,
INDEX_FILES
,
ENABLE_KEEP_ALIVE
,
ACCESS_CONTROL_LIST
,
EXTRA_MIME_TYPES
,
LISTENING_PORTS
,
DOCUMENT_ROOT
,
SSL_CERTIFICATE
,
NUM_THREADS
,
RUN_AS_USER
,
REWRITE
,
HIDE_FILES
,
REQUEST_TIMEOUT
,
NUM_OPTIONS
};
struct
mg_context
{
volatile
int
stop_flag
;
// Should we stop event loop
SSL_CTX
*
ssl_ctx
;
// SSL context
char
*
config
[
NUM_OPTIONS
];
// Mongoose configuration parameters
mg_event_handler_t
event_handler
;
// User-defined callback function
void
*
user_data
;
// User-defined data
struct
socket
*
listening_sockets
;
int
num_listening_sockets
;
volatile
int
num_threads
;
// Number of threads
pthread_mutex_t
mutex
;
// Protects (max|num)_threads
pthread_cond_t
cond
;
// Condvar for tracking workers terminations
struct
socket
queue
[
MGSQLEN
];
// Accepted sockets
volatile
int
sq_head
;
// Head of the socket queue
volatile
int
sq_tail
;
// Tail of the socket queue
pthread_cond_t
sq_full
;
// Signaled when socket is produced
pthread_cond_t
sq_empty
;
// Signaled when socket is consumed
};
struct
mg_connection
{
struct
mg_request_info
request_info
;
struct
mg_event
event
;
struct
mg_context
*
ctx
;
SSL
*
ssl
;
// SSL descriptor
SSL_CTX
*
client_ssl_ctx
;
// SSL context for client connections
struct
socket
client
;
// Connected client
time_t
birth_time
;
// Time when request was received
int64_t
num_bytes_sent
;
// Total bytes sent to client
int64_t
content_len
;
// Content-Length header value
int64_t
num_bytes_read
;
// Bytes read from a remote socket
char
*
buf
;
// Buffer for received data
char
*
path_info
;
// PATH_INFO part of the URL
int
must_close
;
// 1 if connection must be closed
int
buf_size
;
// Buffer size
int
request_len
;
// Size of the request + headers in a buffer
int
data_len
;
// Total size of data in a buffer
int
status_code
;
// HTTP reply status code, e.g. 200
int
throttle
;
// Throttling, bytes/sec. <= 0 means no throttle
time_t
last_throttle_time
;
// Last time throttled data was sent
int64_t
last_throttle_bytes
;
// Bytes sent this second
};
// Directory entry
struct
de
{
struct
mg_connection
*
conn
;
char
*
file_name
;
struct
file
file
;
};
build/src/mongoose.c
View file @
cd7e1b9e
#include "internal.h"
#include "internal.h"
// set_ssl_option() function updates this array.
// It loads SSL library dynamically and changes NULLs to the actual addresses
// of respective functions. The macros above (like SSL_connect()) are really
// just calling these functions indirectly via the pointer.
static
struct
ssl_func
ssl_sw
[]
=
{
{
"SSL_free"
,
NULL
},
{
"SSL_accept"
,
NULL
},
{
"SSL_connect"
,
NULL
},
{
"SSL_read"
,
NULL
},
{
"SSL_write"
,
NULL
},
{
"SSL_get_error"
,
NULL
},
{
"SSL_set_fd"
,
NULL
},
{
"SSL_new"
,
NULL
},
{
"SSL_CTX_new"
,
NULL
},
{
"SSLv23_server_method"
,
NULL
},
{
"SSL_library_init"
,
NULL
},
{
"SSL_CTX_use_PrivateKey_file"
,
NULL
},
{
"SSL_CTX_use_certificate_file"
,
NULL
},
{
"SSL_CTX_set_default_passwd_cb"
,
NULL
},
{
"SSL_CTX_free"
,
NULL
},
{
"SSL_load_error_strings"
,
NULL
},
{
"SSL_CTX_use_certificate_chain_file"
,
NULL
},
{
"SSLv23_client_method"
,
NULL
},
{
"SSL_pending"
,
NULL
},
{
"SSL_CTX_set_verify"
,
NULL
},
{
"SSL_shutdown"
,
NULL
},
{
NULL
,
NULL
}
};
// Similar array as ssl_sw. These functions could be located in different lib.
#if !defined(NO_SSL)
static
struct
ssl_func
crypto_sw
[]
=
{
{
"CRYPTO_num_locks"
,
NULL
},
{
"CRYPTO_set_locking_callback"
,
NULL
},
{
"CRYPTO_set_id_callback"
,
NULL
},
{
"ERR_get_error"
,
NULL
},
{
"ERR_error_string"
,
NULL
},
{
NULL
,
NULL
}
};
#endif // NO_SSL
#endif // NO_SSL_DL
static
const
char
*
month_names
[]
=
{
static
const
char
*
month_names
[]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
};
// Unified socket address. For IPv6 support, add IPv6 address structure
// in the union u.
union
usa
{
struct
sockaddr
sa
;
struct
sockaddr_in
sin
;
#if defined(USE_IPV6)
struct
sockaddr_in6
sin6
;
#endif
};
// Describes a string (chunk of memory).
struct
vec
{
const
char
*
ptr
;
size_t
len
;
};
struct
file
{
int
is_directory
;
time_t
modification_time
;
int64_t
size
;
// set to 1 if the content is gzipped
// in which case we need a content-encoding: gzip header
int
gzipped
;
};
#define STRUCT_FILE_INITIALIZER { 0, 0, 0, 0 }
// Describes listening socket, or socket which was accept()-ed by the master
// thread and queued for future handling by the worker thread.
struct
socket
{
SOCKET
sock
;
// Listening socket
union
usa
lsa
;
// Local socket address
union
usa
rsa
;
// Remote socket address
unsigned
is_ssl
:
1
;
// Is port SSL-ed
unsigned
ssl_redir
:
1
;
// Is port supposed to redirect everything to SSL port
};
// NOTE(lsm): this enum shoulds be in sync with the config_options below.
enum
{
CGI_EXTENSIONS
,
CGI_ENVIRONMENT
,
PUT_DELETE_PASSWORDS_FILE
,
CGI_INTERPRETER
,
PROTECT_URI
,
AUTHENTICATION_DOMAIN
,
SSI_EXTENSIONS
,
THROTTLE
,
ACCESS_LOG_FILE
,
ENABLE_DIRECTORY_LISTING
,
ERROR_LOG_FILE
,
GLOBAL_PASSWORDS_FILE
,
INDEX_FILES
,
ENABLE_KEEP_ALIVE
,
ACCESS_CONTROL_LIST
,
EXTRA_MIME_TYPES
,
LISTENING_PORTS
,
DOCUMENT_ROOT
,
SSL_CERTIFICATE
,
NUM_THREADS
,
RUN_AS_USER
,
REWRITE
,
HIDE_FILES
,
REQUEST_TIMEOUT
,
NUM_OPTIONS
};
static
const
char
*
config_options
[]
=
{
static
const
char
*
config_options
[]
=
{
"cgi_pattern"
,
"**.cgi$|**.pl$|**.php$"
,
"cgi_pattern"
,
"**.cgi$|**.pl$|**.php$"
,
"cgi_environment"
,
NULL
,
"cgi_environment"
,
NULL
,
...
@@ -123,57 +34,6 @@ static const char *config_options[] = {
...
@@ -123,57 +34,6 @@ static const char *config_options[] = {
NULL
NULL
};
};
struct
mg_context
{
volatile
int
stop_flag
;
// Should we stop event loop
SSL_CTX
*
ssl_ctx
;
// SSL context
char
*
config
[
NUM_OPTIONS
];
// Mongoose configuration parameters
mg_event_handler_t
event_handler
;
// User-defined callback function
void
*
user_data
;
// User-defined data
struct
socket
*
listening_sockets
;
int
num_listening_sockets
;
volatile
int
num_threads
;
// Number of threads
pthread_mutex_t
mutex
;
// Protects (max|num)_threads
pthread_cond_t
cond
;
// Condvar for tracking workers terminations
struct
socket
queue
[
MGSQLEN
];
// Accepted sockets
volatile
int
sq_head
;
// Head of the socket queue
volatile
int
sq_tail
;
// Tail of the socket queue
pthread_cond_t
sq_full
;
// Signaled when socket is produced
pthread_cond_t
sq_empty
;
// Signaled when socket is consumed
};
struct
mg_connection
{
struct
mg_request_info
request_info
;
struct
mg_event
event
;
struct
mg_context
*
ctx
;
SSL
*
ssl
;
// SSL descriptor
SSL_CTX
*
client_ssl_ctx
;
// SSL context for client connections
struct
socket
client
;
// Connected client
time_t
birth_time
;
// Time when request was received
int64_t
num_bytes_sent
;
// Total bytes sent to client
int64_t
content_len
;
// Content-Length header value
int64_t
num_bytes_read
;
// Bytes read from a remote socket
char
*
buf
;
// Buffer for received data
char
*
path_info
;
// PATH_INFO part of the URL
int
must_close
;
// 1 if connection must be closed
int
buf_size
;
// Buffer size
int
request_len
;
// Size of the request + headers in a buffer
int
data_len
;
// Total size of data in a buffer
int
status_code
;
// HTTP reply status code, e.g. 200
int
throttle
;
// Throttling, bytes/sec. <= 0 means no throttle
time_t
last_throttle_time
;
// Last time throttled data was sent
int64_t
last_throttle_bytes
;
// Bytes sent this second
};
// Directory entry
struct
de
{
struct
mg_connection
*
conn
;
char
*
file_name
;
struct
file
file
;
};
// Return number of bytes left to read for this connection
// Return number of bytes left to read for this connection
static
int64_t
left_to_read
(
const
struct
mg_connection
*
conn
)
{
static
int64_t
left_to_read
(
const
struct
mg_connection
*
conn
)
{
return
conn
->
content_len
+
conn
->
request_len
-
conn
->
num_bytes_read
;
return
conn
->
content_len
+
conn
->
request_len
-
conn
->
num_bytes_read
;
...
@@ -1119,12 +979,9 @@ static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf,
...
@@ -1119,12 +979,9 @@ static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf,
// How many bytes we send in this iteration
// How many bytes we send in this iteration
k
=
len
-
sent
>
INT_MAX
?
INT_MAX
:
(
int
)
(
len
-
sent
);
k
=
len
-
sent
>
INT_MAX
?
INT_MAX
:
(
int
)
(
len
-
sent
);
#ifndef NO_SSL
if
(
ssl
!=
NULL
)
{
if
(
ssl
!=
NULL
)
{
n
=
SSL_write
(
ssl
,
buf
+
sent
,
k
);
n
=
SSL_write
(
ssl
,
buf
+
sent
,
k
);
}
else
}
else
if
(
fp
!=
NULL
)
{
#endif
if
(
fp
!=
NULL
)
{
n
=
(
int
)
fwrite
(
buf
+
sent
,
1
,
(
size_t
)
k
,
fp
);
n
=
(
int
)
fwrite
(
buf
+
sent
,
1
,
(
size_t
)
k
,
fp
);
if
(
ferror
(
fp
))
if
(
ferror
(
fp
))
n
=
-
1
;
n
=
-
1
;
...
@@ -4325,6 +4182,45 @@ static int set_uid_option(struct mg_context *ctx) {
...
@@ -4325,6 +4182,45 @@ static int set_uid_option(struct mg_context *ctx) {
#endif // !_WIN32
#endif // !_WIN32
#if !defined(NO_SSL)
#if !defined(NO_SSL)
// set_ssl_option() function updates this array.
// It loads SSL library dynamically and changes NULLs to the actual addresses
// of respective functions. The macros above (like SSL_connect()) are really
// just calling these functions indirectly via the pointer.
static
struct
ssl_func
ssl_sw
[]
=
{
{
"SSL_free"
,
NULL
},
{
"SSL_accept"
,
NULL
},
{
"SSL_connect"
,
NULL
},
{
"SSL_read"
,
NULL
},
{
"SSL_write"
,
NULL
},
{
"SSL_get_error"
,
NULL
},
{
"SSL_set_fd"
,
NULL
},
{
"SSL_new"
,
NULL
},
{
"SSL_CTX_new"
,
NULL
},
{
"SSLv23_server_method"
,
NULL
},
{
"SSL_library_init"
,
NULL
},
{
"SSL_CTX_use_PrivateKey_file"
,
NULL
},
{
"SSL_CTX_use_certificate_file"
,
NULL
},
{
"SSL_CTX_set_default_passwd_cb"
,
NULL
},
{
"SSL_CTX_free"
,
NULL
},
{
"SSL_load_error_strings"
,
NULL
},
{
"SSL_CTX_use_certificate_chain_file"
,
NULL
},
{
"SSLv23_client_method"
,
NULL
},
{
"SSL_pending"
,
NULL
},
{
"SSL_CTX_set_verify"
,
NULL
},
{
"SSL_shutdown"
,
NULL
},
{
NULL
,
NULL
}
};
// Similar array as ssl_sw. These functions could be located in different lib.
static
struct
ssl_func
crypto_sw
[]
=
{
{
"CRYPTO_num_locks"
,
NULL
},
{
"CRYPTO_set_locking_callback"
,
NULL
},
{
"CRYPTO_set_id_callback"
,
NULL
},
{
"ERR_get_error"
,
NULL
},
{
"ERR_error_string"
,
NULL
},
{
NULL
,
NULL
}
};
static
pthread_mutex_t
*
ssl_mutexes
;
static
pthread_mutex_t
*
ssl_mutexes
;
static
int
sslize
(
struct
mg_connection
*
conn
,
SSL_CTX
*
s
,
int
(
*
func
)(
SSL
*
))
{
static
int
sslize
(
struct
mg_connection
*
conn
,
SSL_CTX
*
s
,
int
(
*
func
)(
SSL
*
))
{
...
...
mongoose.c
View file @
cd7e1b9e
...
@@ -323,6 +323,8 @@ struct ssl_func {
...
@@ -323,6 +323,8 @@ struct ssl_func {
void
(
*
ptr
)(
void
);
// Function pointer
void
(
*
ptr
)(
void
);
// Function pointer
};
};
static
struct
ssl_func
ssl_sw
[];
#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr)
#define SSL_free (* (void (*)(SSL *)) ssl_sw[0].ptr)
#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr)
#define SSL_accept (* (int (*)(SSL *)) ssl_sw[1].ptr)
#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr)
#define SSL_connect (* (int (*)(SSL *)) ssl_sw[2].ptr)
...
@@ -356,55 +358,8 @@ struct ssl_func {
...
@@ -356,55 +358,8 @@ struct ssl_func {
(
*
(
void
(
*
)(
unsigned
long
(
*
)(
void
)))
crypto_sw
[
2
].
ptr
)
(
*
(
void
(
*
)(
unsigned
long
(
*
)(
void
)))
crypto_sw
[
2
].
ptr
)
#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr)
#define ERR_get_error (* (unsigned long (*)(void)) crypto_sw[3].ptr)
#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr)
#define ERR_error_string (* (char * (*)(unsigned long,char *)) crypto_sw[4].ptr)
// set_ssl_option() function updates this array.
// It loads SSL library dynamically and changes NULLs to the actual addresses
// of respective functions. The macros above (like SSL_connect()) are really
// just calling these functions indirectly via the pointer.
static
struct
ssl_func
ssl_sw
[]
=
{
{
"SSL_free"
,
NULL
},
{
"SSL_accept"
,
NULL
},
{
"SSL_connect"
,
NULL
},
{
"SSL_read"
,
NULL
},
{
"SSL_write"
,
NULL
},
{
"SSL_get_error"
,
NULL
},
{
"SSL_set_fd"
,
NULL
},
{
"SSL_new"
,
NULL
},
{
"SSL_CTX_new"
,
NULL
},
{
"SSLv23_server_method"
,
NULL
},
{
"SSL_library_init"
,
NULL
},
{
"SSL_CTX_use_PrivateKey_file"
,
NULL
},
{
"SSL_CTX_use_certificate_file"
,
NULL
},
{
"SSL_CTX_set_default_passwd_cb"
,
NULL
},
{
"SSL_CTX_free"
,
NULL
},
{
"SSL_load_error_strings"
,
NULL
},
{
"SSL_CTX_use_certificate_chain_file"
,
NULL
},
{
"SSLv23_client_method"
,
NULL
},
{
"SSL_pending"
,
NULL
},
{
"SSL_CTX_set_verify"
,
NULL
},
{
"SSL_shutdown"
,
NULL
},
{
NULL
,
NULL
}
};
// Similar array as ssl_sw. These functions could be located in different lib.
#if !defined(NO_SSL)
static
struct
ssl_func
crypto_sw
[]
=
{
{
"CRYPTO_num_locks"
,
NULL
},
{
"CRYPTO_set_locking_callback"
,
NULL
},
{
"CRYPTO_set_id_callback"
,
NULL
},
{
"ERR_get_error"
,
NULL
},
{
"ERR_error_string"
,
NULL
},
{
NULL
,
NULL
}
};
#endif // NO_SSL
#endif // NO_SSL_DL
#endif // NO_SSL_DL
static
const
char
*
month_names
[]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
// Unified socket address. For IPv6 support, add IPv6 address structure
// Unified socket address. For IPv6 support, add IPv6 address structure
// in the union u.
// in the union u.
union
usa
{
union
usa
{
...
@@ -441,7 +396,7 @@ struct socket {
...
@@ -441,7 +396,7 @@ struct socket {
unsigned
ssl_redir
:
1
;
// Is port supposed to redirect everything to SSL port
unsigned
ssl_redir
:
1
;
// Is port supposed to redirect everything to SSL port
};
};
// NOTE(lsm): this enum shoulds be in sync with the config_options
below
.
// NOTE(lsm): this enum shoulds be in sync with the config_options.
enum
{
enum
{
CGI_EXTENSIONS
,
CGI_ENVIRONMENT
,
PUT_DELETE_PASSWORDS_FILE
,
CGI_INTERPRETER
,
CGI_EXTENSIONS
,
CGI_ENVIRONMENT
,
PUT_DELETE_PASSWORDS_FILE
,
CGI_INTERPRETER
,
PROTECT_URI
,
AUTHENTICATION_DOMAIN
,
SSI_EXTENSIONS
,
THROTTLE
,
PROTECT_URI
,
AUTHENTICATION_DOMAIN
,
SSI_EXTENSIONS
,
THROTTLE
,
...
@@ -452,35 +407,6 @@ enum {
...
@@ -452,35 +407,6 @@ enum {
NUM_OPTIONS
NUM_OPTIONS
};
};
static
const
char
*
config_options
[]
=
{
"cgi_pattern"
,
"**.cgi$|**.pl$|**.php$"
,
"cgi_environment"
,
NULL
,
"put_delete_auth_file"
,
NULL
,
"cgi_interpreter"
,
NULL
,
"protect_uri"
,
NULL
,
"authentication_domain"
,
"mydomain.com"
,
"ssi_pattern"
,
"**.shtml$|**.shtm$"
,
"throttle"
,
NULL
,
"access_log_file"
,
NULL
,
"enable_directory_listing"
,
"yes"
,
"error_log_file"
,
NULL
,
"global_auth_file"
,
NULL
,
"index_files"
,
"index.html,index.htm,index.cgi,index.shtml,index.php,index.lp"
,
"enable_keep_alive"
,
"no"
,
"access_control_list"
,
NULL
,
"extra_mime_types"
,
NULL
,
"listening_ports"
,
"8080"
,
"document_root"
,
NULL
,
"ssl_certificate"
,
NULL
,
"num_threads"
,
"50"
,
"run_as_user"
,
NULL
,
"url_rewrite_patterns"
,
NULL
,
"hide_files_patterns"
,
NULL
,
"request_timeout_ms"
,
"30000"
,
NULL
};
struct
mg_context
{
struct
mg_context
{
volatile
int
stop_flag
;
// Should we stop event loop
volatile
int
stop_flag
;
// Should we stop event loop
SSL_CTX
*
ssl_ctx
;
// SSL context
SSL_CTX
*
ssl_ctx
;
// SSL context
...
@@ -532,6 +458,41 @@ struct de {
...
@@ -532,6 +458,41 @@ struct de {
struct
file
file
;
struct
file
file
;
};
};
static
const
char
*
month_names
[]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
static
const
char
*
config_options
[]
=
{
"cgi_pattern"
,
"**.cgi$|**.pl$|**.php$"
,
"cgi_environment"
,
NULL
,
"put_delete_auth_file"
,
NULL
,
"cgi_interpreter"
,
NULL
,
"protect_uri"
,
NULL
,
"authentication_domain"
,
"mydomain.com"
,
"ssi_pattern"
,
"**.shtml$|**.shtm$"
,
"throttle"
,
NULL
,
"access_log_file"
,
NULL
,
"enable_directory_listing"
,
"yes"
,
"error_log_file"
,
NULL
,
"global_auth_file"
,
NULL
,
"index_files"
,
"index.html,index.htm,index.cgi,index.shtml,index.php,index.lp"
,
"enable_keep_alive"
,
"no"
,
"access_control_list"
,
NULL
,
"extra_mime_types"
,
NULL
,
"listening_ports"
,
"8080"
,
"document_root"
,
NULL
,
"ssl_certificate"
,
NULL
,
"num_threads"
,
"50"
,
"run_as_user"
,
NULL
,
"url_rewrite_patterns"
,
NULL
,
"hide_files_patterns"
,
NULL
,
"request_timeout_ms"
,
"30000"
,
NULL
};
// Return number of bytes left to read for this connection
// Return number of bytes left to read for this connection
static
int64_t
left_to_read
(
const
struct
mg_connection
*
conn
)
{
static
int64_t
left_to_read
(
const
struct
mg_connection
*
conn
)
{
return
conn
->
content_len
+
conn
->
request_len
-
conn
->
num_bytes_read
;
return
conn
->
content_len
+
conn
->
request_len
-
conn
->
num_bytes_read
;
...
@@ -1477,12 +1438,9 @@ static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf,
...
@@ -1477,12 +1438,9 @@ static int64_t push(FILE *fp, SOCKET sock, SSL *ssl, const char *buf,
// How many bytes we send in this iteration
// How many bytes we send in this iteration
k
=
len
-
sent
>
INT_MAX
?
INT_MAX
:
(
int
)
(
len
-
sent
);
k
=
len
-
sent
>
INT_MAX
?
INT_MAX
:
(
int
)
(
len
-
sent
);
#ifndef NO_SSL
if
(
ssl
!=
NULL
)
{
if
(
ssl
!=
NULL
)
{
n
=
SSL_write
(
ssl
,
buf
+
sent
,
k
);
n
=
SSL_write
(
ssl
,
buf
+
sent
,
k
);
}
else
}
else
if
(
fp
!=
NULL
)
{
#endif
if
(
fp
!=
NULL
)
{
n
=
(
int
)
fwrite
(
buf
+
sent
,
1
,
(
size_t
)
k
,
fp
);
n
=
(
int
)
fwrite
(
buf
+
sent
,
1
,
(
size_t
)
k
,
fp
);
if
(
ferror
(
fp
))
if
(
ferror
(
fp
))
n
=
-
1
;
n
=
-
1
;
...
@@ -4683,6 +4641,45 @@ static int set_uid_option(struct mg_context *ctx) {
...
@@ -4683,6 +4641,45 @@ static int set_uid_option(struct mg_context *ctx) {
#endif // !_WIN32
#endif // !_WIN32
#if !defined(NO_SSL)
#if !defined(NO_SSL)
// set_ssl_option() function updates this array.
// It loads SSL library dynamically and changes NULLs to the actual addresses
// of respective functions. The macros above (like SSL_connect()) are really
// just calling these functions indirectly via the pointer.
static
struct
ssl_func
ssl_sw
[]
=
{
{
"SSL_free"
,
NULL
},
{
"SSL_accept"
,
NULL
},
{
"SSL_connect"
,
NULL
},
{
"SSL_read"
,
NULL
},
{
"SSL_write"
,
NULL
},
{
"SSL_get_error"
,
NULL
},
{
"SSL_set_fd"
,
NULL
},
{
"SSL_new"
,
NULL
},
{
"SSL_CTX_new"
,
NULL
},
{
"SSLv23_server_method"
,
NULL
},
{
"SSL_library_init"
,
NULL
},
{
"SSL_CTX_use_PrivateKey_file"
,
NULL
},
{
"SSL_CTX_use_certificate_file"
,
NULL
},
{
"SSL_CTX_set_default_passwd_cb"
,
NULL
},
{
"SSL_CTX_free"
,
NULL
},
{
"SSL_load_error_strings"
,
NULL
},
{
"SSL_CTX_use_certificate_chain_file"
,
NULL
},
{
"SSLv23_client_method"
,
NULL
},
{
"SSL_pending"
,
NULL
},
{
"SSL_CTX_set_verify"
,
NULL
},
{
"SSL_shutdown"
,
NULL
},
{
NULL
,
NULL
}
};
// Similar array as ssl_sw. These functions could be located in different lib.
static
struct
ssl_func
crypto_sw
[]
=
{
{
"CRYPTO_num_locks"
,
NULL
},
{
"CRYPTO_set_locking_callback"
,
NULL
},
{
"CRYPTO_set_id_callback"
,
NULL
},
{
"ERR_get_error"
,
NULL
},
{
"ERR_error_string"
,
NULL
},
{
NULL
,
NULL
}
};
static
pthread_mutex_t
*
ssl_mutexes
;
static
pthread_mutex_t
*
ssl_mutexes
;
static
int
sslize
(
struct
mg_connection
*
conn
,
SSL_CTX
*
s
,
int
(
*
func
)(
SSL
*
))
{
static
int
sslize
(
struct
mg_connection
*
conn
,
SSL_CTX
*
s
,
int
(
*
func
)(
SSL
*
))
{
...
...
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