mimehandler: tabs change only
This commit is contained in:
parent
83e29a9b01
commit
1b59790b02
@ -68,17 +68,17 @@ static RecollFilter *getMimeHandlerFromCache(const string& key)
|
||||
|
||||
multimap<string, RecollFilter *>::iterator it = o_handlers.find(key);
|
||||
if (it != o_handlers.end()) {
|
||||
RecollFilter *h = it->second;
|
||||
hlruit_tp it1 = find(o_hlru.begin(), o_hlru.end(), it);
|
||||
if (it1 != o_hlru.end()) {
|
||||
o_hlru.erase(it1);
|
||||
} else {
|
||||
LOGERR("getMimeHandlerFromCache: lru position not found\n");
|
||||
}
|
||||
o_handlers.erase(it);
|
||||
LOGDEB("getMimeHandlerFromCache: " << xdigest << " found size " <<
|
||||
RecollFilter *h = it->second;
|
||||
hlruit_tp it1 = find(o_hlru.begin(), o_hlru.end(), it);
|
||||
if (it1 != o_hlru.end()) {
|
||||
o_hlru.erase(it1);
|
||||
} else {
|
||||
LOGERR("getMimeHandlerFromCache: lru position not found\n");
|
||||
}
|
||||
o_handlers.erase(it);
|
||||
LOGDEB("getMimeHandlerFromCache: " << xdigest << " found size " <<
|
||||
o_handlers.size() << "\n");
|
||||
return h;
|
||||
return h;
|
||||
}
|
||||
LOGDEB("getMimeHandlerFromCache: " << xdigest << " not found\n");
|
||||
return 0;
|
||||
@ -90,8 +90,8 @@ void returnMimeHandler(RecollFilter *handler)
|
||||
typedef multimap<string, RecollFilter*>::value_type value_type;
|
||||
|
||||
if (handler == 0) {
|
||||
LOGERR("returnMimeHandler: bad parameter\n");
|
||||
return;
|
||||
LOGERR("returnMimeHandler: bad parameter\n");
|
||||
return;
|
||||
}
|
||||
handler->clear();
|
||||
|
||||
@ -108,20 +108,20 @@ void returnMimeHandler(RecollFilter *handler)
|
||||
// are processing the same mime type at the same time.
|
||||
multimap<string, RecollFilter *>::iterator it;
|
||||
if (o_handlers.size() >= max_handlers_cache_size) {
|
||||
static int once = 1;
|
||||
if (once) {
|
||||
once = 0;
|
||||
for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
|
||||
LOGDEB1("Cache full. key: " << it->first << "\n");
|
||||
}
|
||||
LOGDEB1("Cache LRU size: " << o_hlru.size() << "\n");
|
||||
}
|
||||
if (o_hlru.size() > 0) {
|
||||
it = o_hlru.back();
|
||||
o_hlru.pop_back();
|
||||
delete it->second;
|
||||
o_handlers.erase(it);
|
||||
}
|
||||
static int once = 1;
|
||||
if (once) {
|
||||
once = 0;
|
||||
for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
|
||||
LOGDEB1("Cache full. key: " << it->first << "\n");
|
||||
}
|
||||
LOGDEB1("Cache LRU size: " << o_hlru.size() << "\n");
|
||||
}
|
||||
if (o_hlru.size() > 0) {
|
||||
it = o_hlru.back();
|
||||
o_hlru.pop_back();
|
||||
delete it->second;
|
||||
o_handlers.erase(it);
|
||||
}
|
||||
}
|
||||
it = o_handlers.insert(value_type(handler->get_id(), handler));
|
||||
o_hlru.push_front(it);
|
||||
@ -133,7 +133,7 @@ void clearMimeHandlerCache()
|
||||
multimap<string, RecollFilter *>::iterator it;
|
||||
std::unique_lock<std::mutex> locker(o_handlers_mutex);
|
||||
for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
|
||||
delete it->second;
|
||||
delete it->second;
|
||||
}
|
||||
o_handlers.clear();
|
||||
TempFile::tryRemoveAgain();
|
||||
@ -142,7 +142,7 @@ void clearMimeHandlerCache()
|
||||
/** For mime types set as "internal" in mimeconf:
|
||||
* create appropriate handler object. */
|
||||
static RecollFilter *mhFactory(RclConfig *config, const string &mimeOrParams,
|
||||
bool nobuild, string& id)
|
||||
bool nobuild, string& id)
|
||||
{
|
||||
LOGDEB1("mhFactory(" << mimeOrParams << ")\n");
|
||||
vector<string> lparams;
|
||||
@ -154,50 +154,50 @@ static RecollFilter *mhFactory(RclConfig *config, const string &mimeOrParams,
|
||||
string lmime(lparams[0]);
|
||||
stringtolower(lmime);
|
||||
if (cstr_textplain == lmime) {
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerText\n");
|
||||
MD5String("MimeHandlerText", id);
|
||||
return nobuild ? 0 : new MimeHandlerText(config, id);
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerText\n");
|
||||
MD5String("MimeHandlerText", id);
|
||||
return nobuild ? 0 : new MimeHandlerText(config, id);
|
||||
} else if (cstr_texthtml == lmime) {
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerHtml\n");
|
||||
MD5String("MimeHandlerHtml", id);
|
||||
return nobuild ? 0 : new MimeHandlerHtml(config, id);
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerHtml\n");
|
||||
MD5String("MimeHandlerHtml", id);
|
||||
return nobuild ? 0 : new MimeHandlerHtml(config, id);
|
||||
} else if ("text/x-mail" == lmime) {
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerMbox\n");
|
||||
MD5String("MimeHandlerMbox", id);
|
||||
return nobuild ? 0 : new MimeHandlerMbox(config, id);
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerMbox\n");
|
||||
MD5String("MimeHandlerMbox", id);
|
||||
return nobuild ? 0 : new MimeHandlerMbox(config, id);
|
||||
} else if ("message/rfc822" == lmime) {
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerMail\n");
|
||||
MD5String("MimeHandlerMail", id);
|
||||
return nobuild ? 0 : new MimeHandlerMail(config, id);
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerMail\n");
|
||||
MD5String("MimeHandlerMail", id);
|
||||
return nobuild ? 0 : new MimeHandlerMail(config, id);
|
||||
} else if ("inode/symlink" == lmime) {
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerSymlink\n");
|
||||
MD5String("MimeHandlerSymlink", id);
|
||||
return nobuild ? 0 : new MimeHandlerSymlink(config, id);
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerSymlink\n");
|
||||
MD5String("MimeHandlerSymlink", id);
|
||||
return nobuild ? 0 : new MimeHandlerSymlink(config, id);
|
||||
} else if ("application/x-zerosize" == lmime) {
|
||||
LOGDEB("mhFactory(" << lmime << "): returning MimeHandlerNull\n");
|
||||
MD5String("MimeHandlerNull", id);
|
||||
return nobuild ? 0 : new MimeHandlerNull(config, id);
|
||||
LOGDEB("mhFactory(" << lmime << "): returning MimeHandlerNull\n");
|
||||
MD5String("MimeHandlerNull", id);
|
||||
return nobuild ? 0 : new MimeHandlerNull(config, id);
|
||||
} 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.
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerText(x)\n");
|
||||
MD5String("MimeHandlerText", id);
|
||||
LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerText(x)\n");
|
||||
MD5String("MimeHandlerText", id);
|
||||
return nobuild ? 0 : new MimeHandlerText(config, id);
|
||||
} else if ("xsltproc" == lmime) {
|
||||
// XML Types processed with one or several xslt style sheets.
|
||||
MD5String(mimeOrParams, id);
|
||||
return nobuild ? 0 : new MimeHandlerXslt(config, id, lparams);
|
||||
} 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 [" << lmime <<
|
||||
// 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 [" << lmime <<
|
||||
"] set as internal but unknown\n");
|
||||
MD5String("MimeHandlerUnknown", id);
|
||||
return nobuild ? 0 : new MimeHandlerUnknown(config, id);
|
||||
MD5String("MimeHandlerUnknown", id);
|
||||
return nobuild ? 0 : new MimeHandlerUnknown(config, id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ MimeHandlerExec *mhExecFactory(RclConfig *cfg, const string& mtype, string& hs,
|
||||
string cmdstr;
|
||||
|
||||
if (!cfg->valueSplitAttributes(hs, cmdstr, attrs)) {
|
||||
LOGERR("mhExecFactory: bad config line for [" <<
|
||||
LOGERR("mhExecFactory: bad config line for [" <<
|
||||
mtype << "]: [" << hs << "]\n");
|
||||
return 0;
|
||||
}
|
||||
@ -227,12 +227,12 @@ MimeHandlerExec *mhExecFactory(RclConfig *cfg, const string& mtype, string& hs,
|
||||
vector<string> cmdtoks;
|
||||
stringToStrings(cmdstr, cmdtoks);
|
||||
if (cmdtoks.empty()) {
|
||||
LOGERR("mhExecFactory: bad config line for [" << mtype <<
|
||||
LOGERR("mhExecFactory: bad config line for [" << mtype <<
|
||||
"]: [" << hs << "]\n");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
MimeHandlerExec *h = multiple ?
|
||||
new MimeHandlerExecMultiple(cfg, id) :
|
||||
new MimeHandlerExecMultiple(cfg, id) :
|
||||
new MimeHandlerExec(cfg, id);
|
||||
vector<string>::iterator it = cmdtoks.begin();
|
||||
|
||||
@ -264,7 +264,7 @@ MimeHandlerExec *mhExecFactory(RclConfig *cfg, const string& mtype, string& hs,
|
||||
#if 0
|
||||
string scmd;
|
||||
for (it = h->params.begin(); it != h->params.end(); it++) {
|
||||
scmd += string("[") + *it + "] ";
|
||||
scmd += string("[") + *it + "] ";
|
||||
}
|
||||
LOGDEB("mhExecFactory:mt [" << mtype << "] cfgmt [" <<
|
||||
h->cfgFilterOutputMtype << "] cfgcs [" <<
|
||||
@ -293,83 +293,83 @@ RecollFilter *getMimeHandler(const string &mtype, RclConfig *cfg,
|
||||
string id;
|
||||
|
||||
if (!hs.empty()) {
|
||||
// Got a handler definition line
|
||||
// Break definition into type (internal/exec/execm)
|
||||
// and name/command string
|
||||
// Got a handler definition line
|
||||
// Break definition into type (internal/exec/execm)
|
||||
// and name/command string
|
||||
string::size_type b1 = hs.find_first_of(" \t");
|
||||
string handlertype = hs.substr(0, b1);
|
||||
string cmdstr;
|
||||
if (b1 != string::npos) {
|
||||
cmdstr = hs.substr(b1);
|
||||
string cmdstr;
|
||||
if (b1 != string::npos) {
|
||||
cmdstr = hs.substr(b1);
|
||||
trimstring(cmdstr);
|
||||
}
|
||||
bool internal = !stringlowercmp("internal", handlertype);
|
||||
if (internal) {
|
||||
// For internal types let the factory compute the cache id
|
||||
mhFactory(cfg, cmdstr.empty() ? mtype : cmdstr, true, id);
|
||||
} else {
|
||||
// exec/execm: use the md5 of the def line
|
||||
MD5String(hs, id);
|
||||
}
|
||||
}
|
||||
bool internal = !stringlowercmp("internal", handlertype);
|
||||
if (internal) {
|
||||
// For internal types let the factory compute the cache id
|
||||
mhFactory(cfg, cmdstr.empty() ? mtype : cmdstr, true, id);
|
||||
} else {
|
||||
// exec/execm: use the md5 of the def line
|
||||
MD5String(hs, id);
|
||||
}
|
||||
|
||||
// Do we already have a handler object in the cache ?
|
||||
h = getMimeHandlerFromCache(id);
|
||||
if (h != 0)
|
||||
goto out;
|
||||
h = getMimeHandlerFromCache(id);
|
||||
if (h != 0)
|
||||
goto out;
|
||||
|
||||
LOGDEB2("getMimeHandler: " << mtype << " not in cache\n");
|
||||
if (internal) {
|
||||
// If there is a parameter after "internal" it's the mime
|
||||
// type to use, or the further qualifier (e.g. style sheet
|
||||
// name for xslt types). This is so that we can have bogus
|
||||
// mime types like text/x-purple-html-log (for ie:
|
||||
// specific icon) and still use the html filter on
|
||||
// them. This is partly redundant with the
|
||||
// localfields/rclaptg, but better? (and the latter will
|
||||
// probably go away at some point in the future?).
|
||||
LOGDEB2("handlertype internal, cmdstr [" << cmdstr << "]\n");
|
||||
h = mhFactory(cfg, cmdstr.empty() ? mtype : cmdstr, false, id);
|
||||
goto out;
|
||||
} else if (!stringlowercmp("dll", handlertype)) {
|
||||
} else {
|
||||
LOGDEB2("getMimeHandler: " << mtype << " not in cache\n");
|
||||
if (internal) {
|
||||
// If there is a parameter after "internal" it's the mime
|
||||
// type to use, or the further qualifier (e.g. style sheet
|
||||
// name for xslt types). This is so that we can have bogus
|
||||
// mime types like text/x-purple-html-log (for ie:
|
||||
// specific icon) and still use the html filter on
|
||||
// them. This is partly redundant with the
|
||||
// localfields/rclaptg, but better? (and the latter will
|
||||
// probably go away at some point in the future?).
|
||||
LOGDEB2("handlertype internal, cmdstr [" << cmdstr << "]\n");
|
||||
h = mhFactory(cfg, cmdstr.empty() ? mtype : cmdstr, false, id);
|
||||
goto out;
|
||||
} else if (!stringlowercmp("dll", handlertype)) {
|
||||
} else {
|
||||
if (cmdstr.empty()) {
|
||||
LOGERR("getMimeHandler: bad line for " << mtype << ": " <<
|
||||
LOGERR("getMimeHandler: bad line for " << mtype << ": " <<
|
||||
hs << "\n");
|
||||
goto out;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
if (!stringlowercmp("exec", handlertype)) {
|
||||
h = mhExecFactory(cfg, mtype, cmdstr, false, id);
|
||||
goto out;
|
||||
goto out;
|
||||
} else if (!stringlowercmp("execm", handlertype)) {
|
||||
h = mhExecFactory(cfg, mtype, cmdstr, true, id);
|
||||
goto out;
|
||||
goto out;
|
||||
} else {
|
||||
LOGERR("getMimeHandler: bad line for " << mtype << ": " <<
|
||||
LOGERR("getMimeHandler: bad line for " << mtype << ": " <<
|
||||
hs << "\n");
|
||||
goto out;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No identified mime type, or no handler associated.
|
||||
// Unhandled files are either ignored or their name and
|
||||
// generic metadata is indexed, depending on configuration
|
||||
bool indexunknown = false;
|
||||
cfg->getConfParam("indexallfilenames", &indexunknown);
|
||||
if (indexunknown) {
|
||||
MD5String("MimeHandlerUnknown", id);
|
||||
if ((h = getMimeHandlerFromCache(id)) == 0)
|
||||
h = new MimeHandlerUnknown(cfg, id);
|
||||
}
|
||||
goto out;
|
||||
bool indexunknown = false;
|
||||
cfg->getConfParam("indexallfilenames", &indexunknown);
|
||||
if (indexunknown) {
|
||||
MD5String("MimeHandlerUnknown", id);
|
||||
if ((h = getMimeHandlerFromCache(id)) == 0)
|
||||
h = new MimeHandlerUnknown(cfg, id);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
if (h) {
|
||||
h->set_property(RecollFilter::DEFAULT_CHARSET, cfg->getDefCharset());
|
||||
// In multithread context, and in case this handler is out
|
||||
// from the cache, it may have a config pointer belonging to
|
||||
// another thread. Fix it.
|
||||
h->setConfig(cfg);
|
||||
h->set_property(RecollFilter::DEFAULT_CHARSET, cfg->getDefCharset());
|
||||
// In multithread context, and in case this handler is out
|
||||
// from the cache, it may have a config pointer belonging to
|
||||
// another thread. Fix it.
|
||||
h->setConfig(cfg);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
@ -378,10 +378,10 @@ out:
|
||||
bool canIntern(const std::string mtype, RclConfig *cfg)
|
||||
{
|
||||
if (mtype.empty())
|
||||
return false;
|
||||
return false;
|
||||
string hs = cfg->getMimeHandlerDef(mtype);
|
||||
if (hs.empty())
|
||||
return false;
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
/// Same, getting MIME from doc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user