[httpd/mpd] Adjustments to commit #69ff42f

This commit is contained in:
ejurgensen
2017-11-15 23:13:20 +01:00
parent 69ff42fc6a
commit a6fab4ac0d
8 changed files with 80 additions and 66 deletions

View File

@@ -43,6 +43,7 @@
#include <uniconv.h>
#include "logger.h"
#include "conffile.h"
#include "misc.h"
@@ -992,6 +993,45 @@ murmur_hash64(const void *key, int len, uint32_t seed)
# error Platform not supported
#endif
bool
peer_address_is_trusted(const char *addr)
{
cfg_t *section;
const char *network;
int i;
int n;
if (!addr)
return false;
if (strncmp(addr, "::ffff:", strlen("::ffff:")) == 0)
addr += strlen("::ffff:");
section = cfg_getsec(cfg, "general");
n = cfg_size(section, "trusted_networks");
for (i = 0; i < n; i++)
{
network = cfg_getnstr(section, "trusted_networks", i);
if (!network || network[0] == '\0')
return false;
if (strncmp(network, addr, strlen(network)) == 0)
return true;
if ((strcmp(network, "localhost") == 0) && (strcmp(addr, "127.0.0.1") == 0 || strcmp(addr, "::1") == 0))
return true;
if (strcmp(network, "any") == 0)
return true;
}
return false;
}
int
clock_gettime_with_res(clockid_t clock_id, struct timespec *tp, struct timespec *res)
{