void KPR_mergeURI(xsMachine *the) { xsStringValue base = xsToString(xsArg(0)); xsStringValue url = xsToString(xsArg(1)); xsStringValue target; xsThrowIfFskErr(KprURLMerge(base, url, &target)); xsResult = xsString(target); FskMemPtrDispose(target); }
FskErr KprApplicationNew(KprApplication* it, char* url, char* id, Boolean breakOnStart, Boolean breakOnExceptions) { KprCoordinatesRecord coordinates = { kprLeftRight, kprTopBottom, 0, 0, 0, 0, 0, 0 }; xsAllocation allocation = { 2 * 1024 * 1024, 1024 * 1024, 64 * 1024, 8 * 1024, 2048, 16000, 1993 }; FskErr err = kFskErrNone; KprApplication self; bailIfError(FskMemPtrNewClear(sizeof(KprApplicationRecord), it)); self = *it; FskInstrumentedItemNew(self, NULL, &KprApplicationInstrumentation); self->dispatch = &KprApplicationDispatchRecord; self->flags = kprContainer | kprClip | kprVisible; KprContentInitialize((KprContent)self, &coordinates, NULL, NULL); bailIfError(KprURLMerge(gShell->url, url, &self->url)); if (id) { self->id = FskStrDoCopy(id); bailIfNULL(self->id); } self->the = xsAliasMachine(&allocation, gShell->root, self->url, self); if (!self->the) BAIL(kFskErrMemFull); FskInstrumentedItemSendMessageNormal(self, kprInstrumentedContentCreateMachine, self); xsBeginHost(self->the); xsResult = xsNewHostFunction(KPR_include, 1); xsSet(xsResult, xsID("uri"), xsString(self->url)); xsNewHostProperty(xsGlobal, xsID("include"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsResult = xsNewHostFunction(KPR_require, 1); xsSet(xsResult, xsID("uri"), xsString(self->url)); xsNewHostProperty(xsGlobal, xsID("require"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("application"))); self->slot = xsResult; xsSetHostData(xsResult, self); (void)xsCall1(xsGet(xsGlobal, xsID("Object")), xsID("seal"), xsResult); xsNewHostProperty(xsGlobal, xsID("application"), xsResult, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); xsNewHostProperty(xsGlobal, xsID("shell"), xsNull, xsDontDelete | xsDontSet, xsDontScript | xsDontDelete | xsDontSet); if (breakOnStart) xsDebugger(); if (breakOnExceptions) (void)xsCall1(xsGet(xsGet(xsGlobal, xsID("xs")), xsID("debug")), xsID("setBreakOnException"), xsBoolean(breakOnExceptions)); (void)xsCall1(xsGlobal, xsID("include"), xsString(self->url)); xsEndHost(self->the); KprContentChainPrepend(&gShell->applicationChain, self, 0, NULL); bail: return err; }
FskErr KprModulesBasesSetup(char* url, char* path) { FskErr err = kFskErrNone; char* paths = FskEnvironmentGet("modulePath"); UInt32 i = 1; char* colon; if (path) i++; if (paths) { colon = FskStrChr(paths, ';'); while (colon) { i++; colon = FskStrChr(colon + 1, ';'); } i++; } bailIfError(FskMemPtrNewClear(i * sizeof(char*), &gModulesBases)); i = 1; if (path) { bailIfError(KprURLMerge(url, path, &gModulesBases[i])); i++; } if (paths) { path = paths; colon = FskStrChr(path, ';'); while (colon) { *colon = 0; bailIfError(KprURLMerge(url, path, &gModulesBases[i])); *colon = ';'; i++; path = colon + 1; colon = FskStrChr(path, ';'); } bailIfError(KprURLMerge(url, path, &gModulesBases[i])); i++; } gModulesBasesCount = i; bail: return err; }
FskErr KprSoundNew(KprSound *it, KprContext context, char* base, char* url, char* mime) { FskErr err = kFskErrNone; KprSound self; KprSoundSetup(); bailIfError(KprAssetNew((KprAsset *)it, sizeof(KprSoundRecord), context, &context->firstSound, KprSoundDispose)); self = *it; FskInstrumentedItemNew(self, NULL, &KprSoundInstrumentation); #if SUPPORT_INSTRUMENTATION FskInstrumentedItemSetOwner(self, context); #endif if (base && url) bailIfError(KprURLMerge(base, url, &self->url)); if (mime) { self->mime = FskStrDoCopy(mime); bailIfNULL(self->mime); } bail: return err; }
void fxIncludeScript(txParser* parser, txString string) { txBoolean done = 0; char* base = NULL; char name[PATH_MAX]; char* slash = NULL; char* dot = NULL; char* extension = NULL; char* url = NULL; char* path = NULL; FskFileInfo fileInfo; FskFileMapping map= NULL; txFileMapStream fileMapStream; txStringStream stringStream; txMachine* the = parser->console; fxBeginHost(the); { mxTry(the) { xsThrowIfFskErr(KprPathToURL(parser->path->string, &base)); FskStrCopy(name, string); slash = FskStrRChr(name, '/'); if (!slash) slash = name; dot = FskStrRChr(slash, '.'); if (dot) extension = dot; else extension = name + FskStrLen(name); if (!dot) FskStrCopy(extension, ".js"); if (!FskStrCompare(extension, ".js")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, (unsigned char**)&(fileMapStream.buffer), &(fileMapStream.size), 0, &map)); fileMapStream.offset = 0; fxIncludeTree(parser, &fileMapStream, fxFileMapGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } if (!dot) FskStrCopy(extension, ".xml"); if (!FskStrCompare(extension, ".xml")) { xsThrowIfFskErr(KprURLMerge(base, name, &url)); xsThrowIfFskErr(KprURLToPath(url, &path)); if (kFskErrNone == FskFileGetFileInfo(path, &fileInfo)) { xsThrowIfFskErr(FskFileMap(path, &fileMapStream.buffer, &fileMapStream.size, 0, &map)); fileMapStream.offset = 0; mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(0); mxPushInteger(3); fxParse(the, &fileMapStream, fxFileMapGetter, path, 1, xsSourceFlag | xsDebugFlag); fxCallID(the, fxID(the, "generate")); fxToString(the, the->stack); stringStream.slot = the->stack; stringStream.size = c_strlen(stringStream.slot->value.string); stringStream.offset = 0; fxIncludeTree(parser, &stringStream, fxStringGetter, parser->flags, path); done = 1; FskFileDisposeMap(map); map = NULL; } FskMemPtrDisposeAt(&path); FskMemPtrDisposeAt(&url); } FskMemPtrDispose(base); } mxCatch(the) { FskFileDisposeMap(map); FskMemPtrDispose(path); FskMemPtrDispose(url); FskMemPtrDispose(base); break; } } fxEndHost(the); if (!done) fxReportParserError(parser, "include file not found: %s", string); }
void KprHTTPClientStart(KprService service, FskThread thread, xsMachine* the) { FskErr err = kFskErrNone; char* cachePath = NULL; char* preferencePath = NULL; char* temp = NULL; KprHTTPClient self = NULL; UInt32 i, size; KprHTTPConnection connection; bailIfError(FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeCache, true, NULL, &cachePath)); bailIfError(FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, true, NULL, &preferencePath)); bailIfError(FskMemPtrNewClear(sizeof(KprHTTPClientRecord), &self)); FskInstrumentedItemNew(self, NULL, &KprHTTPClientInstrumentation); gKprHTTPClient = self; /* HTTP CACHE */ bailIfError(KprURLMerge(cachePath, "kpr.cache", &temp)); bailIfError(KprHTTPCacheNew(&self->cache, KprEnvironmentGetUInt32("httpCacheSize", 197), KprEnvironmentGetUInt32("httpCacheDiskSize", kprHTTPCacheDiskSize), temp)); KprHTTPCacheRead(self->cache); FskMemPtrDisposeAt(&temp); /* COOKIES */ bailIfError(KprURLMerge(preferencePath, "kpr.cookies", &temp)); bailIfError(KprHTTPCookiesNew(&self->cookies, KprEnvironmentGetUInt32("httpCookiesSize", 197), temp)); KprHTTPCookiesRead(self->cookies); FskMemPtrDisposeAt(&temp); /* KEYCHAIN */ bailIfError(KprURLMerge(preferencePath, "kpr.keychain", &temp)); bailIfError(KprHTTPKeychainNew(&self->keychain, KprEnvironmentGetUInt32("httpKeychainSize", 197), temp)); KprHTTPKeychainRead(self->keychain); FskMemPtrDisposeAt(&temp); /* CONNECTIONS */ size = KprEnvironmentGetUInt32("httpPoolSize", 5); for (i = 0; i < size; i++) { bailIfError(KprHTTPConnectionNew(&connection)); FskInstrumentedItemSetOwner(connection, self); connection->id = i; FskListAppend(&self->connections, connection); } self->contentLength = KprEnvironmentGetUInt32("httpContentLength", 0x800000); self->connectionTimeout = KprEnvironmentGetUInt32("httpConnectionTimeout", 0); gHTTPService.machine = the; gHTTPService.thread = thread; gHTTPSService.machine = the; gHTTPSService.thread = thread; bail: FskMemPtrDispose(temp); FskMemPtrDispose(preferencePath); FskMemPtrDispose(cachePath); return; }