Ejemplo n.º 1
0
static gboolean vibrator_timed_outputclass_real_vibrate_co (VibratorTimedOutputclassVibrateData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = _data_->self->priv->pulses;
	if (_data_->_tmp1_ > ((guint) 0)) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp2_ = _data_->self->priv->fulltimeoutwatch;
		_data_->_tmp0_ = _data_->_tmp2_ > ((guint) 0);
	}
	_data_->_tmp3_ = _data_->_tmp0_;
	if (_data_->_tmp3_) {
		_data_->_tmp4_ = g_error_new_literal (FREE_SMARTPHONE_ERROR, FREE_SMARTPHONE_ERROR_INVALID_PARAMETER, "Already vibrating... please try again");
		_data_->_inner_error_ = _data_->_tmp4_;
		if (((_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR) || (_data_->_inner_error_->domain == G_DBUS_ERROR)) || (_data_->_inner_error_->domain == G_IO_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	_data_->_tmp5_ = _data_->milliseconds;
	if (_data_->_tmp5_ < 50) {
		_data_->_tmp6_ = g_error_new_literal (FREE_SMARTPHONE_ERROR, FREE_SMARTPHONE_ERROR_INVALID_PARAMETER, "Vibration timeout needs to be at least 50 milliseconds");
		_data_->_inner_error_ = _data_->_tmp6_;
		if (((_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR) || (_data_->_inner_error_->domain == G_DBUS_ERROR)) || (_data_->_inner_error_->domain == G_IO_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	vibrator_timed_outputclass_cleanTimeouts (_data_->self);
	_data_->_tmp7_ = _data_->milliseconds;
	vibrator_timed_outputclass_set_enable (_data_->self, _data_->_tmp7_);
	_data_->_tmp8_ = _data_->milliseconds;
	_data_->_tmp9_ = 0U;
	_data_->_tmp9_ = g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) _data_->_tmp8_, ___lambda2__gsource_func, g_object_ref (_data_->self), g_object_unref);
	_data_->self->priv->fulltimeoutwatch = _data_->_tmp9_;
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}
Ejemplo n.º 2
0
static void
tp_file_start_transfer (EmpathyTpFile *self)
{
  gint fd, domain, res = 0;
  GError *error = NULL;
  struct sockaddr *my_addr = NULL;
  size_t my_size = 0;

  if (self->priv->socket_address_type == TP_SOCKET_ADDRESS_TYPE_UNIX)
    {
      domain = AF_UNIX;
    }
  else if (self->priv->socket_address_type == TP_SOCKET_ADDRESS_TYPE_IPV4)
    {
      domain = AF_INET;
    }
  else
    {
      error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
          EMPATHY_FT_ERROR_NOT_SUPPORTED, _("Socket type not supported"));

      DEBUG ("Socket not supported, closing channel");

      ft_operation_close_with_error (self, error);
      g_clear_error (&error);

      return;
    }

  fd = socket (domain, SOCK_STREAM, 0);

  if (fd < 0)
    {
      int code = errno;

      error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
          EMPATHY_FT_ERROR_SOCKET, g_strerror (code));

      DEBUG ("Failed to create socket, closing channel");

      ft_operation_close_with_error (self, error);
      g_clear_error (&error);

      return;
    }

  if (self->priv->socket_address_type == TP_SOCKET_ADDRESS_TYPE_UNIX)
    {
      struct sockaddr_un addr;

      memset (&addr, 0, sizeof (addr));
      addr.sun_family = domain;
      strncpy (addr.sun_path, self->priv->socket_address->data,
          self->priv->socket_address->len);

      my_addr = (struct sockaddr *) &addr;
      my_size = sizeof (addr);
    }
  else if (self->priv->socket_address_type == TP_SOCKET_ADDRESS_TYPE_IPV4)
    {
      struct sockaddr_in addr;

      memset (&addr, 0, sizeof (addr));
      addr.sin_family = domain;
      inet_pton (AF_INET, self->priv->socket_address->data, &addr.sin_addr);
      addr.sin_port = htons (self->priv->port);

      my_addr = (struct sockaddr *) &addr;
      my_size = sizeof (addr);
    }

  res = connect (fd, my_addr, my_size);

  if (res < 0)
    {
      int code = errno;

      error = g_error_new_literal (EMPATHY_FT_ERROR_QUARK,
          EMPATHY_FT_ERROR_SOCKET, g_strerror (code));

      DEBUG ("Failed to connect socket, closing channel");

      ft_operation_close_with_error (self, error);
      close (fd);
      g_clear_error (&error);

      return;
    }

  DEBUG ("Start the transfer");

  self->priv->start_time = empathy_time_get_current ();

  /* notify we're starting a transfer */
  if (self->priv->progress_callback != NULL)
    self->priv->progress_callback (self, 0, self->priv->progress_user_data);

  if (self->priv->incoming)
    {
      GInputStream *socket_stream;

      socket_stream = g_unix_input_stream_new (fd, TRUE);

      g_output_stream_splice_async (self->priv->out_stream, socket_stream,
          G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
          G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
          G_PRIORITY_DEFAULT, self->priv->cancellable,
          splice_stream_ready_cb, self);

      g_object_unref (socket_stream);
    }
  else
    {
      GOutputStream *socket_stream;

      socket_stream = g_unix_output_stream_new (fd, TRUE);

      g_output_stream_splice_async (socket_stream, self->priv->in_stream,
          G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
          G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
          G_PRIORITY_DEFAULT, self->priv->cancellable,
          splice_stream_ready_cb, self);

      g_object_unref (socket_stream);
    }
}
Ejemplo n.º 3
0
void
ephy_sqlite_connection_get_error (EphySQLiteConnection *self, GError **error)
{
  if (error)
    *error = g_error_new_literal (get_ephy_sqlite_quark (), 0, sqlite3_errmsg (self->database));
}
Ejemplo n.º 4
0
static void
master_shunt_read (FlowShunt *shunt, FlowPacket *packet, FlowSshMaster *ssh_master)
{
  FlowSshMasterPrivate *priv           = ssh_master->priv;
  FlowPacketFormat      packet_format  = flow_packet_get_format (packet);
  gpointer              packet_data    = flow_packet_get_data (packet);
  const gchar          *signal_to_emit = NULL;

  g_mutex_lock (priv->mutex);

  if (packet_format == FLOW_PACKET_FORMAT_OBJECT && FLOW_IS_DETAILED_EVENT (packet_data))
  {
    FlowDetailedEvent *detailed_event = (FlowDetailedEvent *) packet_data;

    if (flow_detailed_event_matches (detailed_event, FLOW_STREAM_DOMAIN, FLOW_STREAM_BEGIN))
    {
      /* Shell command is running, but not yet connected to remote end */
    }
    else if (flow_detailed_event_matches (detailed_event, FLOW_STREAM_DOMAIN, FLOW_STREAM_END))
    {
      flow_shunt_destroy (priv->shunt);
      priv->shunt = NULL;

      if (priv->is_connecting)
      {
        if (priv->connect_error)
          g_error_free (priv->connect_error);
        priv->connect_error = g_error_new_literal (FLOW_SSH_DOMAIN_QUARK, FLOW_SSH_MASTER_FAILED,
                                                   "Could not connect SSH master");
        signal_to_emit = "connect-finished";
      }
      else
      {
        signal_to_emit = "disconnected";
      }

      priv->is_connecting = FALSE;
      priv->is_connected = FALSE;
    }
    else if (flow_detailed_event_matches (detailed_event, FLOW_STREAM_DOMAIN, FLOW_STREAM_DENIED))
    {
      flow_shunt_destroy (priv->shunt);
      priv->shunt = NULL;

      if (priv->connect_error)
        g_error_free (priv->connect_error);
      priv->connect_error = g_error_new_literal (FLOW_SSH_DOMAIN_QUARK, FLOW_SSH_MASTER_FAILED,
                                                 "Could not start SSH master");

      priv->is_connecting = FALSE;
      signal_to_emit = "connect-finished";
    }
  }
  else if (packet_format == FLOW_PACKET_FORMAT_BUFFER)
  {
    if (priv->is_connecting)
      signal_to_emit = "connect-finished";

    priv->is_connected = TRUE;
    priv->is_connecting = FALSE;

    if (!is_master_working (ssh_master))
    {
      flow_shunt_destroy (priv->shunt);
      priv->shunt = NULL;
    }
  }

  g_mutex_unlock (priv->mutex);

  flow_packet_unref (packet);

  if (signal_to_emit)
    g_signal_emit_by_name (ssh_master, signal_to_emit);
}
Ejemplo n.º 5
0
static void
thunar_apr_desktop_page_save (ThunarAprDesktopPage *desktop_page,
                              GtkWidget            *widget)
{
    GtkWidget *toplevel;
    GtkWidget *message;
    GKeyFile  *key_file;
    GError    *error = NULL;
    gchar     *filename;
    gchar     *data;
    gchar     *uri;
    gsize      data_length;
    FILE      *fp;

    /* verify that we still have a valid file */
    if (THUNAR_APR_ABSTRACT_PAGE (desktop_page)->file == NULL)
        return;

    /* determine the local path to the file */
    uri = thunarx_file_info_get_uri (THUNAR_APR_ABSTRACT_PAGE (desktop_page)->file);
    filename = g_filename_from_uri (uri, NULL, NULL);
    g_free (uri);

    /* verify that we have a valid local path */
    if (G_UNLIKELY (filename == NULL))
        return;

    /* allocate the key file resources */
    key_file = g_key_file_new ();

    /* try to parse the key file */
    if (g_key_file_load_from_file (key_file, filename, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error))
    {
        /* save the widget changes to the key file */
        thunar_apr_desktop_page_save_widget (desktop_page, widget, key_file);

        /* give empty desktop files a type */
        if (!g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP,
                                 G_KEY_FILE_DESKTOP_KEY_TYPE, NULL))
        {
            g_key_file_set_string (key_file,
                                   G_KEY_FILE_DESKTOP_GROUP,
                                   G_KEY_FILE_DESKTOP_KEY_TYPE,
                                   "Application");
        }

        /* determine the content of the key file */
        data = g_key_file_to_data (key_file, &data_length, &error);
        if (G_LIKELY (data_length > 0))
        {
            /* try to save the key file content to disk */
            fp = fopen (filename, "w");
            if (G_LIKELY (fp != NULL))
            {
                if (fwrite (data, data_length, 1, fp) != 1)
                    error = g_error_new_literal (G_FILE_ERROR, g_file_error_from_errno (errno), g_strerror (errno));
                fclose (fp);
            }
            else
            {
                error = g_error_new_literal (G_FILE_ERROR, g_file_error_from_errno (errno), g_strerror (errno));
            }
        }

        /* cleanup */
        g_free (data);
    }

    /* check if we succeed */
    if (G_UNLIKELY (error != NULL))
    {
        /* display an error dialog to the user */
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (desktop_page));
        message = gtk_message_dialog_new ((GtkWindow *) toplevel,
                                          GTK_DIALOG_DESTROY_WITH_PARENT
                                          | GTK_DIALOG_MODAL,
                                          GTK_MESSAGE_ERROR,
                                          GTK_BUTTONS_CLOSE,
                                          _("Failed to save \"%s\"."), filename);
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s.", error->message);
        gtk_dialog_run (GTK_DIALOG (message));
        gtk_widget_destroy (message);
        g_error_free (error);
    }

    /* cleanup */
    g_key_file_free (key_file);
    g_free (filename);
}
Ejemplo n.º 6
0
static GError *
format_message (GQuark id, char const *message)
{
	char const *msg = message ? message : "";
	return g_error_new_literal (id, 0, msg);
}
Ejemplo n.º 7
0
/**
 * g_dbus_address_get_stream_sync:
 * @address: A valid D-Bus address.
 * @out_guid: %NULL or return location to store the GUID extracted from @address, if any.
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.
 *
 * Synchronously 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.
 *
 * This is a synchronous failable function. See
 * g_dbus_address_get_stream() for the asynchronous version.
 *
 * Returns: (transfer full): A #GIOStream or %NULL if @error is set.
 *
 * Since: 2.26
 */
