Пример #1
0
gboolean
g_vfs_ftp_connection_send (GVfsFtpConnection *conn,
                           const char *       command,
                           int                len,
                           GCancellable *     cancellable,
                           GError **          error)
{
  g_return_val_if_fail (conn != NULL, FALSE);
  g_return_val_if_fail (!conn->waiting_for_reply, FALSE);
  g_return_val_if_fail (command != NULL, FALSE);
  g_return_val_if_fail (len >= -1, FALSE);
  if (len < 0)
    len = strlen (command);
  g_return_val_if_fail (command[len-2] == '\r' && command[len-1] == '\n', FALSE);

  if (g_str_has_prefix (command, "PASS"))
    g_debug ("--%2d ->  PASS ***\r\n", conn->debug_id);
  else
    g_debug ("--%2d ->  %s", conn->debug_id, command);

  conn->waiting_for_reply = TRUE;
  return g_output_stream_write_all (g_io_stream_get_output_stream (conn->commands),
                                    command,
                                    len,
                                    NULL,
                                    cancellable,
                                    error);
}
Пример #2
0
gboolean 
gitg_commit_add_ignore(GitgCommit *commit, GitgChangedFile *file, GError **error)
{
	g_return_if_fail(GITG_IS_COMMIT(commit));
	g_return_if_fail(GITG_IS_CHANGED_FILE(file));
	
	GFile *f = gitg_changed_file_get_file(file);
	gchar *path = gitg_repository_relative(commit->priv->repository, f);
	
	gchar *ignore = g_strdup_printf("%s/.gitignore", gitg_repository_get_path(commit->priv->repository));
	GFile *ig = g_file_new_for_path(ignore);
	
	GFileOutputStream *stream = g_file_append_to(ig, G_FILE_CREATE_NONE, NULL, error);
	gboolean ret = FALSE;
	
	if (stream)
	{
		gchar *line = g_strdup_printf("/%s\n", path);
		ret = g_output_stream_write_all(G_OUTPUT_STREAM(stream), line, strlen(line), NULL, NULL, error);
		g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);

		g_object_unref(stream);
		g_free(line);
	}
	
	if (ret)
		remove_file(commit, file);

	g_object_unref(f);	
	g_free(ignore);
	g_free(path);
}
Пример #3
0
static int
patch_to_stream (const git_diff_delta *delta,
                 const git_diff_hunk  *hunk,
                 const git_diff_line  *line,
                 void                 *payload)
{
	PatchToStream *info = payload;
	gboolean ret;
	gsize written;

	ret = g_output_stream_write_all (info->stream,
	                                 line->content,
	                                 line->content_len,
	                                 &written,
	                                 NULL,
	                                 info->error);

	if (!ret)
	{
		return -1;
	}
	else
	{
		return written;
	}
}
static gboolean
emfe_secure_button_format (EMailFormatterExtension *extension,
                           EMailFormatter *formatter,
                           EMailFormatterContext *context,
                           EMailPart *part,
                           GOutputStream *stream,
                           GCancellable *cancellable)
{
	gchar *str;

	if ((context->mode != E_MAIL_FORMATTER_MODE_NORMAL) &&
	    (context->mode != E_MAIL_FORMATTER_MODE_RAW) &&
	    (context->mode != E_MAIL_FORMATTER_MODE_ALL_HEADERS))
		return FALSE;

	str = g_strdup_printf (
		"<object type=\"application/vnd.evolution.widget.secure-button\" "
		"height=\"20\" width=\"100%%\" data=\"%s\" id=\"%s\"></object>",
		e_mail_part_get_id (part),
		e_mail_part_get_id (part));

	g_output_stream_write_all (
		stream, str, strlen (str), NULL, cancellable, NULL);

	g_free (str);

	return TRUE;
}
Пример #5
0
static gboolean do_send_headers(MegaHttpClient* http_client, GCancellable* cancellable, GError** err)
{
  GError* local_err = NULL;
  GString* headers;

  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;

  headers = g_string_sized_new(300);

  mega_http_client_set_header(http_client, "Host", priv->host);
  mega_http_client_set_content_length(http_client, priv->expected_write_count);

  g_string_append_printf(headers, "%s %s HTTP/1.1\r\n", "POST", priv->resource);
  g_hash_table_foreach(priv->request_headers, (GHFunc)add_header, headers);
  g_string_append(headers, "\r\n");

  gboolean rs = g_output_stream_write_all(priv->ostream, headers->str, headers->len, NULL, cancellable, &local_err);
  if (!rs)
  {
    g_set_error(err, MEGA_HTTP_CLIENT_ERROR, MEGA_HTTP_CLIENT_ERROR_CONNECTION_BROKEN, "Can't write request headers: %s", local_err ? local_err->message : "unknown error");
    g_clear_error(&local_err);
  }

  g_string_free(headers, TRUE);

  return rs;
}
Пример #6
0
gboolean
ot_util_variant_save (GFile *dest,
                      GVariant *variant,
                      GCancellable *cancellable,
                      GError  **error)
{
  gboolean ret = FALSE;
  ot_lobj GOutputStream *out = NULL;
  gsize bytes_written;
  
  out = (GOutputStream*)g_file_replace (dest, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION,
                                        cancellable, error);
  if (!out)
    goto out;

  if (!g_output_stream_write_all (out,
                                  g_variant_get_data (variant),
                                  g_variant_get_size (variant),
                                  &bytes_written,
                                  cancellable,
                                  error))
    goto out;
  if (!g_output_stream_close (out, cancellable, error))
    goto out;

  ret = TRUE;
 out:
  return ret;
}
/**
 * shell_write_string_to_stream:
 * @stream: a #GOutputStream
 * @str: a UTF-8 string to write to @stream
 * @error: location to store GError
 *
 * Write a string to a GOutputStream as UTF-8. This is a workaround
 * for not having binary buffers in GJS.
 *
 * Return value: %TRUE if write succeeded
 */
