From a68cd2ed495914ebb7d2e9a57d200cb7847b78e9 Mon Sep 17 00:00:00 2001
From: Przemyslaw Olejniczak
Date: Thu, 24 Aug 2023 14:13:18 +0200
Subject: [PATCH] #507 connection_name property is not set on windows platform
---
src/connectionstartframe.h | 5 ++---
src/programname.h | 8 ++++++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/connectionstartframe.h b/src/connectionstartframe.h
index 55c90c77..fd51ea75 100644
--- a/src/connectionstartframe.h
+++ b/src/connectionstartframe.h
@@ -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
}
/**