static int es_sqlite_create(duk_context *ctx) { char path[PATH_MAX]; char errbuf[512]; es_context_t *ec = es_get(ctx); const char *name = duk_safe_to_string(ctx, 0); // Create the db-dir for this plugin snprintf(path, sizeof(path), "%s/databases", ec->ec_storage); if(fa_makedirs(path, errbuf, sizeof(errbuf))) duk_error(ctx, DUK_ERR_ERROR, "Unable to create directory %s -- %s", path, errbuf); snprintf(path, sizeof(path), "%s/databases/%s", ec->ec_storage, name); sqlite3 *db = db_open(path, 0); if(db == NULL) duk_error(ctx, DUK_ERR_ERROR, "Unable to open database -- check logs"); es_sqlite_t *es = es_resource_create(ec, &es_resource_sqlite, 0); es->es_db = db; es->es_name = strdup(name); es_resource_push(ctx, &es->super); return 1; }
/** * oldname, newname */ static int es_file_mkdirs(duk_context *ctx) { es_context_t *ec = es_get(ctx); const char *filename = get_filename(ctx, 0, ec, 1); char errbuf[512]; if(fa_makedirs(filename, errbuf, sizeof(errbuf))) duk_error(ctx, DUK_ERR_ERROR, "Unable to mkdir '%s' -- %s", filename, errbuf); return 0; }
JSBool js_db_open(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { const char *name; char path[URL_MAX]; char errbuf[512]; if(!JS_ConvertArguments(cx, argc, argv, "s", &name)) return JS_FALSE; js_plugin_t *jsp = JS_GetPrivate(cx, obj); snprintf(path, sizeof(path), "file://%s/plugins/%s/databases", gconf.persistent_path, jsp->jsp_id); if(fa_makedirs(path, errbuf, sizeof(errbuf))) { JS_ReportError(cx, errbuf); return JS_FALSE; } snprintf(path, sizeof(path), "%s/plugins/%s/databases/%s", gconf.persistent_path, jsp->jsp_id, name); sqlite3 *db = db_open(path, 0); if(db == NULL) { JS_ReportError(cx, "Unable to open database -- check logs"); return JS_FALSE; } JSObject *robj = JS_NewObjectWithGivenProto(cx, &db_class, NULL, obj); *rval = OBJECT_TO_JSVAL(robj); js_db_t *jd = calloc(1, sizeof(js_db_t)); jd->jd_db = db; snprintf(path, sizeof(path), "%s:%s", jsp->jsp_id, name); jd->jd_name = strdup(path); jd->jd_self = hts_thread_current(); JS_SetPrivate(cx, robj, jd); JS_DefineFunctions(cx, robj, db_functions); return JS_TRUE; }
void main_init(void) { char errbuf[512]; hts_mutex_init(&gconf.state_mutex); hts_cond_init(&gconf.state_cond, &gconf.state_mutex); gconf.exit_code = 1; asyncio_init_early(); init_group(INIT_GROUP_NET); unicode_init(); /* Initialize property tree */ prop_init(); init_global_info(); /* Initiailize logging */ trace_init(); /* Callout framework */ callout_init(); prop_init_late(); /* Initialize htsmsg_store() */ htsmsg_store_init(); /* Notification framework */ notifications_init(); /* Initialize settings */ settings_init(); TRACE(TRACE_DEBUG, "core", "Loading resources from %s", app_dataroot()); TRACE(TRACE_DEBUG, "core", "Cache path: %s", gconf.cache_path); /* Try to create cache path */ if(gconf.cache_path != NULL && fa_makedirs(gconf.cache_path, errbuf, sizeof(errbuf))) { TRACE(TRACE_ERROR, "core", "Unable to create cache path %s -- %s", gconf.cache_path, errbuf); gconf.cache_path = NULL; } /* Initialize sqlite3 */ #if ENABLE_SQLITE db_init(); #endif /* Initializte blob cache */ blobcache_init(); TRACE(TRACE_DEBUG, "core", "Persistent path: %s", gconf.persistent_path); /* Try to create settings path */ if(gconf.persistent_path != NULL && fa_makedirs(gconf.persistent_path, errbuf, sizeof(errbuf))) { TRACE(TRACE_ERROR, "core", "Unable to create path for persistent storage %s -- %s", gconf.persistent_path, errbuf); gconf.persistent_path = NULL; } /* Per-item key/value store */ kvstore_init(); /* Metadata init */ #if ENABLE_METADATA metadata_init(); metadb_init(); decoration_init(); #endif subtitles_init(); /* Initialize keyring */ keyring_init(); #if ENABLE_LIBAV /* Initialize libavcodec & libavformat */ av_lockmgr_register(fflockmgr); av_log_set_callback(fflog); av_register_all(); TRACE(TRACE_INFO, "libav", LIBAVFORMAT_IDENT", "LIBAVCODEC_IDENT", "LIBAVUTIL_IDENT" cpuflags:0x%x", av_get_cpu_flags()); #endif init_group(INIT_GROUP_GRAPHICS); #if ENABLE_GLW glw_settings_init(); #endif /* Global keymapper */ keymapper_init(); /* Initialize media subsystem */ media_init(); /* Service handling */ service_init(); /* Initialize backend content handlers */ backend_init(); /* Initialize navigator */ nav_init(); /* Initialize audio subsystem */ audio_init(); /* Initialize plugin manager */ plugins_init(gconf.devplugins); /* Start software installer thread (plugins, upgrade, etc) */ hts_thread_create_detached("swinst", swthread, NULL, THREAD_PRIO_BGTASK); /* Internationalization */ i18n_init(); /* Video settings */ video_settings_init(); /* Various interprocess communication stuff (D-Bus on Linux, etc) */ init_group(INIT_GROUP_IPC); /* Service discovery. Must be after ipc_init() (d-bus and threads, etc) */ if(!gconf.disable_sd) sd_init(); /* Initialize various external APIs */ init_group(INIT_GROUP_API); /* Asynchronous IO (Used by HTTP server, etc) */ asyncio_start(); runcontrol_init(); TRACE(TRACE_DEBUG, "SYSTEM", "Hashed device ID: %s", gconf.device_id); if(gconf.device_type[0]) TRACE(TRACE_DEBUG, "SYSTEM", "Device type: %s", gconf.device_type); }