Switch to unified view

a/src/internfile/mimehandler.cpp b/src/internfile/mimehandler.cpp
...
...
26
26
27
#include "mimehandler.h"
27
#include "mimehandler.h"
28
#include "debuglog.h"
28
#include "debuglog.h"
29
#include "rclconfig.h"
29
#include "rclconfig.h"
30
#include "smallut.h"
30
#include "smallut.h"
31
#include "pthread.h"
32
31
33
#include "mh_exec.h"
32
#include "mh_exec.h"
34
#include "mh_execm.h"
33
#include "mh_execm.h"
35
#include "mh_html.h"
34
#include "mh_html.h"
36
#include "mh_mail.h"
35
#include "mh_mail.h"
37
#include "mh_mbox.h"
36
#include "mh_mbox.h"
38
#include "mh_text.h"
37
#include "mh_text.h"
39
#include "mh_unknown.h"
38
#include "mh_unknown.h"
39
#include "ptmutex.h"
40
40
41
// Performance help: we use a pool of already known and created
41
// Performance help: we use a pool of already known and created
42
// handlers. There can be several instances for a given mime type
42
// handlers. There can be several instances for a given mime type
43
// (think email attachment in email message: 2 rfc822 handlers are
43
// (think email attachment in email message: 2 rfc822 handlers are
44
// needed simulteanously)
44
// needed simulteanously)
...
...
46
// FIXME: this is not compatible with multiple threads and a potential
46
// FIXME: this is not compatible with multiple threads and a potential
47
// problem in the recoll gui (indexing thread + preview request). A
47
// problem in the recoll gui (indexing thread + preview request). A
48
// simple lock should be enough as handlers are removed from the cache
48
// simple lock should be enough as handlers are removed from the cache
49
// while in use and multiple copies are allowed
49
// while in use and multiple copies are allowed
50
static multimap<string, Dijon::Filter*>  o_handlers;
50
static multimap<string, Dijon::Filter*>  o_handlers;
51
pthread_mutex_t o_handlers_mutex;
51
static PTMutexInit o_handlers_mutex;
52
class HandlersLocker {
53
public:
54
    HandlersLocker()
55
    {
56
  pthread_mutex_lock(&o_handlers_mutex);
57
    }
58
    ~HandlersLocker()
59
    {
60
  pthread_mutex_unlock(&o_handlers_mutex);
61
    }
62
};
63
class HandlersLockerInit {
64
public:
65
    HandlersLockerInit() 
66
    {
67
  pthread_mutex_init(&o_handlers_mutex, 0);
68
    }
69
};
70
static HandlersLockerInit o_hli;
71
52
72
/** For mime types set as "internal" in mimeconf: 
53
/** For mime types set as "internal" in mimeconf: 
73
  * create appropriate handler object. */
54
  * create appropriate handler object. */
74
static Dijon::Filter *mhFactory(RclConfig *config, const string &mime)
55
static Dijon::Filter *mhFactory(RclConfig *config, const string &mime)
75
{
56
{
...
...
161
void returnMimeHandler(Dijon::Filter *handler)
142
void returnMimeHandler(Dijon::Filter *handler)
162
{
143
{
163
    typedef multimap<string, Dijon::Filter*>::value_type value_type;
144
    typedef multimap<string, Dijon::Filter*>::value_type value_type;
164
    if (handler) {
145
    if (handler) {
165
    handler->clear();
146
    handler->clear();
166
  HandlersLocker locker;
147
  PTMutexLocker locker(o_handlers_mutex);
167
    o_handlers.insert(value_type(handler->get_mime_type(), handler));
148
    o_handlers.insert(value_type(handler->get_mime_type(), handler));
168
    }
149
    }
169
}
150
}
170
151
171
void clearMimeHandlerCache()
152
void clearMimeHandlerCache()
172
{
153
{
173
    typedef multimap<string, Dijon::Filter*>::value_type value_type;
154
    typedef multimap<string, Dijon::Filter*>::value_type value_type;
174
    map<string, Dijon::Filter *>::iterator it;
155
    map<string, Dijon::Filter *>::iterator it;
175
    HandlersLocker locker;
156
    PTMutexLocker locker(o_handlers_mutex);
176
    for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
157
    for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
177
    delete it->second;
158
    delete it->second;
178
    }
159
    }
179
    o_handlers.clear();
160
    o_handlers.clear();
180
}
161
}
...
...
185
                  bool filtertypes)
166
                  bool filtertypes)
186
{
167
{
187
    LOGDEB2(("getMimeHandler: mtype [%s] filtertypes %d\n", 
168
    LOGDEB2(("getMimeHandler: mtype [%s] filtertypes %d\n", 
188
             mtype.c_str(), filtertypes));
169
             mtype.c_str(), filtertypes));
189
    Dijon::Filter *h = 0;
170
    Dijon::Filter *h = 0;
190
    HandlersLocker locker;
171
    PTMutexLocker locker(o_handlers_mutex);
191
172
192
    // Get handler definition for mime type. We do this even if an
173
    // Get handler definition for mime type. We do this even if an
193
    // appropriate handler object may be in the cache (indexed by mime
174
    // appropriate handler object may be in the cache (indexed by mime
194
    // type). This is fast, and necessary to conform to the
175
    // type). This is fast, and necessary to conform to the
195
    // configuration, (ie: text/html might be filtered out by
176
    // configuration, (ie: text/html might be filtered out by