2007-08-09 15:42:01 +00:00
|
|
|
|
/*
|
|
|
|
|
* tvheadend, channel functions
|
|
|
|
|
* Copyright (C) 2007 Andreas <EFBFBD>man
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <pthread.h>
|
2007-12-07 07:53:27 +00:00
|
|
|
|
#include <assert.h>
|
2007-08-09 15:42:01 +00:00
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <fcntl.h>
|
2007-11-27 17:22:54 +00:00
|
|
|
|
#include <ctype.h>
|
2007-08-09 15:42:01 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2008-01-28 20:40:35 +00:00
|
|
|
|
#include <dirent.h>
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2008-08-25 20:37:19 +00:00
|
|
|
|
#include <libhts/htssettings.h>
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
|
|
|
|
#include "tvhead.h"
|
2007-12-02 11:12:58 +00:00
|
|
|
|
#include "psi.h"
|
2007-08-09 15:42:01 +00:00
|
|
|
|
#include "channels.h"
|
|
|
|
|
#include "transports.h"
|
2008-05-03 06:00:07 +00:00
|
|
|
|
#include "epg.h"
|
2008-09-05 16:02:41 +00:00
|
|
|
|
#include "xmltv.h"
|
2008-09-06 19:08:10 +00:00
|
|
|
|
#include "dtable.h"
|
2008-09-09 17:31:02 +00:00
|
|
|
|
#include "notify.h"
|
2008-09-23 19:38:53 +00:00
|
|
|
|
#include "dvr/dvr.h"
|
2008-09-27 13:24:00 +00:00
|
|
|
|
#include "htsp.h"
|
2008-09-05 16:02:41 +00:00
|
|
|
|
|
|
|
|
|
struct channel_list channels_not_xmltv_mapped;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
struct channel_tree channel_name_tree;
|
|
|
|
|
static struct channel_tree channel_identifier_tree;
|
2008-09-07 08:54:16 +00:00
|
|
|
|
struct channel_tag_queue channel_tags;
|
|
|
|
|
|
|
|
|
|
static void channel_tag_map(channel_t *ch, channel_tag_t *ct, int check);
|
|
|
|
|
static channel_tag_t *channel_tag_find(const char *id, int create);
|
2009-02-25 18:21:05 +00:00
|
|
|
|
static void channel_tag_mapping_destroy(channel_tag_mapping_t *ctm,
|
|
|
|
|
int flags);
|
|
|
|
|
|
|
|
|
|
#define CTM_DESTROY_UPDATE_TAG 0x1
|
|
|
|
|
#define CTM_DESTROY_UPDATE_CHANNEL 0x2
|
|
|
|
|
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2008-09-09 17:31:02 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
channel_list_changed(void)
|
|
|
|
|
{
|
|
|
|
|
htsmsg_t *m = htsmsg_create();
|
|
|
|
|
htsmsg_add_u32(m, "reload", 1);
|
|
|
|
|
notify_by_msg("channels", m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-06 15:08:34 +00:00
|
|
|
|
static int
|
2008-08-25 20:37:19 +00:00
|
|
|
|
dictcmp(const char *a, const char *b)
|
2007-12-06 15:08:34 +00:00
|
|
|
|
{
|
2008-08-25 20:37:19 +00:00
|
|
|
|
long int da, db;
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
switch((*a >= '0' && *a <= '9' ? 1 : 0)|(*b >= '0' && *b <= '9' ? 2 : 0)) {
|
|
|
|
|
case 0: /* 0: a is not a digit, nor is b */
|
|
|
|
|
if(*a != *b)
|
|
|
|
|
return *(const unsigned char *)a - *(const unsigned char *)b;
|
|
|
|
|
if(*a == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
a++;
|
|
|
|
|
b++;
|
|
|
|
|
break;
|
|
|
|
|
case 1: /* 1: a is a digit, b is not */
|
|
|
|
|
case 2: /* 2: a is not a digit, b is */
|
|
|
|
|
return *(const unsigned char *)a - *(const unsigned char *)b;
|
|
|
|
|
case 3: /* both are digits, switch to integer compare */
|
|
|
|
|
da = strtol(a, (char **)&a, 10);
|
|
|
|
|
db = strtol(b, (char **)&b, 10);
|
|
|
|
|
if(da != db)
|
|
|
|
|
return da - db;
|
|
|
|
|
break;
|
2007-12-06 15:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static int
|
2008-08-25 20:37:19 +00:00
|
|
|
|
channelcmp(const channel_t *a, const channel_t *b)
|
2007-12-06 15:08:34 +00:00
|
|
|
|
{
|
2008-08-25 20:37:19 +00:00
|
|
|
|
return dictcmp(a->ch_name, b->ch_name);
|
2007-12-06 15:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
chidcmp(const channel_t *a, const channel_t *b)
|
|
|
|
|
{
|
|
|
|
|
return a->ch_id - b->ch_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-02 14:31:28 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2008-05-03 05:13:31 +00:00
|
|
|
|
static void
|
2008-05-03 06:00:07 +00:00
|
|
|
|
channel_set_name(channel_t *ch, const char *name)
|
2007-08-09 15:42:01 +00:00
|
|
|
|
{
|
2008-08-25 20:37:19 +00:00
|
|
|
|
channel_t *x;
|
2007-11-27 17:22:54 +00:00
|
|
|
|
const char *n2;
|
|
|
|
|
int l, i;
|
|
|
|
|
char *cp, c;
|
2007-08-09 15:42:01 +00:00
|
|
|
|
|
2008-05-03 05:13:31 +00:00
|
|
|
|
free((void *)ch->ch_name);
|
|
|
|
|
free((void *)ch->ch_sname);
|
2007-08-16 10:59:06 +00:00
|
|
|
|
|
2007-08-09 15:42:01 +00:00
|
|
|
|
ch->ch_name = strdup(name);
|
2007-11-27 17:22:54 +00:00
|
|
|
|
|
|
|
|
|
l = strlen(name);
|
|
|
|
|
ch->ch_sname = cp = malloc(l + 1);
|
|
|
|
|
|
2008-10-14 18:56:15 +00:00
|
|
|
|
n2 = strdup(name);
|
2007-11-27 17:22:54 +00:00
|
|
|
|
|
|
|
|
|
for(i = 0; i < strlen(n2); i++) {
|
|
|
|
|
c = tolower(n2[i]);
|
|
|
|
|
if(isalnum(c))
|
|
|
|
|
*cp++ = c;
|
|
|
|
|
else
|
2008-09-05 16:02:41 +00:00
|
|
|
|
*cp++ = '_';
|
2007-11-27 17:22:54 +00:00
|
|
|
|
}
|
|
|
|
|
*cp = 0;
|
|
|
|
|
|
2007-11-28 08:08:46 +00:00
|
|
|
|
free((void *)n2);
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
x = RB_INSERT_SORTED(&channel_name_tree, ch, ch_name_link, channelcmp);
|
2008-08-25 20:37:19 +00:00
|
|
|
|
assert(x == NULL);
|
2008-09-09 17:31:02 +00:00
|
|
|
|
|
|
|
|
|
/* Notify clients */
|
|
|
|
|
channel_list_changed();
|
|
|
|
|
|
2008-05-03 05:13:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
|
2008-05-03 05:13:31 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2008-08-26 14:15:33 +00:00
|
|
|
|
static channel_t *
|
|
|
|
|
channel_create(const char *name)
|
2008-05-03 05:13:31 +00:00
|
|
|
|
{
|
2008-08-26 14:15:33 +00:00
|
|
|
|
channel_t *ch, *x;
|
2008-09-21 10:57:43 +00:00
|
|
|
|
xmltv_channel_t *xc;
|
2008-08-26 14:15:33 +00:00
|
|
|
|
int id;
|
|
|
|
|
|
|
|
|
|
ch = RB_LAST(&channel_identifier_tree);
|
|
|
|
|
if(ch == NULL) {
|
|
|
|
|
id = 1;
|
|
|
|
|
} else {
|
|
|
|
|
id = ch->ch_id + 1;
|
|
|
|
|
}
|
2008-05-03 05:13:31 +00:00
|
|
|
|
|
2008-05-03 06:00:07 +00:00
|
|
|
|
ch = calloc(1, sizeof(channel_t));
|
2008-09-02 20:32:54 +00:00
|
|
|
|
RB_INIT(&ch->ch_epg_events);
|
2008-09-05 16:02:41 +00:00
|
|
|
|
LIST_INSERT_HEAD(&channels_not_xmltv_mapped, ch, ch_xc_link);
|
2008-05-03 05:13:31 +00:00
|
|
|
|
channel_set_name(ch, name);
|
2007-12-02 14:31:28 +00:00
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
ch->ch_id = id;
|
|
|
|
|
x = RB_INSERT_SORTED(&channel_identifier_tree, ch,
|
|
|
|
|
ch_identifier_link, chidcmp);
|
2008-09-21 10:57:43 +00:00
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
assert(x == NULL);
|
2008-09-21 10:57:43 +00:00
|
|
|
|
|
|
|
|
|
if((xc = xmltv_channel_find_by_displayname(name)) != NULL) {
|
|
|
|
|
channel_set_xmltv_source(ch, xc);
|
|
|
|
|
if(xc->xc_icon != NULL)
|
|
|
|
|
channel_set_icon(ch, xc->xc_icon);
|
|
|
|
|
}
|
2008-09-27 13:24:00 +00:00
|
|
|
|
|
|
|
|
|
htsp_channel_add(ch);
|
2007-08-09 15:42:01 +00:00
|
|
|
|
return ch;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-02 14:31:28 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2008-08-26 14:15:33 +00:00
|
|
|
|
channel_t *
|
|
|
|
|
channel_find_by_name(const char *name, int create)
|
2007-08-09 15:42:01 +00:00
|
|
|
|
{
|
2008-08-26 14:15:33 +00:00
|
|
|
|
channel_t skel, *ch;
|
2008-08-29 15:29:33 +00:00
|
|
|
|
|
|
|
|
|
lock_assert(&global_lock);
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
skel.ch_name = (char *)name;
|
|
|
|
|
ch = RB_FIND(&channel_name_tree, &skel, ch_name_link, channelcmp);
|
|
|
|
|
if(ch != NULL || create == 0)
|
|
|
|
|
return ch;
|
|
|
|
|
return channel_create(name);
|
2007-08-09 15:42:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-12-02 14:31:28 +00:00
|
|
|
|
/**
|
2008-08-26 14:15:33 +00:00
|
|
|
|
*
|
2007-12-02 14:31:28 +00:00
|
|
|
|
*/
|
2008-05-03 06:00:07 +00:00
|
|
|
|
channel_t *
|
2008-08-26 14:15:33 +00:00
|
|
|
|
channel_find_by_identifier(int id)
|
2007-08-09 15:42:01 +00:00
|
|
|
|
{
|
2008-08-26 14:15:33 +00:00
|
|
|
|
channel_t skel, *ch;
|
2008-08-29 15:29:33 +00:00
|
|
|
|
|
|
|
|
|
lock_assert(&global_lock);
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
skel.ch_id = id;
|
|
|
|
|
ch = RB_FIND(&channel_identifier_tree, &skel, ch_identifier_link, chidcmp);
|
|
|
|
|
return ch;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-02 14:31:28 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2008-09-05 16:02:41 +00:00
|
|
|
|
static void
|
|
|
|
|
channel_load_one(htsmsg_t *c, int id)
|
|
|
|
|
{
|
|
|
|
|
channel_t *ch;
|
|
|
|
|
const char *s;
|
|
|
|
|
const char *name = htsmsg_get_str(c, "name");
|
2008-09-07 08:54:16 +00:00
|
|
|
|
htsmsg_t *tags;
|
|
|
|
|
htsmsg_field_t *f;
|
|
|
|
|
channel_tag_t *ct;
|
2008-09-05 16:02:41 +00:00
|
|
|
|
|
|
|
|
|
if(name == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ch = calloc(1, sizeof(channel_t));
|
|
|
|
|
ch->ch_id = id;
|
|
|
|
|
if(RB_INSERT_SORTED(&channel_identifier_tree, ch,
|
|
|
|
|
ch_identifier_link, chidcmp)) {
|
|
|
|
|
/* ID collision, should not happen unless there is something
|
|
|
|
|
wrong in the setting storage */
|
|
|
|
|
free(ch);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RB_INIT(&ch->ch_epg_events);
|
|
|
|
|
|
|
|
|
|
channel_set_name(ch, name);
|
|
|
|
|
|
|
|
|
|
if((s = htsmsg_get_str(c, "xmltv-channel")) != NULL &&
|
2008-09-21 11:03:08 +00:00
|
|
|
|
(ch->ch_xc = xmltv_channel_find(s, 0)) != NULL) {
|
2008-09-05 16:02:41 +00:00
|
|
|
|
LIST_INSERT_HEAD(&ch->ch_xc->xc_channels, ch, ch_xc_link);
|
2008-09-21 11:03:08 +00:00
|
|
|
|
tvh_str_update(&ch->ch_icon, ch->ch_xc->xc_icon);
|
|
|
|
|
} else {
|
2008-09-05 16:02:41 +00:00
|
|
|
|
LIST_INSERT_HEAD(&channels_not_xmltv_mapped, ch, ch_xc_link);
|
2008-09-21 11:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tvh_str_update(&ch->ch_icon, htsmsg_get_str(c, "icon"));
|
2008-09-07 08:54:16 +00:00
|
|
|
|
|
|
|
|
|
if((tags = htsmsg_get_array(c, "tags")) != NULL) {
|
|
|
|
|
HTSMSG_FOREACH(f, tags) {
|
|
|
|
|
if(f->hmf_type == HMF_STR &&
|
|
|
|
|
(ct = channel_tag_find(f->hmf_str, 0)) != NULL) {
|
|
|
|
|
channel_tag_map(ch, ct, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-09-05 16:02:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2008-08-26 14:15:33 +00:00
|
|
|
|
channels_load(void)
|
2007-11-20 07:58:09 +00:00
|
|
|
|
{
|
2008-09-05 16:02:41 +00:00
|
|
|
|
htsmsg_t *l, *c;
|
|
|
|
|
htsmsg_field_t *f;
|
|
|
|
|
|
|
|
|
|
if((l = hts_settings_load("channels")) != NULL) {
|
|
|
|
|
HTSMSG_FOREACH(f, l) {
|
|
|
|
|
if((c = htsmsg_get_msg_by_field(f)) == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
channel_load_one(c, atoi(f->hmf_name));
|
|
|
|
|
}
|
2008-09-26 05:07:01 +00:00
|
|
|
|
htsmsg_destroy(l);
|
2008-09-05 16:02:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-20 07:58:09 +00:00
|
|
|
|
|
2008-01-28 20:40:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* Write out a config file for a channel
|
|
|
|
|
*/
|
2008-08-25 20:37:19 +00:00
|
|
|
|
static void
|
|
|
|
|
channel_save(channel_t *ch)
|
2008-01-28 20:40:35 +00:00
|
|
|
|
{
|
2008-08-25 20:37:19 +00:00
|
|
|
|
htsmsg_t *m = htsmsg_create();
|
2008-09-07 08:54:16 +00:00
|
|
|
|
htsmsg_t *tags;
|
|
|
|
|
channel_tag_mapping_t *ctm;
|
2008-08-29 15:29:33 +00:00
|
|
|
|
|
|
|
|
|
lock_assert(&global_lock);
|
|
|
|
|
|
2008-09-05 16:02:41 +00:00
|
|
|
|
htsmsg_add_str(m, "name", ch->ch_name);
|
|
|
|
|
|
|
|
|
|
if(ch->ch_xc != NULL)
|
|
|
|
|
htsmsg_add_str(m, "xmltv-channel", ch->ch_xc->xc_identifier);
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
if(ch->ch_icon != NULL)
|
|
|
|
|
htsmsg_add_str(m, "icon", ch->ch_icon);
|
|
|
|
|
|
2008-09-07 08:54:16 +00:00
|
|
|
|
tags = htsmsg_create_array();
|
|
|
|
|
LIST_FOREACH(ctm, &ch->ch_ctms, ctm_channel_link)
|
2009-02-28 16:31:33 +00:00
|
|
|
|
htsmsg_add_u32(tags, NULL, ctm->ctm_tag->ct_identifier);
|
2008-09-07 08:54:16 +00:00
|
|
|
|
|
|
|
|
|
htsmsg_add_msg(m, "tags", tags);
|
|
|
|
|
|
2008-09-05 16:02:41 +00:00
|
|
|
|
hts_settings_save(m, "channels/%d", ch->ch_id);
|
2008-08-25 20:37:19 +00:00
|
|
|
|
htsmsg_destroy(m);
|
2007-12-02 17:06:51 +00:00
|
|
|
|
}
|
2008-01-28 20:40:35 +00:00
|
|
|
|
|
2008-05-03 05:13:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* Rename a channel and all tied transports
|
|
|
|
|
*/
|
|
|
|
|
int
|
2008-05-03 06:00:07 +00:00
|
|
|
|
channel_rename(channel_t *ch, const char *newname)
|
2008-05-03 05:13:31 +00:00
|
|
|
|
{
|
|
|
|
|
th_transport_t *t;
|
|
|
|
|
|
2008-08-29 15:29:33 +00:00
|
|
|
|
lock_assert(&global_lock);
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
if(channel_find_by_name(newname, 0))
|
2008-05-03 05:13:31 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
tvhlog(LOG_NOTICE, "channels", "Channel \"%s\" renamed to \"%s\"",
|
|
|
|
|
ch->ch_name, newname);
|
|
|
|
|
|
|
|
|
|
RB_REMOVE(&channel_name_tree, ch, ch_name_link);
|
2008-05-03 05:13:31 +00:00
|
|
|
|
channel_set_name(ch, newname);
|
|
|
|
|
|
2008-05-03 06:55:56 +00:00
|
|
|
|
LIST_FOREACH(t, &ch->ch_transports, tht_ch_link) {
|
|
|
|
|
free(t->tht_chname);
|
|
|
|
|
t->tht_chname = strdup(newname);
|
2008-09-09 17:32:06 +00:00
|
|
|
|
pthread_mutex_lock(&t->tht_stream_mutex);
|
2008-05-03 05:13:31 +00:00
|
|
|
|
t->tht_config_change(t);
|
2008-09-09 17:32:06 +00:00
|
|
|
|
pthread_mutex_unlock(&t->tht_stream_mutex);
|
2008-05-03 05:13:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-25 20:37:19 +00:00
|
|
|
|
channel_save(ch);
|
2008-09-27 13:24:00 +00:00
|
|
|
|
htsp_channel_update(ch);
|
2008-05-03 05:13:31 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete channel
|
|
|
|
|
*/
|
|
|
|
|
void
|
2008-05-03 06:00:07 +00:00
|
|
|
|
channel_delete(channel_t *ch)
|
2008-05-03 05:13:31 +00:00
|
|
|
|
{
|
|
|
|
|
th_transport_t *t;
|
2008-05-03 06:00:07 +00:00
|
|
|
|
th_subscription_t *s;
|
2008-09-07 08:54:16 +00:00
|
|
|
|
channel_tag_mapping_t *ctm;
|
2008-05-03 06:00:07 +00:00
|
|
|
|
|
2008-08-29 15:29:33 +00:00
|
|
|
|
lock_assert(&global_lock);
|
|
|
|
|
|
2008-09-07 08:54:16 +00:00
|
|
|
|
while((ctm = LIST_FIRST(&ch->ch_ctms)) != NULL)
|
2009-02-25 18:21:05 +00:00
|
|
|
|
channel_tag_mapping_destroy(ctm, CTM_DESTROY_UPDATE_TAG);
|
|
|
|
|
|
|
|
|
|
htsp_channel_delete(ch);
|
2008-09-07 08:54:16 +00:00
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
tvhlog(LOG_NOTICE, "channels", "Channel \"%s\" deleted",
|
|
|
|
|
ch->ch_name);
|
|
|
|
|
|
2008-09-23 19:38:53 +00:00
|
|
|
|
dvr_destroy_by_channel(ch);
|
2008-05-03 05:13:31 +00:00
|
|
|
|
|
2008-05-03 06:00:07 +00:00
|
|
|
|
while((t = LIST_FIRST(&ch->ch_transports)) != NULL) {
|
2008-09-05 16:08:12 +00:00
|
|
|
|
transport_unmap_channel(t);
|
2008-09-05 22:06:09 +00:00
|
|
|
|
pthread_mutex_lock(&t->tht_stream_mutex);
|
2008-05-03 06:00:07 +00:00
|
|
|
|
t->tht_config_change(t);
|
2008-09-05 22:06:09 +00:00
|
|
|
|
pthread_mutex_unlock(&t->tht_stream_mutex);
|
2008-05-03 06:00:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while((s = LIST_FIRST(&ch->ch_subscriptions)) != NULL) {
|
|
|
|
|
LIST_REMOVE(s, ths_channel_link);
|
|
|
|
|
s->ths_channel = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-07 14:22:21 +00:00
|
|
|
|
epg_unlink_from_channel(ch);
|
2008-05-03 05:13:31 +00:00
|
|
|
|
|
2008-09-05 22:02:22 +00:00
|
|
|
|
fprintf(stderr, "!!!!!//autorec_destroy_by_channel(ch);\n");
|
2008-05-03 06:00:07 +00:00
|
|
|
|
|
2008-09-05 16:02:41 +00:00
|
|
|
|
hts_settings_remove("channels/%d", ch->ch_id);
|
2008-05-03 06:55:56 +00:00
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
RB_REMOVE(&channel_name_tree, ch, ch_name_link);
|
|
|
|
|
RB_REMOVE(&channel_identifier_tree, ch, ch_identifier_link);
|
|
|
|
|
|
2008-09-05 16:02:41 +00:00
|
|
|
|
LIST_REMOVE(ch, ch_xc_link);
|
|
|
|
|
|
2008-08-26 14:15:33 +00:00
|
|
|
|
free(ch->ch_name);
|
|
|
|
|
free(ch->ch_sname);
|
2008-05-03 06:00:07 +00:00
|
|
|
|
free(ch->ch_icon);
|
2008-09-09 17:31:02 +00:00
|
|
|
|
|
|
|
|
|
channel_list_changed();
|
2008-05-03 06:00:07 +00:00
|
|
|
|
|
|
|
|
|
free(ch);
|
2008-05-03 05:13:31 +00:00
|
|
|
|
}
|
2008-05-03 06:38:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Merge transports from channel 'src' to channel 'dst'
|
|
|
|
|
*
|
|
|
|
|
* Then, destroy the 'src' channel
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
channel_merge(channel_t *dst, channel_t *src)
|
|
|
|
|
{
|
|
|
|
|
th_transport_t *t;
|
2008-08-29 15:29:33 +00:00
|
|
|
|
|
|
|
|
|
lock_assert(&global_lock);
|
2008-08-26 14:15:33 +00:00
|
|
|
|
|
|
|
|
|
tvhlog(LOG_NOTICE, "channels", "Channel \"%s\" merged into \"%s\"",
|
|
|
|
|
src->ch_name, dst->ch_name);
|
2008-05-03 06:38:42 +00:00
|
|
|
|
|
|
|
|
|
while((t = LIST_FIRST(&src->ch_transports)) != NULL) {
|
2008-09-05 16:08:12 +00:00
|
|
|
|
transport_unmap_channel(t);
|
|
|
|
|
transport_map_channel(t, dst);
|
2008-09-05 22:02:22 +00:00
|
|
|
|
pthread_mutex_lock(&t->tht_stream_mutex);
|
2008-05-03 06:38:42 +00:00
|
|
|
|
t->tht_config_change(t);
|
2008-09-05 22:02:22 +00:00
|
|
|
|
pthread_mutex_unlock(&t->tht_stream_mutex);
|
2008-05-03 06:38:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
channel_delete(src);
|
|
|
|
|
}
|
2008-08-25 20:37:19 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
channel_set_icon(channel_t *ch, const char *icon)
|
|
|
|
|
{
|
2008-08-29 15:29:33 +00:00
|
|
|
|
lock_assert(&global_lock);
|
|
|
|
|
|
2008-09-05 16:02:41 +00:00
|
|
|
|
if(ch->ch_icon != NULL && !strcmp(ch->ch_icon, icon))
|
|
|
|
|
return;
|
|
|
|
|
|
2008-08-25 20:37:19 +00:00
|
|
|
|
free(ch->ch_icon);
|
2008-09-05 16:02:41 +00:00
|
|
|
|
ch->ch_icon = strdup(icon);
|
|
|
|
|
channel_save(ch);
|
2008-09-27 13:24:00 +00:00
|
|
|
|
htsp_channel_update(ch);
|
2008-09-05 16:02:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
channel_set_xmltv_source(channel_t *ch, xmltv_channel_t *xc)
|
|
|
|
|
{
|
|
|
|
|
lock_assert(&global_lock);
|
|
|
|
|
|
|
|
|
|
if(xc == ch->ch_xc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LIST_REMOVE(ch, ch_xc_link);
|
|
|
|
|
|
|
|
|
|
if(xc == NULL) {
|
|
|
|
|
LIST_INSERT_HEAD(&channels_not_xmltv_mapped, ch, ch_xc_link);
|
|
|
|
|
} else {
|
|
|
|
|
LIST_INSERT_HEAD(&xc->xc_channels, ch, ch_xc_link);
|
|
|
|
|
}
|
|
|
|
|
ch->ch_xc = xc;
|
2008-09-21 11:03:08 +00:00
|
|
|
|
|
|
|
|
|
tvh_str_update(&ch->ch_icon, xc->xc_icon);
|
|
|
|
|
|
2008-08-25 20:37:19 +00:00
|
|
|
|
channel_save(ch);
|
|
|
|
|
}
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
2008-09-07 08:54:16 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
channel_set_tags_from_list(channel_t *ch, const char *maplist)
|
|
|
|
|
{
|
|
|
|
|
channel_tag_mapping_t *ctm, *n;
|
|
|
|
|
channel_tag_t *ct;
|
|
|
|
|
char buf[40];
|
|
|
|
|
int i, change = 0;
|
|
|
|
|
|
|
|
|
|
lock_assert(&global_lock);
|
|
|
|
|
|
|
|
|
|
LIST_FOREACH(ctm, &ch->ch_ctms, ctm_channel_link)
|
|
|
|
|
ctm->ctm_mark = 1; /* Mark for delete */
|
|
|
|
|
|
|
|
|
|
while(*maplist) {
|
|
|
|
|
for(i = 0; i < sizeof(buf) - 1; i++) {
|
|
|
|
|
buf[i] = *maplist;
|
|
|
|
|
if(buf[i] == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
maplist++;
|
|
|
|
|
if(buf[i] == ',') {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buf[i] = 0;
|
|
|
|
|
if((ct = channel_tag_find(buf, 0)) == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
LIST_FOREACH(ctm, &ch->ch_ctms, ctm_channel_link)
|
|
|
|
|
if(ctm->ctm_tag == ct) {
|
|
|
|
|
ctm->ctm_mark = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ctm == NULL) {
|
|
|
|
|
/* Need to create mapping */
|
|
|
|
|
change = 1;
|
|
|
|
|
channel_tag_map(ch, ct, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(ctm = LIST_FIRST(&ch->ch_ctms); ctm != NULL; ctm = n) {
|
|
|
|
|
n = LIST_NEXT(ctm, ctm_channel_link);
|
|
|
|
|
if(ctm->ctm_mark) {
|
|
|
|
|
change = 1;
|
2009-02-25 18:21:05 +00:00
|
|
|
|
channel_tag_mapping_destroy(ctm, CTM_DESTROY_UPDATE_TAG |
|
|
|
|
|
CTM_DESTROY_UPDATE_CHANNEL);
|
2008-09-07 08:54:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(change)
|
|
|
|
|
channel_save(ch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
channel_tag_map(channel_t *ch, channel_tag_t *ct, int check)
|
|
|
|
|
{
|
|
|
|
|
channel_tag_mapping_t *ctm;
|
|
|
|
|
|
|
|
|
|
if(check) {
|
|
|
|
|
LIST_FOREACH(ctm, &ch->ch_ctms, ctm_channel_link)
|
|
|
|
|
if(ctm->ctm_tag == ct)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LIST_FOREACH(ctm, &ct->ct_ctms, ctm_tag_link)
|
|
|
|
|
if(ctm->ctm_channel == ch)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LIST_FOREACH(ctm, &ch->ch_ctms, ctm_channel_link)
|
|
|
|
|
assert(ctm->ctm_tag != ct);
|
|
|
|
|
|
|
|
|
|
LIST_FOREACH(ctm, &ct->ct_ctms, ctm_tag_link)
|
|
|
|
|
assert(ctm->ctm_channel != ch);
|
|
|
|
|
|
|
|
|
|
ctm = malloc(sizeof(channel_tag_mapping_t));
|
|
|
|
|
|
|
|
|
|
ctm->ctm_channel = ch;
|
|
|
|
|
LIST_INSERT_HEAD(&ch->ch_ctms, ctm, ctm_channel_link);
|
|
|
|
|
|
|
|
|
|
ctm->ctm_tag = ct;
|
|
|
|
|
LIST_INSERT_HEAD(&ct->ct_ctms, ctm, ctm_tag_link);
|
|
|
|
|
|
|
|
|
|
ctm->ctm_mark = 0;
|
2008-09-27 13:24:00 +00:00
|
|
|
|
|
2009-02-25 18:21:05 +00:00
|
|
|
|
if(ct->ct_enabled && !ct->ct_internal) {
|
2008-09-27 13:24:00 +00:00
|
|
|
|
htsp_tag_update(ct);
|
2009-02-25 18:21:05 +00:00
|
|
|
|
htsp_channel_update(ch);
|
|
|
|
|
}
|
2008-09-07 08:54:16 +00:00
|
|
|
|
}
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2009-02-25 18:21:05 +00:00
|
|
|
|
channel_tag_mapping_destroy(channel_tag_mapping_t *ctm, int flags)
|
2008-09-06 19:08:10 +00:00
|
|
|
|
{
|
2008-09-27 13:24:00 +00:00
|
|
|
|
channel_tag_t *ct = ctm->ctm_tag;
|
2009-02-25 18:21:05 +00:00
|
|
|
|
channel_t *ch = ctm->ctm_channel;
|
|
|
|
|
|
2008-09-06 19:08:10 +00:00
|
|
|
|
LIST_REMOVE(ctm, ctm_channel_link);
|
|
|
|
|
LIST_REMOVE(ctm, ctm_tag_link);
|
|
|
|
|
free(ctm);
|
2008-09-27 13:24:00 +00:00
|
|
|
|
|
2009-02-25 18:21:05 +00:00
|
|
|
|
if(ct->ct_enabled && !ct->ct_internal) {
|
|
|
|
|
if(flags & CTM_DESTROY_UPDATE_TAG)
|
|
|
|
|
htsp_tag_update(ct);
|
|
|
|
|
if(flags & CTM_DESTROY_UPDATE_CHANNEL)
|
|
|
|
|
htsp_channel_update(ch);
|
|
|
|
|
}
|
2008-09-06 19:08:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static channel_tag_t *
|
|
|
|
|
channel_tag_find(const char *id, int create)
|
|
|
|
|
{
|
|
|
|
|
channel_tag_t *ct;
|
|
|
|
|
char buf[20];
|
|
|
|
|
static int tally;
|
2009-02-28 16:31:33 +00:00
|
|
|
|
uint32_t u32;
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
|
|
|
|
if(id != NULL) {
|
2009-02-28 16:31:33 +00:00
|
|
|
|
u32 = atoi(id);
|
2008-09-06 19:08:10 +00:00
|
|
|
|
TAILQ_FOREACH(ct, &channel_tags, ct_link)
|
2009-02-28 16:31:33 +00:00
|
|
|
|
if(ct->ct_identifier == u32)
|
2008-09-06 19:08:10 +00:00
|
|
|
|
return ct;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(create == 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
ct = calloc(1, sizeof(channel_tag_t));
|
|
|
|
|
if(id == NULL) {
|
|
|
|
|
tally++;
|
|
|
|
|
snprintf(buf, sizeof(buf), "%d", tally);
|
|
|
|
|
id = buf;
|
|
|
|
|
} else {
|
2008-09-07 08:54:16 +00:00
|
|
|
|
tally = MAX(atoi(id), tally);
|
2008-09-06 19:08:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-28 16:31:33 +00:00
|
|
|
|
ct->ct_identifier = atoi(id);
|
2008-09-06 19:08:10 +00:00
|
|
|
|
ct->ct_name = strdup("New tag");
|
|
|
|
|
ct->ct_comment = strdup("");
|
2008-09-28 08:20:30 +00:00
|
|
|
|
ct->ct_icon = strdup("");
|
2008-09-06 19:08:10 +00:00
|
|
|
|
TAILQ_INSERT_TAIL(&channel_tags, ct, ct_link);
|
|
|
|
|
return ct;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-08 22:17:37 +00:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
channel_tag_t *
|
|
|
|
|
channel_tag_find_by_name(const char *name)
|
|
|
|
|
{
|
|
|
|
|
channel_tag_t *ct;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(ct, &channel_tags, ct_link)
|
|
|
|
|
if(!strcmp(ct->ct_name, name))
|
|
|
|
|
break;
|
|
|
|
|
return ct;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
channel_tag_destroy(channel_tag_t *ct)
|
|
|
|
|
{
|
|
|
|
|
channel_tag_mapping_t *ctm;
|
2008-09-07 08:54:16 +00:00
|
|
|
|
channel_t *ch;
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
2008-09-07 08:54:16 +00:00
|
|
|
|
while((ctm = LIST_FIRST(&ct->ct_ctms)) != NULL) {
|
|
|
|
|
ch = ctm->ctm_channel;
|
2009-02-25 18:21:05 +00:00
|
|
|
|
channel_tag_mapping_destroy(ctm, CTM_DESTROY_UPDATE_CHANNEL);
|
2008-09-07 08:54:16 +00:00
|
|
|
|
channel_save(ch);
|
|
|
|
|
}
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
2008-09-27 13:24:00 +00:00
|
|
|
|
if(ct->ct_enabled && !ct->ct_internal)
|
|
|
|
|
htsp_tag_delete(ct);
|
|
|
|
|
|
2008-09-06 19:08:10 +00:00
|
|
|
|
free(ct->ct_name);
|
|
|
|
|
free(ct->ct_comment);
|
2008-09-28 08:20:30 +00:00
|
|
|
|
free(ct->ct_icon);
|
2008-09-06 19:08:10 +00:00
|
|
|
|
TAILQ_REMOVE(&channel_tags, ct, ct_link);
|
|
|
|
|
free(ct);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static htsmsg_t *
|
|
|
|
|
channel_tag_record_build(channel_tag_t *ct)
|
|
|
|
|
{
|
|
|
|
|
htsmsg_t *e = htsmsg_create();
|
|
|
|
|
htsmsg_add_u32(e, "enabled", !!ct->ct_enabled);
|
|
|
|
|
htsmsg_add_u32(e, "internal", !!ct->ct_internal);
|
2008-09-28 08:20:30 +00:00
|
|
|
|
htsmsg_add_u32(e, "titledIcon", !!ct->ct_titled_icon);
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
|
|
|
|
htsmsg_add_str(e, "name", ct->ct_name);
|
|
|
|
|
htsmsg_add_str(e, "comment", ct->ct_comment);
|
2008-09-28 08:20:30 +00:00
|
|
|
|
htsmsg_add_str(e, "icon", ct->ct_icon);
|
2009-02-28 16:31:33 +00:00
|
|
|
|
htsmsg_add_u32(e, "id", ct->ct_identifier);
|
2008-09-06 19:08:10 +00:00
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static htsmsg_t *
|
|
|
|
|
channel_tag_record_get_all(void *opaque)
|
|
|
|
|
{
|
|
|
|
|
htsmsg_t *r = htsmsg_create_array();
|
|
|
|
|
channel_tag_t *ct;
|
|
|
|
|
|
|
|
|
|
TAILQ_FOREACH(ct, &channel_tags, ct_link)
|
|
|
|
|
htsmsg_add_msg(r, NULL, channel_tag_record_build(ct));
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static htsmsg_t *
|
|
|
|
|
channel_tag_record_get(void *opaque, const char *id)
|
|
|
|
|
{
|
|
|
|
|
channel_tag_t *ct;
|
|
|
|
|
|
|
|
|
|
if((ct = channel_tag_find(id, 0)) == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
return channel_tag_record_build(ct);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static htsmsg_t *
|
|
|
|
|
channel_tag_record_create(void *opaque)
|
|
|
|
|
{
|
|
|
|
|
return channel_tag_record_build(channel_tag_find(NULL, 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static htsmsg_t *
|
|
|
|
|
channel_tag_record_update(void *opaque, const char *id, htsmsg_t *values,
|
|
|
|
|
int maycreate)
|
|
|
|
|
{
|
|
|
|
|
channel_tag_t *ct;
|
|
|
|
|
uint32_t u32;
|
2008-09-27 13:24:00 +00:00
|
|
|
|
int was_exposed, is_exposed;
|
2009-02-25 18:21:05 +00:00
|
|
|
|
channel_tag_mapping_t *ctm;
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
|
|
|
|
if((ct = channel_tag_find(id, maycreate)) == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
tvh_str_update(&ct->ct_name, htsmsg_get_str(values, "name"));
|
|
|
|
|
tvh_str_update(&ct->ct_comment, htsmsg_get_str(values, "comment"));
|
2008-09-28 08:20:30 +00:00
|
|
|
|
tvh_str_update(&ct->ct_icon, htsmsg_get_str(values, "icon"));
|
|
|
|
|
|
|
|
|
|
if(!htsmsg_get_u32(values, "titledIcon", &u32))
|
|
|
|
|
ct->ct_titled_icon = u32;
|
2008-09-06 19:08:10 +00:00
|
|
|
|
|
2008-09-27 13:24:00 +00:00
|
|
|
|
was_exposed = ct->ct_enabled && !ct->ct_internal;
|
|
|
|
|
|
|
|
|
|
if(!htsmsg_get_u32(values, "enabled", &u32))
|
2008-09-06 19:08:10 +00:00
|
|
|
|
ct->ct_enabled = u32;
|
|
|
|
|
|
2008-09-27 13:24:00 +00:00
|
|
|
|
if(!htsmsg_get_u32(values, "internal", &u32))
|
2008-09-06 19:08:10 +00:00
|
|
|
|
ct->ct_internal = u32;
|
|
|
|
|
|
2008-09-27 13:24:00 +00:00
|
|
|
|
is_exposed = ct->ct_enabled && !ct->ct_internal;
|
|
|
|
|
|
|
|
|
|
/* We only export tags to HTSP if enabled == true and internal == false,
|
|
|
|
|
thus, it's not as simple as just sending updates here.
|
|
|
|
|
Depending on how the flags transition we add update or delete tags */
|
|
|
|
|
|
2009-02-25 18:21:05 +00:00
|
|
|
|
if(was_exposed == 0 && is_exposed == 1) {
|
2008-09-27 13:24:00 +00:00
|
|
|
|
htsp_tag_add(ct);
|
2009-02-25 18:21:05 +00:00
|
|
|
|
|
|
|
|
|
LIST_FOREACH(ctm, &ct->ct_ctms, ctm_tag_link)
|
|
|
|
|
htsp_channel_update(ctm->ctm_channel);
|
|
|
|
|
|
|
|
|
|
} else if(was_exposed == 1 && is_exposed == 1)
|
2008-09-27 13:24:00 +00:00
|
|
|
|
htsp_tag_update(ct);
|
2009-02-25 18:21:05 +00:00
|
|
|
|
else if(was_exposed == 1 && is_exposed == 0) {
|
|
|
|
|
|
|
|
|
|
LIST_FOREACH(ctm, &ct->ct_ctms, ctm_tag_link)
|
|
|
|
|
htsp_channel_update(ctm->ctm_channel);
|
2008-09-27 13:24:00 +00:00
|
|
|
|
|
2009-02-25 18:21:05 +00:00
|
|
|
|
htsp_tag_delete(ct);
|
|
|
|
|
}
|
2008-09-27 13:24:00 +00:00
|
|
|
|
return channel_tag_record_build(ct);
|
2008-09-06 19:08:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static int
|
|
|
|
|
channel_tag_record_delete(void *opaque, const char *id)
|
|
|
|
|
{
|
|
|
|
|
channel_tag_t *ct;
|
|
|
|
|
|
|
|
|
|
if((ct = channel_tag_find(id, 0)) == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
channel_tag_destroy(ct);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static const dtable_class_t channel_tags_dtc = {
|
|
|
|
|
.dtc_record_get = channel_tag_record_get,
|
|
|
|
|
.dtc_record_get_all = channel_tag_record_get_all,
|
|
|
|
|
.dtc_record_create = channel_tag_record_create,
|
|
|
|
|
.dtc_record_update = channel_tag_record_update,
|
|
|
|
|
.dtc_record_delete = channel_tag_record_delete,
|
2008-09-25 16:38:55 +00:00
|
|
|
|
.dtc_read_access = ACCESS_ADMIN,
|
|
|
|
|
.dtc_write_access = ACCESS_ADMIN,
|
2008-09-06 19:08:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
channels_init(void)
|
|
|
|
|
{
|
|
|
|
|
dtable_t *dt;
|
|
|
|
|
|
|
|
|
|
TAILQ_INIT(&channel_tags);
|
|
|
|
|
|
|
|
|
|
dt = dtable_create(&channel_tags_dtc, "channeltags", NULL);
|
|
|
|
|
dtable_load(dt);
|
|
|
|
|
|
|
|
|
|
channels_load();
|
|
|
|
|
}
|