[Telepathy-commits] [telepathy-gabble/master] GabbleTubesChannel: take an initiator handle, and also export TargetID and InitiatorID
Simon McVittie
simon.mcvittie at collabora.co.uk
Tue Aug 19 10:53:53 PDT 2008
The initiator of a Tubes channel is (currently) defined to be
* the local user, if it was requested; or
* the remote user, if it is 1-1; or
* 0, otherwise (we saw it in someone's presence in a MUC)
20080722142527-53eee-f1b75a0bad494364b813aab55a10955388a65dba.gz
---
src/muc-factory.c | 20 +++++++---
src/private-tubes-factory.c | 19 ++++++----
src/tubes-channel.c | 84 ++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 109 insertions(+), 14 deletions(-)
diff --git a/src/muc-factory.c b/src/muc-factory.c
index 06fdc80..c0662f6 100644
--- a/src/muc-factory.c
+++ b/src/muc-factory.c
@@ -391,7 +391,8 @@ new_muc_channel (GabbleMucFactory *fac,
static GabbleTubesChannel *
new_tubes_channel (GabbleMucFactory *fac,
TpHandle room,
- GabbleMucChannel *muc)
+ GabbleMucChannel *muc,
+ TpHandle initiator)
{
GabbleMucFactoryPrivate *priv = GABBLE_MUC_FACTORY_GET_PRIVATE (fac);
TpBaseConnection *conn = (TpBaseConnection *) priv->conn;
@@ -412,6 +413,7 @@ new_tubes_channel (GabbleMucFactory *fac,
"handle", room,
"handle-type", TP_HANDLE_TYPE_ROOM,
"muc", muc,
+ "initiator-handle", initiator,
NULL);
g_signal_connect (chan, "closed", (GCallback) tubes_channel_closed_cb, fac);
@@ -915,7 +917,10 @@ muc_factory_presence_cb (LmMessageHandler *handler,
* to create a tubes channel */
return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
- tubes_chan = new_tubes_channel (fac, room_handle, muc_chan);
+ /* MUC Tubes channels (as opposed to the individual tubes) don't
+ * have a well-defined initiator (they're a consensus) so use 0 */
+ tubes_chan = new_tubes_channel (fac, room_handle, muc_chan,
+ 0);
tp_channel_factory_iface_emit_new_channel (fac,
(TpChannelIface *) tubes_chan, NULL);
}
@@ -1148,8 +1153,9 @@ gabble_muc_factory_iface_request (TpChannelFactoryIface *iface,
{
GabbleMucFactory *fac = GABBLE_MUC_FACTORY (iface);
GabbleMucFactoryPrivate *priv = GABBLE_MUC_FACTORY_GET_PRIVATE (fac);
- TpHandleRepoIface *room_repo = tp_base_connection_get_handles (
- (TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_ROOM);
+ TpBaseConnection *base_conn = (TpBaseConnection *) priv->conn;
+ TpHandleRepoIface *room_repo = tp_base_connection_get_handles (base_conn,
+ TP_HANDLE_TYPE_ROOM);
GabbleMucChannel *text_chan;
GabbleTubesChannel *tubes_chan;
@@ -1202,14 +1208,16 @@ gabble_muc_factory_iface_request (TpChannelFactoryIface *iface,
{
if (ensure_muc_channel (fac, priv, handle, &text_chan))
{
- tubes_chan = new_tubes_channel (fac, handle, text_chan);
+ tubes_chan = new_tubes_channel (fac, handle, text_chan,
+ base_conn->self_handle);
*ret = TP_CHANNEL_IFACE (tubes_chan);
tp_channel_factory_iface_emit_new_channel (fac, *ret, NULL);
return TP_CHANNEL_FACTORY_REQUEST_STATUS_CREATED;
}
else
{
- tubes_chan = new_tubes_channel (fac, handle, text_chan);
+ tubes_chan = new_tubes_channel (fac, handle, text_chan,
+ base_conn->self_handle);
g_hash_table_insert (priv->text_needed_for_tubes,
text_chan, tubes_chan);
return TP_CHANNEL_FACTORY_REQUEST_STATUS_QUEUED;
diff --git a/src/private-tubes-factory.c b/src/private-tubes-factory.c
index aa01a29..1cd8ddb 100644
--- a/src/private-tubes-factory.c
+++ b/src/private-tubes-factory.c
@@ -39,7 +39,7 @@
#include "util.h"
static GabbleTubesChannel *new_tubes_channel (GabblePrivateTubesFactory *fac,
- TpHandle handle);
+ TpHandle handle, TpHandle initiator);
static void tubes_channel_closed_cb (GabbleTubesChannel *chan,
gpointer user_data);
@@ -246,14 +246,17 @@ tubes_channel_closed_cb (GabbleTubesChannel *chan,
*/
static GabbleTubesChannel *
new_tubes_channel (GabblePrivateTubesFactory *fac,
- TpHandle handle)
+ TpHandle handle,
+ TpHandle initiator)
{
GabblePrivateTubesFactoryPrivate *priv;
TpBaseConnection *conn;
GabbleTubesChannel *chan;
char *object_path;
- g_assert (GABBLE_IS_PRIVATE_TUBES_FACTORY (fac));
+ g_return_val_if_fail (GABBLE_IS_PRIVATE_TUBES_FACTORY (fac), NULL);
+ g_return_val_if_fail (handle != 0, NULL);
+ g_return_val_if_fail (initiator != 0, NULL);
priv = GABBLE_PRIVATE_TUBES_FACTORY_GET_PRIVATE (fac);
conn = (TpBaseConnection *) priv->conn;
@@ -266,6 +269,7 @@ new_tubes_channel (GabblePrivateTubesFactory *fac,
"object-path", object_path,
"handle", handle,
"handle-type", TP_HANDLE_TYPE_CONTACT,
+ "initiator-handle", initiator,
NULL);
DEBUG ("object path %s", object_path);
@@ -360,8 +364,9 @@ gabble_private_tubes_factory_iface_request (TpChannelFactoryIface *iface,
GabblePrivateTubesFactory *fac = GABBLE_PRIVATE_TUBES_FACTORY (iface);
GabblePrivateTubesFactoryPrivate *priv =
GABBLE_PRIVATE_TUBES_FACTORY_GET_PRIVATE (fac);
+ TpBaseConnection *base_conn = (TpBaseConnection *) priv->conn;
TpHandleRepoIface *contacts_repo = tp_base_connection_get_handles (
- (TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_CONTACT);
+ base_conn, TP_HANDLE_TYPE_CONTACT);
GabbleTubesChannel *chan;
TpChannelFactoryRequestStatus status;
@@ -388,7 +393,7 @@ gabble_private_tubes_factory_iface_request (TpChannelFactoryIface *iface,
if (chan == NULL)
{
status = TP_CHANNEL_FACTORY_REQUEST_STATUS_CREATED;
- chan = new_tubes_channel (fac, handle);
+ chan = new_tubes_channel (fac, handle, base_conn->self_handle);
tp_channel_factory_iface_emit_new_channel (fac, (TpChannelIface *) chan,
request);
}
@@ -418,7 +423,7 @@ gabble_private_tubes_factory_handle_si_tube_request (
chan = g_hash_table_lookup (priv->channels, GUINT_TO_POINTER (handle));
if (chan == NULL)
{
- chan = new_tubes_channel (self, handle);
+ chan = new_tubes_channel (self, handle, handle);
tp_channel_factory_iface_emit_new_channel (self,
(TpChannelIface *) chan, NULL);
@@ -507,7 +512,7 @@ private_tubes_factory_msg_tube_cb (LmMessageHandler *handler,
{
/* We create the tubes channel only if the message is a new tube
* offer */
- chan = new_tubes_channel (self, handle);
+ chan = new_tubes_channel (self, handle, handle);
tp_channel_factory_iface_emit_new_channel (self,
(TpChannelIface *) chan, NULL);
}
diff --git a/src/tubes-channel.c b/src/tubes-channel.c
index dffd60c..4ac4be8 100644
--- a/src/tubes-channel.c
+++ b/src/tubes-channel.c
@@ -39,6 +39,8 @@
#include <telepathy-glib/svc-channel.h>
#include <telepathy-glib/svc-generic.h>
+#include "extensions/extensions.h"
+
#define DEBUG_FLAG GABBLE_DEBUG_TUBES
#include "bytestream-factory.h"
@@ -63,6 +65,7 @@ G_DEFINE_TYPE_WITH_CODE (GabbleTubesChannel, gabble_tubes_channel,
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
tp_dbus_properties_mixin_iface_init);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL, channel_iface_init);
+ G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CHANNEL_FUTURE, NULL);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_TYPE_TUBES, tubes_iface_init);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_GROUP,
tp_external_group_mixin_iface_init);
@@ -73,6 +76,7 @@ static const gchar *gabble_tubes_channel_interfaces[] = {
/* If more interfaces are added, either keep Group as the first, or change
* the implementations of gabble_tubes_channel_get_interfaces () and
* gabble_tubes_channel_get_property () too */
+ GABBLE_IFACE_CHANNEL_FUTURE,
NULL
};
@@ -83,9 +87,12 @@ enum
PROP_CHANNEL_TYPE,
PROP_HANDLE_TYPE,
PROP_HANDLE,
+ PROP_TARGET_ID,
PROP_CONNECTION,
PROP_INTERFACES,
PROP_MUC,
+ PROP_INITIATOR_HANDLE,
+ PROP_INITIATOR_ID,
LAST_PROPERTY,
};
@@ -98,6 +105,7 @@ struct _GabbleTubesChannelPrivate
TpHandle handle;
TpHandleType handle_type;
TpHandle self_handle;
+ TpHandle initiator;
GHashTable *tubes;
@@ -134,7 +142,7 @@ gabble_tubes_channel_constructor (GType type,
GabbleTubesChannel *self;
GabbleTubesChannelPrivate *priv;
DBusGConnection *bus;
- TpHandleRepoIface *handle_repo;
+ TpHandleRepoIface *handle_repo, *contact_repo;
DEBUG ("Called");
@@ -143,15 +151,21 @@ gabble_tubes_channel_constructor (GType type,
self = GABBLE_TUBES_CHANNEL (obj);
priv = GABBLE_TUBES_CHANNEL_GET_PRIVATE (self);
+ contact_repo = tp_base_connection_get_handles (
+ (TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_CONTACT);
handle_repo = tp_base_connection_get_handles (
(TpBaseConnection *) priv->conn, priv->handle_type);
tp_handle_ref (handle_repo, priv->handle);
+ if (priv->initiator != 0)
+ tp_handle_ref (contact_repo, priv->initiator);
+
switch (priv->handle_type)
{
case TP_HANDLE_TYPE_CONTACT:
g_assert (self->muc == NULL);
+ g_assert (priv->initiator != 0);
priv->self_handle = ((TpBaseConnection *) (priv->conn))->self_handle;
break;
case TP_HANDLE_TYPE_ROOM:
@@ -198,6 +212,15 @@ gabble_tubes_channel_get_property (GObject *object,
case PROP_HANDLE:
g_value_set_uint (value, priv->handle);
break;
+ case PROP_TARGET_ID:
+ {
+ TpHandleRepoIface *repo = tp_base_connection_get_handles (
+ (TpBaseConnection *) priv->conn, priv->handle_type);
+
+ g_value_set_string (value,
+ tp_handle_inspect (repo, priv->handle));
+ }
+ break;
case PROP_CONNECTION:
g_value_set_object (value, priv->conn);
break;
@@ -216,6 +239,23 @@ gabble_tubes_channel_get_property (GObject *object,
case PROP_MUC:
g_value_set_object (value, chan->muc);
break;
+ case PROP_INITIATOR_HANDLE:
+ g_value_set_uint (value, priv->initiator);
+ break;
+ case PROP_INITIATOR_ID:
+ if (priv->initiator == 0)
+ {
+ g_value_set_static_string (value, "");
+ }
+ else
+ {
+ TpHandleRepoIface *repo = tp_base_connection_get_handles (
+ (TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_CONTACT);
+
+ g_value_set_string (value,
+ tp_handle_inspect (repo, priv->initiator));
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -254,6 +294,9 @@ gabble_tubes_channel_set_property (GObject *object,
case PROP_MUC:
chan->muc = g_value_get_object (value);
break;
+ case PROP_INITIATOR_HANDLE:
+ priv->initiator = g_value_get_uint (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -2387,12 +2430,23 @@ gabble_tubes_channel_class_init (
{ "Interfaces", "interfaces", NULL },
{ NULL }
};
+ static TpDBusPropertiesMixinPropImpl future_props[] = {
+ { "TargetID", "target-id", NULL },
+ { "InitiatorHandle", "initiator-handle", NULL },
+ { "InitiatorID", "initiator-id", NULL },
+ { NULL }
+ };
static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
{ TP_IFACE_CHANNEL,
tp_dbus_properties_mixin_getter_gobject_properties,
NULL,
channel_props,
},
+ { GABBLE_IFACE_CHANNEL_FUTURE,
+ tp_dbus_properties_mixin_getter_gobject_properties,
+ NULL,
+ future_props,
+ },
{ NULL }
};
GObjectClass *object_class = G_OBJECT_CLASS (gabble_tubes_channel_class);
@@ -2449,6 +2503,29 @@ gabble_tubes_channel_class_init (
G_PARAM_STATIC_BLURB);
g_object_class_install_property (object_class, PROP_MUC, param_spec);
+ param_spec = g_param_spec_string ("target-id", "Target JID",
+ "The string obtained by inspecting the target handle",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+ g_object_class_install_property (object_class, PROP_TARGET_ID, param_spec);
+
+ param_spec = g_param_spec_uint ("initiator-handle", "Initiator's handle",
+ "The contact who initiated the channel",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+ g_object_class_install_property (object_class, PROP_INITIATOR_HANDLE,
+ param_spec);
+
+ param_spec = g_param_spec_string ("initiator-id", "Initiator's bare JID",
+ "The string obtained by inspecting the initiator-handle",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+ g_object_class_install_property (object_class, PROP_INITIATOR_ID,
+ param_spec);
+
gabble_tubes_channel_class->dbus_props_class.interfaces = prop_interfaces;
tp_dbus_properties_mixin_class_init (object_class,
G_STRUCT_OFFSET (GabbleTubesChannelClass, dbus_props_class));
@@ -2491,9 +2568,14 @@ gabble_tubes_channel_finalize (GObject *object)
{
GabbleTubesChannel *self = GABBLE_TUBES_CHANNEL (object);
GabbleTubesChannelPrivate *priv = GABBLE_TUBES_CHANNEL_GET_PRIVATE (self);
+ TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (
+ (TpBaseConnection *) priv->conn, TP_HANDLE_TYPE_CONTACT);
g_free (priv->object_path);
+ if (priv->initiator != 0)
+ tp_handle_unref (contact_handles, priv->initiator);
+
G_OBJECT_CLASS (gabble_tubes_channel_parent_class)->finalize (object);
}
--
1.5.6.3
More information about the Telepathy-commits
mailing list