diff --git a/channels.c b/channels.c index 628d12d3..8d16bef6 100644 --- a/channels.c +++ b/channels.c @@ -112,8 +112,7 @@ channel_group_find(const char *name, int create) TAILQ_INSERT_TAIL(&all_channel_groups, tcg, tcg_global_link); - if(!dontwritesettings) - channel_settings_write(); + channel_settings_write(); return tcg; } @@ -132,8 +131,7 @@ channel_set_group(th_channel_t *ch, th_channel_group_t *tcg) ch->ch_group = tcg; TAILQ_INSERT_SORTED(&tcg->tcg_channels, ch, ch_group_link, channelcmp); - if(!dontwritesettings) - channel_settings_write(); + channel_settings_write(); } /** @@ -392,8 +390,9 @@ channel_settings_write(void) FILE *fp; th_channel_group_t *tcg; th_channel_t *ch; + th_transport_t *t; - if(settingsfile == NULL) + if(dontwritesettings || startupcounter > 0 || settingsfile == NULL) return; fp = fopen(settingsfile, "w+"); @@ -404,6 +403,9 @@ channel_settings_write(void) fprintf(fp, "channel-group {\n" "\tname = %s\n", tcg->tcg_name); TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) { + if(LIST_FIRST(&ch->ch_transports) == NULL) + continue; + fprintf(fp, "\tchannel {\n" "\t\tname = %s\n", ch->ch_name); if(ch->ch_teletext_rundown) @@ -412,5 +414,19 @@ channel_settings_write(void) } fprintf(fp, "}\n"); } + + LIST_FOREACH(t, &all_transports, tht_global_link) { + if(t->tht_channel == NULL) + continue; + + fprintf(fp, "transport {\n" + "\tuniquename = %s\n" + "\tchannel = %s\n" + "\tprio = %d\n" + "}\n", + t->tht_uniquename, + t->tht_channel->ch_name, + t->tht_prio); + } fclose(fp); } diff --git a/htmlui.c b/htmlui.c index fa6dbce7..835fe7ee 100644 --- a/htmlui.c +++ b/htmlui.c @@ -460,6 +460,9 @@ page_root(http_connection_t *hc, const char *remain, void *opaque) tcp_qprintf(&tq, "
"); TAILQ_FOREACH(ch, &tcg->tcg_channels, ch_group_link) { + if(LIST_FIRST(&ch->ch_transports) == NULL) + continue; + box_top(&tq, "box"); tcp_qprintf(&tq, "
"); @@ -1550,11 +1553,11 @@ static int page_updatechannel(http_connection_t *hc, const char *remain, void *opaque) { th_channel_t *ch, *ch2; - th_transport_t *t; + th_transport_t *t, **tv; th_channel_group_t *tcg; const char *grp, *s; char buf[100]; - int pri; + int pri, i, n; if(!html_verify_access(hc, "admin")) return HTTP_STATUS_UNAUTHORIZED; @@ -1587,7 +1590,20 @@ page_updatechannel(http_connection_t *hc, const char *remain, void *opaque) channel_set_group(ch, tcg); } - LIST_FOREACH(t, &ch->ch_transports, tht_channel_link) { + /* We are going to rearrange listorder by changing priority, so we + cannot just loop the list */ + + n = 0; + LIST_FOREACH(t, &ch->ch_transports, tht_channel_link) + n++; + + tv = alloca(n * sizeof(th_transport_t *)); + n = 0; + LIST_FOREACH(t, &ch->ch_transports, tht_channel_link) + tv[n++] = t; + + for(i = 0; i < n; i++) { + t = tv[i]; s = http_arg_get(&hc->hc_url_args, t->tht_uniquename); if(s != NULL) { pri = atoi(s); @@ -1597,8 +1613,6 @@ page_updatechannel(http_connection_t *hc, const char *remain, void *opaque) } } - channel_settings_write(); - snprintf(buf, sizeof(buf), "/editchannel/%d", ch->ch_tag); http_redirect(hc, buf); return 0; diff --git a/main.c b/main.c index a29f2069..7ecda1f1 100644 --- a/main.c +++ b/main.c @@ -203,6 +203,8 @@ main(int argc, char **argv) while(running) { if(startupcounter == 0) { + channel_settings_write(); + startupcounter = -1; syslog(LOG_NOTICE, "Initial input setup completed, starting output modules"); diff --git a/transports.c b/transports.c index 48da6471..a7262739 100644 --- a/transports.c +++ b/transports.c @@ -53,6 +53,7 @@ #include "pes.h" #include "buffer.h" #include "plugin.h" +#include "channels.h" static dtimer_t transport_monitor_timer; @@ -387,11 +388,28 @@ transport_set_channel(th_transport_t *t, th_channel_t *ch) th_stream_t *st; char *chname; const char *n; - + config_entry_t *ce; char pid[30]; char lang[30]; assert(t->tht_uniquename != NULL); + + TAILQ_FOREACH(ce, &settings_list, ce_link) { + if(ce->ce_type != CFG_SUB || strcasecmp("transport", ce->ce_key)) + continue; + + n = config_get_str_sub(&ce->ce_sub, "uniquename", NULL); + if(n != NULL && !strcmp(n, t->tht_uniquename)) + break; + } + + if(ce != NULL) { + t->tht_prio = atoi(config_get_str_sub(&ce->ce_sub, "prio", "0")); + n = config_get_str_sub(&ce->ce_sub, "channel", NULL); + if(n != NULL) + ch = channel_find(n, 1, NULL); + } + t->tht_channel = ch; LIST_INSERT_SORTED(&ch->ch_transports, t, tht_channel_link, transportcmp); @@ -437,6 +455,7 @@ transport_set_priority(th_transport_t *t, int prio) LIST_REMOVE(t, tht_channel_link); t->tht_prio = prio; LIST_INSERT_SORTED(&ch->ch_transports, t, tht_channel_link, transportcmp); + channel_settings_write(); } @@ -449,4 +468,5 @@ transport_move(th_transport_t *t, th_channel_t *ch) LIST_REMOVE(t, tht_channel_link); t->tht_channel = ch; LIST_INSERT_SORTED(&ch->ch_transports, t, tht_channel_link, transportcmp); + channel_settings_write(); }