static int64_t scanfile_total_load;
static memoryinfo_t scanfile_memoryinfo = { .my_name = "Scan files" };
+static void scanfile_done_muxes( scanfile_network_t *net );
+
/* **************************************************************************
* Country codes
*/
static int
scanfile_create_network
- ( scanfile_network_t **_net, const char *type, const char *name,
+ ( scanfile_network_t **_net, const char *type,
+ const char *path, const char *name,
dvb_fe_delivery_system_t delsys )
{
scanfile_region_t *reg = NULL;
}
snprintf(buf2, sizeof(buf2), "%s_%s", type, buf);
net = calloc(1, sizeof(scanfile_network_t));
- memoryinfo_alloc(&scanfile_memoryinfo, sizeof(*net) + strlen(buf2) + 1 + strlen(buf) + 1);
+ memoryinfo_alloc(&scanfile_memoryinfo, sizeof(*net) + strlen(buf2) + 1 + strlen(buf) + 1 +
+ strlen(path) + 1 + strlen(type) + 1);
net->sfn_id = strdup(buf2);
net->sfn_name = strdup(buf);
+ net->sfn_path = strdup(path);
+ net->sfn_type = strdup(type);
net->sfn_satpos = opos;
LIST_INSERT_SORTED(®->sfr_networks, net, sfn_link, scanfile_network_cmp);
*/
static int
scanfile_load_one
- ( scanfile_network_t **net, const char *type, const char *name, const char *line )
+ ( scanfile_network_t **net, const char *type, const char *path,
+ const char *name, const char *line, int test )
{
int r = 1;
dvb_mux_conf_t *mux = malloc(sizeof(dvb_mux_conf_t));
if (r) {
free(mux);
} else {
- if (*net == NULL && scanfile_create_network(net, type, name, mux->dmc_fe_delsys)) {
+ if (*net == NULL &&
+ scanfile_create_network(net, type, path, name, mux->dmc_fe_delsys)) {
free(mux);
return -1;
}
- memoryinfo_alloc(&scanfile_memoryinfo, sizeof(*mux));
- LIST_INSERT_HEAD(&(*net)->sfn_muxes, mux, dmc_link);
+ if (!test) {
+ memoryinfo_alloc(&scanfile_memoryinfo, sizeof(*mux));
+ LIST_INSERT_HEAD(&(*net)->sfn_muxes, mux, dmc_link);
+ } else {
+ return -1;
+ }
}
return 1;
}
static int
scanfile_load_dvbv5
- ( scanfile_network_t **net, const char *type, const char *name,
- char *line, fb_file *fp )
+ ( scanfile_network_t **net, const char *type,
+ const char *path, const char *name,
+ char *line, fb_file *fp, int test )
{
int res = 1, r = 1, i;
char buf[256];
dvb_mux_conf_str(mux, buf, sizeof(buf));
tvhtrace(LS_SCANFILE, "mux %s", buf);
if (*net == NULL)
- if (scanfile_create_network(net, type, name, mux->dmc_fe_delsys))
+ if (scanfile_create_network(net, type, path, name, mux->dmc_fe_delsys))
return -1;
- memoryinfo_alloc(&scanfile_memoryinfo, sizeof(*mux));
- LIST_INSERT_HEAD(&(*net)->sfn_muxes, mux, dmc_link);
+ if (!test) {
+ memoryinfo_alloc(&scanfile_memoryinfo, sizeof(*mux));
+ LIST_INSERT_HEAD(&(*net)->sfn_muxes, mux, dmc_link);
+ } else {
+ free(mux);
+ res = -2;
+ }
}
return res;
/*
* Process a file
*/
-static void
+static scanfile_network_t *
scanfile_load_file
- ( const char *type, fb_dir *dir, const char *name )
+ ( scanfile_network_t *net, const char *type, const char *path,
+ fb_file *fp, const char *name, int test )
{
- fb_file *fp;
- scanfile_network_t *net = NULL;
char *str, buf[256];
int load = 0;
tvhtrace(LS_SCANFILE, "load file %s (processed bytes %"PRId64")",
name, scanfile_total_load);
- if (scanfile_total_load > SCANFILE_LIMIT) return;
- fp = fb_open2(dir, name, 1, 0);
- if (!fp) return;
+ if (!fp) return NULL;
+
scanfile_total_load += fb_size(fp);
if (scanfile_total_load > SCANFILE_LIMIT) goto end;
case 'C':
case 'T':
case 'S':
- load = scanfile_load_one(&net, type, name, buf);
+ load = scanfile_load_one(&net, type, path, name, buf, test);
break;
case '[':
- load = scanfile_load_dvbv5(&net, type, name, buf, fp);
+ load = scanfile_load_dvbv5(&net, type, path, name, buf, fp, test);
break;
default:
break;
}
end:
fb_close(fp);
+ return net;
}
/*
*/
static void
scanfile_load_dir
- ( const char *path, const char *type, int lvl )
+ ( const char *path, const char *type, int lvl, int test )
{
- char p[256];
+ char p[PATH_MAX];
fb_dir *dir;
fb_dirent *de;
+ fb_file *fp;
+ scanfile_network_t *net;
+
tvhtrace(LS_SCANFILE, "load dir %s", path);
if (lvl >= 3) return;
if (*de->name == '.') continue;
if (de->type == FB_DIR) {
snprintf(p, sizeof(p), "%s/%s", path, de->name);
- scanfile_load_dir(p, de->name, lvl+1);
+ scanfile_load_dir(p, de->name, lvl+1, test);
} else if (type) {
- scanfile_load_file(type, dir, de->name);
+ snprintf(p, sizeof(p), "%s/%s", path, de->name);
+ if (scanfile_total_load > SCANFILE_LIMIT) continue;
+ fp = fb_open2(dir, de->name, 1, 0);
+ net = scanfile_load_file(NULL, type, p, fp, de->name, test);
+ scanfile_done_muxes(net);
}
}
return 0;
}
+/*
+ * Destroy the muxes
+ */
+static void
+scanfile_done_muxes( scanfile_network_t *net )
+{
+ dvb_mux_conf_t *mux;
+ if (!net) return;
+ while ((mux = LIST_FIRST(&net->sfn_muxes)) != NULL) {
+ memoryinfo_free(&scanfile_memoryinfo, sizeof(*mux));
+ LIST_REMOVE(mux, dmc_link);
+ free(mux);
+ }
+}
+
+
/*
* Destroy the region
*/
{
scanfile_region_t *reg;
scanfile_network_t *net;
- dvb_mux_conf_t *mux;
while ((reg = LIST_FIRST(&list->srl_regions)) != NULL) {
LIST_REMOVE(reg, sfr_link);
while ((net = LIST_FIRST(®->sfr_networks)) != NULL) {
LIST_REMOVE(net, sfn_link);
- while ((mux = LIST_FIRST(&net->sfn_muxes)) != NULL) {
- memoryinfo_free(&scanfile_memoryinfo, sizeof(*mux));
- LIST_REMOVE(mux, dmc_link);
- free(mux);
- }
+ scanfile_done_muxes(net);
memoryinfo_free(&scanfile_memoryinfo, sizeof(*net) +
(net->sfn_id ? strlen(net->sfn_id) + 1 : 0) +
- (net->sfn_name ? strlen(net->sfn_name) + 1 : 0));
+ (net->sfn_name ? strlen(net->sfn_name) + 1 : 0) +
+ (net->sfn_path ? strlen(net->sfn_path) + 1 : 0) +
+ (net->sfn_type ? strlen(net->sfn_type) + 1 : 0));
free((void *)net->sfn_id);
free((void *)net->sfn_name);
+ free((void *)net->sfn_path);
+ free((void *)net->sfn_type);
free(net);
}
memoryinfo_free(&scanfile_memoryinfo, sizeof(*reg) +
scanfile_regions_load[i].srl_alt_type = scanfile_region_types[i][1];
}
- scanfile_load_dir(path, NULL, 0);
+ scanfile_load_dir(path, NULL, 0, 1);
for (i = 0; i < REGIONS; i++) {
snprintf(buf, sizeof(buf)-1, "%s", scanfile_regions_load[i].srl_type);
}
/*
- * Find scanfile
+ * Find scanfile and load muxes
*/
scanfile_network_t *
scanfile_find ( const char *id )
scanfile_region_t *r = NULL;
scanfile_network_t *n = NULL;
scanfile_region_list_t *l;
+ fb_file *fp;
tmp = strdup(id);
/* Type */
break;
free(tmp);
+
+ if (n) {
+ fp = fb_open(n->sfn_path, 1, 0);
+ tmp = strrchr(n->sfn_path, '/');
+ scanfile_load_file(n, n->sfn_type, n->sfn_path, fp, tmp ?: n->sfn_path, 0);
+ }
+
return n;
fail:
free(tmp);
return NULL;
}
+
+/*
+ * Remove muxes from scanfile
+ */
+void
+scanfile_clean( scanfile_network_t *sfn )
+{
+ scanfile_done_muxes(sfn);
+}