Modify the session-initiate handler among other things.
authorNicolas Cornu <nicolas.cornu@ensi-bourges.fr>
Tue, 06 Jul 2010 02:21:33 +0200
changeset 32 72bbe33f151a
parent 31 02f5698ffa49
child 33 92e92ce901e7
Modify the session-initiate handler among other things.
jingle-filetransfer/filetransfer.c
jingle/action-handlers.c
jingle/check.c
jingle/jingle.c
jingle/jingle.h
jingle/register.c
jingle/register.h
jingle/sessions.c
jingle/sessions.h
--- a/jingle-filetransfer/filetransfer.c	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle-filetransfer/filetransfer.c	Tue Jul 06 02:21:33 2010 +0200
@@ -34,7 +34,7 @@
 #include "filetransfer.h"
 
 
-gconstpointer jingle_ft_check(JingleContent *cn, GError **err, gpointer *data);
+gconstpointer jingle_ft_check(JingleContent *cn, GError **err);
 static void jingle_ft_init(void);
 static void jingle_ft_uninit(void);
 
@@ -55,26 +55,20 @@
 };
 
 
-gconstpointer jingle_ft_check(JingleContent *cn, GError **err, gpointer *data)
+gconstpointer jingle_ft_check(JingleContent *cn, GError **err)
 {
   JingleFT *ft = NULL;
-  LmMessageNode *node, *description;
+  LmMessageNode *node;
   const gchar *datestr, *sizestr;
 
-  description = lm_message_node_get_child(cn->node, "description");
-  if (!description) {
-    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING, "Huh ?");
-    return NULL;
-  }
-
-  node = lm_message_node_get_child(description, "offer");
+  node = lm_message_node_get_child(cn->description, "offer");
   if (!node) {
     g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
                 "the offer element is missing");
     return NULL;
   }
 
-  node = lm_message_node_get_child(description, "file");
+  node = lm_message_node_get_child(cn->description, "file");
   if (!node) {
     g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
                 "the file element is missing");
@@ -116,7 +110,7 @@
 
 static void jingle_ft_init(void)
 {
-  jingle_register_app(NS_JINGLE_APP_FT, &funcs, NULL);
+  jingle_register_app(NS_JINGLE_APP_FT, &funcs);
   xmpp_add_feature(NS_JINGLE_APP_FT);
 }
 
