From 06f43c573e297989f5b2d394bb4b7e6bc2631c80 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Fri, 11 Sep 2015 11:26:53 +0200 Subject: [PATCH] 1st successful use of mh_exec (direct antiword exec) --HG-- branch : WINDOWSPORT --- src/common/rclconfig.cpp | 59 +++--- src/index/mimetype.cpp | 2 - src/index/mimetype.h | 2 +- src/internfile/mh_exec.cpp | 6 +- src/internfile/mh_execm.cpp | 4 +- src/internfile/mh_execm.h | 2 - src/internfile/mimehandler.cpp | 4 - src/utils/pathut.cpp | 11 ++ src/utils/pathut.h | 3 + src/windows/Win32ProjectRecoll.vcxproj | 4 + .../Win32ProjectRecoll.vcxproj.filters | 12 ++ src/windows/execmd_w.cpp | 39 ++-- src/windows/trexe/trexecmd/trexecmd.sln | 28 +++ src/windows/trexe/trexecmd/trexecmd.vcxproj | 168 ++++++++++++++++++ .../trexe/trexecmd/trexecmd.vcxproj.filters | 22 +++ src/xaposix/safesyswait.h | 39 ++++ 16 files changed, 345 insertions(+), 60 deletions(-) create mode 100644 src/windows/trexe/trexecmd/trexecmd.sln create mode 100644 src/windows/trexe/trexecmd/trexecmd.vcxproj create mode 100644 src/windows/trexe/trexecmd/trexecmd.vcxproj.filters create mode 100644 src/xaposix/safesyswait.h diff --git a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp index 8ceabbc3..0b93f888 100644 --- a/src/common/rclconfig.cpp +++ b/src/common/rclconfig.cpp @@ -47,6 +47,7 @@ #include "readfile.h" #include "fstreewalk.h" #include "cpuconf.h" +#include "execmd.h" using namespace std; @@ -1305,47 +1306,45 @@ vector RclConfig::getDaemSkippedPaths() const } -// Look up an executable filter. We look in $RECOLL_FILTERSDIR, -// filtersdir in config file, then let the system use the PATH +// Look up an executable filter. We add $RECOLL_FILTERSDIR, +// and filtersdir from the config file to the PATH, then use execmd::which() string RclConfig::findFilter(const string &icmd) const { // If the path is absolute, this is it if (path_isabsolute(icmd)) return icmd; - string cmd; - const char *cp; + const char *cp = getenv("PATH"); + if (!cp) //?? + cp = ""; + string PATH(cp); - // Filters dir from environment ? - if ((cp = getenv("RECOLL_FILTERSDIR"))) { - cmd = path_cat(cp, icmd); - if (access(cmd.c_str(), X_OK) == 0) - return cmd; - } + // For historical reasons: check in personal config directory + PATH = getConfDir() + path_PATHsep() + PATH; - // Filters dir as configuration parameter? - if (getConfParam(string("filtersdir"), cmd)) { - cmd = path_cat(cmd, icmd); - cmd = path_tildexpand(cmd); - if (access(cmd.c_str(), X_OK) == 0) - return cmd; + string temp; + // Prepend $datadir/filters + temp = path_cat(m_datadir, "filters"); + PATH = temp + path_PATHsep() + PATH; + + // Prepend possible configuration parameter? + if (getConfParam(string("filtersdir"), temp)) { + temp = path_tildexpand(temp); + PATH = temp + path_PATHsep() + PATH; } - // Filters dir as datadir subdir. Actually the standard case, but - // this is normally the same value found in config file (previous step) - cmd = path_cat(m_datadir, "filters"); - cmd = path_cat(cmd, icmd); - if (access(cmd.c_str(), X_OK) == 0) - return cmd; + // Prepend possible environment variable + if ((cp = getenv("RECOLL_FILTERSDIR"))) { + PATH = string(cp) + path_PATHsep() + PATH; + } - // Last resort for historical reasons: check in personal config - // directory - cmd = path_cat(getConfDir(), icmd); - if (access(cmd.c_str(), X_OK) == 0) - return cmd; - - // Let the shell try to find it... - return icmd; + string cmd; + if (ExecCmd::which(icmd, cmd, PATH.c_str())) { + return cmd; + } else { + // Let the shell try to find it... + return icmd; + } } /** diff --git a/src/index/mimetype.cpp b/src/index/mimetype.cpp index 87118c49..7e892779 100644 --- a/src/index/mimetype.cpp +++ b/src/index/mimetype.cpp @@ -27,9 +27,7 @@ using namespace std; #include "mimetype.h" #include "debuglog.h" -#ifndef _WIN32 #include "execmd.h" -#endif #include "rclconfig.h" #include "smallut.h" #include "idfile.h" diff --git a/src/index/mimetype.h b/src/index/mimetype.h index 3d659b80..ae30b012 100644 --- a/src/index/mimetype.h +++ b/src/index/mimetype.h @@ -17,10 +17,10 @@ #ifndef _MIMETYPE_H_INCLUDED_ #define _MIMETYPE_H_INCLUDED_ +#include "safesysstat.h" #include class RclConfig; -struct stat; /** * Try to determine a mime type for file. diff --git a/src/internfile/mh_exec.cpp b/src/internfile/mh_exec.cpp index 94ccdbc8..f59acf0c 100644 --- a/src/internfile/mh_exec.cpp +++ b/src/internfile/mh_exec.cpp @@ -17,10 +17,10 @@ #include "autoconfig.h" #include -#include +#include +#include "safesyswait.h" #include -using namespace std; #include "cstr.h" #include "execmd.h" @@ -32,6 +32,8 @@ using namespace std; #include "md5ut.h" #include "rclconfig.h" +using namespace std; + // This is called periodically by ExeCmd when it is waiting for data, // or when it does receive some. We may choose to interrupt the // command. diff --git a/src/internfile/mh_execm.cpp b/src/internfile/mh_execm.cpp index 74a7f911..8a7a82c4 100644 --- a/src/internfile/mh_execm.cpp +++ b/src/internfile/mh_execm.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 J.F.Dockes + /* Copyright (C) 2005 J.F.Dockes * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -32,7 +32,7 @@ using namespace std; #include "idfile.h" #include -#include +#include "safesyswait.h" bool MimeHandlerExecMultiple::startCmd() { diff --git a/src/internfile/mh_execm.h b/src/internfile/mh_execm.h index 70c6b7c9..c2b29242 100644 --- a/src/internfile/mh_execm.h +++ b/src/internfile/mh_execm.h @@ -98,9 +98,7 @@ text/plainData: 10 class MimeHandlerExecMultiple : public MimeHandlerExec { ///////// // Things not reset by "clear()", additionally to those in MimeHandlerExec -#ifndef _WIN32 ExecCmd m_cmd; -#endif /////// End un-cleared stuff. public: diff --git a/src/internfile/mimehandler.cpp b/src/internfile/mimehandler.cpp index 50956463..bb0d09ff 100644 --- a/src/internfile/mimehandler.cpp +++ b/src/internfile/mimehandler.cpp @@ -195,9 +195,6 @@ static const string cstr_mh_charset("charset"); MimeHandlerExec *mhExecFactory(RclConfig *cfg, const string& mtype, string& hs, bool multiple, const string& id) { -#ifdef _WIN32 - return 0; -#else ConfSimple attrs; string cmdstr; @@ -241,7 +238,6 @@ MimeHandlerExec *mhExecFactory(RclConfig *cfg, const string& mtype, string& hs, #endif return h; -#endif } /* Get handler/filter object for given mime type: */ diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 69ade2ec..82e19ef7 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -239,6 +239,17 @@ const string& path_sharedatadir() return datadir; } +string path_PATHsep() +{ + static const string w(";"); + static const string u(":"); +#ifdef _WIN32 + return w; +#else + return u; +#endif +} + bool maketmpdir(string& tdir, string& reason) { #ifndef _WIN32 diff --git a/src/utils/pathut.h b/src/utils/pathut.h index 70b25264..8c825cd6 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -78,6 +78,9 @@ extern long long path_filesize(const std::string& path); /// the file/dir does not exist or that an error occurred. extern bool path_exists(const std::string& path); +/// Return separator for PATH environment variable +extern std::string path_PATHsep(); + /// Dump directory extern bool readdir(const std::string& dir, std::string& reason, std::set& entries); diff --git a/src/windows/Win32ProjectRecoll.vcxproj b/src/windows/Win32ProjectRecoll.vcxproj index 20abc8e1..411410a1 100644 --- a/src/windows/Win32ProjectRecoll.vcxproj +++ b/src/windows/Win32ProjectRecoll.vcxproj @@ -151,6 +151,8 @@ + + @@ -193,6 +195,8 @@ + + diff --git a/src/windows/Win32ProjectRecoll.vcxproj.filters b/src/windows/Win32ProjectRecoll.vcxproj.filters index d1235f2b..d57ce63c 100644 --- a/src/windows/Win32ProjectRecoll.vcxproj.filters +++ b/src/windows/Win32ProjectRecoll.vcxproj.filters @@ -96,6 +96,12 @@ Header Files + + Header Files + + + Header Files + @@ -299,6 +305,12 @@ Source Files + + Source Files + + + Source Files + diff --git a/src/windows/execmd_w.cpp b/src/windows/execmd_w.cpp index 76ad258c..5aff3b62 100644 --- a/src/windows/execmd_w.cpp +++ b/src/windows/execmd_w.cpp @@ -190,6 +190,26 @@ static void make_path_vec(const char *ep, vector& vec) vec.insert(vec.begin(), ".\\"); } +static std::string pipeUniqueName(std::string nClass, std::string prefix) +{ + std::stringstream uName; + + long currCnt; + // PID + multi-thread-protected static counter to be unique + { + static long cnt = 0; + currCnt = InterlockedIncrement(&cnt); + } + DWORD pid = GetCurrentProcessId(); + + // naming convention + uName << "\\\\.\\" << nClass << "\\"; + uName << "pid-" << pid << "-cnt-" << currCnt << "-"; + uName << prefix; + + return uName.str(); +} + enum WaitResult { Ok, Quit, Timeout }; @@ -420,24 +440,9 @@ void ExecCmd::putenv(const string &name, const string& value) m->m_env[name] = value; } -static std::string pipeUniqueName(std::string nClass, std::string prefix) +void ExecCmd::setrlimit_as(int mbytes) { - std::stringstream uName; - - long currCnt; - // PID + multi-thread-protected static counter to be unique - { - static long cnt = 0; - currCnt = InterlockedIncrement(&cnt); - } - DWORD pid = GetCurrentProcessId(); - - // naming convention - uName << "\\\\.\\" << nClass << "\\"; - uName << "pid-" << pid << "-cnt-" << currCnt << "-"; - uName << prefix; - - return uName.str(); + // Later maybe } bool ExecCmd::Internal::preparePipes(bool has_input,HANDLE *hChildInput, diff --git a/src/windows/trexe/trexecmd/trexecmd.sln b/src/windows/trexe/trexecmd/trexecmd.sln new file mode 100644 index 00000000..02263f11 --- /dev/null +++ b/src/windows/trexe/trexecmd/trexecmd.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "trexecmd", "trexecmd.vcxproj", "{AA325A63-79BC-41A5-BEDD-A64879D2A0A0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0}.Debug|x64.ActiveCfg = Debug|x64 + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0}.Debug|x64.Build.0 = Debug|x64 + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0}.Debug|x86.ActiveCfg = Debug|Win32 + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0}.Debug|x86.Build.0 = Debug|Win32 + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0}.Release|x64.ActiveCfg = Release|x64 + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0}.Release|x64.Build.0 = Release|x64 + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0}.Release|x86.ActiveCfg = Release|Win32 + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/windows/trexe/trexecmd/trexecmd.vcxproj b/src/windows/trexe/trexecmd/trexecmd.vcxproj new file mode 100644 index 00000000..dc737038 --- /dev/null +++ b/src/windows/trexe/trexecmd/trexecmd.vcxproj @@ -0,0 +1,168 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {AA325A63-79BC-41A5-BEDD-A64879D2A0A0} + Win32Proj + trexecmd + 8.1 + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(Solutiondir)..\..\..\xaposix;$(Solutiondir)..\..\;$(Solutiondir)..\..\..\common;$(Solutiondir)..\..\..\utils;%(AdditionalIncludeDirectories) + + + Console + true + $(Solutiondir)..\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + librecoll.lib;%(AdditionalDependencies) + + + + + + + Level3 + Disabled + __WIN32__;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(Solutiondir)..\..\..\xaposix;$(Solutiondir)..\..\;$(Solutiondir)..\..\..\common;$(Solutiondir)..\..\..\utils;%(AdditionalIncludeDirectories) + + + Console + true + $(libiconv)\libiconv\$(Platform)\$(Configuration);$(zlib)\$(PLatform)\$(Configuration)\;$(xapian)\win32\$(PLatform)\$(Configuration)\;$(solutiondir)..\..\$(PLatform)\$(Configuration)\;$(pthreads)\lib\x64;%(AdditionalLibraryDirectories) + Win32ProjectRecoll.lib;zlib.lib;xapian-core.lib;libiconv.lib;Ws2_32.lib;Rpcrt4.lib;pthreadVC2.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(Solutiondir)..\..\..\xaposix;$(Solutiondir)..\..\;$(Solutiondir)..\..\..\common;$(Solutiondir)..\..\..\utils;%(AdditionalIncludeDirectories) + + + Console + true + true + true + $(Solutiondir)..\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + librecoll.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + $(Solutiondir)..\..\..\xaposix;$(Solutiondir)..\..\;$(Solutiondir)..\..\..\common;$(Solutiondir)..\..\..\utils;%(AdditionalIncludeDirectories) + + + Console + true + true + true + $(Solutiondir)..\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + librecoll.lib;%(AdditionalDependencies) + + + + + + + + + \ No newline at end of file diff --git a/src/windows/trexe/trexecmd/trexecmd.vcxproj.filters b/src/windows/trexe/trexecmd/trexecmd.vcxproj.filters new file mode 100644 index 00000000..ddbaca70 --- /dev/null +++ b/src/windows/trexe/trexecmd/trexecmd.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/xaposix/safesyswait.h b/src/xaposix/safesyswait.h new file mode 100644 index 00000000..776d9282 --- /dev/null +++ b/src/xaposix/safesyswait.h @@ -0,0 +1,39 @@ +/** @file safesyswait.h + * @brief #include , with portability stuff. + */ +/* Copyright (C) 2010 Olly Betts + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 + * USA + */ + +#ifndef XAPIAN_INCLUDED_SAFESYSWAIT_H +#define XAPIAN_INCLUDED_SAFESYSWAIT_H + +#ifndef __WIN32__ +# include +#else +// We don't try to replace waitpid(), etc - they're only useful for us when +// we can fork(). But it's handy to be able to use WIFEXITED() and +// WEXITSTATUS(). +# ifndef WIFEXITED +# define WIFEXITED(STATUS) (STATUS != -1) +# endif +# ifndef WEXITSTATUS +# define WEXITSTATUS(STATUS) (STATUS) +# endif +#endif + +#endif /* XAPIAN_INCLUDED_SAFESYSWAIT_H */