Commit fd4f2827 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Cleanup: Seperated relay config from runtime data

parent 75314c2b
...@@ -622,13 +622,9 @@ void config_clear(ice_config_t *c) ...@@ -622,13 +622,9 @@ void config_clear(ice_config_t *c)
{ {
ice_config_dir_t *dirnode, ice_config_dir_t *dirnode,
*nextdirnode; *nextdirnode;
relay_server *relay,
*nextrelay;
mount_proxy *mount, mount_proxy *mount,
*nextmount; *nextmount;
#ifdef USE_YP size_t i;
int i;
#endif
free(c->config_filename); free(c->config_filename);
...@@ -666,15 +662,10 @@ void config_clear(ice_config_t *c) ...@@ -666,15 +662,10 @@ void config_clear(ice_config_t *c)
while ((c->listen_sock = config_clear_listener(c->listen_sock))); while ((c->listen_sock = config_clear_listener(c->listen_sock)));
thread_mutex_lock(&(_locks.relay_lock)); thread_mutex_lock(&(_locks.relay_lock));
relay = c->relay; for (i = 0; i < c->relay_length; i++) {
while (relay) { relay_config_free(c->relay[i]);
nextrelay = relay->next;
xmlFree(relay->server);
xmlFree(relay->mount);
xmlFree(relay->localmount);
free(relay);
relay = nextrelay;
} }
free(c->relay);
thread_mutex_unlock(&(_locks.relay_lock)); thread_mutex_unlock(&(_locks.relay_lock));
mount = c->mounts; mount = c->mounts;
...@@ -694,10 +685,8 @@ void config_clear(ice_config_t *c) ...@@ -694,10 +685,8 @@ void config_clear(ice_config_t *c)
dirnode = nextdirnode; dirnode = nextdirnode;
} }
#ifdef USE_YP #ifdef USE_YP
i = 0; for (i = 0; i < c->num_yp_directories; i++) {
while (i < c->num_yp_directories) {
xmlFree(c->yp_url[i]); xmlFree(c->yp_url[i]);
i++;
} }
#endif #endif
...@@ -1690,26 +1679,21 @@ static void _parse_relay(xmlDocPtr doc, ...@@ -1690,26 +1679,21 @@ static void _parse_relay(xmlDocPtr doc,
ice_config_t *configuration) ice_config_t *configuration)
{ {
char *tmp; char *tmp;
relay_server *relay = calloc(1, sizeof(relay_server)); relay_config_t *relay = calloc(1, sizeof(relay_config_t));
relay_server *current = configuration->relay; relay_config_t **n = realloc(configuration->relay, sizeof(*configuration->relay)*(configuration->relay_length + 1));
relay_server *last = NULL;
while(current) { if (!n) {
last = current; ICECAST_LOG_ERROR("Can not allocate memory for additional relay.");
current = current->next; return;
} }
if (last) { configuration->relay = n;
last->next = relay; configuration->relay[configuration->relay_length++] = relay;
} else {
configuration->relay = relay;
}
relay->next = NULL; relay->upstream_default.mp3metadata = 1;
relay->mp3metadata = 1; relay->on_demand = configuration->on_demand;
relay->on_demand = configuration->on_demand; relay->upstream_default.server = (char *) xmlCharStrdup("127.0.0.1");
relay->server = (char *) xmlCharStrdup("127.0.0.1"); relay->upstream_default.mount = (char *) xmlCharStrdup("/");
relay->mount = (char *) xmlCharStrdup("/");
do { do {
if (node == NULL) if (node == NULL)
...@@ -1718,16 +1702,16 @@ static void _parse_relay(xmlDocPtr doc, ...@@ -1718,16 +1702,16 @@ static void _parse_relay(xmlDocPtr doc,
continue; continue;
if (xmlStrcmp(node->name, XMLSTR("server")) == 0) { if (xmlStrcmp(node->name, XMLSTR("server")) == 0) {
if (relay->server) if (relay->upstream_default.server)
xmlFree(relay->server); xmlFree(relay->upstream_default.server);
relay->server = (char *)xmlNodeListGetString(doc, relay->upstream_default.server = (char *)xmlNodeListGetString(doc,
node->xmlChildrenNode, 1); node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("port")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("port")) == 0) {
__read_int(doc, node, &relay->port, "<port> setting must not be empty."); __read_int(doc, node, &relay->upstream_default.port, "<port> setting must not be empty.");
} else if (xmlStrcmp(node->name, XMLSTR("mount")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("mount")) == 0) {
if (relay->mount) if (relay->upstream_default.mount)
xmlFree(relay->mount); xmlFree(relay->upstream_default.mount);
relay->mount = (char *)xmlNodeListGetString(doc, relay->upstream_default.mount = (char *)xmlNodeListGetString(doc,
node->xmlChildrenNode, 1); node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("local-mount")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("local-mount")) == 0) {
if (relay->localmount) if (relay->localmount)
...@@ -1736,18 +1720,18 @@ static void _parse_relay(xmlDocPtr doc, ...@@ -1736,18 +1720,18 @@ static void _parse_relay(xmlDocPtr doc,
node->xmlChildrenNode, 1); node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("relay-shoutcast-metadata")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("relay-shoutcast-metadata")) == 0) {
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
relay->mp3metadata = util_str_to_bool(tmp); relay->upstream_default.mp3metadata = util_str_to_bool(tmp);
if(tmp) if(tmp)
xmlFree(tmp); xmlFree(tmp);
} else if (xmlStrcmp(node->name, XMLSTR("username")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("username")) == 0) {
if (relay->username) if (relay->upstream_default.username)
xmlFree(relay->username); xmlFree(relay->upstream_default.username);
relay->username = (char *)xmlNodeListGetString(doc, relay->upstream_default.username = (char *)xmlNodeListGetString(doc,
node->xmlChildrenNode, 1); node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("password")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("password")) == 0) {
if (relay->password) if (relay->upstream_default.password)
xmlFree(relay->password); xmlFree(relay->upstream_default.password);
relay->password = (char *)xmlNodeListGetString(doc, relay->upstream_default.password = (char *)xmlNodeListGetString(doc,
node->xmlChildrenNode, 1); node->xmlChildrenNode, 1);
} else if (xmlStrcmp(node->name, XMLSTR("on-demand")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("on-demand")) == 0) {
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
...@@ -1755,14 +1739,14 @@ static void _parse_relay(xmlDocPtr doc, ...@@ -1755,14 +1739,14 @@ static void _parse_relay(xmlDocPtr doc,
if (tmp) if (tmp)
xmlFree(tmp); xmlFree(tmp);
} else if (xmlStrcmp(node->name, XMLSTR("bind")) == 0) { } else if (xmlStrcmp(node->name, XMLSTR("bind")) == 0) {
if (relay->bind) if (relay->upstream_default.bind)
xmlFree(relay->bind); xmlFree(relay->upstream_default.bind);
relay->bind = (char *)xmlNodeListGetString(doc, relay->upstream_default.bind = (char *)xmlNodeListGetString(doc,
node->xmlChildrenNode, 1); node->xmlChildrenNode, 1);
} }
} while ((node = node->next)); } while ((node = node->next));
if (relay->localmount == NULL) if (relay->localmount == NULL)
relay->localmount = (char *)xmlStrdup(XMLSTR(relay->mount)); relay->localmount = (char *)xmlStrdup(XMLSTR(relay->upstream_default.mount));
} }
static void _parse_listen_socket(xmlDocPtr doc, static void _parse_listen_socket(xmlDocPtr doc,
......
...@@ -173,6 +173,24 @@ typedef struct _config_tls_context { ...@@ -173,6 +173,24 @@ typedef struct _config_tls_context {
char *cipher_list; char *cipher_list;
} config_tls_context_t; } config_tls_context_t;
typedef struct {
char *server;
int port;
char *mount;
char *username;
char *password;
char *bind;
int mp3metadata;
} relay_config_upstream_t;
typedef struct {
char *localmount;
int on_demand;
size_t upstreams;
relay_config_upstream_t *upstream;
relay_config_upstream_t upstream_default;
} relay_config_t;
struct ice_config_tag { struct ice_config_tag {
char *config_filename; char *config_filename;
...@@ -219,7 +237,8 @@ struct ice_config_tag { ...@@ -219,7 +237,8 @@ struct ice_config_tag {
/* is TLS supported by the server? */ /* is TLS supported by the server? */
int tls_ok; int tls_ok;
relay_server *relay; size_t relay_length;
relay_config_t **relay;
mount_proxy *mounts; mount_proxy *mounts;
......
...@@ -36,9 +36,9 @@ typedef struct ice_global_tag ...@@ -36,9 +36,9 @@ typedef struct ice_global_tag
avl_tree *source_tree; avl_tree *source_tree;
/* for locally defined relays */ /* for locally defined relays */
relay_server *relays; relay_t *relays;
/* relays retrieved from master */ /* relays retrieved from master */
relay_server *master_relays; relay_t *master_relays;
module_container_t *modulecontainer; module_container_t *modulecontainer;
......
...@@ -90,7 +90,7 @@ typedef enum { ...@@ -90,7 +90,7 @@ typedef enum {
/* ---[ slave.[ch] ]--- */ /* ---[ slave.[ch] ]--- */
typedef struct _relay_server relay_server; typedef struct relay_tag relay_t;
/* ---[ module.[ch] ]--- */ /* ---[ module.[ch] ]--- */
......
This diff is collapsed.
...@@ -15,29 +15,13 @@ ...@@ -15,29 +15,13 @@
#include "common/thread/thread.h" #include "common/thread/thread.h"
#include "icecasttypes.h" #include "icecasttypes.h"
#include "cfgfile.h"
struct _relay_server {
char *server;
int port;
char *mount;
char *username;
char *password;
char *localmount;
char *bind;
source_t *source;
int mp3metadata;
int on_demand;
int running;
int cleanup;
time_t start;
thread_type *thread;
relay_server *next;
};
void slave_initialize(void); void slave_initialize(void);
void slave_shutdown(void); void slave_shutdown(void);
void slave_update_all_mounts (void); void slave_update_all_mounts (void);
void slave_rebuild_mounts (void); void slave_rebuild_mounts (void);
relay_server *relay_free (relay_server *relay); void relay_config_free (relay_config_t *relay);
relay_t *relay_free (relay_t *relay);
#endif /* __SLAVE_H__ */ #endif /* __SLAVE_H__ */
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