Handle ack iq
authorNicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Sun, 11 Jul 2010 18:23:28 +0200
changeset 47 964b3ebeba8d
parent 46 f33c814d5b3a
child 48 3c08b78be871
Handle ack iq
jingle/CMakeLists.txt
jingle/action-handlers.c
jingle/general-handlers.c
jingle/general-handlers.h
jingle/jingle.c
jingle/jingle.h
jingle/send.c
jingle/sessions.c
jingle/sessions.h
--- a/jingle/CMakeLists.txt	Sat Jul 10 00:51:45 2010 +0200
+++ b/jingle/CMakeLists.txt	Sun Jul 11 18:23:28 2010 +0200
@@ -1,4 +1,4 @@
-add_library(jingle MODULE jingle.c jingle.h check.c check.h action-handlers.c action-handlers.c register.c register.h sessions.c sessions.h send.c send.h)
+add_library(jingle MODULE jingle.c jingle.h check.c check.h action-handlers.c action-handlers.c register.c register.h sessions.c sessions.h send.c send.h general-handlers.c general-handlers.h)
 set_target_properties(jingle PROPERTIES COMPILE_FLAGS "")
 include_directories(${LM_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})
 target_link_libraries(jingle ${LM_LIBRARIES})
--- a/jingle/action-handlers.c	Sat Jul 10 00:51:45 2010 +0200
+++ b/jingle/action-handlers.c	Sun Jul 11 18:23:28 2010 +0200
@@ -33,6 +33,7 @@
 #include <jingle/register.h>
 #include <jingle/send.h>
 #include <jingle/action-handlers.h>
+#include <jingle/general-handlers.h>
 
 void handle_content_accept(JingleNode *jn)
 {
@@ -68,7 +69,7 @@
 
   for (child = jn->content; child; child = child->next) {
     cn = (JingleContent *)(child->data);
-    session_changestate_sessioncontent(sess, cn->name, ACTIVE);
+    session_changestate_sessioncontent(sess, cn->name, JINGLE_SESSION_STATE_ACTIVE);
   }
 }
 
@@ -137,14 +138,14 @@
       reject.content = g_slist_append(reject.content, cn);
       continue;
     }
-    session_add_content(sess, cn, ACTIVE);
+    session_add_content(sess, cn, JINGLE_SESSION_STATE_ACTIVE);
     accept.content = g_slist_append(accept.content, cn);
   }
   
   if (g_slist_length(accept.content) != 0) {
     r = lm_message_from_jinglenode(&accept, lm_message_get_from(jn->message));
     if (r) {
-      lm_connection_send(lconnection, r, NULL);
+      lm_connection_send_with_reply(lconnection, r,NULL, NULL);
       lm_message_unref(r);
     }
   }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jingle/general-handlers.c	Sun Jul 11 18:23:28 2010 +0200
