Skip to content

Commit 6b6acd3

Browse files
authored
Merge pull request #3149 from cesanta/is_tls
set is_tls at mg_listen and mg_connect level
2 parents 2959428 + b740c80 commit 6b6acd3

File tree

25 files changed

+69
-49
lines changed

25 files changed

+69
-49
lines changed

mongoose.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,8 +4050,9 @@ struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
40504050
c->fn = fn;
40514051
c->is_client = true;
40524052
c->fn_data = fn_data;
4053-
MG_DEBUG(("%lu %ld %s", c->id, c->fd, url));
4053+
c->is_tls = (mg_url_is_ssl(url) != 0);
40544054
mg_call(c, MG_EV_OPEN, (void *) url);
4055+
MG_DEBUG(("%lu %ld %s", c->id, c->fd, url));
40554056
mg_resolve(c, url);
40564057
}
40574058
return c;
@@ -4073,8 +4074,8 @@ struct mg_connection *mg_listen(struct mg_mgr *mgr, const char *url,
40734074
LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c);
40744075
c->fn = fn;
40754076
c->fn_data = fn_data;
4077+
c->is_tls = (mg_url_is_ssl(url) != 0);
40764078
mg_call(c, MG_EV_OPEN, NULL);
4077-
if (mg_url_is_ssl(url)) c->is_tls = 1; // Accepted connection must
40784079
MG_DEBUG(("%lu %ld %s", c->id, c->fd, url));
40794080
}
40804081
return c;
@@ -4342,7 +4343,7 @@ static void settmout(struct mg_connection *c, uint8_t type) {
43424343
: type == MIP_TTYPE_SYN ? MIP_TCP_SYN_MS
43434344
: type == MIP_TTYPE_FIN ? MIP_TCP_FIN_MS
43444345
: MIP_TCP_KEEPALIVE_MS;
4345-
if (s->ttype == MIP_TTYPE_FIN) return; // skip if 3-way closing
4346+
if (s->ttype == MIP_TTYPE_FIN) return; // skip if 3-way closing
43464347
s->timer = ifp->now + n;
43474348
s->ttype = type;
43484349
MG_VERBOSE(("%lu %d -> %llx", c->id, type, s->timer));
@@ -4745,7 +4746,7 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
47454746
return NULL;
47464747
}
47474748
struct connstate *s = (struct connstate *) (c + 1);
4748-
s->dmss = 536; // assume default, RFC-9293 3.7.1
4749+
s->dmss = 536; // assume default, RFC-9293 3.7.1
47494750
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq);
47504751
memcpy(s->mac, pkt->eth->src, sizeof(s->mac));
47514752
settmout(c, MIP_TTYPE_KEEPALIVE);
@@ -4760,8 +4761,10 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
47604761
c->pfn_data = lsn->pfn_data;
47614762
c->fn = lsn->fn;
47624763
c->fn_data = lsn->fn_data;
4764+
c->is_tls = lsn->is_tls;
47634765
mg_call(c, MG_EV_OPEN, NULL);
47644766
mg_call(c, MG_EV_ACCEPT, NULL);
4767+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
47654768
return c;
47664769
}
47674770

