Ejemplo n.º 1
0
void
process_free (ProcessData *process_data)
{
    g_cancellable_disconnect (process_data->cancellable,
                              process_data->cancel_handler);
    g_return_if_fail (process_data != NULL);
    g_clear_error (&process_data->error);
    g_strfreev (process_data->command);
    g_slice_free (ProcessData, process_data);
}
Ejemplo n.º 2
0
static void
source_import_free (gpointer data)
{
    source_import_closure *closure = data;
    g_object_unref (closure->source);
    g_object_unref (closure->input);
    g_cancellable_disconnect (closure->cancellable, closure->cancelled_sig);
    g_clear_object (&closure->cancellable);
    g_object_unref (closure->session);
    g_free (closure);
}
Ejemplo n.º 3
0
static void
source_search_free (gpointer data)
{
    source_search_closure *closure = data;
    g_object_unref (closure->source);
    g_cancellable_disconnect (closure->cancellable, closure->cancelled_sig);
    g_clear_object (&closure->cancellable);
    g_object_unref (closure->session);
    g_clear_object (&closure->results);
    g_free (closure);
}
Ejemplo n.º 4
0
/*
 * SCPD URL downloaded.
 */
static void
got_scpd_url (G_GNUC_UNUSED SoupSession *session,
              SoupMessage               *msg,
              GetSCPDURLData            *data)
{
        GUPnPServiceIntrospection *introspection;
        GError *error;
        GUPnPServiceInfoPrivate *priv;

        introspection = NULL;
        error = NULL;

        if (msg->status_code == SOUP_STATUS_CANCELLED)
                return;

        if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
                xmlDoc *scpd;

                scpd = xmlRecoverMemory (msg->response_body->data,
                                         msg->response_body->length);
                if (scpd) {
                        introspection = gupnp_service_introspection_new (scpd);

                        xmlFreeDoc (scpd);
                }

                if (!introspection) {
                        error = g_error_new
                                        (GUPNP_SERVER_ERROR,
                                         GUPNP_SERVER_ERROR_INVALID_RESPONSE,
                                         "Could not parse SCPD");
                }
        } else
                error = _gupnp_error_new_server_error (msg);

        /* prevent the callback from canceling the cancellable
         * (and so freeing data just before we do) */
        if (data->cancellable)
                g_cancellable_disconnect (data->cancellable,
                                          data->cancelled_id);

        priv = gupnp_service_info_get_instance_private (data->info);
        priv->pending_gets = g_list_remove (priv->pending_gets, data);

        data->callback (data->info,
                        introspection,
                        error,
                        data->user_data);

        if (error)
                g_error_free (error);

        get_scpd_url_data_free (data);
}
Ejemplo n.º 5
0
static void 
fd_source_finalize (GSource *source)
{
  FDSource *fd_source = (FDSource *)source;

  if (fd_source->cancelled_tag)
    g_cancellable_disconnect (fd_source->cancellable,
			      fd_source->cancelled_tag);

  if (fd_source->cancellable)
    g_object_unref (fd_source->cancellable);
}
Ejemplo n.º 6
0
static void
export_closure_free (gpointer data)
{
    ExportClosure *closure = data;
    g_object_unref (closure->source);
    if (closure->data)
        g_string_free (closure->data, TRUE);
    g_cancellable_disconnect (closure->cancellable, closure->cancelled_sig);
    g_clear_object (&closure->cancellable);
    g_object_unref (closure->session);
    g_free (closure);
}
Ejemplo n.º 7
0
static void
cancellable_source_finalize (GSource *source)
{
  GCancellableSource *cancellable_source = (GCancellableSource *)source;

  if (cancellable_source->cancellable)
    {
      g_cancellable_disconnect (cancellable_source->cancellable,
                                cancellable_source->cancelled_handler);
      g_object_unref (cancellable_source->cancellable);
    }
}
static void
auth_request_free (AuthRequest *request)
{
    g_cancellable_disconnect (request->cancellable, request->handler_id);
    g_free (request->action_id);
    g_free (request->message);
    g_free (request->icon_name);
    g_object_unref (request->details);
    g_list_foreach (request->identities, (GFunc) g_object_unref, NULL);
    g_list_free (request->identities);
    g_object_unref (request->simple);
    g_free (request);
}
Ejemplo n.º 9
0
static void
writeback_file_data_free (WritebackFileData *data)
{
	if (data->self) {
		g_object_weak_unref (G_OBJECT (data->self), self_weak_notify, data);
	}

	g_object_unref (data->fs);
	g_object_unref (data->file);
	g_strfreev (data->rdf_types);
	g_ptr_array_unref (data->results);
	g_cancellable_disconnect (data->cancellable, data->cancel_id);
	g_object_unref (data->cancellable);
	g_free (data);
}
Ejemplo n.º 10
0
static void
gth_task_finalize (GObject *object)
{
	GthTask *task;

	task = GTH_TASK (object);

	if (task->priv->cancellable != NULL) {
		g_cancellable_disconnect (task->priv->cancellable, task->priv->cancellable_cancelled);
		g_object_unref (task->priv->cancellable);
	}

	g_free (task->priv->description);

	G_OBJECT_CLASS (gth_task_parent_class)->finalize (object);
}
Ejemplo n.º 11
0
static void
gupnp_service_info_dispose (GObject *object)
{
        GUPnPServiceInfo *info;
        GUPnPServiceInfoPrivate *priv;

        info = GUPNP_SERVICE_INFO (object);
        priv = gupnp_service_info_get_instance_private (info);

        /* Cancel any pending SCPD GETs */
        if (priv->context) {
                SoupSession *session;

                session = gupnp_context_get_session (priv->context);

                while (priv->pending_gets) {
                        GetSCPDURLData *data;

                        data = priv->pending_gets->data;

                        if (data->cancellable)
                                g_cancellable_disconnect (data->cancellable,
                                                          data->cancelled_id);

                        soup_session_cancel_message (session,
                                                     data->message,
                                                     SOUP_STATUS_CANCELLED);

                        get_scpd_url_data_free (data);

                        priv->pending_gets =
                                g_list_delete_link (priv->pending_gets,
                                                    priv->pending_gets);
                }

                /* Unref context */
                g_object_unref (priv->context);
                priv->context = NULL;
        }

        if (priv->doc) {
                g_object_unref (priv->doc);
                priv->doc = NULL;
        }

        G_OBJECT_CLASS (gupnp_service_info_parent_class)->dispose (object);
}
Ejemplo n.º 12
0
static void
at_command_context_free (AtCommandContext *ctx)
{
    mm_serial_port_close (MM_SERIAL_PORT (ctx->port));

    if (ctx->cancelled_id)
        g_cancellable_disconnect (ctx->modem_cancellable,
                                  ctx->cancelled_id);
    if (ctx->user_cancellable)
        g_object_unref (ctx->user_cancellable);
    g_object_unref (ctx->modem_cancellable);
    g_object_unref (ctx->cancellable);

    g_object_unref (ctx->port);
    g_object_unref (ctx->result);
    g_object_unref (ctx->self);
    g_free (ctx);
}
Ejemplo n.º 13
0
static void
ews_autodiscover_data_free (AutodiscoverData *data)
{
	if (data->cancellable_id > 0) {
		g_cancellable_disconnect (
			data->cancellable, data->cancellable_id);
		g_object_unref (data->cancellable);
	}

	/* soup_session_queue_message stole the references to data->msgs */
	xmlOutputBufferClose (data->buf);
	g_object_unref (data->session);

	g_free (data->as_url);
	g_free (data->oab_url);

	g_slice_free (AutodiscoverData, data);
}
Ejemplo n.º 14
0
static void
execute_data_free (ExecuteData *exec_data)
{
	if (exec_data == NULL)
		return;

	if (exec_data->cancel_id != 0)
		g_cancellable_disconnect (exec_data->cancellable, exec_data->cancel_id);

	_g_object_unref (exec_data->process);
	_g_object_unref (exec_data->cancellable);
	_g_object_unref (exec_data->result);
	fr_error_free (exec_data->error);
	fr_error_free (exec_data->first_error);
	_g_string_list_free (exec_data->first_error_stdout);
	_g_string_list_free (exec_data->first_error_stderr);
	g_free (exec_data);
}
Ejemplo n.º 15
0
static void
dispose (GObject *object)
{
    MMBaseModem *self = MM_BASE_MODEM (object);

    /* Cancel all ongoing auth requests */
    g_cancellable_cancel (self->priv->authp_cancellable);
    g_clear_object (&self->priv->authp_cancellable);
    g_clear_object (&self->priv->authp);

    /* Ensure we cancel any ongoing operation, but before
     * disconnect our own signal handler, or we'll end up with
     * another reference of the modem object around. */
    g_cancellable_disconnect (self->priv->cancellable,
                              self->priv->invalid_if_cancelled);
    g_cancellable_cancel (self->priv->cancellable);
    g_clear_object (&self->priv->cancellable);

    g_clear_object (&self->priv->primary);
    g_clear_object (&self->priv->secondary);
    g_list_free_full (self->priv->data, g_object_unref);
    self->priv->data = NULL;
    g_clear_object (&self->priv->qcdm);
    g_clear_object (&self->priv->gps_control);
    g_clear_object (&self->priv->gps);
#if defined WITH_QMI
    /* We need to close the QMI port cleanly when disposing the modem object,
     * otherwise the allocated CIDs will be kept allocated, and if we end up
     * allocating too many newer allocations will fail with client-ids-exhausted
     * errors. */
    g_list_foreach (self->priv->qmi, (GFunc)mm_qmi_port_close, NULL);
    g_list_free_full (self->priv->qmi, g_object_unref);
    self->priv->qmi = NULL;
#endif

    if (self->priv->ports) {
        g_hash_table_destroy (self->priv->ports);
        self->priv->ports = NULL;
    }

    g_clear_object (&self->priv->connection);

    G_OBJECT_CLASS (mm_base_modem_parent_class)->dispose (object);
}
Ejemplo n.º 16
0
void
goa_alarm_set_time (GoaAlarm *self, GDateTime *time, GCancellable *cancellable)
{
  if (g_cancellable_is_cancelled (cancellable))
    return;

  if (self->priv->cancellable != NULL && self->priv->cancellable != cancellable)
    g_cancellable_cancel (self->priv->cancellable);

  if (cancellable != NULL)
    g_object_ref (cancellable);

  if (self->priv->cancelled_id != 0)
    g_cancellable_disconnect (self->priv->cancellable, self->priv->cancelled_id);

  g_clear_object (&self->priv->cancellable);

  if (cancellable != NULL)
    self->priv->cancellable = cancellable;
  else
    self->priv->cancellable = g_cancellable_new ();

  self->priv->cancelled_id = g_cancellable_connect (self->priv->cancellable,
                                                    G_CALLBACK (on_cancelled),
                                                    self, NULL);

  g_date_time_ref (time);

  if (self->priv->time != NULL)
    g_date_time_unref (self->priv->time);

  self->priv->time = time;

  self->priv->context = g_main_context_ref (g_main_context_default ());

  g_object_notify (G_OBJECT (self), "time");

  schedule_wakeups (self);

  /* Wake up right away, in case it's already expired leaving the gate */
  schedule_immediate_wakeup (self);
}
Ejemplo n.º 17
0
static gboolean
http_client_check_data_free (gpointer user_data)
{
  CheckData *data = user_data;

  g_simple_async_result_complete_in_idle (data->res);

  if (data->cancellable_id > 0)
    {
      g_cancellable_disconnect (data->cancellable, data->cancellable_id);
      g_object_unref (data->cancellable);
    }

  /* soup_session_queue_message stole the references to data->msg */
  g_object_unref (data->res);
  g_object_unref (data->session);
  g_slice_free (CheckData, data);

  return G_SOURCE_REMOVE;
}
Ejemplo n.º 18
0
static void
writeback_data_free (WritebackData *data)
{
	/* We rely on data->invocation being freed through
	 * the g_dbus_method_invocation_return_* methods
	 */
	g_cancellable_disconnect (data->cancellable, data->cancel_id);
	g_free (data->subject);
	g_object_unref (data->connection);
	g_ptr_array_unref (data->results);
	g_object_unref (data->cancellable);

	g_list_foreach (data->writeback_handlers, (GFunc) g_object_unref, NULL);
	g_list_free (data->writeback_handlers);

	if (data->error) {
		g_error_free (data->error);
	}
	g_slice_free (WritebackData, data);
}
Ejemplo n.º 19
0
static gboolean
ews_client_autodiscover_data_free (gpointer user_data)
{
  AutodiscoverData *data = user_data;

  g_simple_async_result_complete_in_idle (data->res);

  if (data->cancellable_id > 0)
    {
      g_cancellable_disconnect (data->cancellable, data->cancellable_id);
      g_object_unref (data->cancellable);
    }

  /* soup_session_queue_message stole the references to data->msgs */
  xmlOutputBufferClose (data->buf);
  g_object_unref (data->res);
  g_object_unref (data->session);
  g_slice_free (AutodiscoverData, data);

  return G_SOURCE_REMOVE;
}
Ejemplo n.º 20
0
static gboolean
connect_timed_out_cb (MMBroadbandBearerHso *self)
{
    Dial3gppContext *ctx;

    /* Recover context and remove cancellation */
    ctx = self->priv->connect_pending;

    g_cancellable_disconnect (ctx->cancellable,
                              self->priv->connect_cancellable_id);

    self->priv->connect_pending = NULL;
    self->priv->connect_pending_id = 0;
    self->priv->connect_cancellable_id = 0;

    g_simple_async_result_set_error (ctx->result,
                                     MM_MOBILE_EQUIPMENT_ERROR,
                                     MM_MOBILE_EQUIPMENT_ERROR_NETWORK_TIMEOUT,
                                     "Connection attempt timed out");
    connect_reset (ctx);

    return FALSE;
}
Ejemplo n.º 21
0
static void
g_task_return_error (GTask *task,
					 const GError *error)
{
	/* set result to temp memory location */
	if (task->ret) {
		g_simple_async_result_set_op_res_gpointer (task->res,
							   task->sample,
							   (GDestroyNotify) cd_color_xyz_free);
	} else {
		g_simple_async_result_set_from_error (task->res, error);
	}

	/* deallocate */
	if (g_task_get_cancellable (task) != NULL) {
		g_cancellable_disconnect (g_task_get_cancellable (task), g_task_get_cancellable (task)_id);
		g_object_unref (g_task_get_cancellable (task));
	}

	g_object_unref (task->res);
	g_object_unref (sensor);
	g_slice_free (CdSensorTaskData, task);
}
Ejemplo n.º 22
0
static void
pdf_load_job_free (PdfLoadJob *job)
{
  if (job->cancellable != NULL) {
    g_cancellable_disconnect (job->cancellable, job->cancelled_id);
    job->cancelled_id = 0;
  }

  g_clear_object (&job->document);
  g_clear_object (&job->result);
  g_clear_object (&job->cancellable);
  g_clear_object (&job->stream);
  g_clear_object (&job->download_file);
  g_clear_object (&job->gdata_service);
  g_clear_object (&job->gdata_entry);
  g_clear_object (&job->zpj_service);
  g_clear_object (&job->zpj_entry);

  g_free (job->uri);
  g_free (job->passwd);
  g_free (job->resource_id);

  if (job->pdf_path != NULL) {
    if (job->unlink_cache)
      g_unlink (job->pdf_path);

    g_free (job->pdf_path);
  }

  if (job->unoconv_pid != -1) {
    kill (job->unoconv_pid, SIGKILL);
    job->unoconv_pid = -1;
  }

  g_slice_free (PdfLoadJob, job);
}
Ejemplo n.º 23
0
/* called when we're done running the command line */
static void
udisks_spawned_job_release_resources (UlSpawnedJob *self)
{
  /* Nuke the child, if necessary */
  if (self->child_watch_source != NULL)
    {
      g_source_destroy (self->child_watch_source);
      self->child_watch_source = NULL;
    }

  if (self->child_pid != 0)
    {
      GSource *source;

      g_debug ("ugh, need to kill %d", (gint) self->child_pid);
      kill (self->child_pid, SIGTERM);

      /* OK, we need to reap for the child ourselves - we don't want
       * to use waitpid() because that might block the calling
       * thread (the child might handle SIGTERM and use several
       * seconds for cleanup/rollback).
       *
       * So we use GChildWatch instead.
       *
       * Note that we might be called from the finalizer so avoid
       * taking references to ourselves. We do need to pass the
       * GSource so we can nuke it once handled.
       */
      source = g_child_watch_source_new (self->child_pid);
      g_source_set_callback (source,
                             (GSourceFunc) child_watch_from_release_cb,
                             source,
                             (GDestroyNotify) g_source_destroy);
      g_source_attach (source, self->main_context);
      g_source_unref (source);

      self->child_pid = 0;
    }

  if (self->child_stdout != NULL)
    {
      g_string_free (self->child_stdout, TRUE);
      self->child_stdout = NULL;
    }

  if (self->child_stderr != NULL)
    {
      g_string_free (self->child_stderr, TRUE);
      self->child_stderr = NULL;
    }

  if (self->child_stdin_channel != NULL)
    {
      g_io_channel_unref (self->child_stdin_channel);
      self->child_stdin_channel = NULL;
    }
  if (self->child_stdout_channel != NULL)
    {
      g_io_channel_unref (self->child_stdout_channel);
      self->child_stdout_channel = NULL;
    }
  if (self->child_stderr_channel != NULL)
    {
      g_io_channel_unref (self->child_stderr_channel);
      self->child_stderr_channel = NULL;
    }

  if (self->child_stdin_source != NULL)
    {
      g_source_destroy (self->child_stdin_source);
      self->child_stdin_source = NULL;
    }
  if (self->child_stdout_source != NULL)
    {
      g_source_destroy (self->child_stdout_source);
      self->child_stdout_source = NULL;
    }
  if (self->child_stderr_source != NULL)
    {
      g_source_destroy (self->child_stderr_source);
      self->child_stderr_source = NULL;
    }

  if (self->child_stdin_fd != -1)
    {
      g_warn_if_fail (close (self->child_stdin_fd) == 0);
      self->child_stdin_fd = -1;
    }
  if (self->child_stdout_fd != -1)
    {
      g_warn_if_fail (close (self->child_stdout_fd) == 0);
      self->child_stdout_fd = -1;
    }
  if (self->child_stderr_fd != -1)
    {
      g_warn_if_fail (close (self->child_stderr_fd) == 0);
      self->child_stderr_fd = -1;
    }

  if (self->cancellable_handler_id > 0)
    {
      g_cancellable_disconnect (ul_job_get_cancellable (UL_JOB (self)),
                                self->cancellable_handler_id);
      self->cancellable_handler_id = 0;
    }
}
Ejemplo n.º 24
0
static gssize
nice_output_stream_write (GOutputStream *stream, const void *buffer, gsize count,
    GCancellable *cancellable, GError **error)
{
  NiceOutputStream *self = NICE_OUTPUT_STREAM (stream);
  const gchar* buf = buffer;
  gssize len = 0;
  gint n_sent;
  NiceAgent *agent = NULL;  /* owned */
  gulong cancel_id = 0, closed_cancel_id, writeable_id;
  WriteData *write_data;

  /* Closed streams are not writeable. */
  if (g_output_stream_is_closed (stream)) {
    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CLOSED,
        "Stream is closed.");
    return -1;
  }

  /* Has the agent disappeared? */
  agent = g_weak_ref_get (&self->priv->agent_ref);
  if (agent == NULL) {
    g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CLOSED,
        "Stream is closed due to the NiceAgent being finalised.");
    return -1;
  }

  if (count == 0) {
    g_object_unref (agent);
    return 0;
  }

  /* FIXME: nice_agent_send() is non-blocking, which is a bit unexpected
   * since nice_agent_recv() is blocking. Currently this uses a fairly dodgy
   * GCond solution; would be much better for nice_agent_send() to block
   * properly in the main loop. */
  write_data = g_slice_new0 (WriteData);
  write_data->ref_count = 1;
  g_mutex_init (&write_data->mutex);
  g_cond_init (&write_data->cond);

  if (cancellable != NULL) {
    cancel_id = g_cancellable_connect (cancellable,
        (GCallback) write_cancelled_cb, write_data_ref (write_data),
        (GDestroyNotify) write_data_unref);
  }

  closed_cancel_id = g_cancellable_connect (self->priv->closed_cancellable,
      (GCallback) write_cancelled_cb, write_data_ref (write_data),
      (GDestroyNotify) write_data_unref);

  g_mutex_lock (&write_data->mutex);

  writeable_id = g_signal_connect_data (G_OBJECT (agent),
      "reliable-transport-writable",
      (GCallback) reliable_transport_writeable_cb, write_data_ref (write_data),
      (GClosureNotify) write_data_unref, 0);


  do {
    /* Have to unlock while calling into the agent because
     * it will take the agent lock which will cause a deadlock if one of
     * the callbacks is called.
     */
    if (g_cancellable_is_cancelled (cancellable) ||
        g_cancellable_is_cancelled (self->priv->closed_cancellable))
      break;

    write_data->writable = FALSE;
    g_mutex_unlock (&write_data->mutex);

    n_sent = nice_agent_send (agent, self->priv->stream_id,
        self->priv->component_id, count - len, buf + len);

    g_mutex_lock (&write_data->mutex);

    if (n_sent <= 0) {
      if (!write_data->writable && !write_data->cancelled)
        g_cond_wait (&write_data->cond, &write_data->mutex);
    } else if (n_sent > 0) {
      /* Success. */
      len += n_sent;
    }
  } while ((gsize) len < count);

  g_signal_handler_disconnect (G_OBJECT (agent), writeable_id);
  g_mutex_unlock (&write_data->mutex);

  if (cancel_id)
    g_cancellable_disconnect (cancellable, cancel_id);
  g_cancellable_disconnect (self->priv->closed_cancellable, closed_cancel_id);

  if (len == 0) {
    len = -1;
    if (!g_cancellable_set_error_if_cancelled (cancellable, error)) {
      if (g_cancellable_is_cancelled (self->priv->closed_cancellable))
        g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_CLOSED,
            "Stream has been removed from agent");
    }
  }

  write_data_unref (write_data);

  g_object_unref (agent);
  g_assert (len != 0);

  return len;
}
static gboolean
watch_one_event_from_driver (GsdSmartcardManager       *self,
                             WatchSmartcardsOperation  *operation,
                             GCancellable              *cancellable,
                             GError                   **error)
{
        GsdSmartcardManagerPrivate *priv = self->priv;
        PK11SlotInfo *card, *old_card;
        CK_SLOT_ID slot_id;
        gulong handler_id;
        int old_slot_series = -1, slot_series;

        handler_id = g_cancellable_connect (cancellable,
                                            G_CALLBACK (on_watch_cancelled),
                                            operation,
                                            NULL);

        card = SECMOD_WaitForAnyTokenEvent (operation->driver, 0, PR_SecondsToInterval (1));

        g_cancellable_disconnect (cancellable, handler_id);

        if (g_cancellable_set_error_if_cancelled (cancellable, error)) {
                g_warning ("smartcard event function cancelled");
                return FALSE;
        }

        if (card == NULL) {
                int error_code;

                error_code = PORT_GetError ();

                operation->number_of_consecutive_errors++;
                if (operation->number_of_consecutive_errors > 10) {
                     g_warning ("Got %d consecutive smartcard errors, so giving up.",
                                operation->number_of_consecutive_errors);

                     g_set_error (error,
                                  GSD_SMARTCARD_MANAGER_ERROR,
                                  GSD_SMARTCARD_MANAGER_ERROR_WITH_NSS,
                                  "encountered unexpected error while "
                                  "waiting for smartcard events (error %x)",
                                  error_code);
                     return FALSE;
                }

                g_warning ("Got potentially spurious smartcard event error: %x.", error_code);

                g_usleep (0.5 * G_USEC_PER_SEC);
                return TRUE;
        }
        operation->number_of_consecutive_errors = 0;

        slot_id = PK11_GetSlotID (card);
        slot_series = PK11_GetSlotSeries (card);

        old_card = g_hash_table_lookup (operation->smartcards, GINT_TO_POINTER ((int) slot_id));

        /* If there is a different card in the slot now than
         * there was before, then we need to emit a removed signal
         * for the old card
         */
        if (old_card != NULL) {
                old_slot_series = PK11_GetSlotSeries (old_card);

                if (old_slot_series != slot_series) {
                        /* Card registered with slot previously is
                         * different than this card, so update its
                         * exported state to track the implicit missed
                         * removal
                         */
                        gsd_smartcard_service_sync_token (priv->service, old_card, cancellable);
                }

                g_hash_table_remove (operation->smartcards, GINT_TO_POINTER ((int) slot_id));
        }

        if (PK11_IsPresent (card)) {
                g_debug ("Detected smartcard insertion event in slot %d", (int) slot_id);

                g_hash_table_replace (operation->smartcards,
                                      GINT_TO_POINTER ((int) slot_id),
                                      PK11_ReferenceSlot (card));

                gsd_smartcard_service_sync_token (priv->service, card, cancellable);
        } else if (old_card == NULL) {
                /* If the just removed smartcard is not known to us then
                 * ignore the removal event. NSS sends a synthentic removal
                 * event for slots that are empty at startup
                 */
                g_debug ("Detected slot %d is empty in reader", (int) slot_id);
        } else {
                g_debug ("Detected smartcard removal event in slot %d", (int) slot_id);

                /* If the just removed smartcard is known to us then
                 * we need to update its exported state to reflect the
                 * removal
                 */
                if (old_slot_series == slot_series)
                        gsd_smartcard_service_sync_token (priv->service, card, cancellable);
        }

        PK11_FreeSlot (card);

        return TRUE;
}
Ejemplo n.º 26
0
gboolean
eas_gdbus_call (struct eas_gdbus_client *client, const gchar *object,
		const gchar *interface, const gchar *method,
		EasProgressFn progress_fn, gpointer progress_data,
		const gchar *in_params, const gchar *out_params,
		GCancellable *cancellable, GError **error, ...)
{
	GDBusMessage *message;
	struct _eas_call_data call;
	GMainContext *ctxt;
	GVariant *v = NULL;
	va_list ap;
	gboolean success;
	guint cancel_handler_id;
	guint32 serial = 0;

	va_start (ap, error);

	message = g_dbus_message_new_method_call (EAS_SERVICE_NAME, object,
						  interface, method);

	v = g_variant_new_va (in_params, NULL, &ap);
	g_dbus_message_set_body (message, v);

	call.cancelled = FALSE;
	call.result = NULL;
	ctxt = g_main_context_new ();
	call.loop = g_main_loop_new (ctxt, FALSE);

	g_main_context_push_thread_default (ctxt);

	g_dbus_connection_send_message_with_reply (client->connection,
						   message,
						   G_DBUS_SEND_MESSAGE_FLAGS_NONE,
						   1000000,
						   &serial,
						   cancellable,
						   _call_done,
						   (gpointer) &call);
	g_object_unref (message);

	if (cancellable)
		cancel_handler_id = g_cancellable_connect (cancellable,
							  G_CALLBACK (_call_cancel),
							  (gpointer) &call, NULL);

	/* Ignore error; it's not the end of the world if progress info
	   is lost, and it should never happen anyway */
	if (progress_fn)
		eas_client_add_progress_info_to_table (client, serial, progress_fn,
						       progress_data, NULL);

	g_main_loop_run (call.loop);

	if (cancellable)
		g_cancellable_disconnect (cancellable, cancel_handler_id);

	success = eas_gdbus_call_finish (client, call.result, call.cancelled ? serial : 0,
					 out_params, &ap, error);

	if (serial && progress_fn) {
		EasProgressCallbackInfo *cbinfo;

		g_mutex_lock (client->progress_lock);
		cbinfo = g_hash_table_lookup (client->progress_fns_table,
					      GUINT_TO_POINTER (serial));
		if (cbinfo && cbinfo->calling) {
			g_debug ("Progress for call %u is running; wait for it to complete",
				 serial);
			g_hash_table_steal (client->progress_fns_table,
					    GUINT_TO_POINTER (serial));
			do {
				g_cond_wait (client->progress_cond, client->progress_lock);
			} while (cbinfo->calling);
			g_free (cbinfo);
		} else if (cbinfo) {
			g_hash_table_remove (client->progress_fns_table,
					     GUINT_TO_POINTER (serial));
		}
		g_mutex_unlock (client->progress_lock);
	}

	va_end (ap);

	g_main_context_pop_thread_default (ctxt);
	g_main_context_unref (ctxt);
	g_main_loop_unref (call.loop);
	g_object_unref (call.result);

	return success;
}
Ejemplo n.º 27
0
gboolean
rpmostree_transaction_get_response_sync (RPMOSTreeSysroot *sysroot_proxy,
                                         const char *transaction_address,
                                         GCancellable *cancellable,
                                         GError **error)
{
  guint sigintid = 0;
  GDBusConnection *connection;
  glnx_unref_object GDBusObjectManager *object_manager = NULL;
  glnx_unref_object RPMOSTreeTransaction *transaction = NULL;

  TransactionProgress *tp = transaction_progress_new ();

  const char *bus_name = NULL;
  gint cancel_handler;
  gulong signal_handler = 0;
  gboolean success = FALSE;
  gboolean just_started = FALSE;

  connection = g_dbus_proxy_get_connection (G_DBUS_PROXY (sysroot_proxy));

  if (g_dbus_connection_get_unique_name (connection) != NULL)
    bus_name = BUS_NAME;

  /* If we are on the message bus, setup object manager connection
   * to notify if the owner changes. */
  if (bus_name != NULL)
    {
      object_manager = rpmostree_object_manager_client_new_sync (connection,
                                                          G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
                                                          bus_name,
                                                          "/org/projectatomic/rpmostree1",
                                                          cancellable,
                                                          error);

      if (object_manager == NULL)
        goto out;

      g_signal_connect (object_manager,
                        "notify::name-owner",
                        G_CALLBACK (on_owner_changed),
                        tp);
    }

  transaction = rpmostree_transaction_connect (transaction_address, cancellable, error);
  if (!transaction)
    goto out;

  sigintid = g_unix_signal_add (SIGINT, on_sigint, cancellable);

  /* setup cancel handler */
  cancel_handler = g_cancellable_connect (cancellable,
                                          G_CALLBACK (cancelled_handler),
                                          transaction, NULL);

  signal_handler = g_signal_connect (transaction, "g-signal",
                                     G_CALLBACK (on_transaction_progress),
                                     tp);

  /* Tell the server we're ready to receive signals. */
  if (!rpmostree_transaction_call_start_sync (transaction,
                                              &just_started,
                                              cancellable,
                                              error))
    goto out;

  /* FIXME Use the 'just_started' flag to determine whether to print
   *       a message about reattaching to an in-progress transaction,
   *       like:
   *
   *       Existing upgrade in progress, reattaching.  Control-C to cancel.
   *
   *       But that requires having a printable description of the
   *       operation.  Maybe just add a string arg to this function?
   */

  g_main_loop_run (tp->loop);

  g_cancellable_disconnect (cancellable, cancel_handler);

  if (!g_cancellable_set_error_if_cancelled (cancellable, error))
    {
      if (tp->error)
        {
          g_propagate_error (error, tp->error);
        }
      else
        {
          success = TRUE;
        }
    }

out:
  if (sigintid)
    g_source_remove (sigintid);
  if (signal_handler)
    g_signal_handler_disconnect (transaction, signal_handler);

  transaction_progress_free (tp);
  return success;
}
 ~RegisterWindowCbData()
 {
   g_cancellable_disconnect(mCancellable, mID);
   g_object_unref(mCancellable);
 }
