Ejemplo n.º 1
0
void
e_composer_load_snapshot (EShell *shell,
                          GFile *snapshot_file,
                          GCancellable *cancellable,
                          GAsyncReadyCallback callback,
                          gpointer user_data)
{
	GSimpleAsyncResult *simple;
	LoadContext *context;

	g_return_if_fail (E_IS_SHELL (shell));
	g_return_if_fail (G_IS_FILE (snapshot_file));

	context = g_slice_new0 (LoadContext);

	simple = g_simple_async_result_new (
		G_OBJECT (shell), callback, user_data,
		e_composer_load_snapshot);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_set_op_res_gpointer (
		simple, context, (GDestroyNotify) load_context_free);

	g_file_load_contents_async (
		snapshot_file, cancellable, (GAsyncReadyCallback)
		load_snapshot_loaded_cb, simple);
}
Ejemplo n.º 2
0
void
e_reap_trash_directory (GFile *trash_directory,
                        gint expiry_in_days,
                        gint io_priority,
                        GCancellable *cancellable,
                        GAsyncReadyCallback callback,
                        gpointer user_data)
{
	GSimpleAsyncResult *simple;

	g_return_if_fail (G_IS_FILE (trash_directory));
	g_return_if_fail (expiry_in_days > 0);

	simple = g_simple_async_result_new (
		G_OBJECT (trash_directory), callback,
		user_data, e_reap_trash_directory);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_set_op_res_gssize (simple, expiry_in_days);

	g_simple_async_result_run_in_thread (
		simple, reap_trash_directory_thread,
		io_priority, cancellable);

	g_object_unref (simple);
}
Ejemplo n.º 3
0
void
e_mail_store_create_folder (CamelStore *store,
                            const gchar *full_name,
                            gint io_priority,
                            GCancellable *cancellable,
                            GAsyncReadyCallback callback,
                            gpointer user_data)
{
	GSimpleAsyncResult *simple;
	AsyncContext *context;

	g_return_if_fail (CAMEL_IS_STORE (store));
	g_return_if_fail (full_name != NULL);

	context = g_slice_new0 (AsyncContext);
	context->full_name = g_strdup (full_name);

	simple = g_simple_async_result_new (
		G_OBJECT (store), callback, user_data,
		e_mail_store_create_folder);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_set_op_res_gpointer (
		simple, context, (GDestroyNotify) async_context_free);

	g_simple_async_result_run_in_thread (
		simple, mail_store_create_folder_thread,
		io_priority, cancellable);

	g_object_unref (simple);
}
Ejemplo n.º 4
0
void
e_mail_session_handle_source_headers (EMailSession *session,
                                      CamelMimeMessage *message,
                                      gint io_priority,
                                      GCancellable *cancellable,
                                      GAsyncReadyCallback callback,
                                      gpointer user_data)
{
	GSimpleAsyncResult *simple;
	AsyncContext *context;

	g_return_if_fail (E_IS_MAIL_SESSION (session));
	g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));

	context = g_slice_new0 (AsyncContext);
	context->message = g_object_ref (message);

	simple = g_simple_async_result_new (
		G_OBJECT (session), callback, user_data,
		e_mail_session_handle_source_headers);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_set_op_res_gpointer (
		simple, context, (GDestroyNotify) async_context_free);

	g_simple_async_result_run_in_thread (
		simple, (GSimpleAsyncThreadFunc)
		mail_session_handle_source_headers_thread,
		io_priority, cancellable);

	g_object_unref (simple);
}
Ejemplo n.º 5
0
static void hev_serial_port_write_async(HevSerialPort *self, const gpointer buffer, gsize count,
			GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
{
	HevSerialPortPrivate *priv = NULL;
	GSimpleAsyncResult *simple = NULL;
	HevSerialPortReadWriteData *data = NULL;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	g_return_if_fail(HEV_IS_SERIAL_PORT(self));
	priv = HEV_SERIAL_PORT_GET_PRIVATE(self);

	/* Simple async result */
	simple = g_simple_async_result_new(G_OBJECT(self),
				callback, user_data, hev_serial_port_write_async);
	g_simple_async_result_set_check_cancellable(simple, cancellable);

	/* ReadWrite data */
	data = g_malloc0(sizeof(HevSerialPortReadWriteData));
	data->buffer = buffer;
	data->count = count;
	g_simple_async_result_set_op_res_gpointer(simple, data, NULL);

	g_simple_async_result_run_in_thread(simple, g_simple_async_write_thread_handler,
				G_PRIORITY_DEFAULT, cancellable);

	g_object_unref(simple);
}
Ejemplo n.º 6
0
void
pp_samba_get_devices_async (PpSamba             *samba,
                            gboolean             auth_if_needed,
                            GCancellable        *cancellable,
                            GAsyncReadyCallback  callback,
                            gpointer             user_data)
{
  GSimpleAsyncResult *res;
  SMBData            *data;
  gchar              *hostname = NULL;

  g_object_get (G_OBJECT (samba), "hostname", &hostname, NULL);

  res = g_simple_async_result_new (G_OBJECT (samba), callback, user_data, pp_samba_get_devices_async);
  data = g_new0 (SMBData, 1);
  data->devices = NULL;
  data->context = g_main_context_default ();
  data->hostname_set = hostname != NULL;
  data->auth_if_needed = auth_if_needed;

  g_simple_async_result_set_check_cancellable (res, cancellable);
  g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) smb_data_free);
  g_simple_async_result_run_in_thread (res, _pp_samba_get_devices_thread, 0, cancellable);

  g_free (hostname);
  g_object_unref (res);
}
Ejemplo n.º 7
0
void hev_serial_port_config_async(HevSerialPort *self, struct termios *options,
			GCancellable *cancellable, GAsyncReadyCallback callback,
			gpointer user_data)
{
	HevSerialPortPrivate *priv = NULL;
	GSimpleAsyncResult *simple = NULL;
	struct termios *opts = NULL;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	g_return_if_fail(HEV_IS_SERIAL_PORT(self));
	g_return_if_fail(NULL != options);
	priv = HEV_SERIAL_PORT_GET_PRIVATE(self);

	/* Simple async result */
	simple = g_simple_async_result_new(G_OBJECT(self),
				callback, user_data, hev_serial_port_config_async);
	g_simple_async_result_set_check_cancellable(simple, cancellable);

	opts = g_malloc0(sizeof(struct termios));
	g_memmove(opts, options, sizeof(struct termios));
	g_simple_async_result_set_op_res_gpointer(simple, opts, NULL);

	g_simple_async_result_run_in_thread(simple, g_simple_async_config_thread_handler,
				G_PRIORITY_DEFAULT, cancellable);

	g_object_unref(simple);
}
Ejemplo n.º 8
0
/**
 * g_dbus_address_get_stream:
 * @address: A valid D-Bus address.
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 * @callback: A #GAsyncReadyCallback to call when the request is satisfied.
 * @user_data: Data to pass to @callback.
 *
 * Asynchronously connects to an endpoint specified by @address and
 * sets up the connection so it is in a state to run the client-side
 * of the D-Bus authentication conversation.
 *
 * When the operation is finished, @callback will be invoked. You can
 * then call g_dbus_address_get_stream_finish() to get the result of
 * the operation.
 *
 * This is an asynchronous failable function. See
 * g_dbus_address_get_stream_sync() for the synchronous version.
 *
 * Since: 2.26
 */
