Commit 6d3bf28b authored by Marvin Scholz's avatar Marvin Scholz

Update: Use linked list for YP config entries

This removes the limit of 25 YP directory entries by using a linked
list like with most other config entries.
parent 4284ea5b
......@@ -631,6 +631,18 @@ static void config_clear_resource(resource_t *resource)
}
}
static void config_clear_yp_directories(yp_directory_t *yp_dir)
{
yp_directory_t *next_yp_dir;
while (yp_dir) {
next_yp_dir = yp_dir->next;
free(yp_dir->url);
free(yp_dir);
yp_dir = next_yp_dir;
}
}
listener_t *config_clear_listener(listener_t *listener)
{
listener_t *next = NULL;
......@@ -705,9 +717,7 @@ void config_clear(ice_config_t *c)
config_clear_resource(c->resources);
#ifdef USE_YP
for (i = 0; i < c->num_yp_directories; i++) {
xmlFree(c->yp_url[i]);
}
config_clear_yp_directories(c->yp_directories);
#endif
config_clear_http_header(c->http_headers);
......@@ -908,8 +918,6 @@ static void _set_defaults(ice_config_t *configuration)
->user = NULL;
configuration
->group = NULL;
configuration
->num_yp_directories = 0;
/* default to a typical prebuffer size used by clients */
configuration
->burst_size = CONFIG_DEFAULT_BURST_SIZE;
......@@ -2037,10 +2045,15 @@ static void _parse_oldstyle_directory(xmlDocPtr doc,
xmlNodePtr node,
ice_config_t *configuration)
{
if (configuration->num_yp_directories >= MAX_YP_DIRECTORIES) {
ICECAST_LOG_ERROR("Maximum number of yp directories exceeded!");
yp_directory_t *yp_dir,
*current, *last;
yp_dir = calloc(1, sizeof(*yp_dir));
if (yp_dir == NULL) {
ICECAST_LOG_ERROR("Can not allocate memory for YP directory entry.");
return;
}
do {
if (node == NULL)
break;
......@@ -2048,19 +2061,31 @@ static void _parse_oldstyle_directory(xmlDocPtr doc,
continue;
if (xmlStrcmp(node->name, XMLSTR("yp-url")) == 0) {
if (configuration->yp_url[configuration->num_yp_directories])
xmlFree(configuration->yp_url[configuration->num_yp_directories]);
configuration->yp_url[configuration->num_yp_directories] =
(char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (yp_dir->url)
xmlFree(yp_dir->url);
yp_dir->url = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("yp-url-timeout")) == 0) {
__read_int(doc, node, &configuration->yp_url_timeout[configuration->num_yp_directories], "<yp-url-timeout> must not be empty.");
__read_int(doc, node, &yp_dir->timeout, "<yp-url-timeout> must not be empty.");
} else if (xmlStrcmp(node->name, XMLSTR("touch-interval")) == 0) {
__read_int(doc, node, &configuration->yp_touch_interval[configuration->num_yp_directories], "<touch-interval> must not be empty.");
__read_int(doc, node, &yp_dir->touch_interval, "<touch-interval> must not be empty.");
}
} while ((node = node->next));
if (configuration->yp_url[configuration->num_yp_directories] == NULL)
if (yp_dir->url == NULL)
return;
configuration->num_yp_directories++;
/* Append YP directory entry to the global list */
current = configuration->yp_directories;
last = NULL;
while (current) {
last = current;
current = current->next;
}
if (last) {
last->next = yp_dir;
} else {
configuration->yp_directories = yp_dir;
}
}
static void _parse_resource(xmlDocPtr doc,
......
......@@ -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"
......@@ -144,6 +142,13 @@ typedef struct _resource {
struct _resource *next;
} resource_t;
typedef struct _yp_directory {
char *url;
int timeout;
int touch_interval;
struct _yp_directory *next;
} yp_directory_t;
typedef enum _listener_type_tag {
LISTENER_TYPE_ERROR,
LISTENER_TYPE_NORMAL,
......@@ -262,10 +267,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 {
......
......@@ -217,7 +217,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 +233,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 +246,9 @@ 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->curl = icecast_curl_new(server->url, &(server->curl_error[0]));
if (server->curl == NULL)
{
......
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