comparison mcabber/mcabber/xmpp.c @ 1684:95df4ea512c8

Provide xmpp_is_online()
author Myhailo Danylenko <isbear@ukrpost.net>
date Tue, 19 Jan 2010 19:16:38 +0200
parents b09f82f61745
children 1342df44c814
comparison
equal deleted inserted replaced
1683:b09f82f61745 1684:95df4ea512c8
91 void update_last_use(void) 91 void update_last_use(void)
92 { 92 {
93 iqlast = time(NULL); 93 iqlast = time(NULL);
94 } 94 }
95 95
96 gboolean xmpp_is_online(void)
97 {
98 if (lconnection && lm_connection_is_authenticated(lconnection))
99 return TRUE;
100 else
101 return FALSE;
102 }
103
96 // Note: the caller should check the jid is correct 104 // Note: the caller should check the jid is correct
97 void xmpp_addbuddy(const char *bjid, const char *name, const char *group) 105 void xmpp_addbuddy(const char *bjid, const char *name, const char *group)
98 { 106 {
99 LmMessageNode *query, *y; 107 LmMessageNode *query, *y;
100 LmMessage *iq; 108 LmMessage *iq;
101 char *cleanjid; 109 char *cleanjid;
102 110
103 if (!lconnection || !lm_connection_is_authenticated(lconnection)) 111 if (!xmpp_is_online())
104 return; 112 return;
105 113
106 cleanjid = jidtodisp(bjid); // Stripping resource, just in case... 114 cleanjid = jidtodisp(bjid); // Stripping resource, just in case...
107 115
108 // We don't check if the jabber user already exists in the roster, 116 // We don't check if the jabber user already exists in the roster,
137 { 145 {
138 LmMessage *iq; 146 LmMessage *iq;
139 LmMessageNode *x; 147 LmMessageNode *x;
140 char *cleanjid; 148 char *cleanjid;
141 149
142 if (!lconnection || !lm_connection_is_authenticated(lconnection)) 150 if (!xmpp_is_online())
143 return; 151 return;
144 152
145 // XXX We should check name's and group's correctness 153 // XXX We should check name's and group's correctness
146 154
147 cleanjid = jidtodisp(bjid); // Stripping resource, just in case... 155 cleanjid = jidtodisp(bjid); // Stripping resource, just in case...
168 { 176 {
169 LmMessageNode *y, *z; 177 LmMessageNode *y, *z;
170 LmMessage *iq; 178 LmMessage *iq;
171 char *cleanjid; 179 char *cleanjid;
172 180
173 if (!lconnection || !lm_connection_is_authenticated(lconnection)) 181 if (!xmpp_is_online())
174 return; 182 return;
175 183
176 cleanjid = jidtodisp(bjid); // Stripping resource, just in case... 184 cleanjid = jidtodisp(bjid); // Stripping resource, just in case...
177 185
178 // If the current buddy is an agent, unsubscribe from it 186 // If the current buddy is an agent, unsubscribe from it
304 gchar *enc = NULL; 312 gchar *enc = NULL;
305 313
306 if (encrypted) 314 if (encrypted)
307 *encrypted = 0; 315 *encrypted = 0;
308 316
309 if (!lconnection || !lm_connection_is_authenticated(lconnection)) 317 if (!xmpp_is_online())
310 return; 318 return;
311 319
312 if (!text && type == ROSTER_TYPE_USER) 320 if (!text && type == ROSTER_TYPE_USER)
313 return; 321 return;
314 322
485 GSList *sl_buddy; 493 GSList *sl_buddy;
486 const char *chattag; 494 const char *chattag;
487 char *rjid, *fjid = NULL; 495 char *rjid, *fjid = NULL;
488 struct jep0085 *jep85 = NULL; 496 struct jep0085 *jep85 = NULL;
489 497
490 if (!lconnection || !lm_connection_is_authenticated(lconnection)) 498 if (!xmpp_is_online())
491 return; 499 return;
492 500
493 sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER); 501 sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER);
494 502
495 // If we have a resource name, we use it. Else we use NULL, 503 // If we have a resource name, we use it. Else we use NULL,
544 char *rname, *barejid; 552 char *rname, *barejid;
545 GSList *sl_buddy; 553 GSList *sl_buddy;
546 struct jep0022 *jep22 = NULL; 554 struct jep0022 *jep22 = NULL;
547 guint jep22_state; 555 guint jep22_state;
548 556
549 if (!lconnection || !lm_connection_is_authenticated(lconnection)) 557 if (!xmpp_is_online())
550 return; 558 return;
551 559
552 rname = strchr(fjid, JID_RESOURCE_SEPARATOR); 560 rname = strchr(fjid, JID_RESOURCE_SEPARATOR);
553 barejid = jidtodisp(fjid); 561 barejid = jidtodisp(fjid);
554 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); 562 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
1812 } 1820 }
1813 1821
1814 // Only send the packet if we're online. 1822 // Only send the packet if we're online.
1815 // (But we want to update internal status even when disconnected, 1823 // (But we want to update internal status even when disconnected,
1816 // in order to avoid some problems during network failures) 1824 // in order to avoid some problems during network failures)
1817 if (lconnection && lm_connection_is_authenticated(lconnection)) { 1825 if (xmpp_is_online()) {
1818 const char *s_msg = (st != invisible ? msg : NULL); 1826 const char *s_msg = (st != invisible ? msg : NULL);
1819 m = lm_message_new_presence(st, recipient, s_msg); 1827 m = lm_message_new_presence(st, recipient, s_msg);
1820 insert_entity_capabilities(m->node, st); // Entity Capabilities (XEP-0115) 1828 insert_entity_capabilities(m->node, st); // Entity Capabilities (XEP-0115)
1821 #ifdef HAVE_GPGME 1829 #ifdef HAVE_GPGME
1822 if (!do_not_sign && gpg_enabled()) { 1830 if (!do_not_sign && gpg_enabled()) {
1835 } 1843 }
1836 1844
1837 // If we didn't change our _global_ status, we are done 1845 // If we didn't change our _global_ status, we are done
1838 if (recipient) return; 1846 if (recipient) return;
1839 1847
1840 if (lconnection && lm_connection_is_authenticated(lconnection)) { 1848 if (xmpp_is_online()) {
1841 // Send presence to chatrooms 1849 // Send presence to chatrooms
1842 if (st != invisible) { 1850 if (st != invisible) {
1843 struct T_presence room_presence; 1851 struct T_presence room_presence;
1844 room_presence.st = st; 1852 room_presence.st = st;
1845 room_presence.msg = msg; 1853 room_presence.msg = msg;
2056 } 2064 }
2057 2065
2058 if (!changed) 2066 if (!changed)
2059 return; 2067 return;
2060 2068
2061 if (lconnection && lm_connection_is_authenticated(lconnection)) 2069 if (xmpp_is_online())
2062 send_storage(bookmarks); 2070 send_storage(bookmarks);
2063 else 2071 else
2064 scr_LogPrint(LPRINT_LOGNORM, 2072 scr_LogPrint(LPRINT_LOGNORM,
2065 "Warning: you're not connected to the server."); 2073 "Warning: you're not connected to the server.");
2066 } 2074 }
2197 } 2205 }
2198 2206
2199 if (!changed) 2207 if (!changed)
2200 return; 2208 return;
2201 2209
2202 if (lconnection && lm_connection_is_authenticated(lconnection)) 2210 if (xmpp_is_online())
2203 send_storage(rosternotes); 2211 send_storage(rosternotes);
2204 else 2212 else
2205 scr_LogPrint(LPRINT_LOGNORM, 2213 scr_LogPrint(LPRINT_LOGNORM,
2206 "Warning: you're not connected to the server."); 2214 "Warning: you're not connected to the server.");
2207 } 2215 }