Switch to unified view

a/src/internfile/mimehandler.h b/src/internfile/mimehandler.h
...
...
19
#include "autoconfig.h"
19
#include "autoconfig.h"
20
20
21
#include <stdio.h>
21
#include <stdio.h>
22
22
23
#include <string>
23
#include <string>
24
#include <list>
25
using std::string;
26
using std::list;
27
24
28
#include <Filter.h>
25
#include "Filter.h"
26
#include "cstr.h"
29
27
30
class RclConfig;
28
class RclConfig;
31
29
32
class RecollFilter : public Dijon::Filter {
30
class RecollFilter : public Dijon::Filter {
33
public:
31
public:
34
    RecollFilter(RclConfig *config, const string& mtype)
32
    RecollFilter(RclConfig *config, const std::string& id)
35
  : Dijon::Filter(mtype), m_config(config), 
33
  : m_config(config), m_forPreview(false), m_havedoc(false), m_id(id)
36
    m_forPreview(false), m_havedoc(false)
37
    {}
34
    {}
38
    virtual ~RecollFilter() {}
35
    virtual ~RecollFilter() {}
39
    virtual void setConfig(RclConfig *config)
36
    virtual void setConfig(RclConfig *config)
40
    {
37
    {
41
    m_config = config;
38
    m_config = config;
42
    }
39
    }
43
    virtual bool set_property(Properties p, const string &v) {
40
    virtual bool set_property(Properties p, const std::string &v) {
44
    switch (p) {
41
    switch (p) {
45
    case DJF_UDI: 
42
    case DJF_UDI: 
46
        m_udi = v;
43
        m_udi = v;
47
        break;
44
        break;
48
    case DEFAULT_CHARSET: 
45
    case DEFAULT_CHARSET: 
...
...
57
    }
54
    }
58
    return true;
55
    return true;
59
    }
56
    }
60
57
61
    // We don't use this for now
58
    // We don't use this for now
62
    virtual bool set_document_uri(const std::string &) {return false;}
59
    virtual bool set_document_uri(const std::string& mtype, 
60
                const std::string &) 
61
    {
62
  m_mimeType = mtype;
63
  return false;
64
    }
63
65
64
    // This does nothing right now but should be called from the
66
    // This does nothing right now but should be called from the
65
    // subclass method in case we need some common processing one day
67
    // subclass method in case we need some common processing one day
66
    // (was used for xattrs at some point).  Yes this is the "call
68
    // (was used for xattrs at some point).  Yes this is the "call
67
    // super" anti-pattern, bad, but we have several layers of derived
69
    // super" anti-pattern, bad, but we have several layers of derived
68
    // classes, so that implementing the template method approach (by
70
    // classes, so that implementing the template method approach (by
69
    // having a pure virtual called from here and implemented in the
71
    // having a pure virtual called from here and implemented in the
70
    // subclass) would have to be repeated in each derived class. It's
72
    // subclass) would have to be repeated in each derived class. It's
71
    // just simpler this way.
73
    // just simpler this way.
72
    virtual bool set_document_file(const string & /*file_path*/) {return true;}
74
    virtual bool set_document_file(const std::string& mtype, 
75
                 const std::string & /*file_path*/) 
76
    {
77
  m_mimeType = mtype;
78
  return true;
79
    }
73
80
74
    // Default implementations
81
    // Default implementations
75
    virtual bool set_document_string(const std::string &) {return false;}
82
    virtual bool set_document_string(const std::string& mtype, 
76
    virtual bool set_document_data(const char *cp, unsigned int sz) {
83
                   const std::string &) 
84
    {
85
  m_mimeType = mtype;
86
  return false;
87
    }
88
    virtual bool set_document_data(const std::string& mtype, 
89
                 const char *cp, unsigned int sz) 
90
    {
77
    return set_document_string(string(cp, sz));
91
    return set_document_string(mtype, std::string(cp, sz));
78
    }
92
    }
79
93
80
    virtual void set_docsize(size_t size)
94
    virtual void set_docsize(size_t size)
81
    {
95
    {
82
    char csize[30];
96
    char csize[30];
...
...
85
    }
99
    }
86
100
87
    virtual bool has_documents() const {return m_havedoc;}
101
    virtual bool has_documents() const {return m_havedoc;}
88
102
89
    // Most doc types are single-doc
103
    // Most doc types are single-doc
90
    virtual bool skip_to_document(const string& s) {
104
    virtual bool skip_to_document(const std::string& s) {
91
    if (s.empty())
105
    if (s.empty())
92
        return true;
106
        return true;
93
    return false;
107
    return false;
94
    }
108
    }
95
109
...
...
97
    if (input == DOCUMENT_FILE_NAME)
111
    if (input == DOCUMENT_FILE_NAME)
98
        return true;
112
        return true;
99
    return false;
113
    return false;
100
    }
114
    }
