Example #1
0
/**
 * gsf_input_stdio_new_FILE :
 * @filename  : The filename corresponding to @file.
 * @file      : an existing stdio <type>FILE</type> *
 * @keep_open : Should @file be closed when the wrapper is closed
 *
 * Assumes ownership of @file when succeeding.  If @keep_open is true,
 * ownership reverts to caller when the GsfObject is closed.
 *
 * Returns: a new GsfInput wrapper for @file.  Note that if the file is not
 * 	seekable, this function will make a local copy of the entire file.
 **/
GsfInput *
gsf_input_stdio_new_FILE (char const *filename, FILE *file, gboolean keep_open)
{
	GsfInputStdio *stdio;
	struct stat st;
	gsf_off_t size;

	g_return_val_if_fail (filename != NULL, NULL);
	g_return_val_if_fail (file != NULL, NULL);

	if (fstat (fileno (file), &st) < 0 || !S_ISREG (st.st_mode)) {
		return make_local_copy (file, filename, NULL);
	}

	size = st.st_size;

	stdio = g_object_new (GSF_INPUT_STDIO_TYPE, NULL);
	if (G_UNLIKELY (NULL == stdio)) return NULL;
	stdio->file = file;
	stdio->keep_open = keep_open;
	stdio->filename = g_strdup (filename);
	gsf_input_set_size (GSF_INPUT (stdio), size);
	gsf_input_set_name_from_filename (GSF_INPUT (stdio), filename);
	return GSF_INPUT (stdio);
}
Example #2
0
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);
}
Example #3
0
static GlpkFileVersion
gnm_glpk_detect_version (GnmGlpk *lp,
			 GsfInputTextline *tl)
{
	GnmSubSolver *subsol = lp->parent;
	gsf_off_t cur = gsf_input_tell (GSF_INPUT (tl));
	GlpkFileVersion ver = GLPK_UNKNOWN;
	const char *line;
	unsigned cols, rows;

	if ((line = gsf_input_textline_utf8_gets (tl)) == NULL)
		goto out;
	if (sscanf (line, "%u %u", &rows, &cols) == 2 &&
	    cols == g_hash_table_size (subsol->cell_from_name)) {
		ver = GLPK_457;
		if (gnm_solver_debug ())
			g_printerr ("Detected version 4.57 file format\n");
		goto out;
	}

	if ((line[0] == 'c' || line[0] == 's') && line[1] == ' ') {
		ver = GLPK_458;
		if (gnm_solver_debug ())
			g_printerr ("Detected version 4.58 file format\n");
		goto out;
	}	

out:
	// Extra seek due to gsf bug
	gsf_input_seek (GSF_INPUT (tl), cur + 1, G_SEEK_SET);
	gsf_input_seek (GSF_INPUT (tl), cur, G_SEEK_SET);
	return ver;
}
Example #4
0
/**
 * 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;
}
Example #5
0
static GsfInput *
gsf_input_textline_dup (GsfInput *src_input, G_GNUC_UNUSED GError **err)
{
	GsfInputTextline const *src = (GsfInputTextline *)src_input;
	GsfInputTextline *dst = g_object_new (GSF_INPUT_TEXTLINE_TYPE, NULL);

	dst->source = g_object_ref (src->source);
	gsf_input_set_size (GSF_INPUT (dst), gsf_input_size (src_input));

	return GSF_INPUT (dst);
}
Example #6
0
/* coverity[ -tainted_string_sink_content : arg-0 ] */
GsfInput *
gsf_input_stdio_new (char const *filename, GError **err)
{
	GsfInputStdio *input;
	struct stat st;
	FILE *file;
	gsf_off_t size;

	g_return_val_if_fail (filename != NULL, NULL);

	file = g_fopen (filename, "rb");
	if (file == NULL) {
		if (err) {
			int save_errno = errno;
			char *utf8name = g_filename_display_name (filename);
			g_set_error (err,
				     G_FILE_ERROR,
				     g_file_error_from_errno (save_errno),
				     "%s: %s",
				     utf8name, g_strerror (save_errno));
			g_free (utf8name);
		}
		return NULL;
	}

	if (fstat (fileno (file), &st) < 0 || !S_ISREG (st.st_mode)) {
		GsfInput *res = make_local_copy (file, filename, err);
		fclose (file);
		return res;
	}

	size = st.st_size;
	input = (GsfInputStdio *)g_object_new (GSF_INPUT_STDIO_TYPE, NULL);
	if (G_UNLIKELY (NULL == input)) {
		fclose (file);
		return NULL;
	}

	input->file = file;
	input->filename = g_strdup (filename);
	input->buf  = NULL;
	input->buf_size = 0;
	input->keep_open = FALSE;
	gsf_input_set_size (GSF_INPUT (input), size);
	gsf_input_set_name_from_filename (GSF_INPUT (input), filename);

	return GSF_INPUT (input);
}
Example #7
0
/**
 * 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);
}
Example #8
0
static GsfInput *
gsf_infile_ar_dup (GsfInput *src_input, GError **err)
{
	GsfInfileAr const *src = GSF_INFILE_AR (src_input);
	GsfInfileAr *dst = ar_dup (src);

	if (dst == NULL) {
		if (err != NULL)
			*err = g_error_new (gsf_input_error_id (), 0,
					    "Something went wrong in ar_dup.");
		return NULL;
	}

	dst->vdir = src->vdir;

	if (dst->vdir->dirent)
		if (ar_child_init (dst) != FALSE) {
			g_object_unref (dst);
			if (err != NULL)
				*err = g_error_new (gsf_input_error_id (), 0,
						    "Something went wrong in ar_child_init.");
			return NULL;
		}

	return GSF_INPUT (dst);
}
Example #9
0
static GsfInput *
blob_dup (GsfInput *input, G_GNUC_UNUSED GError **err)
{
	GsfStructuredBlob const *src = (GsfStructuredBlob *) input;
	GsfStructuredBlob *dst = g_object_new (GSF_STRUCTURED_BLOB_TYPE, NULL);

	if (src->data != NULL)
		dst->data = g_object_ref (src->data);

	if (src->children != NULL) {
		unsigned i;
		gpointer child;

		dst->children = g_ptr_array_sized_new (src->children->len);
		g_ptr_array_set_size  (dst->children, src->children->len);
		for (i = 0; i < src->children->len ; i++) {
			child = g_ptr_array_index (src->children, i);
			g_ptr_array_index (dst->children, i) = child
				? g_object_ref (child)
				: NULL;
		}
	}

	return GSF_INPUT (dst);
}
Example #10
0
/**
 * gsf_structured_blob_write:
 * @blob: #GsfStructuredBlob
 * @container: #GsfOutfile
 *
 * Dumps structured blob @blob onto the @container.  Will fail if the output is
 * not an Outfile and blob has multiple streams.
 *
 * Returns: %TRUE on success.
 **/