GIOStream *
g_dbus_address_get_stream_sync (const gchar   *address,
                                gchar        **out_guid,
                                GCancellable  *cancellable,
                                GError       **error)
{
  GIOStream *ret;
  gchar **addr_array;
  guint n;
  GError *last_error;

  g_return_val_if_fail (address != NULL, NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  ret = NULL;
  last_error = NULL;

  addr_array = g_strsplit (address, ";", 0);
  if (addr_array != NULL && addr_array[0] == NULL)
    {
      last_error = g_error_new_literal (G_IO_ERROR,
                                        G_IO_ERROR_INVALID_ARGUMENT,
                                        _("The given address is empty"));
      goto out;
    }

  for (n = 0; addr_array != NULL && addr_array[n] != NULL; n++)
    {
      const gchar *addr = addr_array[n];
      GError *this_error;

      this_error = NULL;
      ret = g_dbus_address_try_connect_one (addr,
                                            out_guid,
                                            cancellable,
                                            &this_error);
      if (ret != NULL)
        {
          goto out;
        }
      else
        {
          g_assert (this_error != NULL);
          if (last_error != NULL)
            g_error_free (last_error);
          last_error = this_error;
        }
    }

 out:
  if (ret != NULL)
    {
      if (last_error != NULL)
        g_error_free (last_error);
    }
  else
    {
      g_assert (last_error != NULL);
      g_propagate_error (error, last_error);
    }

  g_strfreev (addr_array);
  return ret;
}
Ejemplo n.º 8
0
static void
get_ip4_config_done (MMAtSerialPort *port,
                     GString *response,
                     GError *error,
                     gpointer user_data)
{
    MMCallbackInfo *info = (MMCallbackInfo *) user_data;
	char **items, **iter;
    GArray *dns_array;
    int i;
    guint32 tmp;
    gint cid;

    /* If the modem has already been removed, return without
     * scheduling callback */
    if (mm_callback_info_check_modem_removed (info))
        return;

    if (error) {
        info->error = g_error_copy (error);
        goto out;
    } else if (!g_str_has_prefix (response->str, IPDPADDR_TAG)) {
        info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
                                           "Retrieving failed: invalid response.");
        goto out;
    }

    cid = _get_cid (MM_MODEM_ICERA (info->modem));
    dns_array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 2);

    /* %IPDPADDR: <cid>,<ip>,<gw>,<dns1>,<dns2>[,<nbns1>,<nbns2>] */
    items = g_strsplit (response->str + strlen (IPDPADDR_TAG), ", ", 0);

    for (iter = items, i = 0; *iter; iter++, i++) {
        if (i == 0) { /* CID */
            long int num;

            errno = 0;
            num = strtol (*iter, NULL, 10);
            if (errno != 0 || num < 0 || (gint) num != cid) {
                info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
                                           "Unknown CID in IPDPADDR response ("
                                           "got %d, expected %d)", (guint) num, cid);
                break;
            }
        } else if (i == 1) { /* IP address */
            if (inet_pton (AF_INET, *iter, &tmp) > 0)
                mm_callback_info_set_data (info, "ip4-address", GUINT_TO_POINTER (tmp), NULL);
        } else if (i == 3) { /* DNS 1 */
            if (inet_pton (AF_INET, *iter, &tmp) > 0)
                g_array_append_val (dns_array, tmp);
        } else if (i == 4) { /* DNS 2 */
            if (inet_pton (AF_INET, *iter, &tmp) > 0)
                g_array_append_val (dns_array, tmp);
        }
    }

    g_strfreev (items);
    mm_callback_info_set_data (info, "ip4-dns", dns_array, free_dns_array);

 out:
    mm_callback_info_schedule (info);
}
Ejemplo n.º 9
0
static gboolean pdp_qmi_real_sc_activate_co (PdpQmiScActivateData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = fso_gsm_pdp_handler_get_modem ((FsoGsmPdpHandler*) _data_->self);
	_data_->_tmp1_ = _data_->_tmp0_;
	_data_->_tmp2_ = NULL;
	_data_->_tmp2_ = fso_gsm_modem_data (_data_->_tmp1_);
	_data_->data = _data_->_tmp2_;
	_data_->_tmp3_ = _data_->data;
	_data_->_tmp4_ = _data_->_tmp3_->contextParams;
	if (_data_->_tmp4_ == NULL) {
		_data_->_tmp5_ = g_error_new_literal (FREE_SMARTPHONE_ERROR, FREE_SMARTPHONE_ERROR_INTERNAL_ERROR, "Context parameters not set");
		_data_->_inner_error_ = _data_->_tmp5_;
		if ((_data_->_inner_error_->domain == FREE_SMARTPHONE_GSM_ERROR) || (_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->data);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_g_object_unref0 (_data_->data);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	_data_->_tmp6_ = _data_->data;
	_data_->_tmp7_ = _data_->_tmp6_->contextParams;
	_data_->_tmp8_ = _data_->_tmp7_->apn;
	if (_data_->_tmp8_ == NULL) {
		_data_->_tmp9_ = g_error_new_literal (FREE_SMARTPHONE_ERROR, FREE_SMARTPHONE_ERROR_INTERNAL_ERROR, "APN not set");
		_data_->_inner_error_ = _data_->_tmp9_;
		if ((_data_->_inner_error_->domain == FREE_SMARTPHONE_GSM_ERROR) || (_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			_g_object_unref0 (_data_->data);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			_g_object_unref0 (_data_->data);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	_data_->_tmp10_ = _data_->data;
	_data_->_tmp11_ = _data_->_tmp10_->contextParams;
	_data_->_tmp12_ = _data_->_tmp11_->apn;
	_data_->_tmp13_ = NULL;
	_data_->_tmp13_ = string_to_string (_data_->_tmp12_);
	_data_->_tmp14_ = _data_->data;
	_data_->_tmp15_ = _data_->_tmp14_->contextParams;
	_data_->_tmp16_ = _data_->_tmp15_->username;
	_data_->_tmp17_ = NULL;
	_data_->_tmp17_ = string_to_string (_data_->_tmp16_);
	_data_->_tmp18_ = _data_->data;
	_data_->_tmp19_ = _data_->_tmp18_->contextParams;
	_data_->_tmp20_ = _data_->_tmp19_->password;
	_data_->_tmp21_ = NULL;
	_data_->_tmp21_ = string_to_string (_data_->_tmp20_);
	_data_->_tmp22_ = NULL;
	_data_->_tmp22_ = g_strconcat ("up:", _data_->_tmp13_, " ", _data_->_tmp17_, " ", _data_->_tmp21_, NULL);
	_data_->cmdline = _data_->_tmp22_;
	_data_->_tmp23_ = _data_->self->fd;
	_data_->_tmp24_ = _data_->cmdline;
	_data_->_tmp25_ = _data_->cmdline;
	_data_->_tmp26_ = strlen (_data_->_tmp25_);
	_data_->_tmp27_ = _data_->_tmp26_;
	write (_data_->_tmp23_, _data_->_tmp24_, (gsize) _data_->_tmp27_);
	_g_free0 (_data_->cmdline);
	_g_object_unref0 (_data_->data);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}
Ejemplo n.º 10
0
static void
keyring_find_secrets_cb (GnomeKeyringResult result,
                         GList *list,
                         gpointer user_data)
{
	KeyringCall *call = user_data;
	Request *r = call->r;
	GError *error = NULL;
	const char *connection_id = NULL;
	GHashTable *secrets = NULL, *settings = NULL;
	GList *iter;
	gboolean hint_found = FALSE, ask = FALSE;

	r->keyring_calls = g_slist_remove (r->keyring_calls, call);
	if (r->canceled) {
		/* Callback already called by NM or dispose */
		request_free (r);
		return;
	}

	connection_id = nm_connection_get_id (r->connection);

	if (result == GNOME_KEYRING_RESULT_CANCELLED) {
		error = g_error_new_literal (NM_SECRET_AGENT_ERROR,
		                             NM_SECRET_AGENT_ERROR_USER_CANCELED,
		                             "The secrets request was canceled by the user");
		goto done;
	} else if (   result != GNOME_KEYRING_RESULT_OK
	           && result != GNOME_KEYRING_RESULT_NO_MATCH) {
		error = g_error_new (NM_SECRET_AGENT_ERROR,
		                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
		                     "%s.%d - failed to read secrets from keyring (result %d)",
		                     __FILE__, __LINE__, result);
		goto done;
	}

	/* Only ask if we're allowed to, ie if flags != NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE */
	if (r->flags && g_list_length (list) == 0) {
		g_message ("No keyring secrets found for %s/%s; asking user.", connection_id, r->setting_name);
		ask_for_secrets (r);
		return;
	}

	secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);

	/* Extract the secrets from the list of matching keyring items */
	for (iter = list; iter != NULL; iter = g_list_next (iter)) {
		GnomeKeyringFound *found = iter->data;
		GnomeKeyringAttribute *attr;
		const char *key_name = NULL;
		int i;

		for (i = 0; i < found->attributes->len; i++) {
			attr = &(gnome_keyring_attribute_list_index (found->attributes, i));
			if (   (strcmp (attr->name, KEYRING_SK_TAG) == 0)
			    && (attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING)) {

				key_name = attr->value.string;
				g_hash_table_insert (secrets, g_strdup (key_name), string_to_gvalue (found->secret));

				/* See if this property matches a given hint */
				if (r->hints && r->hints[0]) {
					if (!g_strcmp0 (r->hints[0], key_name) || !g_strcmp0 (r->hints[1], key_name))
						hint_found = TRUE;
				}
				break;
			}
		}
	}

	/* If there were hints, and none of the hints were returned by the keyring,
	 * get some new secrets.
	 */
	if (r->flags) {
		if (r->hints && r->hints[0] && !hint_found)
			ask = TRUE;
		else if (r->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW) {
			g_message ("New secrets for %s/%s requested; ask the user", connection_id, r->setting_name);
			ask = TRUE;
		} else if (   (r->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION)
			       && is_connection_always_ask (r->connection))
			ask = TRUE;
	}

	/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
	 * will contain all the individual settings hashes.
	 */
	settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy);
	g_hash_table_insert (settings, g_strdup (r->setting_name), secrets);

done:
	if (ask) {
		GHashTableIter hash_iter;
		const char *setting_name;
		GHashTable *setting_hash;

		/* Stuff all the found secrets into the connection for the UI to use */
		g_hash_table_iter_init (&hash_iter, settings);
		while (g_hash_table_iter_next (&hash_iter,
		                               (gpointer *) &setting_name,
		                               (gpointer *) &setting_hash)) {
			nm_connection_update_secrets (r->connection,
				                          setting_name,
				                          setting_hash,
				                          NULL);
		}

		ask_for_secrets (r);
	} else {
		/* Otherwise send the secrets back to NetworkManager */
		r->get_callback (NM_SECRET_AGENT (r->agent), r->connection, error ? NULL : settings, error, r->callback_data);
		request_free (r);
	}

	if (settings)
		g_hash_table_destroy (settings);
	g_clear_error (&error);
}
Ejemplo n.º 11
0
static gboolean tracker_bus_fd_cursor_real_next (TrackerSparqlCursor* base, GCancellable* cancellable, GError** error) {
	TrackerBusFDCursor * self;
	gboolean result = FALSE;
	gint last_offset = 0;
	gboolean _tmp0_ = FALSE;
	GCancellable* _tmp1_ = NULL;
	gulong _tmp5_ = 0UL;
	gulong _tmp6_ = 0UL;
	gint _tmp7_ = 0;
	gchar* _tmp8_ = NULL;
	gulong _tmp9_ = 0UL;
	gulong _tmp10_ = 0UL;
	gint _tmp11_ = 0;
	gint _tmp12_ = 0;
	gchar* _tmp13_ = NULL;
	gulong _tmp14_ = 0UL;
	gulong _tmp15_ = 0UL;
	gint _tmp16_ = 0;
	gint _tmp17_ = 0;
	gint _tmp18_ = 0;
	gchar* _tmp19_ = NULL;
	gulong _tmp20_ = 0UL;
	gulong _tmp21_ = 0UL;
	gint _tmp22_ = 0;
	GError * _inner_error_ = NULL;
#line 86 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	self = (TrackerBusFDCursor*) base;
#line 89 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp1_ = cancellable;
#line 89 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	if (_tmp1_ != NULL) {
#line 402 "tracker-bus-fd-cursor.c"
		GCancellable* _tmp2_ = NULL;
		gboolean _tmp3_ = FALSE;
#line 89 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		_tmp2_ = cancellable;
#line 89 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		_tmp3_ = g_cancellable_is_cancelled (_tmp2_);
#line 89 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		_tmp0_ = _tmp3_;
#line 411 "tracker-bus-fd-cursor.c"
	} else {
#line 89 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		_tmp0_ = FALSE;
#line 415 "tracker-bus-fd-cursor.c"
	}
#line 89 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	if (_tmp0_) {
#line 419 "tracker-bus-fd-cursor.c"
		GError* _tmp4_ = NULL;
#line 90 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		_tmp4_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CANCELLED, "Operation was cancelled");
#line 90 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		_inner_error_ = _tmp4_;
#line 90 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		g_propagate_error (error, _inner_error_);
#line 90 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		return FALSE;
#line 429 "tracker-bus-fd-cursor.c"
	}
#line 93 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp5_ = self->buffer_index;
#line 93 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp6_ = self->buffer_size;
#line 93 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	if (_tmp5_ >= _tmp6_) {
#line 94 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		result = FALSE;
#line 94 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
		return result;
#line 441 "tracker-bus-fd-cursor.c"
	}
#line 104 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp7_ = tracker_bus_fd_cursor_buffer_read_int (self);
#line 104 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	self->_n_columns = _tmp7_;
#line 108 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp8_ = self->buffer;
#line 108 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp9_ = self->buffer_index;
#line 108 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	self->types = (gint*) (_tmp8_ + _tmp9_);
#line 109 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp10_ = self->buffer_index;
#line 109 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp11_ = tracker_sparql_cursor_get_n_columns ((TrackerSparqlCursor*) self);
#line 109 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp12_ = _tmp11_;
#line 109 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	self->buffer_index = _tmp10_ + (sizeof (gint) * _tmp12_);
#line 111 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp13_ = self->buffer;
#line 111 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp14_ = self->buffer_index;
#line 111 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	self->offsets = (gint*) (_tmp13_ + _tmp14_);
#line 112 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp15_ = self->buffer_index;
#line 112 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp16_ = tracker_sparql_cursor_get_n_columns ((TrackerSparqlCursor*) self);
#line 112 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp17_ = _tmp16_;
#line 112 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	self->buffer_index = _tmp15_ + (sizeof (gint) * (_tmp17_ - 1));
#line 113 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp18_ = tracker_bus_fd_cursor_buffer_read_int (self);
#line 113 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	last_offset = _tmp18_;
#line 115 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp19_ = self->buffer;
#line 115 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp20_ = self->buffer_index;
#line 115 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	self->data = _tmp19_ + _tmp20_;
#line 117 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp21_ = self->buffer_index;
#line 117 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	_tmp22_ = last_offset;
#line 117 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	self->buffer_index = _tmp21_ + (_tmp22_ + 1);
#line 119 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	result = TRUE;
#line 119 "/home/martyn/Source/checkout/gnome/tracker/src/libtracker-bus/tracker-bus-fd-cursor.vala"
	return result;
#line 495 "tracker-bus-fd-cursor.c"
}
Ejemplo n.º 12
0
static void
on_autorun_loaded (GObject      *source_object,
                   GAsyncResult *res,
                   gpointer      user_data)
{
  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
  GFile *autorun_file;
  gchar *content;
  gchar *relative_icon_path;
  gsize content_length;
  GError *error;

  relative_icon_path = NULL;

  autorun_file = G_FILE (source_object);

  error = NULL;
  if (g_file_load_contents_finish (autorun_file,
                                   res,
                                   &content,
                                   &content_length,
                                   NULL,
                                   &error))
    {
      /* Scan through for an "icon=" line. Can't use GKeyFile,
       * because .inf files aren't always valid key files
       **/
      GRegex *icon_regex;
      GMatchInfo *match_info;

      /* [^,] is because sometimes the icon= line
       * has a comma at the end
       **/
      icon_regex = g_regex_new ("icon=([^,\\r\\n]+)",
                                G_REGEX_CASELESS, 0, NULL);
      g_regex_match (icon_regex, content, 0,
                     &match_info);

      /* Even if there are multiple matches, pick only the
       * first.
       **/
      if (g_match_info_matches (match_info))
        {
          gchar *chr;
          gchar *word = g_match_info_fetch (match_info, 1);

          /* Replace '\' with '/' */
          while ((chr = strchr (word, '\\')) != NULL)
            *chr = '/';

          /* If the file name's not valid UTF-8,
           * don't even try to load it
           **/
          if (g_utf8_validate (word, -1, NULL))
            {
              relative_icon_path = word;
            }
          else
            {
              /* TODO: mark for translation. Strictly, this isn't very important; this string
               * will never be displayed since all current users of g_vfs_mount_info_query_autorun_info()
               * passes NULL for the GError**.
               */
              error = g_error_new_literal (G_IO_ERROR,
                                           G_IO_ERROR_FAILED,
                                           "Icon name is not valid UTF-8");
              g_free (word);
            }
        }

      g_match_info_free (match_info);

      g_regex_unref (icon_regex);
      g_free (content);
    }

  /* some autorun.in points to the .exe file for the icon; make sure we avoid using that */
  if (relative_icon_path != NULL)
    {
      if (!g_str_has_suffix (relative_icon_path, ".exe"))
        {
          GFile *root;

          root = g_file_get_parent (autorun_file);

          _g_find_file_insensitive_async (root,
                                          relative_icon_path,
                                          NULL,
                                          on_icon_file_located,
                                          simple);

          g_object_unref (root);
        }
      else
        {
          /* TODO: mark for translation. Strictly, this isn't very important; this string
           * will never be displayed since all current users of g_vfs_mount_info_query_autorun_info()
           * passes NULL for the GError**.
           */
          error = g_error_new_literal (G_IO_ERROR,
                                       G_IO_ERROR_FAILED,
                                       "Icon is an .exe file");
        }
    }

  if (error != NULL)
    {
      g_simple_async_result_set_from_error (simple, error);
      g_simple_async_result_complete_in_idle (simple);
      g_object_unref (simple);
      g_error_free (error);
    }

  g_free (relative_icon_path);
}
Ejemplo n.º 13
0
static void
bdmv_metadata_thread (GSimpleAsyncResult *result,
                      GObject *object,
                      GCancellable *cancellable)
{
  BLURAY *bd;
  META_DL *meta;
  GError *error;
  GFile *file;
  char *disc_root;
  char *icon;
  char *name;
  const char *lang;

  file = G_FILE (object);

  disc_root = g_file_get_path (file);
  bd = bd_open (disc_root, NULL);
  g_free (disc_root);

  if (bd == NULL)
    {
      error = g_error_new_literal (G_IO_ERROR,
                                   G_IO_ERROR_FAILED,
                                   "Device is not a Blu-Ray disc");
      goto error;
    }

  lang = get_iso_639_3_for_locale ();
  if (lang != NULL)
    bd_set_player_setting_str (bd, BLURAY_PLAYER_SETTING_MENU_LANG, lang);

  meta = bd_get_meta (bd);
  if (meta == NULL)
    {
      error = g_error_new_literal (G_IO_ERROR,
                                   G_IO_ERROR_FAILED,
                                   "Device is not a Blu-Ray disc, or has no metadata");
      bd_close (bd);
      goto error;
    }
  name = icon = NULL;

  if (meta != NULL)
    {
      if (meta->di_name && *meta->di_name)
        name = g_strdup (meta->di_name);
      icon = g_strdup (get_icon (meta));
    }

  /* We're missing either an icon, or the name */
  if (!name || !icon)
    {
      bd_set_player_setting_str (bd, BLURAY_PLAYER_SETTING_MENU_LANG, "eng");
      meta = bd_get_meta (bd);

      if (meta != NULL && name == NULL && meta->di_name && *meta->di_name)
        name = meta->di_name;

      if (meta != NULL && icon == NULL)
        icon = g_strdup (get_icon (meta));
    }

  /* Set the results */
  if (icon != NULL)
    {
      char *icon_path;
      GFile *icon_file;

      icon_path = g_strdup_printf ("BDMV/META/DL/%s", icon);
      g_free (icon);
      icon_file = g_file_resolve_relative_path (file, icon_path);
      g_free (icon_path);

      g_simple_async_result_set_op_res_gpointer (result,
                                                 g_file_icon_new (icon_file),
                                                 NULL);
    }
  else
    {
      g_simple_async_result_set_op_res_gpointer (result, NULL, NULL);
    }

  if (name != NULL)
    g_object_set_data_full (G_OBJECT (result), "name", name, g_free);

  bd_close (bd);

  return;

error:
  g_simple_async_result_set_from_error (result, error);
  g_simple_async_result_set_op_res_gpointer (result, NULL, NULL);
  g_error_free (error);
}
Ejemplo n.º 14
0
gssize fusion_tls_connection_send (FusionTLSConnection* self, guint8* buffer, int buffer_length1, GCancellable* cancellable, GError** error) {
	gssize result = 0L;
	gssize ret = 0L;
	GSocket* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	GCancellable* _tmp3_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0L);
	g_warning ("TLSConnection.vala:123: SEND");
	_tmp0_ = self->priv->socket;
	_tmp1_ = g_socket_is_closed (_tmp0_);
	if (_tmp1_) {
		GError* _tmp2_ = NULL;
		_tmp2_ = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CLOSED, "Socket is already closed");
		_inner_error_ = _tmp2_;
		if (_inner_error_->domain == G_IO_ERROR) {
			g_propagate_error (error, _inner_error_);
			return 0L;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0L;
		}
	}
	_tmp3_ = cancellable;
	g_cancellable_set_error_if_cancelled (_tmp3_, &_inner_error_);
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == G_IO_ERROR) {
			g_propagate_error (error, _inner_error_);
			return 0L;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0L;
		}
	}
	while (TRUE) {
		gboolean _tmp4_ = FALSE;
		GSocket* _tmp5_ = NULL;
		gboolean _tmp6_ = FALSE;
		gboolean _tmp11_ = FALSE;
		struct gnutls_session_int* _tmp12_ = NULL;
		guint8* _tmp13_ = NULL;
		gint _tmp13__length1 = 0;
		guint8* _tmp14_ = NULL;
		gint _tmp14__length1 = 0;
		gssize _tmp15_ = 0L;
		gssize _tmp16_ = 0L;
		_tmp5_ = self->priv->socket;
		_tmp6_ = g_socket_get_blocking (_tmp5_);
		if (_tmp6_) {
			gboolean _tmp7_ = FALSE;
			GSocket* _tmp8_ = NULL;
			GCancellable* _tmp9_ = NULL;
			gboolean _tmp10_ = FALSE;
			_tmp8_ = self->priv->socket;
			_tmp9_ = cancellable;
			_tmp10_ = g_socket_condition_wait (_tmp8_, G_IO_OUT, _tmp9_, &_inner_error_);
			_tmp7_ = _tmp10_;
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == G_IO_ERROR) {
					g_propagate_error (error, _inner_error_);
					return 0L;
				} else {
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return 0L;
				}
			}
			_tmp4_ = !_tmp7_;
		} else {
			_tmp4_ = FALSE;
		}
		_tmp11_ = _tmp4_;
		if (_tmp11_) {
			result = (gssize) (-1);
			return result;
		}
		_tmp12_ = self->tls_session;
		_tmp13_ = buffer;
		_tmp13__length1 = buffer_length1;
		_tmp14_ = buffer;
		_tmp14__length1 = buffer_length1;
		_tmp15_ = gnutls_record_send (_tmp12_, _tmp13_, (gsize) _tmp14__length1);
		ret = _tmp15_;
		_tmp16_ = ret;
		if (_tmp16_ < ((gssize) 0)) {
			int ecode = 0;
			gssize _tmp17_ = 0L;
			int _tmp18_ = 0;
			gboolean _tmp19_ = FALSE;
			GSocket* _tmp20_ = NULL;
			gboolean _tmp21_ = FALSE;
			gboolean _tmp23_ = FALSE;
			int _tmp24_ = 0;
			_tmp17_ = ret;
			ecode = (int) _tmp17_;
			_tmp18_ = ecode;
			if (_tmp18_ == GNUTLS_E_INTERRUPTED) {
				continue;
			}
			_tmp20_ = self->priv->socket;
			_tmp21_ = g_socket_get_blocking (_tmp20_);
			if (_tmp21_) {
				int _tmp22_ = 0;
				_tmp22_ = ecode;
				_tmp19_ = _tmp22_ == GNUTLS_E_AGAIN;
			} else {
				_tmp19_ = FALSE;
			}
			_tmp23_ = _tmp19_;
			if (_tmp23_) {
				continue;
			}
			_tmp24_ = ecode;
			fusion_tls_connection_handle_error (self, _tmp24_, 2, &_inner_error_);
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == G_IO_ERROR) {
					g_propagate_error (error, _inner_error_);
					return 0L;
				} else {
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return 0L;
				}
			}
			continue;
		}
		break;
	}
	result = ret;
	return result;
}
Ejemplo n.º 15
0
/*
 * IO watcher for stdout, called whenever there is data to read from the backend.
 * This is where most of the actual IO handling happens.
 */
