gboolean psiconv_read_header (GsfInput *input) { gboolean res = FALSE; psiconv_buffer buf = NULL; psiconv_config config; if ((config = psiconv_config_default()) == NULL) goto out; config->verbosity = PSICONV_VERB_FATAL; psiconv_config_read(NULL,&config); if ((buf = psiconv_stream_to_buffer (input, 1024)) == NULL) goto out; if (psiconv_file_type(config, buf,NULL,NULL) == psiconv_sheet_file) res = TRUE; out: if (config) psiconv_config_free(config); if (buf) psiconv_buffer_free(buf); return res; }
/*! * Check whether this is a Psion file of the given type * * This is used by the recognizeContents methods of the Word and TextEd * sniffers. * \return Psion files have strong magic, so we either return * UT_CONFIDENCE_PERFECT or UT_CONFIDENCE_ZILCH. */ UT_Confidence_t IE_Imp_Psion_Sniffer::checkContents(const char * szBuf, UT_uint32 iNumbytes, psiconv_file_type_t filetype) { UT_uint32 i; psiconv_config config; psiconv_buffer pl; psiconv_file_type_t filetype_detected; // Prepare a new psiconv_config object config = psiconv_config_default(); if (!config) goto ERROR1; config->error_handler = &psion_error_handler; psiconv_config_read(NULL,&config); // It is likely detection will fail, so keep it silent. config->verbosity = PSICONV_VERB_FATAL; // Copy the file data into a psiconv_buffer. pl = psiconv_buffer_new(); if (!pl) goto ERROR2; for (i=0; i < iNumbytes; i++) if ((psiconv_buffer_add(pl,szBuf[i]))) { goto ERROR3; } // Check whether this is a Psion file. filetype_detected = psiconv_file_type(config,pl,NULL,NULL); psiconv_buffer_free(pl); psiconv_config_free(config); if (filetype == filetype_detected) return UT_CONFIDENCE_PERFECT; else return UT_CONFIDENCE_ZILCH; ERROR3: psiconv_buffer_free(pl); ERROR2: psiconv_config_free(config); ERROR1: return UT_CONFIDENCE_ZILCH; }