|
a/src/internfile/mimehandler.cpp |
|
b/src/internfile/mimehandler.cpp |
|
... |
|
... |
29 |
#include "mimehandler.h"
|
29 |
#include "mimehandler.h"
|
30 |
#include "debuglog.h"
|
30 |
#include "debuglog.h"
|
31 |
#include "rclconfig.h"
|
31 |
#include "rclconfig.h"
|
32 |
#include "smallut.h"
|
32 |
#include "smallut.h"
|
33 |
#include "md5ut.h"
|
33 |
#include "md5ut.h"
|
34 |
|
|
|
35 |
#include "mh_exec.h"
|
34 |
#include "mh_exec.h"
|
36 |
#include "mh_execm.h"
|
35 |
#include "mh_execm.h"
|
37 |
#include "mh_html.h"
|
36 |
#include "mh_html.h"
|
38 |
#include "mh_mail.h"
|
37 |
#include "mh_mail.h"
|
39 |
#include "mh_mbox.h"
|
38 |
#include "mh_mbox.h"
|
40 |
#include "mh_text.h"
|
39 |
#include "mh_text.h"
|
41 |
#include "mh_symlink.h"
|
40 |
#include "mh_symlink.h"
|
42 |
#include "mh_unknown.h"
|
41 |
#include "mh_unknown.h"
|
|
|
42 |
#include "mh_null.h"
|
43 |
#include "ptmutex.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
|
|
... |
|
... |
161 |
return nobuild ? 0 : new MimeHandlerMail(config, id);
|
161 |
return nobuild ? 0 : new MimeHandlerMail(config, id);
|
162 |
} else if ("inode/symlink" == lmime) {
|
162 |
} else if ("inode/symlink" == lmime) {
|
163 |
LOGDEB2(("mhFactory(%s): ret MimeHandlerSymlink\n", mime.c_str()));
|
163 |
LOGDEB2(("mhFactory(%s): ret MimeHandlerSymlink\n", mime.c_str()));
|
164 |
MD5String("MimeHandlerSymlink", id);
|
164 |
MD5String("MimeHandlerSymlink", id);
|
165 |
return nobuild ? 0 : new MimeHandlerSymlink(config, id);
|
165 |
return nobuild ? 0 : new MimeHandlerSymlink(config, id);
|
|
|
166 |
} else if ("application/x-zerosize" == lmime) {
|
|
|
167 |
LOGDEB(("mhFactory(%s): ret MimeHandlerNull\n", mime.c_str()));
|
|
|
168 |
MD5String("MimeHandlerNull", id);
|
|
|
169 |
return nobuild ? 0 : new MimeHandlerNull(config, id);
|
166 |
} else if (lmime.find("text/") == 0) {
|
170 |
} else if (lmime.find("text/") == 0) {
|
167 |
// Try to handle unknown text/xx as text/plain. This
|
171 |
// Try to handle unknown text/xx as text/plain. This
|
168 |
// only happen if the text/xx was defined as "internal" in
|
172 |
// only happen if the text/xx was defined as "internal" in
|
169 |
// mimeconf, not at random. For programs, for example this
|
173 |
// mimeconf, not at random. For programs, for example this
|
170 |
// allows indexing and previewing as text/plain (no filter
|
174 |
// allows indexing and previewing as text/plain (no filter
|
|
... |
|
... |
204 |
mtype.c_str(), hs.c_str()));
|
208 |
mtype.c_str(), hs.c_str()));
|
205 |
return 0;
|
209 |
return 0;
|
206 |
}
|
210 |
}
|
207 |
|
211 |
|
208 |
// Split command name and args, and build exec object
|
212 |
// Split command name and args, and build exec object
|
209 |
list<string> cmdtoks;
|
213 |
vector<string> cmdtoks;
|
210 |
stringToStrings(cmdstr, cmdtoks);
|
214 |
stringToStrings(cmdstr, cmdtoks);
|
211 |
if (cmdtoks.empty()) {
|
215 |
if (cmdtoks.empty()) {
|
212 |
LOGERR(("mhExecFactory: bad config line for [%s]: [%s]\n",
|
216 |
LOGERR(("mhExecFactory: bad config line for [%s]: [%s]\n",
|
213 |
mtype.c_str(), hs.c_str()));
|
217 |
mtype.c_str(), hs.c_str()));
|
214 |
return 0;
|
218 |
return 0;
|
215 |
}
|
219 |
}
|
216 |
MimeHandlerExec *h = multiple ?
|
220 |
MimeHandlerExec *h = multiple ?
|
217 |
new MimeHandlerExecMultiple(cfg, id) :
|
221 |
new MimeHandlerExecMultiple(cfg, id) :
|
218 |
new MimeHandlerExec(cfg, id);
|
222 |
new MimeHandlerExec(cfg, id);
|
219 |
list<string>::iterator it = cmdtoks.begin();
|
223 |
vector<string>::iterator it = cmdtoks.begin();
|
|
|
224 |
|
|
|
225 |
// Special-case python and perl on windows: we need to also locate the
|
|
|
226 |
// first argument which is the script name "python somescript.py".
|
|
|
227 |
// On Unix, thanks to #!, we usually just run "somescript.py", but need
|
|
|
228 |
// the same change if we ever want to use the same cmdling as windows
|
|
|
229 |
if (!stringlowercmp("python", *it) || !stringlowercmp("perl", *it)) {
|
|
|
230 |
if (cmdtoks.size() < 2) {
|
|
|
231 |
LOGERR(("mhExecFactory: python/perl cmd: no script?. [%s]: [%s]\n",
|
|
|
232 |
mtype.c_str(), hs.c_str()));
|
|
|
233 |
}
|
|
|
234 |
vector<string>::iterator it1(it);
|
|
|
235 |
it1++;
|
|
|
236 |
*it1 = cfg->findFilter(*it1);
|
|
|
237 |
}
|
|
|
238 |
|
220 |
h->params.push_back(cfg->findFilter(*it++));
|
239 |
h->params.push_back(cfg->findFilter(*it++));
|
221 |
h->params.insert(h->params.end(), it, cmdtoks.end());
|
240 |
h->params.insert(h->params.end(), it, cmdtoks.end());
|
222 |
|
241 |
|
223 |
// Handle additional attributes. We substitute the semi-colons
|
242 |
// Handle additional attributes. We substitute the semi-colons
|
224 |
// with newlines and use a ConfSimple
|
243 |
// with newlines and use a ConfSimple
|