47 static void jingle_init(void); |
47 static void jingle_init(void); |
48 static void jingle_uninit(void); |
48 static void jingle_uninit(void); |
49 |
49 |
50 static LmMessageHandler* jingle_iq_handler = NULL; |
50 static LmMessageHandler* jingle_iq_handler = NULL; |
51 static GSList *ack_handlers = NULL; |
51 static GSList *ack_handlers = NULL; |
|
52 static guint ack_timeout_checker = 0; |
52 static guint connect_hid = 0; |
53 static guint connect_hid = 0; |
53 static guint disconn_hid = 0; |
54 static guint disconn_hid = 0; |
54 |
55 |
55 |
56 |
56 /** |
57 /** |
142 */ |
143 */ |
143 LmHandlerResult jingle_handle_ack_iq(LmMessageHandler *handler, |
144 LmHandlerResult jingle_handle_ack_iq(LmMessageHandler *handler, |
144 LmConnection *connection, |
145 LmConnection *connection, |
145 LmMessage *message, gpointer user_data) |
146 LmMessage *message, gpointer user_data) |
146 { |
147 { |
147 ack_handlers = g_slist_remove(ack_handlers, handler); |
|
148 lm_message_handler_unref(handler); |
|
149 |
|
150 // TODO: check subtype |
148 // TODO: check subtype |
151 if (user_data != NULL) { |
149 if (user_data != NULL) { |
152 JingleAckHandle *ah = user_data; |
150 JingleAckHandle *ah = user_data; |
153 if(ah->callback != NULL) |
151 if(ah->callback != NULL) |
154 ah->callback(message, ah->user_data); |
152 ah->callback(JINGLE_ACK_RESPONSE, message, ah->user_data); |
155 |
153 |
156 g_free(ah); |
154 jingle_ack_handler_free(ah); |
157 } |
155 } |
158 |
156 |
159 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
157 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
160 } |
158 } |
161 |
159 |
|
160 gboolean jingle_ack_timeout_checker(gpointer user_data) |
|
161 { |
|
162 GSList *el; |
|
163 time_t now = time(NULL); |
|
164 JingleAckHandle *ah; |
|
165 |
|
166 for (el = ack_handlers; el; el = g_slist_next(el)) { |
|
167 JingleAckHandle *ah = el->data; |
|
168 |
|
169 if (ah->timeout == 0 || ah->_inserted + ah->timeout > now) |
|
170 continue; |
|
171 |
|
172 if(ah->callback != NULL) |
|
173 ah->callback(JINGLE_ACK_TIMEOUT, NULL, ah->user_data); |
|
174 |
|
175 lm_message_handler_unref(ah->_handler); |
|
176 jingle_ack_handler_free(ah); |
|
177 } |
|
178 return TRUE; |
|
179 } |
|
180 |
162 LmMessageHandler *jingle_new_ack_handler(JingleAckHandle *ah) |
181 LmMessageHandler *jingle_new_ack_handler(JingleAckHandle *ah) |
163 { |
182 { |
164 LmMessageHandler *h = lm_message_handler_new(jingle_handle_ack_iq, |
183 if(ack_timeout_checker == 0) |
165 (gpointer) ah, NULL); |
184 ack_timeout_checker = g_timeout_add_seconds(3, jingle_ack_timeout_checker, NULL); |
166 ack_handlers = g_slist_append(ack_handlers, h); |
185 |
167 return h; |
186 ah->_inserted = time(NULL); |
|
187 ah->_handler = lm_message_handler_new(jingle_handle_ack_iq, |
|
188 (gpointer) ah, NULL); |
|
189 ack_handlers = g_slist_append(ack_handlers, ah); |
|
190 return ah->_handler; |
|
191 } |
|
192 |
|
193 void jingle_ack_handler_free(JingleAckHandle *ah) |
|
194 { |
|
195 lm_message_handler_unref(ah->_handler); |
|
196 ack_handlers = g_slist_remove(ack_handlers, ah); |
|
197 g_free(ah); |
168 } |
198 } |
169 |
199 |
170 /** |
200 /** |
171 * mcabber /event callback. |
201 * mcabber /event callback. |
172 */ |
202 */ |
380 hk_del_handler(HOOK_PRE_DISCONNECT, disconn_hid); |
410 hk_del_handler(HOOK_PRE_DISCONNECT, disconn_hid); |
381 jingle_unregister_lm_handlers(); |
411 jingle_unregister_lm_handlers(); |
382 |
412 |
383 lm_message_handler_invalidate(jingle_iq_handler); |
413 lm_message_handler_invalidate(jingle_iq_handler); |
384 lm_message_handler_unref(jingle_iq_handler); |
414 lm_message_handler_unref(jingle_iq_handler); |
|
415 |
|
416 if (ack_timeout_checker != 0) { |
|
417 GSource *s = g_main_context_find_source_by_id(NULL, ack_timeout_checker); |
|
418 g_source_destroy(s); |
|
419 } |
385 } |
420 } |
386 |
421 |
387 void handle_trans_data(const gchar *xmlns, gconstpointer data, const gchar *data2, guint len) |
422 void handle_trans_data(const gchar *xmlns, gconstpointer data, const gchar *data2, guint len) |
388 { |
423 { |
389 SessionContent *sc = session_find_transport(xmlns, data); |
424 SessionContent *sc = session_find_transport(xmlns, data); |