got rid of accesses to global config through getMainConfig()

This commit is contained in:
Jean-Francois Dockes
2011-03-02 13:47:07 +01:00
parent bac0c1eeb9
commit e1a20aa810
31 changed files with 98 additions and 124 deletions
-4
View File
@@ -1053,10 +1053,6 @@ static int op_flags;
#define OPT_q 0x1
RclConfig *config;
RclConfig *RclConfig::getMainConfig()
{
return config;
}
int main(int argc, char **argv)
{
thisprog = argv[0];
+1 -4
View File
@@ -78,10 +78,7 @@ bool MimeHandlerExec::next_document()
}
int filtermaxseconds = 900;
RclConfig *conf = RclConfig::getMainConfig();
if (conf) {
conf->getConfParam("filtermaxseconds", &filtermaxseconds);
}
m_config->getConfParam("filtermaxseconds", &filtermaxseconds);
// Command name
string cmd = params.front();
+2 -1
View File
@@ -57,7 +57,8 @@ class MimeHandlerExec : public RecollFilter {
bool missingHelper;
////////////////
MimeHandlerExec(const string& mt) : RecollFilter(mt), missingHelper(false)
MimeHandlerExec(RclConfig *cnf, const string& mt)
: RecollFilter(cnf, mt), missingHelper(false)
{}
virtual ~MimeHandlerExec() {}
virtual bool set_document_file(const string &file_path) {
+1 -1
View File
@@ -251,7 +251,7 @@ bool MimeHandlerExecMultiple::next_document()
if (!ipath.empty()) {
m_metaData["ipath"] = ipath;
if (mtype.empty()) {
mtype = mimetype(ipath, 0, RclConfig::getMainConfig(), false);
mtype = mimetype(ipath, 0, m_config, false);
if (mtype.empty()) {
// mimetype() won't call idFile when there is no file. Do it
mtype = idFileMem(m_metaData["content"]);
+2 -2
View File
@@ -91,8 +91,8 @@ class MimeHandlerExecMultiple : public MimeHandlerExec {
/////// End un-cleared stuff.
public:
MimeHandlerExecMultiple(const string& mt)
: MimeHandlerExec(mt)
MimeHandlerExecMultiple(RclConfig *cnf, const string& mt)
: MimeHandlerExec(cnf, mt)
{}
// No resources to clean up, the ExecCmd destructor does it.
virtual ~MimeHandlerExecMultiple() {}
+2 -1
View File
@@ -27,7 +27,8 @@
*/
class MimeHandlerHtml : public RecollFilter {
public:
MimeHandlerHtml(const string& mt) : RecollFilter(mt) {}
MimeHandlerHtml(RclConfig *cnf, const string& mt)
: RecollFilter(cnf, mt) {}
virtual ~MimeHandlerHtml() {}
virtual bool set_document_file(const string &file_path);
virtual bool set_document_string(const string &data);
+7 -8
View File
@@ -55,19 +55,18 @@ static const string cstr_title = "title";
static const string cstr_msgid = "msgid";
static const string cstr_abstract = "abstract";
MimeHandlerMail::MimeHandlerMail(const string &mt)
: RecollFilter(mt), m_bincdoc(0), m_fd(-1), m_stream(0), m_idx(-1)
MimeHandlerMail::MimeHandlerMail(RclConfig *cnf, const string &mt)
: RecollFilter(cnf, mt), m_bincdoc(0), m_fd(-1), m_stream(0), m_idx(-1)
{
// Look for additional headers to be processed as per config:
list<string> hdrnames =
RclConfig::getMainConfig()->getFieldSectNames("mail");
m_config->getFieldSectNames("mail");
if (hdrnames.empty())
return;
for (list<string>::const_iterator it = hdrnames.begin();
it != hdrnames.end(); it++) {
(void)RclConfig::getMainConfig()->
getFieldConfParam(*it, "mail", m_addProcdHdrs[*it]);
(void)m_config->getFieldConfParam(*it, "mail", m_addProcdHdrs[*it]);
}
}
@@ -282,7 +281,7 @@ bool MimeHandlerMail::processAttach()
if (m_metaData[cstr_mimetype] == "application/octet-stream" &&
!m_metaData["filename"].empty()) {
string mt = mimetype(m_metaData["filename"], 0,
RclConfig::getMainConfig(), false);
m_config, false);
if (!mt.empty())
m_metaData[cstr_mimetype] = mt;
}
@@ -532,7 +531,7 @@ void MimeHandlerMail::walkmime(Binc::MimePart* doc, int depth)
!stringlowercmp("x-user-defined", charset) ||
!stringlowercmp("x-unknown", charset) ||
!stringlowercmp("unknown", charset) ) {
RclConfig::getMainConfig()->getConfParam("maildefcharset", charset);
m_config->getConfParam("maildefcharset", charset);
if (charset.empty())
charset = "iso-8859-1";
}
@@ -598,7 +597,7 @@ void MimeHandlerMail::walkmime(Binc::MimePart* doc, int depth)
string utf8;
const string *putf8 = 0;
if (!stringlowercmp("text/html", content_type.value)) {
MimeHandlerHtml mh("text/html");
MimeHandlerHtml mh(m_config, "text/html");
mh.set_property(Dijon::Filter::OPERATING_MODE,
m_forPreview ? "view" : "index");
mh.set_property(Dijon::Filter::DEFAULT_CHARSET, charset);
+1 -1
View File
@@ -40,7 +40,7 @@ class MHMailAttach;
*/
class MimeHandlerMail : public RecollFilter {
public:
MimeHandlerMail(const string &mt);
MimeHandlerMail(RclConfig *cnf, const string &mt);
virtual ~MimeHandlerMail();
virtual bool set_document_file(const string& file_path);
virtual bool set_document_string(const string& data);
+8 -16
View File
@@ -79,11 +79,11 @@ public:
}
~MboxCache() {}
mbhoff_type get_offset(const string& udi, int msgnum)
mbhoff_type get_offset(RclConfig *config, const string& udi, int msgnum)
{
LOGDEB0(("MboxCache::get_offsets: udi [%s] msgnum %d\n", udi.c_str(),
msgnum));
if (!ok()) {
if (!ok(config)) {
LOGDEB0(("MboxCache::get_offsets: init failed\n"));
return -1;
}
@@ -125,11 +125,11 @@ public:
}
// Save array of offsets for a given file, designated by Udi
void put_offsets(const string& udi, mbhoff_type fsize,
void put_offsets(RclConfig *config, const string& udi, mbhoff_type fsize,
vector<mbhoff_type>& offs)
{
LOGDEB0(("MboxCache::put_offsets: %u offsets\n", offs.size()));
if (!ok() || !maybemakedir())
if (!ok(config) || !maybemakedir())
return;
if (fsize < m_minfsize)
return;
@@ -161,13 +161,10 @@ public:
}
// Check state, possibly initialize
bool ok() {
bool ok(RclConfig *config) {
if (m_minfsize == -1)
return false;
if (!m_ok) {
RclConfig *config = RclConfig::getMainConfig();
if (config == 0)
return false;
int minmbs = 5;
config->getConfParam("mboxcacheminmbs", &minmbs);
if (minmbs < 0) {
@@ -269,9 +266,8 @@ bool MimeHandlerMbox::set_document_file(const string &fn)
m_quirks = 0;
// Check for location-based quirks:
RclConfig *config = RclConfig::getMainConfig();
string quirks;
if (config && config->getConfParam(keyquirks, quirks)) {
if (m_config && m_config->getConfParam(keyquirks, quirks)) {
if (quirks == "tbird") {
LOGDEB(("MimeHandlerMbox: setting quirks TBIRD\n"));
m_quirks |= MBOXQUIRK_TBIRD;
@@ -402,7 +398,7 @@ bool MimeHandlerMbox::next_document()
LOGDEB0(("MimeHandlerMbox::next_doc: mtarg %d m_udi[%s]\n",
mtarg, m_udi.c_str()));
if (!m_udi.empty() &&
(off = mcache.get_offset(m_udi, mtarg)) >= 0 &&
(off = mcache.get_offset(m_config, m_udi, mtarg)) >= 0 &&
fseeko(fp, (off_t)off, SEEK_SET) >= 0 &&
fgets(line, LL, fp) &&
(!regexec(&fromregex, line, 0, 0, 0) ||
@@ -485,7 +481,7 @@ bool MimeHandlerMbox::next_document()
LOGDEB2(("MimeHandlerMbox::next: eof hit\n"));
m_havedoc = false;
if (!m_udi.empty()) {
mcache.put_offsets(m_udi, m_fsize, m_offsets);
mcache.put_offsets(m_config, m_udi, m_fsize, m_offsets);
}
}
return msgtxt.empty() ? false : true;
@@ -521,10 +517,6 @@ Usage(void)
exit(1);
}
static RclConfig *config;
RclConfig *RclConfig::getMainConfig()
{
return config;
}
static int op_flags;
#define OPT_MOINS 0x1
#define OPT_m 0x2
+3 -2
View File
@@ -32,8 +32,9 @@ using std::vector;
*/
class MimeHandlerMbox : public RecollFilter {
public:
MimeHandlerMbox(const string& mime)
: RecollFilter(mime), m_vfp(0), m_msgnum(0), m_lineno(0), m_fsize(0)
MimeHandlerMbox(RclConfig *cnf, const string& mime)
: RecollFilter(cnf, mime), m_vfp(0), m_msgnum(0),
m_lineno(0), m_fsize(0)
{}
virtual ~MimeHandlerMbox();
virtual bool set_document_file(const string &file_path);
+2 -2
View File
@@ -59,13 +59,13 @@ bool MimeHandlerText::set_document_file(const string &fn)
// Max file size parameter: texts over this size are not indexed
int maxmbs = 20;
RclConfig::getMainConfig()->getConfParam("textfilemaxmbs", &maxmbs);
m_config->getConfParam("textfilemaxmbs", &maxmbs);
if (maxmbs == -1 || st.st_size / MB <= maxmbs) {
// Text file page size: if set, we split text files into
// multiple documents
int ps = 1000;
RclConfig::getMainConfig()->getConfParam("textfilepagekbs", &ps);
m_config->getConfParam("textfilepagekbs", &ps);
if (ps != -1) {
ps *= KB;
m_paging = true;
+2 -2
View File
@@ -31,8 +31,8 @@ using std::string;
*/
class MimeHandlerText : public RecollFilter {
public:
MimeHandlerText(const string& mt)
: RecollFilter(mt), m_paging(false), m_offs(0) {}
MimeHandlerText(RclConfig *cnf, const string& mt)
: RecollFilter(cnf, mt), m_paging(false), m_offs(0) {}
virtual ~MimeHandlerText() {}
virtual bool set_document_file(const string &file_path);
virtual bool set_document_string(const string&);
+2 -1
View File
@@ -28,7 +28,8 @@
*/
class MimeHandlerUnknown : public RecollFilter {
public:
MimeHandlerUnknown(const string& mt) : RecollFilter(mt) {}
MimeHandlerUnknown(RclConfig *cnf, const string& mt)
: RecollFilter(cnf, mt) {}
virtual ~MimeHandlerUnknown() {}
virtual bool set_document_string(const string& fn) {
RecollFilter::set_document_file(fn);
+12 -12
View File
@@ -51,33 +51,33 @@ static multimap<string, Dijon::Filter*> o_handlers;
/** For mime types set as "internal" in mimeconf:
* create appropriate handler object. */
static Dijon::Filter *mhFactory(const string &mime)
static Dijon::Filter *mhFactory(RclConfig *config, const string &mime)
{
LOGDEB2(("mhFactory(%s)\n", mime.c_str()));
string lmime(mime);
stringtolower(lmime);
if ("text/plain" == lmime) {
return new MimeHandlerText(lmime);
return new MimeHandlerText(config, lmime);
} else if ("text/html" == lmime) {
return new MimeHandlerHtml(lmime);
return new MimeHandlerHtml(config, lmime);
} else if ("text/x-mail" == lmime) {
return new MimeHandlerMbox(lmime);
return new MimeHandlerMbox(config, lmime);
} else if ("message/rfc822" == lmime) {
return new MimeHandlerMail(lmime);
return new MimeHandlerMail(config, lmime);
} else if (lmime.find("text/") == 0) {
// Try to handle unknown text/xx as text/plain. This
// only happen if the text/xx was defined as "internal" in
// mimeconf, not at random. For programs, for example this
// allows indexing and previewing as text/plain (no filter
// exec) but still opening with a specific editor.
return new MimeHandlerText(lmime);
return new MimeHandlerText(config, lmime);
} else {
// We should not get there. It means that "internal" was set
// as a handler in mimeconf for a mime type we actually can't
// handle.
LOGERR(("mhFactory: mime type [%s] set as internal but unknown\n",
lmime.c_str()));
return new MimeHandlerUnknown(lmime);
return new MimeHandlerUnknown(config, lmime);
}
}
@@ -110,8 +110,8 @@ MimeHandlerExec *mhExecFactory(RclConfig *cfg, const string& mtype, string& hs,
return 0;
}
MimeHandlerExec *h = multiple ?
new MimeHandlerExecMultiple(mtype.c_str()) :
new MimeHandlerExec(mtype.c_str());
new MimeHandlerExecMultiple(cfg, mtype.c_str()) :
new MimeHandlerExec(cfg, mtype.c_str());
list<string>::iterator it = cmdtoks.begin();
h->params.push_back(cfg->findFilter(*it++));
h->params.insert(h->params.end(), it, cmdtoks.end());
@@ -205,9 +205,9 @@ Dijon::Filter *getMimeHandler(const string &mtype, RclConfig *cfg,
// point in the future
LOGDEB2(("handlertype internal, cmdstr [%s]\n", cmdstr.c_str()));
if (!cmdstr.empty())
h = mhFactory(cmdstr);
h = mhFactory(cfg, cmdstr);
else
h = mhFactory(mtype);
h = mhFactory(cfg, mtype);
goto out;
} else if (!stringlowercmp("dll", handlertype)) {
} else {
@@ -247,7 +247,7 @@ Dijon::Filter *getMimeHandler(const string &mtype, RclConfig *cfg,
{bool indexunknown = false;
cfg->getConfParam("indexallfilenames", &indexunknown);
if (indexunknown) {
h = new MimeHandlerUnknown("application/octet-stream");
h = new MimeHandlerUnknown(cfg, "application/octet-stream");
goto out;
} else {
goto out;
+4 -2
View File
@@ -30,8 +30,9 @@ class RclConfig;
class RecollFilter : public Dijon::Filter {
public:
RecollFilter(const string& mtype)
: Dijon::Filter(mtype), m_forPreview(false), m_havedoc(false)
RecollFilter(RclConfig *config, const string& mtype)
: Dijon::Filter(mtype), m_config(config),
m_forPreview(false), m_havedoc(false)
{}
virtual ~RecollFilter() {}
virtual bool set_property(Properties p, const string &v) {
@@ -93,6 +94,7 @@ public:
}
protected:
RclConfig *m_config;
bool m_forPreview;
string m_dfltInputCharset;
string m_reason;