Skip to content

Commit d460a5e

Browse files
tleguernpasis
authored andcommitted
Convert bot.c to the new helpers
1 parent 3a56d68 commit d460a5e

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

examples/bot.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
2828
xmpp_stanza_t *reply, *query, *name, *version, *text;
2929
char *ns;
3030
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
31-
printf("Received version request from %s\n", xmpp_stanza_get_attribute(stanza, "from"));
31+
printf("Received version request from %s\n", xmpp_stanza_get_from(stanza));
3232

33-
reply = xmpp_stanza_new(ctx);
34-
xmpp_stanza_set_name(reply, "iq");
33+
reply = xmpp_stanza_reply(stanza);
3534
xmpp_stanza_set_type(reply, "result");
36-
xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza));
37-
xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from"));
38-
35+
3936
query = xmpp_stanza_new(ctx);
4037
xmpp_stanza_set_name(query, "query");
4138
ns = xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza));
@@ -74,17 +71,16 @@ int message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
7471
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
7572

7673
if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1;
77-
if(xmpp_stanza_get_attribute(stanza, "type") !=NULL && !strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error")) return 1;
74+
if(xmpp_stanza_get_type(stanza) !=NULL && !strcmp(xmpp_stanza_get_type(stanza), "error")) return 1;
7875

7976
intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
8077

81-
printf("Incoming message from %s: %s\n", xmpp_stanza_get_attribute(stanza, "from"), intext);
82-
83-
reply = xmpp_stanza_new(ctx);
84-
xmpp_stanza_set_name(reply, "message");
85-
xmpp_stanza_set_type(reply, xmpp_stanza_get_type(stanza)?xmpp_stanza_get_type(stanza):"chat");
86-
xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from"));
78+
printf("Incoming message from %s: %s\n", xmpp_stanza_get_from(stanza), intext);
8779

80+
reply = xmpp_stanza_reply(stanza);
81+
if (xmpp_stanza_get_type(reply) == NULL)
82+
xmpp_stanza_set_type(reply, "chat");
83+
8884
body = xmpp_stanza_new(ctx);
8985
xmpp_stanza_set_name(body, "body");
9086

0 commit comments

Comments
 (0)