|
a/src/internfile/mimehandler.cpp |
|
b/src/internfile/mimehandler.cpp |
|
... |
|
... |
21 |
#include <errno.h>
|
21 |
#include <errno.h>
|
22 |
#include <iostream>
|
22 |
#include <iostream>
|
23 |
#include <string>
|
23 |
#include <string>
|
24 |
#include <vector>
|
24 |
#include <vector>
|
25 |
#include <list>
|
25 |
#include <list>
|
|
|
26 |
#include <mutex>
|
26 |
using namespace std;
|
27 |
using namespace std;
|
27 |
|
28 |
|
28 |
#include "cstr.h"
|
29 |
#include "cstr.h"
|
29 |
#include "mimehandler.h"
|
30 |
#include "mimehandler.h"
|
30 |
#include "log.h"
|
31 |
#include "log.h"
|
|
... |
|
... |
38 |
#include "mh_mbox.h"
|
39 |
#include "mh_mbox.h"
|
39 |
#include "mh_text.h"
|
40 |
#include "mh_text.h"
|
40 |
#include "mh_symlink.h"
|
41 |
#include "mh_symlink.h"
|
41 |
#include "mh_unknown.h"
|
42 |
#include "mh_unknown.h"
|
42 |
#include "mh_null.h"
|
43 |
#include "mh_null.h"
|
43 |
#include "ptmutex.h"
|
|
|
44 |
|
44 |
|
45 |
// Performance help: we use a pool of already known and created
|
45 |
// Performance help: we use a pool of already known and created
|
46 |
// handlers. There can be several instances for a given mime type
|
46 |
// handlers. There can be several instances for a given mime type
|
47 |
// (think email attachment in email message: 2 rfc822 handlers are
|
47 |
// (think email attachment in email message: 2 rfc822 handlers are
|
48 |
// needed simulteanously)
|
48 |
// needed simulteanously)
|
49 |
static multimap<string, RecollFilter*> o_handlers;
|
49 |
static multimap<string, RecollFilter*> o_handlers;
|
50 |
static list<multimap<string, RecollFilter*>::iterator> o_hlru;
|
50 |
static list<multimap<string, RecollFilter*>::iterator> o_hlru;
|
51 |
typedef list<multimap<string, RecollFilter*>::iterator>::iterator hlruit_tp;
|
51 |
typedef list<multimap<string, RecollFilter*>::iterator>::iterator hlruit_tp;
|
52 |
|
52 |
|
53 |
static PTMutexInit o_handlers_mutex;
|
53 |
static std::mutex o_handlers_mutex;
|
54 |
|
54 |
|
55 |
static const unsigned int max_handlers_cache_size = 100;
|
55 |
static const unsigned int max_handlers_cache_size = 100;
|
56 |
|
56 |
|
57 |
/* Look for mime handler in pool */
|
57 |
/* Look for mime handler in pool */
|
58 |
static RecollFilter *getMimeHandlerFromCache(const string& key)
|
58 |
static RecollFilter *getMimeHandlerFromCache(const string& key)
|
59 |
{
|
59 |
{
|
60 |
PTMutexLocker locker(o_handlers_mutex);
|
60 |
std::unique_lock<std::mutex> locker(o_handlers_mutex);
|
61 |
string xdigest;
|
61 |
string xdigest;
|
62 |
MD5HexPrint(key, xdigest);
|
62 |
MD5HexPrint(key, xdigest);
|
63 |
LOGDEB("getMimeHandlerFromCache: " << (xdigest) << " cache size " << (o_handlers.size()) << "\n" );
|
63 |
LOGDEB("getMimeHandlerFromCache: " << (xdigest) << " cache size " << (o_handlers.size()) << "\n" );
|
64 |
|
64 |
|
65 |
multimap<string, RecollFilter *>::iterator it = o_handlers.find(key);
|
65 |
multimap<string, RecollFilter *>::iterator it = o_handlers.find(key);
|
|
... |
|
... |
88 |
LOGERR("returnMimeHandler: bad parameter\n" );
|
88 |
LOGERR("returnMimeHandler: bad parameter\n" );
|
89 |
return;
|
89 |
return;
|
90 |
}
|
90 |
}
|
91 |
handler->clear();
|
91 |
handler->clear();
|
92 |
|
92 |
|
93 |
PTMutexLocker locker(o_handlers_mutex);
|
93 |
std::unique_lock<std::mutex> locker(o_handlers_mutex);
|
94 |
|
94 |
|
95 |
LOGDEB("returnMimeHandler: returning filter for " << (handler->get_mime_type()) << " cache size " << (o_handlers.size()) << "\n" );
|
95 |
LOGDEB("returnMimeHandler: returning filter for " << (handler->get_mime_type()) << " cache size " << (o_handlers.size()) << "\n" );
|
96 |
|
96 |
|
97 |
// Limit pool size. The pool can grow quite big because there are
|
97 |
// Limit pool size. The pool can grow quite big because there are
|
98 |
// many filter types, each of which can be used in several copies
|
98 |
// many filter types, each of which can be used in several copies
|
|
... |
|
... |
122 |
|
122 |
|
123 |
void clearMimeHandlerCache()
|
123 |
void clearMimeHandlerCache()
|
124 |
{
|
124 |
{
|
125 |
LOGDEB("clearMimeHandlerCache()\n" );
|
125 |
LOGDEB("clearMimeHandlerCache()\n" );
|
126 |
multimap<string, RecollFilter *>::iterator it;
|
126 |
multimap<string, RecollFilter *>::iterator it;
|
127 |
PTMutexLocker locker(o_handlers_mutex);
|
127 |
std::unique_lock<std::mutex> locker(o_handlers_mutex);
|
128 |
for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
|
128 |
for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
|
129 |
delete it->second;
|
129 |
delete it->second;
|
130 |
}
|
130 |
}
|
131 |
o_handlers.clear();
|
131 |
o_handlers.clear();
|
132 |
}
|
132 |
}
|