static LmHandlerResult handle_register(LmMessageHandler *handler, LmConnection *connection, LmMessage *lmsg, gpointer user_data) { LmMessageNode *node; struct register_data *rd; const char *id; char *cmd; int error; rd = user_data; id = lm_message_node_get_attribute(lmsg->node, "id"); if (id == NULL || (id != NULL && strcmp(id, rd->id) != 0)) return LM_HANDLER_RESULT_REMOVE_MESSAGE; if ((node = lm_message_node_get_child(lmsg->node, "error")) != NULL) { error = atoi(lm_message_node_get_attribute(node, "code")); signal_emit("xmpp registration failed", 3, rd->username, rd->domain, GINT_TO_POINTER(error)); } else { signal_emit("xmpp registration succeed", 2, rd->username, rd->domain); cmd = g_strdup_printf( "%sXMPPCONNECT %s-host %s -port %d %s@%s %s", settings_get_str("cmdchars"), rd->use_ssl ? "-ssl " : "", rd->address, rd->port, rd->username, rd->domain, rd->password); signal_emit("send command", 3, cmd, NULL, NULL); g_free(cmd); } rd_cleanup(rd); return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
static void send_register(struct register_data *rd) { LmMessage *lmsg; LmMessageNode *node; char *recoded; lmsg = lm_message_new_with_sub_type(rd->domain, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); node = lm_message_node_add_child(lmsg->node, "query", NULL); lm_message_node_set_attribute(node, XMLNS, XMLNS_REGISTER); recoded = xmpp_recode_out(rd->username); lm_message_node_add_child(node, "username", recoded); g_free(recoded); recoded = xmpp_recode_out(rd->password); lm_message_node_add_child(node, "password", recoded); g_free(recoded); rd->id = g_strdup(lm_message_node_get_attribute(lmsg->node, "id")); if (!lm_connection_send_with_reply(rd->lmconn, lmsg, rd->handler, NULL)) { signal_emit("xmpp registration failed", 3, rd->username, rd->domain, REGISTRATION_ERROR_INFO); rd_cleanup(rd); } lm_message_unref(lmsg); }
void registration_deinit(void) { GSList *tmp, *next; command_unbind("xmppregister", (SIGNAL_FUNC)cmd_xmppregister); command_unbind("xmppunregister", (SIGNAL_FUNC)cmd_xmppunregister); command_unbind("xmpppasswd", (SIGNAL_FUNC)cmd_xmpppasswd); for (tmp = register_data; tmp != NULL; tmp = next) { next = tmp->next; rd_cleanup((struct register_data *)tmp->data); } }
static void register_lm_close_cb(LmConnection *connection, LmDisconnectReason reason, gpointer user_data) { struct register_data *rd; if (reason == LM_DISCONNECT_REASON_OK) return; rd = user_data; signal_emit("xmpp registration failed", 3, rd->username, rd->domain, REGISTRATION_ERROR_UNKNOWN); rd_cleanup(rd); }
static void start_registration(struct register_data *rd) { LmConnection *lmconn; GError *error = NULL; lmconn = lm_connection_new(NULL); if (rd->use_ssl) { if (!set_ssl(lmconn, &error, NULL, FALSE)) goto err; } else { if (!set_ssl(lmconn, &error, NULL, TRUE)) goto err; } if (settings_get_bool("xmpp_use_proxy") && !set_proxy(lmconn, &error)) goto err; if (rd->port <= 0) rd->port = rd->use_ssl ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT; lm_connection_set_server(lmconn, rd->address); lm_connection_set_port(lmconn, rd->port); lm_connection_set_jid(lmconn, NULL); rd->id = NULL; rd->lmconn = lmconn; rd->handler = NULL; register_data = g_slist_prepend(register_data, rd); lm_connection_set_disconnect_function(lmconn, register_lm_close_cb, rd, NULL); if (!lm_connection_open(lmconn, register_lm_open_cb, rd, NULL, &error)) { rd_cleanup(rd); signal_emit("xmpp register error", 3, rd->username, rd->domain, error != NULL ? error->message : NULL); if (error != NULL) g_error_free(error); } return; err: signal_emit("xmpp register error", 3, rd->username, rd->domain, error != NULL ? error->message : NULL); if (error != NULL) g_error_free(error); lm_connection_unref(lmconn); }
static void register_lm_open_cb(LmConnection *connection, gboolean success, gpointer user_data) { struct register_data *rd; rd = user_data; if (!success) goto err; rd->handler = lm_message_handler_new(handle_register, rd, NULL); send_register(rd); return; err: signal_emit("xmpp registration failed", 3, rd->username, rd->domain, REGISTRATION_ERROR_CONNECTION); rd_cleanup(rd); }