From a2b3b6b9e255bc350c6182cd20bd28c7b289eddb Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 2 Apr 2025 10:16:16 +0200 Subject: [PATCH] Add `xmpp_tlscert_get_userdata()` This fixes #249 Signed-off-by: Steffen Jaeckel --- src/common.h | 2 +- src/tls.c | 17 +++++++++++++++++ strophe.h | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/common.h b/src/common.h index c387c0f..a367367 100644 --- a/src/common.h +++ b/src/common.h @@ -31,7 +31,7 @@ /** handlers **/ #if (__STDC_VERSION__ >= 202000L) -typedef void* xmpp_void_handler; +typedef void *xmpp_void_handler; #else typedef int (*xmpp_void_handler)(); #endif diff --git a/src/tls.c b/src/tls.c index c548d82..e15fbb1 100644 --- a/src/tls.c +++ b/src/tls.c @@ -74,6 +74,23 @@ xmpp_conn_t *xmpp_tlscert_get_conn(const xmpp_tlscert_t *cert) return cert->conn; } +/** Get the userdata of a Strophe connection which is assigned to this + * certificate. + * + * @param cert a Strophe TLS certificate object + * + * @return the userdata of a Strophe connection object where this certificate + * originates from + * + * @ingroup TLS + */ +void *xmpp_tlscert_get_userdata(const xmpp_tlscert_t *cert) +{ + if (cert->conn == NULL) + return NULL; + return cert->conn->userdata; +} + /** Get the complete PEM of this certificate. * * @param cert a Strophe TLS certificate object diff --git a/strophe.h b/strophe.h index 65f2bf9..18ca3e1 100644 --- a/strophe.h +++ b/strophe.h @@ -642,6 +642,7 @@ void xmpp_ctx_set_timeout(xmpp_ctx_t *ctx, unsigned long timeout); xmpp_ctx_t *xmpp_tlscert_get_ctx(const xmpp_tlscert_t *cert); xmpp_conn_t *xmpp_tlscert_get_conn(const xmpp_tlscert_t *cert); +void *xmpp_tlscert_get_userdata(const xmpp_tlscert_t *cert); const char *xmpp_tlscert_get_pem(const xmpp_tlscert_t *cert); const char *xmpp_tlscert_get_dnsname(const xmpp_tlscert_t *cert, size_t n); const char *xmpp_tlscert_get_string(const xmpp_tlscert_t *cert,