|
a/src/internfile/mh_exec.cpp |
|
b/src/internfile/mh_exec.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: mh_exec.cpp,v 1.12 2008-10-04 14:26:59 dockes Exp $ (C) 2005 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: mh_exec.cpp,v 1.13 2008-10-06 06:22:46 dockes Exp $ (C) 2005 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
21 |
#include "execmd.h"
|
21 |
#include "execmd.h"
|
22 |
#include "mh_exec.h"
|
22 |
#include "mh_exec.h"
|
23 |
#include "mh_html.h"
|
23 |
#include "mh_html.h"
|
24 |
#include "debuglog.h"
|
24 |
#include "debuglog.h"
|
25 |
#include "cancelcheck.h"
|
25 |
#include "cancelcheck.h"
|
|
|
26 |
#include "smallut.h"
|
|
|
27 |
|
|
|
28 |
#include <sys/types.h>
|
|
|
29 |
#include <sys/wait.h>
|
26 |
|
30 |
|
27 |
#ifndef NO_NAMESPACES
|
31 |
#ifndef NO_NAMESPACES
|
28 |
using namespace std;
|
32 |
using namespace std;
|
29 |
#endif /* NO_NAMESPACES */
|
33 |
#endif /* NO_NAMESPACES */
|
30 |
|
34 |
|
|
... |
|
... |
40 |
bool MimeHandlerExec::next_document()
|
44 |
bool MimeHandlerExec::next_document()
|
41 |
{
|
45 |
{
|
42 |
if (m_havedoc == false)
|
46 |
if (m_havedoc == false)
|
43 |
return false;
|
47 |
return false;
|
44 |
m_havedoc = false;
|
48 |
m_havedoc = false;
|
|
|
49 |
if (missingHelper) {
|
|
|
50 |
LOGDEB(("MimeHandlerExec::next_document(): helper known missing\n"));
|
|
|
51 |
return false;
|
|
|
52 |
}
|
45 |
if (params.empty()) {
|
53 |
if (params.empty()) {
|
46 |
// Hu ho
|
54 |
// Hu ho
|
47 |
LOGERR(("MimeHandlerExec::mkDoc: empty params\n"));
|
55 |
LOGERR(("MimeHandlerExec::mkDoc: empty params\n"));
|
48 |
m_reason = "RECFILTERROR BADCONFIG";
|
56 |
m_reason = "RECFILTERROR BADCONFIG";
|
49 |
return false;
|
57 |
return false;
|
|
... |
|
... |
57 |
list<string>myparams(++it, params.end());
|
65 |
list<string>myparams(++it, params.end());
|
58 |
myparams.push_back(m_fn);
|
66 |
myparams.push_back(m_fn);
|
59 |
if (!m_ipath.empty())
|
67 |
if (!m_ipath.empty())
|
60 |
myparams.push_back(m_ipath);
|
68 |
myparams.push_back(m_ipath);
|
61 |
|
69 |
|
62 |
// Execute command and store the result text
|
70 |
// Execute command, store the output
|
63 |
string& output = m_metaData["content"];
|
71 |
string& output = m_metaData["content"];
|
64 |
output.erase();
|
72 |
output.erase();
|
65 |
ExecCmd mexec;
|
73 |
ExecCmd mexec;
|
66 |
MEAdv adv;
|
74 |
MEAdv adv;
|
67 |
mexec.setAdvise(&adv);
|
75 |
mexec.setAdvise(&adv);
|
68 |
mexec.putenv(m_forPreview ? "RECOLL_FILTER_FORPREVIEW=yes" :
|
76 |
mexec.putenv(m_forPreview ? "RECOLL_FILTER_FORPREVIEW=yes" :
|
69 |
"RECOLL_FILTER_FORPREVIEW=no");
|
77 |
"RECOLL_FILTER_FORPREVIEW=no");
|
70 |
int status = mexec.doexec(cmd, myparams, 0, &output);
|
78 |
int status = mexec.doexec(cmd, myparams, 0, &output);
|
|
|
79 |
|
71 |
if (status) {
|
80 |
if (status) {
|
72 |
LOGERR(("MimeHandlerExec: command status 0x%x: %s\n",
|
81 |
LOGERR(("MimeHandlerExec: command status 0x%x for %s\n",
|
73 |
status, cmd.c_str()));
|
82 |
status, cmd.c_str()));
|
|
|
83 |
if (WIFEXITED(status) && WEXITSTATUS(status) == 127) {
|
|
|
84 |
// That's how execmd signals a failed exec (most probably
|
|
|
85 |
// a missing command). Let'hope no filter uses the same value as
|
|
|
86 |
// an exit status... Disable myself permanently and signal the
|
|
|
87 |
// missing cmd.
|
|
|
88 |
missingHelper = true;
|
|
|
89 |
m_reason = string("RECFILTERROR HELPERNOTFOUND ") + cmd;
|
|
|
90 |
} else if (output.find("RECFILTERROR") == 0) {
|
74 |
// If the output string begins with RECFILTERROR, then it's
|
91 |
// If the output string begins with RECFILTERROR, then it's
|
75 |
// interpretable error information
|
92 |
// interpretable error information out from a recoll script
|
76 |
if (output.find("RECFILTERROR") == 0)
|
|
|
77 |
m_reason = output;
|
93 |
m_reason = output;
|
|
|
94 |
list<string> lerr;
|
|
|
95 |
stringToStrings(output, lerr);
|
|
|
96 |
if (lerr.size() > 2) {
|
|
|
97 |
list<string>::iterator it = lerr.begin();
|
|
|
98 |
it++;
|
|
|
99 |
if (*it == "HELPERNOTFOUND") {
|
|
|
100 |
// No use trying again and again to execute this filter,
|
|
|
101 |
// it won't work.
|
|
|
102 |
missingHelper = true;
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
}
|
78 |
return false;
|
106 |
return false;
|
79 |
}
|
107 |
}
|
|
|
108 |
|
|
|
109 |
// Success. Store some external metadata
|
80 |
m_metaData["origcharset"] = m_defcharset;
|
110 |
m_metaData["origcharset"] = m_defcharset;
|
81 |
// Default charset: all recoll filters output utf-8, but this
|
111 |
// Default charset: all recoll filters output utf-8, but this
|
82 |
// could still be overridden by the content-type meta tag.
|
112 |
// could still be overridden by the content-type meta tag.
|
83 |
m_metaData["charset"] = cfgCharset.empty() ? "utf-8" : cfgCharset;
|
113 |
m_metaData["charset"] = cfgCharset.empty() ? "utf-8" : cfgCharset;
|
84 |
m_metaData["mimetype"] = cfgMtype.empty() ? "text/html" : cfgMtype;
|
114 |
m_metaData["mimetype"] = cfgMtype.empty() ? "text/html" : cfgMtype;
|