gboolean
gsf_structured_blob_write (GsfStructuredBlob *blob, GsfOutfile *container)
{
	GsfOutput *output;
	gboolean has_kids;

	g_return_val_if_fail (GSF_IS_STRUCTURED_BLOB (blob), FALSE);
	g_return_val_if_fail (GSF_IS_OUTFILE (container), FALSE);

	has_kids = (blob->children != NULL && blob->children->len > 0);

	output = gsf_outfile_new_child  (GSF_OUTFILE (container),
		gsf_input_name (GSF_INPUT (blob)),
		has_kids);
	if (has_kids) {
		GsfStructuredBlob *child_blob;
		unsigned i;

		for (i = 0 ; i < blob->children->len ; i++) {
			child_blob = g_ptr_array_index (blob->children, i);
			if (!gsf_structured_blob_write (child_blob, GSF_OUTFILE (output)))
				return FALSE;
		}
	}

	if (blob->data != NULL)
		gsf_output_write (output, blob->data->size, blob->data->buf);
	gsf_output_close (output);
	g_object_unref (output);

	return TRUE;
}
Example #11
0
File: gsf.c Project: arcean/libgsf
static int
gsf_list (int argc, char **argv)
{
	int i;

	for (i = 0; i < argc; i++) {
		char const *filename = argv[i];
		char *display_name;
		GsfInfile *infile = open_archive (filename);
		if (!infile)
			return 1;

		if (i > 0)
			g_print ("\n");

		display_name = g_filename_display_name (filename);
		g_print ("%s:\n", display_name);
		g_free (display_name);

		ls_R (GSF_INPUT (infile), NULL);
		g_object_unref (infile);
	}

	return 0;
}
Example #12
0
static int
test (char *argv[])
{
	GsfInfile  *infile;
	GsfOutfile *outfile;
	GsfOutput  *output;
	GError    *err = NULL;

	fprintf (stderr, "%s\n", argv [1]);
	infile = gsf_infile_stdio_new (argv[1], &err);
	if (infile == NULL) {
		g_return_val_if_fail (err != NULL, 1);

		g_warning ("'%s' error: %s", argv[1], err->message);
		g_error_free (err);
		return 1;
	}

	output = gsf_output_stdio_new (argv[2], &err);
	if (output == NULL) {
		g_return_val_if_fail (err != NULL, 1);

		g_warning ("'%s' error: %s", argv[2], err->message);
		g_error_free (err);
		g_object_unref (G_OBJECT (infile));
		return 1;
	}

	outfile = gsf_outfile_msole_new (output);
	g_object_unref (G_OBJECT (output));
	clone (GSF_INPUT (infile), GSF_OUTPUT (outfile));

	return 0;
}
GsfInput * OXMLi_PackageManager::_getDocumentStream()
{
	UT_return_val_if_fail(m_pPkg != NULL, NULL);

	if (m_pDocPart == NULL)
		m_pDocPart = getChildByType ( GSF_INPUT (m_pPkg), DOCUMENT_PART );
	return m_pDocPart;
}
Example #14
0
/**
 * gsf_input_gio_new:
 * @file:
 * @err: optionally NULL.
 *
 * Returns: A new #GsfInputGio or NULL
 */