gboolean
shell_write_string_to_stream (GOutputStream *stream,
                              const char    *str,
                              GError       **error)
{
  return g_output_stream_write_all (stream, str, strlen (str),
                                    NULL, NULL, error);
}
Пример #8
0
static gboolean
write_string (GOutputStream *out,
              const char    *str,
              GError       **error)
{
  return g_output_stream_write_all (out, str, strlen (str),
                                    NULL, NULL,
                                    error);
}
Пример #9
0
 void didReceiveData(ResourceHandle*, const char* data, int length, int /*encodedDataLength*/)
 {
     gsize bytesWritten;
     GOwnPtr<GError> error;
     g_output_stream_write_all(G_OUTPUT_STREAM(m_outputStream.get()), data, length, &bytesWritten, 0, &error.outPtr());
     if (error) {
         downloadFailed(downloadDestinationError(ResourceResponse(m_response.get()), error->message));
         return;
     }
     m_download->didReceiveData(bytesWritten);
 }
static gboolean
dispatch_bspatch (OstreeRepo                 *repo,
                  StaticDeltaExecutionState  *state,
                  GCancellable               *cancellable,
                  GError                    **error)
{
  gboolean ret = FALSE;
  guint64 offset, length;
  g_autoptr(GInputStream) in_stream = NULL;
  g_autoptr(GMappedFile) input_mfile = NULL;
  g_autofree guchar *buf = NULL;
  struct bspatch_stream stream;
  struct bzpatch_opaque_s opaque;
  gsize bytes_written;

  if (!read_varuint64 (state, &offset, error))
    goto out;
  if (!read_varuint64 (state, &length, error))
    goto out;

  if (!state->have_obj)
    {
      input_mfile = g_mapped_file_new_from_fd (state->read_source_fd, FALSE, error);
      if (!input_mfile)
        goto out;

      buf = g_malloc0 (state->content_size);

      opaque.state = state;
      opaque.offset = offset;
      opaque.length = length;
      stream.read = bspatch_read;
      stream.opaque = &opaque;
      if (bspatch ((const guint8*)g_mapped_file_get_contents (input_mfile),
                   g_mapped_file_get_length (input_mfile),
                   buf,
                   state->content_size,
                   &stream) < 0)
        goto out;

      if (!g_output_stream_write_all (state->content_out,
                                      buf,
                                      state->content_size,
                                      &bytes_written,
                                      cancellable, error))
        goto out;

      g_assert (bytes_written == state->content_size);
    }

  ret = TRUE;
 out:
  return ret;
}
Пример #11
0
void
g_vfs_afp_command_put_afp_name (GVfsAfpCommand *comm, GVfsAfpName *afp_name)
{
  g_vfs_afp_command_put_uint32 (comm, afp_name->text_encoding);
  g_vfs_afp_command_put_uint16 (comm, afp_name->len);

  if (afp_name->len > 0)
  {
    g_output_stream_write_all (G_OUTPUT_STREAM (comm), afp_name->str,
                               afp_name->len, NULL, NULL, NULL);
  }
}
Пример #12
0
static gboolean output_stream_write_bytes_all(GOutputStream *stream,
                                              GBytes *bytes,
                                              GCancellable *cancellable,
                                              GError **error)
{
	const void *buffer;
	gsize count, bytes_written;

	buffer = g_bytes_get_data(bytes, &count);
	return g_output_stream_write_all(stream, buffer, count, &bytes_written,
					 cancellable, error);
}
Пример #13
0
char *
ot_editor_prompt (OstreeRepo *repo,
                  const char *input,
                  GCancellable *cancellable,
                  GError **error)
{
  glnx_unref_object GSubprocess *proc = NULL;
  g_autoptr(GFile) file = NULL;
  g_autoptr(GFileIOStream) io = NULL;
  GOutputStream *output;
  const char *editor;
  char *ret = NULL;
  g_autofree char *args = NULL;

  editor = get_editor ();
  if (editor == NULL)
    {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Terminal is dumb, but EDITOR unset");
      goto out;
    }

  file = g_file_new_tmp (NULL, &io, error);
  if (file == NULL)
    goto out;

  output = g_io_stream_get_output_stream (G_IO_STREAM (io));
  if (!g_output_stream_write_all (output, input, strlen (input), NULL, cancellable, error) ||
      !g_io_stream_close (G_IO_STREAM (io), cancellable, error))
    goto out;

  {
    g_autofree char *quoted_file = g_shell_quote (gs_file_get_path_cached (file));
    args = g_strconcat (editor, " ", quoted_file, NULL);
  }

  proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_INHERIT, error, 
                           "/bin/sh", "-c", args, NULL);

  if (!g_subprocess_wait_check (proc, cancellable, error))
    {
      g_prefix_error (error, "There was a problem with the editor '%s'", editor);
      goto out;
    }

  ret = glnx_file_get_contents_utf8_at (AT_FDCWD, gs_file_get_path_cached (file), NULL,
                                        cancellable, error);

