indexedmimetypes

This commit is contained in:
dockes 2007-11-16 14:28:52 +00:00
parent 5aaa3032d9
commit 57b6f22901
5 changed files with 61 additions and 23 deletions

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.54 2007-10-17 09:57:23 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.55 2007-11-16 14:28:52 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -167,6 +167,35 @@ ConfNull *RclConfig::cloneMainConfig()
return conf; return conf;
} }
// Remember what directory we're under (for further conf->get()s), and
// prefetch a few common values.
void RclConfig::setKeyDir(const string &dir)
{
m_keydir = dir;
if (m_conf == 0)
return;
if (!m_conf->get("defaultcharset", defcharset, m_keydir))
defcharset.erase();
getConfParam("guesscharset", &guesscharset);
string rmtstr;
if (m_conf->get("indexedmimetypes", rmtstr, m_keydir)) {
stringtolower(rmtstr);
if (rmtstr != m_rmtstr) {
LOGDEB2(("RclConfig::setKeyDir: rmtstr [%s]\n", rmtstr.c_str()));
m_rmtstr = rmtstr;
list<string> l;
// Yea, no good to go string->list->set. Lazy me.
stringToStrings(rmtstr, l);
for (list<string>::iterator it = l.begin(); it !=l.end(); it++) {
m_restrictMTypes.insert(*it);
}
}
}
}
bool RclConfig::getConfParam(const std::string &name, int *ivp) bool RclConfig::getConfParam(const std::string &name, int *ivp)
{ {
string value; string value;
@ -407,9 +436,15 @@ bool RclConfig::getMimeCatTypes(const string& cat, list<string>& tps)
return true; return true;
} }
string RclConfig::getMimeHandlerDef(const std::string &mtype) string RclConfig::getMimeHandlerDef(const std::string &mtype, bool filtertypes)
{ {
string hs; string hs;
if (filtertypes && !m_restrictMTypes.empty()) {
string mt = mtype;
stringtolower(mt);
if (m_restrictMTypes.find(mt) == m_restrictMTypes.end())
return hs;
}
if (!mimeconf->get(mtype, hs, "index")) { if (!mimeconf->get(mtype, hs, "index")) {
LOGDEB1(("getMimeHandler: no handler for '%s'\n", mtype.c_str())); LOGDEB1(("getMimeHandler: no handler for '%s'\n", mtype.c_str()));
} }
@ -718,6 +753,8 @@ void RclConfig::initFrom(const RclConfig& r)
m_maxsufflen = r.m_maxsufflen; m_maxsufflen = r.m_maxsufflen;
defcharset = r.defcharset; defcharset = r.defcharset;
guesscharset = r.guesscharset; guesscharset = r.guesscharset;
m_rmtstr = r.m_rmtstr;
m_restrictMTypes = r.m_restrictMTypes;
} }
#else // -> Test #else // -> Test

View File