GsfInput *
gsf_input_gio_new (GFile *file, GError **err)
{
	GsfInputGio *input;
	GInputStream *stream;
	gsf_off_t filesize;

	g_return_val_if_fail (file != NULL, NULL);

	stream = (GInputStream *)g_file_read (file, NULL, err);
	if (stream == NULL)
		return NULL;

	if (!can_seek (stream))
		return make_local_copy (file, stream);

	{
		GFileInfo *info =
			g_file_query_info (file,
					   G_FILE_ATTRIBUTE_STANDARD_SIZE,
					   0, NULL, NULL);
		if (!info)
			return make_local_copy (file, stream);
		filesize = g_file_info_get_size (info);
		g_object_unref (info);
	}

	input = g_object_new (GSF_INPUT_GIO_TYPE, NULL);
	if (G_UNLIKELY (NULL == input)) {
		g_input_stream_close (stream, NULL, NULL);
		g_object_unref (stream);
		return NULL;
	}

	gsf_input_set_size (GSF_INPUT (input), filesize);

	g_object_ref (file);

	input->stream = stream;
	input->file = file;
	input->buf  = NULL;
	input->buf_size = 0;

	set_name_from_file (GSF_INPUT (input), file);
	return GSF_INPUT (input);
}
Example #15
0
/**
 * gsf_input_gio_new:
 * @file:
 * @err: (allow-none): place to store a #GError if anything goes wrong
 *
 * Returns: A new #GsfInputGio or %NULL
 */