static gboolean
io_watch_stdout (GIOChannel *source, GIOCondition condition, PasswdHandler *passwd_handler)
{
        static GString *str = NULL;     /* Persistent buffer */

        gchar           buf[BUFSIZE];           /* Temporary buffer */
        gsize           bytes_read;
        GError          *gio_error = NULL;      /* Error returned by functions */
        GError          *error = NULL;          /* Error sent to callbacks */

        gboolean        reinit = FALSE;

        /* Initialize buffer */
        if (str == NULL) {
                str = g_string_new ("");
        }

        if (g_io_channel_read_chars (source, buf, BUFSIZE, &bytes_read, &gio_error)
            != G_IO_STATUS_NORMAL) {
                g_warning ("IO Channel read error: %s", gio_error->message);
                g_error_free (gio_error);

                return TRUE;
        }

        str = g_string_append_len (str, buf, bytes_read);

        /* In which state is the backend? */
        switch (passwd_handler->backend_state) {
                case PASSWD_STATE_AUTH:
                        /* Passwd is asking for our current password */

                        if (is_string_complete (str->str, "assword: ", "failure", "wrong", "error", NULL)) {

                                if (strstr (str->str, "assword: ") != NULL) {
                                        /* Authentication successful */

                                        passwd_handler->backend_state = PASSWD_STATE_NEW;

                                        /* Trigger callback to update authentication status */
                                        if (passwd_handler->auth_cb)
                                                passwd_handler->auth_cb (passwd_handler,
                                                                         NULL,
                                                                         passwd_handler->auth_cb_data);

                                } else {
                                        /* Authentication failed */

                                        error = g_error_new_literal (PASSWD_ERROR, PASSWD_ERROR_AUTH_FAILED,
                                                                     _("Authentication failed"));

                                        passwd_handler->changing_password = FALSE;

                                        /* This error can happen both while authenticating or while changing password:
                                         * if chpasswd_cb is set, this means we're already changing password */
                                        if (passwd_handler->chpasswd_cb)
                                                passwd_handler->chpasswd_cb (passwd_handler,
                                                                             error,
                                                                             passwd_handler->chpasswd_cb_data);
                                        else if (passwd_handler->auth_cb)
                                                passwd_handler->auth_cb (passwd_handler,
                                                                         error,
                                                                         passwd_handler->auth_cb_data);

                                        g_error_free (error);
                                }

                                reinit = TRUE;
                        }
                        break;
                case PASSWD_STATE_NEW:
                        /* Passwd is asking for our new password */

                        if (is_string_complete (str->str, "assword: ", NULL)) {
                                /* Advance to next state */
                                passwd_handler->backend_state = PASSWD_STATE_RETYPE;

                                /* Pop retyped password from queue and into IO channel */
                                io_queue_pop (passwd_handler->backend_stdin_queue, passwd_handler->backend_stdin);

                                reinit = TRUE;
                        }
                        break;
                case PASSWD_STATE_RETYPE:
                        /* Passwd is asking for our retyped new password */

                        if (is_string_complete (str->str,
                                                "successfully",
                                                "short",
                                                "longer",
                                                "palindrome",
                                                "dictionary",
                                                "simple",
                                                "simplistic",
                                                "similar",
                                                "case",
                                                "different",
                                                "wrapped",
                                                "recovered",
                                                "recent",
                                                "unchanged",
                                                "match",
                                                "1 numeric or special",
                                                "failure",
                                                "DIFFERENT",
                                                "BAD PASSWORD",
                                                NULL)) {

                                if (strstr (str->str, "successfully") != NULL) {
                                        /* Hooray! */

                                        passwd_handler->backend_state = PASSWD_STATE_DONE;
                                        /* Trigger callback to update status */
                                        if (passwd_handler->chpasswd_cb)
                                                passwd_handler->chpasswd_cb (passwd_handler,
                                                                             NULL,
                                                                             passwd_handler->chpasswd_cb_data);
                                }
                                else {
                                        /* Ohnoes! */

                                        if (strstr (str->str, "recovered") != NULL) {
                                                /* What does this indicate?
                                                 * "Authentication information cannot be recovered?" from libpam? */
                                                error = g_error_new_literal (PASSWD_ERROR, PASSWD_ERROR_UNKNOWN,
                                                                             str->str);
                                        } else if (strstr (str->str, "short") != NULL ||
                                                   strstr (str->str, "longer") != NULL) {
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_REJECTED,
                                                                     _("The new password is too short"));
                                        } else if (strstr (str->str, "palindrome") != NULL ||
                                                   strstr (str->str, "simple") != NULL ||
                                                   strstr (str->str, "simplistic") != NULL ||
                                                   strstr (str->str, "dictionary") != NULL) {
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_REJECTED,
                                                                     _("The new password is too simple"));
                                        } else if (strstr (str->str, "similar") != NULL ||
                                                   strstr (str->str, "different") != NULL ||
                                                   strstr (str->str, "case") != NULL ||
                                                   strstr (str->str, "wrapped") != NULL) {
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_REJECTED,
                                                                     _("The old and new passwords are too similar"));
                                        } else if (strstr (str->str, "recent") != NULL) {
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_REJECTED,
                                                                     _("The new password has already been used recently."));
                                        } else if (strstr (str->str, "1 numeric or special") != NULL) {
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_REJECTED,
                                                                     _("The new password must contain numeric or special characters"));
                                        } else if (strstr (str->str, "unchanged") != NULL ||
                                                   strstr (str->str, "match") != NULL) {
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_REJECTED,
                                                                     _("The old and new passwords are the same"));
                                        } else if (strstr (str->str, "failure") != NULL) {
                                                /* Authentication failure */
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_AUTH_FAILED,
                                                                     _("Your password has been changed since you initially authenticated!"));
                                        }
                                        else if (strstr (str->str, "DIFFERENT")) {
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_REJECTED,
                                                                     _("The new password does not contain enough different characters"));
                                        }
                                        else {
                                                error = g_error_new (PASSWD_ERROR, PASSWD_ERROR_UNKNOWN,
                                                                     _("Unknown error"));
                                        }

                                        /* At this point, passwd might have exited, in which case
                                         * child_watch_cb should clean up for us and remove this watcher.
                                         * On some error conditions though, passwd just re-prompts us
                                         * for our new password. */
                                        passwd_handler->backend_state = PASSWD_STATE_ERR;

                                        passwd_handler->changing_password = FALSE;

                                        /* Trigger callback to update status */
                                        if (passwd_handler->chpasswd_cb)
                                                passwd_handler->chpasswd_cb (passwd_handler,
                                                                             error,
                                                                             passwd_handler->chpasswd_cb_data);

                                        g_error_free (error);

                                }

                                reinit = TRUE;

                                /* child_watch_cb should clean up for us now */
                        }
                        break;
                case PASSWD_STATE_NONE:
                        /* Passwd is not asking for anything yet */
                        if (is_string_complete (str->str, "assword: ", NULL)) {

                                /* If the user does not have a password set,
                                 * passwd will immediately ask for the new password,
                                 * so skip the AUTH phase */
                                if (is_string_complete (str->str, "new", "New", NULL)) {
                                        gchar *pw;

                                        passwd_handler->backend_state = PASSWD_STATE_NEW;

                                        /* since passwd didn't ask for our old password
                                         * in this case, simply remove it from the queue */
                                        pw = g_queue_pop_head (passwd_handler->backend_stdin_queue);
                                        g_free (pw);

                                        /* Pop the IO queue, i.e. send new password */
                                        io_queue_pop (passwd_handler->backend_stdin_queue, passwd_handler->backend_stdin);

                                } else {

                                        passwd_handler->backend_state = PASSWD_STATE_AUTH;

                                        /* Pop the IO queue, i.e. send current password */
                                        io_queue_pop (passwd_handler->backend_stdin_queue, passwd_handler->backend_stdin);
                                }

                                reinit = TRUE;
                        }
                        break;
                default:
                        /* Passwd has returned an error */
                        reinit = TRUE;
                        break;
        }

        if (reinit) {
                g_string_free (str, TRUE);
                str = NULL;
        }

        /* Continue calling us */
        return TRUE;
}
Ejemplo n.º 16
0
DaemonConfigurationServerConfiguration* daemon_configuration_server_configuration_Parse (const gchar* input, GError** error) {
	DaemonConfigurationServerConfiguration* result = NULL;
	gchar** _tmp0_;
	gchar** _tmp1_ = NULL;
	gchar** parts;
	gint parts_length1;
	gint _parts_size_;
	gboolean _tmp3_ = FALSE;
	gint _tmp4_;
	gchar** _tmp7_;
	gchar** _tmp8_ = NULL;
	gchar** channels;
	gint channels_length1;
	gint _channels_size_;
	gchar* host = NULL;
	guint16* port = NULL;
	gchar* _tmp9_ = NULL;
	guint16* _tmp10_ = NULL;
	guint16* _tmp12_;
	guint16* _tmp13_;
	guint16* _tmp16_;
	DaemonConfigurationServerConfiguration* _tmp17_ = NULL;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (input != NULL, NULL);
	_tmp1_ = _tmp0_ = g_strsplit (input, "/", 0);
	parts = _tmp1_;
	parts_length1 = _vala_array_length (_tmp0_);
	_parts_size_ = _vala_array_length (_tmp0_);
	if (parts_length1 != 2) {
		GError* _tmp2_ = NULL;
		_tmp2_ = g_error_new_literal (DAEMON_CONFIGURATION_CONFIGURATION_ERROR, DAEMON_CONFIGURATION_CONFIGURATION_ERROR_Invalid, "Invalid format");
		_inner_error_ = _tmp2_;
		if (_inner_error_->domain == DAEMON_CONFIGURATION_CONFIGURATION_ERROR) {
			g_propagate_error (error, _inner_error_);
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			return NULL;
		} else {
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp4_ = strlen (parts[0]);
	if (_tmp4_ == 0) {
		_tmp3_ = TRUE;
	} else {
		gint _tmp5_;
		_tmp5_ = strlen (parts[1]);
		_tmp3_ = _tmp5_ == 0;
	}
	if (_tmp3_) {
		GError* _tmp6_ = NULL;
		_tmp6_ = g_error_new_literal (DAEMON_CONFIGURATION_CONFIGURATION_ERROR, DAEMON_CONFIGURATION_CONFIGURATION_ERROR_Invalid, "Must specify both Server and Channel(s)");
		_inner_error_ = _tmp6_;
		if (_inner_error_->domain == DAEMON_CONFIGURATION_CONFIGURATION_ERROR) {
			g_propagate_error (error, _inner_error_);
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			return NULL;
		} else {
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp8_ = _tmp7_ = g_strsplit (parts[1], ",", 0);
	channels = _tmp8_;
	channels_length1 = _vala_array_length (_tmp7_);
	_channels_size_ = _vala_array_length (_tmp7_);
	daemon_helpers_typehelper_ParseHostAndPort (parts[0], &_tmp9_, &_tmp10_, &_inner_error_);
	_g_free0 (host);
	host = _tmp9_;
	_g_free0 (port);
	port = _tmp10_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == DAEMON_HELPERS_DAEMON_ERROR) {
			goto __catch27_daemon_helpers_daemon_error;
		}
		_g_free0 (port);
		_g_free0 (host);
		channels = (_vala_array_free (channels, channels_length1, (GDestroyNotify) g_free), NULL);
		parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
		g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	goto __finally27;
	__catch27_daemon_helpers_daemon_error:
	{
		GError * _error_;
		GError* _tmp11_ = NULL;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp11_ = g_error_new_literal (DAEMON_CONFIGURATION_CONFIGURATION_ERROR, DAEMON_CONFIGURATION_CONFIGURATION_ERROR_Invalid, _error_->message);
		_inner_error_ = _tmp11_;
		_g_error_free0 (_error_);
		goto __finally27;
	}
	__finally27:
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == DAEMON_CONFIGURATION_CONFIGURATION_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (port);
			_g_free0 (host);
			channels = (_vala_array_free (channels, channels_length1, (GDestroyNotify) g_free), NULL);
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			return NULL;
		} else {
			_g_free0 (port);
			_g_free0 (host);
			channels = (_vala_array_free (channels, channels_length1, (GDestroyNotify) g_free), NULL);
			parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp12_ = __uint16_dup0 (port);
	_tmp13_ = _tmp12_;
	if (_tmp13_ == NULL) {
		gint _tmp14_;
		guint16* _tmp15_;
		_tmp14_ = 6667;
		_tmp15_ = __uint16_dup0 (&_tmp14_);
		_g_free0 (_tmp13_);
		_tmp13_ = _tmp15_;
	}
	_tmp16_ = __uint16_dup0 (_tmp13_);
	_g_free0 (port);
	port = _tmp16_;
	_tmp17_ = daemon_configuration_server_configuration_new (host, *port, channels, channels_length1);
	result = _tmp17_;
	_g_free0 (_tmp13_);
	_g_free0 (port);
	_g_free0 (host);
	channels = (_vala_array_free (channels, channels_length1, (GDestroyNotify) g_free), NULL);
	parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
	return result;
}
Ejemplo n.º 17
0
static GthImage *
flickr_thumbnail_loader (GInputStream  *istream,
			 GthFileData   *file_data,
			 int            requested_size,
			 int           *original_width,
			 int           *original_height,
			 gboolean      *loaded_original,
			 gpointer       user_data,
			 GCancellable  *cancellable,
		         GError       **error)
{
	GthImage       *image = NULL;
	GthThumbLoader *thumb_loader = user_data;
	FlickrPhoto    *photo;
	const char     *uri = NULL;

	photo = (FlickrPhoto *) g_file_info_get_attribute_object (file_data->info, "flickr::object");
	requested_size = gth_thumb_loader_get_requested_size (thumb_loader);
	if (requested_size == FLICKR_SIZE_SMALL_SQUARE)
		uri = photo->url[FLICKR_URL_SQ];
	else if (requested_size == FLICKR_SIZE_THUMBNAIL)
		uri = photo->url[FLICKR_URL_T];
	else if (requested_size == FLICKR_SIZE_SMALL)
		uri = photo->url[FLICKR_URL_S];
	else if (requested_size == FLICKR_SIZE_MEDIUM)
		uri = photo->url[FLICKR_URL_M];

	if (uri == NULL)
		uri = photo->url[FLICKR_URL_O];

	if (uri != NULL) {
		GFile *file;
		void  *buffer;
		gsize  size;

		file = g_file_new_for_uri (uri);
		if (_g_file_load_in_buffer (file, &buffer, &size, cancellable, error)) {
			GInputStream *stream;
			GdkPixbuf    *pixbuf;

			stream = g_memory_input_stream_new_from_data (buffer, size, g_free);
			pixbuf = gdk_pixbuf_new_from_stream (stream, cancellable, error);
			if (pixbuf != NULL) {
				GdkPixbuf *rotated;

				rotated = gdk_pixbuf_apply_embedded_orientation (pixbuf);
				g_object_unref (pixbuf);
				pixbuf = rotated;

				image = gth_image_new_for_pixbuf (pixbuf);
			}

			g_object_unref (pixbuf);
			g_object_unref (stream);
		}

		g_object_unref (file);
	}
	else
		*error = g_error_new_literal (GTH_ERROR, 0, "cannot generate the thumbnail");

	return image;
}
static void
keyring_find_secrets_cb (GObject *source,
                         GAsyncResult *result,
                         gpointer user_data)
{
	Request *r = user_data;
	GError *error = NULL;
	GError *search_error = NULL;
	const char *connection_id = NULL;
	GHashTable *secrets = NULL, *settings = NULL;
	GList *list = NULL;
	GList *iter;
	gboolean hint_found = FALSE, ask = FALSE;

	r->keyring_calls--;
	if (g_cancellable_is_cancelled (r->cancellable)) {
		/* Callback already called by NM or dispose */
		request_free (r);
		return;
	}

	list = secret_service_search_finish (NULL, result, &search_error);
	connection_id = nm_connection_get_id (r->connection);

	if (g_error_matches (search_error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
		error = g_error_new_literal (NM_SECRET_AGENT_ERROR,
		                             NM_SECRET_AGENT_ERROR_USER_CANCELED,
		                             "The secrets request was canceled by the user");
		g_error_free (search_error);
		goto done;
	} else if (search_error) {
		error = g_error_new (NM_SECRET_AGENT_ERROR,
		                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
		                     "%s.%d - failed to read secrets from keyring (%s)",
		                     __FILE__, __LINE__, search_error->message);
		g_error_free (search_error);
		goto done;
	}

	/* Only ask if we're allowed to, so that eg a connection editor which
	 * requests secrets for its UI, for a connection which doesn't have any
	 * secrets yet, doesn't trigger the applet secrets dialog.
	 */
	if (   (r->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION)
	    && g_list_length (list) == 0) {
		g_message ("No keyring secrets found for %s/%s; asking user.", connection_id, r->setting_name);
		ask_for_secrets (r);
		return;
	}

	secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);

	/* Extract the secrets from the list of matching keyring items */
	for (iter = list; iter != NULL; iter = g_list_next (iter)) {
		SecretItem *item = iter->data;
		SecretValue *secret;
		const char *key_name;
		GHashTable *attributes;

		secret = secret_item_get_secret (item);
		if (secret) {
			attributes = secret_item_get_attributes (item);
			key_name = g_hash_table_lookup (attributes, KEYRING_SK_TAG);
			if (!key_name) {
				g_hash_table_unref (attributes);
				secret_value_unref (secret);
				continue;
			}

			g_hash_table_insert (secrets, g_strdup (key_name),
			                     string_to_gvalue (secret_value_get (secret, NULL)));

			/* See if this property matches a given hint */
			if (r->hints && r->hints[0]) {
				if (!g_strcmp0 (r->hints[0], key_name) || !g_strcmp0 (r->hints[1], key_name))
					hint_found = TRUE;
			}

			g_hash_table_unref (attributes);
			secret_value_unref (secret);
			break;
		}
	}

	/* If there were hints, and none of the hints were returned by the keyring,
	 * get some new secrets.
	 */
	if (r->flags) {
		if (r->hints && r->hints[0] && !hint_found)
			ask = TRUE;
		else if (r->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW) {
			g_message ("New secrets for %s/%s requested; ask the user", connection_id, r->setting_name);
			ask = TRUE;
		} else if (   (r->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION)
			       && is_connection_always_ask (r->connection))
			ask = TRUE;
	}

	/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
	 * will contain all the individual settings hashes.
	 */
	settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy);
	g_hash_table_insert (settings, g_strdup (r->setting_name), secrets);

done:
	g_list_free_full (list, g_object_unref);
	if (ask) {
		GHashTableIter hash_iter;
		const char *setting_name;
		GHashTable *setting_hash;

		/* Stuff all the found secrets into the connection for the UI to use */
		g_hash_table_iter_init (&hash_iter, settings);
		while (g_hash_table_iter_next (&hash_iter,
		                               (gpointer *) &setting_name,
		                               (gpointer *) &setting_hash)) {
			nm_connection_update_secrets (r->connection,
				                          setting_name,
				                          setting_hash,
				                          NULL);
		}

		ask_for_secrets (r);
	} else {
		/* Otherwise send the secrets back to NetworkManager */
		r->get_callback (NM_SECRET_AGENT (r->agent), r->connection, error ? NULL : settings, error, r->callback_data);
		request_free (r);
	}

	if (settings)
		g_hash_table_destroy (settings);
	g_clear_error (&error);
}
Ejemplo n.º 19
0
void
dlg_export_to_picasaweb (GthBrowser *browser,
		         GList      *file_list)
{
	DialogData       *data;
	GtkTreeSelection *selection;
	GList            *scan;
	int               n_total;
	goffset           total_size;
	char             *total_size_formatted;
	char             *text;

	data = g_new0 (DialogData, 1);
	data->browser = browser;
	data->settings = g_settings_new (GTHUMB_PICASAWEB_SCHEMA);
	data->location = gth_file_data_dup (gth_browser_get_location_data (browser));
	data->builder = _gtk_builder_new_from_file ("export-to-picasaweb.ui", "picasaweb");
	data->dialog = _gtk_builder_get_widget (data->builder, "export_dialog");
	data->cancellable = g_cancellable_new ();

	{
		GtkCellLayout   *cell_layout;
		GtkCellRenderer *renderer;

		cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("name_treeviewcolumn"));

		renderer = gtk_cell_renderer_pixbuf_new ();
		gtk_cell_layout_pack_start (cell_layout, renderer, FALSE);
		gtk_cell_layout_set_attributes (cell_layout, renderer,
						"icon-name", ALBUM_ICON_COLUMN,
						NULL);

		renderer = gtk_cell_renderer_text_new ();
		gtk_cell_layout_pack_start (cell_layout, renderer, TRUE);
		gtk_cell_layout_set_attributes (cell_layout, renderer,
						"text", ALBUM_NAME_COLUMN,
						NULL);

		renderer = gtk_cell_renderer_pixbuf_new ();
		gtk_cell_layout_pack_start (cell_layout, renderer, FALSE);
		gtk_cell_layout_set_attributes (cell_layout, renderer,
						"icon-name", ALBUM_EMBLEM_COLUMN,
						NULL);
	}

	_gtk_window_resize_to_fit_screen_height (data->dialog, 500);

	data->file_list = NULL;
	n_total = 0;
	total_size = 0;
	for (scan = file_list; scan; scan = scan->next) {
		GthFileData *file_data = scan->data;
		const char  *mime_type;

		mime_type = gth_file_data_get_mime_type (file_data);
		if (g_content_type_equals (mime_type, "image/bmp")
		    || g_content_type_equals (mime_type, "image/gif")
		    || g_content_type_equals (mime_type, "image/jpeg")
		    || g_content_type_equals (mime_type, "image/png"))
		{
			total_size += g_file_info_get_size (file_data->info);
			n_total++;
			data->file_list = g_list_prepend (data->file_list, g_object_ref (file_data));
		}
	}
	data->file_list = g_list_reverse (data->file_list);

	if (data->file_list == NULL) {
		GError *error;

		gth_task_dialog (GTH_TASK (data->service), TRUE, NULL);

		error = g_error_new_literal (GTH_ERROR, GTH_ERROR_GENERIC, _("No valid file selected."));
		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not export the files"), error);
		g_clear_error (&error);
		destroy_dialog (data);
		return;
	}

	total_size_formatted = g_format_size (total_size);
	text = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_total), n_total, total_size_formatted);
	gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text);
	g_free (text);
	g_free (total_size_formatted);

	/* Set the widget data */

	data->list_view = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NO_SELECTION, FALSE);
	gth_file_list_set_thumb_size (GTH_FILE_LIST (data->list_view), 112);
	gth_file_list_enable_thumbs (GTH_FILE_LIST (data->list_view), TRUE);
	gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->list_view), TRUE);
	gth_file_list_set_caption (GTH_FILE_LIST (data->list_view), "none");
	gth_file_list_set_sort_func (GTH_FILE_LIST (data->list_view), gth_main_get_sort_type ("file::name")->cmp_func, FALSE);
	gtk_widget_show (data->list_view);
	gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->list_view, TRUE, TRUE, 0);
	gth_file_list_set_files (GTH_FILE_LIST (data->list_view), data->file_list);

	gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("album_liststore")), ALBUM_NAME_COLUMN, GTK_SORT_ASCENDING);

	gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), FALSE);

	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")),
				      g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH) != -1);

	_gtk_combo_box_add_image_sizes (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")),
					g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH),
					g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_HEIGHT));

	/* Set the signals handlers. */

	g_signal_connect (data->dialog,
			  "delete-event",
			  G_CALLBACK (gtk_true),
			  NULL);
	g_signal_connect (data->dialog,
			  "response",
			  G_CALLBACK (export_dialog_response_cb),
			  data);
	g_signal_connect (GET_WIDGET ("add_album_button"),
			  "clicked",
			  G_CALLBACK (add_album_button_clicked_cb),
			  data);
	g_signal_connect (GET_WIDGET ("edit_accounts_button"),
			  "clicked",
			  G_CALLBACK (edit_accounts_button_clicked_cb),
			  data);
	g_signal_connect (GET_WIDGET ("account_combobox"),
			  "changed",
			  G_CALLBACK (account_combobox_changed_cb),
			  data);
	g_signal_connect (GET_WIDGET ("resize_checkbutton"),
			  "toggled",
			  G_CALLBACK (resize_checkbutton_toggled_cb),
			  data);

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("albums_treeview")));
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
	g_signal_connect (selection,
			  "changed",
			  G_CALLBACK (albums_treeview_selection_changed_cb),
			  data);

	update_sensitivity (data);

	data->service = picasa_web_service_new (data->cancellable,
						GTK_WIDGET (data->browser),
						data->dialog);
	g_signal_connect (data->service,
			  "account-ready",
			  G_CALLBACK (service_account_ready_cb),
			  data);
	g_signal_connect (data->service,
			  "accounts-changed",
			  G_CALLBACK (service_accounts_changed_cb),
			  data);

	data->progress_dialog = gth_progress_dialog_new (GTK_WINDOW (data->browser));
	gth_progress_dialog_add_task (GTH_PROGRESS_DIALOG (data->progress_dialog), GTH_TASK (data->service));

	web_service_autoconnect (WEB_SERVICE (data->service));
}
static void
get_secrets (NMSecretAgent *agent,
             NMConnection *connection,
             const char *connection_path,
             const char *setting_name,
             const char **hints,
             guint32 flags,
             NMSecretAgentGetSecretsFunc callback,
             gpointer callback_data)
{
	AppletAgentPrivate *priv = APPLET_AGENT_GET_PRIVATE (agent);
	Request *r;
	GError *error = NULL;
	NMSettingConnection *s_con;
	NMSetting *setting;
	const char *uuid, *ctype;
	GHashTable *attrs;

	setting = nm_connection_get_setting_by_name (connection, setting_name);
	if (!setting) {
		error = g_error_new (NM_SECRET_AGENT_ERROR,
		                     NM_SECRET_AGENT_ERROR_INVALID_CONNECTION,
		                     "%s.%d - Connection didn't have requested setting '%s'.",
		                     __FILE__, __LINE__, setting_name);
		callback (agent, connection, NULL, error, callback_data);
		g_error_free (error);
		return;
	}

	uuid = nm_connection_get_uuid (connection);

	s_con = nm_connection_get_setting_connection (connection);
	g_assert (s_con);
	ctype = nm_setting_connection_get_connection_type (s_con);

	if (!uuid || !ctype) {
		error = g_error_new (NM_SECRET_AGENT_ERROR,
		                     NM_SECRET_AGENT_ERROR_INVALID_CONNECTION,
		                     "%s.%d - Connection didn't have required UUID.",
		                     __FILE__, __LINE__);
		callback (agent, connection, NULL, error, callback_data);
		g_error_free (error);
		return;
	}

	/* Track the secrets request */
	r = request_new (agent, connection, connection_path, setting_name, hints, flags, callback, NULL, NULL, callback_data);
	g_hash_table_insert (priv->requests, GUINT_TO_POINTER (r->id), r);

	/* VPN passwords are handled by the VPN plugin's auth dialog */
	if (!strcmp (ctype, NM_SETTING_VPN_SETTING_NAME)) {
		ask_for_secrets (r);
		return;
	}

	/* Only handle non-VPN secrets if we're supposed to */
	if (priv->vpn_only == TRUE) {
		error = g_error_new_literal (NM_SECRET_AGENT_ERROR,
		                             NM_SECRET_AGENT_ERROR_NO_SECRETS,
		                             "Only handling VPN secrets at this time.");
		callback (agent, connection, NULL, error, callback_data);
		g_error_free (error);
		return;
	}

	/* For everything else we scrape the keyring for secrets first, and ask
	 * later if required.
	 */
	attrs = secret_attributes_build (&network_manager_secret_schema,
	                                 KEYRING_UUID_TAG, uuid,
	                                 KEYRING_SN_TAG, setting_name,
	                                 NULL);

	secret_service_search (NULL, &network_manager_secret_schema, attrs,
	                       SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
	                       r->cancellable, keyring_find_secrets_cb, r);

	r->keyring_calls++;
	g_hash_table_unref (attrs);
}
Ejemplo n.º 21
0
static void
korva_upnp_file_server_on_metadata_query_run_done (GObject      *sender,
                                                   GAsyncResult *res,
                                                   gpointer      user_data)
{
    QueryMetaData *data = (QueryMetaData *) user_data;
    GSimpleAsyncResult *result = data->result;
    HostFileResult *result_data;
    guint port;
    GError *error = NULL;

    if (!korva_upnp_metadata_query_run_finish (KORVA_UPNP_METADATA_QUERY (sender),
                                               res,
                                               &error)) {
        if (error->domain != KORVA_CONTROLLER1_ERROR) {
            int code;
            code = error->code;

            g_error_free (error);
            error = NULL;
            if (code == G_IO_ERROR_NOT_FOUND) {
                error = g_error_new_literal (KORVA_CONTROLLER1_ERROR,
                                             KORVA_CONTROLLER1_ERROR_FILE_NOT_FOUND,
                                             "File not found");
            } else {
                error = g_error_new_literal (KORVA_CONTROLLER1_ERROR,
                                             KORVA_CONTROLLER1_ERROR_NOT_ACCESSIBLE,
                                             "File not accessible");
            }
        }

        g_simple_async_result_take_error (data->result, error);
        g_object_unref (data->data);

        goto out;
    }

    g_signal_connect_swapped (data->data,
                              "timeout",
                              G_CALLBACK (korva_upnp_file_server_on_host_data_timeout),
                              data->self);

    g_hash_table_insert (data->self->priv->host_data,
                         korva_upnp_host_data_get_file (data->data),
                         data->data);
    g_hash_table_insert (data->self->priv->id_map,
                         korva_upnp_host_data_get_id (data->data),
                         korva_upnp_host_data_get_file (data->data));

    port = soup_server_get_port (data->self->priv->http_server);

    result_data = g_new0 (HostFileResult, 1);
    result_data->params = korva_upnp_host_data_get_meta_data (data->data);
    result_data->uri = korva_upnp_host_data_get_uri (data->data, data->iface, port);

    g_simple_async_result_set_op_res_gpointer (result, result_data, g_free);

    data->result = NULL;

out:
    g_free (data->iface);
    data->iface = NULL;

    g_simple_async_result_complete_in_idle (result);
    g_object_unref (result);
    g_object_unref (sender);
    g_slice_free (QueryMetaData, data);
}
Ejemplo n.º 22
0
int
main (int    argc,
      char **argv)
{
  GCancellable *cancellable = g_cancellable_new ();
  RpmOstreeCommand *command;
  int exit_status = EXIT_SUCCESS;
  int in, out;
  const char *command_name = NULL;
  g_autofree char *prgname = NULL;
  GError *local_error = NULL;

  /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */
  g_setenv ("GIO_USE_VFS", "local", TRUE);
  g_set_prgname (argv[0]);

  setlocale (LC_ALL, "");
  
  /*
   * Parse the global options. We rearrange the options as
   * necessary, in order to pass relevant options through
   * to the commands, but also have them take effect globally.
   */
  for (in = 1, out = 1; in < argc; in++, out++)
    {
      /* The non-option is the command, take it out of the arguments */
      if (argv[in][0] != '-')
        {
          if (command_name == NULL)
            {
              command_name = argv[in];
              out--;
              continue;
            }
        }

      else if (g_str_equal (argv[in], "--"))
        {
          break;
        }

      argv[out] = argv[in];
    }

  argc = out;

  g_unix_signal_add (SIGINT, on_sigint, cancellable);
  g_unix_signal_add (SIGTERM, on_sigint, cancellable);
  g_unix_signal_add (SIGHUP, on_sigint, cancellable);

  /* Keep the "rpm" command working for backward-compatibility. */
  if (g_strcmp0 (command_name, "rpm") == 0)
    command_name = "db";

  command = lookup_command_of_type (supported_commands, command_name, NULL);
  if (!command)
    command = lookup_command_of_type (legacy_alias_commands, command_name, NULL);

  if (!command)
    command = lookup_command_of_type (preview_commands, command_name, "a preview");

  if (!command)
    command = lookup_command_of_type (experimental_commands, command_name, "an experimental");

  if (!command)
    {
      g_autoptr(GOptionContext) context = option_context_new_with_commands ();
      g_autofree char *help = NULL;

      /* This will not return for some options (e.g. --version). */
      (void) rpmostree_option_context_parse (context, NULL, &argc, &argv,
                                             RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD,
                                             NULL, NULL, NULL);
      if (command_name == NULL)
        {
          local_error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
                                             "No command specified");
        }
      else
        {
          local_error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
                                     "Unknown command '%s'", command_name);
        }

      help = g_option_context_get_help (context, FALSE, NULL);
      g_printerr ("%s", help);
      exit_status = EXIT_FAILURE;

      goto out;
    }

  prgname = g_strdup_printf ("%s %s", g_get_prgname (), command_name);
  g_set_prgname (prgname);

  exit_status = command->fn (argc, argv, cancellable, &local_error);

 out:
  if (local_error != NULL)
    {
      int is_tty = isatty (1);
      const char *prefix = "";
      const char *suffix = "";
      if (is_tty)
        {
          prefix = "\x1b[31m\x1b[1m"; /* red, bold */
          suffix = "\x1b[22m\x1b[0m"; /* bold off, color reset */
        }
      g_dbus_error_strip_remote_error (local_error);
      g_printerr ("%serror: %s%s\n", prefix, suffix, local_error->message);
      g_error_free (local_error);

      /* Print a warning if the exit status indicates success when we
       * actually had an error, so it gets reported and fixed quickly. */
      g_warn_if_fail (exit_status != EXIT_SUCCESS);
    }

  return exit_status;
}
Ejemplo n.º 23
0
FlowShunt *
flow_ssh_master_run_command (FlowSshMaster *ssh_master, const gchar *remote_command, GError **error)
{
  FlowSshMasterPrivate *priv;
  gchar *remote_name = NULL;
  gint remote_port;
  gchar *cmd = NULL;
  FlowShunt *shunt = NULL;

  g_return_val_if_fail (FLOW_IS_SSH_MASTER (ssh_master), NULL);

  priv = ssh_master->priv;

  g_mutex_lock (priv->mutex);

  if (!priv->is_connected)
  {
    GError *my_error = g_error_new_literal (FLOW_SSH_DOMAIN_QUARK, FLOW_SSH_MASTER_NOT_CONNECTED,
                                            "SSH master is not connected");
    g_propagate_error (error, my_error);
    goto out;
  }

  remote_port = flow_ip_service_get_port (priv->remote_ip_service);
  remote_name = flow_ip_service_get_name (priv->remote_ip_service);
  g_assert (remote_name != NULL);

  if (is_master_supported (ssh_master))
  {
    if (remote_port > 0)
    {
      cmd = g_strdup_printf ("ssh " EXTRA_SSH_OP_OPTIONS " -o 'ControlPath %s' -p %d %s%s%s %s",
                             priv->control_path,
                             remote_port,
                             priv->remote_user ? priv->remote_user : "",
                             priv->remote_user ? "@" : "",
                             remote_name,
                             remote_command);
    }
    else
    {
      cmd = g_strdup_printf ("ssh " EXTRA_SSH_OP_OPTIONS " -o 'ControlPath %s' %s%s%s %s",
                             priv->control_path,
                             priv->remote_user ? priv->remote_user : "",
                             priv->remote_user ? "@" : "",
                             remote_name,
                             remote_command);
    }
  }
  else
  {
    if (remote_port > 0)
      cmd = g_strdup_printf ("ssh " EXTRA_SSH_OP_OPTIONS " -p %d %s%s%s %s",
                             remote_port,
                             priv->remote_user ? priv->remote_user : "",
                             priv->remote_user ? "@" : "",
                             remote_name,
                             remote_command);
    else
      cmd = g_strdup_printf ("ssh " EXTRA_SSH_OP_OPTIONS " %s%s%s %s",
                             priv->remote_user ? priv->remote_user : "",
                             priv->remote_user ? "@" : "",
                             remote_name,
                             remote_command);
  }

  shunt = flow_spawn_command_line (cmd);

out:
  g_mutex_unlock (priv->mutex);
  g_free (cmd);
  g_free (remote_name);
  return shunt;
}
Ejemplo n.º 24
0
Archivo: m_file.c Proyecto: camgunz/d2k
static void set_file_error(GQuark domain, gint code, gchar *message) {
  if (file_error)
    g_clear_error(&file_error);

  g_propagate_error(&file_error, g_error_new_literal(domain, code, message));
}
Ejemplo n.º 25
0
GimpValueArray *
gimp_pdb_execute_procedure_by_name (GimpPDB       *pdb,
                                    GimpContext   *context,
                                    GimpProgress  *progress,
                                    GError       **error,
                                    const gchar   *name,
                                    ...)
{
  GimpProcedure  *procedure;
  GimpValueArray *args;
  GimpValueArray *return_vals;
  va_list         va_args;
  gint            i;

  g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
  g_return_val_if_fail (name != NULL, NULL);

  procedure = gimp_pdb_lookup_procedure (pdb, name);

  if (! procedure)
    {
      GError *pdb_error = g_error_new (GIMP_PDB_ERROR,
                                       GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND,
                                       _("Procedure '%s' not found"), name);

      return_vals = gimp_procedure_get_return_values (NULL, FALSE, pdb_error);
      g_propagate_error (error, pdb_error);

      return return_vals;
    }

  args = gimp_procedure_get_arguments (procedure);

  va_start (va_args, name);

  for (i = 0; i < procedure->num_args; i++)
    {
      GValue *value;
      GType   arg_type;
      gchar  *error_msg = NULL;

      arg_type = va_arg (va_args, GType);

      if (arg_type == G_TYPE_NONE)
        break;

      value = gimp_value_array_index (args, i);

      if (arg_type != G_VALUE_TYPE (value))
        {
          GError      *pdb_error;
          const gchar *expected = g_type_name (G_VALUE_TYPE (value));
          const gchar *got      = g_type_name (arg_type);

          gimp_value_array_unref (args);

          pdb_error = g_error_new (GIMP_PDB_ERROR,
                                   GIMP_PDB_ERROR_INVALID_ARGUMENT,
                                   _("Procedure '%s' has been called with a "
                                     "wrong type for argument #%d. "
                                     "Expected %s, got %s."),
                                   gimp_object_get_name (procedure),
                                   i + 1, expected, got);

          return_vals = gimp_procedure_get_return_values (procedure,
                                                          FALSE, pdb_error);
          g_propagate_error (error, pdb_error);

          va_end (va_args);

          return return_vals;
        }

      G_VALUE_COLLECT (value, va_args, G_VALUE_NOCOPY_CONTENTS, &error_msg);

      if (error_msg)
        {
          GError *pdb_error = g_error_new_literal (GIMP_PDB_ERROR,
                                                   GIMP_PDB_ERROR_INTERNAL_ERROR,
                                                   error_msg);
          g_warning ("%s: %s", G_STRFUNC, error_msg);
          g_free (error_msg);

          gimp_value_array_unref (args);

          return_vals = gimp_procedure_get_return_values (procedure,
                                                          FALSE, pdb_error);
          g_propagate_error (error, pdb_error);

          va_end (va_args);

          return return_vals;
        }
    }

  va_end (va_args);

  return_vals = gimp_pdb_execute_procedure_by_name_args (pdb, context,
                                                         progress, error,
                                                         name, args);

  gimp_value_array_unref (args);

  return return_vals;
}
Ejemplo n.º 26
0
static void skk_map_file_load (SkkMapFile* self, const gchar* rule, const gchar* type, const gchar* name, GeeSet* included, GError** error) {
	const gchar* _tmp0_;
	SkkRuleMetadata* _tmp1_ = NULL;
	SkkRuleMetadata* metadata;
	SkkRuleMetadata* _tmp2_;
	SkkRuleMetadata* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_ = NULL;
	gchar* _tmp12_;
	gchar* filename;
	const gchar* _tmp13_;
	gboolean _tmp14_ = FALSE;
	JsonParser* _tmp17_;
	JsonParser* parser;
	JsonParser* _tmp30_;
	JsonNode* _tmp31_ = NULL;
	JsonNode* _tmp32_;
	JsonNode* root;
	JsonNode* _tmp33_;
	JsonNodeType _tmp34_ = 0;
	JsonNode* _tmp36_;
	JsonObject* _tmp37_ = NULL;
	JsonObject* _tmp38_;
	JsonObject* object;
	JsonNode* member = NULL;
	JsonObject* _tmp39_;
	gboolean _tmp40_ = FALSE;
	JsonObject* _tmp83_;
	gboolean _tmp84_ = FALSE;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (rule != NULL);
	g_return_if_fail (type != NULL);
	g_return_if_fail (name != NULL);
	g_return_if_fail (included != NULL);
	_tmp0_ = rule;
	_tmp1_ = skk_rule_find_rule (_tmp0_);
	metadata = _tmp1_;
	_tmp2_ = metadata;
	if (_tmp2_ == NULL) {
		const gchar* _tmp3_;
		GError* _tmp4_;
		_tmp3_ = rule;
		_tmp4_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "can't find rule %s", _tmp3_);
		_inner_error_ = _tmp4_;
		if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error_);
			_skk_rule_metadata_free0 (metadata);
			return;
		} else {
			_skk_rule_metadata_free0 (metadata);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp5_ = metadata;
	_tmp6_ = (*_tmp5_).base_dir;
	_tmp7_ = type;
	_tmp8_ = name;
	_tmp9_ = g_strconcat (_tmp8_, ".json", NULL);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_build_filename (_tmp6_, _tmp7_, _tmp10_, NULL);
	_tmp12_ = _tmp11_;
	_g_free0 (_tmp10_);
	filename = _tmp12_;
	_tmp13_ = filename;
	_tmp14_ = g_file_test (_tmp13_, G_FILE_TEST_EXISTS);
	if (!_tmp14_) {
		const gchar* _tmp15_;
		GError* _tmp16_;
		_tmp15_ = filename;
		_tmp16_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "no such file %s", _tmp15_);
		_inner_error_ = _tmp16_;
		if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			return;
		} else {
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp17_ = json_parser_new ();
	parser = _tmp17_;
	{
		JsonParser* _tmp18_;
		const gchar* _tmp19_;
		gboolean _tmp20_ = FALSE;
		gboolean _tmp21_;
		_tmp18_ = parser;
		_tmp19_ = filename;
		_tmp20_ = json_parser_load_from_file (_tmp18_, _tmp19_, &_inner_error_);
		_tmp21_ = _tmp20_;
		if (_inner_error_ != NULL) {
			goto __catch28_g_error;
		}
		if (!_tmp21_) {
			GError* _tmp22_;
			_tmp22_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "");
			_inner_error_ = _tmp22_;
			goto __catch28_g_error;
		}
	}
	goto __finally28;
	__catch28_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp23_;
		GError* _tmp24_;
		const gchar* _tmp25_;
		gchar* _tmp26_ = NULL;
		gchar* _tmp27_;
		GError* _tmp28_;
		GError* _tmp29_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp23_ = filename;
		_tmp24_ = e;
		_tmp25_ = _tmp24_->message;
		_tmp26_ = g_strdup_printf ("can't load %s: %s", _tmp23_, _tmp25_);
		_tmp27_ = _tmp26_;
		_tmp28_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, _tmp27_);
		_tmp29_ = _tmp28_;
		_g_free0 (_tmp27_);
		_inner_error_ = _tmp29_;
		_g_error_free0 (e);
		goto __finally28;
	}
	__finally28:
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			return;
		} else {
			_g_object_unref0 (parser);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp30_ = parser;
	_tmp31_ = json_parser_get_root (_tmp30_);
	_tmp32_ = __vala_JsonNode_copy0 (_tmp31_);
	root = _tmp32_;
	_tmp33_ = root;
	_tmp34_ = json_node_get_node_type (_tmp33_);
	if (_tmp34_ != JSON_NODE_OBJECT) {
		GError* _tmp35_;
		_tmp35_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "root element must be an object");
		_inner_error_ = _tmp35_;
		if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
			g_propagate_error (error, _inner_error_);
			__vala_JsonNode_free0 (root);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			return;
		} else {
			__vala_JsonNode_free0 (root);
			_g_object_unref0 (parser);
			_g_free0 (filename);
			_skk_rule_metadata_free0 (metadata);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp36_ = root;
	_tmp37_ = json_node_get_object (_tmp36_);
	_tmp38_ = __vala_JsonObject_copy0 (_tmp37_);
	object = _tmp38_;
	_tmp39_ = object;
	_tmp40_ = json_object_has_member (_tmp39_, "include");
	if (_tmp40_) {
		JsonObject* _tmp41_;
		JsonNode* _tmp42_ = NULL;
		JsonNode* _tmp43_;
		JsonNode* _tmp44_;
		JsonNodeType _tmp45_ = 0;
		JsonNode* _tmp47_;
		JsonArray* _tmp48_ = NULL;
		JsonArray* _tmp49_;
		JsonArray* include;
		JsonArray* _tmp50_;
		GList* _tmp51_ = NULL;
		GList* elements;
		GList* _tmp52_;
		_tmp41_ = object;
		_tmp42_ = json_object_get_member (_tmp41_, "include");
		_tmp43_ = __vala_JsonNode_copy0 (_tmp42_);
		__vala_JsonNode_free0 (member);
		member = _tmp43_;
		_tmp44_ = member;
		_tmp45_ = json_node_get_node_type (_tmp44_);
		if (_tmp45_ != JSON_NODE_ARRAY) {
			GError* _tmp46_;
			_tmp46_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "\"include\" element must be an array");
			_inner_error_ = _tmp46_;
			if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
				g_propagate_error (error, _inner_error_);
				__vala_JsonNode_free0 (member);
				__vala_JsonObject_free0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				_skk_rule_metadata_free0 (metadata);
				return;
			} else {
				__vala_JsonNode_free0 (member);
				__vala_JsonObject_free0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				_skk_rule_metadata_free0 (metadata);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
		_tmp47_ = member;
		_tmp48_ = json_node_get_array (_tmp47_);
		_tmp49_ = __vala_JsonArray_copy0 (_tmp48_);
		include = _tmp49_;
		_tmp50_ = include;
		_tmp51_ = json_array_get_elements (_tmp50_);
		elements = _tmp51_;
		_tmp52_ = elements;
		{
			GList* element_collection = NULL;
			GList* element_it = NULL;
			element_collection = _tmp52_;
			for (element_it = element_collection; element_it != NULL; element_it = element_it->next) {
				JsonNode* element = NULL;
				element = (JsonNode*) element_it->data;
				{
					JsonNode* _tmp53_;
					const gchar* _tmp54_ = NULL;
					gchar* _tmp55_;
					gchar* parent;
					GeeSet* _tmp56_;
					const gchar* _tmp57_;
					gboolean _tmp58_ = FALSE;
					const gchar* _tmp61_;
					gint _tmp62_ = 0;
					gint index;
					gint _tmp63_;
					GeeSet* _tmp81_;
					const gchar* _tmp82_;
					_tmp53_ = element;
					_tmp54_ = json_node_get_string (_tmp53_);
					_tmp55_ = g_strdup (_tmp54_);
					parent = _tmp55_;
					_tmp56_ = included;
					_tmp57_ = parent;
					_tmp58_ = gee_collection_contains ((GeeCollection*) _tmp56_, _tmp57_);
					if (_tmp58_) {
						const gchar* _tmp59_;
						GError* _tmp60_;
						_tmp59_ = parent;
						_tmp60_ = g_error_new (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "found circular include of %s", _tmp59_);
						_inner_error_ = _tmp60_;
						if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
							g_propagate_error (error, _inner_error_);
							_g_free0 (parent);
							_g_list_free0 (elements);
							__vala_JsonArray_free0 (include);
							__vala_JsonNode_free0 (member);
							__vala_JsonObject_free0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							_skk_rule_metadata_free0 (metadata);
							return;
						} else {
							_g_free0 (parent);
							_g_list_free0 (elements);
							__vala_JsonArray_free0 (include);
							__vala_JsonNode_free0 (member);
							__vala_JsonObject_free0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							_skk_rule_metadata_free0 (metadata);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
							g_clear_error (&_inner_error_);
							return;
						}
					}
					_tmp61_ = parent;
					_tmp62_ = string_index_of (_tmp61_, "/", 0);
					index = _tmp62_;
					_tmp63_ = index;
					if (_tmp63_ < 0) {
						const gchar* _tmp64_;
						const gchar* _tmp65_;
						const gchar* _tmp66_;
						GeeSet* _tmp67_;
						_tmp64_ = rule;
						_tmp65_ = type;
						_tmp66_ = parent;
						_tmp67_ = included;
						skk_map_file_load (self, _tmp64_, _tmp65_, _tmp66_, _tmp67_, &_inner_error_);
						if (_inner_error_ != NULL) {
							if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
								g_propagate_error (error, _inner_error_);
								_g_free0 (parent);
								_g_list_free0 (elements);
								__vala_JsonArray_free0 (include);
								__vala_JsonNode_free0 (member);
								__vala_JsonObject_free0 (object);
								__vala_JsonNode_free0 (root);
								_g_object_unref0 (parser);
								_g_free0 (filename);
								_skk_rule_metadata_free0 (metadata);
								return;
							} else {
								_g_free0 (parent);
								_g_list_free0 (elements);
								__vala_JsonArray_free0 (include);
								__vala_JsonNode_free0 (member);
								__vala_JsonObject_free0 (object);
								__vala_JsonNode_free0 (root);
								_g_object_unref0 (parser);
								_g_free0 (filename);
								_skk_rule_metadata_free0 (metadata);
								g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
								g_clear_error (&_inner_error_);
								return;
							}
						}
					} else {
						const gchar* _tmp68_;
						gint _tmp69_;
						gchar* _tmp70_ = NULL;
						gchar* _tmp71_;
						const gchar* _tmp72_;
						const gchar* _tmp73_;
						gint _tmp74_;
						const gchar* _tmp75_;
						gint _tmp76_;
						gint _tmp77_;
						gchar* _tmp78_ = NULL;
						gchar* _tmp79_;
						GeeSet* _tmp80_;
						_tmp68_ = parent;
						_tmp69_ = index;
						_tmp70_ = string_slice (_tmp68_, (glong) 0, (glong) _tmp69_);
						_tmp71_ = _tmp70_;
						_tmp72_ = type;
						_tmp73_ = parent;
						_tmp74_ = index;
						_tmp75_ = parent;
						_tmp76_ = strlen (_tmp75_);
						_tmp77_ = _tmp76_;
						_tmp78_ = string_slice (_tmp73_, (glong) (_tmp74_ + 1), (glong) _tmp77_);
						_tmp79_ = _tmp78_;
						_tmp80_ = included;
						skk_map_file_load (self, _tmp71_, _tmp72_, _tmp79_, _tmp80_, &_inner_error_);
						_g_free0 (_tmp79_);
						_g_free0 (_tmp71_);
						if (_inner_error_ != NULL) {
							if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
								g_propagate_error (error, _inner_error_);
								_g_free0 (parent);
								_g_list_free0 (elements);
								__vala_JsonArray_free0 (include);
								__vala_JsonNode_free0 (member);
								__vala_JsonObject_free0 (object);
								__vala_JsonNode_free0 (root);
								_g_object_unref0 (parser);
								_g_free0 (filename);
								_skk_rule_metadata_free0 (metadata);
								return;
							} else {
								_g_free0 (parent);
								_g_list_free0 (elements);
								__vala_JsonArray_free0 (include);
								__vala_JsonNode_free0 (member);
								__vala_JsonObject_free0 (object);
								__vala_JsonNode_free0 (root);
								_g_object_unref0 (parser);
								_g_free0 (filename);
								_skk_rule_metadata_free0 (metadata);
								g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
								g_clear_error (&_inner_error_);
								return;
							}
						}
					}
					_tmp81_ = included;
					_tmp82_ = parent;
					gee_collection_add ((GeeCollection*) _tmp81_, _tmp82_);
					_g_free0 (parent);
				}
			}
		}
		_g_list_free0 (elements);
		__vala_JsonArray_free0 (include);
	}
	_tmp83_ = object;
	_tmp84_ = json_object_has_member (_tmp83_, "define");
	if (_tmp84_) {
		JsonObject* _tmp85_;
		JsonNode* _tmp86_ = NULL;
		JsonNode* _tmp87_;
		JsonNode* _tmp88_;
		JsonNodeType _tmp89_ = 0;
		JsonNode* _tmp91_;
		JsonObject* _tmp92_ = NULL;
		JsonObject* _tmp93_;
		JsonObject* define;
		JsonObject* _tmp94_;
		GList* _tmp95_ = NULL;
		GList* keys;
		GList* _tmp96_;
		_tmp85_ = object;
		_tmp86_ = json_object_get_member (_tmp85_, "define");
		_tmp87_ = __vala_JsonNode_copy0 (_tmp86_);
		__vala_JsonNode_free0 (member);
		member = _tmp87_;
		_tmp88_ = member;
		_tmp89_ = json_node_get_node_type (_tmp88_);
		if (_tmp89_ != JSON_NODE_OBJECT) {
			GError* _tmp90_;
			_tmp90_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "\"define\" element must be an object");
			_inner_error_ = _tmp90_;
			if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
				g_propagate_error (error, _inner_error_);
				__vala_JsonNode_free0 (member);
				__vala_JsonObject_free0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				_skk_rule_metadata_free0 (metadata);
				return;
			} else {
				__vala_JsonNode_free0 (member);
				__vala_JsonObject_free0 (object);
				__vala_JsonNode_free0 (root);
				_g_object_unref0 (parser);
				_g_free0 (filename);
				_skk_rule_metadata_free0 (metadata);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
		_tmp91_ = member;
		_tmp92_ = json_node_get_object (_tmp91_);
		_tmp93_ = __vala_JsonObject_copy0 (_tmp92_);
		define = _tmp93_;
		_tmp94_ = define;
		_tmp95_ = json_object_get_members (_tmp94_);
		keys = _tmp95_;
		_tmp96_ = keys;
		{
			GList* key_collection = NULL;
			GList* key_it = NULL;
			key_collection = _tmp96_;
			for (key_it = key_collection; key_it != NULL; key_it = key_it->next) {
				const gchar* key = NULL;
				key = (const gchar*) key_it->data;
				{
					GeeMap* _tmp97_;
					const gchar* _tmp98_;
					gboolean _tmp99_ = FALSE;
					JsonObject* _tmp104_;
					const gchar* _tmp105_;
					JsonNode* _tmp106_ = NULL;
					JsonNode* _tmp107_;
					JsonNode* _tmp108_;
					JsonNodeType _tmp109_ = 0;
					GeeMap* _tmp111_;
					const gchar* _tmp112_;
					gpointer _tmp113_ = NULL;
					GeeMap* _tmp114_;
					JsonNode* _tmp115_;
					JsonObject* _tmp116_ = NULL;
					_tmp97_ = self->priv->maps;
					_tmp98_ = key;
					_tmp99_ = gee_map_has_key (_tmp97_, _tmp98_);
					if (!_tmp99_) {
						GeeHashMap* _tmp100_;
						GeeHashMap* map;
						GeeMap* _tmp101_;
						const gchar* _tmp102_;
						GeeHashMap* _tmp103_;
						_tmp100_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, json_node_get_type (), (GBoxedCopyFunc) _vala_JsonNode_copy, _vala_JsonNode_free, NULL, NULL, NULL);
						map = _tmp100_;
						_tmp101_ = self->priv->maps;
						_tmp102_ = key;
						_tmp103_ = map;
						gee_map_set (_tmp101_, _tmp102_, (GeeMap*) _tmp103_);
						_g_object_unref0 (map);
					}
					_tmp104_ = define;
					_tmp105_ = key;
					_tmp106_ = json_object_get_member (_tmp104_, _tmp105_);
					_tmp107_ = __vala_JsonNode_copy0 (_tmp106_);
					__vala_JsonNode_free0 (member);
					member = _tmp107_;
					_tmp108_ = member;
					_tmp109_ = json_node_get_node_type (_tmp108_);
					if (_tmp109_ != JSON_NODE_OBJECT) {
						GError* _tmp110_;
						_tmp110_ = g_error_new_literal (SKK_RULE_PARSE_ERROR, SKK_RULE_PARSE_ERROR_FAILED, "map element must be an object");
						_inner_error_ = _tmp110_;
						if (_inner_error_->domain == SKK_RULE_PARSE_ERROR) {
							g_propagate_error (error, _inner_error_);
							_g_list_free0 (keys);
							__vala_JsonObject_free0 (define);
							__vala_JsonNode_free0 (member);
							__vala_JsonObject_free0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							_skk_rule_metadata_free0 (metadata);
							return;
						} else {
							_g_list_free0 (keys);
							__vala_JsonObject_free0 (define);
							__vala_JsonNode_free0 (member);
							__vala_JsonObject_free0 (object);
							__vala_JsonNode_free0 (root);
							_g_object_unref0 (parser);
							_g_free0 (filename);
							_skk_rule_metadata_free0 (metadata);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
							g_clear_error (&_inner_error_);
							return;
						}
					}
					_tmp111_ = self->priv->maps;
					_tmp112_ = key;
					_tmp113_ = gee_map_get (_tmp111_, _tmp112_);
					_tmp114_ = (GeeMap*) _tmp113_;
					_tmp115_ = member;
					_tmp116_ = json_node_get_object (_tmp115_);
					skk_map_file_load_map (self, _tmp114_, _tmp116_);
					_g_object_unref0 (_tmp114_);
				}
			}
		}
		_g_list_free0 (keys);
		__vala_JsonObject_free0 (define);
	}
	__vala_JsonNode_free0 (member);
	__vala_JsonObject_free0 (object);
	__vala_JsonNode_free0 (root);
	_g_object_unref0 (parser);
	_g_free0 (filename);
	_skk_rule_metadata_free0 (metadata);
}
Ejemplo n.º 27
0
static void
set_error_from_string (const char *string, GError **error)
{
  if (error)
    *error = g_error_new_literal (get_ephy_sqlite_quark (), 0, string);
}
Ejemplo n.º 28
0
static RejillaBurnResult
rejilla_mkisofs_read_stderr (RejillaProcess *process, const gchar *line)
{
	gchar fraction_str [7] = { 0, };
	RejillaMkisofs *mkisofs;
	RejillaMkisofsPrivate *priv;

	mkisofs = REJILLA_MKISOFS (process);
	priv = REJILLA_MKISOFS_PRIVATE (process);

	if (strstr (line, "estimate finish")
	&&  sscanf (line, "%6c%% done, estimate finish", fraction_str) == 1) {
		gdouble fraction;
	
		fraction = g_strtod (fraction_str, NULL) / (gdouble) 100.0;
		rejilla_job_set_progress (REJILLA_JOB (mkisofs), fraction);
		rejilla_job_start_progress (REJILLA_JOB (process), FALSE);
	}
	else if (strstr (line, "Input/output error. Read error on old image")) {
		rejilla_job_error (REJILLA_JOB (process), 
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_IMAGE_LAST_SESSION,
							_("Last session import failed")));
	}
	else if (strstr (line, "Unable to sort directory")) {
		rejilla_job_error (REJILLA_JOB (process), 
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_WRITE_IMAGE,
							_("An image could not be created")));
	}
	else if (strstr (line, "have the same joliet name")
	     ||  strstr (line, "Joliet tree sort failed.")) {
		rejilla_job_error (REJILLA_JOB (process), 
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_IMAGE_JOLIET,
							_("An image could not be created")));
	}
	else if (strstr (line, "Use mkisofs -help")) {
		rejilla_job_error (REJILLA_JOB (process), 
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_GENERAL,
							_("This version of mkisofs is not supported")));
	}