out:
  if (file)
    (void )g_file_delete (file, NULL, NULL);
  return ret;
}
Пример #14
0
static gboolean
handle_set_icon_data_url (CockpitAccount *object,
                          GDBusMethodInvocation *invocation,
                          const gchar *arg_data)
{
  GError *error = NULL;
  Account *acc = ACCOUNT (object);

  if (!account_auth_check (object, invocation, acc))
    return TRUE;

  if (acc->u)
    {
      const gchar *base64_data = strstr (arg_data, "base64,");
      if (base64_data == NULL)
        goto out;

      base64_data += strlen ("base64,");

      gsize raw_size;
      gs_free gchar *raw_data = (gchar *)g_base64_decode (base64_data, &raw_size);

      gs_unref_object GFileIOStream *tmp_stream = NULL;
      gs_unref_object GFile *tmp_file = g_file_new_tmp ("cockpit-user-icon-XXXXXX", &tmp_stream, &error);

      if (tmp_file == NULL)
        goto out;

      GOutputStream *out = g_io_stream_get_output_stream (G_IO_STREAM (tmp_stream));
      if (!g_output_stream_write_all (out, raw_data, raw_size, NULL, NULL, &error))
        goto out;

      if (!g_io_stream_close (G_IO_STREAM (tmp_stream), NULL, &error))
        goto out;

      gs_free gchar *tmp_path = g_file_get_path (tmp_file);
      act_user_set_icon_file (acc->u, tmp_path);
      g_file_delete (tmp_file, NULL, NULL);
    }

out:
  if (error)
    {
      g_dbus_method_invocation_return_error (invocation,
                                             COCKPIT_ERROR, COCKPIT_ERROR_FAILED,
                                             "%s", error->message);
      g_clear_error (&error);
    }
  else
    cockpit_account_complete_set_icon_data_url (object, invocation);
  return TRUE;
}
Пример #15
0
static gboolean
emqfe_headers_format (EMailFormatterExtension *extension,
                      EMailFormatter *formatter,
                      EMailFormatterContext *context,
                      EMailPart *part,
                      GOutputStream *stream,
                      GCancellable *cancellable)
{
	CamelContentType *ct;
	CamelMimePart *mime_part;
	const gchar *charset;
	GString *buffer;
	gchar **default_headers;
	guint ii, length = 0;

	g_return_val_if_fail (E_IS_MAIL_PART_HEADERS (part), FALSE);

	mime_part = e_mail_part_ref_mime_part (part);

	ct = camel_mime_part_get_content_type (mime_part);
	charset = camel_content_type_param (ct, "charset");
	charset = camel_iconv_charset_name (charset);

	buffer = g_string_new ("");

	/* dump selected headers */

	default_headers = e_mail_part_headers_dup_default_headers (
		E_MAIL_PART_HEADERS (part));
	if (default_headers != NULL)
		length = g_strv_length (default_headers);

	for (ii = 0; ii < length; ii++)
		emfqe_format_header (
			formatter, context, buffer, part,
			default_headers[ii], charset);

	g_strfreev (default_headers);

	g_string_append (buffer, HEADER_PREFIX);
	g_string_append (buffer, "<br>");
	g_string_append (buffer, HEADER_SUFFIX);

	g_output_stream_write_all (
		stream, buffer->str, buffer->len, NULL, cancellable, NULL);

	g_string_free (buffer, TRUE);

	g_object_unref (mime_part);

	return TRUE;
}
Пример #16
0
static GIOStream *
g_socks4a_proxy_connect (GProxy            *proxy,
			 GIOStream         *io_stream,
			 GProxyAddress     *proxy_address,
			 GCancellable      *cancellable,
			 GError           **error)
{
  GInputStream *in;
  GOutputStream *out;
  const gchar *hostname;
  guint16 port;
  const gchar *username;

  hostname = g_proxy_address_get_destination_hostname (proxy_address);
  port = g_proxy_address_get_destination_port (proxy_address);
  username = g_proxy_address_get_username (proxy_address);

  in = g_io_stream_get_input_stream (io_stream);
  out = g_io_stream_get_output_stream (io_stream);

  /* Send SOCKS4 connection request */
    {
      guint8 msg[SOCKS4_CONN_MSG_LEN];
      gint len;
      
      len = set_connect_msg (msg, hostname, port, username, error);

      if (len < 0)
	goto error;

      if (!g_output_stream_write_all (out, msg, len, NULL,
				      cancellable, error))
	goto error;
    }

  /* Read SOCKS4 response */
    {
      guint8 data[SOCKS4_CONN_REP_LEN];

      if (!g_input_stream_read_all (in, data, SOCKS4_CONN_REP_LEN, NULL,
				    cancellable, error))
	goto error;

      if (!parse_connect_reply (data, error))
	goto error;
    }

  return g_object_ref (io_stream);

error:
  return NULL;
}
Пример #17
0
static void
write_fn(png_structp png_ptr, png_bytep buffer, png_size_t length)
{
  GError *err = NULL;
  GOutputStream *stream = G_OUTPUT_STREAM(png_get_io_ptr(png_ptr));
  gsize bytes_written = 0;
  g_assert(stream);

  g_output_stream_write_all(stream, buffer, length, &bytes_written, NULL, &err);
  if (err) {
    g_printerr("gegl:save-png %s: %s\n", __PRETTY_FUNCTION__, err->message);
  }
}
Пример #18
0
/**
 * shell_write_soup_message_to_stream:
 * @stream: a #GOutputStream
 * @message: a #SoupMessage
 * @error: location to store GError
 *
 * Write a string to a GOutputStream as binary data. This is a
 * workaround for the lack of proper binary strings in GJS.
 */
