Example #1
0
/* Decompress the iwb file; it is a zip file. */
static void
decompress_iwb (gchar *iwbfile,
                gchar *project_tmp_dir)
{
    GError   *err = (GError *) NULL;
    GsfInput   *input = (GsfInput *) NULL;
    GsfInfile  *infile = (GsfInfile *) NULL;

    gsf_init ();

    input = gsf_input_stdio_new (iwbfile, &err);

    infile = gsf_infile_zip_new (input, &err);
    g_object_unref (G_OBJECT (input));

    if (infile == NULL)
    {
        g_warning ("Error decompressing iwb file %s: %s", iwbfile, err->message);
        g_error_free (err);
        return;
    }

    decompress_infile (infile, project_tmp_dir);
    g_object_unref (G_OBJECT (infile));
    gsf_shutdown ();
}
Example #2
0
static void
read_thumbnail_and_write (const char *in_filename, const char *out_filename, int thumb_size)
{
	GsfInput  *input;
	GsfInfile *infile;
	GError	  *error;

	input = gsf_input_mmap_new (in_filename, NULL);
	if (!input) {
		error = NULL;
		input = gsf_input_stdio_new (in_filename, &error);
		if (!input)
			show_error_and_exit (error);
	}

	input = gsf_input_uncompress (input);

	error = NULL;
	if (NULL != (infile = gsf_infile_msole_new (input, &error)))
		msole_thumbnail (infile, out_filename, thumb_size);
	else if (NULL != (infile = gsf_infile_zip_new (input, &error)))
		zip_thumbnail (infile, out_filename, thumb_size);
	else
		show_error_and_exit (error);

	g_object_unref (infile);
	g_object_unref (input);
}
Example #3
0
const char * AbiWordperfectInputStream::subStreamName(unsigned id)
{
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_msole_new (m_input, NULL)); 
	
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_zip_new (m_input, NULL)); 
	
	if (m_ole)
		{
			if ((int)id >= gsf_infile_num_children(m_ole))
			{
				return 0;
			}
			std::map<unsigned, std::string>::iterator i = m_substreams.lower_bound(id);
			if (i == m_substreams.end() || m_substreams.key_comp()(id, i->first))
				{
					std::string name = gsf_infile_name_by_index(m_ole, (int)id);
					i = m_substreams.insert(i, std::map<unsigned, std::string>::value_type(id, name));
				}
			return i->second.c_str();
		}
	
	return 0;
}
Example #4
0
bool AbiWordperfectInputStream::isStructured()
{
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_msole_new (m_input, NULL)); 

	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_zip_new (m_input, NULL)); 
	
	if (m_ole)
		return true;

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

	fprintf (stderr, "%s\n", argv [1]);
	input = gsf_input_stdio_new (argv[1], &err);
	if (input == NULL) {

		g_return_val_if_fail (err != NULL, 1);

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

	infile = gsf_infile_zip_new (input, &err);
	g_object_unref (G_OBJECT (input));

	if (infile == NULL) {
		g_return_val_if_fail (err != NULL, 1);

		g_warning ("'%s' Not a zip file: %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_zip_new (output, &err);
	g_object_unref (G_OBJECT (output));
	clone_ (infile, outfile);

	return 0;
}
Example #6
0
unsigned AbiWordperfectInputStream::subStreamCount()
{
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_msole_new (m_input, NULL)); 
	
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_zip_new (m_input, NULL)); 
	
	if (m_ole)
		{
			int numChildren = gsf_infile_num_children(m_ole);
			if (numChildren > 0)
				return numChildren;
			return 0;
		}
	
	return 0;
}
Example #7
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;
}
Example #8
0
bool AbiWordperfectInputStream::existsSubStream(const char * name)
{
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_msole_new (m_input, NULL)); 
	
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_zip_new (m_input, NULL)); 
	
	if (m_ole)
		{
			GsfInput *document = gsf_infile_child_by_name(m_ole, name);
			if (document) 
				{
					g_object_unref(G_OBJECT (document));
					return true;
				}
		}
	
	return false;
}
/**
 * Recognize the contents as best we can
 * 
 */
UT_Confidence_t IE_Imp_OpenDocument_Sniffer::recognizeContents (GsfInput * input)
{
    UT_Confidence_t confidence = UT_CONFIDENCE_ZILCH;
	
	GsfInfile * zip  = gsf_infile_zip_new (input, NULL);
	if (zip != NULL) {
		GsfInput* pInput = gsf_infile_child_by_name(zip, "mimetype");
		
		if (pInput) {
			std::string mimetype;
			
			gsf_off_t size = gsf_input_size (pInput);
			if (size > 0) {
				const char * p = (const char *)gsf_input_read(pInput, size, NULL);
				if(p) {
					mimetype.assign(p, size);
				}
			}

			if ((mimetype == "application/vnd.oasis.opendocument.text") ||
				(mimetype == "application/vnd.oasis.opendocument.text-template") ||
				(mimetype == "application/vnd.oasis.opendocument.text-web")) {
				confidence = UT_CONFIDENCE_PERFECT;
			}
			
			g_object_unref (G_OBJECT (pInput));
		}
		else {
			// we need to figure out what to do without mimetype file.
			pInput = gsf_infile_child_by_name(zip, "content.xml");
			if(pInput) {
				// we need to identify further to get a better confidence.
				confidence = UT_CONFIDENCE_SOSO;
			}
			g_object_unref (G_OBJECT (pInput));
		}
		g_object_unref (G_OBJECT (zip));
	}

	return confidence;
}
Example #10
0
UT_Error IE_Imp_EPUB::_loadFile(GsfInput* input)
{
    m_epub = gsf_infile_zip_new(input, NULL);

    if (m_epub == NULL)
    {
        UT_DEBUGMSG(("Can`t create gsf input zip object\n"));
        return UT_ERROR;
    }

    UT_DEBUGMSG(("Reading metadata\n"));
    if (readMetadata() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to read metadata\n"));
        return UT_ERROR;
    }

    UT_DEBUGMSG(("Reading package information\n"));
    if (readPackage() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to read package information\n"));
        return UT_ERROR;
    }

    UT_DEBUGMSG(("Uncompressing OPS data\n"));
    if (uncompress() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to uncompress data\n"));
        return UT_ERROR;
    }

    UT_DEBUGMSG(("Reading OPS data\n"));
    if (readStructure() != UT_OK)
    {
        UT_DEBUGMSG(("Failed to read OPS data\n"));
        return UT_ERROR;
    }

    return UT_OK;

}
Example #11
0
librevenge::RVNGInputStream * AbiWordperfectInputStream::getSubStreamById(unsigned id)
{
	librevenge::RVNGInputStream *documentStream = NULL;
	
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_msole_new (m_input, NULL)); 
	
	if (!m_ole)
		m_ole = GSF_INFILE(gsf_infile_zip_new (m_input, NULL)); 
	
	if (m_ole)
		{
			GsfInput *document = gsf_infile_child_by_index(m_ole, (int)id);
			if (document) 
				{
					documentStream = new AbiWordperfectInputStream(document);
					g_object_unref(G_OBJECT (document)); // the only reference should be encapsulated within the new stream
				}
		}
	
	return documentStream;
}
Example #12
0
static int
test (int argc, char *argv[])
{
	GsfInput  *input;
	GsfInfile *infile;
	GError    *err = NULL;
	int i;

	puts (argv[1]);
	input = gsf_input_stdio_new (argv[1], &err);
	if (input == NULL) {

		g_return_val_if_fail (err != NULL, 1);

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

	infile = gsf_infile_zip_new (input, &err);
	if (infile == NULL) {

		g_return_val_if_fail (err != NULL, 1);

		g_warning ("'%s' Not a Zip file: %s", argv[1], err->message);
		g_error_free (err);
		g_object_unref (G_OBJECT (input));
		return -1;
	}

	for (i = 2 ; i < argc ; i++) {
		dump_child (infile, argv[i]);
	}
	g_object_unref (G_OBJECT (infile));
	g_object_unref (G_OBJECT (input));

	return 0;
}
Example #13
0
File: gsf.c Project: arcean/libgsf
static GsfInfile *
open_archive (char const *filename)
{
	GsfInfile *infile;
	GError *error = NULL;	
	GsfInput *src;
	char *display_name;

	src = gsf_input_stdio_new (filename, &error);
	if (error) {
		display_name = g_filename_display_name (filename);
		g_printerr (_("%s: Failed to open %s: %s\n"),
			    g_get_prgname (),
			    display_name,
			    error->message);
		g_free (display_name);
		return NULL;
	}

	infile = gsf_infile_zip_new (src, NULL);
	if (infile)
		return infile;

	infile = gsf_infile_msole_new (src, NULL);
	if (infile)
		return infile;

	infile = gsf_infile_tar_new (src, NULL);
	if (infile)
		return infile;

	display_name = g_filename_display_name (filename);
	g_printerr (_("%s: Failed to recognize %s as an archive\n"),
		    g_get_prgname (),
		    display_name);
	g_free (display_name);
	return NULL;
}
/**
 * Import the given file
 */
UT_Error IE_Imp_OpenDocument::_loadFile (GsfInput * oo_src)
{
    m_pGsfInfile = GSF_INFILE (gsf_infile_zip_new (oo_src, NULL));
    
    if (m_pGsfInfile == NULL) {
        return UT_ERROR;
    }

    m_pAbiData = new ODi_Abi_Data(getDoc(), m_pGsfInfile);    
    m_pStreamListener = new ODi_StreamListener(getDoc(), m_pGsfInfile, &m_styles,
                                              *m_pAbiData);
    
    _setDocumentProperties();
          
    UT_Error err = UT_OK;
    bool try_recover = false;
    
    err = _handleManifestStream ();
    if ( UT_IE_TRY_RECOVER == err ) {
        try_recover = true;
    }
    else if ( UT_OK != err ) {
        return err;
    }
    err = _handleMimetype ();
    if ( UT_IE_TRY_RECOVER == err ) {
        try_recover = true;        
    }
    else if ( UT_OK != err ) {
        return err;
    }
    err = _handleMetaStream ();
    if ( UT_IE_TRY_RECOVER == err ) {
        try_recover = true;        
    }
    else if ( UT_OK != err ) {
        return err;
    }
    err = _handleStylesStream ();
    if ( UT_IE_TRY_RECOVER == err ) {
        try_recover = true;        
    }
    else if ( UT_OK != err ) {
        return err;
    }

    UT_DEBUGMSG(("IE_Imp_OpenDocument::_loadFile()\n"));
    err = _handleRDFStreams ();
    if ( UT_IE_TRY_RECOVER == err ) {
        try_recover = true;        
    }
    else if ( UT_OK != err ) {
        return err;
    }
    
    err = _handleContentStream ();
    if ( UT_IE_TRY_RECOVER == err ) {
        try_recover = true;        
    }
    else if ( UT_OK != err ) {
        return err;
    }

    
    if((err == UT_OK) && try_recover) {
        err = UT_IE_TRY_RECOVER;
    }
    return err;
}
Example #15
0
static GsfInfile *
get_infile(ChupaArchiveDecomposer *archive_decomposer,
           GsfInput *input, GError **error)
{
    return gsf_infile_zip_new(input, error);
}
Example #16
0
/**
 * tracker_gsf_parse_xml_in_zip:
 * @zip_file_uri: URI of the ZIP archive
 * @xml_filename: Name of the XML file stored inside the ZIP archive
 * @context: Markup context to be used when parsing the XML
 *
 * This function reads and parses the contents of an XML file stored
 *  inside a ZIP compressed archive. Reading and parsing is done buffered, and
 *  maximum size of the uncompressed XML file is limited to be to 20MBytes.
 */
void
tracker_gsf_parse_xml_in_zip (const gchar          *zip_file_uri,
                              const gchar          *xml_filename,
                              GMarkupParseContext  *context,
                              GError              **err)
{
	gchar *filename;
	GError *error = NULL;
	GsfInfile *infile = NULL;
	GsfInput *src = NULL;
	GsfInput *member = NULL;
	FILE *file;

	g_debug ("Parsing '%s' XML file contained inside zip archive...",
	         xml_filename);

	/* Get filename from the given URI */
	if ((filename = g_filename_from_uri (zip_file_uri,
	                                     NULL, &error)) == NULL) {
		g_warning ("Can't get filename from uri '%s': %s",
		           zip_file_uri, error ? error->message : "no error given");
	} else { /* Create a new Input GSF object for the given file */

		file = tracker_file_open (filename);
		if (!file) {
			g_warning ("Can't open file from uri '%s': %s",
			           zip_file_uri, g_strerror (errno));
		} else if ((src = gsf_input_stdio_new_FILE (filename, file, TRUE)) == NULL) {
			g_warning ("Failed creating a GSF Input object for '%s': %s",
			           zip_file_uri, error ? error->message : "no error given");
		}
		/* Input object is a Zip file */
		else if ((infile = gsf_infile_zip_new (src, &error)) == NULL) {
			g_warning ("'%s' Not a zip file: %s",
			           zip_file_uri, error ? error->message : "no error given");
		}
		/* Look for requested filename inside the ZIP file */
		else if ((member = find_member (infile, xml_filename)) == NULL) {
			g_warning ("No member '%s' in zip file '%s'",
			           xml_filename, zip_file_uri);
		}
		/* Load whole contents of the internal file in the xml buffer */
		else {
			guint8 buf[XML_BUFFER_SIZE];
			size_t remaining_size, chunk_size, accum;

			/* Get whole size of the contents to read */
			remaining_size = (size_t) gsf_input_size (GSF_INPUT (member));

			/* Note that gsf_input_read() needs to be able to read ALL specified
			 *  number of bytes, or it will fail */
			chunk_size = MIN (remaining_size, XML_BUFFER_SIZE);

			accum = 0;
			while (!error &&
			       accum  <= XML_MAX_BYTES_READ &&
			       chunk_size > 0 &&
			       gsf_input_read (GSF_INPUT (member), chunk_size, buf) != NULL) {

				/* update accumulated count */
				accum += chunk_size;

				/* Pass the read stream to the context parser... */
				g_markup_parse_context_parse (context, buf, chunk_size, &error);

				/* update bytes to be read */
				remaining_size -= chunk_size;
				chunk_size = MIN (remaining_size, XML_BUFFER_SIZE);
			}
		}

		if (file) {
			tracker_file_close (file, FALSE);
		}
	}

	g_free (filename);

	if (error)
		g_propagate_error (err, error);
	if (infile)
		g_object_unref (infile);
	if (src)
		g_object_unref (src);
	if (member)
		g_object_unref (member);
}