summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/basic.c11
-rw-r--r--src/rexmpp.c25
-rw-r--r--src/rexmpp.h19
3 files changed, 21 insertions, 34 deletions
diff --git a/examples/basic.c b/examples/basic.c
index 1f5527a..d9a3f65 100644
--- a/examples/basic.c
+++ b/examples/basic.c
@@ -69,12 +69,11 @@ main (int argc, char **argv) {
return -1;
}
- err = rexmpp_init(&s,
- argv[1],
- my_logger,
- my_sasl_property_cb,
- my_xml_in_cb,
- my_xml_out_cb);
+ err = rexmpp_init(&s, argv[1]);
+ s.log_function = my_logger;
+ s.sasl_property_cb = my_sasl_property_cb;
+ s.xml_in_cb = my_xml_in_cb;
+ s.xml_out_cb = my_xml_out_cb;
if (err != REXMPP_SUCCESS) {
puts("error");
return -1;
diff --git a/src/rexmpp.c b/src/rexmpp.c
index c74b92b..959626a 100644
--- a/src/rexmpp.c
+++ b/src/rexmpp.c
@@ -203,18 +203,13 @@ xmlNodePtr rexmpp_xml_default_disco_info () {
int rexmpp_sasl_cb (Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop) {
rexmpp_t *s = gsasl_callback_hook_get(ctx);
- if (s == NULL) {
+ if (s == NULL || s->sasl_property_cb == 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,
- sasl_property_cb_t sasl_property_cb,
- xml_in_cb_t xml_in_cb,
- xml_out_cb_t xml_out_cb)
+rexmpp_err_t rexmpp_init (rexmpp_t *s, const char *jid)
{
int err;
xmlSAXHandler sax = {
@@ -262,21 +257,23 @@ rexmpp_err_t rexmpp_init (rexmpp_t *s,
s->reconnect_number = 0;
s->next_reconnect_time.tv_sec = 0;
s->next_reconnect_time.tv_usec = 0;
- s->initial_jid = jid;
+ s->initial_jid = NULL;
s->assigned_jid = NULL;
s->stanza_queue_size = 1024;
s->send_queue_size = 1024;
s->iq_queue_size = 1024;
- s->log_function = log_function;
- s->sasl_property_cb = sasl_property_cb;
- s->xml_in_cb = xml_in_cb;
- s->xml_out_cb = xml_out_cb;
+ s->log_function = NULL;
+ s->sasl_property_cb = NULL;
+ s->xml_in_cb = NULL;
+ s->xml_out_cb = NULL;
if (jid == NULL) {
rexmpp_log(s, LOG_CRIT, "No initial JID is provided.");
return REXMPP_E_JID;
}
+ s->initial_jid = strdup(jid);
+
s->xml_parser = xmlCreatePushParserCtxt(&sax, s, "", 0, NULL);
if (s->xml_parser == NULL) {
@@ -402,6 +399,10 @@ void rexmpp_done (rexmpp_t *s) {
ares_destroy(s->resolver_channel);
ares_library_cleanup();
xmlFreeParserCtxt(s->xml_parser);
+ if (s->initial_jid != NULL) {
+ free(s->initial_jid);
+ s->initial_jid = NULL;
+ }
if (s->stream_id != NULL) {
free(s->stream_id);
s->stream_id = NULL;
diff --git a/src/rexmpp.h b/src/rexmpp.h
index cb650a3..4d2e29c 100644
--- a/src/rexmpp.h
+++ b/src/rexmpp.h
@@ -218,7 +218,7 @@ struct rexmpp
enum carbons_st carbons_state;
/* Basic configuration. */
- const char *initial_jid;
+ char *initial_jid;
/* Manual host/port configuration. */
const char *manual_host;
@@ -322,23 +322,10 @@ struct rexmpp
@brief ::rexmpp structure initialisation.
@param[out] s An allocated structure.
@param[in] jid Initial bare JID.
- @param[in] log_function A user-provided logging function, can be
- NULL.
- @param[in] sasl_property_cb A callback to ask for SASL properties
- (such as password).
- @param[in] xml_in_cb A function to handle incoming XML elements. It
- is called before other processing, so it can alter the elements, or
- interrupt processing by returning a non-zero value. Optional.
- @param[in] xml_out_cb Akin to the previous one, but for outbound
- elements.
@returns ::REXMPP_SUCCESS or some ::rexmpp_err error.
*/
-rexmpp_err_t rexmpp_init (rexmpp_t *s,
- const char *jid,
- log_function_t log_function,
- sasl_property_cb_t sasl_property_cb,
- xml_in_cb_t xml_in_cb,
- xml_out_cb_t xml_out_cb);
+rexmpp_err_t rexmpp_init (rexmpp_t *s, const char *jid);
+
/**
@brief ::rexmpp structure deinitialisation. This will free all the
allocated resources.