101
115
102
    virtual string get_error() const {
116
    virtual std::string get_error() const {
103
    return m_reason;
117
    return m_reason;
118
    }
119
120
    virtual const std::string& get_id() const
121
    {
122
  return m_id;
104
    }
123
    }
105
124
106
    // "Call super" anti-pattern again. Must be called from derived
125
    // "Call super" anti-pattern again. Must be called from derived
107
    // classes which reimplement clear()
126
    // classes which reimplement clear()
108
    virtual void clear() {
127
    virtual void clear() {
...
...
112
    m_reason.clear();
131
    m_reason.clear();
113
    }
132
    }
114
133
115
    // This only makes sense if the contents are currently txt/plain
134
    // This only makes sense if the contents are currently txt/plain
116
    // It converts from keyorigcharset to UTF-8 and sets keycharset.
135
    // It converts from keyorigcharset to UTF-8 and sets keycharset.
117
    bool txtdcode(const string& who);
136
    bool txtdcode(const std::string& who);
118
137
119
protected:
138
protected:
120
    bool preview() {return m_forPreview;}
139
    bool preview() {return m_forPreview;}
121
140
122
    RclConfig *m_config;
141
    RclConfig *m_config;
123
    bool   m_forPreview;
142
    bool   m_forPreview;
124
    string m_dfltInputCharset;
143
    std::string m_dfltInputCharset;
125
    string m_reason;
144
    std::string m_reason;
126
    bool   m_havedoc;
145
    bool   m_havedoc;
127
    string m_udi; // May be set by creator as a hint
146
    std::string m_udi; // May be set by creator as a hint
147
    // m_id is and md5 of the filter definition line (from mimeconf) and
148
    // is used when fetching/returning filters to / from the cache.
149
    std::string m_id;
128
};
150
};
129
151
130
/**
152
/**
131
 * Return indexing handler object for the given mime type. The returned 
153
 * Return indexing handler object for the given mime type. The returned 
132
 * pointer should be passed to returnMimeHandler() for recycling, after use.
154
 * pointer should be passed to returnMimeHandler() for recycling, after use.
133
 * @param mtyp input mime type, ie text/plain
155
 * @param mtyp input mime type, ie text/plain
134
 * @param cfg  the recoll config object to be used
156
 * @param cfg  the recoll config object to be used
135
 * @param filtertypes decide if we should restrict to types in 
157
 * @param filtertypes decide if we should restrict to types in 
136
 *     indexedmimetypes (if this is set at all).
158
 *     indexedmimetypes (if this is set at all).
137
 */
159
 */
138
extern Dijon::Filter *getMimeHandler(const std::string &mtyp, RclConfig *cfg,
160
extern RecollFilter *getMimeHandler(const std::string &mtyp, RclConfig *cfg,
139
                     bool filtertypes=false);
161
                     bool filtertypes=false);
140
162
141
/// Free up filter for reuse (you can also delete it)
163
/// Free up filter for reuse (you can also delete it)
142
extern void returnMimeHandler(Dijon::Filter *);
164
extern void returnMimeHandler(RecollFilter *);
143
165
144
/// Clean up cache at the end of an indexing pass. For people who use
166
/// Clean up cache at the end of an indexing pass. For people who use
145
/// the GUI to index: avoid all those filter processes forever hanging
167
/// the GUI to index: avoid all those filter processes forever hanging
146
/// off recoll.
168
/// off recoll.
147
extern void clearMimeHandlerCache();
169
extern void clearMimeHandlerCache();