Esempio n. 1
0
static void KprPromiseTargetComplete(KprMessage message, void* it)
{
	KprPromiseTarget self = it;
	xsBeginHost(self->the);
	xsVars(3);
	xsVar(0) = xsAccess(self->resolve);
	xsVar(1) = xsAccess(self->reject);
	if (message->error) {
		xsVar(2) = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID_KPR), xsID_message));
		xsSetHostData(xsVar(2), message);
		FskInstrumentedItemSendMessageDebug(message, kprInstrumentedMessageConstruct, message);
		message->usage++; // host
		(void)xsCallFunction1(xsVar(1), xsUndefined, xsVar(2));
	}
	else {
		if (message->stream)
			KprMessageScriptTargetGet(message, the, &xsVar(2));
		else {
			xsVar(2) = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID_KPR), xsID_message));
			xsSetHostData(xsVar(2), message);
			FskInstrumentedItemSendMessageDebug(message, kprInstrumentedMessageConstruct, message);
			message->usage++; // host
		}
		(void)xsCallFunction1(xsVar(0), xsUndefined, xsVar(2));
	}
	xsEndHost(self->the);
}
Esempio n. 2
0
void KprDebugMachineEchoItem(KprDebugMachine self, int theView, char* path, int line, char* name, char* value)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			if (path)
				xsNewHostProperty(xsVar(2), xsID("path"), xsString(path), xsDefault, xsDontScript);
			if (line >= 0)
				xsNewHostProperty(xsVar(2), xsID("line"), xsInteger(line), xsDefault, xsDontScript);
			if (name)
				xsNewHostProperty(xsVar(2), xsID("name"), xsString(name), xsDefault, xsDontScript);
			if (value)
				xsNewHostProperty(xsVar(2), xsID("value"), xsString(value), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Esempio n. 3
0
void KPR_system_saveFile(xsMachine* the)
{
	FskErr err;
	xsIntegerValue argc = xsToInteger(xsArgc);
	xsStringValue name = NULL;
	xsStringValue prompt = NULL;
	xsStringValue initialPath = NULL;
	xsStringValue path = NULL;
	xsStringValue url = NULL;
	if ((argc > 0) && xsTest(xsArg(0))) {
		if (xsFindResult(xsArg(0), xsID_name))
			name = xsToStringCopy(xsResult);
		if (xsFindResult(xsArg(0), xsID_prompt))
			prompt = xsToStringCopy(xsResult);
		if (xsFindResult(xsArg(0), xsID_url))
			KprURLToPath(xsToString(xsResult), &initialPath);
	}
	err = FskFileChooseSave(name, prompt, initialPath, &path);
	if ((kFskErrNone == err) && (NULL != path)) {
		KprPathToURL(path, &url);
		(void)xsCallFunction1(xsArg(1), xsNull, xsString(url));
	}
	FskMemPtrDispose(url);
	FskMemPtrDispose(path);
	FskMemPtrDispose(initialPath);
	FskMemPtrDispose(prompt);
	FskMemPtrDispose(name);
}
Esempio n. 4
0
void KPR_system_alert(xsMachine* the)
{
	int argc = xsToInteger(xsArgc);
	MSGBOXPARAMSW params;
	xsStringValue string;
	xsIntegerValue result;
	xsVars(1);
	params.cbSize = sizeof(params);
	params.hwndOwner = NULL;
	params.hInstance = FskMainGetHInstance();
	params.lpszText = NULL;
	params.lpszCaption = xsStringToWideString("Kinoma Code");
	params.dwStyle = MB_ICONSTOP;
	params.dwContextHelpId = 0;
	params.lpfnMsgBoxCallback = NULL;
	params.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
	if ((argc > 0) && xsTest(xsArg(0))) {
		if (xsFindString(xsArg(0), xsID_type, &string)) {
			if (!FskStrCompare(string, "about"))
				params.dwStyle = MB_ICONINFORMATION;
			else if (!FskStrCompare(string, "stop"))
				params.dwStyle = MB_ICONSTOP;
			else if (!FskStrCompare(string, "note"))
				params.dwStyle = MB_ICONEXCLAMATION;
		}
		if (xsFindResult(xsArg(0), xsID_prompt)) {
			xsVar(0) = xsResult;
		}
		if (xsFindResult(xsArg(0), xsID_info)) {
			xsVar(0) = xsCall1(xsVar(0), xsID("concat"), xsString("\n\n"));
			xsVar(0) = xsCall1(xsVar(0), xsID("concat"), xsResult);
		}
		params.lpszText = xsStringToWideString(xsToString(xsVar(0)));
		if (xsFindResult(xsArg(0), xsID_buttons)) {
			if (xsIsInstanceOf(xsResult, xsArrayPrototype)) {
				xsIntegerValue c = xsToInteger(xsGet(xsResult, xsID_length));
				if (c == 3)
					params.dwStyle |= MB_YESNOCANCEL;
				else if (c == 2)
					params.dwStyle |= MB_OKCANCEL;
				else
					params.dwStyle |= MB_OK;
			}
		}
	}
	result = MessageBoxIndirectW(&params);
	if (params.lpszText)
		CoTaskMemFree((LPVOID *)params.lpszText);
	if (params.lpszCaption)
		CoTaskMemFree((LPVOID *)params.lpszCaption);
	if ((argc > 1) && xsTest(xsArg(1)))
		(void)xsCallFunction1(xsArg(1), xsNull, ((result == IDYES) || (result == IDOK)) ? xsTrue : (result == IDNO) ? xsFalse : xsUndefined);
}
Esempio n. 5
0
void Zeroconf_browser_callback(KprZeroconfBrowser self, char* function, KprZeroconfServiceInfo service)
{
	xsBeginHostSandboxCode(self->the, self->code);
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	xsVars(3);
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			xsVar(1) = xsNewInstanceOf(xsObjectPrototype);
			xsSet(xsVar(1), xsID("name"), xsString(service->name));
			xsSet(xsVar(1), xsID("type"), xsString(service->type));
			if (service->host)
				xsSet(xsVar(1), xsID("host"), xsString(service->host));
			if (service->ip) {
				xsSet(xsVar(1), xsID("ip"), xsString(service->ip));
				xsSet(xsVar(1), xsID("port"), xsInteger(service->port));
			}
			if (service->txt) {
				char* txt = service->txt;
				UInt32 position = 0, size = FskStrLen(txt);
				UInt32 length = 0;
				xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
				xsSet(xsVar(1), xsID("txt"), xsVar(2));
				length = txt[position++] & 0xFF;
				while ((position + length) <= size) {
					char end;
					char* equal;
					if (!length) break;
					end = txt[position + length];
					txt[position + length] = 0;
					equal = FskStrChr(txt + position, '=');
					if (equal) {
						*equal = 0;
						xsSet(xsVar(2), xsID(txt + position), xsString(equal + 1));
						*equal = '=';
					}
					txt[position + length] = end;
					position += length;
					length = txt[position++] & 0xFF;
				}
			}
			if (xsFindResult(xsVar(0), xsID(function))) {
				(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
			}
		}
		xsCatch {
		}
	}
bail:
	xsEndHostSandboxCode();
}
Esempio n. 6
0
void KPR_shell_execute_stdout(KprShellExec exec, xsStringValue string)
{
	if (string) {
		xsBeginHost(exec->the);
		xsVars(3);
		xsVar(0) = xsAccess(exec->slot);
		xsVar(1) = xsGet(xsVar(0), xsID_stdout);
		if (xsTest(xsVar(1))) {
			xsVar(2) = xsString(string);
			xsResult = xsCallFunction1(xsVar(1), xsNull, xsVar(2));
		}
		xsEndHost(exec->the);
		FskMemPtrDispose(string);
	}
	KPR_shell_execute_callback(exec);
}
Esempio n. 7
0
void KPR_shell_execute_callback(KprShellExec exec)
{
	exec->usage--;
	if (exec->usage == 0) {
		xsBeginHost(exec->the);
		xsVars(3);
		xsVar(0) = xsAccess(exec->slot);
		xsVar(1) = xsGet(xsVar(0), xsID_callback);
		if (xsTest(xsVar(1))) {
			xsVar(2) = xsInteger(exec->status);
			xsResult = xsCallFunction1(xsVar(1), xsNull, xsVar(2));
		}
		xsForget(exec->slot);
		xsSetHostData(xsVar(0), NULL);
		xsEndHost(exec->the);
		FskMemPtrDispose(exec);
	}
}
Esempio n. 8
0
void Zeroconf_advertisement_callback(KprZeroconfAdvertisement self, char* function)
{
	xsBeginHostSandboxCode(self->the, self->code);
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	xsVars(2);
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			xsVar(1) = xsAccess(self->slot);
			if (xsFindResult(xsVar(0), xsID(function))) {
				(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
			}
		}
		xsCatch {
		}
	}
