examples/bot: handle quit message
This commit is contained in:
@@ -76,6 +76,7 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
|
|||||||
xmpp_stanza_t *body, *reply;
|
xmpp_stanza_t *body, *reply;
|
||||||
const char *type;
|
const char *type;
|
||||||
char *intext, *replytext;
|
char *intext, *replytext;
|
||||||
|
int quit = 0;
|
||||||
|
|
||||||
body = xmpp_stanza_get_child_by_name(stanza, "body");
|
body = xmpp_stanza_get_child_by_name(stanza, "body");
|
||||||
if (body == NULL)
|
if (body == NULL)
|
||||||
@@ -92,15 +93,24 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
|
|||||||
if (xmpp_stanza_get_type(reply) == NULL)
|
if (xmpp_stanza_get_type(reply) == NULL)
|
||||||
xmpp_stanza_set_type(reply, "chat");
|
xmpp_stanza_set_type(reply, "chat");
|
||||||
|
|
||||||
replytext = (char *) malloc(strlen(" to you too!") + strlen(intext) + 1);
|
if (strcmp(intext, "quit") == 0) {
|
||||||
strcpy(replytext, intext);
|
replytext = strdup("bye!");
|
||||||
strcat(replytext, " to you too!");
|
quit = 1;
|
||||||
|
} else {
|
||||||
|
replytext = (char *) malloc(strlen(" to you too!") + strlen(intext) + 1);
|
||||||
|
strcpy(replytext, intext);
|
||||||
|
strcat(replytext, " to you too!");
|
||||||
|
}
|
||||||
xmpp_free(ctx, intext);
|
xmpp_free(ctx, intext);
|
||||||
xmpp_message_set_body(reply, replytext);
|
xmpp_message_set_body(reply, replytext);
|
||||||
|
|
||||||
xmpp_send(conn, reply);
|
xmpp_send(conn, reply);
|
||||||
xmpp_stanza_release(reply);
|
xmpp_stanza_release(reply);
|
||||||
free(replytext);
|
free(replytext);
|
||||||
|
|
||||||
|
if (quit)
|
||||||
|
xmpp_disconnect(conn);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user