From 6c03417195a973abcc96e7506e8ef7c6c2d16771 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Mon, 22 Nov 2010 15:56:14 +0100 Subject: [PATCH] Move locafields parsing code from fsindexer to rclconfig for possible reuse --- src/common/rclconfig.cpp | 37 ++++++++++++++++++++++++++++++------- src/common/rclconfig.h | 5 ++++- src/index/fsindexer.cpp | 17 +---------------- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index fd546ee8..96e63e55 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -244,7 +244,7 @@ void RclConfig::setKeyDir(const string &dir) getConfParam("guesscharset", &guesscharset); } -bool RclConfig::getConfParam(const std::string &name, int *ivp) +bool RclConfig::getConfParam(const string &name, int *ivp) { string value; if (!getConfParam(name, value)) @@ -258,7 +258,7 @@ bool RclConfig::getConfParam(const std::string &name, int *ivp) return true; } -bool RclConfig::getConfParam(const std::string &name, bool *bvp) +bool RclConfig::getConfParam(const string &name, bool *bvp) { if (!bvp) return false; @@ -271,7 +271,7 @@ bool RclConfig::getConfParam(const std::string &name, bool *bvp) return true; } -bool RclConfig::getConfParam(const std::string &name, vector *svvp) +bool RclConfig::getConfParam(const string &name, vector *svvp) { if (!svvp) return false; @@ -281,7 +281,7 @@ bool RclConfig::getConfParam(const std::string &name, vector *svvp) return false; return stringToStrings(s, *svvp); } -bool RclConfig::getConfParam(const std::string &name, list *svvp) +bool RclConfig::getConfParam(const string &name, list *svvp) { if (!svvp) return false; @@ -354,12 +354,35 @@ const string& RclConfig::getDefCharset(bool filename) } } +bool RclConfig::addLocalFields(map *tgt) +{ + LOGDEB(("RclConfig::addLocalFields: keydir [%s]\n", m_keydir.c_str())); + string sfields; + if (tgt == 0 || ! getConfParam("localfields", sfields)) + return false; + // Substitute ':' with '\n' inside the string. There is no way to escape ':' + for (string::size_type i = 0; i < sfields.size(); i++) + if (sfields[i] == ':') + sfields[i] = '\n'; + // Parse the result with a confsimple and add the results to the metadata + ConfSimple conf(sfields, 1, true); + list nmlst = conf.getNames(""); + for (list::const_iterator it = nmlst.begin(); + it != nmlst.end(); it++) { + conf.get(*it, (*tgt)[*it]); + LOGDEB(("RclConfig::addLocalFields: [%s] => [%s]\n", + (*it).c_str(), (*tgt)[*it].c_str())); + } + return true; +} + + // Get all known document mime values (for indexing). We get them from // the mimeconf 'index' submap: values not in there (ie from mimemap // or idfile) can't possibly belong to documents in the database. -std::list RclConfig::getAllMimeTypes() +list RclConfig::getAllMimeTypes() { - std::list lst; + list lst; if (mimeconf == 0) return lst; lst = mimeconf->getNames("index"); @@ -497,7 +520,7 @@ bool RclConfig::getMimeCatTypes(const string& cat, list& tps) return true; } -string RclConfig::getMimeHandlerDef(const std::string &mtype, bool filtertypes) +string RclConfig::getMimeHandlerDef(const string &mtype, bool filtertypes) { string hs; if (filtertypes && m_rmtstate.needrecompute()) { diff --git a/src/common/rclconfig.h b/src/common/rclconfig.h index 07b2ede8..7dc0f589 100644 --- a/src/common/rclconfig.h +++ b/src/common/rclconfig.h @@ -145,8 +145,11 @@ class RclConfig { Doesn't depend on the keydir */ list getDaemSkippedPaths(); + /** conf: Add local fields to target dic */ + bool addLocalFields(map *tgt); + /** - * Check if file name should be ignored because of suffix + * mimemap: Check if file name should be ignored because of suffix * * The list of ignored suffixes is initialized on first call, and * not changed for subsequent setKeydirs. diff --git a/src/index/fsindexer.cpp b/src/index/fsindexer.cpp index ec73769a..d043ddeb 100644 --- a/src/index/fsindexer.cpp +++ b/src/index/fsindexer.cpp @@ -268,22 +268,7 @@ void FsIndexer::localfieldsfromconf() { LOGDEB(("FsIndexer::localfieldsfromconf\n")); m_localfields.clear(); - string sfields; - if (!m_config->getConfParam("localfields", sfields)) - return; - // Substitute ':' with '\n' inside the string. There is no way to escape ':' - for (string::size_type i = 0; i < sfields.size(); i++) - if (sfields[i] == ':') - sfields[i] = '\n'; - // Parse the result with a confsimple and add the results to the metadata - ConfSimple conf(sfields, 1, true); - list nmlst = conf.getNames(""); - for (list::const_iterator it = nmlst.begin(); - it != nmlst.end(); it++) { - conf.get(*it, m_localfields[*it]); - LOGDEB(("FsIndexer::localfieldsfromconf: [%s] => [%s]\n", - (*it).c_str(), m_localfields[*it].c_str())); - } + m_config->addLocalFields(&m_localfields); } //