Beispiel #1
0
void KPR_message_setRequestCertificate(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	FskSocketCertificateRecord* certs = NULL;
	FskSocketCertificateRecord certsRecord = {
		NULL, 0,
		NULL,
		NULL,
		NULL, 0,
	};
	if (xsIsInstanceOf(xsArg(0), xsObjectPrototype)) {
		certs = &certsRecord;
		if (xsHas(xsArg(0), xsID("certificates"))) {
			certs->certificates = (void*)xsToString(xsGet(xsArg(0), xsID("certificates")));
			certs->certificatesSize = FskStrLen(certs->certificates);
		}
		if (xsHas(xsArg(0), xsID("policies"))) {
			certs->policies = xsToString(xsGet(xsArg(0), xsID("policies")));
		}
		if (xsHas(xsArg(0), xsID("key"))) {
			certs->key = (void*)xsToString(xsGet(xsArg(0), xsID("key")));
			certs->keySize = FskStrLen(certs->key);
		}
	}
	else { // compatibility
		certs = &certsRecord;
		if (xsTest(xsArg(0))) {
			certs->certificates = xsGetHostData(xsArg(0));
			certs->certificatesSize = xsToInteger(xsGet(xsArg(0), xsID_length));
		}
		if (xsTest(xsArg(1)))
			certs->policies = xsToString(xsArg(1));
	}
	xsThrowIfFskErr(KprMessageSetRequestCertificate(self, certs));
}
Beispiel #2
0
void KPR_canvasPattern_setStyle(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsArg(0));
	UInt32 repetition = kFskCanvas2dPatternRepeat;
	FskConstBitmap bitmap = NULL;
	Boolean owned = false;
	xsVars(1);
	xsVar(0) = xsGet(xsThis, xsID("repetition"));
	if (xsTest(xsVar(0))) {
		xsStringValue it = xsToString(xsVar(0));
		if (!FskStrCompare(it, "no-repeat")) repetition = kFskCanvas2dPatternRepeatNone;
		else if (!FskStrCompare(it, "repeat-x")) repetition = kFskCanvas2dPatternRepeatX;
		else if (!FskStrCompare(it, "repeat-y")) repetition = kFskCanvas2dPatternRepeatY;
		else if (!FskStrCompare(it, "repeat")) repetition = kFskCanvas2dPatternRepeat;
		else xsError(kFskErrInvalidParameter);
	}
	xsVar(0) = xsGet(xsThis, xsID("image"));
	if (xsIsInstanceOf(xsVar(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID_texture))) {
		KprTexture texture = xsGetHostData(xsVar(0));
		bitmap = KprTextureGetBitmap(texture, NULL, &owned);
	}
	else {
		KprContent content = xsGetHostData(xsVar(0));
		bitmap = (*content->dispatch->getBitmap)(content, NULL, &owned);
	}
	if (!bitmap)
		xsError(kFskErrInvalidParameter);
	if (xsTest(xsArg(1)))
		FskCanvas2dSetStrokeStylePattern(ctx, repetition, bitmap);
	else
		FskCanvas2dSetFillStylePattern(ctx, repetition, bitmap);
	if (!owned)
		FskBitmapDispose((FskBitmap)bitmap);
}
Beispiel #3
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);
}
Beispiel #4
0
void KPR_message_setRequestCertificate(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	void *data = NULL;
	xsStringValue policies = NULL;
	xsIntegerValue size = 0;
	if (xsTest(xsArg(0))) {
		data = xsGetHostData(xsArg(0));
		size = xsToInteger(xsGet(xsArg(0), xsID_length));
	}
	if (xsTest(xsArg(1)))
		policies = xsToString(xsArg(1));
	xsThrowIfFskErr(KprMessageSetRequestCertificate(self, data, size, policies));
}
Beispiel #5
0
xsBooleanValue fxFindModuleLoadAsDirectory(xsMachine* the, xsStringValue base, xsStringValue name, xsIndex* id)
{
	char node[1024];
	UInt32 nodeSize;
	xsStringValue slash;
	FskErr err;
	FskFileMapping map = NULL;
	xsBooleanValue result = 0;
	xsStringValue path = NULL;
	unsigned char* data;
	FskInt64 size;
	xsSlot slot;
	
	nodeSize = sizeof(node);
	FskStrNCopy(node, base, nodeSize);
	slash = FskStrRChr(node, '/');
	if (slash)
		*slash = 0;
	FskStrNCat(node, "/", nodeSize);
	FskStrNCat(node, name, nodeSize);
	if (FskStrTail(node, "/") != 0)
		FskStrNCat(node, "/", nodeSize);
	FskStrNCat(node, "package.json", nodeSize);
	err = KprURLToPath(node, &path);
	if (err == kFskErrNone) {
		err = FskFileMap(path, &data, &size, 0, &map);
		if (err == kFskErrNone) {
			xsTry {
				slot = xsNewInstanceOf(xsChunkPrototype);
				xsSetHostData(slot, data);
				xsSetHostDestructor(slot, NULL);
				xsSet(slot, xsID("length"), xsInteger(size));
				slot = xsCall1(xsGet(xsGlobal, xsID("JSON")), xsID("parse"), slot);
			}
			xsCatch {
				slot = xsUndefined;
			}
			if (xsTest(slot)) {
				slot = xsGet(slot, xsID("main"));
				if (xsTest(slot)) {
					FskStrNCopy(node, name, nodeSize);
					if (FskStrTail(node, "/") != 0)
						FskStrNCat(node, "/", nodeSize);
					FskStrNCat(node, xsToString(slot), nodeSize);
					if (fxFindModuleLoadAsFile(the, base, node, id))
						result = 1;
				}
			}
		}
Beispiel #6
0
void Library_cacheQuery(xsMachine* the)
{
    KprLibraryServer self = gLibraryServer;
    UInt32 index;
    KprLibraryQuery query;
    FskMutexAcquire(self->queryMutex);
    index = self->queryIndex % kQueryCount;
    query = self->queries[index];
    if (query) {
        KprLibraryQueryDispose(query);
        self->queries[index] = NULL;
    }
    KprLibraryQueryNew(&query);
    FskInstrumentedItemSetOwner(query, self);
    xsEnterSandbox();
    query->index = self->queryIndex;
    query->info = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("info"))));
    query->kind = xsToInteger(xsGet(xsArg(0), xsID("kind")));
    query->mime = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("mime"))));
    query->url = FskStrDoCopy(xsToString(xsGet(xsArg(0), xsID("url"))));
    xsResult = xsGet(xsArg(0), xsID("authorization"));
    if (xsTest(xsResult))
        query->authorization = FskStrDoCopy(xsToString(xsResult));
    xsLeaveSandbox();
    self->queries[index] = query;
    xsResult = xsInteger(self->queryIndex);
    self->queryIndex++;
    FskMutexRelease(self->queryMutex);
}
Beispiel #7
0
void xs_gpio_repeat(xsMachine* the)
{
    FskGPIO gpio = xsGetHostData(xsThis);

    if (gpio) {
        if (in != gpio->direction)
            xsThrowDiagnosticIfFskErr(kFskErrUnimplemented, "Digital pin %d cannot repeat on output pin", (int)gpio->pinNum);

        if (gpio->poller)
            FskListRemove(&gGPIOPollers, gpio);
        
        gpio->poller = (xsTest(xsArg(0))) ? xsGetHostData(xsArg(0)) : NULL;

        if (gpio->poller) {
            FskListAppend(&gGPIOPollers, gpio);
            gpio->pollerValue = -1;     // won't match
            if (NULL == gGPIOPoller) {
                FskTimeCallbackNew(&gGPIOPoller);
                FskTimeCallbackScheduleNextRun(gGPIOPoller, gpioPoller, NULL);
            }
        }
        else if ((NULL == gGPIOPollers) && (NULL != gGPIOPoller)) {
            FskTimeCallbackDispose(gGPIOPoller);
            gGPIOPoller = NULL;
        }
    }
}
Beispiel #8
0
static void
cipher_process(xsMachine *the, kcl_symmetric_direction_t direction)
{
	crypt_cipher_t *cipher = xsGetHostData(xsThis);
	size_t len;
	void *indata, *outdata;

	if (cipher->keysched != NULL) {
		if (cipher->direction != direction) {
			(*cipher->keysched)(cipher->ctx, direction);
			cipher->direction = direction;
		}
	}
	if (xsToInteger(xsArgc) > 1 && xsTest(xsArg(1))) {
		if (xsGetArrayBufferLength(xsArg(1)) < (xsIntegerValue)cipher->blockSize)
			crypt_throw_error(the, "cipher: too small buffer");
		xsResult = xsArg(1);
	}
	else
		xsResult = xsArrayBuffer(NULL, cipher->blockSize);
	if (xsTypeOf(xsArg(0)) == xsStringType) {
		indata = xsToString(xsArg(0));
		len = c_strlen(indata);
	}
	else {
		indata = xsToArrayBuffer(xsArg(0));
		len = xsGetArrayBufferLength(xsArg(0));
	}
	if (len < cipher->blockSize)
		crypt_throw_error(the, "cipher: wrong size");
	outdata = xsToArrayBuffer(xsResult);
	(*cipher->process)(cipher->ctx, indata, outdata);
}
Beispiel #9
0
void KPR_mqttclient_publish(xsMachine* the)
{
	KPR_MQTTClientRecord *self = xsGetHostData(xsThis);
	FskErr err = kFskErrNone;
	char *topic;
	void *payload = NULL;
	UInt32 payloadLength = 0;
	UInt8 qos;
	Boolean retain;
	UInt16 token;

	if (xsToInteger(xsArgc) != 4) xsThrowIfFskErr(kFskErrParameterError);

	topic = xsToString(xsArg(0));

	if (xsTest(xsArg(1))) {
		if (isArrayBuffer(xsArg(1))) {
			payload = xsToArrayBuffer(xsArg(1));
			payloadLength = xsGetArrayBufferLength(xsArg(1));
		} else {
			payload = xsToString(xsArg(1));
			payloadLength = FskStrLen(payload);
		}
	}

	qos = xsToInteger(xsArg(2));
	retain = xsToBoolean(xsArg(3));

	bailIfError(KprMQTTClientPublish(self->client, topic, payload, payloadLength, qos, retain, &token));
	xsResult = xsInteger(token);

bail:
	xsThrowIfFskErr(err);
}
Beispiel #10
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);
}
Beispiel #11
0
void
xs_stream_encrypt(xsMachine *the)
{
	crypt_stream_t *stream = xsGetHostData(xsThis);
	int ac = xsToInteger(xsArgc);
	size_t len;
	void *indata, *outdata;

	if (xsTypeOf(xsArg(0)) == xsStringType)
		len = strlen(xsToString(xsArg(0)));
	else
		len = xsGetArrayBufferLength(xsArg(0));
	if (ac > 2 && xsTypeOf(xsArg(2)) != xsUndefinedType) {
		size_t n = xsToInteger(xsArg(2));
		if (n < len)
			len = n;
	}
	xsResult = ac > 1 && xsTest(xsArg(1)) ? xsArg(1) : xsArrayBuffer(NULL, len);
	if (xsTypeOf(xsArg(0)) == xsStringType)
		indata = xsToString(xsArg(0));
	else
		indata = xsToArrayBuffer(xsArg(0));
	outdata = xsToArrayBuffer(xsResult);
	(*stream->process)(stream->ctx, indata, outdata, len);
}
Beispiel #12
0
FskErr
FskSSLRead(void *a, void *buf, int *bufLen)
{
	FskSSL *fssl = a;
	FskErr err = kFskErrNone;
	int len = *bufLen, nread;

	if (fssl->skt == NULL)
		return kFskErrOperationFailed;

	xsBeginHost(fssl->vm->the);
	xsTry {
		xsCall1_noResult(fssl->socket, xsID("attachData"), xsHostData(fssl->skt));
		xsResult = xsCall2(fssl->ssl, xsID("read"), fssl->socket, xsInteger(len));
		if (xsTest(xsResult)) {
			nread = xsToInteger(xsGet(xsResult, xsID("length")));
			if (nread > len)
				nread = len;
			FskMemCopy(buf, xsGetHostData(xsResult), nread);
			xsCall0_noResult(xsResult, xsID("free"));
			*bufLen = nread;
			err = nread == 0 ? kFskErrNoData: kFskErrNone;
		}
		else
			err = kFskErrConnectionClosed;
	} xsCatch {
		if (xsHas(xsException, xsID("code")))
			err = xsToInteger(xsGet(xsException, xsID("code")));
		if (err == kFskErrNone)
			err = kFskErrOperationFailed;
	}
	xsEndHost(fssl->vm->the);
	return err;
}
Beispiel #13
0
void
xs_chacha_init(xsMachine *the)
{
	crypt_stream_t *stream = xsGetHostData(xsThis);
	int ac = xsToInteger(xsArgc);
	void *key, *iv;
	size_t keysize, ivsize;
	uint64_t counter = 0;
	kcl_err_t err;

	key = xsToArrayBuffer(xsArg(0));
	keysize = xsGetArrayBufferLength(xsArg(0));
	if (ac > 1 && xsTest(xsArg(1))) {
		iv = xsToArrayBuffer(xsArg(1));
		ivsize = xsGetArrayBufferLength(xsArg(1));
	}
	else {
		iv = NULL;
		ivsize = 0;
	}
	if (ac > 2) {
		switch (xsTypeOf(xsArg(2))) {
		case xsIntegerType:
		case xsNumberType:
			counter = xsToInteger(xsArg(2));	/* @@ take only 32bit */
			break;
		}
	}
	if ((err = kcl_chacha_init(&stream->ctx, key, keysize, iv, ivsize, counter)) != KCL_ERR_NONE)
		kcl_throw_error(the, err);
	stream->process = kcl_chacha_process;
	stream->finish = kcl_chacha_finish;
}
Beispiel #14
0
void
xs_chacha_setIV(xsMachine *the)
{
	crypt_stream_t *stream = xsGetHostData(xsThis);
	int ac = xsToInteger(xsArgc);
	void *iv;
	size_t ivsize;
	uint64_t counter = 0;

	if (ac > 0 && xsTest(xsArg(0))) {
		iv = xsToArrayBuffer(xsArg(0));
		ivsize = xsGetArrayBufferLength(xsArg(0));
	}
	else {
		iv = NULL;
		ivsize = 0;
	}
	if (ac > 1) {
		switch (xsTypeOf(xsArg(1))) {
		case xsIntegerType:
		case xsNumberType:
			counter = xsToInteger(xsArg(1));	/* @@ take only 32bit */
			break;
		}
	}
	kcl_chacha_setIV(stream->ctx, iv, ivsize, counter);
}
Beispiel #15
0
void
xs_stream_encrypt(xsMachine *the)
{
	crypt_stream_t *stream = xsGetHostData(xsThis);
	int ac = xsToInteger(xsArgc);
	size_t len;
	void *indata, *outdata;

	if (xsTypeOf(xsArg(0)) == xsStringType)
		len = c_strlen(xsToString(xsArg(0)));
	else
		len = xsGetArrayBufferLength(xsArg(0));
	if (ac > 2 && xsTypeOf(xsArg(2)) != xsUndefinedType) {
		size_t n = xsToInteger(xsArg(2));
		if (n < len)
			len = n;
	}
	if (ac > 1 && xsTest(xsArg(1))) {
		if (xsGetArrayBufferLength(xsArg(1)) < (xsIntegerValue)len)
			crypt_throw_error(the, "too small buffer");
		xsResult = xsArg(1);
	}
	else
		xsResult = xsArrayBuffer(NULL, len);
	if (xsTypeOf(xsArg(0)) == xsStringType)
		indata = xsToString(xsArg(0));
	else
		indata = xsToArrayBuffer(xsArg(0));
	outdata = xsToArrayBuffer(xsResult);
	(*stream->process)(stream->ctx, indata, outdata, len);
}
Beispiel #16
0
void KPR_canvasRadialGradient_setStyle(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsArg(0));
	xsNumberValue x0 = xsToNumber(xsGet(xsThis, xsID("x0")));
	xsNumberValue y0 = xsToNumber(xsGet(xsThis, xsID("y0")));
	xsNumberValue r0 = xsToNumber(xsGet(xsThis, xsID("r0")));
	xsNumberValue x1 = xsToNumber(xsGet(xsThis, xsID("x1")));
	xsNumberValue y1 = xsToNumber(xsGet(xsThis, xsID("y1")));
	xsNumberValue r1 = xsToNumber(xsGet(xsThis, xsID("r1")));
	UInt32 c, i;
	FskCanvas2dGradientStop stops[kCanvas2DMaxGradientStops];
	xsVars(2);
	xsVar(0) = xsGet(xsThis, xsID("stops"));
	c = xsToInteger(xsGet(xsVar(0), xsID("length")));
	if (c > kCanvas2DMaxGradientStops) c = kCanvas2DMaxGradientStops;
	for (i = 0; i < c; i++) {
		xsVar(1) = xsGetAt(xsVar(0), xsInteger(i));
		stops[i].offset = xsToNumber(xsGet(xsVar(1), xsID("offset")));
		xsVar(1) = xsGet(xsVar(1), xsID("color"));
		if (!KprParseColor(the, xsToString(xsVar(1)), &(stops[i].color)))
			return;
	}
	if (xsTest(xsArg(1)))
		FskCanvas2dSetStrokeStyleRadialGradient(ctx, x0, y0, r0, x1, y1, r1, c, stops);
	else
		FskCanvas2dSetFillStyleRadialGradient(ctx, x0, y0, r0, x1, y1, r1, c, stops);
}
Beispiel #17
0
void KPR_message_set_method(xsMachine *the)
{
	KprMessage self = xsGetHostData(xsThis);
	if (xsTest(xsArg(0)))
		xsThrowIfFskErr(KprMessageSetMethod(self, xsToString(xsArg(0))));
	else
		xsThrowIfFskErr(KprMessageSetMethod(self, NULL));
}
Beispiel #18
0
void KPR_host_set_rotating(xsMachine *the)
{
	KprHost self = xsGetHostData(xsThis);
	if (xsTest(xsArg(0)))
		self->flags |= kprRotating;
	else
		self->flags &= ~kprRotating;
}
Beispiel #19
0
void
xs_dbg_login(xsMachine *the)
{
	char *host = xsToString(xsArg(0));
	char *name = NULL;
	if (xsToInteger(xsArgc) > 1 && xsTest(xsArg(1)))
		name = xsToString(xsArg(1));
	xsSetBoolean(xsResult, xsStartDebug(the, host, name));
}
Beispiel #20
0
void KPR_message_set_responseText(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	if (xsTest(xsArg(0))) {
		xsStringValue body = xsToString(xsArg(0));
		xsThrowIfFskErr(KprMessageSetResponseBody(self, body, FskStrLen(body)));
	}
	else
		xsThrowIfFskErr(KprMessageSetResponseBody(self, NULL, 0));
}
Beispiel #21
0
void KPR_message_set_responseBuffer(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	if (xsTest(xsArg(0))) {
		void* data = xsToArrayBuffer(xsArg(0));
		xsIntegerValue size = xsGetArrayBufferLength(xsArg(0));
		xsThrowIfFskErr(KprMessageSetResponseBody(self, data, size));
	}
	else
		xsThrowIfFskErr(KprMessageSetResponseBody(self, NULL, 0));
}
Beispiel #22
0
void KPR_message_set_requestChunk(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	if (xsTest(xsArg(0))) {
		void* data = xsGetHostData(xsArg(0));
		xsIntegerValue size = xsToInteger(xsGet(xsArg(0), xsID_length));
		xsThrowIfFskErr(KprMessageSetRequestBody(self, data, size));
	}
	else
		xsThrowIfFskErr(KprMessageSetRequestBody(self, NULL, 0));
}
Beispiel #23
0
void KPR_canvasRenderingContext2D_arc(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue x = xsToNumber(xsArg(0));
	xsNumberValue y = xsToNumber(xsArg(1));
	xsNumberValue radius = xsToNumber(xsArg(2));
	xsNumberValue startAngle = xsToNumber(xsArg(3));
	xsNumberValue endAngle = xsToNumber(xsArg(4));
	xsBooleanValue anticlockwise = (xsToInteger(xsArgc) > 5) ? xsTest(xsArg(5)) : 0;
	FskCanvas2dPathArc(ctx, NULL, x, y, radius, startAngle, endAngle, anticlockwise);
}
Beispiel #24
0
void KPR_debug_set_behavior(xsMachine *the)
{
	KprDebug self = xsGetHostData(xsThis);
	xsForget(self->behavior);
	if (xsTest(xsArg(0))) {
		if (xsIsInstanceOf(xsArg(0), xsObjectPrototype)) {
			self->behavior = xsArg(0);
			xsRemember(self->behavior);
		}
	}
}
Beispiel #25
0
void parseAttributes(xsMachine* the)
{
	xsIntegerValue c, i;
	if (xsTest(xsVar(CHILDREN))) {
		c = xsToInteger(xsGet(xsVar(CHILDREN), xsID_length));
		for (i = 0; i < c; i++) {
			xsVar(CHILD) = xsGet(xsVar(CHILDREN), i);
			parseAttribute(the);
		}
	}
}
Beispiel #26
0
void Zeroconf_set_behavior(xsMachine *the)
{
	KprZeroconfCommon self = xsGetHostData(xsThis);
	xsForget(self->behavior);
	self->behavior = xsUndefined;
	if (xsTest(xsArg(0))) {
		if (xsIsInstanceOf(xsArg(0), xsObjectPrototype)) {
			self->behavior = xsArg(0);
			xsRemember(self->behavior);
		}
	}
}
Beispiel #27
0
void KPR_message_set_responseChunk(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	//xsTrace("message.responseChunk deprecated, use responseBuffer\n");
	if (xsTest(xsArg(0))) {
		void* data = xsGetHostData(xsArg(0));
		xsIntegerValue size = xsToInteger(xsGet(xsArg(0), xsID_length));
		xsThrowIfFskErr(KprMessageSetResponseBody(self, data, size));
	}
	else
		xsThrowIfFskErr(KprMessageSetResponseBody(self, NULL, 0));
}
Beispiel #28
0
void xscAppendPattern(txMachine* the, txByte theCode)
{
	xsIntegerValue c, i;

	xscAppend1(the, theCode);
	c = xsToInteger(xsGet(xsVar(1), the->lengthID));
	xscAppend1(the, (txByte)c);
	for (i = 0; i < c; i++) {
		xsVar(2) = xsGet(xsVar(1), (xsIndex)i);
		xsVar(3) = xsGet(xsVar(2), xsID("namespace"));
		if (xsTest(xsVar(3)))
			xscAppend2(the, xsToID(xsVar(3)));
		else
			xscAppend2(the, XS_NO_ID);
		xsVar(3) = xsGet(xsVar(2), xsID("name"));
		if (xsTest(xsVar(3)))
			xscAppend2(the, xsToID(xsVar(3)));
		else
			xscAppend2(the, XS_NO_ID);
	}
}
Beispiel #29
0
void KPR_host_get_profiling(xsMachine* the)
{
	KprHost self = xsGetHostData(xsThis);
	KprApplication application = (KprApplication)self->first;
	Boolean result = false;
	xsBeginHost(application->the);
	{
		result = xsTest(xsCall0(xsGet(xsGlobal, xsID("xs")), xsID("isProfiling")));
	}
	xsEndHost(application->the);
	xsResult = xsBoolean(result);
}
Beispiel #30
0
void KPR_mqttclient_connect(xsMachine* the)
{
	KPR_MQTTClientRecord *self = xsGetHostData(xsThis);
	char *host;
	UInt16 port;
	KprMQTTClientConnectOptions options;

	if (xsToInteger(xsArgc) != 10) xsThrowIfFskErr(kFskErrParameterError);

	host = xsToString(xsArg(0));
	port = xsToInteger(xsArg(1));

	options.isSecure = xsToBoolean(xsArg(2));
	options.keepAlive = xsToInteger(xsArg(3));
	options.username = xsTest(xsArg(4)) ? xsToString(xsArg(4)) : NULL;
	options.password = xsTest(xsArg(5)) ? xsToString(xsArg(5)) : NULL;
	options.willIsRetained = false;
	options.willQualityOfService = 0;
	options.willTopic = NULL;
	options.willPayload = NULL;
	options.willPayloadLength = 0;

	if (xsTest(xsArg(6))) {
		options.willTopic = xsToString(xsArg(6));
		options.willQualityOfService = xsToInteger(xsArg(7));
		options.willIsRetained = xsToBoolean(xsArg(8));

		if (xsTest(xsArg(9))) {
			if (isArrayBuffer(xsArg(9))) {
				options.willPayload = xsToArrayBuffer(xsArg(9));
				options.willPayloadLength = xsGetArrayBufferLength(xsArg(9));
			} else {
				options.willPayload = xsToString(xsArg(9));
				options.willPayloadLength = FskStrLen(options.willPayload);
			}
		}
	}

	xsThrowIfFskErr(KprMQTTClientConnect(self->client, host, port, &options));
}