/**
 * tp_yts_client_request_channel_async:
 * @self: The client object
 * @target_contact: The contact to open the channel to
 * @target_service: The Ytstenut service to open the channel to
 * @request_type: The type of request to send
 * @request_attributes: A table of Ytstenut attributes, or %NULL
 * @request_body: A UTF-8 encoded XML Ytstenut message, or %NULL
 * @cancellable: Used to cancel this operation
 * @callback: Called when the operation completes
 * @user_data: Data to pass to the callback
 *
 * Start an operation to request a new Ytstenut channel.
 *
 * The new channel will have a Ytstenut request message ready to send. The
 * message is assembled from the arguments specified here.
 */
void
tp_yts_client_request_channel_async (TpYtsClient *self,
    TpContact *target_contact,
    const gchar *target_service,
    TpYtsRequestType request_type,
    GHashTable *request_attributes,
    const gchar *request_body,
    GCancellable *cancellable,
    GAsyncReadyCallback callback,
    gpointer user_data)
{
  TpAccountChannelRequest *channel_request;
  GSimpleAsyncResult *res;
  GHashTable *request_properties;
  TpHandle target_handle;

  g_return_if_fail (TP_IS_YTS_CLIENT (self));
  g_return_if_fail (TP_IS_CONTACT (target_contact));
  g_return_if_fail (tp_dbus_check_valid_interface_name (target_service, NULL));

  if (!request_body)
    request_body = "";

  g_return_if_fail (g_utf8_validate (request_body, -1, NULL));

  target_handle = tp_contact_get_handle (target_contact);
  g_return_if_fail (target_handle);

  res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
      tp_yts_client_request_channel_async);

  request_properties = tp_asv_new (
      TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING, TP_YTS_IFACE_CHANNEL,
      TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
      TP_IFACE_CHANNEL ".TargetHandle", G_TYPE_UINT, target_handle,
      TP_YTS_IFACE_CHANNEL ".TargetService", G_TYPE_STRING, target_service,
      TP_YTS_IFACE_CHANNEL ".InitiatorService", G_TYPE_STRING,
          self->priv->service_name,
      TP_YTS_IFACE_CHANNEL ".RequestType", G_TYPE_UINT, request_type,
      TP_YTS_IFACE_CHANNEL ".RequestBody", G_TYPE_STRING, request_body,
      NULL);

  if (request_attributes)
    tp_asv_set_boxed (request_properties,
        TP_YTS_IFACE_CHANNEL ".RequestAttributes",
        TP_HASH_TYPE_STRING_STRING_MAP, request_attributes);

  channel_request = tp_account_channel_request_new (self->priv->account,
      request_properties, 0);

  tp_account_channel_request_create_and_handle_channel_async (channel_request,
      cancellable, on_channel_request_create_and_handle_channel_returned, res);

  g_hash_table_unref (request_properties);
}
Ejemplo n.º 2
0
/*
 * Create a new TpSignalledMessage.
 *
 * Any message-sender and message-sender-id in parts[0] will be ignored
 * completely: the caller is responsible for interpreting those fields
 * and providing a suitable @sender.
 *
 * The message-sender will be removed from the header, and the
 * message-sender-id will be set to match the #TpContact:identifier of @sender.
 *
 * @sender may be %NULL, which means the message wasn't sent by a contact
 * (this could be used for administrative messages from a chatroom or the
 * server) or we have no idea who sent it.
 */
TpMessage *
_tp_signalled_message_new (const GPtrArray *parts,
    TpContact *sender)
{
  TpMessage *self;
  guint i;

  g_return_val_if_fail (parts != NULL, NULL);
  g_return_val_if_fail (parts->len > 0, NULL);
  g_return_val_if_fail (sender == NULL || TP_IS_CONTACT (sender), NULL);

  self = g_object_new (TP_TYPE_SIGNALLED_MESSAGE,
      "sender", sender,
      NULL);

  for (i = 0; i < parts->len; i++)
    {
      /* First part is automatically created */
      if (i != 0)
        tp_message_append_part (self);

      tp_g_hash_table_update (g_ptr_array_index (self->parts, i),
          g_ptr_array_index (parts, i),
          (GBoxedCopyFunc) g_strdup,
          (GBoxedCopyFunc) tp_g_value_slice_dup);
    }

  /* This handle may not be persistent, user should use the TpContact
   * directly */
  tp_message_delete_key (self, 0, "message-sender");

  /* override any message-sender-id that the message might have had */
  if (sender == NULL)
    {
      tp_message_delete_key (self, 0, "message-sender-id");
    }
  else
    {
      tp_message_set_string (self, 0, "message-sender-id",
          tp_contact_get_identifier (sender));
    }

  _tp_message_set_immutable (self);

  return self;
}
Ejemplo n.º 3
0
/**
 * empathy_ft_handler_new_outgoing:
 * @account: the #TpAccount to send @source to
 * @contact: the #TpContact to send @source to
 * @source: the #GFile to send
 * @callback: callback to be called when the handler has been created
 * @user_data: user data to be passed to @callback
 *
 * Triggers the creation of a new #EmpathyFTHandler for an outgoing transfer.
 */
void
empathy_ft_handler_new_outgoing (
    TpAccount *account,
    TpContact *contact,
    GFile *source,
    gint64 action_time,
    EmpathyFTHandlerReadyCallback callback,
    gpointer user_data)
{
  EmpathyFTHandler *handler;
  CallbacksData *data;
  EmpathyFTHandlerPriv *priv;

  DEBUG ("New handler outgoing");

  g_return_if_fail (TP_IS_ACCOUNT (account));
  g_return_if_fail (TP_IS_CONTACT (contact));
  g_return_if_fail (G_IS_FILE (source));

  handler = g_object_new (EMPATHY_TYPE_FT_HANDLER,
      "account", account,
      "contact", contact,
      "gfile", source,
      "user-action-time", action_time,
      NULL);

  priv = handler->priv;

  data = g_slice_new0 (CallbacksData);
  data->callback = callback;
  data->user_data = user_data;
  data->handler = g_object_ref (handler);

  /* start collecting info about the file */
  g_file_query_info_async (priv->gfile,
      G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
      G_FILE_ATTRIBUTE_STANDARD_SIZE ","
      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
      G_FILE_ATTRIBUTE_STANDARD_TYPE ","
      G_FILE_ATTRIBUTE_TIME_MODIFIED,
      G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
      NULL, (GAsyncReadyCallback) ft_handler_gfile_ready_cb, data);
}
void
empathy_share_my_desktop_share_with_contact (EmpathyContact *contact)
{
  TpAccountChannelRequest *req;
  GHashTable *request;
  TpContact *tp_contact;

  tp_contact = empathy_contact_get_tp_contact (contact);

  DEBUG ("Creation of ShareMyDesktop");

  if (!TP_IS_CONTACT (tp_contact))
    {
      DEBUG ("It's not a tp contact");
      return;
    }

  request = tp_asv_new (
      TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
        TP_IFACE_CHANNEL_TYPE_STREAM_TUBE,
      TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
        TP_HANDLE_TYPE_CONTACT,
      TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT,
        tp_contact_get_handle (tp_contact),
      TP_PROP_CHANNEL_TYPE_STREAM_TUBE_SERVICE, G_TYPE_STRING, "rfb",
      NULL);

  req = tp_account_channel_request_new (empathy_contact_get_account (contact),
      request, TP_USER_ACTION_TIME_CURRENT_TIME);

  tp_account_channel_request_create_channel_async (req, NULL, NULL,
      create_tube_channel_cb, NULL);

  g_object_unref (req);
  g_hash_table_unref (request);
}