Ejemplo n.º 29
0
static void
resolve_t_param_cb (SoupSession *session, SoupMessage *message, TParamData *data)
{
	gchar *video_uri = NULL;
	const gchar *video_id, *contents;
	gsize length;
	GMatchInfo *match_info;
	GtkTreeIter iter;
	TotemYouTubePlugin *self = data->plugin;

	/* Prevent cancellation */
	g_cancellable_disconnect (data->cancellable, data->cancelled_id);

	/* Finish loading the page */
	if (message->status_code != SOUP_STATUS_OK) {
		GtkWindow *window;

		/* Bail out if the operation was cancelled */
		if (message->status_code == SOUP_STATUS_CANCELLED)
			goto free_data;

		/* Couldn't load the page contents; error */
		window = totem_get_main_window (data->plugin->totem);
		totem_interface_error (_("Error Looking Up Video URI"), message->response_body->data, window);
		g_object_unref (window);
		goto free_data;
	}

	contents = message->response_body->data;
	length = message->response_body->length;

	video_id = gdata_youtube_video_get_video_id (GDATA_YOUTUBE_VIDEO (data->entry));

	/* Check for the fmt_url_map parameter */
	g_regex_match (self->regex, contents, 0, &match_info);
	if (g_match_info_matches (match_info) == TRUE) {
		gchar *fmt_url_map_escaped, *fmt_url_map;
		gchar **mappings, **i;
		GHashTable *fmt_table;
		gint connection_speed;

		/* We have a match */
		fmt_url_map_escaped = g_match_info_fetch (match_info, 1);
		fmt_url_map = g_uri_unescape_string (fmt_url_map_escaped, NULL);
		g_free (fmt_url_map_escaped);

		/* The fmt_url_map parameter is in the following format:
		 *   fmt1|uri1,fmt2|uri2,fmt3|uri3,...
		 * where fmtN is an identifier for the audio and video encoding and resolution as described here:
		 * (http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs) and uriN is the playback URI for that format.
		 *
		 * We parse it into a hash table from format to URI, and use that against a ranked list of preferred formats (based on the user's
		 * connection speed) to determine the URI to use. */
		fmt_table = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
		mappings = g_strsplit (fmt_url_map, ",", 0);

		for (i = mappings; *i != NULL; i++) {
			/* For the moment we just take the first format we get */
			gchar **mapping;
			gint fmt;

			mapping = g_strsplit (*i, "|", 2);

			if (mapping[0] == NULL || mapping[1] == NULL) {
				g_warning ("Bad format-URI mapping: %s", *i);
				g_strfreev (mapping);
				continue;
			}

			fmt = atoi (mapping[0]);

			if (fmt < 1) {
				g_warning ("Badly-formed format: %s", mapping[0]);
				g_strfreev (mapping);
				continue;
			}

			g_hash_table_insert (fmt_table, GUINT_TO_POINTER ((guint) fmt), g_strdup (mapping[1]));
			g_strfreev (mapping);
		}

		g_strfreev (mappings);

		/* Starting with the highest connection speed we support, look for video URIs matching our connection speed. */
		connection_speed = MIN (bacon_video_widget_get_connection_speed (self->bvw), (gint) G_N_ELEMENTS (fmt_preferences) - 1);
		for (; connection_speed >= 0; connection_speed--) {
			guint idx = (guint) connection_speed;
			video_uri = g_strdup (g_hash_table_lookup (fmt_table, GUINT_TO_POINTER (fmt_preferences [idx])));

			/* Have we found a match yet? */
			if (video_uri != NULL) {
				g_debug ("Using video URI for format %u (connection speed %u)", fmt_preferences[idx], idx);
				break;
			}
		}

		g_hash_table_destroy (fmt_table);
	}

	/* Fallback */
	if (video_uri == NULL) {
		GDataMediaContent *content;

		/* We don't have a match, which is odd; fall back to the FLV URI as advertised by the YouTube API */
		content = GDATA_MEDIA_CONTENT (gdata_youtube_video_look_up_content (GDATA_YOUTUBE_VIDEO (data->entry),
										    "application/x-shockwave-flash"));
		if (content != NULL) {
			video_uri = g_strdup (gdata_media_content_get_uri (content));
			g_debug ("Couldn't find the t param of entry %s; falling back to its FLV URI (\"%s\")", video_id, video_uri);
		} else {
			/* Cop out */
			g_warning ("Couldn't find the t param of entry %s or its FLV URI.", video_uri);
			video_uri = NULL;
		}
	}

	g_match_info_free (match_info);

	/* Update the tree view with the new MRL */
	if (gtk_tree_model_get_iter (GTK_TREE_MODEL (self->list_store[data->tree_view]), &iter, data->path) == TRUE) {
		gtk_list_store_set (self->list_store[data->tree_view], &iter, 2, video_uri, -1);
		g_debug ("Updated list store with new video URI (\"%s\") for entry %s", video_uri, video_id);
	}

	g_free (video_uri);

free_data:
	/* Update the progress bar */
	increment_progress_bar_fraction (self, data->tree_view);

	g_object_unref (data->cancellable);
	g_object_unref (data->plugin);
	g_object_unref (data->entry);
	gtk_tree_path_free (data->path);
	g_slice_free (TParamData, data);
}
Ejemplo n.º 30
0
/**
 * g_vfs_ftp_task_acquire_connection:
 * @task: a task without an associated connection
 *
 * Acquires a new connection for use by this @task. This uses the connection
 * pool of @task's backend, so it reuses previously opened connections and
 * does not reopen new connections unnecessarily. If all connections are busy,
 * it waits %G_VFS_FTP_TIMEOUT_IN_SECONDS seconds for a new connection to
 * become available. Keep in mind that a newly acquired connection might have
 * timed out and therefore closed by the FTP server. You must account for
 * this when sending the first command to the server.
 *
 * Returns: %TRUE if a connection could be acquired, %FALSE if an error
 *          occured
 **/
