Added a function for generic address parsing
Changed listen_add_config_param() to use generic address parsing
This commit is contained in:
parent
2127a482da
commit
52521d02ea
@ -1023,6 +1023,7 @@ libconf_a_SOURCES = \
|
|||||||
src/config/Migrate.cxx src/config/Migrate.hxx \
|
src/config/Migrate.cxx src/config/Migrate.hxx \
|
||||||
src/config/Templates.cxx src/config/Templates.hxx \
|
src/config/Templates.cxx src/config/Templates.hxx \
|
||||||
src/config/Domain.cxx src/config/Domain.hxx \
|
src/config/Domain.cxx src/config/Domain.hxx \
|
||||||
|
src/config/Net.cxx src/config/Net.hxx \
|
||||||
src/config/Option.hxx
|
src/config/Option.hxx
|
||||||
|
|
||||||
# the Song library
|
# the Song library
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "config/Param.hxx"
|
#include "config/Param.hxx"
|
||||||
#include "config/Data.hxx"
|
#include "config/Data.hxx"
|
||||||
#include "config/Option.hxx"
|
#include "config/Option.hxx"
|
||||||
|
#include "config/Net.hxx"
|
||||||
#include "system/Error.hxx"
|
#include "system/Error.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "fs/AllocatedPath.hxx"
|
#include "fs/AllocatedPath.hxx"
|
||||||
@ -48,13 +49,7 @@ listen_add_config_param(ClientListener &listener,
|
|||||||
{
|
{
|
||||||
assert(param != nullptr);
|
assert(param != nullptr);
|
||||||
|
|
||||||
if (0 == strcmp(param->value.c_str(), "any")) {
|
ServerSocketAddGeneric(listener, param->value.c_str(), port);
|
||||||
listener.AddPort(port);
|
|
||||||
} else if (param->value[0] == '/' || param->value[0] == '~') {
|
|
||||||
listener.AddPath(param->GetPath());
|
|
||||||
} else {
|
|
||||||
listener.AddHost(param->value.c_str(), port);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_SYSTEMD_DAEMON
|
#ifdef ENABLE_SYSTEMD_DAEMON
|
||||||
|
36
src/config/Net.cxx
Normal file
36
src/config/Net.cxx
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2017 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "Net.hxx"
|
||||||
|
#include "event/ServerSocket.hxx"
|
||||||
|
#include "Path.hxx"
|
||||||
|
#include "fs/AllocatedPath.hxx"
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerSocketAddGeneric(ServerSocket &server_socket, const char *address, unsigned int port)
|
||||||
|
{
|
||||||
|
if (address == nullptr || 0 == strcmp(address, "any")) {
|
||||||
|
server_socket.AddPort(port);
|
||||||
|
} else if (address[0] == '/' || address[0] == '~') {
|
||||||
|
server_socket.AddPath(ParsePath(address));
|
||||||
|
} else {
|
||||||
|
server_socket.AddHost(address, port);
|
||||||
|
}
|
||||||
|
}
|
44
src/config/Net.hxx
Normal file
44
src/config/Net.hxx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2017 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MPD_CONFIG_NET_HXX
|
||||||
|
#define MPD_CONFIG_NET_HXX
|
||||||
|
|
||||||
|
class ServerSocket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the address or unix socket of a ServerSocket instance
|
||||||
|
* There are three possible ways
|
||||||
|
* 1) Set address to a valid ip address and specify port.
|
||||||
|
* server_socket will listen on this address/port tuple.
|
||||||
|
* 2) Set address to null and specify port.
|
||||||
|
* server_socket will listen on ANY address on that port.
|
||||||
|
* 3) Set address to a path of a unix socket. port is ignored.
|
||||||
|
* server_socket will listen on this unix socket.
|
||||||
|
*
|
||||||
|
* Throws #std::runtime_error on error.
|
||||||
|
*
|
||||||
|
* @param server_socket the instance to modify
|
||||||
|
* @param address the address to listen on
|
||||||
|
* @param port the port to listen on
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ServerSocketAddGeneric(ServerSocket &server_socket, const char *address, unsigned int port);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user