mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-06 15:51:25 +00:00
set is_tls at mg_listen and mg_connect level
This commit is contained in:
1 parent
29594283c1
commit
b740c80855
25 files changed
+69
-49
No files matched your search
@@ -28,8 +28,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
// Connected to server. Extract host name from URL
|
||||
struct mg_str host = mg_url_host(s_url);
|
||||
|
||||
// If s_url is https://, tell client connection to use TLS
|
||||
if (mg_url_is_ssl(s_url)) {
|
||||
// If s_url is https://, init TLS client connection
|
||||
if (c->is_tls) {
|
||||
struct mg_tls_opts opts = {.ca = s_ca, .name = host};
|
||||
mg_tls_init(c, &opts);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ static struct mg_connection *s_sntp_conn = NULL;
|
||||
|
||||
// Event handler for the listening HTTP/HTTPS connection.
|
||||
static void wcb(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_ACCEPT && c->fn_data != NULL) {
|
||||
if (ev == MG_EV_ACCEPT && c->is_tls) {
|
||||
struct mg_tls_opts opts = {.cert = (char *) s_ssl_cert, .key = (char *) s_ssl_key};
|
||||
mg_tls_init(c, &opts);
|
||||
} else if (ev == MG_EV_HTTP_MSG) {
|
||||
@@ -89,7 +89,7 @@ int main(int argc, char *argv[]) {
|
||||
mg_mgr_init(&mgr);
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
mg_http_listen(&mgr, s_http_addr, wcb, NULL);
|
||||
mg_http_listen(&mgr, s_https_addr, wcb, &mgr);
|
||||
mg_http_listen(&mgr, s_https_addr, wcb, NULL);
|
||||
|
||||
mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ static struct mg_connection *s_sntp_conn = NULL;
|
||||
static void fn(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_OPEN) {
|
||||
c->is_hexdumping = 1;
|
||||
} else if (ev == MG_EV_ACCEPT && c->fn_data != NULL) {
|
||||
} else if (ev == MG_EV_ACCEPT && c->is_tls) {
|
||||
struct mg_tls_opts opts = {.cert = (char *) s_ssl_cert, .key = (char *) s_ssl_key};
|
||||
mg_tls_init(c, &opts);
|
||||
} else if (ev == MG_EV_HTTP_MSG) {
|
||||
@@ -85,7 +85,7 @@ int main(int argc, char *argv[]) {
|
||||
mg_mgr_init(&mgr);
|
||||
mg_log_set(MG_LL_DEBUG);
|
||||
mg_http_listen(&mgr, s_ws_addr, fn, NULL);
|
||||
mg_http_listen(&mgr, s_wss_addr, fn, &mgr);
|
||||
mg_http_listen(&mgr, s_wss_addr, fn, NULL);
|
||||
mg_timer_add(&mgr, 5000, MG_TIMER_REPEAT | MG_TIMER_RUN_NOW, timer_fn, &mgr);
|
||||
|
||||
// Start infinite event loop
|
||||
|
||||
Reference in new issue
Block a user