void
shell_write_soup_message_to_stream (GOutputStream *stream,
                                    SoupMessage   *message,
                                    GError       **error)
{
  SoupMessageBody *body;

  body = message->response_body;

  g_output_stream_write_all (stream,
                             body->data, body->length,
                             NULL, NULL, error);
}
Пример #19
0
/**
 * tmpl_template_expand:
 * @self: A TmplTemplate.
 * @stream: a #GOutputStream to write the results to
 * @scope: (nullable): A #TmplScope containing state for the template, or %NULL.
 * @cancellable: (nullable): An optional cancellable for the operation.
 * @error: A location for a #GError, or %NULL.
 *
 * Expands a template into @stream using the @scope provided.
 *
 * @scope should have all of the variables set that are required to expand
 * the template, or you will get a symbol reference error and %FALSE will
 * be returned.
 *
 * To set a symbol value, get the symbol with tmpl_scope_get() and assign
 * a value using tmpl_scope_assign_value() or similar methods.
 *
 * Returns: %TRUE if successful, otherwise %FALSE and @error is set.
 */
gboolean
tmpl_template_expand (TmplTemplate  *self,
                      GOutputStream *stream,
                      TmplScope     *scope,
                      GCancellable  *cancellable,
                      GError       **error)
{
  TmplTemplatePrivate *priv = tmpl_template_get_instance_private (self);
  TmplTemplateExpandState state = { 0 };
  TmplScope *local_scope = NULL;

  g_return_val_if_fail (TMPL_IS_TEMPLATE (self), FALSE);
  g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
  g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);

  if (priv->parser == NULL)
    {
      g_set_error (error,
                   TMPL_ERROR,
                   TMPL_ERROR_INVALID_STATE,
                   _("Must parse template before expanding"));
      return FALSE;
    }

  if (scope == NULL)
    scope = local_scope = tmpl_scope_new ();

  state.root = tmpl_parser_get_root (priv->parser);
  state.self = self;
  state.output = g_string_new (NULL);
  state.result = TRUE;
  state.error = error;
  state.scope = scope;

  tmpl_node_visit_children (state.root, tmpl_template_expand_visitor, &state);

  if (state.result != FALSE)
    state.result = g_output_stream_write_all (stream,
                                              state.output->str,
                                              state.output->len,
                                              NULL,
                                              cancellable,
                                              error);

  g_string_free (state.output, TRUE);

  if (local_scope != NULL)
    tmpl_scope_unref (local_scope);

  return state.result;
}
Пример #20
0
static gboolean
send_request_sync (GOutputStream     *output,
                   DsiCommand        command,
                   guint16           request_id,
                   guint32           writeOffset,
                   gsize             len,
                   const char        *data,
                   GCancellable      *cancellable,
                   GError            **error)
{
  DSIHeader dsi_header;
  gboolean res;
  gsize write_count, bytes_written;

  dsi_header.flags = 0x00;
  dsi_header.command = command;
  dsi_header.requestID = GUINT16_TO_BE (request_id);
  dsi_header.writeOffset = GUINT32_TO_BE (writeOffset);
  dsi_header.totalDataLength = GUINT32_TO_BE (len); 
  dsi_header.reserved = 0;

  write_count = sizeof (DSIHeader);
  res = g_output_stream_write_all (output, &dsi_header, write_count,
                                   &bytes_written, cancellable, error);
  if (!res)
    return FALSE;

  if (data == NULL)
    return TRUE;

  write_count = len;
  res = g_output_stream_write_all (output, data, write_count, &bytes_written,
                                   cancellable, error);
  if (!res)
    return FALSE;

  return TRUE;
}
Пример #21
0
gboolean
byzanz_serialize_header (GOutputStream * stream,
                         guint           width,
                         guint           height,
                         GCancellable *  cancellable,
                         GError **       error)
{
  guint32 w, h;
  guchar endian;

  g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
  g_return_val_if_fail (width <= G_MAXUINT32, FALSE);
  g_return_val_if_fail (height <= G_MAXUINT32, FALSE);

  w = width;
  h = height;
  endian = byte_order_to_uchar ();

  return g_output_stream_write_all (stream, IDENTIFICATION, strlen (IDENTIFICATION), NULL, cancellable, error) &&
    g_output_stream_write_all (stream, &endian, sizeof (guchar), NULL, cancellable, error) &&
    g_output_stream_write_all (stream, &w, sizeof (guint32), NULL, cancellable, error) &&
    g_output_stream_write_all (stream, &h, sizeof (guint32), NULL, cancellable, error);
}
Пример #22
0
static gboolean output_stream_write_uint64_all(GOutputStream *stream,
                                              guint64 data,
                                              GCancellable *cancellable,
                                              GError **error)
{
	gsize bytes_written;
	gboolean res;

	data = GUINT64_TO_BE(data);
	res = g_output_stream_write_all(stream, &data, sizeof(data), &bytes_written,
					 cancellable, error);
	g_assert(bytes_written == sizeof(data));
	return res;
}
Пример #23
0
static void
send_error (GOutputStream * out, gint error_code, const gchar * reason)
{
  char *res;

  res = g_strdup_printf ("HTTP/1.0 %d %s\r\n\r\n"
                         "<html><head><title>%d %s</title></head>"
                         "<body>%s</body></html>",
                         error_code, reason,
                         error_code, reason,
                         reason);
  g_output_stream_write_all (out, res, strlen (res), NULL, NULL, NULL);
  g_free (res);
}
Пример #24
0
void sc_local_storage_manager_handle_chunk(ScLocalStorageManager *manager,
					   const gchar *buffer,
					   gint len) {
  GError *error = NULL;
  g_output_stream_write_all(G_OUTPUT_STREAM(manager->ostream),
				  buffer,
				  len,
				  NULL,
				  NULL,
				  &error);
  if(error) {
    g_critical(G_STRLOC ": %d : %s", error->code, error->message);
    g_error_free(error);
  }
}
Пример #25
0
    void didReceiveData(ResourceHandle*, const char* data, unsigned length, int /*encodedDataLength*/)
    {
        if (m_handleResponseLaterID) {
            g_source_remove(m_handleResponseLaterID);
            handleResponse();
        }

        gsize bytesWritten;
        GOwnPtr<GError> error;
        g_output_stream_write_all(G_OUTPUT_STREAM(m_outputStream.get()), data, length, &bytesWritten, 0, &error.outPtr());
        if (error) {
            downloadFailed(platformDownloadDestinationError(m_response, error->message));
            return;
        }
        m_download->didReceiveData(bytesWritten);
    }
