static GsfInput * gsf_infile_zip_new_child (GsfInfileZip *parent, GsfZipVDir *vdir, GError **err) { GsfInfileZip *child; GsfZipDirent *dirent = vdir->dirent; child = zip_dup (parent, err); if (child == NULL) return NULL; gsf_input_set_name (GSF_INPUT (child), vdir->name); gsf_input_set_container (GSF_INPUT (child), GSF_INFILE (parent)); child->vdir = vdir; if (dirent) { gsf_input_set_size (GSF_INPUT (child), (gsf_off_t) dirent->usize); if (zip_child_init (child, err) != FALSE) { g_object_unref (child); return NULL; } } else gsf_input_set_size (GSF_INPUT (child), 0); return GSF_INPUT (child); }
/** * gsf_structured_blob_read: * @input: An input (potentially a GsfInfile) holding the blob * * Create a tree of binary blobs with unknown content from a #GsfInput or * #GsfInfile and store it in a newly created #GsfStructuredBlob. * * Returns: (transfer full): a new #GsfStructuredBlob object which the caller is responsible for. **/ GsfStructuredBlob * gsf_structured_blob_read (GsfInput *input) { GsfStructuredBlob *blob; gsf_off_t content_size; int i = 0; g_return_val_if_fail (GSF_IS_INPUT (input), NULL); blob = g_object_new (GSF_STRUCTURED_BLOB_TYPE, NULL); content_size = gsf_input_remaining (input); if (content_size > 0) { guint8 *buf = (guint8*)g_try_malloc (content_size); if (buf == NULL) { g_warning ("Failed attempting to allocate %" GSF_OFF_T_FORMAT " bytes", content_size); g_object_unref (blob); return NULL; } gsf_input_read (input, content_size, buf); blob->data = gsf_shared_memory_new (buf, content_size, TRUE); } gsf_input_set_name (GSF_INPUT (blob), gsf_input_name (input)); if (GSF_IS_INFILE (input)) i = gsf_infile_num_children (GSF_INFILE (input)); if (i > 0) { GsfInput *child; GsfStructuredBlob *child_blob; blob->children = g_ptr_array_sized_new (i); g_ptr_array_set_size (blob->children, i); while (i-- > 0) { child = gsf_infile_child_by_index (GSF_INFILE (input), i); child_blob = gsf_structured_blob_read (child); g_object_unref (child); g_ptr_array_index (blob->children, i) = child_blob; #if 0 /* * We don't need this, and setting it causes circular * links. */ gsf_input_set_container (GSF_INPUT (child_blob), GSF_INFILE (blob)); #endif } } return blob; }
static void set_name_from_file (GsfInput *input, GFile *file) { GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL); if (info) { gsf_input_set_name (input, g_file_info_get_name (info)); g_object_unref (info); } }
static GsfInput * make_local_copy (GFile *file, GInputStream *stream) { GsfOutput *out; GsfInput *copy; GFileInfo *info; out = gsf_output_memory_new (); while (1) { guint8 buf[4096]; gssize nread; nread = g_input_stream_read (stream, buf, sizeof(buf), NULL, NULL); if (nread > 0) { if (!gsf_output_write (out, nread, buf)) { copy = NULL; goto cleanup_and_exit; } } else if (nread == 0) break; else { copy = NULL; goto cleanup_and_exit; } } copy = gsf_input_memory_new_clone (gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)), gsf_output_size (out)); if (copy != NULL) { info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL); if (info) { gsf_input_set_name (GSF_INPUT (copy), g_file_info_get_name (info)); g_object_unref (info); } } cleanup_and_exit: gsf_output_close (out); g_object_unref (out); g_input_stream_close (stream, NULL, NULL); g_object_unref (stream); set_name_from_file (copy, file); return copy; }
/** * gsf_input_textline_new: * @source: in some combination of ascii and utf8 * * <note>This adds a reference to @source.</note> * * Returns: a new file or %NULL. **/ GsfInput * gsf_input_textline_new (GsfInput *source) { GsfInputTextline *input; g_return_val_if_fail (source != NULL, NULL); input = g_object_new (GSF_INPUT_TEXTLINE_TYPE, NULL); input->source = g_object_ref (source); input->buf = NULL; input->buf_size = 0; gsf_input_set_size (GSF_INPUT (input), gsf_input_size (source)); gsf_input_set_name (GSF_INPUT (input), gsf_input_name (source)); return GSF_INPUT (input); }
static GsfInfileTar * tar_create_dir (GsfInfileTar *dir, const char *name) { TarChild c; c.offset = 0; c.length = 0; c.name = g_strdup (name); c.dir = g_object_new (GSF_INFILE_TAR_TYPE, NULL); /* * We set the source here, so gsf_infile_tar_constructor doesn't * start reading the tarfile recursively. */ gsf_infile_tar_set_source (c.dir, dir->source); gsf_input_set_name (GSF_INPUT (c.dir), name); g_array_append_val (dir->children, c); return c.dir; }
/** * gsf_input_gzip_new : * @source : The underlying data source. * @err : optionally %NULL. * * Adds a reference to @source. * * Returns: a new file or %NULL. **/ GsfInput * gsf_input_gzip_new (GsfInput *source, GError **err) { GsfInputGZip *gzip; g_return_val_if_fail (GSF_IS_INPUT (source), NULL); gzip = g_object_new (GSF_INPUT_GZIP_TYPE, "source", source, NULL); if (G_UNLIKELY (NULL == gzip)) return NULL; if (gzip->err) { if (err) *err = g_error_copy (gzip->err); g_object_unref (gzip); return NULL; } gsf_input_set_name (GSF_INPUT (gzip), gsf_input_name (source)); return GSF_INPUT (gzip); }
static GsfInput * gsf_infile_tar_child_by_index (GsfInfile *infile, int target, GError **err) { GsfInfileTar *tar = GSF_INFILE_TAR (infile); const TarChild *c; if (err) *err = NULL; if (target < 0 || (unsigned)target >= tar->children->len) return NULL; c = &g_array_index (tar->children, TarChild, target); if (c->dir) return g_object_ref (c->dir); else { GsfInput *input = gsf_input_proxy_new_section (tar->source, c->offset, c->length); gsf_input_set_name (input, c->name); return input; } }