Split handle_session_initiate into two functions
authorNicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Sat, 10 Jul 2010 00:09:56 +0200
changeset 43 357e69106171
parent 42 526d61c145a7
child 44 4738d78edc05
Split handle_session_initiate into two functions
jingle/action-handlers.c
jingle/send.c
--- a/jingle/action-handlers.c	Fri Jul 09 16:22:11 2010 +0200
+++ b/jingle/action-handlers.c	Sat Jul 10 00:09:56 2010 +0200
@@ -238,25 +238,12 @@
   }
 }
 
-/* The session-initiate action is used to request negotiation of a new Jingle
- * session. When sending a session-initiate with one <content/> element, the
- * value of the <content/> element's 'disposition' attribute MUST be "session"
- * (if there are multiple <content/> elements then at least one MUST have a
- * disposition of "session"); if this rule is violated, the responder MUST
- * return a <bad-request/> error to the initiator.
- */
 void handle_session_initiate(LmMessage *m, JingleNode *jn)
 {
   GError *err = NULL;
   GSList *child = NULL;
   gboolean valid_disposition = FALSE;
   JingleContent *cn;
-  JingleAppFuncs *appfuncs; 
-  JingleTransportFuncs *transfuncs;
-  gconstpointer description, transport;
-  const gchar *xmlns;
-  JingleSession* sess;
-  JingleNode accept;
   LmMessage *r;
   
   if (!check_contents(jn, &err)) {
@@ -294,51 +281,7 @@
 
   jingle_ack_iq(m);
 
-  accept.action = JINGLE_SESSION_ACCEPT;
-  accept.responder = g_strdup_printf("%s/%s",
-                                     lm_connection_get_jid(lconnection),
-                                     settings_opt_get("resource"));
-  accept.sid = jn->sid;
-  accept.content = NULL;
-  
-  sess = session_new(jn);
-  
-  for (child = jn->content; child; child = child->next) {
-    cn = (JingleContent *)(child->data);
-    
-    xmlns = lm_message_node_get_attribute(cn->description, "xmlns");
-    appfuncs = jingle_get_appfuncs(xmlns);
-    if (appfuncs == NULL) continue;
-    
-    xmlns = lm_message_node_get_attribute(cn->transport, "xmlns");
-    transfuncs = jingle_get_transportfuncs(xmlns);
-    if (appfuncs == NULL) continue; // negociate another transport ?
-    
-    description = appfuncs->check(cn, &err);
-    if (description == NULL || err != NULL) continue;
-    transport = transfuncs->check(cn, &err);
-    if (transport == NULL || err != NULL) continue;
-    
-    session_add_content(sess, cn, ACTIVE);
-    accept.content = g_slist_append(accept.content, cn);
-  }
-  
-  if(g_slist_length(sess->content) == 0) {
-    jingle_send_session_terminate(jn, "unsupported-applications");
-    session_delete(sess);
-    return;
-  }
-  
-  // Send a session-accept
-  if (g_slist_length(accept.content) != 0) {
-    r = lm_message_from_jinglenode(&accept, lm_message_get_from(m));
-    if (r) {
-      lm_connection_send(lconnection, r, NULL);
-      lm_message_unref(r);
-    }
-  }
-  
-  // TODO: try transport
+  // TODO: generate an event and wait for the user's choice
 }
 
 void handle_session_terminate(LmMessage *m, JingleNode *jn)
--- a/jingle/send.c	Fri Jul 09 16:22:11 2010 +0200
+++ b/jingle/send.c	Sat Jul 10 00:09:56 2010 +0200
@@ -26,6 +26,7 @@
 #include <mcabber/xmpp_defines.h>
 
 #include <jingle/jingle.h>
+#include <jingle/sessions.h>
 #include <jingle/send.h>
 
 
@@ -52,3 +53,59 @@
   }
 }
 
+void jingle_send_session_accept(JingleNode *jn)
+{
+  JingleNode accept = {0};
+  JingleSession* sess;
+  JingleContent *cn;
+  GSList *child = NULL;
+  JingleAppFuncs *appfuncs;
+  JingleTransportFuncs *transfuncs;
+  gconstpointer description, transport;
+  const gchar *xmlns;
+  GError *err = NULL;
+
+  accept.action = JINGLE_SESSION_ACCEPT;
+  accept.responder = g_strdup_printf("%s/%s",
+                                     lm_connection_get_jid(lconnection),
+                                     settings_opt_get("resource"));
+  accept.sid = jn->sid;
+  accept.content = NULL;
+
+  sess = session_new(jn);
+
+  for (child = jn->content; child; child = child->next) {
+    cn = (JingleContent *)(child->data);
+
+    xmlns = lm_message_node_get_attribute(cn->description, "xmlns");
+    appfuncs = jingle_get_appfuncs(xmlns);
+    if (appfuncs == NULL) continue;
+
+    xmlns = lm_message_node_get_attribute(cn->transport, "xmlns");
+    transfuncs = jingle_get_transportfuncs(xmlns);
+    if (appfuncs == NULL) continue; // negociate another transport ?
+
+    description = appfuncs->check(cn, &err);
+    if (description == NULL || err != NULL) continue;
+    transport = transfuncs->check(cn, &err);
+    if (transport == NULL || err != NULL) continue;
+
+    session_add_content(sess, cn, ACTIVE);
+    accept.content = g_slist_append(accept.content, cn);
+  }
+
+  if(g_slist_length(sess->content) == 0) {
+    jingle_send_session_terminate(jn, "unsupported-applications");
+    session_delete(sess);
+    return;
+  }
+
+  if (g_slist_length(accept.content) <= 0) return;
+
+  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);
+    lm_message_unref(accept.message);
+  }
+}