@@ -4949,6 +4952,7 @@ static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) {
49494952
settmout(c, MIP_TTYPE_KEEPALIVE);
49504953
mg_call(c, MG_EV_CONNECT, NULL); // Let user know
49514954
if (c->is_tls_hs) mg_tls_handshake(c);
4955+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
49524956
} else if (c != NULL && c->is_connecting && pkt->tcp->flags != TH_ACK) {
49534957
// mg_hexdump(pkt->raw.buf, pkt->raw.len);
49544958
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
@@ -5374,16 +5378,18 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
53745378
for (c = mgr->conns; c != NULL; c = tmp) {
53755379
tmp = c->next;
53765380
struct connstate *s = (struct connstate *) (c + 1);
5381+
bool is_tls = !c->is_resolving && !c->is_arplooking && !c->is_listening &&
5382+
!c->is_connecting;
53775383
mg_call(c, MG_EV_POLL, &now);
53785384
MG_VERBOSE(("%lu .. %c%c%c%c%c %lu %lu", c->id, c->is_tls ? 'T' : 't',
53795385
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
53805386
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c',
53815387
mg_tls_pending(c), c->rtls.len));
53825388
// order is important, TLS conn close with > 1 record in buffer (below)
5383-
if (c->is_tls && (c->rtls.len > 0 || mg_tls_pending(c) > 0))
5389+
if (is_tls && (c->rtls.len > 0 || mg_tls_pending(c) > 0))
53845390
handle_tls_recv(c);
53855391
if (can_write(c)) write_conn(c);
5386-
if (!c->is_listening && c->is_tls && !c->is_tls_hs && c->send.len == 0) mg_tls_flush(c);
5392+
if (is_tls && c->send.len == 0) mg_tls_flush(c);
53875393
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
53885394
init_closure(c);
53895395
// For non-TLS, close immediately upon completing the 3-way closure
@@ -8969,6 +8975,7 @@ static void connect_conn(struct mg_connection *c) {
89698975
mg_call(c, MG_EV_CONNECT, NULL);
89708976
MG_EPOLL_MOD(c, 0);
89718977
if (c->is_tls_hs) mg_tls_handshake(c);
8978+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
89728979
} else {
89738980
mg_error(c, "socket error");
89748981
}
@@ -9021,6 +9028,7 @@ void mg_connect_resolved(struct mg_connection *c) {
90219028
if (rc == 0) { // Success
90229029
setlocaddr(FD(c), &c->loc);
90239030
mg_call(c, MG_EV_CONNECT, NULL); // Send MG_EV_CONNECT to the user
9031+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
90249032
} else if (MG_SOCK_PENDING(rc)) { // Need to wait for TCP handshake
90259033
MG_DEBUG(("%lu %ld -> %M pend", c->id, c->fd, mg_print_ip_port, &c->rem));
90269034
c->is_connecting = 1;
@@ -9076,10 +9084,12 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
90769084
c->pfn_data = lsn->pfn_data;
90779085
c->fn = lsn->fn;
90789086
c->fn_data = lsn->fn_data;
9087+
c->is_tls = lsn->is_tls;
90799088
MG_DEBUG(("%lu %ld accepted %M -> %M", c->id, c->fd, mg_print_ip_port,
90809089
&c->rem, mg_print_ip_port, &c->loc));
90819090
mg_call(c, MG_EV_OPEN, NULL);
90829091
mg_call(c, MG_EV_ACCEPT, NULL);
9092+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
90839093
}
90849094
}
90859095

src/net.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
170170
c->fn = fn;
171171
c->is_client = true;
172172
c->fn_data = fn_data;
173-
MG_DEBUG(("%lu %ld %s", c->id, c->fd, url));
173+
c->is_tls = (mg_url_is_ssl(url) != 0);
174174
mg_call(c, MG_EV_OPEN, (void *) url);
175+
MG_DEBUG(("%lu %ld %s", c->id, c->fd, url));
175176
mg_resolve(c, url);
176177
}
177178
return c;
@@ -193,8 +194,8 @@ struct mg_connection *mg_listen(struct mg_mgr *mgr, const char *url,
193194
LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c);
194195
c->fn = fn;
195196
c->fn_data = fn_data;
197+
c->is_tls = (mg_url_is_ssl(url) != 0);
196198
mg_call(c, MG_EV_OPEN, NULL);
197-
if (mg_url_is_ssl(url)) c->is_tls = 1; // Accepted connection must
198199
MG_DEBUG(("%lu %ld %s", c->id, c->fd, url));
199200
}
200201
return c;

src/net_builtin.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static void settmout(struct mg_connection *c, uint8_t type) {
177177
: type == MIP_TTYPE_SYN ? MIP_TCP_SYN_MS
178178
: type == MIP_TTYPE_FIN ? MIP_TCP_FIN_MS
179179
: MIP_TCP_KEEPALIVE_MS;
180-
if (s->ttype == MIP_TTYPE_FIN) return; // skip if 3-way closing
180+
if (s->ttype == MIP_TTYPE_FIN) return; // skip if 3-way closing
181181
s->timer = ifp->now + n;
182182
s->ttype = type;
183183
MG_VERBOSE(("%lu %d -> %llx", c->id, type, s->timer));
@@ -580,7 +580,7 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
580580
return NULL;
581581
}
582582
struct connstate *s = (struct connstate *) (c + 1);
583-
s->dmss = 536; // assume default, RFC-9293 3.7.1
583+
s->dmss = 536; // assume default, RFC-9293 3.7.1
584584
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq);
585585
memcpy(s->mac, pkt->eth->src, sizeof(s->mac));
586586
settmout(c, MIP_TTYPE_KEEPALIVE);
@@ -595,8 +595,10 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
595595
c->pfn_data = lsn->pfn_data;
596596
c->fn = lsn->fn;
597597
c->fn_data = lsn->fn_data;
598+
c->is_tls = lsn->is_tls;
598599
mg_call(c, MG_EV_OPEN, NULL);
599600
mg_call(c, MG_EV_ACCEPT, NULL);
601+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
600602
return c;
601603
}
602604

