[Telepathy-commits] [telepathy-sofiasip/master] Put some brainpower into saving the NUA message structure
Mikhail Zabaluev
mikhail.zabaluev at nokia.com
Fri Oct 24 04:12:47 PDT 2008
The previous code for that was stupid and broken.
---
src/sip-text-channel.c | 27 +++++++++++++--------------
src/sip-text-channel.h | 2 +-
src/text-factory.c | 7 ++-----
3 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/src/sip-text-channel.c b/src/sip-text-channel.c
index 2851e7a..07d7b21 100644
--- a/src/sip-text-channel.c
+++ b/src/sip-text-channel.c
@@ -102,7 +102,7 @@ struct _TpsipTextPendingMessage
gchar *text;
nua_handle_t *nh;
- nua_saved_event_t *saved_event;
+ nua_saved_event_t saved_event[1];
};
typedef struct _TpsipTextChannelPrivate TpsipTextChannelPrivate;
@@ -138,7 +138,7 @@ static void tpsip_text_pending_free (TpsipTextPendingMessage *msg,
g_free (msg->text);
- if (msg->saved_event)
+ if (msg->saved_event[0])
nua_destroy_event (msg->saved_event);
if (msg->nh)
@@ -485,7 +485,7 @@ tpsip_text_channel_finalize(GObject *object)
static gint tpsip_pending_message_compare(gconstpointer msg, gconstpointer id)
{
TpsipTextPendingMessage *message = (TpsipTextPendingMessage *)(msg);
- return (message->id != GPOINTER_TO_INT(id));
+ return (message->id != GPOINTER_TO_UINT(id));
}
static gint tpsip_acknowledged_messages_compare(gconstpointer msg,
@@ -504,19 +504,16 @@ static gint tpsip_acknowledged_messages_compare(gconstpointer msg,
*/
static void
tpsip_text_channel_acknowledge_pending_messages(TpSvcChannelTypeText *iface,
- const GArray *ids,
- DBusGMethodInvocation *context)
+ const GArray *ids,
+ DBusGMethodInvocation *context)
{
- TpsipTextChannel *obj = TPSIP_TEXT_CHANNEL (iface);
- TpsipTextChannelPrivate *priv;
+ TpsipTextChannel *chan = TPSIP_TEXT_CHANNEL (iface);
+ TpsipTextChannelPrivate *priv = TPSIP_TEXT_CHANNEL_GET_PRIVATE(chan);
TpHandleRepoIface *contact_repo;
GList **nodes;
TpsipTextPendingMessage *msg;
guint i;
- DEBUG("enter");
-
- priv = TPSIP_TEXT_CHANNEL_GET_PRIVATE(obj);
contact_repo = tp_base_connection_get_handles (
(TpBaseConnection *)(priv->conn), TP_HANDLE_TYPE_CONTACT);
@@ -527,7 +524,7 @@ tpsip_text_channel_acknowledge_pending_messages(TpSvcChannelTypeText *iface,
guint id = g_array_index(ids, guint, i);
nodes[i] = g_queue_find_custom (priv->pending_messages,
- GINT_TO_POINTER (id),
+ GUINT_TO_POINTER (id),
tpsip_pending_message_compare);
if (nodes[i] == NULL)
@@ -909,8 +906,8 @@ tpsip_text_channel_nua_r_message_cb (TpsipTextChannel *self,
}
void tpsip_text_channel_receive(TpsipTextChannel *chan,
+ nua_t *nua,
nua_handle_t *nh,
- nua_saved_event_t *event,
TpHandle sender,
const char *text,
gsize len)
@@ -924,11 +921,12 @@ void tpsip_text_channel_receive(TpsipTextChannel *chan,
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_strndup (text, len);
+ nua_save_event (nua, msg->saved_event);
+
g_queue_push_tail(priv->pending_messages, msg);
nua_handle_ref (nh);
@@ -938,7 +936,8 @@ void tpsip_text_channel_receive(TpsipTextChannel *chan,
tp_handle_ref (contact_repo, sender);
- DEBUG("received message: %s", text);
+ DEBUG("received message id %u, now %u pending",
+ msg->id, g_queue_get_length (priv->pending_messages));
tp_svc_channel_type_text_emit_received ((TpSvcChannelTypeText *)chan,
msg->id, msg->timestamp, msg->sender, msg->type,
diff --git a/src/sip-text-channel.h b/src/sip-text-channel.h
index e3db61b..323e71e 100644
--- a/src/sip-text-channel.h
+++ b/src/sip-text-channel.h
@@ -59,8 +59,8 @@ GType tpsip_text_channel_get_type(void);
(G_TYPE_INSTANCE_GET_CLASS ((obj), TPSIP_TYPE_TEXT_CHANNEL, TpsipTextChannelClass))
void tpsip_text_channel_receive (TpsipTextChannel *obj,
+ nua_t *nua,
nua_handle_t *nh,
- nua_saved_event_t *event,
TpHandle sender,
const char *text,
gsize len);
diff --git a/src/text-factory.c b/src/text-factory.c
index e8624db..1b450f5 100644
--- a/src/text-factory.c
+++ b/src/text-factory.c
@@ -333,7 +333,6 @@ tpsip_nua_i_message_cb (TpBaseConnection *conn,
const char *text = "";
gsize len = 0;
gboolean own_text = FALSE;
- nua_saved_event_t event[1];
/* Block anything else except text/plain messages (like isComposings) */
if (sip->sip_content_type
@@ -443,17 +442,15 @@ tpsip_nua_i_message_cb (TpBaseConnection *conn,
channel = tpsip_text_factory_new_channel (fac,
handle, handle, NULL);
- 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_182_QUEUED,
- NUTAG_WITH_SAVED(event),
+ NUTAG_WITH_THIS(ev->nua),
TAG_END());
tpsip_text_channel_receive (channel,
- ev->nua_handle, event, handle, text, len);
+ ev->nua, ev->nua_handle, handle, text, len);
tp_handle_unref (contact_repo, handle);
--
1.5.6.5
More information about the Telepathy-commits
mailing list