[farsight2/master] msn: Stash the session id in the candidate username

Olivier Crête olivier.crete at collabora.co.uk
Tue Jul 14 09:51:02 PDT 2009


---
 gst/fsmsnconference/fs-msn-connection.c |   35 +++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/gst/fsmsnconference/fs-msn-connection.c b/gst/fsmsnconference/fs-msn-connection.c
index 115215a..4b0113d 100644
--- a/gst/fsmsnconference/fs-msn-connection.c
+++ b/gst/fsmsnconference/fs-msn-connection.c
@@ -349,6 +349,7 @@ fs_msn_connection_set_remote_candidates (FsMsnConnection *self,
   GList *item = NULL;
   gchar *recipient_id = NULL;
   gboolean ret = FALSE;
+  guint session_id = 0;
 
   if (!candidates)
   {
@@ -390,9 +391,38 @@ fs_msn_connection_set_remote_candidates (FsMsnConnection *self,
     {
       recipient_id = candidate->foundation;
     }
+
+    if (candidate->username)
+    {
+      guint sid = atoi (candidate->username);
+
+      if (sid < 9000 || session_id > 9999)
+      {
+          g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
+              "The session ID (in the username) must be between 9000 and 9999,"
+              " %d is invalid", sid);
+          goto out;
+      }
+
+      if (session_id)
+      {
+        if (session_id != sid)
+        {
+          g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
+              "The candidates do not have the same session ID"
+              " (in the username)");
+          goto out;
+        }
+      }
+      else
+      {
+        session_id = sid;
+      }
+    }
   }
 
   self->remote_recipient_id = g_strdup (recipient_id);
+  self->session_id = session_id;
   ret = TRUE;
   for (item = candidates; item; item = g_list_next (item))
   {
@@ -420,6 +450,7 @@ fs_msn_open_listening_port_unlock (FsMsnConnection *self, guint16 port,
   FsCandidate * candidate = NULL;
   GList *addresses = fs_interfaces_get_local_ips (FALSE);
   GList *item = NULL;
+  gchar *session_id;
 
 
   GST_DEBUG ("Attempting to listen on port %d.....",port);
@@ -495,6 +526,7 @@ fs_msn_open_listening_port_unlock (FsMsnConnection *self, guint16 port,
 
   self->local_recipient_id = g_strdup_printf ("%d",
       g_random_int_range (100, 199));
+  session_id = g_strdup_printf ("%u", self->session_id);
 
   FS_MSN_CONNECTION_UNLOCK (self);
 
@@ -504,12 +536,15 @@ fs_msn_open_listening_port_unlock (FsMsnConnection *self, guint16 port,
   {
     candidate = fs_candidate_new (self->local_recipient_id, 1,
         FS_CANDIDATE_TYPE_HOST, FS_NETWORK_PROTOCOL_TCP, item->data, port);
+    candidate->username = g_strdup (session_id);
 
     g_signal_emit (self, signals[SIGNAL_NEW_LOCAL_CANDIDATE], 0, candidate);
 
     fs_candidate_destroy (candidate);
   }
 
+  g_free (session_id);
+
   g_list_foreach (addresses, (GFunc) g_free, NULL);
   g_list_free (addresses);
 
-- 
1.5.6.5




More information about the farsight-commits mailing list