Exemple #1
0
GVfsFtpConnection *
g_vfs_ftp_connection_new (GSocketConnectable *addr,
                          GCancellable *      cancellable,
                          GError **           error)
{
  GVfsFtpConnection *conn;

  g_return_val_if_fail (G_IS_SOCKET_CONNECTABLE (addr), NULL);

  conn = g_slice_new0 (GVfsFtpConnection);
  conn->client = g_socket_client_new ();
  conn->debug_id = g_atomic_int_exchange_and_add (&debug_id, 1);
  conn->commands = G_IO_STREAM (g_socket_client_connect (conn->client,
                                                         addr,
                                                         cancellable,
                                                         error));
  if (conn->commands == NULL)
    {
      g_object_unref (conn->client);
      g_slice_free (GVfsFtpConnection, conn);
      return NULL;
    }

  enable_keepalive (G_SOCKET_CONNECTION (conn->commands));
  conn->commands_in = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (conn->commands)));
  g_data_input_stream_set_newline_type (conn->commands_in, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
  /* The first thing that needs to happen is receiving the welcome message */
  conn->waiting_for_reply = TRUE;

  return conn;
}
static void
on_channel_dat_received (MexDownloadQueue *queue,
                         const char       *uri,
                         const char       *buffer,
                         gsize             count,
                         const GError     *dq_error,
                         gpointer          userdata)
{
  MexEpgRadiotimes *provider = MEX_EPG_RADIOTIMES (userdata);
  MexEpgRadiotimesPrivate *priv = provider->priv;
  GInputStream *input;
  GDataInputStream *data;
  GError *error = NULL;
  gchar *line;

  MEX_NOTE (EPG, "received %s, size %"G_GSIZE_FORMAT, uri, count);

  if (dq_error)
    {
      g_warning ("Could not download %s: %s", uri, dq_error->message);
      return;
    }

  /* prepare channel2id hash table */
  if (priv->channel2id)
    g_hash_table_unref (priv->channel2id);

  priv->channel2id = g_hash_table_new_full (g_str_hash, g_str_equal,
                                           g_free, g_free);

  /* parse the date line by line */
  input = g_memory_input_stream_new_from_data (buffer, count, NULL);
  data = g_data_input_stream_new (input);

  /* The first line is empty */
  line = g_data_input_stream_read_line (data, NULL, NULL, &error);
  g_free (line);

  /* The second line is the disclamer*/
  line = g_data_input_stream_read_line (data, NULL, NULL, &error);
  g_free (line);

  line = g_data_input_stream_read_line (data, NULL, NULL, &error);
  while (line)
    {
      parse_channels_dat_line (provider, line);
      g_free (line);
      line = g_data_input_stream_read_line (data, NULL, NULL, &error);
    }
  if (G_UNLIKELY (error))
    {
      g_warning ("Could not read line: %s", error->message);
      g_clear_error (&error);
    }

  g_object_unref (data);
  g_object_unref (input);

  g_signal_emit_by_name (provider, "epg-provider-ready", 0);
}
Exemple #3
0
GSpeechdClient *
gspeechd_client_new (GSocketConnection *connection)
{
	GSpeechdClient *client;
	GOutputStream *output_stream;
	GInputStream *input_stream;

	client = g_slice_new0 (GSpeechdClient);
	client->ref_count = 1;
	client->cancellable = g_cancellable_new ();
	client->connection = g_object_ref (connection);
	client->failed = FALSE;

	/*
	 * Start listening for the message
	 */
	input_stream = g_io_stream_get_input_stream(G_IO_STREAM(connection));
	client->input = g_data_input_stream_new (input_stream);

	g_data_input_stream_read_line_async(client->input,
							G_PRIORITY_DEFAULT,
							client->cancellable,
							(GAsyncReadyCallback)gspeechd_client_read_line_cb,
							gspeechd_client_ref (client));

	output_stream = g_io_stream_get_output_stream (G_IO_STREAM(connection));
	client->output = g_data_output_stream_new (output_stream);

	return (client);
}
/**
 * pk_package_sack_add_packages_from_file:
 * @sack: a valid #PkPackageSack instance
 * @file: a valid package-list file
 * @error: a %GError to put the error code and message in, or %NULL
 *
 * Adds packages from package-list file to a PkPackageSack.
 *
 * Return value: %TRUE if there were no errors.
 *
 **/