static gboolean
g_vfs_ftp_task_acquire_connection (GVfsFtpTask *task)
{
  GVfsBackendFtp *ftp;
  gint64 end_time;
  gulong id;

  g_return_val_if_fail (task != NULL, FALSE);
  g_return_val_if_fail (task->conn == NULL, FALSE);

  if (g_vfs_ftp_task_is_in_error (task))
    return FALSE;

  ftp = task->backend;
  g_mutex_lock (&ftp->mutex);
  id = g_cancellable_connect (task->cancellable,
        		      G_CALLBACK (do_broadcast),
        		      &ftp->cond, NULL);
  while (task->conn == NULL && ftp->queue != NULL)
    {
      if (g_cancellable_is_cancelled (task->cancellable))
        {
          task->error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CANCELLED,
        		                     _("Operation was cancelled"));
          break;
        }

      task->conn = g_queue_pop_head (ftp->queue);
      if (task->conn != NULL)
        break;

      if (ftp->connections < ftp->max_connections)
        {
          static GThread *last_thread = NULL;
          /* Save current number of connections here, so we can limit maximum
           * connections later.
           * This is necessary for threading reasons (connections can be
           * opened or closed while we are still in the opening process. */
          guint maybe_max_connections = ftp->connections;

          ftp->connections++;
          last_thread = g_thread_self ();
          g_mutex_unlock (&ftp->mutex);
          task->conn = g_vfs_ftp_connection_new (ftp->addr, task->cancellable, &task->error);
          if (G_LIKELY (task->conn != NULL))
            {
              g_vfs_ftp_task_receive (task, 0, NULL);
              g_vfs_ftp_task_login (task, ftp->user, ftp->password);
              g_vfs_ftp_task_setup_connection (task);
              if (G_LIKELY (!g_vfs_ftp_task_is_in_error (task)))
                break;
            }

          g_vfs_ftp_connection_free (task->conn);
          task->conn = NULL;
          g_mutex_lock (&ftp->mutex);
          ftp->connections--;
          /* If this value is still equal to our thread it means there were no races 
           * trying to open connections and the maybe_max_connections value is 
           * reliable. */
          if (last_thread == g_thread_self () && 
              !g_vfs_ftp_task_error_matches (task, G_IO_ERROR, G_IO_ERROR_CANCELLED))
            {
              g_print ("maybe: %u, max %u (due to %s)\n", maybe_max_connections, ftp->max_connections, task->error->message);
              ftp->max_connections = MIN (ftp->max_connections, maybe_max_connections);
              if (ftp->max_connections == 0)
                {
                  g_debug ("no more connections left, exiting...\n");
                  /* FIXME: shut down properly */
                  exit (0);
                }
            }

          g_vfs_ftp_task_clear_error (task);
          continue;
        }

      end_time = g_get_monotonic_time () + G_VFS_FTP_TIMEOUT_IN_SECONDS * G_TIME_SPAN_SECOND;
      if (ftp->busy_connections >= ftp->connections ||
          !g_cond_wait_until (&ftp->cond, &ftp->mutex, end_time))
        {
          task->error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_BUSY,
        		                     _("The FTP server is busy. Try again later"));
          break;
        }
    }
  g_cancellable_disconnect (task->cancellable, id);
  g_mutex_unlock (&ftp->mutex);

  return task->conn != NULL;
}