@ -16,17 +16,19 @@
*/ */
#ifndef _RCLCONFIG_H_INCLUDED_ #ifndef _RCLCONFIG_H_INCLUDED_
#define _RCLCONFIG_H_INCLUDED_ #define _RCLCONFIG_H_INCLUDED_
/* @(#$Id: rclconfig.h,v 1.38 2007-10-09 09:43:10 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: rclconfig.h,v 1.39 2007-11-16 14:28:52 dockes Exp $ (C) 2004 J.F.Dockes */
#include <list> #include <list>
#include <string> #include <string>
#include <vector> #include <vector>
#include <set>
#include <utility> #include <utility>
#ifndef NO_NAMESPACES #ifndef NO_NAMESPACES
using std::list; using std::list;
using std::string; using std::string;
using std::vector; using std::vector;
using std::pair; using std::pair;
using std::set;
#endif #endif
#include "conftree.h" #include "conftree.h"
@ -60,17 +62,7 @@ class RclConfig {
string getConfDir() {return m_confdir;} string getConfDir() {return m_confdir;}
/** Set current directory reference, and fetch automatic parameters. */ /** Set current directory reference, and fetch automatic parameters. */
void setKeyDir(const string &dir) void setKeyDir(const string &dir);
{
m_keydir = dir;
if (m_conf == 0)
return;
if (!m_conf->get("defaultcharset", defcharset, m_keydir))
defcharset.erase();
string str;
m_conf->get("guesscharset", str, m_keydir);
guesscharset = stringToBool(str);
}
string getKeyDir() const {return m_keydir;} string getKeyDir() const {return m_keydir;}
/** Get generic configuration parameter according to current keydir */ /** Get generic configuration parameter according to current keydir */
@ -136,7 +128,7 @@ class RclConfig {
string getSuffixFromMimeType(const string &mt); string getSuffixFromMimeType(const string &mt);
/** mimeconf: get input filter for mimetype */ /** mimeconf: get input filter for mimetype */
string getMimeHandlerDef(const string &mimetype); string getMimeHandlerDef(const string &mimetype, bool filtertypes=false);
/** mimeconf: get icon name for mimetype */ /** mimeconf: get icon name for mimetype */
string getMimeIconName(const string &mtype, string *path = 0); string getMimeIconName(const string &mtype, string *path = 0);
@ -198,6 +190,9 @@ class RclConfig {
// Parameters auto-fetched on setkeydir // Parameters auto-fetched on setkeydir
string defcharset; // These are stored locally to avoid string defcharset; // These are stored locally to avoid
bool guesscharset; // They are fetched initially or on setKeydir() bool guesscharset; // They are fetched initially or on setKeydir()
// Limiting set of mime types to be processed. Normally empty.
string m_rmtstr;
set<string> m_restrictMTypes;
/** Create initial user configuration */ /** Create initial user configuration */
bool initUserConfig(); bool initUserConfig();

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: internfile.cpp,v 1.36 2007-10-27 08:40:07 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: internfile.cpp,v 1.37 2007-11-16 14:28:52 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -145,7 +145,7 @@ FileInterner::FileInterner(const std::string &f, const struct stat *stp,
// Look for appropriate handler (might still return empty) // Look for appropriate handler (might still return empty)
m_mimetype = l_mime; m_mimetype = l_mime;
Dijon::Filter *df = getMimeHandler(l_mime, m_cfg); Dijon::Filter *df = getMimeHandler(l_mime, m_cfg, !m_forPreview);
if (!df) { if (!df) {
// No handler for this type, for now :( if indexallfilenames // No handler for this type, for now :( if indexallfilenames

View File

@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.21 2006-12-19 08:40:50 dockes Exp $ (C) 2004 J.F.Dockes"; static char rcsid[] = "@(#$Id: mimehandler.cpp,v 1.22 2007-11-16 14:28:52 dockes Exp $ (C) 2004 J.F.Dockes";
#endif #endif
/* /*
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -52,15 +52,16 @@ static Dijon::Filter *mhFactory(const string &mime)
return new MimeHandlerUnknown(lmime); return new MimeHandlerUnknown(lmime);
} }
/** /*
* Return handler object for given mime type: * Return handler object for given mime type:
*/ */
Dijon::Filter *getMimeHandler(const string &mtype, RclConfig *cfg) Dijon::Filter *getMimeHandler(const string &mtype, RclConfig *cfg,
bool filtertypes)
{ {
// Get handler definition for mime type // Get handler definition for mime type
string hs; string hs;
if (!mtype.empty()) if (!mtype.empty())
hs = cfg->getMimeHandlerDef(mtype); hs = cfg->getMimeHandlerDef(mtype, filtertypes);
if (!hs.empty()) { if (!hs.empty()) {
// Break definition into type and name // Break definition into type and name

View File

@ -16,7 +16,7 @@
*/ */
#ifndef _MIMEHANDLER_H_INCLUDED_ #ifndef _MIMEHANDLER_H_INCLUDED_
#define _MIMEHANDLER_H_INCLUDED_ #define _MIMEHANDLER_H_INCLUDED_
/* @(#$Id: mimehandler.h,v 1.14 2006-12-16 15:39:54 dockes Exp $ (C) 2004 J.F.Dockes */ /* @(#$Id: mimehandler.h,v 1.15 2007-11-16 14:28:52 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string> #include <string>
#include <list> #include <list>
@ -86,8 +86,13 @@ protected:
/** /**
* Return indexing handler object for the given mime type * Return indexing handler object for the given mime type
* returned pointer should be deleted by caller * returned pointer should be deleted by caller
* @param mtyp input mime type, ie text/plain
* @param cfg the recoll config object to be used
* @param filtertypes decide if we should restrict to types in
* indexedmimetypes (if this is set at all).
*/ */
extern Dijon::Filter *getMimeHandler(const std::string &mtyp, RclConfig *cfg); extern Dijon::Filter *getMimeHandler(const std::string &mtyp, RclConfig *cfg,
bool filtertypes=false);
/// Can this mime type be interned ? /// Can this mime type be interned ?
extern bool canIntern(const std::string mimetype, RclConfig *cfg); extern bool canIntern(const std::string mimetype, RclConfig *cfg);