gboolean
pk_package_sack_add_packages_from_file (PkPackageSack *sack,
					GFile *file,
					GError **error)
{
	GError *error_local = NULL;
	g_autoptr(GFileInputStream) is = NULL;
	g_autoptr(GDataInputStream) input = NULL;

	g_return_val_if_fail (PK_IS_PACKAGE_SACK (sack), FALSE);

	is = g_file_read (file, NULL, &error_local);
	if (is == NULL) {
		g_propagate_error (error, error_local);
		return FALSE;
	}

	input = g_data_input_stream_new (G_INPUT_STREAM (is));

	/* read package info file line by line */
	while (TRUE) {
		gchar *line;
		line = g_data_input_stream_read_line (input, NULL, NULL, NULL);
		if (line == NULL)
			break;
		g_strstrip (line);
		if (!pk_package_sack_add_packages_from_line (sack, line, error))
			return FALSE;
	}
	return TRUE;
}
Exemple #5
0
static GstylePalette *
gstyle_palette_new_from_gpl (GFile         *file,
                             GCancellable  *cancellable,
                             GError       **error)
{
  g_autoptr(GDataInputStream) data_stream = NULL;
  g_autoptr (GInputStream) stream = NULL;
  GstylePalette *palette = NULL;
  g_autofree gchar *palette_name = NULL;
  g_autofree gchar *id = NULL;
  GstyleColor *color;
  gchar *color_name;
  GdkRGBA rgba;
  GError *tmp_error = NULL;
  gint line_count = 1;
  gboolean has_colors = FALSE;

  g_assert (G_IS_FILE (file));

  if ((stream = G_INPUT_STREAM (g_file_read (file, cancellable, &tmp_error))))
    {
      data_stream = g_data_input_stream_new (stream);
      if (read_gpl_header (data_stream, &palette_name, &line_count, &tmp_error))
        {
          id = g_strcanon (g_strdup (palette_name), GSTYLE_PALETTE_ID_CHARSET, '_');
          palette = g_object_new (GSTYLE_TYPE_PALETTE,
                                 "id", id,
                                 "name", palette_name,
                                 "file", file,
                                 NULL);

          while (read_gpl_color_line (data_stream, &rgba, &color_name, &line_count, &tmp_error))
            {
              has_colors = TRUE;
              color = gstyle_color_new_from_rgba (color_name, GSTYLE_COLOR_KIND_RGB_HEX6, &rgba);
              gstyle_palette_add (palette, color, &tmp_error);
              g_object_unref (color);
              g_free (color_name);
              if (tmp_error != NULL)
                break;
            }
        }
    }

  if (tmp_error == NULL && !has_colors)
    {
      g_autofree gchar *uri = g_file_get_uri (file);

      g_set_error (&tmp_error, GSTYLE_PALETTE_ERROR, GSTYLE_PALETTE_ERROR_EMPTY,
                   _("%s: palette is empty\n"), uri);
    }

  if (tmp_error != NULL)
    {
      g_clear_object (&palette);
      g_propagate_error (error, tmp_error);
    }

  return palette;
}
Exemple #6
0
static void _configfile (CustomData *data, gboolean writemode) {
    gchar *filename = g_strdup_printf("file://%s/.4deckradio", g_get_home_dir());
    g_print ("config file: %s\n", filename);
    GFile *file = g_file_new_for_uri (filename);

    if (TRUE == writemode) {
        /* Save the last folder locations to ~/.4deckradio */
        GString *configstring = g_string_new("");
        for (int i=0; i < NUM_PLAYERS; i++) {
            g_print ("deck %i folder %s\n", i, data[i].last_folder_uri);
            g_string_append_printf (configstring, "%s\n", data[i].last_folder_uri);
        }

        g_file_replace_contents (file,
                configstring->str,
                configstring->len,
                NULL, /* old etag */
                FALSE, /* backup */
                G_FILE_CREATE_PRIVATE,
                NULL, /* new etag */
                NULL, /* cancellable */
                NULL);
        g_string_free (configstring, TRUE);
    } else {
        /* load config file */
        GFileInputStream *inputstream = g_file_read (file,
                NULL,
                NULL);
        if (NULL == inputstream) {
            return;
        }

        GDataInputStream *config = g_data_input_stream_new (G_INPUT_STREAM (inputstream));

        if (NULL == config) {
            return;
        }


        GError *error = NULL;

        for (int i = 0; i < NUM_PLAYERS; i++) {
            gsize length;
            data[i].last_folder_uri =
                g_data_input_stream_read_line_utf8(config, &length, NULL, &error);
            if (NULL != error) {
                g_print ("Error reading config file: %s\n", error->message);
            }
            g_clear_error (&error);
            g_print ("Will use %s for deck %i\n", data[i].last_folder_uri, i);
        }

        g_input_stream_close (G_INPUT_STREAM (config), NULL, NULL);
        g_input_stream_close (G_INPUT_STREAM (inputstream), NULL, NULL);
        g_object_unref (config);
        g_object_unref (inputstream);
    }
    g_free (filename);
    g_object_unref (file);
}
static gboolean
sysroot_setup_stdout_redirect (RpmostreedSysroot *self,
                               GError **error)
{
  g_autoptr(GInputStream) stream = NULL;
  g_autoptr(GSource) source = NULL;
  StdoutClosure *closure;
  gint pipefd[2];
  gboolean ret = FALSE;

  /* XXX libostree logs messages to systemd's journal and also to stdout.
   *     Redirect our own stdout back to ourselves so we can capture those
   *     messages and pass them on to clients.  Admittedly hokey but avoids
   *     hacking libostree directly (for now). */

  closure = g_slice_new0 (StdoutClosure);
  g_weak_ref_set (&closure->sysroot, self);

  /* Save the real stdout before overwriting its file descriptor. */
  closure->real_stdout = g_unix_output_stream_new (dup (STDOUT_FILENO), FALSE);

  if (pipe (pipefd) < 0)
    {
      glnx_set_prefix_error_from_errno (error, "%s", "pipe() failed");
      goto out;
    }

  if (dup2 (pipefd[1], STDOUT_FILENO) < 0)
    {
      glnx_set_prefix_error_from_errno (error, "%s", "dup2() failed");
      goto out;
    }

  stream = g_memory_input_stream_new ();
  closure->data_stream = g_data_input_stream_new (stream);
  g_clear_object (&stream);

  stream = g_unix_input_stream_new (pipefd[0], FALSE);

  source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (stream),
                                                  NULL);
  /* Transfer ownership of the StdoutClosure. */
  g_source_set_callback (source,
                         (GSourceFunc) sysroot_stdout_ready_cb,
                         closure,
                         (GDestroyNotify) stdout_closure_free);
  closure = NULL;

  self->stdout_source_id = g_source_attach (source, NULL);

  ret = TRUE;

