Switch to unified view

a/src/internfile/mimehandler.cpp b/src/internfile/mimehandler.cpp
...
...
39
#include "mh_mbox.h"
39
#include "mh_mbox.h"
40
#include "mh_text.h"
40
#include "mh_text.h"
41
#include "mh_symlink.h"
41
#include "mh_symlink.h"
42
#include "mh_unknown.h"
42
#include "mh_unknown.h"
43
#include "mh_null.h"
43
#include "mh_null.h"
44
#include "mh_xslt.h"
44
45
45
// Performance help: we use a pool of already known and created
46
// Performance help: we use a pool of already known and created
46
// handlers. There can be several instances for a given mime type
47
// handlers. There can be several instances for a given mime type
47
// (think email attachment in email message: 2 rfc822 handlers are
48
// (think email attachment in email message: 2 rfc822 handlers are
48
// needed simulteanously)
49
// needed simulteanously)
...
...
135
    o_handlers.clear();
136
    o_handlers.clear();
136
}
137
}
137
138
138
/** For mime types set as "internal" in mimeconf: 
139
/** For mime types set as "internal" in mimeconf: 
139
  * create appropriate handler object. */
140
  * create appropriate handler object. */
140
static RecollFilter *mhFactory(RclConfig *config, const string &mime,
141
static RecollFilter *mhFactory(RclConfig *config, const string &mimeOrParams,
141
                bool nobuild, string& id)
142
                bool nobuild, string& id)
