zeroconf/glue: use strstr() and std::string::replace() instead of std::regex_replace()
std::regex_replace() is heavily bloated and overkill for this feature.
This commit is contained in:
parent
b1d68fe995
commit
657ef48518
@ -27,9 +27,10 @@
|
|||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
#include "util/Compiler.h"
|
#include "util/Compiler.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
static constexpr Domain zeroconf_domain("zeroconf");
|
static constexpr Domain zeroconf_domain("zeroconf");
|
||||||
|
|
||||||
@ -62,10 +63,17 @@ ZeroconfInit(const ConfigData &config, gcc_unused EventLoop &loop)
|
|||||||
serviceName = config.GetString(ConfigOption::ZEROCONF_NAME,
|
serviceName = config.GetString(ConfigOption::ZEROCONF_NAME,
|
||||||
SERVICE_NAME);
|
SERVICE_NAME);
|
||||||
|
|
||||||
|
/* replace "%h" with the host name */
|
||||||
|
const char *h = strstr(serviceName, "%h");
|
||||||
|
std::string buffer;
|
||||||
|
if (h != nullptr) {
|
||||||
char hostname[HOST_NAME_MAX+1];
|
char hostname[HOST_NAME_MAX+1];
|
||||||
gethostname(hostname, HOST_NAME_MAX);
|
if (gethostname(hostname, HOST_NAME_MAX) == 0) {
|
||||||
std::string sName = std::regex_replace(serviceName, std::regex("%h"), hostname);
|
buffer = serviceName;
|
||||||
serviceName = sName.c_str();
|
buffer.replace(h - serviceName, 2, hostname);
|
||||||
|
serviceName = buffer.c_str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_AVAHI
|
#ifdef HAVE_AVAHI
|
||||||
AvahiInit(loop, serviceName);
|
AvahiInit(loop, serviceName);
|
||||||
|
Loading…
Reference in New Issue
Block a user