out:
  if (closure != NULL)
    stdout_closure_free (closure);

  return ret;
}
static GHashTable *
disabled_repos_new (GError **error)
{
	GHashTable *table;
	GFile *file;

	GFileInputStream *is;
	GDataInputStream *input;

	GError *e = NULL;

	g_debug ("reading disabled repos from %s", PK_BACKEND_REPO_FILE);
	file = g_file_new_for_path (PK_BACKEND_REPO_FILE);
	is = g_file_read (file, NULL, &e);

	if (is == NULL) {
		g_object_unref (file);
		g_propagate_error (error, e);
		return NULL;
	}

	table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	input = g_data_input_stream_new (G_INPUT_STREAM (is));

	/* read disabled repos line by line, ignoring comments */
	while (TRUE) {
		gchar *line;

		line = g_data_input_stream_read_line (input, NULL, NULL, &e);

		if (line != NULL) {
			g_strstrip (line);
		} else {
			break;
		}

		if (*line == '\0' || *line == '#') {
			g_free (line);
			continue;
		}

		g_hash_table_insert (table, line, GINT_TO_POINTER (1));
	}

	g_object_unref (input);
	g_object_unref (is);
	g_object_unref (file);

	if (e != NULL) {
		g_hash_table_unref (table);
		g_propagate_error (error, e);
		return NULL;
	} else {
		return table;
	}
}
Exemple #9
0
static void
_j4status_io_stream_set_connection(J4statusIOStream *self, GSocketConnection *connection)
{
    self->connection = connection;
    self->out = g_data_output_stream_new(g_io_stream_get_output_stream(G_IO_STREAM(self->connection)));
    self->in = g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(self->connection)));
    if ( ! self->header_sent )
        _j4status_io_stream_put_header(self, self->io->header);
    g_data_input_stream_read_line_async(self->in, G_PRIORITY_DEFAULT, NULL, _j4status_io_stream_read_callback, self);
}
Exemple #10
0
GDataOutputStream *ekg_connection_add(
		GSocketConnection *conn,
		GInputStream *raw_instream,
		GOutputStream *raw_outstream,
		ekg_input_callback_t callback,
		ekg_failure_callback_t failure_callback,
		gpointer priv_data)
{
	struct ekg_connection *c = g_slice_new(struct ekg_connection);
	GOutputStream *bout = g_buffered_output_stream_new(raw_outstream);

	c->conn = conn;
	c->instream = g_data_input_stream_new(raw_instream);
	c->outstream = g_data_output_stream_new(bout);
	c->cancellable = g_cancellable_new();
	c->wr_buffer = g_string_new("");

	c->callback = callback;
	c->failure_callback = failure_callback;
	c->priv_data = priv_data;

#if NEED_SLAVERY
	c->master = get_slave_connection_by_conn(conn);
	c->slave = NULL;

		/* be a good slave.. er, servant */
	if (G_UNLIKELY(c->master)) {
		struct ekg_connection *ci;
		c->master->slave = c;

		/* shift flush handlers (if set)
		 * this is required in order to be able to easily set flush
		 * handlers for future slaves */
		for (ci = c;
				ci->master && (ci->master->flush_handler != setup_async_write);
				ci = ci->master)
			ci->flush_handler = ci->master->flush_handler;
		ci->flush_handler = setup_async_write;
	} else
#endif
		c->flush_handler = setup_async_write;

		/* LF works fine for CRLF */
	g_data_input_stream_set_newline_type(c->instream, G_DATA_STREAM_NEWLINE_TYPE_LF);
		/* disallow any blocking writes */
	g_buffered_output_stream_set_auto_grow(G_BUFFERED_OUTPUT_STREAM(bout), TRUE);

	connections = g_slist_prepend(connections, c);
#if NEED_SLAVERY
	if (G_LIKELY(!c->master))
#endif
		setup_async_read(c);

	return c->outstream;
}
Exemple #11
0
static void
create_input_stream (GVfsFtpConnection *conn)
{
  if (conn->commands_in)
    {
      g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (conn->commands_in), FALSE);
      g_object_unref (conn->commands_in);
    }

  conn->commands_in = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (conn->commands)));
  g_data_input_stream_set_newline_type (conn->commands_in, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
}
Exemple #12
0
static gboolean barebox_state_get_int(const gchar* name, int *value) {
	GSubprocess *sub;
	GError *error = NULL;
	gboolean res = FALSE;
	GInputStream *instream;
	GDataInputStream *datainstream;
	gchar* outline;
	guint64 result = 0;
	GPtrArray *args = g_ptr_array_new_full(10, g_free);
	
	g_ptr_array_add(args, g_strdup(BAREBOX_STATE_NAME));
	g_ptr_array_add(args, g_strdup("-g"));
	g_ptr_array_add(args, g_strdup(name));
	g_ptr_array_add(args, NULL);

	sub = g_subprocess_newv((const gchar * const *)args->pdata,
				  G_SUBPROCESS_FLAGS_NONE, &error);
	if (!sub) {
		g_warning("getting state failed: %s", error->message);
		g_clear_error(&error);
		goto out;
	}

	instream = g_subprocess_get_stdout_pipe(sub);
	datainstream = g_data_input_stream_new(instream);

	outline = g_data_input_stream_read_line(datainstream, NULL, NULL, NULL);
	if (!outline) {
		g_warning("failed reading state");
		goto out;
	}


	result = g_ascii_strtoull(outline, NULL, 10);
	if (errno != 0) {
		g_warning("Invalid return value: '%s'\n", outline);
		goto out;
	}

	res = g_subprocess_wait_check(sub, NULL, &error);
	if (!res) {
		g_warning("getting state failed: %s", error->message);
		g_clear_error(&error);
		goto out;
	}

out:
	g_ptr_array_unref(args);
	*value = result;
	return res;
}
Exemple #13
0
static gboolean load_file( GbdX11emitter* self,GFile* src,GError** err ) {
	GbdX11emitterPrivate* const priv = self->priv;

	g_clear_object( &priv->srcstream );
	g_clear_object( &priv->srcdata );

	GFileInputStream* is = g_file_read( src,NULL,err );
	if( !is )
		return FALSE;

	priv->srcstream = is;
	priv->srcdata = g_data_input_stream_new( G_INPUT_STREAM( priv->srcstream ) );
	return TRUE;
}
Exemple #14
0
GSList *check_file_load(GSList *ud_list, GFile *file)
{
	g_assert(file);

	char *data = NULL;
	gsize len = 0;
	GError *error = NULL;

	if (!g_file_load_contents(file, NULL, &data, &len, NULL, &error)) {
		check_file_error(file, error);
		g_error_free(error);
		return 0;
	}

	GInputStream *is = g_memory_input_stream_new_from_data(data, len, NULL);
	GDataInputStream *dis = g_data_input_stream_new(is);

	char *line = NULL;
	len = 0;
	error = NULL;

	while ((line = g_data_input_stream_read_line_utf8(dis, &len, NULL, &error))) {
		enum hash_func_e id = HASH_FUNC_INVALID;
		char *filename = NULL;
		char *digest = NULL;

		if ((len >= 8) &&
			check_file_parse_line(line, &id, &filename, &digest))
		{
			if (HASH_FUNC_IS_VALID(id))
				gui_enable_hash_func(id);

			ud_list = check_file_add_uri(ud_list, file, filename, digest);
		}

		g_free(line);
	}

	if (error) {
		check_file_error(file, error);
		g_error_free(error);
	} else
		check_file_enable_hinted_hash_func(file);

	g_object_unref(dis);
	g_object_unref(is);
	g_free(data);

	return ud_list;
}
static GHashTable *
disabled_repos_new (GError **error)
{
	GHashTable *disabled;
	GFile *file;

	GFileInputStream *file_stream;
	GDataInputStream *data_stream;

	gchar *line;
	GError *e = NULL;

	g_debug ("pacman: reading disabled repos from %s", PACMAN_REPO_LIST);
	file = g_file_new_for_path (PACMAN_REPO_LIST);
	file_stream = g_file_read (file, NULL, &e);

	if (file_stream == NULL) {
		g_object_unref (file);
		g_propagate_error (error, e);
		return NULL;
	}

	disabled = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	data_stream = g_data_input_stream_new (G_INPUT_STREAM (file_stream));

	/* read disabled repos line by line, ignoring comments */
	while ((line = g_data_input_stream_read_line (data_stream, NULL, NULL, &e)) != NULL) {
		g_strstrip (line);

		if (*line == '\0' || *line == '#') {
			g_free (line);
			continue;
		}

		g_hash_table_insert (disabled, line, GINT_TO_POINTER (1));
	}

	g_object_unref (data_stream);
	g_object_unref (file_stream);
	g_object_unref (file);

	if (e != NULL) {
		g_hash_table_unref (disabled);
		g_propagate_error (error, e);
		return NULL;
	} else {
		return disabled;
	}
}
Exemple #16
0
static void
log_dumper (GInputStream *stream,
            gboolean      is_stderr)
{
  g_autoptr(GDataInputStream) data_stream = NULL;
  GThread *thread;

  g_assert (G_IS_INPUT_STREAM (stream));

  data_stream = g_data_input_stream_new (stream);
  g_object_set_data (G_OBJECT (data_stream), "IS_STDERR", GINT_TO_POINTER (!!is_stderr));

  thread = g_thread_new ("LogThread", log_thread, g_object_ref (data_stream));
  log_threads = g_list_prepend (log_threads, thread);
}
gboolean
ide_source_snippet_parser_load_from_file (IdeSourceSnippetParser *parser,
                                          GFile                  *file,
                                          GError                **error)
{
  GFileInputStream *file_stream;
  GDataInputStream *data_stream;
  GError *local_error = NULL;
  gchar *line;
  gchar *basename = NULL;

  g_return_val_if_fail (IDE_IS_SOURCE_SNIPPET_PARSER (parser), FALSE);
  g_return_val_if_fail (G_IS_FILE (file), FALSE);

  basename = g_file_get_basename (file);

  if (basename)
    {
      if (strstr (basename, "."))
        *strstr (basename, ".") = '\0';
    }

  file_stream = g_file_read (file, NULL, error);
  if (!file_stream)
    return FALSE;

  data_stream = g_data_input_stream_new (G_INPUT_STREAM (file_stream));
  g_object_unref (file_stream);

again:
  line = g_data_input_stream_read_line_utf8 (data_stream, NULL, NULL, &local_error);
  if (line && local_error)
    {
      g_propagate_error (error, local_error);
      return FALSE;
    }
  else if (line)
    {
      ide_source_snippet_parser_feed_line (parser, basename, line);
      g_free (line);
      goto again;
    }

  ide_source_snippet_parser_finish (parser);
  g_free(basename);

  return TRUE;
}
int main(void)
{
    pid_t parent_pid;
    GInputStream *stdin_unix_stream;

  /* Nuke the environment to get a well-known and sanitized
   * environment to avoid attacks via e.g. the DBUS_SYSTEM_BUS_ADDRESS
   * environment variable and similar.
   */
    if (clearenv () != 0) {
        FATAL_ERROR("Error clearing environment: %s\n", g_strerror (errno));
        return 1;
    }

#if !GLIB_CHECK_VERSION(2,36,0)
    g_type_init();
#endif

    loop = g_main_loop_new(NULL, FALSE);

    authority = polkit_authority_get_sync(NULL, NULL);
    parent_pid = getppid ();
    if (parent_pid == 1) {
            FATAL_ERROR("Parent process was reaped by init(1)\n");
            return 1;
    }
    /* Do what pkexec does */
    subject = polkit_unix_process_new_for_owner(parent_pid, 0, getuid ());

    stdin_unix_stream = g_unix_input_stream_new(STDIN_FILENO, 0);
    stdin_stream = g_data_input_stream_new(stdin_unix_stream);
    g_data_input_stream_set_newline_type(stdin_stream,
                                         G_DATA_STREAM_NEWLINE_TYPE_LF);
    g_clear_object(&stdin_unix_stream);
    g_data_input_stream_read_line_async(stdin_stream, G_PRIORITY_DEFAULT, NULL,
                                        stdin_read_complete, NULL);

    g_main_loop_run(loop);

    if (polkit_cancellable)
        g_clear_object(&polkit_cancellable);
    g_object_unref(stdin_stream);
    g_object_unref(authority);
    g_object_unref(subject);
    g_main_loop_unref(loop);

    return exit_status;
}
Exemple #19
0
static TestClient *
test_client_new (const char          *id,
                 MetaWindowClientType type,
                 GError             **error)
{
  TestClient *client = g_new0 (TestClient, 1);
  GSubprocessLauncher *launcher;
  GSubprocess *subprocess;

  launcher =  g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE);

  g_assert (meta_is_wayland_compositor ());
  MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();

  g_subprocess_launcher_setenv (launcher,
                                "WAYLAND_DISPLAY", meta_wayland_get_wayland_display_name (compositor),
                                TRUE);
  g_subprocess_launcher_setenv (launcher,
                                "DISPLAY", meta_wayland_get_xwayland_display_name (compositor),
                                TRUE);

  subprocess = g_subprocess_launcher_spawn (launcher,
                                            error,
                                            test_client_path,
                                            "--client-id",
                                            id,
                                            type == META_WINDOW_CLIENT_TYPE_WAYLAND ? "--wayland" : NULL,
                                            NULL);
  g_object_unref (launcher);

  if (!subprocess)
    return NULL;

  client->type = type;
  client->id = g_strdup (id);
  client->cancellable = g_cancellable_new ();
  client->subprocess = subprocess;
  client->in = g_data_output_stream_new (g_subprocess_get_stdin_pipe (subprocess));
  client->out = g_data_input_stream_new (g_subprocess_get_stdout_pipe (subprocess));
  client->loop = g_main_loop_new (NULL, FALSE);

  if (client->type == META_WINDOW_CLIENT_TYPE_X11)
    client->waiter = async_waiter_new ();

  return client;
}
static gboolean
parse_config (MexUriChannelProvider *provider)
{
  MexUriChannelProviderPrivate *priv = provider->priv;
  GFileInputStream *input;
  GDataInputStream *data;
  gboolean result = TRUE;
  GError *error = NULL;
  gchar *line;
  GFile *file;

  if (priv->channels)
    g_ptr_array_free (priv->channels, TRUE);
  priv->channels = g_ptr_array_new_with_free_func (g_object_unref);

  file = g_file_new_for_path (priv->config_file);
  input = g_file_read (file, NULL, &error);
  if (G_UNLIKELY (error))
    {
      MEX_WARNING ("Could not read config file %s: %s",
                   priv->config_file, error->message);
      g_clear_error (&error);
      goto read_error;
    }

  data = g_data_input_stream_new (G_INPUT_STREAM (input));

  line = g_data_input_stream_read_line (data, NULL, NULL, &error);
  while (line)
    {
      parse_line (provider, line);
      g_free (line);
      line = g_data_input_stream_read_line (data, NULL, NULL, &error);
    }
  if (G_UNLIKELY (error))
    {
      MEX_WARNING ("Could not read line: %s", error->message);
      g_clear_error (&error);
    }

  g_object_unref (data);
  g_object_unref (input);
read_error:
  g_object_unref (file);
  return result;
}
Exemple #21
0
gboolean tagsistant_wal_apply_log(dbi_conn dbi, const gchar *log_entry, const gchar *last_tstamp)
{
	gboolean parsed = FALSE;

	gchar *wal_entry_path = g_strdup_printf("%s/wal/%s", tagsistant.repository, log_entry);
	if (!wal_entry_path) {
		dbg('s', LOG_ERR, "WAL: error opening %s/wal/%s", tagsistant.repository, log_entry);
		return (FALSE);
	}

	GFile *f = g_file_new_for_path(wal_entry_path);
	if (f) {
		GFileInputStream *s = g_file_read(f, NULL, NULL);
		if (s) {
			GDataInputStream *ds = g_data_input_stream_new(G_INPUT_STREAM(s));
			if (ds) {
				while (1) {
					gsize size;
					GError *error = NULL;
					gchar *line = g_data_input_stream_read_line(ds, &size, NULL, &error);
					if (line) {
						if (!tagsistant_wal_apply_line(dbi, line, last_tstamp)) break;
					} else {
						if (!error) {
							// last line read
							parsed = TRUE;
						} else {
							dbg('s', LOG_ERR, "WAL: error parsing line: %s", error->message);
							g_error_free(error);
						}
						break;
					}
				}
				g_object_unref(ds);
			}
			g_object_unref(s);
		}
		g_object_unref(f);
	}
	g_free(wal_entry_path);

	return (parsed);
}
Exemple #22
0
static gboolean do_connect(MegaHttpClient* http_client, GCancellable* cancellable, GError** err)
{
  GError* local_err = NULL;

  g_return_val_if_fail(MEGA_IS_HTTP_CLIENT(http_client), FALSE);
  g_return_val_if_fail(err == NULL || *err == NULL, FALSE);

  MegaHttpClientPrivate* priv = http_client->priv;

  do_disconnect(http_client);

  // enable/disable TLS
  if (priv->https)
  {
    if (!g_tls_backend_supports_tls(g_tls_backend_get_default())) 
    {
      g_set_error(err, MEGA_HTTP_CLIENT_ERROR, MEGA_HTTP_CLIENT_ERROR_OTHER, "TLS backend not found, please install glib-networking.");
      return FALSE;
    }

    g_socket_client_set_tls(priv->client, TRUE);
  }
  else
  {
    g_socket_client_set_tls(priv->client, FALSE);
  }


  priv->conn = g_socket_client_connect_to_host(priv->client, priv->host, priv->port, cancellable, &local_err);
  if (!priv->conn)
  {
    g_propagate_prefixed_error(err, local_err, "Connection failed: ");
    return FALSE;
  }
  
  GDataInputStream* data_stream = g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(http_client->priv->conn)));
  g_data_input_stream_set_newline_type(data_stream, G_DATA_STREAM_NEWLINE_TYPE_ANY);

  priv->istream = G_INPUT_STREAM(data_stream);
  priv->ostream = g_object_ref(g_io_stream_get_output_stream(G_IO_STREAM(http_client->priv->conn)));

  return TRUE;
}
gboolean
rejilla_image_format_cue_bin_byte_swap (gchar *uri,
					GCancellable *cancel,
					GError **error)
{
	GFile *file;
	gchar *line;
	GFileInputStream *input;
	GDataInputStream *stream;
	gboolean is_audio = FALSE;
	gboolean is_binary = FALSE;

	file = g_file_new_for_uri (uri);
	input = g_file_read (file, cancel, error);

	if (!input) {
		g_object_unref (file);
		return FALSE;
	}

	stream = g_data_input_stream_new (G_INPUT_STREAM (input));
	g_object_unref (input);

	while ((line = g_data_input_stream_read_line (stream, NULL, cancel, error))) {
		const gchar *ptr;
		
		if ((ptr = strstr (line, "FILE"))) {
			if (strstr (ptr, "BINARY"))
				is_binary = TRUE;
		}
		else if ((ptr = strstr (line, "TRACK"))) {
			if (strstr (ptr, "AUDIO"))
				is_audio = TRUE;
		}
		g_free (line);
	}

	g_object_unref (stream);
	g_object_unref (file);

	return is_binary && is_audio;
}
Exemple #24
0
static gboolean
identd_incoming_cb (GSocketService *service, GSocketConnection *conn,
					GObject *source, gpointer userdata)
{
	GDataInputStream *data_stream;
	GInputStream *stream;
	ident_info *info;

	info = g_new0 (ident_info, 1);

	info->conn = conn;
	g_object_ref (conn);

	stream = g_io_stream_get_input_stream (G_IO_STREAM (conn));
	data_stream = g_data_input_stream_new (stream);
	g_data_input_stream_set_newline_type (data_stream, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
	g_data_input_stream_read_line_async (data_stream, G_PRIORITY_DEFAULT,
										NULL, (GAsyncReadyCallback)identd_read_ready, info);

	return TRUE;
}
Exemple #25
0
/* Populate shells GList using the default file path.
 * The first line is avoided
 */
_populate_shells (Users *us) {
  GFile *shells_file = g_file_new_for_path(SHELLS_FILE_PATH);
  GError *err =NULL;
  GDataInputStream *data_stream = NULL;
  GFileInputStream *shells_stream = g_file_read (shells_file, NULL, &err);
  data_stream = g_data_input_stream_new (G_INPUT_STREAM(shells_stream));
  us->shells = NULL;
  g_print ("HOLA\n");
  gsize length=0;
  char *mytext;
  // Avoid the first line
  mytext = g_data_input_stream_read_line (data_stream, &length, NULL, &err);
  mytext = g_data_input_stream_read_line (data_stream, &length, NULL, &err);

  while (mytext != NULL) {
    us->shells = g_list_append (us->shells, mytext);
    mytext = g_data_input_stream_read_line (data_stream, &length, NULL, &err);
    g_print ("%s\n", mytext);
  }
  g_input_stream_close (G_INPUT_STREAM(shells_stream), NULL, &err);
  g_object_unref (shells_file);

}
static gboolean
grep_literal (GFile              *f,
              const char         *string,
              gboolean           *out_matches,
              GCancellable       *cancellable,
              GError            **error)
{
  gboolean ret = FALSE;
  gboolean ret_matches = FALSE;
  ot_lobj GInputStream *in = NULL;
  ot_lobj GDataInputStream *datain = NULL;
  ot_lfree char *line = NULL;

  in = (GInputStream*)g_file_read (f, cancellable, error);
  if (!in)
    goto out;
  datain = (GDataInputStream*)g_data_input_stream_new (in);
  if (!in)
    goto out;

  while ((line = g_data_input_stream_read_line (datain, NULL, cancellable, error)) != NULL)
    {
      if (strstr (line, string))
        {
          ret_matches = TRUE;
          break;
        }
      
      g_free (line);
    }

  ret = TRUE;
  if (out_matches)
    *out_matches = ret_matches;
 out:
  return ret;
}
Exemple #27
0
GDataInputStream *
http_data_input_stream(GInputStream * stream,gsize * length,GCancellable * cancellable,GError ** error)
{
	GMemoryOutputStream
	* out = G_MEMORY_OUTPUT_STREAM(g_memory_output_stream_new_resizable());
	gchar * content = NULL;
	guint8 byte = 0;
	while(g_input_stream_read(stream,&byte,1,cancellable,error))
	{
		if(g_memory_output_stream_get_data_size(out) > 2048)
		{
			g_output_stream_close(G_OUTPUT_STREAM(out),NULL,NULL);
			g_free(g_memory_output_stream_steal_data(out));
			g_object_unref(out);
			return NULL;
		}
		g_output_stream_write_all(G_OUTPUT_STREAM(out),&byte,1,NULL,NULL,NULL);
		if(g_memory_output_stream_get_data_size(out) >= 4)
		{
			content = g_memory_output_stream_get_data(out);
			if(strncmp((content + g_memory_output_stream_get_data_size(out) - 4),"\r\n\r\n",4) == 0)
				break;
		}
	}
	g_output_stream_close(G_OUTPUT_STREAM(out),NULL,NULL);
	GMemoryInputStream
	* result = G_MEMORY_INPUT_STREAM(g_memory_input_stream_new_from_data(
				g_memory_output_stream_steal_data(out),
				g_memory_output_stream_get_data_size(out),
				g_free
			));
	g_object_unref(out);
	GDataInputStream
	* dis = g_data_input_stream_new(G_INPUT_STREAM(result));
	g_data_input_stream_set_newline_type(dis,G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
	return dis;
}
Exemple #28
0
static char *
read_json ()
{
	GFile *file;
	GFileInputStream *fstrm;
	GDataInputStream *dstrm;
	gchar *data = NULL;
	GError *err = NULL;

	file = g_file_new_for_uri ("resource:///org/wkgtk/khanacademy/khanacademy.json");
	fstrm = g_file_read (file, NULL, &err);
	if (!fstrm) {
		g_printerr ("Failed opening file: %s\n", err->message);
		g_error_free (err);
		goto bail;
	}
	dstrm = g_data_input_stream_new (G_INPUT_STREAM (fstrm));
	data = g_data_input_stream_read_upto (dstrm, "\0", 1, NULL, NULL, &err);
	if (!data) {
		g_printerr ("Failed reading file: %s\n", err->message);
		g_error_free (err);
		goto bail;
	}
	if (!g_input_stream_close (G_INPUT_STREAM (fstrm), NULL, &err)) {
		g_printerr ("Failed closing file: %s\n", err->message);
		g_error_free (err);
		goto bail;
	}

bail:
	g_object_unref (dstrm);
	g_object_unref (fstrm);
	g_object_unref (file);

	return data;
}
Exemple #29
0
gboolean
gimp_levels_config_load_cruft (GimpLevelsConfig  *config,
                               GInputStream      *input,
                               GError           **error)
{
  GDataInputStream *data_input;
  gint              low_input[5];
  gint              high_input[5];
  gint              low_output[5];
  gint              high_output[5];
  gdouble           gamma[5];
  gchar            *line;
  gsize             line_len;
  gint              i;

  g_return_val_if_fail (GIMP_IS_LEVELS_CONFIG (config), FALSE);
  g_return_val_if_fail (G_IS_INPUT_STREAM (input), FALSE);
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  data_input = g_data_input_stream_new (input);

  line_len = 64;
  line = g_data_input_stream_read_line (data_input, &line_len,
                                        NULL, error);
  if (! line)
    return FALSE;

  if (strcmp (line, "# GIMP Levels File") != 0)
    {
      g_set_error_literal (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
			   _("not a GIMP Levels file"));
      g_object_unref (data_input);
      g_free (line);
      return FALSE;
    }

  g_free (line);

  for (i = 0; i < 5; i++)
    {
      gchar  float_buf[32];
      gchar *endp;
      gint   fields;

      line_len = 64;
      line = g_data_input_stream_read_line (data_input, &line_len,
                                            NULL, error);
      if (! line)
        {
          g_object_unref (data_input);
          return FALSE;
        }

      fields = sscanf (line, "%d %d %d %d %31s",
                       &low_input[i],
                       &high_input[i],
                       &low_output[i],
                       &high_output[i],
                       float_buf);

      g_free (line);

      if (fields != 5)
        goto error;

      gamma[i] = g_ascii_strtod (float_buf, &endp);

      if (endp == float_buf || errno == ERANGE)
        goto error;
    }

  g_object_unref (data_input);

  g_object_freeze_notify (G_OBJECT (config));

  for (i = 0; i < 5; i++)
    {
      config->low_input[i]   = low_input[i]   / 255.0;
      config->high_input[i]  = high_input[i]  / 255.0;
      config->low_output[i]  = low_output[i]  / 255.0;
      config->high_output[i] = high_output[i] / 255.0;
      config->gamma[i]       = gamma[i];
    }

  g_object_notify (G_OBJECT (config), "gamma");
  g_object_notify (G_OBJECT (config), "low-input");
  g_object_notify (G_OBJECT (config), "high-input");
  g_object_notify (G_OBJECT (config), "low-output");
  g_object_notify (G_OBJECT (config), "high-output");

  g_object_thaw_notify (G_OBJECT (config));

  return TRUE;

 error:
  g_object_unref (data_input);

  g_set_error_literal (error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
		       _("parse error"));
  return FALSE;
}
GList *
gimp_brush_generated_load (GimpContext   *context,
                           GFile         *file,
                           GInputStream  *input,
                           GError       **error)
{
  GimpBrush               *brush;
  GDataInputStream        *data_input;
  gchar                   *string;
  gsize                    string_len;
  gint                     linenum;
  gchar                   *name       = NULL;
  GimpBrushGeneratedShape  shape      = GIMP_BRUSH_GENERATED_CIRCLE;
  gboolean                 have_shape = FALSE;
  gint                     spikes     = 2;
  gdouble                  spacing;
  gdouble                  radius;
  gdouble                  hardness;
  gdouble                  aspect_ratio;
  gdouble                  angle;

  g_return_val_if_fail (G_IS_FILE (file), NULL);
  g_return_val_if_fail (G_IS_INPUT_STREAM (input), NULL);
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);

  data_input = g_data_input_stream_new (input);

  /* make sure the file we are reading is the right type */
  linenum = 1;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;

  if (! g_str_has_prefix (string, "GIMP-VBR"))
    {
      g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                   _("Not a GIMP brush file."));
      g_free (string);
      goto failed;
    }

  g_free (string);

  /* make sure we are reading a compatible version */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;

  if (! g_str_has_prefix (string, "1.0"))
    {
      if (! g_str_has_prefix (string, "1.5"))
        {
          g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                       _("Unknown GIMP brush version."));
          g_free (string);
          goto failed;
        }
      else
        {
          have_shape = TRUE;
        }
    }

  g_free (string);

  /* read name */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;

  g_strstrip (string);

  /* the empty string is not an allowed name */
  if (strlen (string) < 1)
    {
      name = g_strdup (_("Untitled"));
    }
  else
    {
      name = gimp_any_to_utf8 (string, -1,
                               _("Invalid UTF-8 string in brush file '%s'."),
                               gimp_file_get_utf8_name (file));
    }

  g_free (string);

  if (have_shape)
    {
      GEnumClass *enum_class;
      GEnumValue *shape_val;

      enum_class = g_type_class_peek (GIMP_TYPE_BRUSH_GENERATED_SHAPE);

      /* read shape */
      linenum++;
      string_len = 256;
      string = g_data_input_stream_read_line (data_input, &string_len,
                                              NULL, error);
      if (! string)
        goto failed;

      g_strstrip (string);
      shape_val = g_enum_get_value_by_nick (enum_class, string);

      if (! shape_val)
        {
          g_set_error (error, GIMP_DATA_ERROR, GIMP_DATA_ERROR_READ,
                       _("Unknown GIMP brush shape."));
          g_free (string);
          goto failed;
        }

      g_free (string);

      shape = shape_val->value;
    }

  /* read brush spacing */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  spacing = g_ascii_strtod (string, NULL);
  g_free (string);

  /* read brush radius */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  radius = g_ascii_strtod (string, NULL);
  g_free (string);

  if (have_shape)
    {
      /* read number of spikes */
      linenum++;
      string_len = 256;
      string = g_data_input_stream_read_line (data_input, &string_len,
                                              NULL, error);
      if (! string)
        goto failed;
      spikes = CLAMP (atoi (string), 2, 20);
      g_free (string);
    }

  /* read brush hardness */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  hardness = g_ascii_strtod (string, NULL);
  g_free (string);

  /* read brush aspect_ratio */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  aspect_ratio = g_ascii_strtod (string, NULL);
  g_free (string);

  /* read brush angle */
  linenum++;
  string_len = 256;
  string = g_data_input_stream_read_line (data_input, &string_len,
                                          NULL, error);
  if (! string)
    goto failed;
  angle = g_ascii_strtod (string, NULL);
  g_free (string);

  g_object_unref (data_input);

  brush = GIMP_BRUSH (gimp_brush_generated_new (name, shape, radius, spikes,
                                                hardness, aspect_ratio, angle));
  g_free (name);

  gimp_brush_set_spacing (brush, spacing);

  return g_list_prepend (NULL, brush);

 failed:

  g_object_unref (data_input);

  if (name)
    g_free (name);

  g_prefix_error (error, _("In line %d of brush file: "), linenum);

  return NULL;
}