From 57b6f22901b3a0ccca3894f30d847baf749493a3 Mon Sep 17 00:00:00 2001 From: dockes Date: Fri, 16 Nov 2007 14:28:52 +0000 Subject: [PATCH] indexedmimetypes --- src/common/rclconfig.cpp | 41 ++++++++++++++++++++++++++++++++-- src/common/rclconfig.h | 21 +++++++---------- src/internfile/internfile.cpp | 4 ++-- src/internfile/mimehandler.cpp | 9 ++++---- src/internfile/mimehandler.h | 9 ++++++-- 5 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index f6b01487..694c3a76 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -1,5 +1,5 @@ #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 /* * This program is free software; you can redistribute it and/or modify @@ -167,6 +167,35 @@ ConfNull *RclConfig::cloneMainConfig() 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 l; + // Yea, no good to go string->list->set. Lazy me. + stringToStrings(rmtstr, l); + for (list::iterator it = l.begin(); it !=l.end(); it++) { + m_restrictMTypes.insert(*it); + } + } + } +} + bool RclConfig::getConfParam(const std::string &name, int *ivp) { string value; @@ -407,9 +436,15 @@ bool RclConfig::getMimeCatTypes(const string& cat, list& tps) return true; } -string RclConfig::getMimeHandlerDef(const std::string &mtype) +string RclConfig::getMimeHandlerDef(const std::string &mtype, bool filtertypes) { 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")) { 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; defcharset = r.defcharset; guesscharset = r.guesscharset; + m_rmtstr = r.m_rmtstr; + m_restrictMTypes = r.m_restrictMTypes; } #else // -> Test diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 07d39645..bc6c790a 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -16,17 +16,19 @@ */ #ifndef _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 #include #include +#include #include #ifndef NO_NAMESPACES using std::list; using std::string; using std::vector; using std::pair; +using std::set; #endif #include "conftree.h" @@ -60,17 +62,7 @@ class RclConfig { string getConfDir() {return m_confdir;} /** Set current directory reference, and fetch automatic parameters. */ - 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); - } + void setKeyDir(const string &dir); string getKeyDir() const {return m_keydir;} /** Get generic configuration parameter according to current keydir */ @@ -136,7 +128,7 @@ class RclConfig { string getSuffixFromMimeType(const string &mt); /** 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 */ string getMimeIconName(const string &mtype, string *path = 0); @@ -198,6 +190,9 @@ class RclConfig { // Parameters auto-fetched on setkeydir string defcharset; // These are stored locally to avoid bool guesscharset; // They are fetched initially or on setKeydir() + // Limiting set of mime types to be processed. Normally empty. + string m_rmtstr; + set m_restrictMTypes; /** Create initial user configuration */ bool initUserConfig(); diff --git a/src/internfile/internfile.cpp b/src/internfile/internfile.cpp index f8a6dc99..606101c0 100644 --- a/src/internfile/internfile.cpp +++ b/src/internfile/internfile.cpp @@ -1,5 +1,5 @@ #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 /* * 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) m_mimetype = l_mime; - Dijon::Filter *df = getMimeHandler(l_mime, m_cfg); + Dijon::Filter *df = getMimeHandler(l_mime, m_cfg, !m_forPreview); if (!df) { // No handler for this type, for now :( if indexallfilenames diff --git a/src/internfile/mimehandler.cpp b/src/internfile/mimehandler.cpp index 58c0a663..4b284173 100644 --- a/src/internfile/mimehandler.cpp +++ b/src/internfile/mimehandler.cpp @@ -1,5 +1,5 @@ #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 /* * 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 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 string hs; if (!mtype.empty()) - hs = cfg->getMimeHandlerDef(mtype); + hs = cfg->getMimeHandlerDef(mtype, filtertypes); if (!hs.empty()) { // Break definition into type and name diff --git a/src/internfile/mimehandler.h b/src/internfile/mimehandler.h index 95fd4594..9674c670 100644 --- a/src/internfile/mimehandler.h +++ b/src/internfile/mimehandler.h @@ -16,7 +16,7 @@ */ #ifndef _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 #include @@ -86,8 +86,13 @@ protected: /** * Return indexing handler object for the given mime type * 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 ? extern bool canIntern(const std::string mimetype, RclConfig *cfg);