Exemplo n.º 1
0
static void
linuxdvb_ca_class_enabled_notify ( void *p, const char *lang )
{
  linuxdvb_ca_t *lca = (linuxdvb_ca_t *) p;

  if (lca->lca_enabled) {
    if (lca->lca_ca_fd < 0) {
      lca->lca_ca_fd = tvh_open(lca->lca_ca_path, O_RDWR | O_NONBLOCK, 0);
      tvhtrace("linuxdvb", "opening ca%u %s (fd %d)",
               lca->lca_number, lca->lca_ca_path, lca->lca_ca_fd);
    }
  } else {
    tvhtrace("linuxdvb", "closing ca%u %s (fd %d)",
             lca->lca_number, lca->lca_ca_path, lca->lca_ca_fd);

    if (lca->lca_en50221_thread_running) {
      lca->lca_en50221_thread_running = 0;
      pthread_join(lca->lca_en50221_thread, NULL);
    }

    ioctl(lca->lca_ca_fd, CA_RESET, NULL);

    close(lca->lca_ca_fd);
    lca->lca_ca_fd = -1;

    idnode_notify_title_changed(&lca->lca_id, lang);
  }
}
Exemplo n.º 2
0
void
hts_settings_save(htsmsg_t *record, const char *pathfmt, ...)
{
  char path[PATH_MAX];
  char tmppath[PATH_MAX];
  int fd;
  va_list ap;
  htsbuf_queue_t hq;
  htsbuf_data_t *hd;
  int ok, r, pack;

  if(settingspath == NULL)
    return;

  /* Clean the path */
  va_start(ap, pathfmt);
  _hts_settings_buildpath(path, sizeof(path), pathfmt, ap, settingspath);
  va_end(ap);

  /* Create directories */
  if (hts_settings_makedirs(path)) return;

  tvhdebug("settings", "saving to %s", path);

  /* Create tmp file */
  snprintf(tmppath, sizeof(tmppath), "%s.tmp", path);
  if((fd = tvh_open(tmppath, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR)) < 0) {
    tvhlog(LOG_ALERT, "settings", "Unable to create \"%s\" - %s",
	    tmppath, strerror(errno));
    return;
  }

  /* Store data */
#if ENABLE_ZLIB
  pack = strstr(path, "/muxes/") != NULL && /* ugly, redesign API */
         strstr(path, "/networks/") != NULL &&
         strstr(path, "/input/") != NULL;
#else
  pack = 0;
#endif
  ok = 1;

  if (!pack) {
    htsbuf_queue_init(&hq, 0);
    htsmsg_json_serialize(record, &hq, 1);
    TAILQ_FOREACH(hd, &hq.hq_q, hd_link)
      if(tvh_write(fd, hd->hd_data + hd->hd_data_off, hd->hd_data_len)) {
        tvhlog(LOG_ALERT, "settings", "Failed to write file \"%s\" - %s",
                tmppath, strerror(errno));
        ok = 0;
        break;
      }
    htsbuf_queue_flush(&hq);
  } else {
Exemplo n.º 3
0
void
hts_settings_save(htsmsg_t *record, const char *pathfmt, ...)
{
  char path[256];
  char tmppath[256];
  int fd;
  va_list ap;
  htsbuf_queue_t hq;
  htsbuf_data_t *hd;
  int ok;

  if(settingspath == NULL)
    return;

  /* Clean the path */
  va_start(ap, pathfmt);
  _hts_settings_buildpath(path, sizeof(path), pathfmt, ap, settingspath);
  va_end(ap);

  /* Create directories */
  if (hts_settings_makedirs(path)) return;

  tvhdebug("settings", "saving to %s", path);

  /* Create tmp file */
  snprintf(tmppath, sizeof(tmppath), "%s.tmp", path);
  if((fd = tvh_open(tmppath, O_CREAT | O_TRUNC | O_RDWR, 0700)) < 0) {
    tvhlog(LOG_ALERT, "settings", "Unable to create \"%s\" - %s",
	    tmppath, strerror(errno));
    return;
  }

  /* Store data */
  ok = 1;
  htsbuf_queue_init(&hq, 0);
  htsmsg_json_serialize(record, &hq, 1);
  TAILQ_FOREACH(hd, &hq.hq_q, hd_link)
    if(tvh_write(fd, hd->hd_data + hd->hd_data_off, hd->hd_data_len)) {
      tvhlog(LOG_ALERT, "settings", "Failed to write file \"%s\" - %s",
	      tmppath, strerror(errno));
      ok = 0;
      break;
    }
  close(fd);
  htsbuf_queue_flush(&hq);

  /* Move */
  if(ok) {
    rename(tmppath, path);
  
  /* Delete tmp */
  } else
    unlink(tmppath);
}
Exemplo n.º 4
0
/*
 * Output packet
 */
static int _timeshift_read
  ( timeshift_t *ts, timeshift_seek_t *seek,
    streaming_message_t **sm, int *wait )
{
  timeshift_file_t *tsf = seek->file;
  ssize_t r;
  off_t off = 0;

  *sm = NULL;

  if (tsf) {

    /* Open file */
    if (tsf->rfd < 0 && !tsf->ram) {
      tsf->rfd = tvh_open(tsf->path, O_RDONLY, 0);
      tvhtrace(LS_TIMESHIFT, "ts %d open file %s (fd %i)", ts->id, tsf->path, tsf->rfd);
      if (tsf->rfd < 0)
        return -1;
    }
    if (tsf->rfd >= 0)
      if ((off = lseek(tsf->rfd, tsf->roff, SEEK_SET)) != tsf->roff)
        tvherror(LS_TIMESHIFT, "ts %d seek to %s failed (off %"PRId64" != %"PRId64"): %s",
                 ts->id, tsf->path, (int64_t)tsf->roff, (int64_t)off, strerror(errno));

    /* Read msg */
    r = _read_msg(tsf, -1, sm);
    if (r < 0) {
      streaming_message_t *e = streaming_msg_create_code(SMT_STOP, SM_CODE_UNDEFINED_ERROR);
      streaming_target_deliver2(ts->output, e);
      tvhtrace(LS_TIMESHIFT, "ts %d seek to %jd (woff %jd) (fd %i)", ts->id, (intmax_t)off, (intmax_t)tsf->woff, tsf->rfd);
      tvherror(LS_TIMESHIFT, "ts %d could not read buffer", ts->id);
      return -1;
    }
    tvhtrace(LS_TIMESHIFT, "ts %d seek to %jd (fd %i) read msg %p/%"PRId64" (%"PRId64")",
             ts->id, (intmax_t)off, tsf->rfd, *sm, *sm ? (*sm)->sm_time : -1, (int64_t)r);

    /* Special case - EOF */
    if (r <= sizeof(size_t) || tsf->roff > tsf->size || *sm == NULL) {
      timeshift_file_get(seek->file); /* _read_close decreases file reference */
      _read_close(seek);
      _seek_set_file(seek, timeshift_filemgr_next(tsf, NULL, 0), 0);
      *wait     = 0;
      tvhtrace(LS_TIMESHIFT, "ts %d eof, seek->file %p (prev %p)", ts->id, seek->file, tsf);
      timeshift_filemgr_dump(ts);
    }
  }
  return 0;
}
Exemplo n.º 5
0
static int
download_file(download_t *dn, const char *filename)
{
  int fd, res;
  struct stat st;
  char *data, *last_url;
  ssize_t r;
  off_t off;

  fd = tvh_open(filename, O_RDONLY, 0);
  if (fd < 0) {
    tvherror(dn->log, "unable to open file '%s': %s",
             filename, strerror(errno));
    return -1;
  }
  if (fstat(fd, &st) || st.st_size == 0) {
    tvherror(dn->log, "unable to stat file '%s': %s",
             filename, strerror(errno));
    close(fd);
    return -1;
  }
  data = malloc(st.st_size+1);
  off = 0;
  do {
    r = read(fd, data + off, st.st_size - off);
    if (r < 0) {
      if (ERRNO_AGAIN(errno))
        continue;
      break;
    }
    off += r;
  } while (off != st.st_size);
  close(fd);

  if (off == st.st_size) {
    data[off] = '\0';
    last_url = strrchr(filename, '/');
    if (last_url)
      last_url++;
    res = dn->process(dn->aux, last_url, NULL, data, off);
  } else {
    res = -1;
  }
  free(data);
  return res;
}
Exemplo n.º 6
0
/*
 * Open file
 */
static int
iptv_file_start ( iptv_mux_t *im, const char *raw, const url_t *url )
{
  file_priv_t *fp;
  int fd = tvh_open(raw + 7, O_RDONLY | O_NONBLOCK, 0);

  if (fd < 0) {
    tvherror(LS_IPTV, "unable to open file '%s'", raw + 7);
    return -1;
  }

  fp = calloc(1, sizeof(*fp));
  fp->fd = fd;
  tvh_cond_init(&fp->cond);
  im->im_data = fp;
  iptv_input_mux_started(im);
  tvhthread_create(&fp->tid, NULL, iptv_file_thread, im, "iptvfile");
  return 0;
}
Exemplo n.º 7
0
int
hts_settings_open_file(int for_write, const char *pathfmt, ...)
{
  char path[256];
  va_list ap;

  /* Build path */
  va_start(ap, pathfmt);
  _hts_settings_buildpath(path, sizeof(path), pathfmt, ap, settingspath);
  va_end(ap);

  /* Create directories */
  if (for_write)
    if (hts_settings_makedirs(path)) return -1;

  /* Open file */
  int flags = for_write ? O_CREAT | O_TRUNC | O_WRONLY : O_RDONLY;

  return tvh_open(path, flags, 0700);
}
Exemplo n.º 8
0
/**
 * Open a dump file which we write the entire mux output to
 */
static void
dvb_adapter_open_dump_file(th_dvb_adapter_t *tda)
{
  struct dmx_pes_filter_params dmx_param;
  char fullname[1000];
  char path[500];
  const char *fname = tda->tda_mux_current->tdmi_identifier;

  int fd = tvh_open(tda->tda_demux_path, O_RDWR, 0);
  if(fd == -1)
    return;

  memset(&dmx_param, 0, sizeof(dmx_param));
  dmx_param.pid = 0x2000;
  dmx_param.input = DMX_IN_FRONTEND;
  dmx_param.output = DMX_OUT_TS_TAP;
  dmx_param.pes_type = DMX_PES_OTHER;
  dmx_param.flags = DMX_IMMEDIATE_START;
  
  if(ioctl(fd, DMX_SET_PES_FILTER, &dmx_param)) {
    tvhlog(LOG_ERR, "dvb",
	   "\"%s\" unable to configure demuxer \"%s\" for all PIDs -- %s",
	   fname, tda->tda_demux_path, 
	   strerror(errno));
    close(fd);
    return;
  }

  snprintf(path, sizeof(path), "%s/muxdumps", 
      dvr_config_find_by_name_default("")->dvr_storage);

  if(mkdir(path, 0777) && errno != EEXIST) {
    tvhlog(LOG_ERR, "dvb", "\"%s\" unable to create mux dump dir %s -- %s",
	   fname, path, strerror(errno));
    close(fd);
    return;
  }

  int attempt = 1;

  while(1) {
    struct stat st;
    snprintf(fullname, sizeof(fullname), "%s/%s.dump%d.ts",
	     path, fname, attempt);

    if(stat(fullname, &st) == -1)
      break;
    
    attempt++;
  }
  
  int f = open(fullname, O_CREAT | O_TRUNC | O_WRONLY, 0777);

  if(f == -1) {
    tvhlog(LOG_ERR, "dvb", "\"%s\" unable to create mux dump file %s -- %s",
	   fname, fullname, strerror(errno));
    close(fd);
    return;
  }
	   
  tvhlog(LOG_WARNING, "dvb", "\"%s\" writing to mux dump file %s",
	 fname, fullname);

  tda->tda_allpids_dmx_fd = fd;
  tda->tda_dump_fd = f;
}