Commit 987bdec3 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Merge branch 'epirat-yp-listenurl-fix'

Good work. Thanks to ePirat.
parents 2b56f73c 9275dfd8
Pipeline #1886 failed with stage
This diff is collapsed.
......@@ -20,8 +20,6 @@
#define CONFIG_EBADROOT -3
#define CONFIG_EPARSE -4
#define MAX_YP_DIRECTORIES 25
#include <libxml/tree.h>
#include "common/thread/thread.h"
#include "common/avl/avl.h"
......@@ -52,12 +50,6 @@ typedef struct ice_config_http_header_tag {
struct ice_config_http_header_tag *next;
} ice_config_http_header_t;
typedef struct ice_config_dir_tag {
char *host;
int touch_interval;
struct ice_config_dir_tag *next;
} ice_config_dir_t;
struct _config_options {
char *type;
char *name;
......@@ -150,6 +142,14 @@ typedef struct _resource {
struct _resource *next;
} resource_t;
typedef struct _yp_directory {
char *url;
int timeout;
int touch_interval;
char *listen_socket_id;
struct _yp_directory *next;
} yp_directory_t;
typedef enum _listener_type_tag {
LISTENER_TYPE_ERROR,
LISTENER_TYPE_NORMAL,
......@@ -219,9 +219,6 @@ struct ice_config_tag {
struct event_registration_tag *event;
int touch_interval;
ice_config_dir_t *dir_list;
char *hostname;
int sane_hostname;
int port;
......@@ -271,10 +268,8 @@ struct ice_config_tag {
int chuid;
char *user;
char *group;
char *yp_url[MAX_YP_DIRECTORIES];
int yp_url_timeout[MAX_YP_DIRECTORIES];
int yp_touch_interval[MAX_YP_DIRECTORIES];
size_t num_yp_directories;
yp_directory_t *yp_directories;
};
typedef struct {
......
......@@ -39,8 +39,6 @@ int main(void)
void _dump_config(ice_config_t *config)
{
ice_config_dir_t *node;
printf("-----\n");
printf("location = %s\n", config->location);
printf("admin = %s\n", config->admin);
......@@ -49,16 +47,6 @@ void _dump_config(ice_config_t *config)
printf("threadpool_size = %d\n", config->threadpool_size);
printf("client_timeout = %d\n", config->client_timeout);
printf("source_password = %s\n", config->source_password);
printf("touch_interval = %d\n", config->touch_interval);
node = config->dir_list;
while (node) {
printf("directory.touch_interval = %d\n", node->touch_interval);
printf("directory.host = %s\n", node->host);
node = node->next;
}
printf("hostname = %s\n", config->hostname);
printf("port = %d\n", config->port);
printf("bind_address = %s\n", config->bind_address);
......
......@@ -53,7 +53,6 @@ struct listensocket_tag {
sock_t sock;
};
static listensocket_t * listensocket_container_get_by_id(listensocket_container_t *self, const char *id);
static int listensocket_container_configure__unlocked(listensocket_container_t *self, const ice_config_t *config);
static int listensocket_container_setup__unlocked(listensocket_container_t *self);
static ssize_t listensocket_container_sockcount__unlocked(listensocket_container_t *self);
......@@ -484,7 +483,7 @@ static ssize_t listensocket_container_sockcount__unlocked(listensocket_container
return count;
}
static listensocket_t * listensocket_container_get_by_id(listensocket_container_t *self, const char *id)
listensocket_t * listensocket_container_get_by_id(listensocket_container_t *self, const char *id)
{
size_t i;
const listener_t *listener;
......
......@@ -22,6 +22,7 @@ int listensocket_container_setup(listensocket_container_
connection_t * listensocket_container_accept(listensocket_container_t *self, int timeout);
int listensocket_container_set_sockcount_cb(listensocket_container_t *self, void (*cb)(size_t count, void *userdata), void *userdata);
ssize_t listensocket_container_sockcount(listensocket_container_t *self);
listensocket_t * listensocket_container_get_by_id(listensocket_container_t *self, const char *id);
REFOBJECT_FORWARD_TYPE(listensocket_t);
......
......@@ -29,6 +29,7 @@
#include "source.h"
#include "cfgfile.h"
#include "stats.h"
#include "listensocket.h"
#ifdef WIN32
#define snprintf _snprintf
......@@ -43,6 +44,7 @@ struct yp_server
unsigned url_timeout;
unsigned touch_interval;
int remove;
char *listen_socket_id;
CURL *curl;
struct ypdata_tag *mounts, *pending_mounts;
......@@ -217,7 +219,6 @@ static ypdata_t *find_yp_mount (ypdata_t *mounts, const char *mount)
void yp_recheck_config (ice_config_t *config)
{
size_t i;
struct yp_server *server;
ICECAST_LOG_DEBUG("Updating YP configuration");
......@@ -234,9 +235,9 @@ void yp_recheck_config (ice_config_t *config)
server_version = strdup (config->server_id);
/* for each yp url in config, check to see if one exists
if not, then add it. */
for (i=0 ; i < config->num_yp_directories; i++)
for (yp_directory_t *yp = config->yp_directories; yp; yp = yp->next)
{
server = find_yp_server (config->yp_url[i]);
server = find_yp_server (yp->url);
if (server == NULL)
{
server = calloc (1, sizeof (struct yp_server));
......@@ -247,9 +248,10 @@ void yp_recheck_config (ice_config_t *config)
break;
}
server->server_id = strdup ((char *)server_version);
server->url = strdup (config->yp_url[i]);
server->url_timeout = config->yp_url_timeout[i];
server->touch_interval = config->yp_touch_interval[i];
server->url = strdup (yp->url);
server->url_timeout = yp->timeout;
server->touch_interval = yp->touch_interval;
server->listen_socket_id = yp->listen_socket_id;
server->curl = icecast_curl_new(server->url, &(server->curl_error[0]));
if (server->curl == NULL)
{
......@@ -563,16 +565,19 @@ static void yp_process_server (struct yp_server *server)
static ypdata_t *create_yp_entry (const char *mount)
static ypdata_t *create_yp_entry (struct yp_server *server, const char *mount)
{
ypdata_t *yp;
char *s;
if (!server)
return NULL;
yp = calloc (1, sizeof (ypdata_t));
do
{
listensocket_t *listen_socket = NULL;
unsigned len = 512;
int ret;
ssize_t ret;
char *url;
mount_proxy *mountproxy = NULL;
ice_config_t *config;
......@@ -595,15 +600,33 @@ static ypdata_t *create_yp_entry (const char *mount)
url = malloc (len);
if (url == NULL)
break;
config = config_get_config();
ret = snprintf (url, len, "http://%s:%d%s", config->hostname, config->port, mount);
if (ret >= (signed)len)
{
s = realloc (url, ++ret);
if (s) url = s;
snprintf (url, ret, "http://%s:%d%s", config->hostname, config->port, mount);
if (server->listen_socket_id) {
listen_socket = listensocket_container_get_by_id(global.listensockets,
server->listen_socket_id);
if (!listen_socket)
ICECAST_LOG_ERROR("Failure to find listen socket with ID %#H, using default.",
server->listen_socket_id);
}
ret = client_get_baseurl(NULL, listen_socket, url, len, NULL, NULL, NULL, mount, NULL);
if (ret >= len) {
// Buffer was too small, allocate a big enough one
char *s = realloc (url, ret + 1);
if (!s) {
refobject_unref(listen_socket);
free(url);
break;
}
url = s;
ret = client_get_baseurl(NULL, listen_socket, url, len, NULL, NULL, NULL, mount, NULL);
}
refobject_unref(listen_socket);
if (ret < 0 || ret >= len)
break;
config = config_get_config();
mountproxy = config_find_mount (config, mount, MOUNT_TYPE_NORMAL);
if (mountproxy && mountproxy->cluster_password)
add_yp_info (yp, mountproxy->cluster_password, YP_CLUSTER_PASSWORD);
......@@ -633,7 +656,7 @@ static void check_servers (void)
if (server->remove)
{
struct yp_server *to_go = server;
ICECAST_LOG_DEBUG("YP server \"%s\"removed", server->url);
ICECAST_LOG_DEBUG("YP server \"%s\" removed", server->url);
*server_p = server->next;
server = server->next;
destroy_yp_server(to_go);
......@@ -662,10 +685,9 @@ static void check_servers (void)
ypdata_t *yp;
source_t *source = node->key;
if (source->yp_public && (yp = create_yp_entry (source->mount)) != NULL)
if (source->yp_public && (yp = create_yp_entry (server, source->mount)) != NULL)
{
ICECAST_LOG_DEBUG("Adding existing mount %s", source->mount);
yp->server = server;
yp->touch_interval = server->touch_interval;
yp->next = server->mounts;
server->mounts = yp;
......@@ -901,7 +923,7 @@ void yp_add (const char *mount)
if (yp == NULL)
{
/* add new ypdata to each servers pending yp */
yp = create_yp_entry (mount);
yp = create_yp_entry (server, mount);
if (yp)
{
ICECAST_LOG_DEBUG("Adding %s to %s", mount, server->url);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment