From 27f613bc8413a60120bd5a19135d0e756f88ae51 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Sun, 18 Feb 2018 13:18:43 +0200 Subject: [PATCH] stanza: small fixes in xmpp_error_new() - Receive const text - Move variable declaration to the beginning of the block --- src/stanza.c | 10 +++++++--- strophe.h | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/stanza.c b/src/stanza.c index 76e8f40..8e45f23 100644 --- a/src/stanza.c +++ b/src/stanza.c @@ -1220,7 +1220,7 @@ xmpp_stanza_t *xmpp_presence_new(xmpp_ctx_t *ctx) } /** Create an stanza object with given type and error text. - * iError text are optional and may be NULL. + * The error text is optional and may be NULL. * * @param ctx a Strophe context object * @param type enum of xmpp_error_type_t @@ -1228,9 +1228,12 @@ xmpp_stanza_t *xmpp_presence_new(xmpp_ctx_t *ctx) * * @return a new Strophe stanza object * + * @todo Handle errors in this function + * * @ingroup Stanza */ -xmpp_stanza_t *xmpp_error_new(xmpp_ctx_t *ctx, xmpp_error_type_t const type, char * const text) +xmpp_stanza_t *xmpp_error_new(xmpp_ctx_t *ctx, xmpp_error_type_t const type, + const char * const text) { xmpp_stanza_t *error = _stanza_new_with_attrs(ctx, "stream:error", NULL, NULL, NULL); xmpp_stanza_t *error_type = xmpp_stanza_new(ctx); @@ -1319,10 +1322,11 @@ xmpp_stanza_t *xmpp_error_new(xmpp_ctx_t *ctx, xmpp_error_type_t const type, cha if (text) { xmpp_stanza_t *error_text = xmpp_stanza_new(ctx); + xmpp_stanza_t *content = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(error_text, "text"); xmpp_stanza_set_ns(error_text, XMPP_NS_STREAMS_IETF); - xmpp_stanza_t *content = xmpp_stanza_new(ctx); xmpp_stanza_set_text(content, text); xmpp_stanza_add_child(error_text, content); xmpp_stanza_release(content); diff --git a/strophe.h b/strophe.h index 9a81c3c..5a18f1a 100644 --- a/strophe.h +++ b/strophe.h @@ -382,7 +382,8 @@ int xmpp_message_set_body(xmpp_stanza_t *msg, const char * const text); xmpp_stanza_t *xmpp_iq_new(xmpp_ctx_t *ctx, const char * const type, const char * const id); xmpp_stanza_t *xmpp_presence_new(xmpp_ctx_t *ctx); -xmpp_stanza_t *xmpp_error_new(xmpp_ctx_t *ctx, xmpp_error_type_t const type, char * const text); +xmpp_stanza_t *xmpp_error_new(xmpp_ctx_t *ctx, xmpp_error_type_t const type, + const char * const text); /* jid */