/*	else if ((pos =  strstr (line,"mkisofs: Permission denied. "))) {
		int res = FALSE;
		gboolean isdir = FALSE;
		char *path = NULL;

		pos += strlen ("mkisofs: Permission denied. ");
		if (!strncmp (pos, "Unable to open directory ", 24)) {
			isdir = TRUE;

			pos += strlen ("Unable to open directory ");
			path = g_strdup (pos);
			path[strlen (path) - 1] = 0;
		}
		else if (!strncmp (pos, "File ", 5)) {
			char *end;

			isdir = FALSE;
			pos += strlen ("File ");
			end = strstr (pos, " is not readable - ignoring");
			if (end)
				path = g_strndup (pos, end - pos);
		}
		else
			return TRUE;

		res = rejilla_mkisofs_base_ask_unreadable_file (REJILLA_GENISOIMAGE_BASE (process),
								path,
								isdir);
		if (!res) {
			g_free (path);

			rejilla_job_progress_changed (REJILLA_JOB (process), 1.0, -1);
			rejilla_job_cancel (REJILLA_JOB (process), FALSE);
			return FALSE;
		}
	}*/
	else if (strstr (line, "Incorrectly encoded string")) {
		rejilla_job_error (REJILLA_JOB (process),
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_INPUT_INVALID,
							_("Some files have invalid filenames")));
	}
	else if (strstr (line, "Unknown charset")) {
		rejilla_job_error (REJILLA_JOB (process),
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_INPUT_INVALID,
							_("Unknown character encoding")));
	}
	else if (strstr (line, "No space left on device")) {
		rejilla_job_error (REJILLA_JOB (process),
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_DISK_SPACE,
							_("There is no space left on the device")));

	}
	else if (strstr (line, "Unable to open disc image file")) {
		rejilla_job_error (REJILLA_JOB (process),
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_PERMISSION,
							_("You do not have the required permission to write at this location")));

	}
	else if (strstr (line, "Value too large for defined data type")) {
		rejilla_job_error (REJILLA_JOB (process),
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_MEDIUM_SPACE,
							_("Not enough space available on the disc")));
	}

	/** REMINDER: these should not be necessary

	else if (strstr (line, "Resource temporarily unavailable")) {
		rejilla_job_error (REJILLA_JOB (process),
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_INPUT,
							_("Data could not be written")));
	}
	else if (strstr (line, "Bad file descriptor.")) {
		rejilla_job_error (REJILLA_JOB (process),
				   g_error_new_literal (REJILLA_BURN_ERROR,
							REJILLA_BURN_ERROR_INPUT,
							_("Internal error: bad file descriptor")));
	}

	**/

	return REJILLA_BURN_OK;
}
Ejemplo n.º 29
0
static gpointer
brasero_dvdcss_write_image_thread (gpointer data)
{
	guchar buf [DVDCSS_BLOCK_SIZE * BRASERO_DVDCSS_I_BLOCKS];
	BraseroScrambledSectorRange *range = NULL;
	BraseroMedium *medium = NULL;
	BraseroVolFile *files = NULL;
	dvdcss_handle *handle = NULL;
	BraseroDrive *drive = NULL;
	BraseroDvdcssPrivate *priv;
	gint64 written_sectors = 0;
	BraseroDvdcss *self = data;
	BraseroTrack *track = NULL;
	guint64 remaining_sectors;
	FILE *output_fd = NULL;
	BraseroVolSrc *vol;
	gint64 volume_size;
	GQueue *map = NULL;

	brasero_job_set_use_average_rate (BRASERO_JOB (self), TRUE);
	brasero_job_set_current_action (BRASERO_JOB (self),
					BRASERO_BURN_ACTION_ANALYSING,
					_("Retrieving DVD keys"),
					FALSE);
	brasero_job_start_progress (BRASERO_JOB (self), FALSE);

	priv = BRASERO_DVDCSS_PRIVATE (self);

	/* get the contents of the DVD */
	brasero_job_get_current_track (BRASERO_JOB (self), &track);
	drive = brasero_track_disc_get_drive (BRASERO_TRACK_DISC (track));

	vol = brasero_volume_source_open_file (brasero_drive_get_device (drive), &priv->error);
	files = brasero_volume_get_files (vol,
					  0,
					  NULL,
					  NULL,
					  NULL,
					  &priv->error);
	brasero_volume_source_close (vol);
	if (!files)
		goto end;

	medium = brasero_drive_get_medium (drive);
	brasero_medium_get_data_size (medium, NULL, &volume_size);
	if (volume_size == -1) {
		priv->error = g_error_new (BRASERO_BURN_ERROR,
					   BRASERO_BURN_ERROR_GENERAL,
					   _("The size of the volume could not be retrieved"));
		goto end;
	}

	/* create a handle/open DVD */
	handle = dvdcss_open (brasero_drive_get_device (drive));
	if (!handle) {
		priv->error = g_error_new (BRASERO_BURN_ERROR,
					   BRASERO_BURN_ERROR_GENERAL,
					   _("Video DVD could not be opened"));
		goto end;
	}

	/* look through the files to get the ranges of encrypted sectors
	 * and cache the CSS keys while at it. */
	map = g_queue_new ();
	if (!brasero_dvdcss_create_scrambled_sectors_map (self, drive, map, handle, files, &priv->error))
		goto end;

	BRASERO_JOB_LOG (self, "DVD map created (keys retrieved)");

	g_queue_sort (map, brasero_dvdcss_sort_ranges, NULL);

	brasero_volume_file_free (files);
	files = NULL;

	if (dvdcss_seek (handle, 0, DVDCSS_NOFLAGS) < 0) {
		BRASERO_JOB_LOG (self, "Error initial seeking");
		priv->error = g_error_new (BRASERO_BURN_ERROR,
					   BRASERO_BURN_ERROR_GENERAL,
					   _("Error while reading video DVD (%s)"),
					   dvdcss_error (handle));
		goto end;
	}

	brasero_job_set_current_action (BRASERO_JOB (self),
					BRASERO_BURN_ACTION_DRIVE_COPY,
					_("Copying video DVD"),
					FALSE);

	brasero_job_start_progress (BRASERO_JOB (self), TRUE);

	remaining_sectors = volume_size;
	range = g_queue_pop_head (map);

	if (brasero_job_get_fd_out (BRASERO_JOB (self), NULL) != BRASERO_BURN_OK) {
		gchar *output = NULL;

		brasero_job_get_image_output (BRASERO_JOB (self), &output, NULL);
		output_fd = fopen (output, "w");
		if (!output_fd) {
			priv->error = g_error_new_literal (BRASERO_BURN_ERROR,
							   BRASERO_BURN_ERROR_GENERAL,
							   g_strerror (errno));
			g_free (output);
			goto end;
		}
		g_free (output);
	}

	while (remaining_sectors) {
		gint flag;
		guint64 num_blocks, data_size;

		if (priv->cancel)
			break;

		num_blocks = BRASERO_DVDCSS_I_BLOCKS;

		/* see if we are approaching the end of the dvd */
		if (num_blocks > remaining_sectors)
			num_blocks = remaining_sectors;

		/* see if we need to update the key */
		if (!range || written_sectors < range->start) {
			/* this is in a non scrambled sectors range */
			flag = DVDCSS_NOFLAGS;
	
			/* we don't want to mix scrambled and non scrambled sectors */
			if (range && written_sectors + num_blocks > range->start)
				num_blocks = range->start - written_sectors;
		}
		else {
			/* this is in a scrambled sectors range */
			flag = DVDCSS_READ_DECRYPT;

			/* see if we need to update the key */
			if (written_sectors == range->start) {
				int pos;

				pos = dvdcss_seek (handle, written_sectors, DVDCSS_SEEK_KEY);
				if (pos < 0) {
					BRASERO_JOB_LOG (self, "Error seeking");
					priv->error = g_error_new (BRASERO_BURN_ERROR,
								   BRASERO_BURN_ERROR_GENERAL,
								   _("Error while reading video DVD (%s)"),
								   dvdcss_error (handle));
					break;
				}
			}

			/* we don't want to mix scrambled and non scrambled sectors
			 * NOTE: range->end address is the next non scrambled sector */
			if (written_sectors + num_blocks > range->end)
				num_blocks = range->end - written_sectors;

			if (written_sectors + num_blocks == range->end) {
				/* update to get the next range of scrambled sectors */
				g_free (range);
				range = g_queue_pop_head (map);
			}
		}

		num_blocks = dvdcss_read (handle, buf, num_blocks, flag);
		if (num_blocks < 0) {
			BRASERO_JOB_LOG (self, "Error reading");
			priv->error = g_error_new (BRASERO_BURN_ERROR,
						   BRASERO_BURN_ERROR_GENERAL,
						   _("Error while reading video DVD (%s)"),
						   dvdcss_error (handle));
			break;
		}

		data_size = num_blocks * DVDCSS_BLOCK_SIZE;
		if (output_fd) {
			if (fwrite (buf, 1, data_size, output_fd) != data_size) {
                                int errsv = errno;

				priv->error = g_error_new (BRASERO_BURN_ERROR,
							   BRASERO_BURN_ERROR_GENERAL,
							   _("Data could not be written (%s)"),
							   g_strerror (errsv));
				break;
			}
		}
		else {
			BraseroBurnResult result;

			result = brasero_dvdcss_write_sector_to_fd (self,
								    buf,
								    data_size);
			if (result != BRASERO_BURN_OK)
				break;
		}

		written_sectors += num_blocks;
		remaining_sectors -= num_blocks;
		brasero_job_set_written_track (BRASERO_JOB (self), written_sectors * DVDCSS_BLOCK_SIZE);
	}

end:

	if (range)
		g_free (range);

	if (handle)
		dvdcss_close (handle);

	if (files)
		brasero_volume_file_free (files);

	if (output_fd)
		fclose (output_fd);

	if (map) {
		g_queue_foreach (map, (GFunc) g_free, NULL);
		g_queue_free (map);
	}

	if (!priv->cancel)
		priv->thread_id = g_idle_add (brasero_dvdcss_thread_finished, self);

	/* End thread */
	g_mutex_lock (priv->mutex);
	priv->thread = NULL;
	g_cond_signal (priv->cond);
	g_mutex_unlock (priv->mutex);

	g_thread_exit (NULL);

	return NULL;
}
Ejemplo n.º 30
0
static gboolean vibrator_timed_outputclass_real_vibrate_pattern_co (VibratorTimedOutputclassVibratePatternData* _data_) {
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp1_ = _data_->self->priv->pulses;
	if (_data_->_tmp1_ > ((guint) 0)) {
		_data_->_tmp0_ = TRUE;
	} else {
		_data_->_tmp2_ = _data_->self->priv->fulltimeoutwatch;
		_data_->_tmp0_ = _data_->_tmp2_ > ((guint) 0);
	}
	_data_->_tmp3_ = _data_->_tmp0_;
	if (_data_->_tmp3_) {
		_data_->_tmp4_ = g_error_new_literal (FREE_SMARTPHONE_ERROR, FREE_SMARTPHONE_ERROR_INVALID_PARAMETER, "Already vibrating... please try again");
		_data_->_inner_error_ = _data_->_tmp4_;
		if (((_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR) || (_data_->_inner_error_->domain == G_DBUS_ERROR)) || (_data_->_inner_error_->domain == G_IO_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	_data_->_tmp5_ = _data_->pulses;
	if (_data_->_tmp5_ < 1) {
		_data_->_tmp6_ = g_error_new_literal (FREE_SMARTPHONE_ERROR, FREE_SMARTPHONE_ERROR_INVALID_PARAMETER, "Number of pulses needs to be at least 1");
		_data_->_inner_error_ = _data_->_tmp6_;
		if (((_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR) || (_data_->_inner_error_->domain == G_DBUS_ERROR)) || (_data_->_inner_error_->domain == G_IO_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	_data_->_tmp7_ = _data_->delay_on;
	if (_data_->_tmp7_ < 50) {
		_data_->_tmp8_ = g_error_new_literal (FREE_SMARTPHONE_ERROR, FREE_SMARTPHONE_ERROR_INVALID_PARAMETER, "Delay on duration needs to be at least 50 milliseconds");
		_data_->_inner_error_ = _data_->_tmp8_;
		if (((_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR) || (_data_->_inner_error_->domain == G_DBUS_ERROR)) || (_data_->_inner_error_->domain == G_IO_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	_data_->_tmp9_ = _data_->delay_off;
	if (_data_->_tmp9_ < 50) {
		_data_->_tmp10_ = g_error_new_literal (FREE_SMARTPHONE_ERROR, FREE_SMARTPHONE_ERROR_INVALID_PARAMETER, "Delay off duration needs to be at least 50 milliseconds");
		_data_->_inner_error_ = _data_->_tmp10_;
		if (((_data_->_inner_error_->domain == FREE_SMARTPHONE_ERROR) || (_data_->_inner_error_->domain == G_DBUS_ERROR)) || (_data_->_inner_error_->domain == G_IO_ERROR)) {
			g_simple_async_result_set_from_error (_data_->_async_result, _data_->_inner_error_);
			g_error_free (_data_->_inner_error_);
			if (_data_->_state_ == 0) {
				g_simple_async_result_complete_in_idle (_data_->_async_result);
			} else {
				g_simple_async_result_complete (_data_->_async_result);
			}
			g_object_unref (_data_->_async_result);
			return FALSE;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error_->message, g_quark_to_string (_data_->_inner_error_->domain), _data_->_inner_error_->code);
			g_clear_error (&_data_->_inner_error_);
			return FALSE;
		}
	}
	_data_->_tmp11_ = _data_->delay_on;
	_data_->self->priv->don = (guint) _data_->_tmp11_;
	_data_->_tmp12_ = _data_->delay_off;
	_data_->self->priv->doff = (guint) _data_->_tmp12_;
	_data_->_tmp13_ = _data_->pulses;
	_data_->self->priv->pulses = (guint) _data_->_tmp13_;
	vibrator_timed_outputclass_onToggleTimeout (_data_->self);
	if (_data_->_state_ == 0) {
		g_simple_async_result_complete_in_idle (_data_->_async_result);
	} else {
		g_simple_async_result_complete (_data_->_async_result);
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}