misc cleanup + tell filters if working for preview or index
This commit is contained in:
parent
b83513021d
commit
01780f5c42
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.8 2005-11-14 09:59:17 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.9 2005-11-18 15:19:14 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
@ -72,23 +72,24 @@ static bool uncompressfile(RclConfig *conf, const string& ifn,
|
||||
|
||||
void FileInterner::tmpcleanup()
|
||||
{
|
||||
if (tdir.empty() || tfile.empty())
|
||||
if (m_tdir.empty() || m_tfile.empty())
|
||||
return;
|
||||
if (unlink(tfile.c_str()) < 0) {
|
||||
if (unlink(m_tfile.c_str()) < 0) {
|
||||
LOGERR(("FileInterner::tmpcleanup: unlink(%s) errno %d\n",
|
||||
tfile.c_str(), errno));
|
||||
m_tfile.c_str(), errno));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Handler==0 on return says we're in error
|
||||
// Handler==0 on return says we're in error, will be handled when calling
|
||||
// internfile
|
||||
FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
|
||||
const string& td, const string *imime)
|
||||
: fn(f), config(cnf), tdir(td), handler(0)
|
||||
: m_fn(f), m_cfg(cnf), m_tdir(td), m_handler(0)
|
||||
{
|
||||
// Note that we are actually going to access the file, so that it's ok
|
||||
// to check this config variable at every call even if it can only change
|
||||
// when we change directories
|
||||
// We are actually going to access the file, so it's ok
|
||||
// performancewise to check this config variable at every call
|
||||
// even if it can only change when we change directories
|
||||
string usfc;
|
||||
int usfci;
|
||||
if (!cnf->getConfParam("usesystemfilecommand", usfc))
|
||||
@ -97,17 +98,19 @@ FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
|
||||
usfci = atoi(usfc.c_str()) ? 1 : 0;
|
||||
LOGDEB1(("FileInterner::FileInterner: usfci now %d\n", usfci));
|
||||
|
||||
bool forPreview = imime ? true : false;
|
||||
|
||||
// We need to run mime type identification in any case to check
|
||||
// for a compressed file.
|
||||
mime = mimetype(fn, config->getMimeMap(), usfci);
|
||||
m_mime = mimetype(m_fn, m_cfg->getMimeMap(), usfci);
|
||||
|
||||
// If identification fails, try to use the input parameter. Note that this
|
||||
// is normally not a compressed type (it's the mime type from the db)
|
||||
if (mime.empty() && imime)
|
||||
mime = *imime;
|
||||
if (mime.empty()) {
|
||||
if (m_mime.empty() && imime)
|
||||
m_mime = *imime;
|
||||
if (m_mime.empty()) {
|
||||
// No mime type: not listed in our map, or present in stop list
|
||||
LOGDEB(("FileInterner::FileInterner: (no mime) [%s]\n", fn.c_str()));
|
||||
LOGDEB(("FileInterner::FileInterner: (no mime) [%s]\n", m_fn.c_str()));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -115,42 +118,45 @@ FileInterner::FileInterner(const std::string &f, RclConfig *cnf,
|
||||
// uncompressed file, and rerun the mime type identification, then do the
|
||||
// rest with the temp file.
|
||||
list<string>ucmd;
|
||||
if (getUncompressor(mime, config->getMimeConf(), ucmd)) {
|
||||
if (!uncompressfile(config, fn, ucmd, tdir, tfile)) {
|
||||
if (getUncompressor(m_mime, m_cfg->getMimeConf(), ucmd)) {
|
||||
if (!uncompressfile(m_cfg, m_fn, ucmd, m_tdir, m_tfile)) {
|
||||
return;
|
||||
}
|
||||
LOGDEB(("internfile: after ucomp: tdir %s, tfile %s\n",
|
||||
tdir.c_str(), tfile.c_str()));
|
||||
fn = tfile;
|
||||
mime = mimetype(fn, config->getMimeMap(), usfci);
|
||||
if (mime.empty() && imime)
|
||||
mime = *imime;
|
||||
if (mime.empty()) {
|
||||
LOGDEB(("internfile: after ucomp: m_tdir %s, tfile %s\n",
|
||||
m_tdir.c_str(), m_tfile.c_str()));
|
||||
m_fn = m_tfile;
|
||||
m_mime = mimetype(m_fn, m_cfg->getMimeMap(), usfci);
|
||||
if (m_mime.empty() && imime)
|
||||
m_mime = *imime;
|
||||
if (m_mime.empty()) {
|
||||
// No mime type ?? pass on.
|
||||
LOGDEB(("internfile: (no mime) [%s]\n", fn.c_str()));
|
||||
LOGDEB(("internfile: (no mime) [%s]\n", m_fn.c_str()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Look for appropriate handler
|
||||
handler = getMimeHandler(mime, config->getMimeConf());
|
||||
if (!handler) {
|
||||
m_handler = getMimeHandler(m_mime, m_cfg->getMimeConf());
|
||||
if (!m_handler) {
|
||||
// No handler for this type, for now :(
|
||||
LOGDEB(("FileInterner::FileInterner: %s: no handler\n", mime.c_str()));
|
||||
LOGDEB(("FileInterner::FileInterner: %s: no handler\n",
|
||||
m_mime.c_str()));
|
||||
return;
|
||||
}
|
||||
|
||||
LOGDEB(("FileInterner::FileInterner: %s [%s]\n",mime.c_str(), fn.c_str()));
|
||||
m_handler->setForPreview(forPreview);
|
||||
LOGDEB(("FileInterner::FileInterner: %s [%s]\n", m_mime.c_str(),
|
||||
m_fn.c_str()));
|
||||
}
|
||||
|
||||
FileInterner::Status FileInterner::internfile(Rcl::Doc& doc, string& ipath)
|
||||
{
|
||||
if (!handler)
|
||||
if (!m_handler)
|
||||
return FIError;
|
||||
|
||||
// Turn file into a document. The document has fields for title, body
|
||||
// etc., all text converted to utf8
|
||||
MimeHandler::Status mhs = handler->mkDoc(config, fn, mime, doc, ipath);
|
||||
MimeHandler::Status mhs =
|
||||
m_handler->mkDoc(m_cfg, m_fn, m_mime, doc, ipath);
|
||||
FileInterner::Status ret = FIError;
|
||||
switch (mhs) {
|
||||
case MimeHandler::MHError: break;
|
||||
@ -158,13 +164,13 @@ FileInterner::Status FileInterner::internfile(Rcl::Doc& doc, string& ipath)
|
||||
case MimeHandler::MHAgain: ret = FIAgain;break;
|
||||
}
|
||||
|
||||
doc.mimetype = mime;
|
||||
doc.mimetype = m_mime;
|
||||
return ret;
|
||||
}
|
||||
|
||||
FileInterner::~FileInterner()
|
||||
{
|
||||
delete handler;
|
||||
handler = 0;
|
||||
delete m_handler;
|
||||
m_handler = 0;
|
||||
tmpcleanup();
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef _INTERNFILE_H_INCLUDED_
|
||||
#define _INTERNFILE_H_INCLUDED_
|
||||
/* @(#$Id: internfile.h,v 1.4 2005-11-14 09:59:17 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: internfile.h,v 1.5 2005-11-18 15:19:14 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -12,24 +12,20 @@ class MimeHandler;
|
||||
/// Turn external file into internal representation, according to mime
|
||||
/// type etc
|
||||
class FileInterner {
|
||||
string fn;
|
||||
RclConfig *config;
|
||||
const string &tdir;
|
||||
MimeHandler *handler;
|
||||
string tfile;
|
||||
string mime;
|
||||
|
||||
void tmpcleanup();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Identify and possibly decompress file, create adequate handler
|
||||
* Identify and possibly decompress file, create adequate
|
||||
* handler. The mtype parameter is only set when the object is
|
||||
* created for previewing a file. Filter output may be
|
||||
* different for previewing and indexing.
|
||||
*
|
||||
* @param fn file name
|
||||
* @param cnf Recoll configuration
|
||||
* @param td temporary directory to use as working space for possible
|
||||
* decompression
|
||||
* @param mimetype mime type if known. For a compressed file this is the
|
||||
* mime type for the uncompressed version.
|
||||
* @param td temporary directory to use as working space if
|
||||
* decompression needed.
|
||||
* @param mtype mime type if known. For a compressed file this is the
|
||||
* mime type for the uncompressed version. This currently doubles up
|
||||
* to indicate that this object is for previewing (not indexing).
|
||||
*/
|
||||
FileInterner(const std::string &fn, RclConfig *cnf, const string& td,
|
||||
const std::string *mtype = 0);
|
||||
@ -53,6 +49,17 @@ class FileInterner {
|
||||
* should be called again to get the following one(s).
|
||||
*/
|
||||
Status internfile(Rcl::Doc& doc, string &ipath);
|
||||
|
||||
private:
|
||||
string m_fn;
|
||||
RclConfig *m_cfg;
|
||||
const string &m_tdir;
|
||||
MimeHandler *m_handler;
|
||||
|
||||
string m_tfile;
|
||||
string m_mime;
|
||||
|
||||
void tmpcleanup();
|
||||
};
|
||||
|
||||
#endif /* _INTERNFILE_H_INCLUDED_ */
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: mh_exec.cpp,v 1.1 2005-11-18 13:23:46 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: mh_exec.cpp,v 1.2 2005-11-18 15:19:14 dockes Exp $ (C) 2005 J.F.Dockes";
|
||||
#endif
|
||||
|
||||
#include "execmd.h"
|
||||
@ -32,6 +32,8 @@ MimeHandlerExec::mkDoc(RclConfig *conf, const string &fn,
|
||||
// Execute command and store the result text, which is supposedly html
|
||||
string html;
|
||||
ExecCmd exec;
|
||||
exec.putenv(m_forPreview ? "RECOLL_FILTER_FORPREVIEW=yes" :
|
||||
"RECOLL_FILTER_FORPREVIEW=no");
|
||||
int status = exec.doexec(cmd, myparams, 0, &html);
|
||||
if (status) {
|
||||
LOGERR(("MimeHandlerExec: command status 0x%x: %s\n",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef _MIMEHANDLER_H_INCLUDED_
|
||||
#define _MIMEHANDLER_H_INCLUDED_
|
||||
/* @(#$Id: mimehandler.h,v 1.8 2005-11-16 15:07:20 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: mimehandler.h,v 1.9 2005-11-18 15:19:14 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
@ -14,6 +14,7 @@
|
||||
*/
|
||||
class MimeHandler {
|
||||
public:
|
||||
MimeHandler() : m_forPreview(false) {}
|
||||
virtual ~MimeHandler() {}
|
||||
|
||||
/// Status from mkDoc method.
|
||||
@ -41,6 +42,11 @@ class MimeHandler {
|
||||
const std::string &mimetype,
|
||||
Rcl::Doc& outdoc,
|
||||
string& ipath) = 0;
|
||||
|
||||
virtual void setForPreview(bool onoff) {m_forPreview = onoff;};
|
||||
|
||||
protected:
|
||||
bool m_forPreview;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#ifndef _EXECMD_H_INCLUDED_
|
||||
#define _EXECMD_H_INCLUDED_
|
||||
/* @(#$Id: execmd.h,v 1.3 2005-11-18 13:52:48 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: execmd.h,v 1.4 2005-11-18 15:19:14 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
@ -28,7 +28,8 @@ class ExecCmd {
|
||||
std::string *output = 0);
|
||||
/**
|
||||
* Add/replace environment variable before executing command. This should
|
||||
* be called before doexec of course.
|
||||
* be called before doexec of course (possibly multiple times for several
|
||||
* variables).
|
||||
* @param envassign an environment assignment string (name=value)
|
||||
*/
|
||||
void putenv(const std::string &envassign);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user