GsfInput *
gsf_input_gio_new (GFile *file, GError **err)
{
    GsfInputGio *input;
    GInputStream *stream;
    gsf_off_t filesize;

    g_return_val_if_fail (file != NULL, NULL);

    stream = (GInputStream *)g_file_read (file, NULL, err);
    if (stream == NULL)
        return NULL;

    if (1) {
        /* see https://bugzilla.gnome.org/show_bug.cgi?id=724970 */
        return make_local_copy (file, stream);
    }

    if (!can_seek (stream))
        return make_local_copy (file, stream);

    {
        GFileInfo *info =
            g_file_query_info (file,
                               G_FILE_ATTRIBUTE_STANDARD_SIZE,
                               0, NULL, NULL);
        if (!info)
            return make_local_copy (file, stream);
        filesize = g_file_info_get_size (info);
        g_object_unref (info);
    }

    input = g_object_new (GSF_INPUT_GIO_TYPE, NULL);

    gsf_input_set_size (GSF_INPUT (input), filesize);

    g_object_ref (file);

    input->stream = stream;
    input->file = file;
    input->buf  = NULL;
    input->buf_size = 0;

    set_name_from_file (GSF_INPUT (input), file);
    return GSF_INPUT (input);
}
Example #16
0
static void
gsf_input_gzip_set_source (GsfInputGZip *gzip, GsfInput *source)
{
	if (source)
		g_object_ref (GSF_INPUT (source));
	if (gzip->source)
		g_object_unref (gzip->source);
	gzip->source = source;
}
Example #17
0
File: support.c Project: AbiWord/wv
U32
wvStream_goto (wvStream * in, long position)
{
    if (in->kind == GSF_STREAM)
      {
	gsf_input_seek (GSF_INPUT (in->stream.gsf_stream), position, G_SEEK_SET);
	return (U32)gsf_input_tell(GSF_INPUT (in->stream.gsf_stream));
      }
    else if (in->kind == FILE_STREAM)
      {
	  return ((U32) fseek (in->stream.file_stream, position, SEEK_SET));
      }
    else
      {
	in->stream.memory_stream->current = position;
        return in->stream.memory_stream->current;
      }
}
Example #18
0
File: support.c Project: AbiWord/wv
U32
wvStream_offset (wvStream * in, long offset)
{
    if (in->kind == GSF_STREAM)
      {
	gsf_input_seek (GSF_INPUT (in->stream.gsf_stream), offset, G_SEEK_CUR);
	return (U32)gsf_input_tell(GSF_INPUT (in->stream.gsf_stream));
      }
    else if (in->kind == FILE_STREAM)
      {
	  return ((U32) fseek (in->stream.file_stream, offset, SEEK_CUR));
      }
    else
      {
	in->stream.memory_stream->current += offset;
	return  in->stream.memory_stream->current;
      }
}
Example #19
0
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;
}
Example #20
0
/**
 * 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);
}
Example #21
0
static GsfInput *
make_local_copy (FILE *stream, const char *filename, GError **err)
{
	GsfOutput *out;
	GsfInput *copy = NULL;

	out = gsf_output_memory_new ();

	while (1) {
		guint8 buf[4096];
		gssize nread;

		nread = fread (buf, 1, sizeof(buf), stream);

		if (nread > 0) {
			if (!gsf_output_write (out, nread, buf))
				goto error;
		} else if (nread == 0)
			break;
		else
			goto error;
	}

	copy = gsf_input_memory_new_clone
		(gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)),
		 gsf_output_size (out));

	gsf_output_close (out);
	g_object_unref (out);

	if (filename)
		gsf_input_set_name_from_filename (GSF_INPUT (copy), filename);

	return copy;

error:
	if (err) {
		char *utf8name = filename
			? g_filename_display_name (filename)
			: g_strdup ("?");
		g_set_error (err, gsf_input_error_id (), 0,
			     "%s: not a regular file",
			     utf8name);
		g_free (utf8name);
	}

	gsf_output_close (out);
	g_object_unref (out);

	return NULL;
}
Example #22
0
/* Add the filename under path to the gst_outfile. */
static void add_file_to_gst_outfile (GsfOutfile   *out_file,
                                     gchar        *path,
                                     const gchar  *file_name)
{
  GError   *err = (GError *) NULL;
  gchar *file_path = g_build_filename (path, file_name, NULL);
  GsfInput *input = GSF_INPUT (gsf_input_stdio_new (file_path, &err));
  GsfOutput  *child  = gsf_outfile_new_child (out_file, file_name, FALSE);

  gsf_input_copy (input, child);
  gsf_output_close (child);
  g_object_unref (child);
  g_object_unref (input);

  g_free (file_path);
}
Example #23
0
File: support.c Project: AbiWord/wv
U32
wvStream_tell (wvStream * in)
{
    if (in->kind == GSF_STREAM)
      {
	return (U32)gsf_input_tell(GSF_INPUT (in->stream.gsf_stream));
      }
    else if(in->kind == FILE_STREAM)
      {
	  return ((U32) ftell (in->stream.file_stream));
      }
    else
      {
	return (in->stream.memory_stream->current);
      }
}
Example #24
0
static GsfInput *
gsf_infile_stdio_dup (GsfInput *src_input, G_GNUC_UNUSED GError **err)
{
	GsfInfileStdio *src = GSF_INFILE_STDIO (src_input);
	unsigned ui;

	GsfInfileStdio *dst = g_object_new (GSF_INFILE_STDIO_TYPE, NULL);
	dst->root = g_strdup (src->root);

	for (ui = 0; ui < src->children->len; ui++) {
		const char *child = g_ptr_array_index (src->children, ui);
		g_ptr_array_add (dst->children, g_strdup (child));
	}

	return GSF_INPUT (dst);
}
Example #25
0
File: support.c Project: AbiWord/wv
void
wvStream_rewind (wvStream * in)
{
    if (in->kind == GSF_STREAM)
      {
	gsf_input_seek (GSF_INPUT (in->stream.gsf_stream), 0, G_SEEK_SET);
      }
    else if (in->kind == FILE_STREAM)
      {
	  rewind (in->stream.file_stream);
      }
    else
      {
	in->stream.memory_stream->current = 0;
      }
}
Example #26
0
/**
 * gsf_open_pkg_open_rel:
 * @opkg: #GsfInput
 * @rel: #GsfOpenPkgRel
 * @err: #GError.
 *
 * Returns: (transfer full): a new #GsfInput which the called needs to unref, or %NULL and sets @err
 **/