--- a/jingle/action-handlers.c	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle/action-handlers.c	Tue Jul 06 02:21:33 2010 +0200
@@ -41,11 +41,13 @@
 void handle_session_initiate(LmMessage *m, JingleNode *jn)
 {
   GError *err = NULL;
-  gboolean is_session = FALSE, support_both = FALSE;
   GSList *child = NULL;
+  gboolean valid_disposition = FALSE;
   JingleContent *cn;
-  JingleAppFuncs *af;
-  JingleTransportFuncs *tf;
+  JingleAppFuncs *appfuncs; 
+  JingleTransportFuncs *transfuncs;
+  gconstpointer description, transport;
+  const gchar *xmlns;
 
   if (!check_contents(jn, &err)) {
     scr_log_print(LPRINT_DEBUG, "jingle: One of the content element was invalid (%s)",
@@ -60,13 +62,16 @@
     return;
   }
   
-  // one of the content element must be a "session"
-  for (child = jn->content; child && !is_session; child = child->next) {
-    if (g_strcmp0(((JingleContent*)(child->data))->disposition, "session") ||
-       ((JingleContent*)(child->data))->disposition == NULL) // default: session
-      is_session = TRUE;
+  /* When sending a session-initiate at least one <content/> element MUST have
+   * a disposition of "session"); if this rule is violated, the responder MUST
+   * return a <bad-request/> error to the initiator.
+   */
+  for (child = jn->content; child && !valid_disposition; child = child->next) {
+    cn = (JingleContent*)(child->data);
+    if (g_strcmp0(cn->disposition, "session") == 0 || cn->disposition == NULL)
+      valid_disposition = TRUE;
   }
-  if (!is_session) {
+  if (!valid_disposition) {
     jingle_send_iq_error(m, "cancel", "bad-request", NULL);
     return;  
   }
@@ -80,14 +85,20 @@
   jingle_ack_iq(m);
 
   for (child = jn->content; child; child = child->next) {
-    cn = (JingleContent*)(child->data);
+    cn = (JingleContent *)(child->data);
+    
+    xmlns = lm_message_node_get_attribute(cn->description, "xmlns");
+    appfuncs = jingle_get_appfuncs(xmlns);
+    if (appfuncs == NULL) continue;
     
-    af = jingle_get_appfuncs(cn->xmlns_desc);
-    tf = jingle_get_transportfuncs(cn->xmlns_trans);
-    if (af == NULL && tf == NULL) continue;
+    xmlns = lm_message_node_get_attribute(cn->transport, "xmlns");
+    transfuncs = jingle_get_transportfuncs(xmlns);
+    if (appfuncs == NULL) continue; // negociate another transport ?
     
-    cn->description = af->check(cn, NULL, NULL);
-    cn->transport = tf->check(cn, NULL, NULL);
+    description = appfuncs->check(cn, &err);
+    if (description == NULL || err != NULL) continue;
+    transport = transfuncs->check(cn, &err);
+    if (transport == NULL || err != NULL) continue;
   }
 }
 
@@ -101,13 +112,3 @@
   session_delete(sess);
   jingle_ack_iq(m);
 }
-
-const gchar* get_xmlnstrans(const GSList* list)
-{
-  return ((JingleContent*)(list->data))->xmlns_trans;
-}
-
-const gchar* get_xmlnsdesc(const GSList* list)
-{
-  return ((JingleContent*)(list->data))->xmlns_desc;
-}
--- a/jingle/check.c	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle/check.c	Tue Jul 06 02:21:33 2010 +0200
@@ -105,7 +105,7 @@
   const gchar *creatorstr, *sendersstr;
   gint tmp, tmp2;
   LmMessageNode *tmpnode = NULL;
-  
+
   creatorstr      = lm_message_node_get_attribute(node, "creator");
   cn->disposition = lm_message_node_get_attribute(node, "disposition");
   cn->name        = lm_message_node_get_attribute(node, "name");
@@ -117,7 +117,7 @@
     g_free(cn);
     return NULL;
   }
-  
+
   tmp = index_in_array(creatorstr, jingle_content_creator);
   tmp2 = index_in_array(sendersstr, jingle_content_senders);
   if (tmp < 0 || tmp2 < 0) {
@@ -128,27 +128,16 @@
   }
   cn->creator = (JingleCreator)tmp;
   cn->senders = (JingleSenders)tmp2;
-  
-  tmpnode = lm_message_node_get_child(node, "description");
-  if(tmpnode == NULL) {
-    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
-                "a child element of content is missing");
-    g_free(cn);
-    return NULL;
-  }
-  
-  cn->xmlns_desc = lm_message_node_get_attribute(tmpnode, "xmlns");
-  
-  tmpnode = lm_message_node_get_child(node, "transport");
-  if (tmpnode == NULL) {
-    g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
-                "a child element of content is missing");
-    g_free(cn);
-    return NULL;
-  }
 
-  cn->xmlns_trans = lm_message_node_get_attribute(tmpnode, "xmlns");
-  
+  cn->description = lm_message_node_get_child(node, "description");
+  cn->transport   = lm_message_node_get_child(node, "transport");
+  if (cn->description == NULL || cn->transport == NULL) {
+     g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING,
+                 "a child element of content is missing");
+     g_free(cn);
+     return NULL;
+   }
+
   return cn;
 }
 
--- a/jingle/jingle.c	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle/jingle.c	Tue Jul 06 02:21:33 2010 +0200
@@ -299,8 +299,4 @@
     lm_message_node_set_attribute(node, "senders", "initiator");
   else if (content->senders == JINGLE_SENDERS_RESPONDER)
     lm_message_node_set_attribute(node, "senders", "responder");
-
-  // Care of desc & trans
-  node->children = jingle_get_appfuncs(content->xmlns_desc)->desc(content->description);
-  node->children->next = jingle_get_transportfuncs(content->xmlns_trans)->trans(content->transport);
 }
--- a/jingle/jingle.h	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle/jingle.h	Tue Jul 06 02:21:33 2010 +0200
@@ -94,15 +94,12 @@
   /* each content element (must) contain one description
    * child element that specifies a desired application.
    * the content of this node is app specific. */
-  gconstpointer description;
+  LmMessageNode *description;
 
   /* each content element (must) contain one transport
    * child element that specifies a potential transport
    * method */
-  gconstpointer transport;
-  
-  const gchar *xmlns_desc;
-  const gchar *xmlns_trans;
+  LmMessageNode *transport;
 
 } JingleContent;
 
--- a/jingle/register.c	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle/register.c	Tue Jul 06 02:21:33 2010 +0200
@@ -30,13 +30,11 @@
 typedef struct {
   gchar *xmlns;
   JingleAppFuncs *funcs;
-  gpointer data;
 } AppHandlerEntry;
 
 typedef struct {
   gchar *xmlns;
   JingleTransportFuncs *funcs;
-  gpointer data;
 } TransportHandlerEntry;
 
 
