Example #1
0
static void
location_request_location (
    TpSvcConnectionInterfaceLocation *iface,
    TpHandle handle,
    DBusGMethodInvocation *context)
{
  GabbleConnection *self = GABBLE_CONNECTION (iface);
  TpBaseConnection *base = (TpBaseConnection *) self;
  TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (base,
      TP_HANDLE_TYPE_CONTACT);
  const gchar *jid;
  WockyBareContact *contact;
  YetAnotherContextStruct *ctx;
  GError *error = NULL;

  if (!tp_handle_is_valid (contact_handles, handle, &error))
    {
      dbus_g_method_return_error (context, error);
      g_error_free (error);
      return;
    }

  /* Oh! for GDBus. */
  ctx = g_slice_new (YetAnotherContextStruct);
  ctx->self = g_object_ref (self);
  ctx->handle = handle;
  ctx->context = context;

  jid = tp_handle_inspect (contact_handles, handle);
  contact = ensure_bare_contact_from_jid (self, jid);
  DEBUG ("fetching location for '%s'", jid);
  wocky_pep_service_get_async (self->pep_location, contact, NULL,
      request_location_reply_cb, ctx);
  g_object_unref (contact);
}
Example #2
0
static void
set_aliases (TpSvcConnectionInterfaceAliasing *aliasing,
             GHashTable *aliases,
             DBusGMethodInvocation *context)
{
  ExampleContactListConnection *self =
    EXAMPLE_CONTACT_LIST_CONNECTION (aliasing);
  TpBaseConnection *base = TP_BASE_CONNECTION (aliasing);
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (base,
      TP_HANDLE_TYPE_CONTACT);
  GHashTableIter iter;
  gpointer key, value;

  g_hash_table_iter_init (&iter, aliases);

  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      GError *error = NULL;

      if (!tp_handle_is_valid (contact_repo, GPOINTER_TO_UINT (key),
            &error))
        {
          dbus_g_method_return_error (context, error);
          g_error_free (error);
          return;
        }
    }

  g_hash_table_iter_init (&iter, aliases);

  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      example_contact_list_manager_set_alias (self->priv->list_manager,
          GPOINTER_TO_UINT (key), value);
    }

  tp_svc_connection_interface_aliasing_return_from_set_aliases (context);
}
static gboolean
_im_manager_requestotron (IdleIMManager *self,
						  gpointer request_token,
						  GHashTable *request_properties,
						  gboolean require_new)
{
	IdleIMManagerPrivate *priv = IDLE_IM_MANAGER_GET_PRIVATE (self);
	TpBaseConnection *base_conn = (TpBaseConnection *) priv->conn;
	TpHandleRepoIface *contact_repo =
		tp_base_connection_get_handles (base_conn, TP_HANDLE_TYPE_CONTACT);
	TpHandle handle;
	GError *error = NULL;
	TpExportableChannel *channel;

	if (tp_strdiff (tp_asv_get_string (request_properties,
									   TP_IFACE_CHANNEL ".ChannelType"), TP_IFACE_CHANNEL_TYPE_TEXT))
		return FALSE;

	if (tp_asv_get_uint32 (request_properties,
						   TP_IFACE_CHANNEL ".TargetHandleType", NULL) != TP_HANDLE_TYPE_CONTACT)
		return FALSE;

	handle = tp_asv_get_uint32 (request_properties,
								TP_IFACE_CHANNEL ".TargetHandle", NULL);

	if (!tp_handle_is_valid (contact_repo, handle, &error))
		goto error;

	/* Check if there are any other properties that we don't understand */
	if (tp_channel_manager_asv_has_unknown_properties (request_properties,
													   im_channel_fixed_properties,
													   im_channel_allowed_properties,
													   &error))
	{
		goto error;
	}

	/* Don't support opening a channel to our self handle */
	if (handle == base_conn->self_handle)
	{
		g_set_error (&error, TP_ERROR, TP_ERROR_NOT_IMPLEMENTED,
					 "Can't open a text channel to yourself");
		goto error;
	}

	channel = g_hash_table_lookup (priv->channels, GUINT_TO_POINTER (handle));

	if (channel == NULL)
	{
		_im_manager_new_channel (self, handle, base_conn->self_handle, request_token);
		return TRUE;
	}

	if (require_new)
	{
		g_set_error (&error, TP_ERROR, TP_ERROR_NOT_AVAILABLE,
					 "Already chatting with contact #%u in another channel", handle);
		goto error;
	}

	tp_channel_manager_emit_request_already_satisfied (self, request_token,
													   channel);
	return TRUE;

error:
	tp_channel_manager_emit_request_failed (self, request_token,
											error->domain, error->code, error->message);
	g_error_free (error);
	return TRUE;
}
/**
 * tp_contacts_mixin_get_contact_attributes: (skip)
 * @obj: A connection instance that uses this mixin. The connection must be connected.
 * @handles: List of handles to retrieve contacts for. Any invalid handles will be
 * dropped from the returned mapping.
 * @interfaces: A list of interfaces to retrieve attributes from.
 * @assumed_interfaces: A list of additional interfaces to retrieve attributes
 *  from. This can be used for interfaces documented as automatically included,
 *  like %TP_IFACE_CONNECTION for GetContactAttributes,
 *  or %TP_IFACE_CONNECTION and %TP_IFACE_CONNECTION_INTERFACE_CONTACT_LIST for
 *  GetContactListAttributes.
 * @sender: The DBus client's unique name. If this is not NULL, the requested handles
 * will be held on behalf of this client.
 *
 * Get contact attributes for the given contacts. Provide attributes for all requested
 * interfaces. If contact attributes are not immediately known, the behaviour is defined
 * by the interface; the attribute should either be omitted from the result or replaced
 * with a default value.
 *
 * Returns: A dictionary mapping the contact handles to contact attributes.
 *
 */
