# HG changeset patch # User Myhailo Danylenko # Date 1263887592 -7200 # Node ID d1e8fb14ce2dbc70814818d8da20221c81b49f44 # Parent 687f6b515d8774b3e5cbc3b4842ef02e2c679cea Destroy lm connection object on disconnect diff -r 687f6b515d87 -r d1e8fb14ce2d mcabber/mcabber/commands.c --- a/mcabber/mcabber/commands.c Tue Jan 19 15:45:25 2010 +0200 +++ b/mcabber/mcabber/commands.c Tue Jan 19 09:53:12 2010 +0200 @@ -888,7 +888,7 @@ char *msg; enum imstatus st; - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); return; } @@ -1022,7 +1022,7 @@ char *id, *nick; char *jid_utf8 = NULL; - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); return; } @@ -1184,7 +1184,7 @@ int isroom; gpointer xep184 = NULL; - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); return 1; } @@ -1529,7 +1529,7 @@ LmMessageSubType msg_type = LM_MESSAGE_SUB_TYPE_NOT_SET; bool quiet = FALSE; - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); return; } @@ -2249,7 +2249,7 @@ char **paramlst; char *subcmd; - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); return; } @@ -3042,7 +3042,7 @@ char *subcmd; gpointer bud; - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); return; } @@ -3139,7 +3139,7 @@ char *subcmd; char *jid_utf8; - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); return; } @@ -3253,7 +3253,7 @@ return; } - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { scr_LogPrint(LPRINT_NORMAL, "You are not connected."); free_arg_lst(paramlst); return; diff -r 687f6b515d87 -r d1e8fb14ce2d mcabber/mcabber/histolog.c --- a/mcabber/mcabber/histolog.c Tue Jan 19 15:45:25 2010 +0200 +++ b/mcabber/mcabber/histolog.c Tue Jan 19 09:53:12 2010 +0200 @@ -445,7 +445,7 @@ goto hlog_save_state_return; } - if (!lm_connection_is_authenticated(lconnection)) { + if (!lconnection || !lm_connection_is_authenticated(lconnection)) { // We're not connected. Let's use the unread_jids hash. GList *unread_jid = unread_jid_get_list(); unread_ptr = unread_jid; diff -r 687f6b515d87 -r d1e8fb14ce2d mcabber/mcabber/xmpp.c --- a/mcabber/mcabber/xmpp.c Tue Jan 19 15:45:25 2010 +0200 +++ b/mcabber/mcabber/xmpp.c Tue Jan 19 09:53:12 2010 +0200 @@ -43,7 +43,7 @@ #define RECONNECTION_TIMEOUT 60L -LmConnection* lconnection; +LmConnection* lconnection = NULL; static guint AutoConnection; inline void update_last_use(void); @@ -100,7 +100,8 @@ LmMessage *iq; char *cleanjid; - if (!lm_connection_is_authenticated(lconnection)) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection)) + return; cleanjid = jidtodisp(bjid); // Stripping resource, just in case... @@ -138,7 +139,8 @@ LmMessageNode *x; char *cleanjid; - if (!lm_connection_is_authenticated(lconnection)) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection)) + return; // XXX We should check name's and group's correctness @@ -168,7 +170,8 @@ LmMessage *iq; char *cleanjid; - if (!lm_connection_is_authenticated(lconnection)) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection)) + return; cleanjid = jidtodisp(bjid); // Stripping resource, just in case... @@ -303,7 +306,7 @@ if (encrypted) *encrypted = 0; - if (!lm_connection_is_authenticated(lconnection)) + if (!lconnection || !lm_connection_is_authenticated(lconnection)) return; if (!text && type == ROSTER_TYPE_USER) @@ -484,7 +487,8 @@ char *rjid, *fjid = NULL; struct jep0085 *jep85 = NULL; - if (!lm_connection_is_authenticated(lconnection)) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection)) + return; sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER); @@ -542,7 +546,8 @@ struct jep0022 *jep22 = NULL; guint jep22_state; - if (!lm_connection_is_authenticated(lconnection)) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection)) + return; rname = strchr(fjid, JID_RESOURCE_SEPARATOR); barejid = jidtodisp(fjid); @@ -840,13 +845,14 @@ gboolean xmpp_reconnect() { - if (!lm_connection_is_authenticated(lconnection)) + if (!lconnection) xmpp_connect(); return FALSE; } static void _try_to_reconnect(void) { + xmpp_disconnect(); if (AutoConnection) g_timeout_add_seconds(RECONNECTION_TIMEOUT, xmpp_reconnect, NULL); } @@ -1595,8 +1601,7 @@ LmMessageHandler *handler; GError *error = NULL; - if (lconnection && lm_connection_is_open(lconnection)) - xmpp_disconnect(); + xmpp_disconnect(); servername = settings_opt_get("server"); userjid = settings_opt_get("jid"); @@ -1768,14 +1773,18 @@ void xmpp_disconnect(void) { - if (!lconnection || !lm_connection_is_authenticated(lconnection)) + if (!lconnection) return; - - // Launch pre-disconnect internal hook - hook_execute_internal("hook-pre-disconnect"); - // Announce it to everyone else - xmpp_setstatus(offline, NULL, "", FALSE); - lm_connection_close(lconnection, NULL); + if (lm_connection_is_authenticated(lconnection)) { + // Launch pre-disconnect internal hook + hook_execute_internal("hook-pre-disconnect"); + // Announce it to everyone else + xmpp_setstatus(offline, NULL, "", FALSE); + } + if (lm_connection_is_open(lconnection)) + lm_connection_close(lconnection, NULL); + lm_connection_unref(lconnection); + lconnection = NULL; } void xmpp_setstatus(enum imstatus st, const char *recipient, const char *msg, @@ -1805,7 +1814,7 @@ // Only send the packet if we're online. // (But we want to update internal status even when disconnected, // in order to avoid some problems during network failures) - if (lm_connection_is_authenticated(lconnection)) { + if (lconnection && lm_connection_is_authenticated(lconnection)) { const char *s_msg = (st != invisible ? msg : NULL); m = lm_message_new_presence(st, recipient, s_msg); insert_entity_capabilities(m->node, st); // Entity Capabilities (XEP-0115) @@ -1828,7 +1837,7 @@ // If we didn't change our _global_ status, we are done if (recipient) return; - if (lm_connection_is_authenticated(lconnection)) { + if (lconnection && lm_connection_is_authenticated(lconnection)) { // Send presence to chatrooms if (st != invisible) { struct T_presence room_presence; @@ -2049,7 +2058,7 @@ if (!changed) return; - if (lm_connection_is_authenticated(lconnection)) + if (lconnection && lm_connection_is_authenticated(lconnection)) send_storage(bookmarks); else scr_LogPrint(LPRINT_LOGNORM, @@ -2190,7 +2199,7 @@ if (!changed) return; - if (lm_connection_is_authenticated(lconnection)) + if (lconnection && lm_connection_is_authenticated(lconnection)) send_storage(rosternotes); else scr_LogPrint(LPRINT_LOGNORM, diff -r 687f6b515d87 -r d1e8fb14ce2d mcabber/mcabber/xmpp_muc.c --- a/mcabber/mcabber/xmpp_muc.c Tue Jan 19 15:45:25 2010 +0200 +++ b/mcabber/mcabber/xmpp_muc.c Tue Jan 19 09:53:12 2010 +0200 @@ -113,7 +113,8 @@ gchar *roomid; GSList *room_elt; - if (!lm_connection_is_authenticated(lconnection) || !room) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection) || !room) + return; if (!nickname) return; roomid = g_strdup_printf("%s/%s", room, nickname); @@ -161,7 +162,8 @@ LmMessage *msg; LmMessageNode *x, *y; - if (!lm_connection_is_authenticated(lconnection) || !room || !fjid) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection) || !room || !fjid) + return; msg = lm_message_new(room, LM_MESSAGE_TYPE_MESSAGE); @@ -186,7 +188,8 @@ LmMessage *iq; LmMessageNode *query, *x; - if (!lm_connection_is_authenticated(lconnection) || !roomid) return 1; + if (!lconnection || !lm_connection_is_authenticated(lconnection) || !roomid) + return 1; if (!fjid && !nick) return 1; if (check_jid_syntax((char*)roomid)) { @@ -235,7 +238,8 @@ LmMessageNode *node; LmMessage *iq; - if (!lm_connection_is_authenticated(lconnection) || !room) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection) || !room) + return; iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET); @@ -258,7 +262,8 @@ LmMessage *iq; LmMessageNode *query, *x; - if (!lm_connection_is_authenticated(lconnection) || !room) return; + if (!lconnection || !lm_connection_is_authenticated(lconnection) || !room) + return; iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET);