Esempio n. 1
0
void KprZeroconfServiceDiscover(KprService self, char* authority, char* id, Boolean useEnvironment)
{
	FskErr err = kFskErrNone;
	char* type = NULL;
	KprZeroconfBrowser browser = NULL;
	if (useEnvironment ? KprEnvironmentGetUInt32("useZeroconf", 0) : true) {
		bailIfError(KprZeroconfServiceNewType(id, &type));
		browser = KprZeroconfBrowserFind(gKprZeroconfBrowsers, type);
		if (!browser) {
			bailIfError(KprZeroconfBrowserNew(&browser, type));
			browser->serviceUpCallback = KprZeroconfServiceServiceUpCallback;
			browser->serviceDownCallback = KprZeroconfServiceServiceDownCallback;
			browser->authority = FskStrDoCopy(authority);
			bailIfError(KprZeroconfBrowserStart(browser));
			FskListAppend(&gKprZeroconfBrowsers, browser);
		}
	}
bail:
	if (err)
		KprZeroconfBrowserDispose(browser);
	FskMemPtrDispose(type);
	FskMemPtrDispose(authority);
	FskMemPtrDispose(id);
	return;
}
Esempio n. 2
0
void FskECMAScriptInitializeThread()
{
	FskRectangleRecord bounds;
	char* shellPath;
	KprShell shell;

	bounds.x = 0;
	bounds.y = 0;
	bounds.width = KprEnvironmentGetUInt32("windowWidth", 800);
	bounds.height = KprEnvironmentGetUInt32("windowHeight", 600);
 	shellPath = FskEnvironmentGet("shellPath");
#if !TARGET_OS_ANDROID
    KprShellNew(&shell, NULL, &bounds, shellPath, NULL, NULL, NULL, 0);
#else
	if (kFskErrNone == KprShellNew(&shell, NULL, &bounds, shellPath, NULL, NULL, NULL, 0)) {
		while (!gQuitting) // (!gQuitting && !vmi->vm->quitting)
			FskThreadRunloopCycle(-1);
	}
#endif
}
Esempio n. 3
0
void KprZeroconfServiceShare(KprService self, char* authority, Boolean shareIt, Boolean useEnvironment)
{
	FskErr err = kFskErrNone;
	char* type = NULL;
	KprZeroconfAdvertisement advertisement = NULL;
	KprHTTPServer server = KprHTTPServerGet(authority);
	bailIfError(KprZeroconfServiceNewType(authority, &type));
	advertisement = KprZeroconfAdvertisementFind(gKprZeroconfAdvertisements, type, 0);
	if (shareIt && useEnvironment)
		shareIt = KprEnvironmentGetUInt32("useZeroconf", 0);
	if (shareIt && server) {
		if (!advertisement) {
			UInt32 port = server ? KprHTTPServerGetPort(server) : 0;
			Boolean secure = server ? KprHTTPServerIsSecure(server) : false;
			char* uuid = FskUUIDGetForKey(authority);
			FskAssociativeArray txt = NULL;
			if (secure) {
				txt = FskAssociativeArrayNew();
				FskAssociativeArrayElementSetString(txt, "secure", "true");
			}
			bailIfError(KprZeroconfAdvertisementNew(&advertisement, type, uuid, port, txt));
			bailIfError(KprZeroconfPlatformAdvertisementStart(advertisement));
			FskListAppend(&gKprZeroconfAdvertisements, advertisement);
		}
	}
	else {
		if (advertisement) {
			FskListRemove(&gKprZeroconfAdvertisements, advertisement);
			bailIfError(KprZeroconfPlatformAdvertisementStop(advertisement));
			KprZeroconfAdvertisementDispose(advertisement);
		}
	}
bail:
	if (err)
		KprZeroconfAdvertisementDispose(advertisement);
	FskMemPtrDispose(type);
	FskMemPtrDispose(authority);
	return;
}
Esempio n. 4
0
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;
}