GsfInput *
gsf_open_pkg_open_rel (GsfInput *opkg, GsfOpenPkgRel const *rel,
		       G_GNUC_UNUSED GError **err /* just in case we need it one day */ )
{
	GsfInput *res = NULL;
	GsfInfile *parent, *prev_parent;
	gchar **elems;
	unsigned i;

	g_return_val_if_fail (rel != NULL, NULL);
	g_return_val_if_fail (opkg != NULL, NULL);

	/* References from the root use children of opkg
	 * References from a child are relative to siblings of opkg */
	parent = gsf_input_name (opkg)
		? gsf_input_container (opkg) : GSF_INFILE (opkg);
	g_object_ref (parent);

	elems = g_strsplit (rel->target, "/", 0);
	for (i = 0 ; elems[i] && NULL != parent ; i++) {
		if (0 == strcmp (elems[i], ".") || '\0' == *elems[i])
			continue; /* ignore '.' and empty */

		prev_parent = parent;
		if (0 == strcmp (elems[i], "..")) {
			parent = gsf_input_container (GSF_INPUT (parent));
			res = NULL;	/* only return newly created children */
			if (NULL != parent) {
				/* check for attempt to gain access outside the zip file */
				if (G_OBJECT_TYPE (parent) == G_OBJECT_TYPE (prev_parent))
					g_object_ref (parent);
				else
					parent = NULL;
			}
		} else {
			res = gsf_infile_child_by_name (parent, elems[i]);
			if (NULL != elems[i+1]) {
				g_return_val_if_fail (GSF_IS_INFILE (res), NULL);
				parent = GSF_INFILE (res);
			}
		}
		g_object_unref (prev_parent);
	}
	g_strfreev (elems);

	return res;
}
Example #27
0
File: support.c Project: AbiWord/wv
U32
wvStream_read (void *ptr, size_t size, size_t nmemb, wvStream * in)
{
    if (in->kind == GSF_STREAM)
      {
	gsf_input_read (GSF_INPUT (in->stream.gsf_stream), size*nmemb, ptr);
	return size*nmemb;
      }
    else if (in->kind == FILE_STREAM)
      {
	  return (fread (ptr, size, nmemb, in->stream.file_stream));
      }
    else
      {
	return memorystream_read(in->stream.memory_stream, ptr, size * nmemb);
      }
}
Example #28
0
static GsfInput *
gsf_infile_zip_dup (GsfInput *src_input, GError **err)
{
	GsfInfileZip const *src = GSF_INFILE_ZIP (src_input);
	GsfInfileZip *dst = zip_dup (src, err);

	if (dst == NULL)
		return NULL;

	dst->vdir = src->vdir;

	if (dst->vdir->dirent && zip_child_init (dst, err)) {
		g_object_unref (dst);
		return NULL;
	}

	return GSF_INPUT (dst);
}
Example #29
0
UT_Error IE_Imp_EPUB::readPackage()
{
    gchar **aname = g_strsplit(m_rootfilePath.c_str(), G_DIR_SEPARATOR_S, 0);
    GsfInput* opf = gsf_infile_child_by_aname(m_epub, (const char**) aname);

    UT_DEBUGMSG(("Getting parent\n"));
    GsfInfile* opfParent = gsf_input_container(opf);
    m_opsDir = std::string(gsf_input_name(GSF_INPUT(opfParent)));

    UT_DEBUGMSG(("OPS dir: %s\n", m_opsDir.c_str()));

    if (opf == NULL)
    {
        UT_DEBUGMSG(("Can`t open .opf file\n"));
        return UT_ERROR;
    }

    size_t opfSize = gsf_input_size(opf);
    gchar* opfXml = (gchar*) gsf_input_read(opf, opfSize, NULL);

    UT_XML opfParser;
    OpfListener opfListener;
    opfParser.setListener(&opfListener);
    if (opfParser.sniff(opfXml, opfSize, "package"))
    {
        UT_DEBUGMSG(("Parsing opf file\n"));
        opfParser.parse(opfXml, opfSize);
    }
    else
    {
        UT_DEBUGMSG(("Incorrect opf file found \n"));
        return UT_ERROR;
    }

    g_strfreev(aname);
    g_object_unref(G_OBJECT(opf));
    //g_object_unref(G_OBJECT(opfParent));

    m_spine = opfListener.getSpine();
    m_manifestItems = opfListener.getManifestItems();

    return UT_OK;
}
Example #30
0
/**
 * gsf_input_find_vba:
 * @input: #GsfInput
 * @err: #GError, optionally %NULL.
 *
 * A utility routine that attempts to find the VBA file withint a stream.
 *
 * Returns: (transfer full): a GsfInfile
 **/
