예제 #1
0
void KPR_message_set_requestText(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	if (xsTest(xsArg(0))) {
		xsStringValue body = xsToString(xsArg(0));
		xsThrowIfFskErr(KprMessageSetRequestBody(self, body, FskStrLen(body)));
	}
	else
		xsThrowIfFskErr(KprMessageSetRequestBody(self, NULL, 0));
}
예제 #2
0
void KPR_message_set_requestBuffer(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	if (xsTest(xsArg(0))) {
		void* data = xsToArrayBuffer(xsArg(0));
		xsIntegerValue size = xsGetArrayBufferLength(xsArg(0));
		xsThrowIfFskErr(KprMessageSetRequestBody(self, data, size));
	}
	else
		xsThrowIfFskErr(KprMessageSetRequestBody(self, NULL, 0));
}
예제 #3
0
void KPR_message_set_requestChunk(xsMachine* the)
{
	KprMessage self = xsGetHostData(xsThis);
	//xsTrace("message.requestChunk deprecated, use requestBuffer\n");
	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));
}
예제 #4
0
 void KprZeroconfDiscoverServerCallback(KprZeroconfBrowser self, KprZeroconfServiceInfo service, Boolean alive)
 {
 #define kKPRZeroconfKinomaDiscoverURL "xkpr://%s/discover"
 #define kKPRZeroconfKinomaDiscoverJSON "{\"id\":\"%s\",\"uuid\":\"%s\",\"url\":\"http://%s:%lu/\",\"protocol\":\"zeroconf\"}"
 #define kKPRZeroconfKinomaForgetURL "xkpr://%s/forget"
 #define kKPRZeroconfKinomaForgetJSON "{\"id\":\"%s\",\"uuid\":\"%s\",\"protocol\":\"zeroconf\"}"
 	FskErr err = kFskErrNone;
 	char id[256];
 	char url[1024];
 	char json[2048];
 	UInt32 size;
 	KprMessage message = NULL;
 	char* authority = NULL;
 	bailIfError(KprZeroconfServiceNewAuthority(service->type, &authority));
	if (alive) {
		snprintf(url, sizeof(url), kKPRZeroconfKinomaDiscoverURL, self->authority);
		snprintf(json, sizeof(json), kKPRZeroconfKinomaDiscoverJSON, authority, service->name, service->ip, service->port);
	}
	else {
		snprintf(url, sizeof(url), kKPRZeroconfKinomaForgetURL, self->authority);
		snprintf(json, sizeof(json), kKPRZeroconfKinomaForgetJSON, authority, service->name);
	}
 	size = FskStrLen(json);
 	bailIfError(KprMessageNew(&message, url));
 	bailIfError(KprMessageSetRequestBody(message, json, size));
 	FskStrNumToStr(size, id, sizeof(id));
 	bailIfError(KprMessageSetRequestHeader(message, kFskStrContentLength, id));
 	bailIfError(KprMessageSetRequestHeader(message, kFskStrContentType, "application/json"));
 	KprMessageInvoke(message, NULL, NULL, NULL);
  	FskMemPtrDispose(authority);
	return;
 bail:
	KprMessageDispose(message);
  	FskMemPtrDispose(authority);
 }