Skip to content

Commit

Permalink
CopernicaMarketingSoftware#507 connection_name property is not set on…
Browse files Browse the repository at this point in the history
… windows platform
  • Loading branch information
olejniczak committed Aug 24, 2023
1 parent 38eff40 commit a68cd2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/connectionstartframe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/programname.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
* Dependencies
*/
#include <limits.h>
#if defined(_WIN32) || defined(_WIN64)
#include "Windows.h"
#else
#include <unistd.h>
#endif

/**
* Begin of namespace
Expand Down Expand Up @@ -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);

Expand All @@ -55,6 +62,7 @@ class ProgramName

// set trailing null byte
_path[size == PATH_MAX ? PATH_MAX-1 : size] = '\0';
#endif
}

/**
Expand Down

0 comments on commit a68cd2e

Please sign in to comment.