@@ -784,6 +786,7 @@ static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) {
784786
settmout(c, MIP_TTYPE_KEEPALIVE);
785787
mg_call(c, MG_EV_CONNECT, NULL); // Let user know
786788
if (c->is_tls_hs) mg_tls_handshake(c);
789+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
787790
} else if (c != NULL && c->is_connecting && pkt->tcp->flags != TH_ACK) {
788791
// mg_hexdump(pkt->raw.buf, pkt->raw.len);
789792
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
@@ -1209,16 +1212,18 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
12091212
for (c = mgr->conns; c != NULL; c = tmp) {
12101213
tmp = c->next;
12111214
struct connstate *s = (struct connstate *) (c + 1);
1215+
bool is_tls = !c->is_resolving && !c->is_arplooking && !c->is_listening &&
1216+
!c->is_connecting;
12121217
mg_call(c, MG_EV_POLL, &now);
12131218
MG_VERBOSE(("%lu .. %c%c%c%c%c %lu %lu", c->id, c->is_tls ? 'T' : 't',
12141219
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
12151220
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c',
12161221
mg_tls_pending(c), c->rtls.len));
12171222
// order is important, TLS conn close with > 1 record in buffer (below)
1218-
if (c->is_tls && (c->rtls.len > 0 || mg_tls_pending(c) > 0))
1223+
if (is_tls && (c->rtls.len > 0 || mg_tls_pending(c) > 0))
12191224
handle_tls_recv(c);
12201225
if (can_write(c)) write_conn(c);
1221-
if (!c->is_listening && c->is_tls && !c->is_tls_hs && c->send.len == 0) mg_tls_flush(c);
1226+
if (is_tls && c->send.len == 0) mg_tls_flush(c);
12221227
if (c->is_draining && c->send.len == 0 && s->ttype != MIP_TTYPE_FIN)
12231228
init_closure(c);
12241229
// For non-TLS, close immediately upon completing the 3-way closure

src/sock.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ static void connect_conn(struct mg_connection *c) {
361361
mg_call(c, MG_EV_CONNECT, NULL);
362362
MG_EPOLL_MOD(c, 0);
363363
if (c->is_tls_hs) mg_tls_handshake(c);
364+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
364365
} else {
365366
mg_error(c, "socket error");
366367
}
@@ -413,6 +414,7 @@ void mg_connect_resolved(struct mg_connection *c) {
413414
if (rc == 0) { // Success
414415
setlocaddr(FD(c), &c->loc);
415416
mg_call(c, MG_EV_CONNECT, NULL); // Send MG_EV_CONNECT to the user
417+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
416418
} else if (MG_SOCK_PENDING(rc)) { // Need to wait for TCP handshake
417419
MG_DEBUG(("%lu %ld -> %M pend", c->id, c->fd, mg_print_ip_port, &c->rem));
418420
c->is_connecting = 1;
@@ -468,10 +470,12 @@ static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
468470
c->pfn_data = lsn->pfn_data;
469471
c->fn = lsn->fn;
470472
c->fn_data = lsn->fn_data;
473+
c->is_tls = lsn->is_tls;
471474
MG_DEBUG(("%lu %ld accepted %M -> %M", c->id, c->fd, mg_print_ip_port,
472475
&c->rem, mg_print_ip_port, &c->loc));
473476
mg_call(c, MG_EV_OPEN, NULL);
474477
mg_call(c, MG_EV_ACCEPT, NULL);
478+
if (!c->is_tls_hs) c->is_tls = 0; // user did not call mg_tls_init()
475479
}
476480
}
477481

tutorials/http/device-dashboard/net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static void handle_firmware_upload(struct mg_connection *c,
205205
// HTTP request handler function
206206
static void fn(struct mg_connection *c, int ev, void *ev_data) {
207207
if (ev == MG_EV_ACCEPT) {
208-
if (c->fn_data != NULL) { // TLS listener!
208+
if (c->is_tls) { // TLS listener!
209209
struct mg_tls_opts opts = {0};
210210
opts.cert = mg_unpacked("/certs/server_cert.pem");
211211
opts.key = mg_unpacked("/certs/server_key.pem");
@@ -253,7 +253,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
253253
void web_init(struct mg_mgr *mgr) {
254254
s_settings.device_name = strdup("My Device");
255255
mg_http_listen(mgr, HTTP_URL, fn, NULL);
256-
mg_http_listen(mgr, HTTPS_URL, fn, (void *) 1);
256+
mg_http_listen(mgr, HTTPS_URL, fn, NULL);
257257
mg_timer_add(mgr, 3600 * 1000, MG_TIMER_RUN_NOW | MG_TIMER_REPEAT,
258258
timer_sntp_fn, mgr);
259259
}

tutorials/http/file-upload-single-post/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void handle_uploads(struct mg_connection *c, int ev, void *ev_data) {
7474
}
7575

7676
static void fn(struct mg_connection *c, int ev, void *ev_data) {
77-
if (ev == MG_EV_ACCEPT && c->fn_data != NULL) {
77+
if (ev == MG_EV_ACCEPT && c->is_tls) {
7878
struct mg_tls_opts opts = {.cert = mg_str(s_tls_cert),
7979
.key = mg_str(s_tls_key)};
8080
mg_tls_init(c, &opts);

tutorials/http/http-client/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
2828
// Connected to server. Extract host name from URL
2929
struct mg_str host = mg_url_host(s_url);
3030

31-
if (mg_url_is_ssl(s_url)) {
31+
if (c->is_tls) {
3232
struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
3333
.name = mg_url_host(s_url)};
3434
mg_tls_init(c, &opts);

tutorials/http/http-proxy-client/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
2121
// Proxy TCP connection established. Send CONNECT request
2222
struct mg_str host = mg_url_host(url);
2323

24-
if (mg_url_is_ssl(url)) {
24+
if (c->is_tls) {
2525
struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
2626
.name = host};
2727
mg_tls_init(c, &opts);

tutorials/http/http-restful-server/main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static const char *s_tls_key =
5252
// We use the same event handler function for HTTP and HTTPS connections
5353
// fn_data is NULL for plain HTTP, and non-NULL for HTTPS
5454
static void fn(struct mg_connection *c, int ev, void *ev_data) {
55-
if (ev == MG_EV_ACCEPT && c->fn_data != NULL) {
55+
if (ev == MG_EV_ACCEPT && c->is_tls) {
5656
struct mg_tls_opts opts;
5757
memset(&opts, 0, sizeof(opts));
5858
#ifdef TLS_TWOWAY
@@ -91,12 +91,12 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
9191
}
9292

9393
int main(void) {
94-
struct mg_mgr mgr; // Event manager
95-
mg_log_set(MG_LL_DEBUG); // Set log level
96-
mg_mgr_init(&mgr); // Initialise event manager
97-
mg_http_listen(&mgr, s_http_addr, fn, NULL); // Create HTTP listener
98-
mg_http_listen(&mgr, s_https_addr, fn, (void *) 1); // HTTPS listener
99-
for (;;) mg_mgr_poll(&mgr, 1000); // Infinite event loop
94+
struct mg_mgr mgr; // Event manager
95+
mg_log_set(MG_LL_DEBUG); // Set log level
96+
mg_mgr_init(&mgr); // Initialise event manager
97+
mg_http_listen(&mgr, s_http_addr, fn, NULL); // Create HTTP listener
98+
mg_http_listen(&mgr, s_https_addr, fn, NULL); // HTTPS listener
99+
for (;;) mg_mgr_poll(&mgr, 1000); // Infinite event loop
100100
mg_mgr_free(&mgr);
101101
return 0;
102102
}

tutorials/http/http-reverse-proxy/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
5858
if (c2 == NULL) {
5959
mg_error(c, "Cannot create backend connection");
6060
} else {
61-
if (mg_url_is_ssl(s_backend_url)) {
61+
if (c->is_tls) {
6262
struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
6363
.name = mg_url_host(s_backend_url)};
6464
mg_tls_init(c2, &opts);

tutorials/http/http-server/arduino/w5500-http/w5500-http.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
5353
}
5454
}
5555
// Initialise TLS if we're a TLS listener
56-
if (ev == MG_EV_ACCEPT && c->fn_data != NULL) {
56+
if (c->is_tls && ev == MG_EV_ACCEPT) {
5757
struct mg_tls_opts opts;
5858
memset(&opts, 0, sizeof(opts));
5959

@@ -102,7 +102,7 @@ void setup() {
102102

103103
// Setup HTTP & HTTPS listeners. Respond "ok" on any HTTP request
104104
mg_http_listen(&mgr, "http://0.0.0.0:80", http_ev_handler, NULL);
105-
mg_http_listen(&mgr, "https://0.0.0.0:443", http_ev_handler, (void *) 1);
105+
mg_http_listen(&mgr, "https://0.0.0.0:443", http_ev_handler, NULL);
106106
}
107107

108108
void loop() {

tutorials/http/http-server/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void signal_handler(int signo) {
5252
// Event handler for the listening connection.
5353
// Simply serve static files from `s_root_dir`
5454
static void cb(struct mg_connection *c, int ev, void *ev_data) {
55-
if (ev == MG_EV_ACCEPT && c->fn_data != NULL) {
55+
if (ev == MG_EV_ACCEPT && c->is_tls) {
5656
struct mg_tls_opts opts;
5757
memset(&opts, 0, sizeof(opts));
5858
#ifdef TLS_TWOWAY
@@ -164,8 +164,8 @@ int main(int argc, char *argv[]) {
164164
s_addr1));
165165
exit(EXIT_FAILURE);
166166
}
167-
if ((c = mg_http_listen(&mgr, s_addr2, cb, (void *) 1)) == NULL) {
168-
MG_ERROR(("Cannot listen on %s. Use http://ADDR:PORT or :PORT",
167+
if ((c = mg_http_listen(&mgr, s_addr2, cb, NULL)) == NULL) {
168+
MG_ERROR(("Cannot listen on %s. Use https://ADDR:PORT",
169169
s_addr2));
170170
exit(EXIT_FAILURE);
171171
}

tutorials/http/http-streaming-client/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
1919
if (ev == MG_EV_CONNECT) {
2020
// Connected to server. Extract host name from URL
2121
struct mg_str host = mg_url_host(s_url);
22-
if (mg_url_is_ssl(s_url)) {
22+
if (c->is_tls) {
2323
struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
2424
.name = host};
2525
mg_tls_init(c, &opts);

tutorials/http/wifi-router-dashboard/net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static void handle_dhcp_get(struct mg_connection *c) {
276276
// HTTP request handler function
277277
static void fn(struct mg_connection *c, int ev, void *ev_data) {
278278
if (ev == MG_EV_ACCEPT) {
279-
if (c->fn_data != NULL) { // TLS
279+
if (c->is_tls) {
280280
struct mg_tls_opts opts = {0};
281281
opts.cert = mg_str(s_tls_cert);
282282
opts.key = mg_str(s_tls_key);
@@ -323,7 +323,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
323323

324324
void web_init(struct mg_mgr *mgr) {
325325
mg_http_listen(mgr, HTTP_URL, fn, NULL);
326-
mg_http_listen(mgr, HTTPS_URL, fn, (void *) 1);
326+
mg_http_listen(mgr, HTTPS_URL, fn, NULL);
327327

328328
// mg_timer_add(c->mgr, 1000, MG_TIMER_REPEAT, timer_mqtt_fn, c->mgr);
329329
mg_timer_add(mgr, 3600 * 1000, MG_TIMER_RUN_NOW | MG_TIMER_REPEAT,

tutorials/mqtt/mqtt-client-aws-iot/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
4040
if (ev == MG_EV_OPEN) {
4141
// c->is_hexdumping = 1;
4242
} else if (ev == MG_EV_CONNECT) {
43-
if (mg_url_is_ssl(s_url)) {
43+
if (c->is_tls) {
4444
struct mg_tls_opts opts = {.ca = mg_unpacked("/ca.pem"),
4545
.cert = mg_unpacked("/crt.pem"),
4646
.key = mg_unpacked("/key.pem"),

tutorials/mqtt/mqtt-client/arduino/sim800-mqtt/sim800-mqtt.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void handle_command(struct mg_str msg) {
5959
}
6060

6161
static void mqtt_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
62-
if (ev == MG_EV_CONNECT && mg_url_is_ssl(MQTT_SERVER)) {
62+
if (c->is_tls && ev == MG_EV_CONNECT) {
6363
struct mg_tls_opts opts = {};
6464
opts.ca = mg_str(TLS_CA);
6565
mg_tls_init(c, &opts);

tutorials/mqtt/mqtt-client/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
2929
MG_INFO(("%lu CREATED", c->id));
3030
// c->is_hexdumping = 1;
3131
} else if (ev == MG_EV_CONNECT) {
32-
if (mg_url_is_ssl(s_url)) {
32+
if (c->is_tls) {
3333
struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
3434
.name = mg_url_host(s_url)};
3535
mg_tls_init(c, &opts);

tutorials/mqtt/mqtt-over-ws-client/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
2525
// On error, log error message
2626
MG_ERROR(("%p %s", c->fd, (char *) ev_data));
2727
} else if (ev == MG_EV_CONNECT) {
28-
if (mg_url_is_ssl(s_url)) {
28+
if (c->is_tls) {
2929
struct mg_tls_opts opts = {.ca = mg_unpacked("/certs/ca.pem"),
3030
.name = mg_url_host(s_url)};
3131
mg_tls_init(c, &opts);

0 commit comments

Comments
 (0)