void xmpp_cleanup() { xmpp_disconnect(); if (connection) lm_connection_unref(connection); xmpp_roster_cleanup(); config_cleanup(); } /* xmpp_cleanup */
bool XMPPAccountHandler::tearDown() { if (m_pConnection) { // unregister and destroy the message handler callbacks if (m_pPresenceHandler) { lm_connection_unregister_message_handler(m_pConnection, m_pPresenceHandler, LM_MESSAGE_TYPE_PRESENCE); lm_message_handler_unref(m_pPresenceHandler); m_pPresenceHandler = NULL; } if (m_pStreamErrorHandler) { lm_connection_unregister_message_handler(m_pConnection, m_pStreamErrorHandler, LM_MESSAGE_TYPE_STREAM_ERROR); lm_message_handler_unref(m_pStreamErrorHandler); m_pStreamErrorHandler = NULL; } if (m_pChatHandler) { lm_connection_unregister_message_handler(m_pConnection, m_pChatHandler, LM_MESSAGE_TYPE_MESSAGE); lm_message_handler_unref(m_pChatHandler); m_pChatHandler = NULL; } lm_connection_close(m_pConnection, NULL); lm_connection_unref(m_pConnection); m_pConnection = NULL; } m_bLoggedIn = false; return true; }
ConnectResult XMPPAccountHandler::connect() { UT_DEBUGMSG(("XMPPAccountHandler::connect()\n")); if (m_bLoggedIn) return CONNECT_ALREADY_CONNECTED; if (m_pConnection) return CONNECT_IN_PROGRESS; // try to request a frame here; note that this might return 0, for example on application startup XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame(); const std::string server = getProperty("server"); const std::string username = getProperty("username"); const std::string port = getProperty("port"); // TODO: unused atm const std::string resource = getProperty("resource"); const std::string encryption = getProperty("encryption"); std::string jid = username + "@" + server; UT_DEBUGMSG(("Connecting to server: |%s|, username: |%s|, resource: |%s|\n", server.c_str(), username.c_str(), resource.c_str())); // NULL means perform SRV record lookup based on JID (Loudmouth 1.3.2+) m_pConnection = lm_connection_new(NULL); UT_return_val_if_fail(m_pConnection, CONNECT_INTERNAL_ERROR); lm_connection_set_jid(m_pConnection, jid.c_str()); // setup SSL if (lm_ssl_is_supported() && encryption == "true") { LmSSL* pSSL = lm_ssl_new(NULL, NULL, NULL, NULL); // TODO: free this lm_ssl_use_starttls(pSSL, TRUE, TRUE); lm_connection_set_ssl(m_pConnection, pSSL); lm_ssl_unref(pSSL); } GError* error = NULL; if (!lm_connection_open(m_pConnection, lm_connection_open_async_cb, this, NULL, &error)) { UT_DEBUGMSG(("Failed to open: %s\n", error ? error->message : "")); lm_connection_unref(m_pConnection); m_pConnection = NULL; if (pFrame) { // inform the user of the connection failure // TODO: this shouldn't be here, the caller should handle this UT_UTF8String msg; // TODO: make this localizable UT_UTF8String_sprintf(msg, "Error while connecting to %s: %s\n", server.c_str(), (error ? error->message : "")); pFrame->showMessageBox(msg.utf8_str(), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); } return CONNECT_FAILED; } return CONNECT_IN_PROGRESS; }
void xmpp_disconnect (void) { lm_connection_close (connection, NULL); lm_connection_unref (connection); destroy_user_table(); initialize_user_table(); }
LM::Presentity::~Presentity () { lm_message_node_unref (item); item = 0; lm_connection_unref (connection); connection = 0; }
//doc Loudmouth registerAccount(server, username, password) Registers a new account at XMPP server. Returns <code>true</code> or <code>false</code>. IoObject *IoLoudmouth_registerAccount(IoLoudmouth *self, IoObject *locals, IoMessage *m) { char *server = IoMessage_locals_cStringArgAt_(m, locals, 0), *username = IoMessage_locals_cStringArgAt_(m, locals, 1), *password = IoMessage_locals_cStringArgAt_(m, locals, 2), *error_message = "Unknown error"; LmConnection *connection = lm_connection_new(server); LmMessage *xmpp_msg, *xmpp_reply; LmMessageNode *query, *node; int success = 0; if(!lm_connection_open_and_block(connection, NULL)) { error_message = "Could not open connection"; success = 0; } else { xmpp_msg = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); query = lm_message_node_add_child(xmpp_msg->node, "query", NULL); lm_message_node_set_attributes(query, "xmlns", "jabber:iq:register", NULL); lm_message_node_add_child(query, "username", username); lm_message_node_add_child(query, "password", password); xmpp_reply = lm_connection_send_with_reply_and_block(connection, xmpp_msg, NULL); lm_connection_close(connection, NULL); lm_connection_unref(connection); if(!xmpp_reply) { success = 0; error_message = "No reply from server"; } else { switch(lm_message_get_sub_type(xmpp_reply)) { case LM_MESSAGE_SUB_TYPE_RESULT: success = 1; break; case LM_MESSAGE_SUB_TYPE_ERROR: default: success = 0; node = lm_message_node_find_child(xmpp_reply->node, "error"); error_message = (node == NULL) ? lm_message_node_get_value(node) : "Unknown error"; lm_message_node_unref(node); } } lm_message_unref(xmpp_reply); lm_message_unref(xmpp_msg); lm_message_node_unref(query); } free(server); free(username); free(password); IOASSERT(success, error_message); free(error_message); return IOBOOL(self, success); }
LM::Account::~Account () { if (lm_connection_is_open (connection)) { handle_down (); lm_connection_close (connection, NULL); } lm_connection_unref (connection); connection = 0; }
gboolean close_connection(MP3tunesHarmony *harmony) { GError *err = NULL; if (lm_connection_is_open(harmony->connection)) { lm_connection_close(harmony->connection, &err); lm_connection_unref(harmony->connection); if (err != NULL) { error_emit(harmony, MP3TUNES_HARMONY_ERROR_MISC, "Closing the connection failed", err); return FALSE; } /* return TRUE; */ /* state_change_emit(harmony, MP3TUNES_HARMONY_STATE_DISCONNECTED); */ } return TRUE; }
static void server_cleanup(XMPP_SERVER_REC *server) { if (!IS_XMPP_SERVER(server)) return; if (server->timeout_tag) g_source_remove(server->timeout_tag); if (lm_connection_get_state(server->lmconn) != LM_CONNECTION_STATE_CLOSED) lm_connection_close(server->lmconn, NULL); lm_connection_unref(server->lmconn); g_free(server->jid); g_free(server->user); g_free(server->domain); g_free(server->resource); g_free(server->ping_id); }
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 rd_cleanup(struct register_data *rd) { register_data = g_slist_remove(register_data, rd); g_free(rd->username); g_free(rd->domain); g_free(rd->password); g_free(rd->address); g_free(rd->id); if (rd->handler != NULL) { if (lm_message_handler_is_valid(rd->handler)) lm_message_handler_invalidate(rd->handler); lm_message_handler_unref(rd->handler); } if (lm_connection_get_state(rd->lmconn) != LM_CONNECTION_STATE_CLOSED) lm_connection_close(rd->lmconn, NULL); lm_connection_unref(rd->lmconn); g_free(rd); }
void xmpp_disconnect() { LmMessage *m; const gchar *conf_server = get_settings_str(SERVER); wantconnection = 0; if (connection == NULL) return; if (lm_connection_get_state(connection) == LM_CONNECTION_STATE_AUTHENTICATED) { m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_PRESENCE, LM_MESSAGE_SUB_TYPE_UNAVAILABLE); lm_connection_send(connection, m, NULL); } if(lm_connection_is_open(connection)) { ui_print("Closing connection to %s\n", conf_server); lm_connection_close(connection, NULL); g_printerr("Disconnected\n"); } lm_connection_unref(connection); connection = NULL; } /* xmpp_disconnect */
bool XMPPAccountHandler::authenticate() { UT_DEBUGMSG(("XMPPAccountHandler::authenticate()\n")); UT_return_val_if_fail(m_pConnection, false); // try to request a frame here; note that this might return 0, for example on application startup XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame(); const std::string server = getProperty("server"); const std::string username = getProperty("username"); const std::string password = getProperty("password"); const std::string resource = getProperty("resource"); GError* error = NULL; if (!lm_connection_authenticate(m_pConnection, username.c_str(), password.c_str(), resource.c_str(), lm_connection_authenticate_async_cb, this, NULL, &error)) { UT_DEBUGMSG(("connect() - couldn't authenticate with '%s' '%s':\n%s\n", username.c_str(), password.c_str(), (error ? error->message : ""))); lm_connection_close(m_pConnection, NULL); lm_connection_unref(m_pConnection); m_pConnection = NULL; if (pFrame) { // inform the user of the authentication failure // TODO: this shouldn't be here, the caller should handle this UT_UTF8String msg; // TODO: make this localizable UT_UTF8String_sprintf(msg, "Error while connecting to %s: %s\n", server.c_str(), (error ? error->message : "")); pFrame->showMessageBox(msg.utf8_str(), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); } return false; } return true; }
static void ft_disconnect_function (LmConnection *conn, LmDisconnectReason reason, gpointer user_data) { lm_connection_unref (state.conn); state.conn = NULL; ft_roster_flush (); // TODO: ft_file_flush (); scm_run_hook (ex_disconnect_hook, scm_list_n (scm_from_int (reason), SCM_UNDEFINED)); /* set conn_status after hook so that discon hook procedures can get the previous state from ft-get-conn-status. helps in deciding if an automatic reconnection logic (dont auto reconnect if previous state was not FT_AUTH, etc) */ do_set_conn_status (FT_DEAD); return; }
bool XMPPAccountHandler::setup() { UT_DEBUGMSG(("XMPPAccountHandler::setup()\n")); UT_return_val_if_fail(m_pConnection, false); AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager(); UT_return_val_if_fail(pManager, false); // try to request a frame here; note that this might return 0, for example on application startup XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame(); const std::string server = getProperty("server"); // Register message handler for presence messages m_pPresenceHandler = lm_message_handler_new((LmHandleMessageFunction)presence_handler, reinterpret_cast< gpointer >(this), NULL); lm_connection_register_message_handler(m_pConnection, m_pPresenceHandler, LM_MESSAGE_TYPE_PRESENCE, LM_HANDLER_PRIORITY_NORMAL); // Register message handler for stream error messages m_pStreamErrorHandler = lm_message_handler_new((LmHandleMessageFunction)stream_error_handler, reinterpret_cast< gpointer >(this), NULL); lm_connection_register_message_handler(m_pConnection, m_pStreamErrorHandler, LM_MESSAGE_TYPE_STREAM_ERROR, LM_HANDLER_PRIORITY_NORMAL); // Register message handler for chat messages m_pChatHandler = lm_message_handler_new((LmHandleMessageFunction)chat_handler, reinterpret_cast< gpointer >(this), NULL); lm_connection_register_message_handler(m_pConnection, m_pChatHandler, LM_MESSAGE_TYPE_MESSAGE, LM_HANDLER_PRIORITY_NORMAL); // Send presence message to server GError* error = NULL; LmMessage* m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_PRESENCE, LM_MESSAGE_SUB_TYPE_NOT_SET); if (!lm_connection_send(m_pConnection, m, &error)) { UT_DEBUGMSG(("Presence message could not be sent: %s", error ? error->message : "")); lm_connection_close(m_pConnection, NULL); lm_connection_unref(m_pConnection); m_pConnection = NULL; // FIXME: unregister the message handlers! // ... if (pFrame) { // inform the user of the sending error // TODO: this shouldn't be here, the caller should handle this UT_UTF8String msg; // TODO: make this localizable UT_UTF8String_sprintf(msg, "Error while connecting to %s: %s\n", server.c_str(), (error ? error->message : "")); pFrame->showMessageBox(msg.utf8_str(), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); } return false; } lm_message_unref(m); m_bLoggedIn = true; // we are connected now, time to start sending out messages (such as events) pManager->registerEventListener(this); // signal all listeners we are logged in AccountOnlineEvent event; // TODO: fill the event AbiCollabSessionManager::getManager()->signal(event); return true;; }
gboolean jid_reg(struct _jid *jid, GMainContext *context) { LmConnection *reg_connect; LmMessage *m, *reply; LmMessageNode *query, *node; GError *error = NULL; // Проверяем context if(!context) context = g_main_context_default(); // Подключаемся reg_connect = lm_connection_new_with_context(jid->server, context); // Настраиваем ssl /* if(jid->use_ssl) { LmSSL *ssl; // Проверяем поддержку ssl if(!lm_ssl_is_supported()) { g_print("Your Loudmouth doesn't support SSL. Reinstall loudmouth.\n"); jid->use_ssl = FALSE; } g_print("Configure ssl\n"); ssl = lm_ssl_new(NULL, LM_SSL_RESPONSE_CONTINUE, NULL, NULL); lm_connection_set_ssl(reg_connect, ssl); lm_ssl_unref(ssl); lm_connection_set_port(reg_connect, LM_CONNECTION_DEFAULT_PORT_SSL); } */ // Проверяем коннект if(!lm_connection_open_and_block(reg_connect, &error)) { fprintf(stderr, "Failed to open connection: %s\n", error->message); return FALSE; } // Определяем сообщение m = lm_message_new_with_sub_type(NULL, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); // Составляем запрос query = lm_message_node_add_child(m->node, "query", NULL); lm_message_node_set_attributes(query, "xmlns", "jabber:iq:register", NULL); lm_message_node_add_child(query, "username", jid->username); lm_message_node_add_child(query, "password", jid->password); // Отпревляем сообщение и ждём ответ reply = lm_connection_send_with_reply_and_block(reg_connect, m, &error); if(!reply) { fprintf(stderr, "Failed to send registration request on server \"%s\":\n %s\n", jid->server, error->message); return FALSE; } //Закрываем соединение lm_connection_close(reg_connect, NULL); lm_connection_unref(reg_connect); // Проверяем ответ switch(lm_message_get_sub_type(reply)) { case LM_MESSAGE_SUB_TYPE_RESULT: g_print("Succeeded in register account '%s@%s'\n", jid->username, jid->server); break; case LM_MESSAGE_SUB_TYPE_ERROR: default: g_print("Failed to register account '%s@%s' due to: ", jid->username, jid->server); node = lm_message_node_find_child(reply->node, "error"); if(node) g_print("%s\n", lm_message_node_get_value (node)); else g_print("Unknown error\n"); return FALSE; break; } return TRUE; }
void IoLoudmouth_free(IoLoudmouth *self) { if(LMCONN(self) != NULL) { lm_connection_close(LMCONN(self), NULL); lm_connection_unref(LMCONN(self)); } }