[telepathy-gabble/master] Remove duplicated <content>-generation code.

Will Thompson will.thompson at collabora.co.uk
Mon Jun 22 08:14:22 PDT 2009


Fixes fd.o#22236: “gabble_jingle_content_produce_node and
transmit_candidates contain similar but subtly-different <content>
stanza generators”. The difference mentioned on that bug (whether or not
a <transport/> node is added for GTalk3) was fixed in the course of
adding Google Video support.
---
 src/jingle-content.c          |   42 +++++++++++++++++++++++-----------------
 src/jingle-content.h          |    5 +++-
 src/jingle-session.c          |    2 +-
 src/jingle-transport-google.c |   34 +-------------------------------
 4 files changed, 31 insertions(+), 52 deletions(-)

diff --git a/src/jingle-content.c b/src/jingle-content.c
index 6fee858..08dacf5 100644
--- a/src/jingle-content.c
+++ b/src/jingle-content.c
@@ -660,7 +660,10 @@ gabble_jingle_content_parse_description_info (GabbleJingleContent *c,
 
 void
 gabble_jingle_content_produce_node (GabbleJingleContent *c,
-  LmMessageNode *parent, gboolean full)
+    LmMessageNode *parent,
+    gboolean include_description,
+    gboolean include_transport,
+    LmMessageNode **trans_node_out)
 {
   GabbleJingleContentPrivate *priv = c->priv;
   LmMessageNode *content_node, *trans_node;
@@ -673,10 +676,6 @@ gabble_jingle_content_produce_node (GabbleJingleContent *c,
   if ((dialect == JINGLE_DIALECT_GTALK3) ||
       (dialect == JINGLE_DIALECT_GTALK4))
     {
-      /* content-* isn't used in GTalk anyways, so we always have to include
-       * the full content description */
-      g_assert (full == TRUE);
-
       content_node = parent;
     }
   else
@@ -694,17 +693,24 @@ gabble_jingle_content_produce_node (GabbleJingleContent *c,
         lm_message_node_set_attribute (content_node, "creator", "responder");
     }
 
-  if (!full)
-    return;
-
-  produce_desc (c, content_node);
+  if (include_description)
+    produce_desc (c, content_node);
 
-  /* We can do it here, don't need to call into transport object for this */
-  if (dialect != JINGLE_DIALECT_GTALK3)
+  if (include_transport)
     {
-      /* Galk 03 doesn't use a transport, but assumes Gtalk p2p */
-      trans_node = lm_message_node_add_child (content_node, "transport", NULL);
-      lm_message_node_set_attribute (trans_node, "xmlns", priv->transport_ns);
+      if (dialect == JINGLE_DIALECT_GTALK3)
+        {
+          /* GTalk 03 doesn't use a transport, but assumes gtalk-p2p */
+          trans_node = parent;
+        }
+      else
+        {
+          trans_node = lm_message_node_add_child (content_node, "transport", NULL);
+          lm_message_node_set_attribute (trans_node, "xmlns", priv->transport_ns);
+        }
+
+      if (trans_node_out != NULL)
+        *trans_node_out = trans_node;
     }
 }
 
@@ -809,7 +815,7 @@ send_content_add_or_accept (GabbleJingleContent *self)
 
   msg = gabble_jingle_session_new_message (self->session,
       action, &sess_node);
-  gabble_jingle_content_produce_node (self, sess_node, TRUE);
+  gabble_jingle_content_produce_node (self, sess_node, TRUE, TRUE, NULL);
   gabble_jingle_session_send (self->session, msg, NULL, NULL);
 
   priv->state = new_state;
@@ -874,7 +880,7 @@ gabble_jingle_content_maybe_send_description (GabbleJingleContent *self)
 
   msg = gabble_jingle_session_new_message (self->session,
       JINGLE_ACTION_DESCRIPTION_INFO, &sess_node);
-  gabble_jingle_content_produce_node (self, sess_node, TRUE);
+  gabble_jingle_content_produce_node (self, sess_node, TRUE, TRUE, NULL);
   gabble_jingle_session_send (self->session, msg, NULL, NULL);
 }
 
