/** * Try to open the given URL with a playqueue context */ static int file_open_audio(prop_t *page, const char *url) { char parent[URL_MAX]; char parent2[URL_MAX]; struct fa_stat fs; prop_t *model; if(fa_parent(parent, sizeof(parent), url)) return 1; if(fa_stat(parent, &fs, NULL, 0)) return 1; model = prop_create(page, "model"); prop_set_string(prop_create(model, "type"), "directory"); /* Find a meaningful page title (last component of URL) */ rstr_t *title = title_from_url(parent); prop_setv(model, "metadata", "title", NULL, PROP_SET_RSTRING, title); // Set parent if(!fa_parent(parent2, sizeof(parent2), parent)) prop_set_string(prop_create(page, "parent"), parent2); fa_scanner_page(parent, fs.fs_mtime, model, url, prop_create(page, "directClose"), title); rstr_release(title); return 0; }
/** * Try to open the given URL with a playqueue context */ static int file_open_audio(prop_t *page, const char *url) { char parent[URL_MAX]; char parent2[URL_MAX]; struct fa_stat fs; prop_t *model; if(fa_parent(parent, sizeof(parent), url)) return 1; if(fa_stat(parent, &fs, NULL, 0)) return 1; model = prop_create(page, "model"); prop_set_string(prop_create(model, "type"), "directory"); /* Find a meaningful page title (last component of URL) */ set_title_from_url(prop_create(model, "metadata"), parent); // Set parent if(!fa_parent(parent2, sizeof(parent2), parent)) prop_set_string(prop_create(page, "parent"), parent2); fa_scanner(parent, model, url); return 0; }
static int file_open_dir(prop_t *page, const char *url) { prop_t *model; int type; char parent[URL_MAX]; int r; fa_handle_t *ref; ref = fa_reference(url); type = fa_probe_dir(NULL, url); if(type == CONTENT_DVD) { r = backend_open_video(page, url); } else { model = prop_create(page, "model"); prop_set_string(prop_create(model, "type"), "directory"); /* Find a meaningful page title (last component of URL) */ set_title_from_url(prop_create(model, "metadata"), url); // Set parent if(!fa_parent(parent, sizeof(parent), url)) prop_set_string(prop_create(page, "parent"), parent); fa_scanner(url, model, NULL); r = 0; } fa_unreference(ref); return r; }
static void file_open_browse(prop_t *page, const char *url, time_t mtime) { prop_t *model; char parent[URL_MAX]; model = prop_create(page, "model"); prop_set_string(prop_create(model, "type"), "directory"); /* Find a meaningful page title (last component of URL) */ rstr_t *title = title_from_url(url); prop_setv(model, "metadata", "title", NULL, PROP_SET_RSTRING, title); // Set parent if(!fa_parent(parent, sizeof(parent), url)) prop_set_string(prop_create(page, "parent"), parent); fa_scanner_page(url, mtime, model, NULL, prop_create(page, "directClose"), title); rstr_release(title); }
int js_plugin_load(const char *id, const char *url, char *errbuf, size_t errlen) { char *sbuf; struct fa_stat fs; JSContext *cx; js_plugin_t *jsp; JSObject *pobj, *gobj, *confobj; JSScript *s; char path[PATH_MAX]; jsval val; if((sbuf = fa_quickload(url, &fs, NULL, errbuf, errlen)) == NULL) return -1; cx = js_newctx(err_reporter); JS_BeginRequest(cx); /* Remove any plugin with same URL */ LIST_FOREACH(jsp, &js_plugins, jsp_link) if(!strcmp(jsp->jsp_id, id)) break; if(jsp != NULL) js_plugin_unload(cx, jsp); jsp = calloc(1, sizeof(js_plugin_t)); jsp->jsp_url = strdup(url); jsp->jsp_id = strdup(id); LIST_INSERT_HEAD(&js_plugins, jsp, jsp_link); gobj = JS_NewObject(cx, &global_class, NULL, NULL); JS_InitStandardClasses(cx, gobj); JS_DefineProperty(cx, gobj, "showtime", OBJECT_TO_JSVAL(showtimeobj), NULL, NULL, JSPROP_READONLY | JSPROP_PERMANENT); /* Plugin object */ pobj = JS_NewObject(cx, &plugin_class, NULL, gobj); JS_AddNamedRoot(cx, &pobj, "plugin"); JS_SetPrivate(cx, pobj, jsp); JS_DefineFunctions(cx, pobj, plugin_functions); /* Plugin config object */ confobj = JS_DefineObject(cx, pobj, "config", &plugin_conf_class, NULL, 0); JS_SetPrivate(cx, confobj, jsp); val = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, url)); JS_SetProperty(cx, confobj, "url", &val); if(!fa_parent(path, sizeof(path), url)) { val = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, path)); JS_SetProperty(cx, confobj, "path", &val); } JS_DefineProperty(cx, confobj, "URIRouting", BOOLEAN_TO_JSVAL(1), NULL, jsp_setEnableURIRoute, JSPROP_PERMANENT); JS_DefineProperty(cx, confobj, "search", BOOLEAN_TO_JSVAL(1), NULL, jsp_setEnableSearch, JSPROP_PERMANENT); s = JS_CompileScript(cx, pobj, sbuf, fs.fs_size, url, 1); free(sbuf); if(s != NULL) { JSObject *sobj = JS_NewScriptObject(cx, s); jsval result; JS_AddNamedRoot(cx, &sobj, "script"); JS_ExecuteScript(cx, pobj, s, &result); JS_RemoveRoot(cx, &sobj); } JS_RemoveRoot(cx, &pobj); JS_EndRequest(cx); JS_GC(cx); JS_DestroyContext(cx); return 0; }