コード例 #1
0
ファイル: FskECMAScript.c プロジェクト: giapdangle/kinomajs
void FskECMAScriptGetDebug(char **host, char **breakpoints, Boolean *keepSource)
{
    if (host)
        *host = FskEnvironmentGet("debugger");
    if (breakpoints)
        *breakpoints = NULL;
    if (keepSource)
        *keepSource = 0;
}
コード例 #2
0
ファイル: FskECMAScript.c プロジェクト: giapdangle/kinomajs
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
}
コード例 #3
0
ファイル: kpr.c プロジェクト: basuke/kinomajs
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;
}
コード例 #4
0
ファイル: FskSSL.c プロジェクト: afrog33k/kinomajs
FskErr
FskSSLInitialize(char *CA_List)
{
	char *calistpath;
	FskErr err = kFskErrNone;

#if TARGET_OS_ANDROID
	unpackAndroid();
	calistpath = FskStrDoCat(gAndroidCallbacks->getStaticDataDirCB(), CA_List);
#else
	calistpath = FskStrDoCat(FskEnvironmentGet("applicationPath"), CA_List);
#endif

#if OPEN_SSL
	(void)FskOpenSSLInitialize(calistpath);
#endif
#if CLOSED_SSL
	err = makeSSLRootVM(calistpath);
#endif
	FskMemPtrDispose(calistpath);
	return err;
}
コード例 #5
0
ファイル: KplFilesLinux.c プロジェクト: VzqzAc/kinomajs
FskErr KplDirectoryGetSpecialPath(UInt32 type, const Boolean create, const char *volumeName, char **fullPath)
{
	FskErr	err = kFskErrFileNotFound;
	KplFileInfo finfo;
	char *tmp = NULL, *specialDirEnv = NULL;

	*fullPath = NULL;

	switch (type & ~kFskDirectorySpecialTypeSharedFlag) {
		case kFskDirectorySpecialTypeDocument:
			specialDirEnv = "DocumentsDir";
			break;
		case kFskDirectorySpecialTypePhoto:
			specialDirEnv = "PhotosDir";
			break;
		case kFskDirectorySpecialTypeMusic:
			specialDirEnv = "MusicDir";
			break;
		case kFskDirectorySpecialTypeVideo:
			specialDirEnv = "VideoDir";
			break;
		case kFskDirectorySpecialTypeTV:
			specialDirEnv = "TVDir";
			break;
#ifdef ANDROID_PLATFORM
		case kFskDirectorySpecialTypeApplicationPreference:
			tmp = FskEnvironmentGet("PreferencesDir");
			if (!tmp)
				*fullPath = FskStrDoCopy("/data/local/tmp/.kinoma/");
			else
				*fullPath = FskStrDoCopy(tmp);
			err = kFskErrNone;
			goto bail;
		case kFskDirectorySpecialTypeTemporary:
			*fullPath = FskStrDoCopy("/data/local/tmp/");
			err = kFskErrNone;
			goto bail;
		case kFskDirectorySpecialTypeCache:
			*fullPath = FskStrDoCopy("/data/local/tmp/");
			err = kFskErrNone;
			goto bail;
#else
		case kFskDirectorySpecialTypeApplicationPreference:
			tmp = FskEnvironmentGet("PreferencesDir");
			if (!tmp)
#if BG3CDP
			{
				*fullPath = FskStrDoCopy("/data/.kinoma/");
			}
#else
			{
				if (0 == FskStrCompare("/", getenv("HOME")))
					*fullPath = FskStrDoCopy("/.kinoma/");
				else
					*fullPath = FskStrDoCat(getenv("HOME"), "/.kinoma/");
			}
#endif
			else
				*fullPath = FskStrDoCopy(tmp);
			err = kFskErrNone;
			goto bail;
		case kFskDirectorySpecialTypeTemporary:
			*fullPath = FskStrDoCopy("/tmp/");
			err = kFskErrNone;
			goto bail;
		case kFskDirectorySpecialTypeCache:
			*fullPath = FskStrDoCopy("/tmp/");
			err = kFskErrNone;
			goto bail;
#endif
		default:
			err = kFskErrInvalidParameter;
			goto bail;
	}
コード例 #6
0
ファイル: FskECMAScript.c プロジェクト: giapdangle/kinomajs
void FskExtensionsEmbedGrammar(char *vmName, char **xsbName, xsGrammar **grammar)
{
	*xsbName = FskEnvironmentGet("grammarName");
	*grammar = &FskManifestGrammar;
}
コード例 #7
0
ファイル: xs6Platform.c プロジェクト: dadongdong/kinomajs
void fxConnect(txMachine* the)
{
	if (!FskStrLen(debugAddress)) {
        char *address = FskEnvironmentGet("debugger");
		if (address)
			FskStrCopy(debugAddress, address);
#if TARGET_OS_WIN32 || (TARGET_OS_MAC && !TARGET_OS_IPHONE)
		else
			FskStrCopy(debugAddress, "localhost");
#endif
	}
	if (FskStrLen(debugAddress)) {
		FskErr err = kFskErrNone;
		char host[64];
		char* colon;
		int port;
		UInt32 addr;
		struct sockaddr_in sockaddr;
		FskSocket skt = NULL;
		int	flag;
		
		colon = FskStrNCopyUntil(host, debugAddress, 63, ':');
		if (*colon)
			port = FskStrToNum(colon);
		else
			port = 5002;
		err = FskNetHostnameResolveQT(host, 0, &addr, NULL);
		if (err) goto bail;
		FskMemSet(&sockaddr, 0, sizeof(sockaddr));
		sockaddr.sin_family = AF_INET;
		sockaddr.sin_port = htons(port);
		sockaddr.sin_addr.s_addr = htonl(addr);
		
		err = FskNetSocketNewTCPPrioritized(&skt, false, 0, "fxConnect");
		if (err) goto bail;
		
#if TARGET_OS_WIN32
		flag = 1;
		if (ioctlsocket(skt->platSkt, FIONBIO, &flag))
			goto bail;
#else
		flag = fcntl(skt->platSkt, F_GETFL, 0);
		if (fcntl(skt->platSkt, F_SETFL, flag | O_NONBLOCK) < 0)
			goto bail;
#endif

		if (connect(skt->platSkt, (struct sockaddr*)(void*)&sockaddr, sizeof(sockaddr)) < 0) {
			struct timeval aTimeout = { 10, 0 }; // 10 seconds, 0 micro-seconds
			fd_set aReadSet;
			fd_set aWriteSet;
#if TARGET_OS_WIN32
			fd_set aexceptSet;
			if (WSAGetLastError() != WSAEWOULDBLOCK)
				goto bail;
#else
			if (errno != EINPROGRESS)
				goto bail;
#endif
			FD_ZERO(&aReadSet);
			FD_SET(skt->platSkt, &aReadSet);
			aWriteSet = aReadSet;

#if TARGET_OS_WIN32
			// See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms740141(v=vs.85).aspx
			aexceptSet = aReadSet;
			if (select(skt->platSkt + 1, &aReadSet, &aWriteSet, &aexceptSet, &aTimeout) <= 0)
                goto bail;
            if (!(FD_ISSET(skt->platSkt, &aReadSet)) && !(FD_ISSET(skt->platSkt, &aWriteSet)) && !(FD_ISSET(skt->platSkt, &aexceptSet)))
				goto bail;
#else
			if (select(skt->platSkt + 1, &aReadSet, &aWriteSet, NULL, &aTimeout) <= 0)
                goto bail;
			if (!(FD_ISSET(skt->platSkt, &aReadSet)) && !(FD_ISSET(skt->platSkt, &aWriteSet)))
				goto bail;
#endif
            }
		
#if TARGET_OS_WIN32
		flag = 0;
		if (ioctlsocket(skt->platSkt, FIONBIO, &flag))
			goto bail;
#else
		if (fcntl(skt->platSkt, F_SETFL, flag) < 0)
			goto bail;
#endif
		
		the->connection = (txSocket)skt;
		fxAddReadableCallback(the);
		return;
bail:		
		FskNetSocketClose(skt);
		debugAddressFailed = true;
	}
}	
コード例 #8
0
ファイル: xs6Platform.c プロジェクト: dadongdong/kinomajs
static void fxDoConnect(txMachine *the)
{
	if (!FskStrLen(debugAddress)) {
        char *address = FskEnvironmentGet("debugger");
		if (address)
			FskStrCopy(debugAddress, address);
#if TARGET_OS_WIN32 || (TARGET_OS_MAC && !TARGET_OS_IPHONE)
		else
			FskStrCopy(debugAddress, "localhost");
#endif
	}
	if (FskStrLen(debugAddress) && !debugAddressFailed) {
		FskErr err;
		char host[64];
		char* colon;
		int port;
		FskTimeRecord expireTime, now;
		SInt32 waitMS;
		
		colon = FskStrNCopyUntil(host, debugAddress, 63, ':');
		if (*colon)
			port = FskStrToNum(colon);
		else
			port = 5002;
			
#if TARGET_OS_MAC
		waitMS = 0;
#else
		waitMS = -1;
#endif
		// Connect to the host asynchronously
		err = FskNetConnectToHostPrioritized(host, port, false, fxConnectComplete, the, 0, 0, NULL, "fxConnect");
		if (err) goto bail;
		
		// Allow two seconds for the connection to resolve and for the socket to become readable and writable
		FskTimeGetNow(&expireTime);
		FskTimeAddSecs(&expireTime, 2);
		while (!the->connection) {
			FskTimeGetNow(&now);
			if (FskTimeCompare(&expireTime, &now) > 0)
				goto bail;
			FskThreadRunloopCycle(waitMS);
		}
		while (!FskNetSocketIsReadable((FskSocket)the->connection) && !FskNetSocketIsWritable((FskSocket)the->connection)) {
			FskTimeGetNow(&now);
			if (FskTimeCompare(&expireTime, &now) > 0)
				goto bail;
			FskThreadRunloopCycle(waitMS);
		}
		
		// Make the socket blocking
		FskNetSocketMakeBlocking((FskSocket)the->connection);
		return;
		
bail:
		if (the->connection) {
			FskNetSocketClose((FskSocket)the->connection);
			the->connection = 0;
		}
		debugAddressFailed = true;
	}
}
コード例 #9
0
ファイル: FskEnvironment.c プロジェクト: giapdangle/kinomajs
char *FskEnvironmentApply(char *input)
{
	FskErr err;
	char *p;
	char *out = NULL;
	char *start, *end;
	UInt32 outCount = 0;
	char tempName[256];
	UInt32 nameLen;
	char *value;
	Boolean doApply = false;

	if (NULL == input)
		goto bail;

	if ('"' == *input) {
		// special case for string literal - useful when there is leading or trailing white space or [ or ] in the string
		UInt32 len = FskStrLen(input);
		if ('"' == input[len - 1]) {
			err = FskMemPtrNew(len - 1, &out);
			BAIL_IF_ERR(err);
			out[len - 2] = 0;
			FskMemMove(out, input + 1, len - 2);
			goto bail;
		}
	}

	// scan
	p = input;
	while (true) {
		start = FskStrChr(p, '[');
		if (NULL == start) {
			outCount += FskStrLen(p);
			break;
		}
		outCount += start - p;
		end = FskStrChr(start + 1, ']');
		if (NULL == end) {
			outCount += FskStrLen(start);
			break;
		}

		nameLen = end - start - 1;
		if (nameLen > (sizeof(tempName) - 1))
			goto bail;
		FskMemMove(tempName, start + 1, nameLen);
		tempName[nameLen] = 0;

		value = FskEnvironmentGet(tempName);
		outCount += FskStrLen(value);

		doApply = true;
		p = end + 1;
	}

	if (!doApply)
		goto bail;

	// replace
	err = FskMemPtrNew(outCount + 1, &out);
	BAIL_IF_ERR(err);

	out[0] = 0;
	p = input;
	while (true) {
		start = FskStrChr(p, '[');
		if (NULL == start) {
			FskStrCat(out, p);
			break;
		}
		outCount += start - p;
		end = FskStrChr(start + 1, ']');
		if (NULL == end) {
			FskStrCat(out, start);
			break;
		}

		FskStrNCat(out, p, start - p);

		nameLen = end - start - 1;
		FskMemMove(tempName, start + 1, nameLen);
		tempName[nameLen] = 0;
		FskStrCat(out, FskEnvironmentGet(tempName));

		p = end + 1;
	}

bail:
	return out;
}
コード例 #10
0
FskErr FskFSDirectoryGetSpecialPath(UInt32 type, const Boolean create, const char *volumeName, char **fullPath)
{
	FskErr	err = kFskErrFileNotFound;
	FskFileInfo finfo;
	char *tmp = NULL, *specialDir = NULL;
	char *dataDir = gAndroidCallbacks->getStaticDataDirCB();
	char *externalDir = gAndroidCallbacks->getStaticExternalDirCB();
	Boolean doCreate = create;

	*fullPath = NULL;

	FskAndroidFilesPrintfDebug("for SpecialPath - type %d, use dataDir as %s (volumeName %s)\n", type, dataDir, volumeName);

	switch (type & ~kFskDirectorySpecialTypeSharedFlag) {
		case kFskDirectorySpecialTypeDownload:
			if (androidSystemDownloadsDir)
				tmp = FskStrDoCat(androidSystemDownloadsDir, "/");
			else if (externalDir)
				tmp = FskStrDoCat(externalDir, "/Kinoma/Downloads/");
			else
				BAIL(kFskErrNotDirectory);
			break;
		case kFskDirectorySpecialTypeDocument:
			doCreate = true;
			if (externalDir)
				tmp = FskStrDoCat(externalDir, "/");
			else if (androidSystemDownloadsDir)
				tmp = FskStrDoCat(androidSystemDownloadsDir, "/");
			else
				specialDir = "Download";
			break;
		case kFskDirectorySpecialTypePhoto:
			if (androidSystemPicturesDir)
				tmp = FskStrDoCat(androidSystemPicturesDir, "/");
			else
				specialDir = "Pictures";
			break;
		case kFskDirectorySpecialTypeMusic:
			if (androidSystemMusicDir)
				tmp = FskStrDoCat(androidSystemMusicDir, "/");
			else
				specialDir = "Music";
			break;
		case kFskDirectorySpecialTypeVideo:
			if (androidSystemMoviesDir)
				tmp = FskStrDoCat(androidSystemMoviesDir, "/");
			else
				specialDir = "Movies";
			break;
		case kFskDirectorySpecialTypeTV:
			specialDir = "TV";
			break;
		case kFskDirectorySpecialTypeApplicationPreference:
			*fullPath = FskStrDoCat(dataDir, "kinoma/");
			err = FskFSFileCreateDirectory(*fullPath);
			err = kFskErrNone;
			goto makeit;
		case kFskDirectorySpecialTypeTemporary:
			*fullPath = FskStrDoCat(dataDir, "tmp/");
			err = FskFSFileCreateDirectory(*fullPath);
			err = kFskErrNone;
			goto makeit;
		case kFskDirectorySpecialTypeCache:
			*fullPath = FskStrDoCat(dataDir, "tmp/");
			err = FskFSFileCreateDirectory(*fullPath);
			err = kFskErrNone;
			goto makeit;
		default:
			FskAndroidFilesPrintfDebug("SpecialDirectory - bad special directory\n");
			BAIL(kFskErrInvalidParameter);
	}

	if (specialDir)
		tmp = FskStrDoCopy(FskEnvironmentGet(specialDir));

	if (!tmp) {
		char *home;
		home = dataDir;
		err = FskMemPtrNewClear(FskStrLen(home) + FskStrLen(specialDir) + 3, (FskMemPtr*)(void*)&tmp);
		BAIL_IF_ERR(err);
		FskStrCopy(tmp, home);
		if (tmp[FskStrLen(tmp)-1] != '/')
			FskStrCat(tmp, "/");
		if (specialDir) {
			FskStrCat(tmp, specialDir);
			FskStrCat(tmp, "/");
		}
	}
	FskAndroidFilesPrintfDebug("looking for %s - got %s", specialDir, tmp);
	*fullPath = tmp;

makeit:
	if (doCreate) {
		err = FskFSFileCreateDirectory(*fullPath);
	}
	else {
		err = FskFSFileGetFileInfo(*fullPath, &finfo);
		if (kFskErrNone == err) {
			if (kFskDirectoryItemIsDirectory != finfo.filetype)
				BAIL(kFskErrNotDirectory);
		}
	}

bail:
	if (kFskErrFileExists == err) {
		err = kFskErrNone;
		FskAndroidFilesPrintfDebug("DIRECTORY EXISTS specialDirectory - looking for type %d - got [%s]", type, *fullPath);
	}
	else if (kFskErrNone != err) {
		FskAndroidFilesPrintfDebug("DIRECGOTRY DIDN'T EXIST - specialDirectory - looking for type %d - got [%s] err: %d", type, *fullPath, err);
	}

	return err;
}