Convert bot.c to the new helpers
This commit is contained in:
committed by
Dmitry Podgorny
parent
3a56d68f47
commit
d460a5eb16
@@ -28,14 +28,11 @@ int version_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void
|
|||||||
xmpp_stanza_t *reply, *query, *name, *version, *text;
|
xmpp_stanza_t *reply, *query, *name, *version, *text;
|
||||||
char *ns;
|
char *ns;
|
||||||
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
|
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
|
||||||
printf("Received version request from %s\n", xmpp_stanza_get_attribute(stanza, "from"));
|
printf("Received version request from %s\n", xmpp_stanza_get_from(stanza));
|
||||||
|
|
||||||
reply = xmpp_stanza_new(ctx);
|
reply = xmpp_stanza_reply(stanza);
|
||||||
xmpp_stanza_set_name(reply, "iq");
|
|
||||||
xmpp_stanza_set_type(reply, "result");
|
xmpp_stanza_set_type(reply, "result");
|
||||||
xmpp_stanza_set_id(reply, xmpp_stanza_get_id(stanza));
|
|
||||||
xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from"));
|
|
||||||
|
|
||||||
query = xmpp_stanza_new(ctx);
|
query = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(query, "query");
|
xmpp_stanza_set_name(query, "query");
|
||||||
ns = xmpp_stanza_get_ns(xmpp_stanza_get_children(stanza));
|
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
|
|||||||
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
|
xmpp_ctx_t *ctx = (xmpp_ctx_t*)userdata;
|
||||||
|
|
||||||
if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1;
|
if(!xmpp_stanza_get_child_by_name(stanza, "body")) return 1;
|
||||||
if(xmpp_stanza_get_attribute(stanza, "type") !=NULL && !strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error")) return 1;
|
if(xmpp_stanza_get_type(stanza) !=NULL && !strcmp(xmpp_stanza_get_type(stanza), "error")) return 1;
|
||||||
|
|
||||||
intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
|
intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
|
||||||
|
|
||||||
printf("Incoming message from %s: %s\n", xmpp_stanza_get_attribute(stanza, "from"), intext);
|
printf("Incoming message from %s: %s\n", xmpp_stanza_get_from(stanza), intext);
|
||||||
|
|
||||||
reply = xmpp_stanza_new(ctx);
|
|
||||||
xmpp_stanza_set_name(reply, "message");
|
|
||||||
xmpp_stanza_set_type(reply, xmpp_stanza_get_type(stanza)?xmpp_stanza_get_type(stanza):"chat");
|
|
||||||
xmpp_stanza_set_attribute(reply, "to", xmpp_stanza_get_attribute(stanza, "from"));
|
|
||||||
|
|
||||||
|
reply = xmpp_stanza_reply(stanza);
|
||||||
|
if (xmpp_stanza_get_type(reply) == NULL)
|
||||||
|
xmpp_stanza_set_type(reply, "chat");
|
||||||
|
|
||||||
body = xmpp_stanza_new(ctx);
|
body = xmpp_stanza_new(ctx);
|
||||||
xmpp_stanza_set_name(body, "body");
|
xmpp_stanza_set_name(body, "body");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user