[Telepathy-commits] [telepathy-sofiasip/master] Delay the final 200 response to an incoming MESSAGE until acknowledged

Mikhail Zabaluev mikhail.zabaluev at nokia.com
Fri Oct 17 10:13:19 PDT 2008


---
 src/sip-connection.c   |   16 ++++++++++----
 src/sip-text-channel.c |   50 ++++++++++++++++++++++++++++++-----------------
 src/sip-text-channel.h |    9 ++++---
 3 files changed, 48 insertions(+), 27 deletions(-)

diff --git a/src/sip-connection.c b/src/sip-connection.c
index 92c6655..28e3bc7 100644
--- a/src/sip-connection.c
+++ b/src/sip-connection.c
@@ -926,6 +926,8 @@ tpsip_connection_nua_i_message_cb (TpsipConnection   *self,
 
   if (handle)
     {
+      nua_saved_event_t event[1];
+
       DEBUG("Got incoming message from <%s>", 
             tp_handle_inspect (contact_repo, handle));
 
@@ -935,14 +937,18 @@ tpsip_connection_nua_i_message_cb (TpsipConnection   *self,
         channel = tpsip_text_factory_new_channel (priv->text_factory,
             handle, handle, NULL);
 
-      tpsip_text_channel_receive (channel, handle, text);
-
-      tp_handle_unref (contact_repo, handle);
+      nua_save_event (ev->nua, event);
 
+      /* Return a provisional response to quench retransmissions.
+       * The acknowledgement will be signalled later with 200 OK */
       nua_respond (ev->nua_handle,
-                   SIP_200_OK,
-                   NUTAG_WITH_THIS(ev->nua),
+                   SIP_182_QUEUED,
+                   NUTAG_WITH_SAVED(event),
                    TAG_END());
+
+      tpsip_text_channel_receive (channel, ev->nua_handle, event, handle, text);
+
+      tp_handle_unref (contact_repo, handle);
     }
   else
     {
diff --git a/src/sip-text-channel.c b/src/sip-text-channel.c
index 661b50c..bcb52e6 100644
--- a/src/sip-text-channel.c
+++ b/src/sip-text-channel.c
@@ -30,8 +30,6 @@
 #include <time.h>
 
 #include <dbus/dbus-glib.h>
-#include <sofia-sip/sip.h>
-#include <sofia-sip/sip_header.h>
 #include <telepathy-glib/channel-iface.h>
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/errors.h>
@@ -42,11 +40,14 @@
 
 #include <tpsip/event-target.h>
 
-#define DEBUG_FLAG TPSIP_DEBUG_IM
-#include "debug.h"
 #include "sip-connection.h"
 #include "sip-connection-helpers.h"
 
+#include <sofia-sip/sip_status.h>
+
+#define DEBUG_FLAG TPSIP_DEBUG_IM
+#include "debug.h"
+
 static gboolean
 tpsip_text_channel_nua_r_message_cb (TpsipTextChannel *self,
                                      const TpsipNuaEvent *ev,
@@ -94,15 +95,13 @@ typedef struct _TpsipTextPendingMessage TpsipTextPendingMessage;
 struct _TpsipTextPendingMessage
 {
   guint id;
-  nua_handle_t *nh;
-  
-  
   time_t timestamp;
   TpHandle sender;
-  
   TpChannelTextMessageType type;
-  
   gchar *text;
+
+  nua_handle_t *nh;
+  nua_saved_event_t *saved_event;
 };
 
 typedef struct _TpsipTextChannelPrivate TpsipTextChannelPrivate;
@@ -140,7 +139,11 @@ static void tpsip_text_pending_free (TpsipTextPendingMessage *msg,
 
   g_free (msg->text);
 
-  nua_handle_unref (msg->nh);
+  if (msg->saved_event)
+    nua_destroy_event (msg->saved_event);
+
+  if (msg->nh)
+    nua_handle_unref (msg->nh);
 
   g_slice_free (TpsipTextPendingMessage, msg);
 }
@@ -442,6 +445,9 @@ tpsip_text_channel_finalize(GObject *object)
 
   if (!g_queue_is_empty (priv->pending_messages))
     {
+      /* XXX: could have responded to the requests with e.g. 480,
+       * but generating network traffic upon abnormal channel termination
+       * does not sound like a good idea */
       g_warning ("zapping %u pending incoming messages",
                  g_queue_get_length (priv->pending_messages));
       g_queue_foreach (priv->pending_messages,
@@ -535,6 +541,11 @@ tpsip_text_channel_acknowledge_pending_messages(TpSvcChannelTypeText *iface,
 
       g_queue_remove (priv->pending_messages, msg);
 
+      nua_respond (msg->nh,
+                   SIP_200_OK,
+                   NUTAG_WITH_SAVED(msg->saved_event),
+                   TAG_END());
+
       tpsip_text_pending_free (msg, contact_repo);
     }
 
@@ -866,32 +877,35 @@ tpsip_text_channel_nua_r_message_cb (TpsipTextChannel *self,
 }
 
 void tpsip_text_channel_receive(TpsipTextChannel *chan,
+                                nua_handle_t *nh,
+                                nua_saved_event_t *event,
 			        TpHandle sender,
 			        const char *message)
 {
+  TpsipTextChannelPrivate *priv = TPSIP_TEXT_CHANNEL_GET_PRIVATE (chan);
   TpsipTextPendingMessage *msg;
-  TpsipTextChannelPrivate *priv;
   TpHandleRepoIface *contact_repo;
 
   DEBUG("enter");
 
-  g_assert(chan != NULL);
-  g_assert(TPSIP_IS_TEXT_CHANNEL(chan));
-  priv = TPSIP_TEXT_CHANNEL_GET_PRIVATE (chan);
-  contact_repo = tp_base_connection_get_handles (
-      (TpBaseConnection *)(priv->conn), TP_HANDLE_TYPE_CONTACT);
-
   msg = _tpsip_text_pending_new();
 
   msg->id = priv->recv_id++;
   msg->timestamp = time(NULL);
+  msg->nh = nh;
+  msg->saved_event = event;
   msg->sender = sender;
   msg->type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;
   msg->text = g_strdup(message);
 
   g_queue_push_tail(priv->pending_messages, msg);
 
-  tp_handle_ref (contact_repo, msg->sender);
+  nua_handle_ref (nh);
+
+  contact_repo = tp_base_connection_get_handles (
+      (TpBaseConnection *)(priv->conn), TP_HANDLE_TYPE_CONTACT);
+
+  tp_handle_ref (contact_repo, sender);
 
   DEBUG("received message: %s", message);
 
diff --git a/src/sip-text-channel.h b/src/sip-text-channel.h
index 5e8603c..0b84bef 100644
--- a/src/sip-text-channel.h
+++ b/src/sip-text-channel.h
@@ -63,10 +63,11 @@ GType tpsip_text_channel_get_type(void);
 
 void tpsip_text_channel_close (TpsipTextChannel *self);
 
-void tpsip_text_channel_receive (TpsipTextChannel *obj,
-                                 TpHandle        sender,
-                                 const char     *message);
-
+void tpsip_text_channel_receive (TpsipTextChannel  *obj,
+                                 nua_handle_t      *nh,
+                                 nua_saved_event_t *event,
+                                 TpHandle           sender,
+                                 const char        *message);
 
 G_END_DECLS
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list