bail:
	xsEndHostSandboxCode();
}
Esempio n. 9
0
static void KPRLibrarySniffPodcastComplete(KprMessage message, void* it)
{
    KprFunctionTarget self = it;
    char* mime = KprMessageGetResponseHeader(message, "content-type");
    char* sniff = NULL;
    if (message->response.body) {
        if (kFskErrNone == FskMediaPlayerSniffForMIME(message->response.body, message->response.size, NULL, message->url, &sniff)) {
            mime = sniff;
        }
    }
    {
        xsBeginHostSandboxCode(self->the, self->code);
        if (mime)
            xsResult = xsString(mime);
        else
            xsResult = xsString("");
        (void)xsCallFunction1(self->slot, xsGlobal, xsResult);
        xsEndHostSandboxCode();
    }
    FskMemPtrDispose(sniff);
}
Esempio n. 10
0
void KPR_host_quitting(xsMachine* the)
{
	KprContainer container = xsGetHostData(xsThis);
	KprContent content = container->first;
	KprScriptBehavior self = (KprScriptBehavior)content->behavior;
#if SUPPORT_INSTRUMENTATION
	void* params[2] = { self, "xsID_onQuitting" };
	FskInstrumentedItemSendMessageDebug(content, kprInstrumentedContentCallBehavior, params);
#endif
    if (self) {
        xsBeginHostSandboxCode(self->the, self->code);
        {
 			xsVars(2);
			xsVar(0) = xsAccess(self->slot);
			if (xsFindResult(xsVar(0), xsID_onQuitting)) {
				xsVar(1) = kprContentGetter(content);
				(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
			}
        }
        xsEndHostSandboxCode();
    }
}
Esempio n. 11
0
void KprDebugMachineCallbackText(KprDebugMachine machine, char* function, int view, char* text)
{
	KprDebug self = machine->debug;
	xsMachine* the = self->the;
	if (xsTypeOf(self->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(self->behavior);
			if (xsFindResult(xsVar(0), xsID(function))) {
				if (view >= 0)
					(void)xsCallFunction3(xsResult, xsVar(0), xsString(machine->address), xsInteger(view), xsString(text));
				else if (text)
					(void)xsCallFunction2(xsResult, xsVar(0), xsString(machine->address), xsString(text));
				else
					(void)xsCallFunction1(xsResult, xsVar(0), xsString(machine->address));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Esempio n. 12
0
void KprDebugMachineEchoProperty(KprDebugMachine self, int theView, int column, char* flags, char* name, char* value)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d - %s = %s", __FUNCTION__, theView, theName, theValue);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			xsNewHostProperty(xsVar(2), xsID("column"), xsInteger(column), xsDefault, xsDontScript);
			flags[4] = 0;
			xsNewHostProperty(xsVar(2), xsID("flags"), xsString(flags + 1), xsDefault, xsDontScript);
			if (flags[0] == ' ')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(0), xsDefault, xsDontScript);
			else if (flags[0] == '+')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(1), xsDefault, xsDontScript);
			else if (flags[0] == '-')
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(2), xsDefault, xsDontScript);
			else
				xsNewHostProperty(xsVar(2), xsID("state"), xsInteger(0), xsDefault, xsDontScript);
			if (name)
				xsNewHostProperty(xsVar(2), xsID("name"), xsString(name), xsDefault, xsDontScript);
			if (value)
				xsNewHostProperty(xsVar(2), xsID("value"), xsString(value), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Esempio n. 13
0
void KprDebugMachineEchoView(KprDebugMachine self, int theView, char* theName, char* theValue)
{
	KprDebug debug = self->debug;
	xsMachine* the = debug->the;

	// FskDebugStr("%s: %d - %s = %s", __FUNCTION__, theView, theName, theValue);
	if (xsTypeOf(debug->behavior) == xsUndefinedType) goto bail;
	{
		xsTry {
			xsVar(0) = xsAccess(debug->behavior);
			xsVar(1) = xsGet(xsVar(0), xsID(self->address));
			xsVar(2) = xsNewInstanceOf(xsObjectPrototype);
			xsNewHostProperty(xsVar(2), xsID("name"), xsString(theName), xsDefault, xsDontScript);
			xsNewHostProperty(xsVar(2), xsID("value"), xsString(theValue), xsDefault, xsDontScript);
			if (xsFindResult(xsVar(1), xsID_push)) {
				(void)xsCallFunction1(xsResult, xsVar(1), xsVar(2));
			}
		}
		xsCatch {
		}
	}
bail:
	return;
}
Esempio n. 14
0
void KPR_system_openDirectory(xsMachine* the)
{
	HRESULT hr;
	xsIntegerValue argc = xsToInteger(xsArgc);
	IFileOpenDialog *pFileOpen = NULL;
	IShellItem *pItem = NULL;
	xsStringValue string;
	PWSTR wideString = NULL;
	xsIntegerValue urlLength;
	xsStringValue url = NULL;
	hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, (LPVOID *)&pFileOpen);
	if (!SUCCEEDED(hr)) goto bail;
	if ((argc > 0) && xsTest(xsArg(0))) {
		if (xsFindString(xsArg(0), xsID_prompt, &string)) {
			wideString = xsStringToWideString(string);
			hr = pFileOpen->SetTitle(wideString);
			if (!SUCCEEDED(hr)) goto bail;
			CoTaskMemFree(wideString);
			wideString = NULL;
		}
		if (xsFindString(xsArg(0), xsID_message, &string)) {
			wideString = xsStringToWideString(string);
			hr = pFileOpen->SetTitle(wideString);
			if (!SUCCEEDED(hr)) goto bail;
			CoTaskMemFree(wideString);
			wideString = NULL;
		}
		if (xsFindString(xsArg(0), xsID_url, &string)) {
			wideString = xsStringToWideString(string);
			hr = SHCreateItemFromParsingName(wideString, NULL, IID_IShellItem, (LPVOID *)&pItem);
			if (!SUCCEEDED(hr)) goto bail;
			CoTaskMemFree(wideString);
			wideString = NULL;
			hr = pFileOpen->SetFolder(pItem);
			if (!SUCCEEDED(hr)) goto bail;
			pItem->Release();
			pItem = NULL;
		}
	}
	hr = pFileOpen->SetOptions(FOS_PICKFOLDERS);
	if (!SUCCEEDED(hr)) goto bail;
	hr = pFileOpen->Show(GetForegroundWindow());
	if (!SUCCEEDED(hr)) goto bail;
	hr = pFileOpen->GetResult(&pItem);
	if (!SUCCEEDED(hr)) goto bail;
	hr = pItem->GetDisplayName(SIGDN_URL, &wideString);
	if (!SUCCEEDED(hr)) goto bail;
	
	urlLength = WideCharToMultiByte(CP_UTF8, 0, wideString, -1, NULL, 0, NULL, NULL);
	FskMemPtrNew(urlLength + 1, &url);
	WideCharToMultiByte(CP_UTF8, 0, wideString, -1, url, urlLength, NULL, NULL);
	url[urlLength - 1] = '/';
	url[urlLength] = 0;
	(void)xsCallFunction1(xsArg(1), xsNull, xsString(url));
	
bail:
	FskMemPtrDispose(url);
	if (wideString)
		CoTaskMemFree(wideString);
	if (pItem)
		pItem->Release();
	if (pFileOpen)
		pFileOpen->Release();
}