void
g_dbus_address_get_stream (const gchar         *address,
                           GCancellable        *cancellable,
                           GAsyncReadyCallback  callback,
                           gpointer             user_data)
{
  GSimpleAsyncResult *res;
  GetStreamData *data;

  g_return_if_fail (address != NULL);

  res = g_simple_async_result_new (NULL,
                                   callback,
                                   user_data,
                                   g_dbus_address_get_stream);
  g_simple_async_result_set_check_cancellable (res, cancellable);
  data = g_new0 (GetStreamData, 1);
  data->address = g_strdup (address);
  g_simple_async_result_set_op_res_gpointer (res,
                                             data,
                                             (GDestroyNotify) get_stream_data_free);
  g_simple_async_result_run_in_thread (res,
                                       get_stream_thread_func,
                                       G_PRIORITY_DEFAULT,
                                       cancellable);
  g_object_unref (res);
}
void
goa_http_client_check (GoaHttpClient       *self,
                       const gchar         *uri,
                       const gchar         *username,
                       const gchar         *password,
                       gboolean             accept_ssl_errors,
                       GCancellable        *cancellable,
                       GAsyncReadyCallback  callback,
                       gpointer             user_data)
{
  CheckData *data;
  CheckAuthData *auth;
  SoupLogger *logger;

  g_return_if_fail (GOA_IS_HTTP_CLIENT (self));
  g_return_if_fail (uri != NULL && uri[0] != '\0');
  g_return_if_fail (username != NULL && username[0] != '\0');
  g_return_if_fail (password != NULL && password[0] != '\0');
  g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));

  data = g_slice_new0 (CheckData);
  data->res = g_simple_async_result_new (G_OBJECT (self), callback, user_data, goa_http_client_check);
  data->session = soup_session_new_with_options (SOUP_SESSION_SSL_STRICT, FALSE,
                                                 NULL);

  logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1);
  soup_logger_set_printer (logger, http_client_log_printer, NULL, NULL);
  soup_session_add_feature (data->session, SOUP_SESSION_FEATURE (logger));
  g_object_unref (logger);

  data->accept_ssl_errors = accept_ssl_errors;

  data->msg = soup_message_new (SOUP_METHOD_GET, uri);
  soup_message_headers_append (data->msg->request_headers, "Connection", "close");

  if (cancellable != NULL)
    {
      data->cancellable = g_object_ref (cancellable);
      data->cancellable_id = g_cancellable_connect (data->cancellable,
                                                    G_CALLBACK (http_client_check_cancelled_cb),
                                                    data,
                                                    NULL);
      g_simple_async_result_set_check_cancellable (data->res, data->cancellable);
    }

  auth = g_slice_new0 (CheckAuthData);
  auth->username = g_strdup (username);
  auth->password = g_strdup (password);
  g_signal_connect_data (data->session,
                         "authenticate",
                         G_CALLBACK (http_client_authenticate),
                         auth,
                         http_client_check_auth_data_free,
                         0);

  g_signal_connect (data->session, "request-started", G_CALLBACK (http_client_request_started), data);
  soup_session_queue_message (data->session, data->msg, http_client_check_response_cb, data);
}
Ejemplo n.º 10
0
/**
 * push_c2dm_client_deliver_async:
 * @client: A #PushC2dmClient.
 * @identity: A #PushC2dmIdentity.
 * @message: A #PushC2dmMessage.
 * @cancellable: (allow-none): A #GCancellable, or %NULL.
 * @callback: A callback to execute upon completion.
 * @user_data: User data for @callback.
 *
 * Requests that @message is pushed to the device identified by @identity.
 * Upon completion, @callback will be executed and is expected to call
 * push_c2dm_client_deliver_finish() to retrieve the result.
 */
