[icinga-checkins] icinga.org: icinga2/feature/windows-nano-server-12128: Add an option to include the Msi function with its headers or not when compiling.

git at icinga.org git at icinga.org
Thu Aug 4 03:50:12 CEST 2016


Module: icinga2
Branch: feature/windows-nano-server-12128
Commit: 2f38fda1894be39d83b0d27c072e707675d74524
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=2f38fda1894be39d83b0d27c072e707675d74524

Author: Rune Darrud <theflyingcorpse at gmail.com>
Date:   Thu Aug  4 00:07:35 2016 +0200

Add an option to include the Msi function with its headers or not when compiling.

refs #12128

---

 CMakeLists.txt           |    4 ++++
 lib/base/scriptutils.cpp |   26 ++++++++++++++++++++++++++
 lib/base/scriptutils.hpp |    1 +
 3 files changed, 31 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0dcbac6..9f18e10 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,6 +40,7 @@ option(ICINGA2_WITH_PERFDATA "Build the perfdata module" ON)
 option(ICINGA2_WITH_STUDIO "Build the Icinga Studio application" OFF)
 option(ICINGA2_WITH_TESTS "Run unit tests" ON)
 option(ICINGA2_WITH_CLRCHECKTASK "Allow loading .Net code under Windows" ON)
+option(ICINGA2_WITH_MSI_FUNCTION "Msi headers and functions" ON)
 
 file(STRINGS icinga2.spec VERSION_LINE REGEX "^Version: ")
 string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE})
@@ -85,6 +86,9 @@ endif()
 if(WIN32)
   set(Boost_USE_STATIC_LIBS ON)
   add_definitions(-DBOOST_ALL_NO_LIB)
+  if(ICINGA2_WITH_MSI_FUNCTION)
+    add_definitions(-DICINGA2_WITH_MSI_FUNCTION)
+  endif()
   add_definitions(/bigobj)
 endif()
 
diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp
index 94a0f01..e48ae38 100644
--- a/lib/base/scriptutils.cpp
+++ b/lib/base/scriptutils.cpp
@@ -31,9 +31,12 @@
 #include <boost/regex.hpp>
 #include <algorithm>
 #include <set>
+
+#ifdef ICINGA2_WITH_MSI_FUNCTION
 #ifdef _WIN32
 #include <msi.h>
 #endif /* _WIN32 */
+#endif /* ICINGA2_WITH_MSI_FUNCTION */
 
 using namespace icinga;
 
@@ -59,6 +62,7 @@ REGISTER_SAFE_SCRIPTFUNCTION(get_time, &Utility::GetTime);
 REGISTER_SAFE_SCRIPTFUNCTION(basename, &Utility::BaseName);
 REGISTER_SAFE_SCRIPTFUNCTION(dirname, &Utility::DirName);
 REGISTER_SAFE_SCRIPTFUNCTION(msi_get_component_path, &ScriptUtils::MsiGetComponentPathShim);
+REGISTER_SAFE_SCRIPTFUNCTION(windows_program_path, &ScriptUtils::WindowsGetProgramPath);
 REGISTER_SAFE_SCRIPTFUNCTION(track_parents, &ScriptUtils::TrackParents);
 REGISTER_SAFE_SCRIPTFUNCTION(escape_shell_cmd, &Utility::EscapeShellCmd);
 REGISTER_SAFE_SCRIPTFUNCTION(escape_shell_arg, &Utility::EscapeShellArg);
@@ -300,6 +304,7 @@ void ScriptUtils::Assert(const Value& arg)
 String ScriptUtils::MsiGetComponentPathShim(const String& component)
 {
 #ifdef _WIN32
+#ifdef ICINGA2_WITH_MSI_FUNCTION
 	TCHAR productCode[39];
 	if (MsiGetProductCode(component.CStr(), productCode) != ERROR_SUCCESS)
 		return "";
@@ -308,6 +313,27 @@ String ScriptUtils::MsiGetComponentPathShim(const String& component)
 	path[0] = '\0';
 	MsiGetComponentPath(productCode, component.CStr(), path, &szPath);
 	return path;
+#endif /* ICINGA2_WITH_MSI_FUNCTION */
+	return String();
+#else /* _WIN32 */
+	return String();
+#endif /* _WIN32 */
+}
+
+String ScriptUtils::WindowsGetProgramPath(void)
+{
+#ifdef _WIN32
+	char result[ MAX_PATH ];
+	std::string path = std::string( result, GetModuleFileName( NULL, result, MAX_PATH ) );
+        boost::regex pattern ("(.+\\)*(.+)\.exe$");
+        boost::smatch programpath;
+
+	if (boost::regex_search(path, programpath, pattern)) {
+		return std::string(programpath[1]);
+	}
+	else {
+		BOOST_THROW_EXCEPTION(std::runtime_error("Failed to get the path of the icinga2 executable"));
+	}
 #else /* _WIN32 */
 	return String();
 #endif /* _WIN32 */
diff --git a/lib/base/scriptutils.hpp b/lib/base/scriptutils.hpp
index a79bb4d..b1bc829 100644
--- a/lib/base/scriptutils.hpp
+++ b/lib/base/scriptutils.hpp
@@ -51,6 +51,7 @@ public:
 	static Array::Ptr GetObjects(const Type::Ptr& type);
 	static void Assert(const Value& arg);
 	static String MsiGetComponentPathShim(const String& component);
+	static String WindowsGetProgramPath(void);
 	static Array::Ptr TrackParents(const Object::Ptr& parent);
 	static double Ptr(const Object::Ptr& object);
 



More information about the icinga-checkins mailing list