GHashTable *
tp_contacts_mixin_get_contact_attributes (GObject *obj,
    const GArray *handles,
    const gchar **interfaces,
    const gchar **assumed_interfaces,
    const gchar *sender)
{
  GHashTable *result;
  guint i;
  TpBaseConnection *conn = TP_BASE_CONNECTION (obj);
  TpContactsMixin *self = TP_CONTACTS_MIXIN (obj);
  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
        TP_HANDLE_TYPE_CONTACT);
  GArray *valid_handles;
  TpContactsMixinFillContactAttributesFunc func;

  g_return_val_if_fail (TP_IS_BASE_CONNECTION (obj), NULL);
  g_return_val_if_fail (TP_CONTACTS_MIXIN_OFFSET (obj) != 0, NULL);
  g_return_val_if_fail (tp_base_connection_check_connected (conn, NULL), NULL);

  /* Setup handle array and hash with valid handles, optionally holding them */
  valid_handles = g_array_sized_new (TRUE, TRUE, sizeof (TpHandle),
      handles->len);
  result = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
      (GDestroyNotify) g_hash_table_unref);

  for (i = 0 ; i < handles->len ; i++)
    {
      TpHandle h;
      h = g_array_index (handles, TpHandle, i);
      if (tp_handle_is_valid (contact_repo, h, NULL))
        {
          GHashTable *attr_hash = g_hash_table_new_full (g_str_hash,
              g_str_equal, g_free, (GDestroyNotify) tp_g_value_slice_free);
          g_array_append_val (valid_handles, h);
          g_hash_table_insert (result, GUINT_TO_POINTER(h), attr_hash);
        }
    }

  for (i = 0; assumed_interfaces != NULL && assumed_interfaces[i] != NULL; i++)
    {
      func = g_hash_table_lookup (self->priv->interfaces, assumed_interfaces[i]);

      if (func == NULL)
        DEBUG ("non-inspectable assumed interface %s given; ignoring",
            assumed_interfaces[i]);
      else
        func (obj, valid_handles, result);
    }

  for (i = 0; interfaces != NULL && interfaces[i] != NULL; i++)
    {

      func = g_hash_table_lookup (self->priv->interfaces, interfaces[i]);

      if (func == NULL)
        DEBUG ("non-inspectable interface %s given; ignoring", interfaces[i]);
      else
        func (obj, valid_handles, result);
    }

  g_array_unref (valid_handles);

  return result;
}