@@ -63,6 +63,19 @@ static volatile int update_all_mounts = 0;
6363static volatile unsigned int max_interval = 0 ;
6464static mutex_t _slave_mutex ; // protects update_settings, update_all_mounts, max_interval
6565
66+ master_server * master_free (master_server * master )
67+ {
68+ master_server * next = master -> next ;
69+ ICECAST_LOG_DEBUG ("freeing master %s:%d" , master -> server , master -> port );
70+ xmlFree (master -> server );
71+ if (master -> username )
72+ xmlFree (master -> username );
73+ if (master -> password )
74+ xmlFree (master -> password );
75+ free (master );
76+ return next ;
77+ }
78+
6679relay_server * relay_free (relay_server * relay )
6780{
6881 relay_server * next = relay -> next ;
@@ -598,10 +611,8 @@ static void relay_check_streams (relay_server *to_start,
598611}
599612
600613
601- static int update_from_master (ice_config_t * config )
614+ static int update_from_master (master_server * master )
602615{
603- char * master = NULL , * password = NULL , * username = NULL ;
604- int port ;
605616 sock_t mastersock ;
606617 int ret = 0 ;
607618 char buf [256 ];
@@ -610,33 +621,22 @@ static int update_from_master(ice_config_t *config)
610621 char * authheader , * data ;
611622 relay_server * new_relays = NULL , * cleanup_relays ;
612623 int len , count = 1 ;
613- int on_demand ;
614-
615- username = strdup (config -> master_username );
616- if (config -> master_password )
617- password = strdup (config -> master_password );
618-
619- if (config -> master_server )
620- master = strdup (config -> master_server );
621624
622- port = config -> master_server_port ;
623-
624- if (password == NULL || master == NULL || port == 0 )
625+ if (master -> password == NULL || master -> server == NULL || master -> port == 0 )
625626 break ;
626- on_demand = config -> on_demand ;
627627 ret = 1 ;
628628 config_release_config ();
629- mastersock = sock_connect_wto (master , port , 10 );
629+ mastersock = sock_connect_wto (master -> server , master -> port , 10 );
630630
631631 if (mastersock == SOCK_ERROR )
632632 {
633633 ICECAST_LOG_WARN ("Relay slave failed to contact master server to fetch stream list" );
634634 break ;
635635 }
636636
637- len = strlen (username ) + strlen (password ) + 2 ;
637+ len = strlen (master -> username ) + strlen (master -> password ) + 2 ;
638638 authheader = malloc (len );
639- snprintf (authheader , len , "%s:%s" , username , password );
639+ snprintf (authheader , len , "%s:%s" , master -> username , master -> password );
640640 data = util_base64_encode (authheader , len );
641641 sock_write (mastersock ,
642642 "GET /admin/streamlist.txt HTTP/1.0\r\n"
@@ -682,14 +682,14 @@ static int update_from_master(ice_config_t *config)
682682 }
683683 else
684684 {
685- r -> server = (char * )xmlCharStrdup (master );
686- r -> port = port ;
685+ r -> server = (char * )xmlCharStrdup (master -> server );
686+ r -> port = master -> port ;
687687 }
688688
689689 r -> mount = strdup (parsed_uri -> path );
690690 r -> localmount = strdup (parsed_uri -> path );
691691 r -> mp3metadata = 1 ;
692- r -> on_demand = on_demand ;
692+ r -> on_demand = master -> on_demand ;
693693 r -> next = new_relays ;
694694 ICECAST_LOG_DEBUG ("Added relay host=\"%s\", port=%d, mount=\"%s\"" , r -> server , r -> port , r -> mount );
695695 new_relays = r ;
@@ -708,12 +708,24 @@ static int update_from_master(ice_config_t *config)
708708
709709 } while (0 );
710710
711- if (master )
712- free (master );
713- if (username )
714- free (username );
715- if (password )
716- free (password );
711+ return ret ;
712+ }
713+
714+ static int update_from_master_legacy (ice_config_t * config )
715+ {
716+ master_server * master = calloc (1 , sizeof (master_server ));
717+ int ret = 0 ;
718+
719+ if (master ) {
720+ master -> username = strdup (config -> master_username );
721+ if (config -> master_password )
722+ master -> password = strdup (config -> master_password );
723+ if (config -> master_server )
724+ master -> server = strdup (config -> master_server );
725+ master -> port = config -> master_server_port ;
726+ ret = update_from_master (master );
727+ master_free (master );
728+ }
717729
718730 return ret ;
719731}
@@ -759,6 +771,7 @@ static void *_slave_thread(void *arg)
759771 thread_mutex_lock (& _slave_mutex );
760772 if (max_interval <= interval )
761773 {
774+ master_server * master ;
762775 ICECAST_LOG_DEBUG ("checking master stream list" );
763776 config = config_get_config ();
764777
@@ -767,9 +780,16 @@ static void *_slave_thread(void *arg)
767780 interval = 0 ;
768781 max_interval = config -> master_update_interval ;
769782 thread_mutex_unlock (& _slave_mutex );
783+
784+ /* update all non-legacy master servers */
785+ master = config -> master ;
786+ while (master ) {
787+ update_from_master (master );
788+ master = master -> next ;
789+ }
770790
771791 /* the connection could take some time, so the lock can drop */
772- if (update_from_master (config ))
792+ if (update_from_master_legacy (config ))
773793 config = config_get_config ();
774794
775795 thread_mutex_lock (& (config_locks ()-> relay_lock ));
0 commit comments