From 443b4d3116b62a33d83a9ef87ea1e7ad8c0e388d Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Tue, 20 Jun 2017 01:38:53 +0300 Subject: [PATCH] Use more variables in bot.c message_handler() to avoid calling the same function twice. --- examples/bot.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/bot.c b/examples/bot.c index f11b6db..c6312eb 100644 --- a/examples/bot.c +++ b/examples/bot.c @@ -73,15 +73,18 @@ int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata; - xmpp_stanza_t *reply; + xmpp_stanza_t *body, *reply; + const char *type; char *intext, *replytext; - if (!xmpp_stanza_get_child_by_name(stanza, "body")) + body = xmpp_stanza_get_child_by_name(stanza, "body"); + if (body == NULL) return 1; - if (xmpp_stanza_get_type(stanza) != NULL && !strcmp(xmpp_stanza_get_type(stanza), "error")) + type = xmpp_stanza_get_type(stanza); + if (type != NULL && strcmp(type, "error") == 0) return 1; - intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body")); + intext = xmpp_stanza_get_text(body); printf("Incoming message from %s: %s\n", xmpp_stanza_get_from(stanza), intext);