summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2020-05-09 12:17:45 +0300
committerdefanor <defanor@uberspace.net>2020-05-09 12:17:45 +0300
commit97a1943d41d0bf067ddd3b6a465ba447d41923de (patch)
tree87cc7fbc01724478f1bc49ab1542611b295885a4
parenta94e340cc77152535383d53dbbaecd5076201a1c (diff)
downloadrexmpp-97a1943d41d0bf067ddd3b6a465ba447d41923de.zip
rexmpp-97a1943d41d0bf067ddd3b6a465ba447d41923de.tar.gz
rexmpp-97a1943d41d0bf067ddd3b6a465ba447d41923de.tar.bz2
Wrap the SASL property callback
So that a library user's SASL property callback gets a pointer to the whole rexmpp structure at once, similarly to other callbacks.
-rw-r--r--examples/basic.c6
-rw-r--r--src/rexmpp.c11
-rw-r--r--src/rexmpp.h2
3 files changed, 14 insertions, 5 deletions
diff --git a/examples/basic.c b/examples/basic.c
index d869f77..4ae0f8f 100644
--- a/examples/basic.c
+++ b/examples/basic.c
@@ -24,16 +24,16 @@ void my_logger (rexmpp_t *s, int priority, const char *fmt, va_list args) {
fprintf(stderr, "\n");
}
-int my_sasl_property_cb (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property prop) {
+int my_sasl_property_cb (rexmpp_t *s, Gsasl_property prop) {
if (prop == GSASL_PASSWORD) {
char buf[4096];
printf("password: ");
gets(buf);
- gsasl_property_set (sctx, GSASL_PASSWORD, buf);
+ gsasl_property_set (s->sasl_session, GSASL_PASSWORD, buf);
return GSASL_OK;
}
if (prop == GSASL_AUTHID) {
- gsasl_property_set (sctx, GSASL_AUTHID, "test");
+ gsasl_property_set (s->sasl_session, GSASL_AUTHID, "test");
return GSASL_OK;
}
printf("unhandled gsasl property: %d\n", prop);
diff --git a/src/rexmpp.c b/src/rexmpp.c
index 2e05cbb..c74b92b 100644
--- a/src/rexmpp.c
+++ b/src/rexmpp.c
@@ -201,6 +201,14 @@ xmlNodePtr rexmpp_xml_default_disco_info () {
return identity;
}
+int rexmpp_sasl_cb (Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop) {
+ rexmpp_t *s = gsasl_callback_hook_get(ctx);
+ if (s == NULL) {
+ return GSASL_NO_CALLBACK;
+ }
+ return s->sasl_property_cb(s, prop);
+}
+
rexmpp_err_t rexmpp_init (rexmpp_t *s,
const char *jid,
log_function_t log_function,
@@ -322,7 +330,8 @@ rexmpp_err_t rexmpp_init (rexmpp_t *s,
xmlFreeParserCtxt(s->xml_parser);
return REXMPP_E_SASL;
}
- gsasl_callback_set(s->sasl_ctx, s->sasl_property_cb);
+ gsasl_callback_hook_set(s->sasl_ctx, s);
+ gsasl_callback_set(s->sasl_ctx, rexmpp_sasl_cb);
s->disco_info = rexmpp_xml_default_disco_info();
diff --git a/src/rexmpp.h b/src/rexmpp.h
index 97592f7..cb650a3 100644
--- a/src/rexmpp.h
+++ b/src/rexmpp.h
@@ -199,7 +199,7 @@ enum rexmpp_err {
typedef enum rexmpp_err rexmpp_err_t;
typedef void (*log_function_t) (rexmpp_t *s, int priority, const char *format, va_list args);
-typedef int (*sasl_property_cb_t) (Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop);
+typedef int (*sasl_property_cb_t) (rexmpp_t *s, Gsasl_property prop);
typedef int (*xml_in_cb_t) (rexmpp_t *s, xmlNodePtr node);
typedef int (*xml_out_cb_t) (rexmpp_t *s, xmlNodePtr node);