Beispiel #1
0
int
metadata_folder_to_season(const char *s,
			  int *seasonp, rstr_t **titlep)
{
  int i;
  for(i = 0; folder_to_season[i] != NULL; i++) {
    hts_regex_t re;
    if(!hts_regcomp(&re, folder_to_season[i])) {
      hts_regmatch_t matches[8];
      if(!hts_regexec(&re, s, 8, matches, 0)) {
	hts_regfree(&re);
	if(seasonp != NULL)
	  *seasonp = atoi(s + matches[2].rm_so);
	if(titlep != NULL) {
	  int l = matches[1].rm_eo - matches[1].rm_so;
	  if(l > 0)
	    *titlep = rstr_allocl(s + matches[i].rm_so, l);
	  else
	    *titlep = NULL;
	}
	return 0;
      }
      hts_regfree(&re);
    }
  }
  return -1;
}
Beispiel #2
0
static int
es_route_create(duk_context *ctx)
{
  const char *str = duk_safe_to_string(ctx, 0);

  if(str[0] != '^') {
    int l = strlen(str);
    char *s = alloca(l + 2);
    s[0] = '^';
    memcpy(s+1, str, l+1);
    str = s;
  }

  es_context_t *ec = es_get(ctx);

  hts_mutex_lock(&route_mutex);

  es_route_t *er;

  LIST_FOREACH(er, &routes, er_link)
    if(!strcmp(er->er_pattern, str))
      break;

  if(er != NULL) {
    hts_mutex_unlock(&route_mutex);
    duk_error(ctx, DUK_ERR_ERROR, "Route %s already exist", str);
  }

  er = es_resource_alloc(&es_resource_route);
  if(hts_regcomp(&er->er_regex, str)) {
    hts_mutex_unlock(&route_mutex);
    free(er);
    duk_error(ctx, DUK_ERR_ERROR, "Invalid regular expression for route %s",
              str);
  }

  er->er_pattern = strdup(str);
  er->er_prio = strcspn(str, "()[].*?+$") ?: INT32_MAX;

  LIST_INSERT_SORTED(&routes, er, er_link, er_cmp, es_route_t);

  es_resource_link(&er->super, ec, 1);

  hts_mutex_unlock(&route_mutex);

  es_root_register(ctx, 1, er);

  es_resource_push(ctx, &er->super);
  return 1;
}