Пример #26
0
static void
httpd_log (OtTrivialHttpd *httpd, const gchar *format, ...)
{
  g_autoptr(GString) str = NULL;
  va_list args;
  gsize written;

  if (!httpd->log)
    return;

  str = g_string_new (NULL);
  va_start (args, format);
  g_string_vprintf (str, format, args);
  va_end (args);

  g_output_stream_write_all (httpd->log, str->str, str->len, &written, NULL, NULL);
}
Пример #27
0
/* Called by gpgme to read data */
static ssize_t
output_write(void *handle, const void *buffer, size_t size)
{
	GOutputStream* output = handle;
	GError *err = NULL;
	gsize written;
	
	g_return_val_if_fail (G_IS_OUTPUT_STREAM (output), -1);
	
	if (!g_output_stream_write_all (output, buffer, size, &written, NULL, &err))
		return handle_gio_error (err);
	
	if (!g_output_stream_flush (output, NULL, &err))
		return handle_gio_error (err);
		
	return written;
}
Пример #28
0
gboolean
gimp_palette_save (GimpData       *data,
                   GOutputStream  *output,
                   GError        **error)
{
  GimpPalette *palette = GIMP_PALETTE (data);
  GString     *string;
  GList       *list;
  gsize        bytes_written;

  string = g_string_new ("GIMP Palette\n");

  g_string_append_printf (string,
                          "Name: %s\n"
                          "Columns: %d\n"
                          "#\n",
                          gimp_object_get_name (palette),
                          CLAMP (gimp_palette_get_columns (palette), 0, 256));

  for (list = gimp_palette_get_colors (palette);
       list;
       list = g_list_next (list))
    {
      GimpPaletteEntry *entry = list->data;
      guchar            r, g, b;

      gimp_rgb_get_uchar (&entry->color, &r, &g, &b);

      g_string_append_printf (string, "%3d %3d %3d\t%s\n",
                              r, g, b, entry->name);
    }

  if (! g_output_stream_write_all (output, string->str, string->len,
                                   &bytes_written, NULL, error) ||
      bytes_written != string->len)
    {
      g_string_free (string, TRUE);

      return FALSE;
    }

  g_string_free (string, TRUE);

  return TRUE;
}
Пример #29
0
static void hev_scgi_handler_response_error_message(HevSCGIHandlerCGITaskData *task_data,
			const gchar *message)
{
	GHashTable *res_hash_table = NULL;
	GOutputStream *output_stream = NULL;

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

	res_hash_table =
		hev_scgi_response_get_header_hash_table(HEV_SCGI_RESPONSE(task_data->scgi_response));
	g_hash_table_insert(res_hash_table, g_strdup("Status"), g_strdup("500 Internal Server Error"));
	g_hash_table_insert(res_hash_table, g_strdup("ContentType"), g_strdup("text/plain"));
	hev_scgi_response_write_header(HEV_SCGI_RESPONSE(task_data->scgi_response), NULL);

	output_stream = hev_scgi_response_get_output_stream(HEV_SCGI_RESPONSE(task_data->scgi_response));
	g_output_stream_write_all(output_stream, message, strlen(message), NULL, NULL, NULL);

	exit(EXIT_FAILURE);
}
static gboolean
emqfe_text_html_format (EMailFormatterExtension *extension,
                        EMailFormatter *formatter,
                        EMailFormatterContext *context,
                        EMailPart *part,
                        GOutputStream *stream,
                        GCancellable *cancellable)
{
	EMailFormatterQuoteContext *qf_context;
	GOutputStream *filtered_stream;
	const gchar *string;

	qf_context = (EMailFormatterQuoteContext *) context;

	string = "<!-- text/html -->";
	g_output_stream_write_all (
		stream, string, strlen (string), NULL, cancellable, NULL);

	filtered_stream = g_object_ref (stream);

	if ((qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_KEEP_SIG) == 0) {
		CamelMimeFilter *filter;
		GOutputStream *temp_stream;

		filter = e_mail_stripsig_filter_new (FALSE);
		temp_stream = camel_filter_output_stream_new (
			filtered_stream, filter);
		g_filter_output_stream_set_close_base_stream (
			G_FILTER_OUTPUT_STREAM (temp_stream), FALSE);
		g_object_unref (filtered_stream);
		filtered_stream = temp_stream;
		g_object_unref (filter);
	}

	e_mail_formatter_format_text (
		formatter, part, filtered_stream, cancellable);

	g_output_stream_flush (filtered_stream, cancellable, NULL);

	g_object_unref (filtered_stream);

	return TRUE;
}