void
push_c2dm_client_deliver_async (PushC2dmClient      *client,
                                PushC2dmIdentity    *identity,
                                PushC2dmMessage     *message,
                                GCancellable        *cancellable,
                                GAsyncReadyCallback  callback,
                                gpointer             user_data)
{
   PushC2dmClientPrivate *priv;
   GSimpleAsyncResult *simple;
   const gchar *auth_header;
   const gchar *registration_id;
   SoupMessage *request;
   GHashTable *params;

   ENTRY;

   g_return_if_fail(PUSH_IS_C2DM_CLIENT(client));
   g_return_if_fail(PUSH_IS_C2DM_IDENTITY(identity));
   g_return_if_fail(PUSH_IS_C2DM_MESSAGE(message));
   g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable));
   g_return_if_fail(callback);

   priv = client->priv;

   registration_id = push_c2dm_identity_get_registration_id(identity);
   params = push_c2dm_message_build_params(message);
   g_hash_table_insert(params,
                       g_strdup("registration_id"),
                       g_strdup(registration_id));
   request = soup_form_request_new_from_hash(SOUP_METHOD_POST,
                                             PUSH_C2DM_CLIENT_URL,
                                             params);
   auth_header = g_strdup_printf("GoogleLogin auth=%s", priv->auth_token);
   soup_message_headers_append(request->request_headers,
                               "Authorization",
                               auth_header);
   simple = g_simple_async_result_new(G_OBJECT(client), callback, user_data,
                                      push_c2dm_client_deliver_async);
   g_simple_async_result_set_check_cancellable(simple, cancellable);
   g_object_set_data_full(G_OBJECT(simple), "registration-id",
                          g_strdup(registration_id), g_free);
   soup_session_queue_message(SOUP_SESSION(client),
                              request,
                              push_c2dm_client_message_cb,
                              simple);
   g_hash_table_unref(params);

   EXIT;
}
void
pp_maintenance_command_execute_async (PpMaintenanceCommand *command,
                                      GCancellable         *cancellable,
                                      GAsyncReadyCallback   callback,
                                      gpointer              user_data)
{
  GSimpleAsyncResult *res;

  res = g_simple_async_result_new (G_OBJECT (command), callback, user_data, pp_maintenance_command_execute_async);

  g_simple_async_result_set_check_cancellable (res, cancellable);
  g_simple_async_result_run_in_thread (res, _pp_maintenance_command_execute_thread, 0, cancellable);

  g_object_unref (res);
}
Ejemplo n.º 12
0
void
e_composer_save_snapshot (EMsgComposer *composer,
                          GCancellable *cancellable,
                          GAsyncReadyCallback callback,
                          gpointer user_data)
{
	GSimpleAsyncResult *simple;
	SaveContext *context;
	GFile *snapshot_file;
	GError *local_error = NULL;

	g_return_if_fail (E_IS_MSG_COMPOSER (composer));

	context = g_slice_new0 (SaveContext);

	if (G_IS_CANCELLABLE (cancellable))
		context->cancellable = g_object_ref (cancellable);

	simple = g_simple_async_result_new (
		G_OBJECT (composer), callback, user_data,
		e_composer_save_snapshot);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_set_op_res_gpointer (
		simple, context, (GDestroyNotify) save_context_free);

	snapshot_file = e_composer_get_snapshot_file (composer);

	if (!G_IS_FILE (snapshot_file))
		snapshot_file = create_snapshot_file (composer, &local_error);

	if (local_error != NULL) {
		g_warn_if_fail (snapshot_file == NULL);
		g_simple_async_result_take_error (simple, local_error);
		g_simple_async_result_complete (simple);
		g_object_unref (simple);
		return;
	}

	g_return_if_fail (G_IS_FILE (snapshot_file));

	g_file_replace_async (
		snapshot_file, NULL, FALSE,
		G_FILE_CREATE_PRIVATE, G_PRIORITY_DEFAULT,
		context->cancellable, (GAsyncReadyCallback)
		save_snapshot_replace_cb, simple);
}
Ejemplo n.º 13
0
void
mongo_cursor_count_async (MongoCursor         *cursor,
                          GCancellable        *cancellable,
                          GAsyncReadyCallback  callback,
                          gpointer             user_data)
{
   MongoCursorPrivate *priv;
   GSimpleAsyncResult *simple;
   MongoBson *command;

   ENTRY;

   g_return_if_fail(MONGO_IS_CURSOR(cursor));
   g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable));
   g_return_if_fail(callback);

   priv = cursor->priv;

   if (!priv->connection) {
      g_simple_async_report_error_in_idle(G_OBJECT(cursor),
                                          callback,
                                          user_data,
                                          MONGO_CONNECTION_ERROR,
                                          MONGO_CONNECTION_ERROR_NOT_CONNECTED,
                                          _("Cursor is missing MongoConnection."));
      EXIT;
   }

   simple = g_simple_async_result_new(G_OBJECT(cursor), callback, user_data,
                                      mongo_cursor_count_async);
   g_simple_async_result_set_check_cancellable(simple, cancellable);

   command = mongo_bson_new_empty();
   mongo_bson_append_string(command, "count", priv->collection);
   if (priv->query) {
      mongo_bson_append_bson(command, "query", priv->query);
   }
   mongo_connection_command_async(priv->connection,
                                  priv->database,
                                  command,
                                  cancellable,
                                  mongo_cursor_count_cb,
                                  simple);
   mongo_bson_unref(command);

   EXIT;
}
Ejemplo n.º 14
0
static void
mail_config_page_submit (EMailConfigPage *page,
                         GCancellable *cancellable,
                         GAsyncReadyCallback callback,
                         gpointer user_data)
{
	GSimpleAsyncResult *simple;

	simple = g_simple_async_result_new (
		G_OBJECT (page), callback,
		user_data, mail_config_page_submit);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_complete_in_idle (simple);

	g_object_unref (simple);
}
Ejemplo n.º 15
0
static void
hev_iobj_async_initable_init_async (GAsyncInitable *initable,
			gint io_priority, GCancellable *cancellable,
			GAsyncReadyCallback callback, gpointer user_data)
{
	HevIObj *self = HEV_IOBJ (initable);
	HevIObjPrivate *priv = HEV_IOBJ_GET_PRIVATE (self);
	GSimpleAsyncResult *simple = NULL;

	g_debug ("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);
	
	simple = g_simple_async_result_new (G_OBJECT(initable),
				callback, user_data, hev_iobj_async_initable_init_async);
	g_simple_async_result_set_check_cancellable (simple, cancellable);
	g_simple_async_result_run_in_thread (simple,
				async_result_run_in_thread_handler,
				io_priority, cancellable);
	g_object_unref (simple);
}
Ejemplo n.º 16
0
void
pp_host_get_remote_cups_devices_async (PpHost              *host,
                                       GCancellable        *cancellable,
                                       GAsyncReadyCallback  callback,
                                       gpointer             user_data)
{
  GSimpleAsyncResult *res;
  GSDData            *data;

  res = g_simple_async_result_new (G_OBJECT (host), callback, user_data, pp_host_get_remote_cups_devices_async);
  data = g_new0 (GSDData, 1);
  data->devices = NULL;

  g_simple_async_result_set_check_cancellable (res, cancellable);
  g_simple_async_result_set_op_res_gpointer (res, data, (GDestroyNotify) gsd_data_free);
  g_simple_async_result_run_in_thread (res, _pp_host_get_remote_cups_devices_thread, 0, cancellable);

  g_object_unref (res);
}
Ejemplo n.º 17
0
void hev_serial_port_close_async(HevSerialPort *self,
			GCancellable *cancellable, GAsyncReadyCallback callback,
			gpointer user_data)
{
	HevSerialPortPrivate *priv = NULL;
	GSimpleAsyncResult *simple = NULL;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	g_return_if_fail(HEV_IS_SERIAL_PORT(self));
	priv = HEV_SERIAL_PORT_GET_PRIVATE(self);

	/* Simple async result */
	simple = g_simple_async_result_new(G_OBJECT(self),
				callback, user_data, hev_serial_port_close_async);
	g_simple_async_result_set_check_cancellable(simple, cancellable);

	g_simple_async_result_run_in_thread(simple, g_simple_async_close_thread_handler,
				G_PRIORITY_DEFAULT, cancellable);

	g_object_unref(simple);
}
Ejemplo n.º 18
0
void
e_mail_session_append_to_local_folder (EMailSession *session,
                                       EMailLocalFolder local_id,
                                       CamelMimeMessage *message,
                                       CamelMessageInfo *info,
                                       gint io_priority,
                                       GCancellable *cancellable,
                                       GAsyncReadyCallback callback,
                                       gpointer user_data)
{
	GSimpleAsyncResult *simple;
	AsyncContext *context;

	g_return_if_fail (E_IS_MAIL_SESSION (session));
	g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));

	context = g_slice_new0 (AsyncContext);
	context->local_id = local_id;
	context->message = g_object_ref (message);

	if (info != NULL)
		context->info = camel_message_info_ref (info);

	simple = g_simple_async_result_new (
		G_OBJECT (session), callback, user_data,
		e_mail_session_append_to_local_folder);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_set_op_res_gpointer (
		simple, context, (GDestroyNotify) async_context_free);

	g_simple_async_result_run_in_thread (
		simple, mail_session_append_to_local_folder_thread,
		io_priority, cancellable);

	g_object_unref (simple);
}
Ejemplo n.º 19
0
void hev_serial_port_queue_command_async(HevSerialPort *self, GByteArray *command,
			HevSerialPortReadSizeCallback read_callback, GCancellable *cancellable,
			GAsyncReadyCallback callback, gpointer user_data)
{
	HevSerialPortPrivate *priv = NULL;
	GSimpleAsyncResult *simple = NULL;
	HevSerialPortQueueCommandData *data = NULL;
	gboolean empty = FALSE;

	g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__);

	g_return_if_fail(HEV_IS_SERIAL_PORT(self));
	g_return_if_fail(NULL != command);
	g_return_if_fail(NULL != read_callback);
	priv = HEV_SERIAL_PORT_GET_PRIVATE(self);

	/* Queue is empty */
	empty = g_queue_is_empty(priv->queue);
	
	/* Simple async result */
	simple = g_simple_async_result_new(G_OBJECT(self),
				callback, user_data, hev_serial_port_queue_command_async);
	g_simple_async_result_set_check_cancellable(simple, cancellable);

	/* Queue command data */
	data = g_malloc0(sizeof(HevSerialPortQueueCommandData));
	data->command = g_byte_array_ref(command);
	data->read_callback = read_callback;
	data->cancellable = cancellable;
	data->user_data = user_data;
	g_simple_async_result_set_op_res_gpointer(simple, data, NULL);

	/* Push head */
	g_queue_push_head(priv->queue, simple);

	if(empty)
	  hev_serial_port_queue_command_handler(self);
}
Ejemplo n.º 20
0
void
e_mail_store_prepare_for_offline (CamelStore *store,
                                  gint io_priority,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,
                                  gpointer user_data)
{
	GSimpleAsyncResult *simple;

	g_return_if_fail (CAMEL_IS_STORE (store));

	simple = g_simple_async_result_new (
		G_OBJECT (store), callback, user_data,
		e_mail_store_prepare_for_offline);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_run_in_thread (
		simple, mail_store_prepare_for_offline_thread,
		io_priority, cancellable);

	g_object_unref (simple);
}
Ejemplo n.º 21
0
void
mongo_cursor_foreach_async (MongoCursor         *cursor,
                            MongoCursorCallback  foreach_func,
                            gpointer             foreach_data,
                            GDestroyNotify       foreach_notify,
                            GCancellable        *cancellable,
                            GAsyncReadyCallback  callback,
                            gpointer             user_data)
{
   MongoCursorPrivate *priv;
   GSimpleAsyncResult *simple;
   gchar *db_and_collection;

   ENTRY;

   g_return_if_fail(MONGO_IS_CURSOR(cursor));
   g_return_if_fail(foreach_func);
   g_return_if_fail(!cancellable || G_IS_CANCELLABLE(cancellable));
   g_return_if_fail(callback);

   priv = cursor->priv;

   if (!priv->connection) {
      g_simple_async_report_error_in_idle(G_OBJECT(cursor),
                                          callback,
                                          user_data,
                                          MONGO_CONNECTION_ERROR,
                                          MONGO_CONNECTION_ERROR_NOT_CONNECTED,
                                          _("Not currently connected."));
      GOTO(failure);
   }

   simple = g_simple_async_result_new(G_OBJECT(cursor),
                                      callback,
                                      user_data,
                                      mongo_cursor_foreach_async);
   g_simple_async_result_set_check_cancellable(simple, cancellable);
   if (cancellable) {
      g_object_set_data_full(G_OBJECT(simple), "cancellable",
                             cancellable, (GDestroyNotify)g_object_unref);
   }
   g_object_set_data(G_OBJECT(simple), "foreach-func", foreach_func);
   if (foreach_notify) {
      g_object_set_data_full(G_OBJECT(simple), "foreach-data",
                             foreach_data, foreach_notify);
   } else {
      g_object_set_data(G_OBJECT(simple), "foreach-data", foreach_data);
   }

   db_and_collection = g_strdup_printf("%s.%s",
                                       priv->database,
                                       priv->collection);

   mongo_connection_query_async(priv->connection,
                                db_and_collection,
                                priv->flags,
                                priv->skip,
                                priv->limit,
                                priv->query,
                                priv->fields,
                                cancellable,
                                mongo_cursor_foreach_query_cb,
                                simple);

   g_free(db_and_collection);

failure:

   EXIT;
}
Ejemplo n.º 22
0
void
e_mail_session_send_to (EMailSession *session,
                        CamelMimeMessage *message,
                        gint io_priority,
                        GCancellable *cancellable,
                        CamelFilterGetFolderFunc get_folder_func,
                        gpointer get_folder_data,
                        GAsyncReadyCallback callback,
                        gpointer user_data)
{
	GSimpleAsyncResult *simple;
	AsyncContext *context;
	CamelAddress *from;
	CamelAddress *recipients;
	CamelMedium *medium;
	CamelMessageInfo *info;
	CamelService *transport;
	GPtrArray *post_to_uris;
	struct _camel_header_raw *xev;
	struct _camel_header_raw *header;
	const gchar *resent_from;
	GError *error = NULL;

	g_return_if_fail (E_IS_MAIL_SESSION (session));
	g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));

	medium = CAMEL_MEDIUM (message);

	camel_medium_set_header (medium, "X-Mailer", X_MAILER);

	/* Do this before removing "X-Evolution" headers. */
	transport = e_mail_session_ref_transport_for_message (
		session, message);

	xev = mail_tool_remove_xevolution_headers (message);

	/* Extract directives from X-Evolution headers. */

	post_to_uris = g_ptr_array_new ();
	for (header = xev; header != NULL; header = header->next) {
		gchar *folder_uri;

		if (g_strcmp0 (header->name, "X-Evolution-PostTo") != 0)
			continue;

		folder_uri = g_strstrip (g_strdup (header->value));
		g_ptr_array_add (post_to_uris, folder_uri);
	}

	/* Collect sender and recipients from headers. */

	from = (CamelAddress *) camel_internet_address_new ();
	recipients = (CamelAddress *) camel_internet_address_new ();
	resent_from = camel_medium_get_header (medium, "Resent-From");

	if (resent_from != NULL) {
		const CamelInternetAddress *addr;
		const gchar *type;

		camel_address_decode (from, resent_from);

		type = CAMEL_RECIPIENT_TYPE_RESENT_TO;
		addr = camel_mime_message_get_recipients (message, type);
		camel_address_cat (recipients, CAMEL_ADDRESS (addr));

		type = CAMEL_RECIPIENT_TYPE_RESENT_CC;
		addr = camel_mime_message_get_recipients (message, type);
		camel_address_cat (recipients, CAMEL_ADDRESS (addr));

		type = CAMEL_RECIPIENT_TYPE_RESENT_BCC;
		addr = camel_mime_message_get_recipients (message, type);
		camel_address_cat (recipients, CAMEL_ADDRESS (addr));

	} else {
		const CamelInternetAddress *addr;
		const gchar *type;

		addr = camel_mime_message_get_from (message);
		camel_address_copy (from, CAMEL_ADDRESS (addr));

		type = CAMEL_RECIPIENT_TYPE_TO;
		addr = camel_mime_message_get_recipients (message, type);
		camel_address_cat (recipients, CAMEL_ADDRESS (addr));

		type = CAMEL_RECIPIENT_TYPE_CC;
		addr = camel_mime_message_get_recipients (message, type);
		camel_address_cat (recipients, CAMEL_ADDRESS (addr));

		type = CAMEL_RECIPIENT_TYPE_BCC;
		addr = camel_mime_message_get_recipients (message, type);
		camel_address_cat (recipients, CAMEL_ADDRESS (addr));
	}

	/* Miscellaneous preparations. */

	info = camel_message_info_new_from_header (
		NULL, CAMEL_MIME_PART (message)->headers);
	((CamelMessageInfoBase *) info)->size =
		get_message_size (message, cancellable);
	camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, ~0);

	/* expand, or remove empty, group addresses */
	em_utils_expand_groups (CAMEL_INTERNET_ADDRESS (recipients));

	/* The rest of the processing happens in a thread. */

	context = g_slice_new0 (AsyncContext);
	context->message = g_object_ref (message);
	context->io_priority = io_priority;
	context->from = from;
	context->recipients = recipients;
	context->info = info;
	context->xev = xev;
	context->post_to_uris = post_to_uris;
	context->transport = transport;

	if (G_IS_CANCELLABLE (cancellable))
		context->cancellable = g_object_ref (cancellable);

	/* Failure here emits a runtime warning but is non-fatal. */
	context->driver = camel_session_get_filter_driver (
		CAMEL_SESSION (session), E_FILTER_SOURCE_OUTGOING, &error);
	if (context->driver != NULL && get_folder_func)
		camel_filter_driver_set_folder_func (
			context->driver, get_folder_func, get_folder_data);
	if (error != NULL) {
		g_warn_if_fail (context->driver == NULL);
		g_warning ("%s", error->message);
		g_error_free (error);
	}

	/* This gets popped in async_context_free(). */
	camel_operation_push_message (
		context->cancellable, _("Sending message"));

	simple = g_simple_async_result_new (
		G_OBJECT (session), callback,
		user_data, e_mail_session_send_to);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_set_op_res_gpointer (
		simple, context, (GDestroyNotify) async_context_free);

	g_simple_async_result_run_in_thread (
		simple, (GSimpleAsyncThreadFunc)
		mail_session_send_to_thread,
		context->io_priority,
		context->cancellable);

	g_object_unref (simple);
}
Ejemplo n.º 23
0
void
goa_ews_autodiscover (GoaObject *goa_object,
                      GCancellable *cancellable,
                      GAsyncReadyCallback callback,
                      gpointer user_data)
{
	GoaAccount *goa_account;
	GoaExchange *goa_exchange;
	GoaPasswordBased *goa_password;
	GSimpleAsyncResult *simple;
	AutodiscoverData *data;
	AutodiscoverAuthData *auth;
	gchar *url1;
	gchar *url2;
	xmlDoc *doc;
	xmlOutputBuffer *buf;
	gchar *email;
	gchar *host;
	gchar *password = NULL;
	GError *error = NULL;

	g_return_if_fail (GOA_IS_OBJECT (goa_object));

	goa_account = goa_object_get_account (goa_object);
	goa_exchange = goa_object_get_exchange (goa_object);
	goa_password = goa_object_get_password_based (goa_object);

	email = goa_account_dup_presentation_identity (goa_account);
	host = goa_exchange_dup_host (goa_exchange);

	doc = ews_create_autodiscover_xml (email);
	buf = xmlAllocOutputBuffer (NULL);
	xmlNodeDumpOutput (buf, doc, xmlDocGetRootElement (doc), 0, 1, NULL);
	xmlOutputBufferFlush (buf);

	url1 = g_strdup_printf (
		"https://%s/autodiscover/autodiscover.xml", host);
	url2 = g_strdup_printf (
		"https://autodiscover.%s/autodiscover/autodiscover.xml", host);

	g_free (host);
	g_free (email);

	/* http://msdn.microsoft.com/en-us/library/ee332364.aspx says we are
	* supposed to try $domain and then autodiscover.$domain. But some
	* people have broken firewalls on the former which drop packets
	* instead of rejecting connections, and make the request take ages
	* to time out. So run both queries in parallel and let the fastest
	* (successful) one win. */
	data = g_slice_new0 (AutodiscoverData);
	data->buf = buf;
	data->msgs[0] = ews_create_msg_for_url (url1, buf);
	data->msgs[1] = ews_create_msg_for_url (url2, buf);
	data->session = soup_session_async_new_with_options (
		SOUP_SESSION_USE_NTLM, TRUE,
		SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
		SOUP_SESSION_TIMEOUT, 90,
		SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE,
		NULL);
	if (G_IS_CANCELLABLE (cancellable)) {
		data->cancellable = g_object_ref (cancellable);
		data->cancellable_id = g_cancellable_connect (
			data->cancellable,
			G_CALLBACK (ews_autodiscover_cancelled_cb),
			data, NULL);
	}

	simple = g_simple_async_result_new (
		G_OBJECT (goa_object), callback,
		user_data, goa_ews_autodiscover);

	g_simple_async_result_set_check_cancellable (simple, cancellable);

	g_simple_async_result_set_op_res_gpointer (
		simple, data, (GDestroyNotify) ews_autodiscover_data_free);

	goa_password_based_call_get_password_sync (
		goa_password, "", &password, cancellable, &error);

	/* Sanity check */
	g_return_if_fail (
		((password != NULL) && (error == NULL)) ||
		((password == NULL) && (error != NULL)));

	if (error == NULL) {
		gchar *username;

		username = goa_account_dup_identity (goa_account);

		auth = g_slice_new0 (AutodiscoverAuthData);
		auth->username = username;  /* takes ownership */
		auth->password = password;  /* takes ownership */

		g_signal_connect_data (
			data->session, "authenticate",
			G_CALLBACK (ews_authenticate), auth,
			ews_autodiscover_auth_data_free, 0);

		soup_session_queue_message (
			data->session, data->msgs[0],
			ews_autodiscover_response_cb, simple);
		soup_session_queue_message (
			data->session, data->msgs[1],
			ews_autodiscover_response_cb, simple);
	} else {
		g_dbus_error_strip_remote_error (error);
		g_simple_async_result_take_error (simple, error);
		g_simple_async_result_complete_in_idle (simple);
		g_object_unref (simple);
	}

	g_free (url2);
	g_free (url1);
	xmlFreeDoc (doc);

	g_object_unref (goa_account);
	g_object_unref (goa_exchange);
	g_object_unref (goa_password);
}