summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author <rob.taylor@collabora.co.uk>2006-02-22 17:31:53 +0000
committer <rob.taylor@collabora.co.uk>2006-02-22 17:31:53 +0000
commit9e8347e6a025798eab64f80d2982a42f7ceb547a (patch)
tree2af85848dc0a7fe073ba0728be6398e5ed1a752d
parentf2e847eccd41a56bb0e21c8243e1e5eeb08d37b2 (diff)
manually pulled the send_with_reply patch from telepathy-gabble-voipbefore_merge_of_telepathy-gabble-voip
-rw-r--r--src/gabble-connection.c87
-rw-r--r--src/gabble-connection.h7
2 files changed, 94 insertions, 0 deletions
diff --git a/src/gabble-connection.c b/src/gabble-connection.c
index 17d73c4ea..2d75336e6 100644
--- a/src/gabble-connection.c
+++ b/src/gabble-connection.c
@@ -744,6 +744,93 @@ _gabble_connection_send (GabbleConnection *conn, LmMessage *msg, GError **error)
return TRUE;
}
+typedef struct {
+ GabbleConnectionMsgReplyFunc reply_func;
+
+ GabbleConnection *conn;
+ LmMessage *sent_msg;
+ gpointer user_data;
+} GabbleMsgHandlerData;
+
+static LmHandlerResult
+message_send_reply_cb (LmMessageHandler *handler,
+ LmConnection *connection,
+ LmMessage *reply_msg,
+ gpointer user_data)
+{
+ GabbleMsgHandlerData *handler_data = user_data;
+ LmMessageSubType sub_type;
+
+ sub_type = lm_message_get_sub_type (reply_msg);
+ if (sub_type != LM_MESSAGE_SUB_TYPE_RESULT &&
+ sub_type != LM_MESSAGE_SUB_TYPE_ERROR)
+ {
+ lm_message_unref (handler_data->sent_msg);
+
+ return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
+ }
+
+ handler_data->reply_func (handler_data->conn,
+ handler_data->sent_msg,
+ reply_msg,
+ handler_data->user_data);
+
+ lm_message_unref (handler_data->sent_msg);
+
+ return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+}
+
+/**
+ * _gabble_connection_send_with_reply
+ *
+ * Send a tracked LmMessage and trap network errors appropriately.
+ */
+gboolean
+_gabble_connection_send_with_reply (GabbleConnection *conn,
+ LmMessage *msg,
+ GabbleConnectionMsgReplyFunc reply_func,
+ gpointer user_data,
+ GError **error)
+{
+ GabbleConnectionPrivate *priv;
+ LmMessageHandler *handler;
+ GabbleMsgHandlerData *handler_data;
+ gboolean ret;
+ GError *lmerror = NULL;
+
+ g_assert (GABBLE_IS_CONNECTION (conn));
+
+ priv = GABBLE_CONNECTION_GET_PRIVATE (conn);
+
+ lm_message_ref (msg);
+
+ handler_data = g_new (GabbleMsgHandlerData, 1);
+ handler_data->reply_func = reply_func;
+ handler_data->conn = conn;
+ handler_data->sent_msg = msg;
+ handler_data->user_data = user_data;
+
+ handler = lm_message_handler_new (message_send_reply_cb, handler_data, g_free);
+
+ ret = lm_connection_send_with_reply (priv->conn, msg, handler, &lmerror);
+ if (!ret)
+ {
+ g_debug ("_gabble_connection_send_with_reply failed: %s", lmerror->message);
+
+ if (error)
+ {
+ *error = g_error_new (TELEPATHY_ERRORS, NetworkError,
+ "message send failed: %s", lmerror->message);
+ }
+
+ g_error_free (lmerror);
+ }
+
+ lm_message_handler_unref (handler);
+
+ return ret;
+}
+
static LmHandlerResult connection_message_cb (LmMessageHandler*, LmConnection*, LmMessage*, gpointer);
static LmHandlerResult connection_presence_cb (LmMessageHandler*, LmConnection*, LmMessage*, gpointer);
static LmHandlerResult connection_iq_roster_cb (LmMessageHandler*, LmConnection*, LmMessage*, gpointer);
diff --git a/src/gabble-connection.h b/src/gabble-connection.h
index 6058613be..1d8510053 100644
--- a/src/gabble-connection.h
+++ b/src/gabble-connection.h
@@ -31,6 +31,11 @@ G_BEGIN_DECLS
typedef struct _GabbleConnection GabbleConnection;
typedef struct _GabbleConnectionClass GabbleConnectionClass;
+typedef void (*GabbleConnectionMsgReplyFunc) (GabbleConnection *conn,
+ LmMessage *sent_msg,
+ LmMessage *reply_msg,
+ gpointer user_data);
+
struct _GabbleConnectionClass {
GObjectClass parent_class;
};
@@ -60,6 +65,8 @@ gboolean _gabble_connection_register (GabbleConnection *conn, char **bus_name, c
gboolean _gabble_connection_connect (GabbleConnection *conn, GError **error);
GabbleHandleRepo *_gabble_connection_get_handles (GabbleConnection *conn);
gboolean _gabble_connection_send (GabbleConnection *conn, LmMessage *msg, GError **error);
+gboolean _gabble_connection_send_with_reply (GabbleConnection *conn, LmMessage *msg, GabbleConnectionMsgReplyFunc reply_func, gpointer user_data, GError **error);
+void _gabble_connection_send_iq_ack (GabbleConnection *conn, LmMessageNode *iq_node, LmMessageSubType type);
void _gabble_connection_client_hold_handle (GabbleConnection *conn, gchar* client_name, GabbleHandle handle, TpHandleType type);
gboolean _gabble_connection_client_release_handle (GabbleConnection *conn, gchar* client_name, GabbleHandle handle, TpHandleType type);