diff --git a/src/connectionstartframe.h b/src/connectionstartframe.h index 55c90c77..7ccef881 100644 --- a/src/connectionstartframe.h +++ b/src/connectionstartframe.h @@ -11,8 +11,8 @@ /** * Dependencies */ -#if !defined(_WIN32) && !defined(_WIN64) #include "programname.h" +#if !defined(_WIN32) && !defined(_WIN64) #include "platformname.h" #endif @@ -228,15 +228,14 @@ class ConnectionStartFrame : public ConnectionFrame if (!properties.contains("information")) properties["information"] = "https://github.com/CopernicaMarketingSoftware/AMQP-CPP"; if (!properties.contains("capabilities")) properties["capabilities"] = capabilities; + if (!properties.contains("product")) properties["product"] = ProgramName();; + if (!properties.contains("connection_name")) properties["connection_name"] = ProgramName(); #if defined(_WIN32) || defined(_WIN64) // i don't know that much about win32, so let's use hardcoded string - if (!properties.contains("product")) properties["product"] = "application based on AMQP-CPP"; if (!properties.contains("platform")) properties["platform"] = "windows"; #else // on unix-like systems I know how to retrieve application and platform info - if (!properties.contains("product")) properties["product"] = ProgramName(); if (!properties.contains("platform")) properties["platform"] = PlatformName(); - if (!properties.contains("connection_name")) properties["connection_name"] = ProgramName(); #endif // send back a connection start ok frame diff --git a/src/programname.h b/src/programname.h index 4a16c359..5cb97aaa 100644 --- a/src/programname.h +++ b/src/programname.h @@ -16,7 +16,11 @@ * Dependencies */ #include +#if defined(_WIN32) || defined(_WIN64) +#include "Windows.h" +#else #include +#endif /** * Begin of namespace @@ -47,6 +51,9 @@ class ProgramName */ ProgramName() { +#if defined(_WIN32) || defined(_WIN64) + GetModuleFileNameA(NULL, _path, MAX_PATH); +#else // read the link target auto size = readlink("/proc/self/exe", _path, PATH_MAX); @@ -55,6 +62,7 @@ class ProgramName // set trailing null byte _path[size == PATH_MAX ? PATH_MAX-1 : size] = '\0'; +#endif } /**