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; }
int ecmascript_openuri(prop_t *page, const char *url, int sync) { hts_regmatch_t matches[8]; hts_mutex_lock(&route_mutex); es_route_t *er; LIST_FOREACH(er, &routes, er_link) if(!hts_regexec(&er->er_regex, url, 8, matches, 0)) break; if(er == NULL) { hts_mutex_unlock(&route_mutex); return 1; } es_resource_retain(&er->super); es_context_t *ec = er->super.er_ctx; hts_mutex_unlock(&route_mutex); es_context_begin(ec); duk_context *ctx = ec->ec_duk; es_push_root(ctx, er); es_stprop_push(ctx, page); duk_push_boolean(ctx, sync); int array_idx = duk_push_array(ctx); for(int i = 1; i < 8; i++) { if(matches[i].rm_so == -1) break; duk_push_lstring(ctx, url + matches[i].rm_so, matches[i].rm_eo - matches[i].rm_so); duk_put_prop_index(ctx, array_idx, i-1); } int rc = duk_pcall(ctx, 3); if(rc) { if(duk_is_string(ctx, -1)) { nav_open_error(page, duk_to_string(ctx, -1)); } else { duk_get_prop_string(ctx, -1, "message"); nav_open_error(page, duk_to_string(ctx, -1)); duk_pop(ctx); } es_dump_err(ctx); } duk_pop(ctx); es_context_end(ec); es_resource_release(&er->super); return 0; }