コード例 #1
0
ファイル: dvr_rec.c プロジェクト: digrobot/tvheadend
int
dvr_rec_subscribe(dvr_entry_t *de)
{
  char buf[100];
  int weight;
  profile_t *pro;
  profile_chain_t *prch;
  struct sockaddr sa;
  access_t *aa;
  uint32_t rec_count, net_count;
  int c1, c2;

  assert(de->de_s == NULL);
  assert(de->de_chain == NULL);

  if(de->de_pri >= 0 && de->de_pri < ARRAY_SIZE(prio2weight))
    weight = prio2weight[de->de_pri];
  else
    weight = 300;

  snprintf(buf, sizeof(buf), "DVR: %s", lang_str_get(de->de_title, NULL));

  if (de->de_owner && de->de_owner[0] != '\0')
    aa = access_get_by_username(de->de_owner);
  else if (de->de_creator && de->de_creator[0] != '\0' &&
           tcp_get_ip_from_str(de->de_creator, &sa) != NULL)
    aa = access_get_by_addr(&sa);
  else {
    tvherror(LS_DVR, "unable to find access (owner '%s', creator '%s')",
             de->de_owner, de->de_creator);
    return -EPERM;
 }

  if (aa->aa_conn_limit || aa->aa_conn_limit_dvr) {
    rec_count = dvr_usage_count(aa);
    net_count = aa->aa_conn_limit ? tcp_connection_count(aa) : 0;
    /* the rule is: allow if one condition is OK */
    c1 = aa->aa_conn_limit ? rec_count + net_count >= aa->aa_conn_limit : -1;
    c2 = aa->aa_conn_limit_dvr ? rec_count >= aa->aa_conn_limit_dvr : -1;
    if (c1 && c2) {
      tvherror(LS_DVR, "multiple connections are not allowed for user '%s' from '%s' "
                      "(limit %u, dvr limit %u, active DVR %u, streaming %u)",
               aa->aa_username ?: "", aa->aa_representative ?: "",
               aa->aa_conn_limit, aa->aa_conn_limit_dvr, rec_count, net_count);
      access_destroy(aa);
      return -EOVERFLOW;
    }
コード例 #2
0
ファイル: dvr_rec.c プロジェクト: ruuk/tvheadend
int
dvr_rec_subscribe(dvr_entry_t *de)
{
  char buf[100];
  int weight;
  profile_t *pro;
  profile_chain_t *prch;
  struct sockaddr sa;
  access_t *aa;
  uint32_t rec_count, net_count;

  assert(de->de_s == NULL);
  assert(de->de_chain == NULL);

  if(de->de_pri > 0 && de->de_pri < ARRAY_SIZE(prio2weight))
    weight = prio2weight[de->de_pri];
  else
    weight = 300;

  snprintf(buf, sizeof(buf), "DVR: %s", lang_str_get(de->de_title, NULL));

  if (de->de_owner && de->de_owner[0] != '\0')
    aa = access_get_by_username(de->de_owner);
  else if (de->de_creator && de->de_creator[0] != '\0' &&
           tcp_get_ip_from_str(de->de_creator, &sa) != NULL)
    aa = access_get_by_addr(&sa);
  else {
    tvherror("dvr", "unable to find access");
    return -1;
  }

  if (aa->aa_conn_limit) {
    rec_count = dvr_usage_count(aa);
    net_count = tcp_connection_count(aa);
    if (rec_count + net_count >= aa->aa_conn_limit) {
      tvherror("dvr", "multiple connections are not allowed for user '%s' from '%s' "
                      "(limit %u, active streaming %u, active DVR %u)",
               aa->aa_username ?: "", aa->aa_representative ?: "",
               aa->aa_conn_limit, rec_count, net_count);
      return -1;
    }