142
{
143
{
143
    LOGDEB2("mhFactory(" << mime << ")\n");
144
    LOGDEB1("mhFactory(" << mimeOrParams << ")\n");
145
    vector<string> lparams;
146
    stringToStrings(mimeOrParams, lparams);
147
    if (lparams.empty()) {
148
        // ??
149
        return nullptr;
150
    }
144
    string lmime(mime);
151
    string lmime(lparams[0]);
145
    stringtolower(lmime);
152
    stringtolower(lmime);
146
    if (cstr_textplain == lmime) {
153
    if (cstr_textplain == lmime) {
147
    LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerText\n");
154
    LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerText\n");
148
    MD5String("MimeHandlerText", id);
155
    MD5String("MimeHandlerText", id);
149
    return nobuild ? 0 : new MimeHandlerText(config, id);
156
    return nobuild ? 0 : new MimeHandlerText(config, id);
...
...
158
    } else if ("message/rfc822" == lmime) {
165
    } else if ("message/rfc822" == lmime) {
159
    LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerMail\n");
166
    LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerMail\n");
160
    MD5String("MimeHandlerMail", id);
167
    MD5String("MimeHandlerMail", id);
161
    return nobuild ? 0 : new MimeHandlerMail(config, id);
168
    return nobuild ? 0 : new MimeHandlerMail(config, id);
162
    } else if ("inode/symlink" == lmime) {
169
    } else if ("inode/symlink" == lmime) {
163
    LOGDEB2("mhFactory(" << mime << "): ret MimeHandlerSymlink\n");
170
    LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerSymlink\n");
164
    MD5String("MimeHandlerSymlink", id);
171
    MD5String("MimeHandlerSymlink", id);
165
    return nobuild ? 0 : new MimeHandlerSymlink(config, id);
172
    return nobuild ? 0 : new MimeHandlerSymlink(config, id);
166
    } else if ("application/x-zerosize" == lmime) {
173
    } else if ("application/x-zerosize" == lmime) {
167
    LOGDEB("mhFactory(" << mime << "): ret MimeHandlerNull\n");
174
    LOGDEB("mhFactory(" << lmime << "): returning MimeHandlerNull\n");
168
    MD5String("MimeHandlerNull", id);
175
    MD5String("MimeHandlerNull", id);
169
    return nobuild ? 0 : new MimeHandlerNull(config, id);
176
    return nobuild ? 0 : new MimeHandlerNull(config, id);
170
    } else if (lmime.find("text/") == 0) {
177
    } else if (lmime.find("text/") == 0) {
171
        // Try to handle unknown text/xx as text/plain. This
178
        // Try to handle unknown text/xx as text/plain. This
172
        // only happen if the text/xx was defined as "internal" in
179
        // only happen if the text/xx was defined as "internal" in
173
        // mimeconf, not at random. For programs, for example this
180
        // mimeconf, not at random. For programs, for example this
174
        // allows indexing and previewing as text/plain (no filter
181
        // allows indexing and previewing as text/plain (no filter
175
        // exec) but still opening with a specific editor.
182
        // exec) but still opening with a specific editor.
176
    LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerText(x)\n");
183
    LOGDEB2("mhFactory(" << mime << "): returning MimeHandlerText(x)\n");
177
    MD5String("MimeHandlerText", id);
184
    MD5String("MimeHandlerText", id);
178
        return nobuild ? 0 : new MimeHandlerText(config, id); 
185
        return nobuild ? 0 : new MimeHandlerText(config, id);
186
    } else if ("xsltproc" == lmime) {
187
        // XML Types processed with one or several xslt style sheets.
188
        MD5String(mimeOrParams, id);
189
        return nobuild ? 0 : new MimeHandlerXslt(config, id, lparams);
179
    } else {
190
    } else {
180
    // We should not get there. It means that "internal" was set
191
    // We should not get there. It means that "internal" was set
181
    // as a handler in mimeconf for a mime type we actually can't
192
    // as a handler in mimeconf for a mime type we actually can't
182
    // handle.
193
    // handle.
183
    LOGERR("mhFactory: mime type [" << lmime <<
194
    LOGERR("mhFactory: mime type [" << lmime <<
...
...
260
    return h;
271
    return h;
261
}
272
}
262
273
263
/* Get handler/filter object for given mime type: */
274
/* Get handler/filter object for given mime type: */
264
RecollFilter *getMimeHandler(const string &mtype, RclConfig *cfg, 
275
RecollFilter *getMimeHandler(const string &mtype, RclConfig *cfg, 
265
                bool filtertypes)
276
                             bool filtertypes)
266
{
277
{
267
    LOGDEB("getMimeHandler: mtype [" << mtype << "] filtertypes " <<
278
    LOGDEB("getMimeHandler: mtype [" << mtype << "] filtertypes " <<
268
           filtertypes << "\n");
279
           filtertypes << "\n");
269
    RecollFilter *h = 0;
280
    RecollFilter *h = 0;
270
281
...
...
289
        cmdstr = hs.substr(b1);
300
        cmdstr = hs.substr(b1);
290
            trimstring(cmdstr);
301
            trimstring(cmdstr);
291
    }
302
    }
292
    bool internal = !stringlowercmp("internal", handlertype);
303
    bool internal = !stringlowercmp("internal", handlertype);
293
    if (internal) {
304
    if (internal) {
294
        // For internal types let the factory compute the id
305
        // For internal types let the factory compute the cache id
295
        mhFactory(cfg, cmdstr.empty() ? mtype : cmdstr, true, id);
306
        mhFactory(cfg, cmdstr.empty() ? mtype : cmdstr, true, id);
296
    } else {
307
    } else {
297
        // exec/execm: use the md5 of the def line
308
        // exec/execm: use the md5 of the def line
298
        MD5String(hs, id);
309
        MD5String(hs, id);
299
    }
310
    }
...
...
302
    h = getMimeHandlerFromCache(id);
313
    h = getMimeHandlerFromCache(id);
303
    if (h != 0)
314
    if (h != 0)
304
        goto out;
315
        goto out;
305
316
306
    LOGDEB2("getMimeHandler: " << mtype << " not in cache\n");
317
    LOGDEB2("getMimeHandler: " << mtype << " not in cache\n");
307
308
  // Not in cache. 
309
    if (internal) {
318
    if (internal) {
310
        // If there is a parameter after "internal" it's the mime
319
        // If there is a parameter after "internal" it's the mime
320
      // type to use, or the further qualifier (e.g. style sheet
311
        // type to use. This is so that we can have bogus mime
321
        // name for xslt types). This is so that we can have bogus
312
        // types like text/x-purple-html-log (for ie: specific
322
        // mime types like text/x-purple-html-log (for ie:
313
        // icon) and still use the html filter on them. This is
323
        // specific icon) and still use the html filter on
314
      // partly redundant with the localfields/rclaptg, but
324
      // them. This is partly redundant with the
315
      // better and the latter will probably go away at some
325
      // localfields/rclaptg, but better? (and the latter will
316
      // point in the future.
326
      // probably go away at some point in the future?).
317
        LOGDEB2("handlertype internal, cmdstr [" << cmdstr << "]\n");
327
        LOGDEB2("handlertype internal, cmdstr [" << cmdstr << "]\n");
318
        h = mhFactory(cfg, cmdstr.empty() ? mtype : cmdstr, false, id);
328
        h = mhFactory(cfg, cmdstr.empty() ? mtype : cmdstr, false, id);
319
        goto out;
329
        goto out;
320
    } else if (!stringlowercmp("dll", handlertype)) {
330
    } else if (!stringlowercmp("dll", handlertype)) {
321
    } else {
331
    } else {
...
...
334
        LOGERR("getMimeHandler: bad line for " << mtype << ": " <<
344
        LOGERR("getMimeHandler: bad line for " << mtype << ": " <<
335
                       hs << "\n");
345
                       hs << "\n");
336
        goto out;
346
        goto out;
337
            }
347
            }
338
    }
348
    }
339
    }
349
    } else {
340
341
    // We get here if there was no specific error, but there is no
342
    // identified mime type, or no handler associated.
350
        // No identified mime type, or no handler associated.
343
344
    // Finally, unhandled files are either ignored or their name and
351
        // Unhandled files are either ignored or their name and
345
    // generic metadata is indexed, depending on configuration
352
        // generic metadata is indexed, depending on configuration
346
    {
347
    bool indexunknown = false;
353
    bool indexunknown = false;
348
    cfg->getConfParam("indexallfilenames", &indexunknown);
354
    cfg->getConfParam("indexallfilenames", &indexunknown);
349
    if (indexunknown) {
355
    if (indexunknown) {
350
        MD5String("MimeHandlerUnknown", id);
356
        MD5String("MimeHandlerUnknown", id);
351
        if ((h = getMimeHandlerFromCache(id)) == 0)
357
        if ((h = getMimeHandlerFromCache(id)) == 0)