From 3f5fd89fd7b1716950ef1616aea33a7df41bdea0 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Tue, 14 Dec 2021 13:21:59 +0000 Subject: [PATCH] Pass more args to custom TLS init --- mongoose.c | 6 ++++-- mongoose.h | 2 +- src/tls.h | 2 +- src/tls_mbed.c | 3 ++- src/tls_openssl.c | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mongoose.c b/mongoose.c index 2b74754a..76a141f1 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3780,7 +3780,8 @@ void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { if (tls == NULL) { mg_error(c, "TLS OOM"); goto fail; - } else if (opts->ifn != NULL && opts->ifn(opts) != 0) { + } else if (opts->custom_init != NULL && + opts->custom_init(c, opts, tls) != 0) { mg_error(c, "TLS custom init failed"); goto fail; } @@ -3948,7 +3949,8 @@ void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { if (tls == NULL) { mg_error(c, "TLS OOM"); goto fail; - } else if (opts->ifn != NULL && opts->ifn(opts) != 0) { + } else if (opts->custom_init != NULL && + opts->custom_init(c, opts, tls) != 0) { mg_error(c, "TLS custom init failed"); goto fail; } diff --git a/mongoose.h b/mongoose.h index 02c89347..09e08a54 100644 --- a/mongoose.h +++ b/mongoose.h @@ -930,7 +930,7 @@ struct mg_tls_opts { const char *certkey; // Certificate key const char *ciphers; // Cipher list struct mg_str srvname; // If not empty, enables server name verification - int (*ifn)(struct mg_tls_opts *); // Custom init func. Return 0 on success + int (*custom_init)(struct mg_connection *, struct mg_tls_opts *, void *tls); }; void mg_tls_init(struct mg_connection *, struct mg_tls_opts *); diff --git a/src/tls.h b/src/tls.h index 41662147..c9846f78 100644 --- a/src/tls.h +++ b/src/tls.h @@ -11,7 +11,7 @@ struct mg_tls_opts { const char *certkey; // Certificate key const char *ciphers; // Cipher list struct mg_str srvname; // If not empty, enables server name verification - int (*ifn)(struct mg_tls_opts *); // Custom init func. Return 0 on success + int (*custom_init)(struct mg_connection *, struct mg_tls_opts *, void *tls); }; void mg_tls_init(struct mg_connection *, struct mg_tls_opts *); diff --git a/src/tls_mbed.c b/src/tls_mbed.c index cfe192e0..af928190 100644 --- a/src/tls_mbed.c +++ b/src/tls_mbed.c @@ -58,7 +58,8 @@ void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { if (tls == NULL) { mg_error(c, "TLS OOM"); goto fail; - } else if (opts->ifn != NULL && opts->ifn(opts) != 0) { + } else if (opts->custom_init != NULL && + opts->custom_init(c, opts, tls) != 0) { mg_error(c, "TLS custom init failed"); goto fail; } diff --git a/src/tls_openssl.c b/src/tls_openssl.c index bc69b7e5..13aa0afa 100644 --- a/src/tls_openssl.c +++ b/src/tls_openssl.c @@ -28,7 +28,8 @@ void mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { if (tls == NULL) { mg_error(c, "TLS OOM"); goto fail; - } else if (opts->ifn != NULL && opts->ifn(opts) != 0) { + } else if (opts->custom_init != NULL && + opts->custom_init(c, opts, tls) != 0) { mg_error(c, "TLS custom init failed"); goto fail; }