diff options
author | Riccardo Spagni <ric@spagni.net> | 2019-01-28 21:35:46 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2019-01-28 21:35:46 +0200 |
commit | 40bb66cc1eb2b8fbb129e4931af88857875f7a42 (patch) | |
tree | 7f5cba7f154df0878cf5826370a86d0240aba9e9 /src/common | |
parent | Merge pull request #5080 (diff) | |
parent | blockchain: add --reorg-notify (diff) | |
download | monero-40bb66cc1eb2b8fbb129e4931af88857875f7a42.tar.xz |
Merge pull request #5053
23813c71 blockchain: add --reorg-notify (moneromooo-monero)
f6db59b0 notify: handle arbitrary tags (moneromooo-monero)
ff959216 notify: warn if the spec contains one of '"\ (moneromooo-monero)
13852678 common: set MONERO_DEFAULT_LOG_CATEGORY for notify and spawn (moneromooo-monero)
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/notify.cpp | 27 | ||||
-rw-r--r-- | src/common/notify.h | 2 | ||||
-rw-r--r-- | src/common/spawn.cpp | 3 |
3 files changed, 28 insertions, 4 deletions
diff --git a/src/common/notify.cpp b/src/common/notify.cpp index cadc68ea7..c3165fb05 100644 --- a/src/common/notify.cpp +++ b/src/common/notify.cpp @@ -27,11 +27,15 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <boost/algorithm/string.hpp> +#include <stdarg.h> #include "misc_log_ex.h" #include "file_io_utils.h" #include "spawn.h" #include "notify.h" +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "notify" + namespace tools { @@ -46,15 +50,32 @@ Notify::Notify(const char *spec) boost::split(args, spec, boost::is_any_of(" ")); CHECK_AND_ASSERT_THROW_MES(args.size() > 0, "Failed to parse spec"); + if (strchr(spec, '\'') || strchr(spec, '\"') || strchr(spec, '\\')) + MWARNING("A notification spec contains a quote or backslash: note that these are handled verbatim, which may not be the intent"); filename = args[0]; CHECK_AND_ASSERT_THROW_MES(epee::file_io_utils::is_file_exist(filename), "File not found: " << filename); } -int Notify::notify(const char *parameter) +static void replace(std::vector<std::string> &v, const char *tag, const char *s) +{ + for (std::string &str: v) + boost::replace_all(str, tag, s); +} + +int Notify::notify(const char *tag, const char *s, ...) { std::vector<std::string> margs = args; - for (std::string &s: margs) - boost::replace_all(s, "%s", parameter); + + replace(margs, tag, s); + + va_list ap; + va_start(ap, s); + while ((tag = va_arg(ap, const char*))) + { + s = va_arg(ap, const char*); + replace(margs, tag, s); + } + va_end(ap); return tools::spawn(filename.c_str(), margs, false); } diff --git a/src/common/notify.h b/src/common/notify.h index 81aacebb0..f813e8def 100644 --- a/src/common/notify.h +++ b/src/common/notify.h @@ -39,7 +39,7 @@ class Notify public: Notify(const char *spec); - int notify(const char *parameter); + int notify(const char *tag, const char *s, ...); private: std::string filename; diff --git a/src/common/spawn.cpp b/src/common/spawn.cpp index b2d03f62f..e03552f8c 100644 --- a/src/common/spawn.cpp +++ b/src/common/spawn.cpp @@ -42,6 +42,9 @@ #include "util.h" #include "spawn.h" +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "spawn" + namespace tools { |