/** * based on find_member() from vsd_utils.c: * http://vsdump.sourcearchive.com/documentation/0.0.44/vsd__utils_8c-source.html */ static GsfInput * find_member (GsfInfile *arch, gchar const *name) { gchar const *slash; slash = strchr (name, '/'); if (slash) { gchar *dirname; GsfInput *member; dirname = g_strndup (name, slash - name); /** * Ignore if the directory is the current one that is ".". * Go to next direcotry if exists */ if (strcmp (dirname, ".") == 0) { member = find_member (arch, slash + 1); } else if ((member = gsf_infile_child_by_name (arch, dirname)) != NULL) { GsfInfile *dir; dir = GSF_INFILE (member); member = find_member (dir, slash + 1); g_object_unref (dir); } g_free (dirname); return member; } else { return gsf_infile_child_by_name (arch, name); } }
static GsfDocMetaData * get_meta_data (GsfInfile *infile, const char *filename) { GsfDocMetaData *meta_data = gsf_doc_meta_data_new (); if (GSF_IS_INFILE_MSOLE (infile)) { GsfInput *in; GError *err; in = gsf_infile_child_by_name (infile, "\05SummaryInformation"); if (NULL != in) { err = gsf_msole_metadata_read (in, meta_data); if (err != NULL) { g_warning ("'%s' error: %s", filename, err->message); g_error_free (err); err = NULL; } g_object_unref (G_OBJECT (in)); } in = gsf_infile_child_by_name (infile, "\05DocumentSummaryInformation"); if (NULL != in) { err = gsf_msole_metadata_read (in, meta_data); if (err != NULL) { g_warning ("'%s' error: %s", filename, err->message); g_error_free (err); err = NULL; } g_object_unref (G_OBJECT (in)); } } return meta_data; }
UT_Error IE_Imp_EPUB::readMetadata() { GsfInput* metaInf = gsf_infile_child_by_name(m_epub, "META-INF"); if (metaInf == NULL) { UT_DEBUGMSG(("Can`t open container META-INF dir\n")); return UT_ERROR; } GsfInput* meta = gsf_infile_child_by_name(GSF_INFILE(metaInf), "container.xml"); if (meta == NULL) { UT_DEBUGMSG(("Can`t open container metadata\n")); return UT_ERROR; } size_t metaSize = gsf_input_size(meta); if (metaSize == 0) { UT_DEBUGMSG(("Container metadata file is empty\n")); return UT_ERROR; } gchar* metaXml = (gchar*) gsf_input_read(meta, metaSize, NULL); std::string rootfilePath; UT_XML metaParser; ContainerListener containerListener; metaParser.setListener(&containerListener); if (metaParser.sniff(metaXml, metaSize, "container")) { UT_DEBUGMSG(("Parsing container.xml file\n")); metaParser.parse(metaXml, metaSize); } else { UT_DEBUGMSG(("Incorrect container.xml file\n")); return UT_ERROR; } m_rootfilePath = containerListener.getRootFilePath(); g_object_unref(G_OBJECT(meta)); g_object_unref(G_OBJECT(metaInf)); return UT_OK; }
/** * Handle the mimetype file */ UT_Error IE_Imp_OpenDocument::_handleMimetype () { GsfInput* pInput = gsf_infile_child_by_name(m_pGsfInfile, "mimetype"); if (!pInput) { UT_DEBUGMSG(("Error: didn't get a mimetype. Assuming that it's a" " application/vnd.oasis.opendocument.text document\n")); return UT_OK; } UT_UTF8String mimetype; if (gsf_input_size (pInput) > 0) { mimetype.append( (const char *)gsf_input_read(pInput, gsf_input_size (pInput), NULL), gsf_input_size (pInput)); } UT_Error err = UT_OK; if ((strcmp("application/vnd.oasis.opendocument.text", mimetype.utf8_str()) != 0) && (strcmp("application/vnd.oasis.opendocument.text-template", mimetype.utf8_str()) != 0) && (strcmp("application/vnd.oasis.opendocument.text-web", mimetype.utf8_str()) != 0)) { UT_DEBUGMSG(("*** Unknown mimetype '%s'\n", mimetype.utf8_str())); err = UT_IE_BOGUSDOCUMENT; } g_object_unref (G_OBJECT (pInput)); return err; }
/** * Handle the manifest file. */ UT_Error IE_Imp_OpenDocument::_handleManifestStream() { // clear the cryptography state m_cryptoInfo.clear(); m_sPassword = ""; GsfInput* pMetaInf = gsf_infile_child_by_name(m_pGsfInfile, "META-INF"); ODi_ManifestStream_ListenerState manifestListener(getDoc(), *(m_pStreamListener->getElementStack()), m_cryptoInfo); m_pStreamListener->setState(&manifestListener, false); UT_Error error = _handleStream (GSF_INFILE(pMetaInf), "manifest.xml", *m_pStreamListener); g_object_unref (G_OBJECT (pMetaInf)); if (error != UT_OK) { return error; } if (m_cryptoInfo.size() > 0) { // there is at least one entry in the manifest that is encrypted, so // ask the user for a password m_sPassword = GetPassword(); if (m_sPassword.size() == 0) return UT_IE_PROTECTED; } return UT_OK; }
static void dump_child (GsfInfile *infile, char const *childname) { GsfInput *child = gsf_infile_child_by_name (infile, childname); GsfInputTextline *textinput; unsigned char *res; int len = 0; if (child == NULL) { printf ("not an OpenOffice document\n"); return; } textinput = (GsfInputTextline *)gsf_input_textline_new (child); if (textinput == NULL) { printf ("Could not read lines from %s", gsf_input_name (child)); return; } do { res = gsf_input_textline_ascii_gets (textinput); if (res) { printf ("'%s'\n", res); len += strlen (res) + 1; } } while (res); printf ("Finished reading - %d bytes\n", len); g_object_unref (G_OBJECT (textinput)); g_object_unref (G_OBJECT (child)); }
/** * Code from Dom Lachowicz and/or Robert Staudinger. */ UT_Error ODi_Abi_Data::_loadStream (GsfInfile* oo, const char* stream, UT_ByteBuf& buf ) { guint8 const *data = NULL; size_t len = 0; static const size_t BUF_SZ = 4096; buf.truncate (0); GsfInput * input = gsf_infile_child_by_name(oo, stream); if (!input) return UT_ERROR; if (gsf_input_size (input) > 0) { while ((len = gsf_input_remaining (input)) > 0) { len = UT_MIN (len, BUF_SZ); if (NULL == (data = gsf_input_read (input, len, NULL))) { g_object_unref (G_OBJECT (input)); return UT_ERROR; } buf.append ((const UT_Byte *)data, len); } } g_object_unref (G_OBJECT (input)); return UT_OK; }
static void msole_thumbnail (GsfInfile *infile, const char *out_filename, int thumb_size) { GsfInput *summary_stream; GsfDocMetaData *meta_data; GsfDocProp *thumb_doc_prop; GValue const *thumb_value; GsfClipData *clip_data; GsfClipFormat clip_format; gconstpointer data; gsize size; GError *error; summary_stream = gsf_infile_child_by_name (infile, "\05SummaryInformation"); if (!summary_stream) show_error_string_and_exit ("Could not find the SummaryInformation stream"); meta_data = gsf_doc_meta_data_new (); error = gsf_msole_metadata_read (summary_stream, meta_data); if (error) show_error_and_exit (error); thumb_doc_prop = gsf_doc_meta_data_lookup (meta_data, GSF_META_NAME_THUMBNAIL); if (!thumb_doc_prop) show_error_string_and_exit ("The metadata does not have a thumbnail property"); thumb_value = gsf_doc_prop_get_val (thumb_doc_prop); if (!thumb_value) show_error_string_and_exit ("We got the thumbnail property, but it didn't have a value!?"); clip_data = GSF_CLIP_DATA (g_value_get_object (thumb_value)); clip_format = gsf_clip_data_get_format (clip_data); if (clip_format == GSF_CLIP_FORMAT_WINDOWS_CLIPBOARD) { GsfClipFormatWindows win_format; error = NULL; win_format = gsf_clip_data_get_windows_clipboard_format (clip_data, &error); if (win_format == GSF_CLIP_FORMAT_WINDOWS_ERROR) show_error_and_exit (error); } error = NULL; data = gsf_clip_data_peek_real_data (clip_data, &size, &error); if (!data) show_error_and_exit (error); write_thumbnail (out_filename, data, size, thumb_size); g_object_unref (clip_data); g_object_unref (meta_data); g_object_unref (summary_stream); }
gboolean gsf_infile_child_exists(GsfInfile *infile, char const *name) { GsfInput* pInput = gsf_infile_child_by_name(infile, name); if (!pInput) { return FALSE; } g_object_unref (G_OBJECT (pInput)); return TRUE; }
/** * 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; }
static GsfInput * find_member (GsfInfile *arch, char const *name) { char const *slash = strchr (name, '/'); if (slash) { char *dirname = g_strndup (name, slash - name); GsfInput *member; GsfInfile *dir; member = gsf_infile_child_by_name (arch, dirname); g_free (dirname); if (!member) return NULL; dir = GSF_INFILE (member); member = find_member (dir, slash + 1); g_object_unref (dir); return member; } else { return gsf_infile_child_by_name (arch, name); } }
UT_Error IE_Imp_Hancom::_loadFile(GsfInput * input) { mDoc = GSF_INFILE(gsf_infile_msole_new (input, NULL)); if (!mDoc) return UT_IE_BOGUSDOCUMENT; GsfInput *textStream = gsf_infile_child_by_name(mDoc, "/PrvText"); if (!textStream) return UT_IE_BOGUSDOCUMENT; size_t len = gsf_input_size(textStream); UT_DEBUGMSG(("HANCOM: Text length = %zd bytes\n", len)); unsigned char* buf = new unsigned char[len]; if (!buf) { g_object_unref (G_OBJECT (textStream)); return UT_IE_NOMEMORY; } gsf_input_read(textStream, len, buf); g_object_unref (G_OBJECT (textStream)); UT_uint32 length; UT_UCS4Char* text = reinterpret_cast<UT_UCS4Char*>(UT_convert((const char *)buf, len, "UCS-2LE", UCS_INTERNAL, NULL, &length)); delete[] buf; if (!text) return UT_IE_NOMEMORY; UT_DEBUGMSG(("HANCOM: Text successfully converted.\n")); if (!appendStrux(PTX_Section, NULL)) { FREEP(text); return UT_IE_NOMEMORY; } if (!appendStrux(PTX_Block, NULL)) { FREEP(text); return UT_IE_NOMEMORY; } if (!appendSpan(text, length/4)) { FREEP(text); return UT_IE_NOMEMORY; } FREEP(text); return UT_OK; }
/** * 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; }
UT_Error IE_Imp_EPUB::uncompress() { m_tmpDir = UT_go_filename_to_uri(g_get_tmp_dir()); m_tmpDir += G_DIR_SEPARATOR_S; m_tmpDir += getDoc()->getDocUUIDString(); if (!UT_go_directory_create(m_tmpDir.c_str(), 0644, NULL)) { UT_DEBUGMSG(("Can`t create temporary directory\n")); return UT_ERROR; } GsfInput *opsDirInput = gsf_infile_child_by_name(m_epub, m_opsDir.c_str()); UT_DEBUGMSG(("Child count : %d", gsf_infile_num_children(m_epub))); if (opsDirInput == NULL) { UT_DEBUGMSG(("Failed to open OPS dir\n")); return UT_ERROR; } for (std::map<std::string, std::string>::iterator i = m_manifestItems.begin(); i != m_manifestItems.end(); i++) { gchar *itemFileName = UT_go_filename_from_uri( (m_tmpDir + G_DIR_SEPARATOR_S + (*i).second).c_str()); gchar** aname = g_strsplit((*i).second.c_str(), G_DIR_SEPARATOR_S, 0); GsfInput* itemInput = gsf_infile_child_by_aname( GSF_INFILE(opsDirInput), (const char**) aname); GsfOutput* itemOutput = createFileByPath(itemFileName); gsf_input_seek(itemInput, 0, G_SEEK_SET); gsf_input_copy(itemInput, itemOutput); g_strfreev(aname); g_free(itemFileName); g_object_unref(G_OBJECT(itemInput)); gsf_output_close(itemOutput); } g_object_unref(G_OBJECT(opsDirInput)); return UT_OK; }
UT_Confidence_t IE_Imp_StarOffice_Sniffer::recognizeContents(GsfInput * input) { GsfInfile * ole; UT_Confidence_t confidence = UT_CONFIDENCE_ZILCH; ole = gsf_infile_msole_new (input, NULL); if (ole) { GsfInput * starWriterDocument = gsf_infile_child_by_name (ole, "StarWriterDocument"); if (starWriterDocument != NULL) { confidence = UT_CONFIDENCE_PERFECT; g_object_unref (G_OBJECT (starWriterDocument)); } g_object_unref (G_OBJECT (ole)); } return confidence; }
WPXInputStream * AbiWordperfectInputStream::getDocumentOLEStream(const char * name) { WPXInputStream *documentStream = NULL; if (!m_ole) m_ole = GSF_INFILE(gsf_infile_msole_new (m_input, NULL)); if (m_ole) { GsfInput *document = gsf_infile_child_by_name(m_ole, name); if (document) { documentStream = new AbiWordperfectInputStream(document); g_object_unref(G_OBJECT (document)); // the only reference should be encapsulated within the new stream } } return documentStream; }
static GsfInfileTar * tar_directory_for_file (GsfInfileTar *dir, const char *name, gboolean last) { const char *s = name; while (1) { const char *s0 = s; char *dirname; /* Find a directory component, if any. */ while (1) { if (*s == 0) { if (last && s != s0) break; else return dir; } /* This is deliberately slash-only. */ if (*s == '/') break; s++; } dirname = g_strndup (s0, s - s0); while (*s == '/') s++; if (strcmp (dirname, ".") != 0) { GsfInput *subdir = gsf_infile_child_by_name (GSF_INFILE (dir), dirname); if (subdir) { /* Undo the ref. */ g_object_unref (subdir); dir = GSF_INFILE_TAR (subdir); } else dir = tar_create_dir (dir, dirname); } g_free (dirname); } }
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; }
/** * Handle the stream @stream using the listener @listener. * Tries to abstract away how we're actually going to handle * how we read the stream, so that the underlying implementation * can easily adapt or change */ UT_Error IE_Imp_OpenDocument::_handleStream ( GsfInfile* pGsfInfile, const char * pStream, UT_XML::Listener& rListener) { GsfInput* pInput = gsf_infile_child_by_name(pGsfInfile, pStream); UT_return_val_if_fail(pInput, UT_ERROR); // check if the stream is encrypted, and if so, decrypt it std::map<std::string, ODc_CryptoInfo>::iterator pos = m_cryptoInfo.find(pStream); if (pos != m_cryptoInfo.end()) { UT_DEBUGMSG(("Running decrypt on stream %s\n", pStream)); #ifndef HAVE_GCRYPT UT_DEBUGMSG(("Can not decrypt files because of how abiword is compiled!\n")); return UT_ERROR; #endif GsfInput* pDecryptedInput = NULL; UT_Error err = ODc_Crypto::decrypt(pInput, (*pos).second, m_sPassword.utf8_str(), &pDecryptedInput); g_object_unref (G_OBJECT (pInput)); if (err != UT_OK) { UT_DEBUGMSG(("Decryption failed!\n")); return err; } UT_DEBUGMSG(("Stream %s decrypted\n", pStream)); pInput = pDecryptedInput; } // parse the XML stream UT_XML reader; reader.setListener ( &rListener ); UT_Error err = _parseStream (pInput, reader); g_object_unref (G_OBJECT (pInput)); return err; }
gboolean qpro_file_probe (GOFileOpener const *fo, GsfInput *input, GOFileProbeLevel pl) { GsfInfile *ole; GsfInput *stream; gboolean res = FALSE; /* check for >= QPro 6.0 which is OLE based */ ole = gsf_infile_msole_new (input, NULL); if (ole != NULL) { stream = gsf_infile_child_by_name (GSF_INFILE (ole), "PerfectOffice_MAIN"); if (stream != NULL) { res = qpro_check_signature (stream); g_object_unref (stream); } g_object_unref (ole); } else res = qpro_check_signature (input); return res; }
static void print_summary_stream (GsfInfile * msole, const char * file_name, const char * stream_name, GHashTable * human_readable_names) { GsfInput * stream = gsf_infile_child_by_name (msole, stream_name); if (stream != NULL) { GsfDocMetaData *meta_data = gsf_doc_meta_data_new (); GError *err = NULL; err = gsf_msole_metadata_read (stream, meta_data); if (err != NULL) { g_warning ("Error getting metadata for %s->%s: %s", file_name, stream_name, err->message); g_error_free (err); err = NULL; } else gsf_doc_meta_data_foreach (meta_data, (GHFunc) cb_print_property, human_readable_names); g_object_unref (meta_data); g_object_unref (G_OBJECT (stream)); } }
static void vba_extract_module_source (GsfInfileMSVBA *vba, char const *name, guint32 src_offset) { GsfInput *module; guint8 *code; int inflated_size; g_return_if_fail (name != NULL); module = gsf_infile_child_by_name (vba->source, name); if (module == NULL) return; code = gsf_vba_inflate (module, (gsf_off_t) src_offset, &inflated_size, FALSE); if (code != NULL) { if (NULL == vba->modules) vba->modules = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); g_hash_table_insert (vba->modules, g_strdup (name), code); } else g_warning ("Problems extracting the source for %s @ %u", name, src_offset); g_object_unref (module); }
UT_Error IE_Imp_OpenDocument::_handleRDFStreams () { #ifndef WITH_REDLAND return UT_OK; #else UT_Error error = UT_OK; UT_DEBUGMSG(("IE_Imp_OpenDocument::_handleRDFStreams()\n")); // // DEBUG. // { // PD_DocumentRDFHandle rdf = getDoc()->getDocumentRDF(); // PD_DocumentRDFMutationHandle m = rdf->createMutation(); // m->add( PD_URI("http://www.example.com/foo#bar" ), // PD_URI("http://www.example.com/foo#bar" ), // PD_Object("http://www.example.com/foo#bar" ) ); // m->commit(); // rdf->dumpModel("added foo"); // } RDFArguments args; librdf_model* model = args.model; // check if we can load a manifest.rdf file GsfInput* pRdfManifest = gsf_infile_child_by_name(m_pGsfInfile, "manifest.rdf"); if (pRdfManifest) { UT_DEBUGMSG(("IE_Imp_OpenDocument::_handleRDFStreams() have manifest.rdf\n")); error = _loadRDFFromFile( pRdfManifest, "manifest.rdf", &args ); g_object_unref (G_OBJECT (pRdfManifest)); if (error != UT_OK) return error; } // find other RDF/XML files referenced in the manifest const char* query_string = "" "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" "prefix odf: <http://docs.oasis-open.org/opendocument/meta/package/odf#> \n" "prefix odfcommon: <http://docs.oasis-open.org/opendocument/meta/package/common#> \n" "select ?subj ?fileName \n" " where { \n" " ?subj rdf:type odf:MetaDataFile . \n" " ?subj odfcommon:path ?fileName \n" " } \n"; librdf_uri* base_uri = 0; librdf_query* query = librdf_new_query( args.world, "sparql", 0, (unsigned char*)query_string, base_uri ); librdf_query_results* results = librdf_query_execute( query, model ); if( !results ) { // Query failed is a failure to execute the SPARQL, // in which case there might be results but we couldn't find them UT_DEBUGMSG(("IE_Imp_OpenDocument::_handleRDFStreams() SPARQL query to find auxillary RDF/XML files failed! q:%p\n", query )); error = UT_ERROR; } else { UT_DEBUGMSG(("IE_Imp_OpenDocument::_handleRDFStreams() aux RDF/XML file count:%d\n", librdf_query_results_get_count( results ))); // parse auxillary RDF/XML files too for( ; !librdf_query_results_finished( results ) ; librdf_query_results_next( results )) { librdf_node* fnNode = librdf_query_results_get_binding_value_by_name ( results, "fileName" ); UT_DEBUGMSG(("_handleRDFStreams() fnNode:%p\n", fnNode )); std::string fn = toString(fnNode); UT_DEBUGMSG(("_handleRDFStreams() loading auxilary RDF/XML file from:%s\n", fn.c_str())); GsfInput* pAuxRDF = gsf_infile_child_by_name(m_pGsfInfile, fn.c_str()); if (pAuxRDF) { error = _loadRDFFromFile( pAuxRDF, fn.c_str(), &args ); g_object_unref (G_OBJECT (pAuxRDF)); if( error != UT_OK ) break; } else { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); return UT_ERROR; } } librdf_free_query_results( results ); } librdf_free_query( query ); UT_DEBUGMSG(("_handleRDFStreams() error:%d model.sz:%d\n", error, librdf_model_size( model ))); if( error != UT_OK ) { return error; } // convert the redland model into native AbiWord RDF triples { PD_DocumentRDFHandle rdf = getDoc()->getDocumentRDF(); PD_DocumentRDFMutationHandle m = rdf->createMutation(); librdf_statement* statement = librdf_new_statement( args.world ); librdf_stream* stream = librdf_model_find_statements( model, statement ); while (!librdf_stream_end(stream)) { librdf_statement* current = librdf_stream_get_object( stream ); int objectType = PD_Object::OBJECT_TYPE_URI; std::string xsdType = ""; if( librdf_node_is_blank( librdf_statement_get_object( current ))) { objectType = PD_Object::OBJECT_TYPE_BNODE; } if( librdf_node_is_literal( librdf_statement_get_object( current ))) { objectType = PD_Object::OBJECT_TYPE_LITERAL; if( librdf_uri* u = librdf_node_get_literal_value_datatype_uri( librdf_statement_get_object( current ))) { xsdType = toString(u); } } if( DEBUG_RDF_IO ) { UT_DEBUGMSG(("_handleRDFStreams() adding s:%s p:%s o:%s rotv:%d otv:%d ots:%s\n", toString( librdf_statement_get_subject( current )).c_str(), toString( librdf_statement_get_predicate( current )).c_str(), toString( librdf_statement_get_object( current )).c_str(), librdf_node_get_type(librdf_statement_get_object( current )), objectType, xsdType.c_str() )); } m->add( PD_URI( toString( librdf_statement_get_subject( current ))), PD_URI( toString( librdf_statement_get_predicate( current ))), PD_Object( toString( librdf_statement_get_object( current )), objectType, xsdType )); // m->add( PD_URI( toString( librdf_statement_get_subject( current ))), // PD_URI( toString( librdf_statement_get_predicate( current ))), // PD_Object( toString( librdf_statement_get_object( current )), // objectType, // xsdType )); librdf_stream_next(stream); } librdf_free_stream( stream ); librdf_free_statement( statement ); // m->add( PD_URI("http://www.example.com/foo#bar" ), // PD_URI("http://www.example.com/foo#bar" ), // PD_Object("http://www.example.com/foo#bar" ) ); m->commit(); } if( DEBUG_RDF_IO ) { getDoc()->getDocumentRDF()->dumpModel("Loaded RDF from ODF file"); } return error; #endif }
static int test (unsigned argc, char *argv[]) { static char const * const stream_names[] = { "Workbook", "WORKBOOK", "workbook", "Book", "BOOK", "book" }; GsfInput *input, *stream, *pcache_dir; GsfInfile *infile; GError *err = NULL; unsigned i, j; for (i = 1 ; i < argc ; i++) { fprintf( stderr, "%s\n",argv[i]); input = gsf_input_mmap_new (argv[i], NULL); if (input == NULL) /* Only report error if stdio fails too */ input = gsf_input_stdio_new (argv[i], &err); if (input == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' error: %s", argv[i], err->message); g_error_free (err); err = NULL; continue; } input = gsf_input_uncompress (input); infile = gsf_infile_msole_new (input, &err); if (infile == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' Not an OLE file: %s", argv[i], err->message); g_error_free (err); err = NULL; #ifdef DUMP_CONTENT dump_biff_stream (input); #endif g_object_unref (G_OBJECT (input)); continue; } #if 0 stream = gsf_infile_child_by_name (infile, "\01CompObj"); if (stream != NULL) { gsf_off_t len = gsf_input_size (stream); guint8 const *data = gsf_input_read (stream, len, NULL); if (data != NULL) gsf_mem_dump (data, len); g_object_unref (G_OBJECT (stream)); } return 0; #endif stream = gsf_infile_child_by_name (infile, "\05SummaryInformation"); if (stream != NULL) { GsfDocMetaData *meta_data = gsf_doc_meta_data_new (); puts ( "SummaryInfo"); err = gsf_doc_meta_data_read_from_msole (meta_data, stream); if (err != NULL) { g_warning ("'%s' error: %s", argv[i], err->message); g_error_free (err); err = NULL; } else gsf_doc_meta_dump (meta_data); g_object_unref (meta_data); g_object_unref (G_OBJECT (stream)); } stream = gsf_infile_child_by_name (infile, "\05DocumentSummaryInformation"); if (stream != NULL) { GsfDocMetaData *meta_data = gsf_doc_meta_data_new (); puts ( "DocSummaryInfo"); err = gsf_doc_meta_data_read_from_msole (meta_data, stream); if (err != NULL) { g_warning ("'%s' error: %s", argv[i], err->message); g_error_free (err); err = NULL; } else gsf_doc_meta_dump (meta_data); g_object_unref (meta_data); g_object_unref (G_OBJECT (stream)); } for (j = 0 ; j < G_N_ELEMENTS (stream_names) ; j++) { stream = gsf_infile_child_by_name (infile, stream_names[j]); if (stream != NULL) { puts (j < 3 ? "Excel97" : "Excel95"); #ifdef DUMP_CONTENT dump_biff_stream (stream); #endif g_object_unref (G_OBJECT (stream)); break; } } #ifdef DUMP_CONTENT pcache_dir = gsf_infile_child_by_name (infile, "_SX_DB_CUR"); /* Excel 97 */ if (NULL == pcache_dir) pcache_dir = gsf_infile_child_by_name (infile, "_SX_DB"); /* Excel 95 */ if (NULL != pcache_dir) { int i, n = gsf_infile_num_children (infile); for (i = 0 ; i < n ; i++) { stream = gsf_infile_child_by_index (GSF_INFILE (pcache_dir), i); if (stream != NULL) { printf ("=================================================\nPivot cache '%04hX'\n\n", i); dump_biff_stream (stream); g_object_unref (G_OBJECT (stream)); } } g_object_unref (G_OBJECT (pcache_dir)); } #endif g_object_unref (G_OBJECT (infile)); g_object_unref (G_OBJECT (input)); } return 0; }
/** * vba_project_read: * @vba: #GsfInfileMSVBA * @err: (allow-none): place to store a #GError if anything goes wrong * * Read an VBA dirctory and its project file. * along the way. * * Returns: %FALSE on error setting @err if it is supplied. **/ static gboolean vba_project_read (GsfInfileMSVBA *vba, GError **err) { /* NOTE : This seems constant, find some confirmation */ static guint8 const signature[] = { 0xcc, 0x61 }; static struct { guint8 const signature[4]; char const * const name; int const vba_version; gboolean const is_mac; } const versions [] = { { { 0x5e, 0x00, 0x00, 0x01 }, "Office 97", 5, FALSE}, { { 0x5f, 0x00, 0x00, 0x01 }, "Office 97 SR1", 5, FALSE }, { { 0x65, 0x00, 0x00, 0x01 }, "Office 2000 alpha?", 6, FALSE }, { { 0x6b, 0x00, 0x00, 0x01 }, "Office 2000 beta?", 6, FALSE }, { { 0x6d, 0x00, 0x00, 0x01 }, "Office 2000", 6, FALSE }, { { 0x6f, 0x00, 0x00, 0x01 }, "Office 2000", 6, FALSE }, { { 0x70, 0x00, 0x00, 0x01 }, "Office XP beta 1/2", 6, FALSE }, { { 0x73, 0x00, 0x00, 0x01 }, "Office XP", 6, FALSE }, { { 0x76, 0x00, 0x00, 0x01 }, "Office 2003", 6, FALSE }, { { 0x79, 0x00, 0x00, 0x01 }, "Office 2003", 6, FALSE }, { { 0x60, 0x00, 0x00, 0x0e }, "MacOffice 98", 5, TRUE }, { { 0x62, 0x00, 0x00, 0x0e }, "MacOffice 2001", 5, TRUE }, { { 0x63, 0x00, 0x00, 0x0e }, "MacOffice X", 6, TRUE }, { { 0x64, 0x00, 0x00, 0x0e }, "MacOffice 2004", 6, TRUE }, }; guint8 const *data; unsigned i, count, len; gunichar2 *uni_name; char *name; GsfInput *dir; dir = gsf_infile_child_by_name (vba->source, "dir"); if (dir == NULL) { if (err != NULL) *err = g_error_new (gsf_input_error_id (), 0, _("Can't find the VBA directory stream")); return FALSE; } if (gsf_input_seek (dir, 0, G_SEEK_SET) || NULL == (data = gsf_input_read (dir, VBA56_DIRENT_HEADER_SIZE, NULL)) || 0 != memcmp (data, signature, sizeof (signature))) { if (err != NULL) *err = g_error_new (gsf_input_error_id (), 0, _("No VBA signature")); return FALSE; } for (i = 0 ; i < G_N_ELEMENTS (versions); i++) if (!memcmp (data+2, versions[i].signature, 4)) break; if (i >= G_N_ELEMENTS (versions)) { if (err != NULL) *err = g_error_new (gsf_input_error_id (), 0, _("Unknown VBA version signature 0x%x%x%x%x"), data[2], data[3], data[4], data[5]); return FALSE; } puts (versions[i].name); /* these depend strings seem to come in 2 blocks */ count = GSF_LE_GET_GUINT16 (data + VBA56_DIRENT_RECORD_COUNT); for (; count > 0 ; count--) { if (NULL == ((data = gsf_input_read (dir, 2, NULL)))) break; len = GSF_LE_GET_GUINT16 (data); if (NULL == ((data = gsf_input_read (dir, len, NULL)))) { printf ("len == 0x%x ??\n", len); break; } uni_name = g_new0 (gunichar2, len/2 + 1); /* be wary about endianness */ for (i = 0 ; i < len ; i += 2) uni_name [i/2] = GSF_LE_GET_GUINT16 (data + i); name = g_utf16_to_utf8 (uni_name, -1, NULL, NULL, NULL); g_free (uni_name); printf ("%d %s\n", count, name); /* ignore this blob ???? */ if (!strncmp ("*\\G", name, 3)) { if (NULL == ((data = gsf_input_read (dir, 12, NULL)))) { printf ("len == 0x%x ??\n", len); break; } } g_free (name); } g_return_val_if_fail (count == 0, FALSE); return TRUE; }
static void make_stream (HwpHWP5File *file, GError **error) { GsfInput *input = NULL; GsfInfile *ole = GSF_INFILE (file->priv->olefile); gint n_root_entry = gsf_infile_num_children (ole); if (n_root_entry < 1) { g_set_error_literal (error, HWP_FILE_ERROR, HWP_FILE_ERROR_INVALID, "invalid hwp file"); return; } /* 우선 순위에 따라 스트림을 만든다 */ input = gsf_infile_child_by_name (ole, "FileHeader"); if (input && gsf_infile_num_children (GSF_INFILE (input)) == -1) { file->file_header_stream = input; input = NULL; parse_file_header (file); } else { goto FAIL; } input = gsf_infile_child_by_name (ole, "DocInfo"); if (input && gsf_infile_num_children (GSF_INFILE (input)) == -1) { if (file->is_compress) { GInputStream *gis; GZlibDecompressor *zd; GInputStream *cis; gis = (GInputStream *) gsf_input_stream_new (input); zd = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW); cis = g_converter_input_stream_new (gis, (GConverter *) zd); g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (cis), TRUE); file->doc_info_stream = cis; g_object_unref (zd); g_object_unref (gis); input = NULL; } else { file->doc_info_stream = (GInputStream *) gsf_input_stream_new (input); } } else { goto FAIL; } if (!file->is_distribute) input = gsf_infile_child_by_name (ole, "BodyText"); else input = gsf_infile_child_by_name (ole, "ViewText"); if (input) { for (gint i = 0; i < gsf_infile_num_children (GSF_INFILE (input)); i++) { GsfInput *section = gsf_infile_child_by_name (GSF_INFILE (input), g_strdup_printf("Section%d", i)); if (gsf_infile_num_children (GSF_INFILE (section)) != -1) { if (GSF_IS_INPUT (section)) g_object_unref (section); g_set_error_literal (error, HWP_FILE_ERROR, HWP_FILE_ERROR_INVALID, "invalid hwp file"); return; } if (file->is_distribute) { guint8 *data = g_malloc0 (256); gsf_input_read (section, 4, NULL); gsf_input_read (section, 256, data); guint32 seed = GSF_LE_GET_GUINT32 (data); msvc_srand (seed); gint n = 0, val = 0, offset; for (guint i = 0; i < 256; i++) { if (n == 0) { val = msvc_rand() & 0xff; n = (msvc_rand() & 0xf) + 1; } data[i] ^= val; n--; } offset = 4 + (seed & 0xf); gchar *key = g_malloc0 (16); memcpy (key, (const gchar *) data + offset, 16); #ifdef HWP_ENABLE_DEBUG gchar *sha1 = g_convert ((const gchar *) data + offset, 80, "UTF-8", "UTF-16LE", NULL, NULL, error); printf ("sha1: %s\n", sha1); printf ("key: %s\n", key); g_free (sha1); #endif g_free (data); EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new (); EVP_CIPHER_CTX_init (ctx); EVP_DecryptInit_ex (ctx, EVP_aes_128_ecb(), NULL, (unsigned char *) key, NULL); g_free (key); EVP_CIPHER_CTX_set_padding(ctx, 0); /* no padding */ gsf_off_t encrypted_data_len = gsf_input_remaining (section); guint8 const *encrypted_data = gsf_input_read (section, encrypted_data_len, NULL); guint8 *decrypted_data = g_malloc (encrypted_data_len); int decrypted_data_len, len; EVP_DecryptUpdate (ctx, decrypted_data, &len, encrypted_data, encrypted_data_len); decrypted_data_len = len; EVP_DecryptFinal_ex (ctx, decrypted_data + len, &len); decrypted_data_len += len; EVP_CIPHER_CTX_free (ctx); g_object_unref (section); section = gsf_input_memory_new (decrypted_data, decrypted_data_len, TRUE); } if (file->is_compress) { GInputStream *gis; GZlibDecompressor *zd; GInputStream *cis; gis = (GInputStream *) gsf_input_stream_new (section); zd = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW); cis = g_converter_input_stream_new (gis, (GConverter *) zd); g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (cis), TRUE); g_ptr_array_add (file->section_streams, cis); g_object_unref (zd); g_object_unref (gis); } else { GInputStream *stream = (GInputStream *) gsf_input_stream_new (section); g_ptr_array_add (file->section_streams, stream); } } /* for */ g_object_unref (input); input = NULL; } else { goto FAIL; } input = gsf_infile_child_by_name (ole, "\005HwpSummaryInformation"); if (input && gsf_infile_num_children (GSF_INFILE (input)) == -1) { file->summary_info_stream = input; input = NULL; } else { goto FAIL; } input = gsf_infile_child_by_name (ole, "BinData"); if (input) { gint n_data = gsf_infile_num_children (GSF_INFILE (input)); for (gint i = 0; i < n_data; i++) { GsfInput *bin_data_input = gsf_infile_child_by_index (GSF_INFILE (input), i); if (gsf_infile_num_children (GSF_INFILE (bin_data_input)) != -1) { if (GSF_IS_INPUT (bin_data_input)) g_object_unref (bin_data_input); g_set_error_literal (error, HWP_FILE_ERROR, HWP_FILE_ERROR_INVALID, "invalid hwp file"); return; } if (file->is_compress) { GInputStream *gis; GZlibDecompressor *zd; GInputStream *cis; gis = (GInputStream *) gsf_input_stream_new (bin_data_input); zd = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW); cis = g_converter_input_stream_new (gis, (GConverter *) zd); g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (cis), TRUE); g_ptr_array_add (file->bin_data_streams, cis); g_object_unref (zd); g_object_unref (gis); } else { GInputStream *stream = (GInputStream *) gsf_input_stream_new (bin_data_input); g_ptr_array_add (file->bin_data_streams, stream); } } g_object_unref (input); input = NULL; } input = gsf_infile_child_by_name (ole, "PrvText"); if (input && gsf_infile_num_children (GSF_INFILE (input)) == -1) { file->prv_text_stream = input; input = NULL; } else { goto FAIL; } input = gsf_infile_child_by_name (ole, "PrvImage"); if (input && gsf_infile_num_children (GSF_INFILE (input)) == -1) { file->prv_image_stream = input; input = NULL; } else { goto FAIL; } return; FAIL: if (GSF_IS_INPUT (input)) g_object_unref (input); g_set_error_literal (error, HWP_FILE_ERROR, HWP_FILE_ERROR_INVALID, "invalid hwp file"); return; }
UT_Error IE_Imp_StarOffice::_loadFile(GsfInput * input) { try { UT_DEBUGMSG(("SDW: Starting import\n")); mOle = GSF_INFILE (gsf_infile_msole_new(input, NULL)); if (!mOle) return UT_IE_BOGUSDOCUMENT; // firstly, load metadata SDWDocInfo::load(mOle, getDoc()); mDocStream = gsf_infile_child_by_name(mOle, "StarWriterDocument"); if (!mDocStream) return UT_IE_BOGUSDOCUMENT; gsf_off_t size = gsf_input_size(mDocStream); if (!appendStrux(PTX_Section, PP_NOPROPS)) return UT_IE_NOMEMORY; UT_DEBUGMSG(("SDW: Attempting to load DocHdr...\n")); mDocHdr.load(mDocStream); UT_DEBUGMSG(("SDW: ...success\n")); // Ask for and verify the password if (mDocHdr.cryptor) { if (!mDocHdr.cryptor->SetPassword(GetPassword().c_str())) { UT_DEBUGMSG(("SDW: Wrong password\n")); return UT_IE_PROTECTED; } } // do the actual reading char type; bool done = false; UT_uint32 recSize; while (!done) { if (gsf_input_tell(mDocStream) == size) break; readChar(mDocStream, type); gsf_off_t eor; readRecSize(mDocStream, recSize, &eor); switch (type) { case SWG_CONTENTS: { gsf_off_t flagsEnd = 0; UT_uint32 nNodes; // sw/source/core/sw3io/sw3sectn.cxx#L129 if (mDocHdr.nVersion >= SWG_LAYFRAMES) { UT_uint8 flags; readFlagRec(mDocStream, flags, &flagsEnd); } if (mDocHdr.nVersion >= SWG_LONGIDX) streamRead(mDocStream, nNodes); else { if (mDocHdr.nVersion >= SWG_LAYFRAMES) { UT_uint16 sectidDummy; streamRead(mDocStream, sectidDummy); } UT_uint16 nodes16; streamRead(mDocStream, nodes16); nNodes = (UT_uint32)nodes16; } if (flagsEnd) { UT_ASSERT(flagsEnd >= gsf_input_tell(mDocStream)); if (gsf_input_tell(mDocStream) != flagsEnd) { UT_DEBUGMSG(("SDW: have not read all flags\n")); if (gsf_input_seek(mDocStream, flagsEnd, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } } bool done2 = false; UT_uint32 size2; while (!done2) { readChar(mDocStream, type); gsf_off_t eor2; readRecSize(mDocStream, size2, &eor2); switch (type) { case SWG_TEXTNODE: { // sw/source/core/sw3io/sw3nodes.cxx#L788 UT_DEBUGMSG(("SDW: Found Textnode! (start at 0x%08llX end at 0x%08llX)\n", (long long)gsf_input_tell(mDocStream), (long long)eor2)); UT_uint8 flags; gsf_off_t newPos; readFlagRec(mDocStream, flags, &newPos); // XXX check flags if (gsf_input_seek(mDocStream, newPos, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; // Read the actual text UT_UCS4Char* str; readByteString(mDocStream, str); UT_UCS4String textNode(str); free(str); UT_DEBUGMSG(("SDW: ...length=%zu contents are: |%s|\n", textNode.length(), textNode.utf8_str())); // now get the attributes UT_String attrs; UT_String pAttrs; UT_Vector charAttributes; while (gsf_input_tell(mDocStream) < eor2) { char attVal; streamRead(mDocStream, attVal); UT_uint32 attSize; gsf_off_t eoa; // end of attribute readRecSize(mDocStream, attSize, &eoa); if (attVal == SWG_ATTRIBUTE) { TextAttr* a = new TextAttr; streamRead(mDocStream, *a, eoa); UT_DEBUGMSG(("SDW: ...found text-sub-node, which=0x%x, ver=0x%x, start=%u, end=%u - data:%s len:%llu data is:", a->which, a->ver, a->start, a->end, a->data?"Yes":"No", (long long unsigned)a->dataLen)); #ifdef DEBUG hexdump(a->data, a->dataLen); putc('\n', stderr); #endif charAttributes.addItem(a); } else if (attVal == SWG_ATTRSET) { // bah, yet another loop UT_DEBUGMSG(("SDW: ...paragraph attributes found\n")); while (gsf_input_tell(mDocStream) < eoa) { // reusing attVal and attSize streamRead(mDocStream, attVal); gsf_off_t eoa2; // end of attribute readRecSize(mDocStream, attSize, &eoa2); if (attVal == SWG_ATTRIBUTE) { TextAttr a; streamRead(mDocStream, a, eoa2); if (!a.attrVal.empty()) { if (a.isPara) UT_String_setProperty(pAttrs, a.attrName, a.attrVal); else UT_String_setProperty(attrs, a.attrName, a.attrVal); } UT_DEBUGMSG(("SDW: ......found paragraph attr, which=0x%x, ver=0x%x, start=%u, end=%u (string now %s) Data:%s Len=%lld Data:", a.which, a.ver, (a.startSet?a.start:0), (a.endSet?a.end:0), attrs.c_str(), (a.data ? "Yes" : "No"), (long long)a.dataLen)); #ifdef DEBUG hexdump(a.data, a.dataLen); putc('\n', stderr); #endif } if (gsf_input_seek(mDocStream, eoa2, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } } else { UT_DEBUGMSG(("SDW: ...unknown attribute '%c' found (start=%" GSF_OFF_T_FORMAT " end=%" GSF_OFF_T_FORMAT ")\n", attVal, gsf_input_tell(mDocStream), eoa)); } if (gsf_input_seek(mDocStream, eoa, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } PP_PropertyVector attributes = { "props", pAttrs.c_str() }; // first, insert the paragraph if (!appendStrux(PTX_Block, attributes)) return UT_IE_NOMEMORY; UT_String pca(attrs); // character attributes for the whole paragraph // now insert the spans of text UT_uint32 len = textNode.length(); UT_uint32 lastInsPos = 0; for (UT_uint32 i = 1; i < len; i++) { bool doInsert = false; // whether there was an attribute change for (UT_sint32 j = 0; j < charAttributes.getItemCount(); j++) { const TextAttr* a = reinterpret_cast<const TextAttr*>(charAttributes[j]); // clear the last attribute, if set if (a->endSet && a->end == (i - 1)) { if (a->isOff) { UT_String propval = UT_String_getPropVal(pca, a->attrName); UT_String_setProperty(attrs, a->attrName, propval); } else UT_String_removeProperty(attrs, a->attrName); } // now set new attribute, if needed if (a->startSet && a->start == (i - 1)) { if (a->isPara) UT_String_setProperty(pAttrs, a->attrName, a->attrVal); else if (a->isOff) UT_String_removeProperty(attrs, a->attrName); else UT_String_setProperty(attrs, a->attrName, a->attrVal); } // insert if this is the last character, or if there was a format change if ((a->endSet && a->end == i) || (a->startSet && a->start == i)) doInsert = true; } if (doInsert || i == (len - 1)) { attributes[1] = attrs.c_str(); UT_DEBUGMSG(("SDW: Going to appendFmt with %s\n", attributes[1].c_str())); if (!appendFmt(attributes)) return UT_IE_NOMEMORY; /* leave cast alone! */ UT_DEBUGMSG(("SDW: About to insert %u-%u\n", lastInsPos, i)); size_t spanLen = i - lastInsPos; if (i == (len - 1)) spanLen++; UT_UCS4String span = textNode.substr(lastInsPos, spanLen); appendSpan(span.ucs4_str(), spanLen); lastInsPos = i; } } UT_VECTOR_PURGEALL(TextAttr*, charAttributes); break; } case SWG_JOBSETUP: { // flags are apparently unused here. no idea why they are there. gsf_off_t newpos; UT_uint8 flags; readFlagRec(mDocStream, flags, &newpos); if (gsf_input_seek(mDocStream, newpos, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; UT_uint16 len, system; streamRead(mDocStream, len); streamRead(mDocStream, system); char printerName[64]; streamRead(mDocStream, printerName, 64); char deviceName[32], portName[32], driverName[32]; streamRead(mDocStream, deviceName, 32); streamRead(mDocStream, portName, 32); streamRead(mDocStream, driverName, 32); UT_DEBUGMSG(("SDW: Jobsetup: len %u sys 0x%x printer |%.64s| device |%.32s| port |%.32s| driver |%.32s|\n", len, system, printerName, deviceName, portName, driverName)); if (system == JOBSET_FILE364_SYSTEM || system == JOBSET_FILE605_SYSTEM) { UT_uint16 len2, system2; streamRead(mDocStream, len2); streamRead(mDocStream, system2); UT_uint32 ddl; // driver data length streamRead(mDocStream, ddl); // now the interesting data UT_uint16 orient; // 0=portrait 1=landscape streamRead(mDocStream, orient); UT_uint16 paperBin; streamRead(mDocStream, paperBin); UT_uint16 paperFormat; streamRead(mDocStream, paperFormat); UT_uint32 width, height; streamRead(mDocStream, width); streamRead(mDocStream, height); UT_DEBUGMSG(("SDW: orient %u bin %u format %u width %u height %u\n", orient, paperBin, paperFormat, width, height)); // rest of the data is ignored, seems to be printer specific anyway. // Use A4, Portrait by default PP_PropertyVector attributes = { "pagetype", "a4", // A4/Letter/... "orientation", "portrait", "width", "210", "height", "297", "units", "mm" }; const char* sdwPaperToAbi[] = { "A3", "A4", "A5", "B4", "B5", "Letter", "Legal", "Tabloid/Ledger", "Custom" }; if (paperFormat < sizeof(sdwPaperToAbi)/sizeof(*sdwPaperToAbi)) { attributes[1] = sdwPaperToAbi[paperFormat]; } const char* sdwOrientToAbi[] = { "portrait", "landscape" }; if (orient < sizeof(sdwOrientToAbi)/sizeof(*sdwOrientToAbi)) { attributes[3] = sdwOrientToAbi[orient]; } attributes[5] = UT_std_string_sprintf("%f", static_cast<double>(width)/100); attributes[7] = UT_std_string_sprintf("%f", static_cast<double>(height)/100); getDoc()->setPageSizeFromFile(attributes); } break; } case SWG_EOF: done2 = true; break; default: UT_DEBUGMSG(("SDW: SWG_CONTENT: Skipping %u bytes for record type '%c' (starting at 0x%08llX)\n", size2, type, (long long)gsf_input_tell(mDocStream))); } if (gsf_input_seek(mDocStream, eor2, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } break; } case SWG_STRINGPOOL: { if (mDocHdr.nVersion <= SWG_POOLIDS) { UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); break; } UT_uint8 encoding; streamRead(mDocStream, encoding); UT_iconv_t cd = findConverter(encoding); if (!UT_iconv_isValid(cd)) throw UT_IE_IMPORTERROR; UT_uint16 count; streamRead(mDocStream, count); while (count--) { UT_uint16 id; streamRead(mDocStream, id); char* str; UT_uint16 len; ::readByteString(mDocStream, str, &len); if (id == IDX_NOCONV_FF) { UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); } // FIXME: find a way to not have to copy and free // the result of UT_convert_cd.... --hub UT_DEBUGMSG(("SDW: StringPool: found 0x%04x <-> %.*s\n", id, len, str)); UT_UCS4Char* convertedString = reinterpret_cast<UT_UCS4Char*>(UT_convert_cd(str, len + 1, cd, NULL, NULL)); mStringPool.insert(stringpool_map::value_type(id, convertedString)); FREEP(convertedString); delete [] str; } UT_iconv_close(cd); break; } case SWG_COMMENT: // skip over comments break; case SWG_EOF: done = true; break; default: UT_DEBUGMSG(("SDW: Skipping %u bytes for record type '%c' (starting at 0x%08llX)\n", recSize, type, (long long)gsf_input_tell(mDocStream))); } // Seek to the end of the record, in case it wasn't read completely if (gsf_input_seek(mDocStream, eor, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } UT_DEBUGMSG(("SDW: Done\n")); return UT_OK; } catch(UT_Error e) { UT_DEBUGMSG(("SDW: error %d\n", e)); return e; } catch(...) { UT_DEBUGMSG(("SDW: Unknown error\n")); return UT_IE_BOGUSDOCUMENT; } }
static int test (int argc, char *argv[]) { GsfInput *input; GsfInfile *infile; 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; } input = gsf_input_uncompress (input); infile = gsf_infile_msole_new (input, &err); g_object_unref (G_OBJECT (input)); if (infile == NULL) { g_return_val_if_fail (err != NULL, 1); g_warning ("'%s' Not an OLE file: %s", argv[1], err->message); g_error_free (err); return 1; } if (argc > 2) { int i; GsfInput *child, *ptr = GSF_INPUT (infile); for (i = 2 ; i < argc && ptr != NULL; i++, ptr = child) { fprintf (stderr, "--> '%s'\n", argv [i]); if (GSF_IS_INFILE (ptr) && gsf_infile_num_children (GSF_INFILE (ptr)) >= 0) { child = gsf_infile_child_by_name (GSF_INFILE (ptr), argv [i]); if (child == NULL) { g_warning ("No child named '%s'", argv [i]); child = NULL; } } else { g_warning ("stream is not a directory '%s'", argv [i]); child = NULL; } g_object_unref (G_OBJECT (ptr)); } if (ptr != NULL) { /* See the comment on is_dir in test-cp-msole.c. */ if (GSF_IS_INFILE (ptr) && gsf_infile_num_children (GSF_INFILE (ptr)) >= 0) ls_R (ptr); /* unrefs infile */ else { gsf_input_dump (GSF_INPUT (ptr), dump_as_hex); g_object_unref (G_OBJECT (ptr)); } } } else ls_R (GSF_INPUT (infile)); /* unrefs infile */ return 0; }
/** * Adds an data item (<d> tag) in the AbiWord document for the specified image. * * Code mainly from Dom Lachowicz and/or Robert Staudinger. * * @param rDataId Receives the id that has been given to the added data item. * @param ppAtts The attributes of a <draw:image> element. */ bool ODi_Abi_Data::addObjectDataItem(UT_String& rDataId, const gchar** ppAtts, int& pto_Type) { const gchar* pHRef = UT_getAttribute ("xlink:href", ppAtts); UT_return_val_if_fail(pHRef,false); // If we have a string smaller then this we are in trouble. File corrupted? UT_return_val_if_fail((strlen(pHRef) >= 10 /*10 == strlen("Pictures/a")*/), false); UT_Error error = UT_OK; UT_ByteBuf *object_buf; GsfInfile* pObjects_dir; UT_uint32 objectID; // The subdirectory that holds the picture. e.g: "ObjectReplacements" or "Pictures" UT_String dirName; // The file name of the picture. e.g.: "Object 1" or "10000201000000D100000108FF0E3707.png" UT_String fileName; const std::string id = m_href_to_id[pHRef]; if (!id.empty()) { // This object was already added. // Use the existing data item id. rDataId = id; return true; } // Get a new, unique, ID. objectID = m_pAbiDocument->getUID(UT_UniqueId::Math); UT_String_sprintf(rDataId, "MathLatex%d", objectID); // Add this id to the list UT_DebugOnly<href_id_map_t::iterator> iter = m_href_to_id .insert(m_href_to_id.begin(), href_id_map_t::value_type(pHRef, rDataId.c_str())); UT_ASSERT((href_id_map_t::iterator)iter != m_href_to_id.end()); _splitDirectoryAndFileName(pHRef, dirName, fileName); if (fileName.empty ()) fileName = "content.xml"; pObjects_dir = GSF_INFILE(gsf_infile_child_by_name(m_pGsfInfile, dirName.c_str())); UT_return_val_if_fail(pObjects_dir, false); // Loads object_buf object_buf = new UT_ByteBuf (); error = _loadStream(pObjects_dir, fileName.c_str(), *object_buf); g_object_unref (G_OBJECT (pObjects_dir)); if (error != UT_OK) { delete object_buf; return false; } // check to ensure that we're seeing math. this can probably be made smarter. static const char math_header[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE math:math"; if ((object_buf->getLength () > strlen (math_header)) && (strncmp ((const char*)object_buf->getPointer (0), math_header, strlen (math_header)) != 0)) { delete object_buf; return false; } // // Create the data item. // if (!m_pAbiDocument->createDataItem(rDataId.c_str(), false, object_buf, "application/mathml+xml", NULL)) { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); return false; } pto_Type = PTO_Math; return true; }
/** * Adds an data item (<d> tag) in the AbiWord document for the specified image. * * Code mainly from Dom Lachowicz and/or Robert Staudinger. * * @param rDataId Receives the id that has been given to the added data item. * @param ppAtts The attributes of a <draw:image> element. */ bool ODi_Abi_Data::addImageDataItem(UT_String& rDataId, const gchar** ppAtts) { const gchar* pHRef = UT_getAttribute ("xlink:href", ppAtts); UT_return_val_if_fail(pHRef,false); // If we have a string smaller then this we are in trouble. File corrupted? UT_return_val_if_fail((strlen(pHRef) >= 10 /*10 == strlen("Pictures/a")*/), false); UT_Error error = UT_OK; UT_ByteBuf img_buf; GsfInfile* pPictures_dir; FG_Graphic* pFG = NULL; const UT_ByteBuf* pPictData = NULL; UT_uint32 imageID; // The subdirectory that holds the picture. e.g: "ObjectReplacements" or "Pictures" UT_String dirName; // The file name of the picture. e.g.: "Object 1" or "10000201000000D100000108FF0E3707.png" UT_String fileName; const std::string id = m_href_to_id[pHRef]; if (!id.empty()) { // This image was already added. // Use the existing data item id. rDataId = id; return true; } // Get a new, unique, ID. imageID = m_pAbiDocument->getUID(UT_UniqueId::Image); UT_String_sprintf(rDataId, "%d", imageID); // Add this id to the list UT_DebugOnly<href_id_map_t::iterator> iter = m_href_to_id .insert(m_href_to_id.begin(), href_id_map_t::value_type(pHRef, rDataId.c_str())); UT_ASSERT((href_id_map_t::iterator)iter != m_href_to_id.end()); _splitDirectoryAndFileName(pHRef, dirName, fileName); pPictures_dir = GSF_INFILE(gsf_infile_child_by_name(m_pGsfInfile, dirName.c_str())); UT_return_val_if_fail(pPictures_dir, false); // Loads img_buf error = _loadStream(pPictures_dir, fileName.c_str(), img_buf); g_object_unref (G_OBJECT (pPictures_dir)); if (error != UT_OK) { return false; } // Builds pImporter from img_buf error = IE_ImpGraphic::loadGraphic (img_buf, IEGFT_Unknown, &pFG); if ((error != UT_OK) || !pFG) { // pictData is already freed in ~FG_Graphic return false; } // Builds pPictData from pFG // TODO: can we get back a vector graphic? pPictData = pFG->getBuffer(); if (!pPictData) { // i don't think that this could ever happen, but... UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); return false; } // // Create the data item. // if (!m_pAbiDocument->createDataItem(rDataId.c_str(), false, pPictData, pFG->getMimeType(), NULL)) { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); return false; } return true; }