1 /* |
|
2 * general-handlers.c |
|
3 * |
|
4 * Copyrigth (C) 2010 Nicolas Cornu <nicolas.cornu@ensi-bourges.fr> |
|
5 * |
|
6 * This program is free software; you can redistribute it and/or modify |
|
7 * it under the terms of the GNU General Public License as published by |
|
8 * the Free Software Foundation; either version 2 of the License, or (at |
|
9 * your option) any later version. |
|
10 * |
|
11 * This program is distributed in the hope that it will be useful, but |
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 * General Public License for more details. |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License |
|
17 * along with this program; if not, write to the Free Software |
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
19 * USA |
|
20 */ |
|
21 |
|
22 #include <glib.h> |
|
23 |
|
24 #include <mcabber/events.h> |
|
25 #include <mcabber/logprint.h> |
|
26 #include <mcabber/xmpp_helper.h> |
|
27 |
|
28 #include <jingle/jingle.h> |
|
29 #include <jingle/general-handlers.h> |
|
30 |
|
31 GSList *ack_wait = NULL; |
|
32 |
|
33 extern LmMessageHandler* jingle_ack_iq_handler; |
|
34 gboolean evscallback_jingle(guint evcontext, const gchar *arg, |
|
35 gpointer userdata) |
|
36 { |
|
37 JingleNode *jn = userdata; |
|
38 |
|
39 // Demande à mcKael l'utilité de ce truc |
|
40 /* |
|
41 if (G_UNLIKELY(!jn)) { |
|
42 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback."); |
|
43 return FALSE; |
|
44 } |
|
45 */ |
|
46 |
|
47 if (evcontext == EVS_CONTEXT_TIMEOUT) { |
|
48 scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s timed out, cancelled.", |
|
49 jn->initiator); |
|
50 jingle_free_jinglenode(jn); |
|
51 return FALSE; |
|
52 } |
|
53 if (evcontext = EVS_CONTEXT_CANCEL) { |
|
54 scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s cancelled.", |
|
55 jn->initiator); |
|
56 jingle_free_jinglenode(jn); |
|
57 return FALSE; |
|
58 } |
|
59 if (!(evcontext == EVS_CONTEXT_ACCEPT || evcontext == EVS_CONTEXT_REJECT)) { |
|
60 jingle_free_jinglenode(jn); |
|
61 return FALSE; |
|
62 } |
|
63 |
|
64 if (evcontext == EVS_CONTEXT_ACCEPT) { |
|
65 jingle_send_session_accept(jn); |
|
66 } else { |
|
67 jingle_send_session_terminate(jn, "decline"); |
|
68 jingle_free_jinglenode(jn); |
|
69 } |
|
70 |
|
71 return FALSE; |
|
72 } |
|
73 |
|
74 LmHandlerResult jingle_handle_ack_iq (LmMessageHandler *handler, |
|
75 LmConnection *connection, |
|
76 LmMessage *message, gpointer user_data) |
|
77 { |
|
78 GSList *child; |
|
79 const gchar *id = lm_message_get_id(message); |
|
80 ack_iq *ai; |
|
81 for (child = ack_wait; child; child = child->next) { |
|
82 ai = (ack_iq*)child->data; |
|
83 if(!g_strcmp0(ai->id, id)) { |
|
84 g_free(ai->id); |
|
85 if(ai->callback != NULL) |
|
86 ai->callback(message, ai->udata); |
|
87 ack_wait = g_slist_remove(ack_wait, child); |
|
88 return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
|
89 } |
|
90 } |
|
91 return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS; |
|
92 } |
|
93 |
|
94 void add_ack_wait(ack_iq *elem) |
|
95 { |
|
96 ack_wait = g_slist_append(ack_wait, elem); |
|
97 } |
|