Beispiel #1
0
void KprMessageResumed(KprMessage self)
{
	if (!self->response.callback) {
        KprMessageTransform(self, gShell->the);
		KprMessageComplete(self);
	}
}
Beispiel #2
0
void KprMessageResume(KprMessage self)
{
	FskInstrumentedItemSendMessageDebug(self, kprInstrumentedMessageResume, self);
	if (self->response.dispose)
		(*self->response.dispose)(self->response.target);
	self->response.callback = NULL;
	self->response.dispose = NULL;
	self->response.target = NULL;
	self->usage--; // response
	KprMessageTransform(self, gShell->the);
	KprMessageComplete(self);
}
Beispiel #3
0
void KprHTTPClientInvoke(KprService service UNUSED, KprMessage message)
{
	FskErr err = kFskErrNone;
	KprHTTPClient self = gKprHTTPClient;
	if (KprMessageContinue(message)) {
		KprHTTPTarget target = NULL;
		KprHTTPCacheValue cached = NULL;
		char* value;
		FskInstrumentedItemSendMessageDebug(message, kprInstrumentedMessageHTTPBegin, message)
		bailIfError(KprHTTPTargetNew(&target, message));
		if (!message->method || !FskStrCompare(message->method, "GET"))
			KprHTTPCacheFetch(self->cache, message->url, &cached);
		if (cached) {
			if (KprHTTPCacheValueIsFresh(cached)) {
				if (KprHTTPClientReadCache(message, cached) == kFskErrNone) {
					KprMessageTransform(message, gHTTPService.machine);
					KprHTTPClientResumeTarget(target);
					return;
				}
			}
			else {
				value = FskAssociativeArrayElementGetString(cached->headers, kprHTTPHeaderLastModified);
				if (value)
					(void)KprMessageSetRequestHeader(message, kprHTTPHeaderIfModifiedSince, value);
				value = FskAssociativeArrayElementGetString(cached->headers, kprHTTPHeaderETag);
				if (value)
					(void)KprMessageSetRequestHeader(message, kprHTTPHeaderIfNoneMatch, value);
				target->cached = cached;
			}
		}
		KprHTTPClientCookiesGet(message->url, &value);
		if (value) {
			(void)KprMessageSetRequestHeader(message, kprHTTPHeaderCookie, value);
			FskMemPtrDispose(value);
		}
		KprHTTPClientAddTarget(target);
		return;
	bail:
		message->error = err;
	}
	FskThreadPostCallback(KprShellGetThread(gShell), (FskThreadCallback)KprMessageComplete, message, NULL, NULL, NULL);
}
Beispiel #4
0
void KprXKPRServiceInvoke(KprService self UNUSED, KprMessage message)
{
	char* authority = message->parts.authority;
	UInt32 authorityLength = message->parts.authorityLength;
	message->usage--; // event queue
	if (!FskStrCompareWithLength(authority, "shell", authorityLength))
		KprContextInvoke(gShell, message);
	else {
		KprContentLink link = gShell->applicationChain.first;
		while (link) {
			KprApplication application = (KprApplication)link->content;
			if (application->id && (!FskStrCompareWithLength(authority, application->id, authorityLength))) {
				KprContextInvoke(application, message);
				break;
			}
			link = link->next;
		}
	}
	if (!message->response.callback) {
        KprMessageTransform(message, gShell->the);
		KprMessageComplete(message);
	}
}
Beispiel #5
0
void KprFILEServiceInvoke(KprService service UNUSED, KprMessage message)
{
	FskErr err = kFskErrNone;
	char* path = NULL;
	FskFileInfo info;
	FskDirectoryIterator iterator = NULL;
	char* pathName = NULL;
	char* sniff = NULL;
	FskFile fref = NULL;
	char *name = NULL;
	if (KprMessageContinue(message)) {
		if (!message->method || FskStrCompare(message->method, "GET")) {
			bailIfError(KprURLToPath(message->url, &path));
			bailIfError(FskFileGetFileInfo(path, &info));
			if (kFskDirectoryItemIsDirectory == info.filetype) {
				unsigned char buffer[4096];
				UInt32 itemType;
				double date;
				UInt32 size;
				xsBeginHostSandboxCode(gFILEService.machine, NULL);
				{
					xsVars(3);
					{
						xsTry {
							xsVar(0) = xsGet(xsGlobal, xsID("Files"));
							xsResult = xsNewInstanceOf(xsArrayPrototype);
							bailIfError(FskDirectoryIteratorNew(path, &iterator, 0));
							while (kFskErrNone == FskDirectoryIteratorGetNext(iterator, &name, &itemType)) {
								if (name[0] == '.') {
									FskMemPtrDisposeAt(&name);
									continue;
								}
								if (kFskDirectoryItemIsFile == itemType) {
									pathName = FskStrDoCat(path, name);
									bailIfError(FskFileGetFileInfo(pathName, &info));
									bailIfError(FskFileOpen(pathName, kFskFilePermissionReadOnly, &fref));
									bailIfError(FskFileRead(fref, sizeof(buffer), buffer, &size));
									FskFileClose(fref);
									fref = NULL;
									if (kFskErrNone == FskMediaPlayerSniffForMIME(buffer, size, NULL, pathName, &sniff)) {
									}
									else if (kFskErrNone == FskImageDecompressSniffForMIME(buffer, size, NULL, pathName, &sniff)) {
									}
									FskMemPtrDispose(pathName);
									pathName = NULL;
								}
								xsVar(1) = xsNewInstanceOf(xsObjectPrototype);
								xsNewHostProperty(xsVar(1), xsID("name"), xsString(name), xsDefault, xsDontScript);
								xsNewHostProperty(xsVar(1), xsID("path"), xsString(name), xsDefault, xsDontScript);
								FskStrCopy((char*)buffer, message->url);
								FskStrCat((char*)buffer, name);
								if (kFskDirectoryItemIsDirectory == itemType) {
									xsVar(2) = xsGet(xsVar(0), xsID("directoryType"));
									FskStrCat((char*)buffer, "/");
								}
								else if (kFskDirectoryItemIsFile == itemType) {
									xsVar(2) = xsGet(xsVar(0), xsID("fileType"));
									if (info.fileModificationDate > info.fileCreationDate)
										date = info.fileModificationDate * 1000.0;	
									else
										date = info.fileCreationDate * 1000.0;
									xsNewHostProperty(xsVar(1), xsID("date"), xsNumber(date), xsDefault, xsDontScript);
									xsNewHostProperty(xsVar(1), xsID("size"), xsNumber(info.filesize), xsDefault, xsDontScript);
									if (sniff) {
										xsNewHostProperty(xsVar(1), xsID("mime"), xsString(sniff), xsDefault, xsDontScript);
										FskMemPtrDispose(sniff);
										sniff = NULL;
									}
								}
								else
									xsVar(2) = xsGet(xsVar(0), xsID("linkType"));
								xsNewHostProperty(xsVar(1), xsID("type"), xsVar(2), xsDefault, xsDontScript);
								xsNewHostProperty(xsVar(1), xsID("url"), xsString((char*)buffer), xsDefault, xsDontScript);
								(void)xsCall1(xsResult, xsID("push"), xsVar(1));
								FskMemPtrDisposeAt(&name);
							}
							xsResult = xsCall1(xsGet(xsGlobal, xsID("JSON")), xsID("stringify"), xsResult);
							message->response.body = FskStrDoCopy(xsToString(xsResult));
							message->response.size = FskStrLen(message->response.body);
							KprMessageTransform(message, gFILEService.machine);
						}
						xsCatch {
						}
					}
				}
				xsEndHostSandboxCode();
			}
			else if (kFskDirectoryItemIsFile == info.filetype) {