@@ -944,7 +950,7 @@ gabble_jingle_content_change_direction (GabbleJingleContent *c,
 
   msg = gabble_jingle_session_new_message (c->session,
       JINGLE_ACTION_CONTENT_MODIFY, &sess_node);
-  gabble_jingle_content_produce_node (c, sess_node, FALSE);
+  gabble_jingle_content_produce_node (c, sess_node, FALSE, FALSE, NULL);
   gabble_jingle_session_send (c->session, msg, NULL, NULL);
 
   /* FIXME: actually check whether remote end accepts our content-modify */
@@ -1000,7 +1006,7 @@ gabble_jingle_content_remove (GabbleJingleContent *c, gboolean signal_peer)
 
       msg = gabble_jingle_session_new_message (c->session,
           JINGLE_ACTION_CONTENT_REMOVE, &sess_node);
-      gabble_jingle_content_produce_node (c, sess_node, FALSE);
+      gabble_jingle_content_produce_node (c, sess_node, FALSE, FALSE, NULL);
       gabble_jingle_session_send (c->session, msg, _on_remove_reply,
           (GObject *) c);
     }
diff --git a/src/jingle-content.h b/src/jingle-content.h
index 62c159f..a65f407 100644
--- a/src/jingle-content.h
+++ b/src/jingle-content.h
@@ -100,7 +100,10 @@ void gabble_jingle_content_parse_add (GabbleJingleContent *c,
 void gabble_jingle_content_update_senders (GabbleJingleContent *c,
     LmMessageNode *content_node, GError **error);
 void gabble_jingle_content_produce_node (GabbleJingleContent *c,
-  LmMessageNode *parent, gboolean full);
+    LmMessageNode *parent,
+    gboolean include_description,
+    gboolean include_transport,
+    LmMessageNode **trans_node_out);
 void gabble_jingle_content_parse_accept (GabbleJingleContent *c,
   LmMessageNode *content_node, gboolean google_mode, GError **error);
 
diff --git a/src/jingle-session.c b/src/jingle-session.c
index 2efff30..f4dd25f 100644
--- a/src/jingle-session.c
+++ b/src/jingle-session.c
@@ -1658,7 +1658,7 @@ _fill_content (GabbleJingleSession *sess,
   LmMessageNode *sess_node = user_data;
   JingleContentState state;
 
-  gabble_jingle_content_produce_node (c, sess_node, TRUE);
+  gabble_jingle_content_produce_node (c, sess_node, TRUE, TRUE, NULL);
 
   g_object_get (c, "state", &state, NULL);
 
diff --git a/src/jingle-transport-google.c b/src/jingle-transport-google.c
index 8d7d70b..1de8396 100644
--- a/src/jingle-transport-google.c
+++ b/src/jingle-transport-google.c
@@ -415,38 +415,8 @@ transmit_candidates (GabbleJingleTransportGoogle *transport, GList *candidates)
   g_object_get (priv->content->session, "dialect", &dialect, NULL);
   g_object_get (priv->content, "media-type", &media_type, NULL);
 
-  if (dialect == JINGLE_DIALECT_GTALK3)
-    {
-      trans_node = sess_node;
-    }
-  else if (dialect == JINGLE_DIALECT_GTALK4)
-    {
-      trans_node = lm_message_node_add_child (sess_node, "transport", NULL);
-      lm_message_node_set_attribute (trans_node, "xmlns",
-          NS_GOOGLE_TRANSPORT_P2P);
-    }
-  else
-    {
-      const gchar *name = gabble_jingle_content_get_name (priv->content);
-      const gchar *ns = gabble_jingle_content_get_ns (priv->content);
-      LmMessageNode *content_node;
-
-      /* FIXME: this should use gabble_jingle_content_produce_node(); #22236 */
-
-      /* we need the <content> ... */
-      content_node = lm_message_node_add_child (sess_node, "content", NULL);
-      lm_message_node_set_attribute (content_node, "xmlns", ns);
-      lm_message_node_set_attribute (content_node, "name", name);
-
-      if (gabble_jingle_content_creator_is_initiator (priv->content))
-        lm_message_node_set_attribute (content_node, "creator", "initiator");
-      else
-        lm_message_node_set_attribute (content_node, "creator", "responder");
-
-      /* .. and the <transport> node */
-      trans_node = lm_message_node_add_child (content_node, "transport", NULL);
-      lm_message_node_set_attribute (trans_node, "xmlns", priv->transport_ns);
-    }
+  gabble_jingle_content_produce_node (priv->content, sess_node, FALSE, TRUE,
+      &trans_node);
 
   for (li = candidates; li; li = li->next)
     {
-- 
1.5.6.5




More information about the telepathy-commits mailing list