@@ -48,8 +46,7 @@
 GSList *jingle_transport_handlers = NULL;
 
 
-void jingle_register_app(const gchar *xmlns, JingleAppFuncs *funcs,
-                         gpointer data)
+void jingle_register_app(const gchar *xmlns, JingleAppFuncs *funcs)
 {
   if (!g_str_has_prefix(xmlns, NS_JINGLE_APP_PREFIX)) return;
 
@@ -57,13 +54,11 @@
 
   h->xmlns  = g_strdup(xmlns);
   h->funcs  = funcs;
-  h->data   = data;
 
   jingle_app_handlers = g_slist_append(jingle_app_handlers, h);
 }
 
-void jingle_register_transport(const gchar *xmlns, JingleTransportFuncs *funcs,
-                                   gpointer data)
+void jingle_register_transport(const gchar *xmlns, JingleTransportFuncs *funcs)
 {
   if (!g_str_has_prefix(xmlns, NS_JINGLE_TRANSPORT_PREFIX)) return;
 
@@ -71,7 +66,6 @@
 
   h->xmlns  = g_strdup(xmlns);
   h->funcs  = funcs;
-  h->data   = data;
 
   jingle_transport_handlers = g_slist_append(jingle_transport_handlers, h);
 }
--- a/jingle/register.h	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle/register.h	Tue Jul 06 02:21:33 2010 +0200
@@ -8,12 +8,12 @@
 #define NS_JINGLE_TRANSPORT_PREFIX "urn:xmpp:jingle:transport:"
 
 
-typedef gconstpointer (*JingleAppCheck) (JingleContent *cn, GError **err, gpointer *data);
-typedef void (*JingleAppHandle) (JingleNode *jn, JingleContent *cn, gpointer *data);
+typedef gconstpointer (*JingleAppCheck) (JingleContent *cn, GError **err);
+typedef void (*JingleAppHandle) (JingleNode *jn, JingleContent *cn);
 typedef LmMessageNode* (*JingleAppGetLM) (gconstpointer data);
 
-typedef gconstpointer (*JingleTransportCheck) (JingleContent *cn, GError **err, gpointer *data);
-typedef void (*JingleTransportHandle) (JingleNode *jn, JingleContent *cn, gpointer *data);
+typedef gconstpointer (*JingleTransportCheck) (JingleContent *cn, GError **err);
+typedef void (*JingleTransportHandle) (JingleNode *jn, JingleContent *cn);
 typedef LmMessageNode* (*JingleTransportGetLM) (gconstpointer data);
 
 typedef struct {
@@ -40,10 +40,8 @@
 } JingleTransportFuncs;
 
 
-void jingle_register_app(const gchar *xmlns, JingleAppFuncs *funcs,
-                         gpointer data);
-void jingle_register_transport(const gchar *xmlns, JingleTransportFuncs *funcs,
-                               gpointer data);
+void jingle_register_app(const gchar *xmlns, JingleAppFuncs *funcs);
+void jingle_register_transport(const gchar *xmlns, JingleTransportFuncs *funcs);
 JingleAppFuncs *jingle_get_appfuncs(const gchar *xmlns);
 JingleTransportFuncs *jingle_get_transportfuncs(const gchar *xmlns);
 void jingle_unregister_app(const gchar *xmlns);
--- a/jingle/sessions.c	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle/sessions.c	Tue Jul 06 02:21:33 2010 +0200
@@ -32,8 +32,7 @@
 /**
  * Create a new session and insert it in the linked list.
  */
-JingleSession *session_new(JingleNode *jn, LmMessageNode* app,
-                           LmMessageNode* trans)
+JingleSession *session_new(JingleNode *jn)
 {
   JingleSession *js = g_new0(JingleSession, 1);
   const gchar *from;
@@ -45,9 +44,9 @@
     return NULL;
   }
   js->from = g_strdup(from);
-  
 
   sessions = g_slist_append(sessions, js);
+  return js;
 }
 
 JingleSession *session_find_by_sid(const gchar *sid, const gchar *from)
--- a/jingle/sessions.h	Mon Jul 05 00:52:27 2010 +0200
+++ b/jingle/sessions.h	Tue Jul 06 02:21:33 2010 +0200
@@ -16,6 +16,13 @@
   GSList *content;
 } JingleSession;
 
+typedef struct {
+  gconstpointer *description;
+  JingleAppFuncs *appfuncs;
+  gconstpointer *transport;
+  JingleTransportFuncs *transfuncs;
+} SessionContent;
+
 
 JingleSession *session_new(JingleNode *jn, LmMessageNode *app,
                            LmMessageNode *transport);