aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-01-09 14:28:42 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-01-28 19:32:28 +0000
commitf6db59b011914c2180b42ed4f6f144679a126994 (patch)
tree3215a9b6889f19a7ba88f24fcca98e683da40542 /src/common
parentnotify: warn if the spec contains one of '"\ (diff)
downloadmonero-f6db59b011914c2180b42ed4f6f144679a126994.tar.xz
notify: handle arbitrary tags
Diffstat (limited to 'src/common')
-rw-r--r--src/common/notify.cpp22
-rw-r--r--src/common/notify.h2
2 files changed, 20 insertions, 4 deletions
diff --git a/src/common/notify.cpp b/src/common/notify.cpp
index 0ac3d501b..c3165fb05 100644
--- a/src/common/notify.cpp
+++ b/src/common/notify.cpp
@@ -27,6 +27,7 @@
// 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"
@@ -55,11 +56,26 @@ Notify::Notify(const char *spec)
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;