@@ -0,0 +1,89 @@
+/*
+ * general-handlers.c
+ *
+ * Copyrigth (C) 2010 Nicolas Cornu <nicolas.cornu@ensi-bourges.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#include <glib.h>
+
+#include <mcabber/events.h>
+#include <mcabber/logprint.h>
+
+#include <jingle/jingle.h>
+#include <jingle/general-handlers.h>
+
+extern LmMessageHandler* jingle_ack_iq_handler;
+gboolean evscallback_jingle(guint evcontext, const gchar *arg,
+                            gpointer userdata)
+{
+  JingleNode *jn = userdata;
+
+  // Demande à mcKael l'utilité de ce truc
+  /*
+  if (G_UNLIKELY(!jn)) {
+    scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
+    return FALSE;
+  }
+  */
+
+  if (evcontext == EVS_CONTEXT_TIMEOUT) {
+    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s timed out, cancelled.",
+                 jn->initiator);
+    jingle_free_jinglenode(jn);
+    return FALSE;
+  }
+  if (evcontext = EVS_CONTEXT_CANCEL) {
+    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s cancelled.",
+                 jn->initiator);
+    jingle_free_jinglenode(jn);
+    return FALSE;
+  }
+  if (!(evcontext == EVS_CONTEXT_ACCEPT || evcontext == EVS_CONTEXT_REJECT)) {
+    jingle_free_jinglenode(jn);
+    return FALSE;
+  }
+  
+  if (evcontext == EVS_CONTEXT_ACCEPT) {
+    jingle_send_session_accept(jn);
+  } else {
+    jingle_send_session_terminate(jn, "decline");
+    jingle_free_jinglenode(jn);
+  }
+
+  return FALSE;
+}
+
+LmHandlerResult jingle_handle_ack_iq (LmMessageHandler *handler,
+                                      LmConnection *connection, 
+                                      LmMessage *message, gpointer user_data)
+{
+  static GSList *ack_wait;
+  GSList *child;
+  LmMessageNode *node = lm_message_get_node(message);
+  const gchar *id = lm_message_node_get_attribute(node, "id");
+  ack_iq *ai;
+  for (child = ack_wait; child; child = child->next) {
+    ai = (ack_iq*)child->data;
+    if(!g_strcmp0(ai->id, id)) {
+      ai->callback(ai->udata);
+      ack_wait = g_slist_remove(ack_wait, child);
+      return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+    }
+  }
+  return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jingle/general-handlers.h	Sun Jul 11 18:23:28 2010 +0200
@@ -0,0 +1,16 @@
+#ifndef __JINGLE_GENERAL_HANDLERS_H__
+#define __JINGLE_GENERAL_HANDLERS_H__ 1
+
+typedef void (*jingle_func_ack_iq) (void*);
+typedef struct {
+  const gchar *id;
+  jingle_func_ack_iq callback;
+  void *udata;
+} ack_iq;
+
+gboolean evscallback_jingle(guint evcontext, const gchar *arg, gpointer userdata);
+LmHandlerResult jingle_handle_ack_iq (LmMessageHandler *handler,
+                                      LmConnection *connection, 
+                                      LmMessage *message, gpointer user_data);
+
+#endif
--- a/jingle/jingle.c	Sat Jul 10 00:51:45 2010 +0200
+++ b/jingle/jingle.c	Sun Jul 11 18:23:28 2010 +0200
@@ -29,14 +29,13 @@
 #include <mcabber/modules.h>
 #include <mcabber/logprint.h>
 #include <mcabber/xmpp_helper.h>
-#include <mcabber/xmpp_defines.h> 
-#include <mcabber/events.h>
 
 #include <jingle/jingle.h>
 #include <jingle/check.h>
 #include <jingle/action-handlers.h>
 #include <jingle/register.h>
 #include <jingle/send.h>
+#include <jingle/general-handlers.h>
 
 static void  jingle_register_lm_handlers(void);
 static void  jingle_unregister_lm_handlers(void);
@@ -50,6 +49,7 @@
 
 
 static LmMessageHandler* jingle_iq_handler = NULL;
+LmMessageHandler* jingle_ack_iq_handler = NULL;
 static guint connect_hid = 0;
 static guint disconn_hid = 0;
 
@@ -246,6 +246,8 @@
 static void jingle_init(void)
 {
   jingle_iq_handler = lm_message_handler_new(jingle_handle_iq, NULL, NULL);
+  jingle_ack_iq_handler = lm_message_handler_new(jingle_handle_ack_iq, NULL,
+                                                 NULL);
   xmpp_add_feature(NS_JINGLE);
 
   connect_hid = hk_add_handler(jingle_connect_hh, HOOK_POST_CONNECT,
@@ -265,6 +267,8 @@
 
   lm_message_handler_invalidate(jingle_iq_handler);
   lm_message_handler_unref(jingle_iq_handler);
+  lm_message_handler_invalidate(jingle_ack_iq_handler);
+  lm_message_handler_unref(jingle_ack_iq_handler);
 }
 
 LmMessage *lm_message_from_jinglenode(const JingleNode *jn, const gchar *to)
@@ -323,42 +327,3 @@
     lm_message_node_set_attribute(node, "senders", "responder");
 }
 
-gboolean evscallback_jingle(guint evcontext, const gchar *arg,
-                            gpointer userdata)
-{
-  JingleNode *jn = userdata;
-
-  // Demande à mcKael l'utilité de ce truc
-  /*
-  if (G_UNLIKELY(!jn)) {
-    scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
-    return FALSE;
-  }
-  */
-
-  if (evcontext == EVS_CONTEXT_TIMEOUT) {
-    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s timed out, cancelled.",
-                 jn->initiator);
-    jingle_free_jinglenode(jn);
-    return FALSE;
-  }
-  if (evcontext = EVS_CONTEXT_CANCEL) {
-    scr_LogPrint(LPRINT_LOGNORM, "Jingle event from %s cancelled.",
-                 jn->initiator);
-    jingle_free_jinglenode(jn);
-    return FALSE;
-  }
-  if (!(evcontext == EVS_CONTEXT_ACCEPT || evcontext == EVS_CONTEXT_REJECT)) {
-    jingle_free_jinglenode(jn);
-    return FALSE;
-  }
-  
-  if (evcontext == EVS_CONTEXT_ACCEPT) {
-    jingle_send_session_accept(jn);
-  } else {
-    jingle_send_session_terminate(jn, "decline");
-    jingle_free_jinglenode(jn);
-  }
-
-  return FALSE;
-}
--- a/jingle/jingle.h	Sat Jul 10 00:51:45 2010 +0200
+++ b/jingle/jingle.h	Sun Jul 11 18:23:28 2010 +0200
@@ -115,5 +115,4 @@
 void jingle_ack_iq(LmMessage *m);
 JingleAction jingle_action_from_str(const gchar* string);
 LmMessage *lm_message_from_jinglenode(const JingleNode *jn, const gchar *to);
-gboolean evscallback_jingle(guint evcontext, const gchar *arg, gpointer userdata);
 #endif
--- a/jingle/send.c	Sat Jul 10 00:51:45 2010 +0200
+++ b/jingle/send.c	Sun Jul 11 18:23:28 2010 +0200
@@ -29,6 +29,7 @@
 #include <jingle/sessions.h>
 #include <jingle/send.h>
 
+extern LmMessageHandler* jingle_ack_iq_handler;
 
 void jingle_send_session_terminate(JingleNode *jn, const gchar *reason)
 {
@@ -90,7 +91,7 @@
     transport = transfuncs->check(cn, &err);
     if (transport == NULL || err != NULL) continue;
 
-    session_add_content(sess, cn, ACTIVE);
+    session_add_content(sess, cn, JINGLE_SESSION_STATE_ACTIVE);
     accept.content = g_slist_append(accept.content, cn);
   }
 
@@ -105,7 +106,7 @@
   accept.message = lm_message_from_jinglenode(&accept, lm_message_get_from(jn->message));
   if (accept.message) {
     lm_connection_send_with_reply(lconnection, accept.message,
-                                  NULL, &err);
+                                  jingle_ack_iq_handler, &err);
     lm_message_unref(accept.message);
   }
 }
--- a/jingle/sessions.c	Sat Jul 10 00:51:45 2010 +0200
+++ b/jingle/sessions.c	Sun Jul 11 18:23:28 2010 +0200
@@ -109,7 +109,7 @@
   sc = session_find_sessioncontent(sess, name);
   if(sc == NULL) return;
 
-  if (sc->state == ACTIVE); // We should stop the transfert
+  if (sc->state == JINGLE_SESSION_STATE_ACTIVE); // We should stop the transfert
 
   sess->content = g_slist_remove(sess->content, sc);
 }
--- a/jingle/sessions.h	Sat Jul 10 00:51:45 2010 +0200
+++ b/jingle/sessions.h	Sun Jul 11 18:23:28 2010 +0200
@@ -11,9 +11,9 @@
 } JingleStatus;
 
 typedef enum {
-  ACTIVE,
-  PENDING,
-  ENDED,
+  JINGLE_SESSION_STATE_ACTIVE,
+  JINGLE_SESSION_STATE_PENDING,
+  JINGLE_SESSION_STATE_ENDED,
 } SessionState;
 
 typedef struct {