GsfInfileMSVBA *
gsf_input_find_vba (GsfInput *input, GError **err)
{
	GsfInput  *vba = NULL;
	GsfInfile *infile;

	if (NULL != (infile = gsf_infile_msole_new (input, NULL))) {
		/* 1) Try XLS */
		vba = gsf_infile_child_by_vname (infile, "_VBA_PROJECT_CUR", "VBA", NULL);
		/* 2) DOC */
		if (NULL == vba)
			vba = gsf_infile_child_by_vname (infile, "Macros", "VBA", NULL);

		/* TODO : PPT is more complex */

		g_object_unref (infile);
	} else if (NULL != (infile = gsf_infile_zip_new (input, NULL))) {
		GsfInput *main_part = gsf_open_pkg_open_rel_by_type (GSF_INPUT (infile),
			"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
		        NULL);

		if (NULL != main_part) {
			GsfInput *vba_stream = gsf_open_pkg_open_rel_by_type (main_part,
				"http://schemas.microsoft.com/office/2006/relationships/vbaProject",
			        NULL);
			if (NULL != vba_stream) {
				GsfInfile *ole = gsf_infile_msole_new (vba_stream, err);
				if (NULL != ole) {
					vba = gsf_infile_child_by_vname (ole, "VBA", NULL);
					g_object_unref (ole);
				}
				g_object_unref (vba_stream);
			}
			g_object_unref (main_part);
		}
		g_object_unref (infile);
	}

	if (NULL != vba)
	       return (GsfInfileMSVBA *)
			gsf_infile_msvba_new (GSF_INFILE (vba), err);
	return NULL;
}