Merge pull request #508 from olejniczak/master

#507 connection_name property is not set on windows platform
This commit is contained in:
Emiel Bruijntjes 2023-08-24 21:23:47 +02:00 committed by GitHub
commit 019c270add
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -11,8 +11,8 @@
/** /**
* Dependencies * Dependencies
*/ */
#if !defined(_WIN32) && !defined(_WIN64)
#include "programname.h" #include "programname.h"
#if !defined(_WIN32) && !defined(_WIN64)
#include "platformname.h" #include "platformname.h"
#endif #endif
@ -228,15 +228,14 @@ public:
if (!properties.contains("information")) properties["information"] = "https://github.com/CopernicaMarketingSoftware/AMQP-CPP"; if (!properties.contains("information")) properties["information"] = "https://github.com/CopernicaMarketingSoftware/AMQP-CPP";
if (!properties.contains("capabilities")) properties["capabilities"] = capabilities; 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) #if defined(_WIN32) || defined(_WIN64)
// i don't know that much about win32, so let's use hardcoded string // 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"; if (!properties.contains("platform")) properties["platform"] = "windows";
#else #else
// on unix-like systems I know how to retrieve application and platform info // 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("platform")) properties["platform"] = PlatformName();
if (!properties.contains("connection_name")) properties["connection_name"] = ProgramName();
#endif #endif
// send back a connection start ok frame // send back a connection start ok frame

View File

@ -16,7 +16,11 @@
* Dependencies * Dependencies
*/ */
#include <limits.h> #include <limits.h>
#if defined(_WIN32) || defined(_WIN64)
#include "Windows.h"
#else
#include <unistd.h> #include <unistd.h>
#endif
/** /**
* Begin of namespace * Begin of namespace
@ -47,6 +51,9 @@ public:
*/ */
ProgramName() ProgramName()
{ {
#if defined(_WIN32) || defined(_WIN64)
GetModuleFileNameA(NULL, _path, MAX_PATH);
#else
// read the link target // read the link target
auto size = readlink("/proc/self/exe", _path, PATH_MAX); auto size = readlink("/proc/self/exe", _path, PATH_MAX);
@ -55,6 +62,7 @@ public:
// set trailing null byte // set trailing null byte
_path[size == PATH_MAX ? PATH_MAX-1 : size] = '\0'; _path[size == PATH_MAX ? PATH_MAX-1 : size] = '\0';
#endif
} }
/** /**