From c955e6a8f80b93f22074ac589f074a0e3c0d5c03 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 4 Feb 2021 09:41:10 +0100 Subject: [PATCH] new execution line format --- resources/docs/Feed-formats.md | 12 ++++++------ .../services/standard/standardfeed.cpp | 18 ++++++------------ .../services/standard/standardfeed.h | 4 ++-- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/resources/docs/Feed-formats.md b/resources/docs/Feed-formats.md index 15474baba..1283fe90e 100755 --- a/resources/docs/Feed-formats.md +++ b/resources/docs/Feed-formats.md @@ -60,15 +60,15 @@ However, if you choose `Script` option, then you cannot provide URL of your feed Any errors in your script must be written to **error output**. -Note that you must provide full execution line to your custom script, including interpreter binary path and name and all that must be written in special format `#`. The `#` character is there to separate interpreter from its arguments. +Note that you must provide full execution line to your custom script, including interpreter binary path and name and all that must be written in special format `###....`. The `#` character is there to separate interpreter and individual arguments. -Interpreter must be provided in all cases, arguments do not have to be. For example `bash.exe#` is valid execution line, as well as `bash#-C "cat feed.atom"`. Note the difference in interpreter's binary name suffix. Some examples of valid and tested execution lines are: +Interpreter must be provided in all cases, arguments do not have to be. For example `bash.exe#` is valid execution line, as well as `bash#-c#cat feed.atom`. Note the difference in interpreter's binary name suffix. Also be very carefuly about arguments quoting. Some examples of valid and tested execution lines are: | Command | Explanation | |---------|-------------| -| `bash#-c "curl 'https://github.com/martinrotter.atom'"` | Downloads ATOM feed file with Bash and Curl. | -| `Powershell#"Invoke-WebRequest 'https://github.com/martinrotter.atom' \| Select-Object -ExpandProperty Content"` | Downloads ATOM feed file with Powershell. | -| `php#tweeper.php -v 0 https://twitter.com/NSACareers` | Scrape Twitter RSS feed file with [Tweeper](https://git.ao2.it/tweeper.git). Tweeper is utility which is able to produce RSS feed from Twitter and other similar social platforms. | +| `bash#-c#"curl https://github.com/martinrotter.atom"` | Downloads ATOM feed file with Bash and Curl. | +| `Powershell#Invoke-WebRequest 'https://github.com/martinrotter.atom' \| Select-Object -ExpandProperty Content` | Downloads ATOM feed file with Powershell. | +| `php#tweeper.php#-v#0#https://twitter.com/NSACareers` | Scrape Twitter RSS feed file with [Tweeper](https://git.ao2.it/tweeper.git). Tweeper is utility which is able to produce RSS feed from Twitter and other similar social platforms. | @@ -88,4 +88,4 @@ Typical post-processing filter might do things like advanced CSS formatting of f | Command | Explanation | |---------|-------------| -| `bash#-c "xmllint --format -"` | Pretty-print input XML feed data. | \ No newline at end of file +| `bash#-c#xmllint --format -` | Pretty-print input XML feed data. | \ No newline at end of file diff --git a/src/librssguard/services/standard/standardfeed.cpp b/src/librssguard/services/standard/standardfeed.cpp index e9b341e0a..3ac59f214 100644 --- a/src/librssguard/services/standard/standardfeed.cpp +++ b/src/librssguard/services/standard/standardfeed.cpp @@ -657,20 +657,19 @@ QList StandardFeed::obtainNewMessages(bool* error_during_obtaining) { return messages; } -QPair StandardFeed::prepareExecutionLine(const QString& execution_line) { +QStringList StandardFeed::prepareExecutionLine(const QString& execution_line) { auto split_exec = execution_line.split('#', Qt::SplitBehaviorFlags::KeepEmptyParts); - if (split_exec.size() != 2) { + if (split_exec.size() <= 1) { throw ScriptException(ScriptException::Reason::ExecutionLineInvalid); } auto user_data_folder = qApp->userDataFolder(); - return { split_exec[0].replace(EXECUTION_LINE_USER_DATA_PLACEHOLDER, user_data_folder), - split_exec[1].replace(EXECUTION_LINE_USER_DATA_PLACEHOLDER, user_data_folder) }; + return split_exec.replaceInStrings(EXECUTION_LINE_USER_DATA_PLACEHOLDER, user_data_folder); } -QString StandardFeed::runScriptProcess(const QPair& cmd_args, const QString& working_directory, +QString StandardFeed::runScriptProcess(const QStringList& cmd_args, const QString& working_directory, int run_timeout, bool provide_input, const QString& input) { QProcess process; @@ -681,13 +680,8 @@ QString StandardFeed::runScriptProcess(const QPair& cmd_args, process.setProcessEnvironment(QProcessEnvironment::systemEnvironment()); process.setProcessChannelMode(QProcess::ProcessChannelMode::SeparateChannels); process.setWorkingDirectory(working_directory); - process.setProgram(cmd_args.first); - -#if defined(Q_OS_WIN) - process.setNativeArguments(cmd_args.second); -#else - process.setArguments({ cmd_args.second }); -#endif + process.setProgram(cmd_args.at(0)); + process.setArguments(cmd_args.mid(1)); if (!process.open()) { switch (process.error()) { diff --git a/src/librssguard/services/standard/standardfeed.h b/src/librssguard/services/standard/standardfeed.h index baf8b8bd6..77e89a4d7 100644 --- a/src/librssguard/services/standard/standardfeed.h +++ b/src/librssguard/services/standard/standardfeed.h @@ -78,7 +78,7 @@ class StandardFeed : public Feed { QList obtainNewMessages(bool* error_during_obtaining); - static QPair prepareExecutionLine(const QString& execution_line); + static QStringList prepareExecutionLine(const QString& execution_line); static QString generateFeedFileWithScript(const QString& execution_line, int run_timeout); static QString postProcessFeedFileWithScript(const QString& execution_line, const QString raw_feed_data, int run_timeout); @@ -103,7 +103,7 @@ class StandardFeed : public Feed { void fetchMetadataForItself(); private: - static QString runScriptProcess(const QPair& cmd_args, const QString& working_directory, + static QString runScriptProcess(const QStringList& cmd_args, const QString& working_directory, int run_timeout, bool provide_input, const QString& input = {}); private: