void send_iq_error(LmConnection *c, LmMessage *m, guint error) { LmMessage *r; r = lm_message_new_iq_error(m, error); lm_connection_send(c, r, NULL); lm_message_unref(r); }
LmHandlerResult handle_iq_commands(LmMessageHandler *h, LmConnection *c, LmMessage *m, gpointer ud) { const char *requester_jid = NULL; LmMessageNode *cmd; const struct adhoc_command *command; // mcabber has only partial XEP-0146 support... if (LM_MESSAGE_SUB_TYPE_SET != lm_message_get_sub_type(m)) return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; requester_jid = lm_message_get_from(m); cmd = lm_message_node_get_child(m->node, "command"); if (!cmd) { //send_iq_error(c, m, XMPP_ERROR_BAD_REQUEST); return LM_HANDLER_RESULT_REMOVE_MESSAGE; } if (jid_equal(lm_connection_get_jid(c), requester_jid)) { const char *action, *node; action = lm_message_node_get_attribute(cmd, "action"); node = lm_message_node_get_attribute(cmd, "node"); // action can be NULL, in which case it seems to take the default, // ie execute if (!action || !strcmp(action, "execute") || !strcmp(action, "cancel") || !strcmp(action, "next") || !strcmp(action, "complete")) { for (command = adhoc_command_list; command->name; command++) { if (!strcmp(node, command->name)) command->callback(h, c, m, ud); } // "prev" action will get there, as we do not implement it, // and do not authorize it } else { LmMessage *r; LmMessageNode *err; r = lm_message_new_iq_error(m, XMPP_ERROR_BAD_REQUEST); if (r) { err = lm_message_node_get_child(r->node, "error"); lm_message_node_set_attribute (lm_message_node_add_child(err, "malformed-action", NULL), "xmlns", NS_COMMANDS); lm_connection_send(c, r, NULL); lm_message_unref(r); } } } else { send_iq_error(c, m, XMPP_ERROR_FORBIDDEN); } return LM_HANDLER_RESULT_REMOVE_MESSAGE; }