Example #1
0
void on_drag_data_received(GtkWidget* widget, GdkDragContext* context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data)
{
	FskGtkWindow gtkWin = user_data;
	gboolean dnd_success = FALSE;
	FskDragDropFile dropFileList = NULL;
	FskDragDropFile droppedFile = NULL;
	char* path = NULL;
	if (gdk_drag_context_get_suggested_action(context) == GDK_ACTION_COPY) {
		char* string = (char*)gtk_selection_data_get_data(data);
		char* end;
		FskFileInfo itemInfo;
		for (end = FskStrStr(string, "\r\n"); end; end = FskStrStr(string, "\r\n")) {
			BAIL_IF_ERR(FskMemPtrNewClear(sizeof(FskDragDropFileRecord), (FskMemPtr*)&droppedFile));
			FskListAppend((FskList *)&dropFileList, droppedFile);
			*end = 0;
			BAIL_IF_ERR(KprURLToPath(string, &path));
			BAIL_IF_ERR(FskFileGetFileInfo(path, &itemInfo));
			if (itemInfo.filetype == kFskDirectoryItemIsDirectory) {
				int length = FskStrLen(path);
				BAIL_IF_ERR(FskMemPtrNew(length + 2, &droppedFile->fullPathName));
				FskMemCopy(droppedFile->fullPathName, path, length);
				droppedFile->fullPathName[length] = '/';
				droppedFile->fullPathName[length + 1] = 0;
				FskMemPtrDispose(path);
			}
			else {
				droppedFile->fullPathName = path;
			}
			path = NULL;
			string = end + 2;
			*end = '\r';
		}
		(*gDropTargetProc)(kFskDragDropTargetEnterWindow, x, y, dropFileList, gtkWin->owner);
		(*gDropTargetProc)(kFskDragDropTargetDropInWindow, x, y, dropFileList, gtkWin->owner);
		dnd_success = TRUE;
	}
bail:
	gtk_drag_finish(context, dnd_success, TRUE, time);
	FskMemPtrDispose(path);
	while (NULL != dropFileList) {
		droppedFile = dropFileList;
		FskListRemove((FskList *)&dropFileList, droppedFile);
		FskMemPtrDispose(droppedFile->fullPathName);
		FskMemPtrDispose(droppedFile);
	}
}
Example #2
0
FskErr mp3ReaderNew(FskMediaReader reader, void **readerState, const char *mimeType, const char *uri, FskMediaSpooler spooler)
{
	FskErr err;
	mp3Reader state = NULL;

	if (NULL == spooler) {
		err = kFskErrUnimplemented;
		goto bail;
	}

	err = FskMemPtrNewClear(sizeof(mp3ReaderRecord), &state);
	if (err) goto bail;

	*readerState = state;				// must occur before doSetState
	state->spooler = spooler;
	state->reader = reader;

	state->spooler->onSpoolerCallback = mp3SpoolerCallback;
	state->spooler->clientRefCon = state;
	state->spooler->flags |= kFskMediaSpoolerForwardOnly;

	if (spooler->doOpen) {
		err = (spooler->doOpen)(spooler, kFskFilePermissionReadOnly);
		if (err) goto bail;

		state->spoolerOpen = true;
	}

	(reader->doSetState)(reader, kFskMediaPlayerStateInstantiating);

	state->icy.isNanocaster = (NULL != FskStrStr(mimeType, "live365=true"));

	err = mp3Instantiate(state);
	if (err) {
		if (kFskErrNeedMoreTime == err)
			err = kFskErrNone;
		goto bail;
	}

bail:
	if ((kFskErrNone != err) && (NULL != state)) {
		mp3ReaderDispose(reader, state);
		state = NULL;
	}

	*readerState = state;

	return err;
}
Example #3
0
void KprServicesDiscover(KprContext context, char* id, char* services)
{
	KprService service = gServices;
	while (service) {
		if (service->discover) {
			if (!service->thread)
				service->thread = KprShellGetThread(gShell);
			if (services) {
				if (FskStrStr(services, service->id))
					FskThreadPostCallback(service->thread, (FskThreadCallback)service->discover, service, FskStrDoCopy(context->id), FskStrDoCopy(id), false);
				else if (service->forget)
					FskThreadPostCallback(service->thread, (FskThreadCallback)service->forget, service, FskStrDoCopy(context->id), FskStrDoCopy(id), NULL);
			}
			else 
				FskThreadPostCallback(service->thread, (FskThreadCallback)service->discover, service, FskStrDoCopy(context->id), FskStrDoCopy(id), (void*)true);
		}
		service = service->next;
	}
}
Example #4
0
FskErr mp3ReaderGetFlags(void *readerState, void *track, UInt32 propertyID, FskMediaPropertyValue property)
{
	mp3Reader state = readerState;
	FskMediaPropertyValueRecord value;

	property->type = kFskMediaPropertyTypeInteger;
	property->value.integer = kFskMediaPlayerFlagHasAudio;

	if (kFskErrNone == FskMediaMetaDataGet(state->mi.meta, "Genre", 0, &value, NULL)) {
		if (0 == FskStrCompareCaseInsensitive(value.value.str, "Audiobooks"))
			property->value.integer |= kFskMediaPlayerFlagHasAudioBook;
	}

	if (kFskErrNone == FskMediaMetaDataGet(state->mi.meta, "Album", 0, &value, NULL)) {
		if (NULL != FskStrStr(value.value.str, "Librivox"))
			property->value.integer |= kFskMediaPlayerFlagHasAudioBook;
	}

	return kFskErrNone;
}
Example #5
0
FskErr FskFSVolumeGetInfo(UInt32 volumeID, char **pathOut, char **nameOut, UInt32 *volumeType, Boolean *isRemovable, FskInt64 *capacity, FskInt64 *freeSpace)
{
	FskErr err = kFskErrNone;
	struct statfs *fs;

	if (volumeID >= (UInt32)gNumStatFS)
		return kFskErrInvalidParameter;
	fs = &gStatFS[volumeID];
	if (pathOut)
		*pathOut = FskStrDoCopy(fs->f_mntonname);
	if (nameOut)
		*nameOut = FskStrDoCopy(FskCocoaDisplayNameAtPath(fs->f_mntonname));
	if (capacity)
		*capacity = fs->f_blocks * fs->f_bsize;
	if (freeSpace)
		*freeSpace = fs->f_bavail * fs->f_bsize;
	if (isRemovable)
		*isRemovable = FskCocoaIsRemovable(fs->f_mntonname);
	if (volumeType) {
		*volumeType = kFskVolumeTypeUnknown;
		if (!(fs->f_flags & MNT_LOCAL))
			*volumeType = kFskVolumeTypeNetwork;
		else if (FskStrCompare(fs->f_fstypename, "hfs") == 0 || FskStrCompare(fs->f_fstypename, "ufs") == 0)
			*volumeType = kFskVolumeTypeFixed;
		else if (FskStrCompare(fs->f_fstypename, "devfs") == 0)
			*volumeType = kFskVolumeTypeUnknown;
		else {
			char *product;
			if ((err = FskFSVolumeGetDeviceInfo(volumeID, NULL, &product, NULL, NULL)) != kFskErrNone)
				return err;
			if (product == NULL)
				*volumeType = kFskVolumeTypeUnknown;
			else if (FskStrStr(product, "MS") || FskStrStr(product, "WM-MS"))
				*volumeType = kFskVolumeTypeMemoryStick;
			else if (FskStrStr(product, "MMC"))
				*volumeType = kFskVolumeTypeMMC;
			else if (FskStrStr(product, "CF"))
				*volumeType = kFskVolumeTypeCompactFlash;
			else if (FskStrStr(product, "SM"))
				*volumeType = kFskVolumeTypeSmartMedia;
			else if (FskStrStr(product, "SD"))
				*volumeType = kFskVolumeTypeSDMemory;
			else
				*volumeType = kFskVolumeTypeUnknown;
		}
	}
	return err;
}
Example #6
0
static void DNSSD_API KprZeroconfPlatformWildcardCallback(DNSServiceRef serviceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char* name, const char* type, const char* domain, void* context)
{
	FskErr err = kFskErrNone;
	KprZeroconfBrowser self = context;
	KprZeroconfPlatformBrowser browser = self->platform;
	char* ptr = NULL;
	char* serviceType = NULL;
	if (errorCode != kDNSServiceErr_NoError) {
		FskInstrumentedItemPrintfDebug(browser, "KprZeroconfPlatformWildcardCallback returned %d\n", errorCode);
	}
	else if (flags & kDNSServiceFlagsAdd) {
		char* ptr = FskStrStr(type, "local.");
		if (ptr) {
			*ptr = 0;
			bailIfError(FskMemPtrNew(FskStrLen(name) + FskStrLen(type) + 2, &serviceType));
			FskStrCopy(serviceType, name);
			FskStrCat(serviceType, ".");
			FskStrCat(serviceType, type);
			if (!KprZeroconfPlatformServiceFindType(browser->types, serviceType)) {
				KprZeroconfPlatformService service = NULL;
				DNSServiceErrorType error;
				FskInstrumentedItemPrintfDebug(browser, "WILDCARD: %d %s", interfaceIndex, serviceType);
				error = DNSServiceBrowse(&serviceRef, 0, 0, serviceType, NULL, KprZeroconfPlatformBrowseCallback, self);
				if (error != kDNSServiceErr_NoError) {
					bailIfError(kFskErrNetworkErr);
				}
				bailIfError(KprZeroconfPlatformServiceNew(&service, NULL, serviceRef, serviceType, 0));
				FskListAppend(&browser->types, service);
			}
		}
	}
bail:
	if (ptr) *ptr = 'l';
	FskMemPtrDispose(serviceType);
	return;
}
Example #7
0
void KprServicesShare(KprContext context, Boolean shareIt, char* services, char* uuid)
{
	KprService service = gServices;
	while (service) {
		if (service->share) {
			if (!service->thread)
				service->thread = KprShellGetThread(gShell);
//			FskThreadPostCallback(service->thread, (FskThreadCallback)service->share, service, FskStrDoCopy(context->id), (void*)(services ? (FskStrStr(services, service->id) ? value : false) : value), (void*)(services ? false : true));
			FskThreadPostCallback(service->thread, (FskThreadCallback)service->share, service, FskStrDoCopy(context->id), (void*)(services ? (FskStrStr(services, service->id) != NULL) : shareIt), (void*)uuid);
		}
		service = service->next;
	}
}
Example #8
0
FskErr FskTextFreeTypeInstallFonts(char* fontsPath, char* defaultFont)
{
	FskErr err = kFskErrNone;
	FskTextEngine fte;
	char *fromDirectory = NULL;
	char* fromPath = NULL;
	FskDirectoryIterator iterator = NULL;
	char *name = NULL;
	UInt32 type;
#if TARGET_OS_ANDROID
	char *toDirectory = NULL;
	char* toPath = NULL;
	FskFileInfo itemInfo;
	FskFileMapping map = NULL;
	unsigned char *data;
	FskInt64 dataSize;
	FskFile file = NULL;
#endif	
	err = FskTextEngineNew(&fte, NULL);
	if (err) goto bail;
	fromDirectory = FskEnvironmentDoApply(FskStrDoCopy(fontsPath));
	if (!fromDirectory) { err = kFskErrMemFull; goto bail; }
#if TARGET_OS_ANDROID
	if (!FskStrCompareWithLength(fromDirectory, "/data/app/", 10)) {
		err = FskDirectoryGetSpecialPath(kFskDirectorySpecialTypeApplicationPreference, false, NULL, &toDirectory);
		if (err) goto bail;
	}
#endif
	err = FskDirectoryIteratorNew(fromDirectory, &iterator, 0);
	if (err) goto bail;
	while (kFskErrNone == FskDirectoryIteratorGetNext(iterator, &name, &type)) {
		if (type == kFskDirectoryItemIsFile) {
			fromPath = FskStrDoCat(fromDirectory, name);
			if (!fromPath) { err = kFskErrMemFull; goto bail; }
			FskDebugStr("from %s", fromPath);
#if TARGET_OS_ANDROID
			if (toDirectory) {
				toPath = FskStrDoCat(toDirectory, name);
				FskDebugStr("to %s", toPath);
				if (kFskErrNone != FskFileGetFileInfo(toPath, &itemInfo)) {
					err = FskFileMap(fromPath, &data, &dataSize, 0, &map);
					if (err) goto bail;
					err = FskFileCreate(toPath);
					if (err) goto bail;
					err = FskFileOpen(toPath, kFskFilePermissionReadWrite, &file);
					if (err) goto bail;
					err = FskFileWrite(file, dataSize, data, NULL);
					if (err) goto bail;
					FskFileClose(file);
					file = NULL;
					FskFileDisposeMap(map);
					map = NULL;
				}
				FskDebugStr("add %s", toPath);
				FskTextAddFontFile(fte, toPath);
				FskMemPtrDisposeAt(&toPath);
			}
			else
#endif
				FskTextAddFontFile(fte, fromPath);
			FskMemPtrDisposeAt(&fromPath);
		}
		FskMemPtrDisposeAt(&name);
	}
#if TARGET_OS_ANDROID
	if (gAndroidCallbacks->getModelInfoCB) {
		char* osVersion;
		gAndroidCallbacks->getModelInfoCB(NULL, &osVersion, NULL, NULL, NULL);
		if ((FskStrStr(osVersion, "android.5") == osVersion) // for KPR applications
			|| (FskStrStr(osVersion, "5.") == osVersion)) {  // for tests
			BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/fonts.xml"));
		}
		if ((FskStrStr(osVersion, "android.4") == osVersion) // for KPR applications
			|| (FskStrStr(osVersion, "4.") == osVersion)) {  // for tests
			BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/system_fonts.xml"));
			err = FskFTAddMapping("/vendor/etc/fallback_fonts.xml");
			if (err != kFskErrFileNotFound) BAIL(err);
			BAIL_IF_ERR(err = FskFTAddMapping("/system/etc/fallback_fonts.xml"));
		}
		else {
			defaultFont = "Droid Sans";
			BAIL_IF_ERR(err = FskFTAddMapping(NULL));
		}
	}
#endif
	if (defaultFont)
		FskTextDefaultFontSet(fte, defaultFont);
bail:
#if TARGET_OS_ANDROID
	if (file)
		FskFileClose(file);
	if (map)
		FskFileDisposeMap(map);
	FskMemPtrDispose(toPath);
	FskMemPtrDispose(toDirectory);
#endif
	FskMemPtrDispose(name);
	FskDirectoryIteratorDispose(iterator);
	FskMemPtrDispose(fromPath);
	FskMemPtrDispose(fromDirectory);
	FskTextEngineDispose(fte);
	return err;
}
Example #9
0
Boolean FskSSLCheckServerCert(SSL *ssl, char *hostname) {
	long err;
	X509 *peer;
	char peer_CN[256];
	err = SSL_get_verify_result(ssl);
#if 0
	if ((err != X509_V_OK)
		&& (err != X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
		&& (err != X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) {
		ERR_print_errors_fp(stderr);
fprintf(stderr, "[%s] cert for %s didn't verify %d %s\n", threadTag(FskThreadGetCurrent()), hostname, err, X509_verify_cert_error_string(err));
#else
	if (err != X509_V_OK) {
		if ((NULL != FskStrStr(hostname, "google.com")) 
			|| (NULL != FskStrStr(hostname, "googleapis.com")) 
			|| (NULL != FskStrStr(hostname, "twitter.com"))
			|| (NULL != FskStrStr(hostname, "yammer.com"))
			|| (NULL != FskStrStr(hostname, "facebook.com"))
			|| (NULL != FskStrStr(hostname, "foursquare.com"))
			|| (NULL != FskStrStr(hostname, "akamaihd.net"))
			|| (NULL != FskStrStr(hostname, "fbcdn.net"))
			|| (NULL != FskStrStr(hostname, "radiotime.com"))
			|| (NULL != FskStrStr(hostname, "s3.amazonaws.com"))
			|| (NULL != FskStrStr(hostname, "orb.com"))) {
			if ((err != X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
				&& (err != X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY)) {
				return false;
			}
			myprintf((stderr, "b) cert didn't verify because %d %s\n", err, X509_verify_cert_error_string(err)));
			myprintf((stderr, " but since it's %s we'll let it through\n", hostname));
		}
		else {
#endif
			return false;
		}
	}

	peer = SSL_get_peer_certificate(ssl);
	X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName,
						peer_CN, 256);
//fprintf(stderr, "comparing peer_CN %s with hostname %s\n", peer_CN, hostname);
	if (FskStrCompareCaseInsensitive(peer_CN, hostname)) {
		int pos, L, subL;
		char *match = peer_CN + 1;

		subL = FskStrLen(match);
		L = FskStrLen(hostname);
		if (peer_CN[0] == '*') {
			pos = L - subL;
			if (0 == FskStrCompareCaseInsensitive(match, hostname + pos)) {
//fprintf(stderr, "Matched wildcard %s and %s\n", match, hostname + pos);
				return true;
			}
		}

		if (	(FskStrEndsWith(match, "akamaihd.net")
				&& FskStrEndsWith(hostname, "akamai.net")) 
			||	(FskStrEndsWith(match, "akamai.net")
				&& FskStrEndsWith(hostname, "akamaihd.net")) ) {
			return true;
		}
			
	

		myprintf((stderr, "cert common name %s and host %s don't match\n", peer_CN, hostname));
		return false;
	}

	return true;
}

//SSL_CTX *FskSSLInitialize(char *keyfile, char *password)
static SSL_CTX *FskOpenSSLInitialize(const char *calistpath)
{
	SSL_METHOD	*method;
	SSL_CTX		*context;

	if (gSSLContext) {
		return gSSLContext;
	}
	else {
		SSL_library_init();
		SSL_load_error_strings();			// not necessary, but useful
	}

	method = SSLv23_method();
	context = SSL_CTX_new(method);

#if 0
	if (FskStrLen(keyfile) > 0) {
		keyfile = FskEnvironmentDoApply(FskStrDoCopy(keyfile));
		if (!SSL_CTX_use_certificate_chain_file(context, keyfile))
			doSSLError("Can't read certificate file");
		fprintf(stderr, "keyfile is %s\n", keyfile);

		if (FskStrLen(password) > 0) {
			gSSLPassword = FskStrDoCopy(password);
			SSL_CTX_set_default_passwd_cb(context, passwordCallback);
			if (!SSL_CTX_use_PrivateKey_file(context, keyfile, SSL_FILETYPE_PEM))
				doSSLError( "Can't read private keyfile");
		}

		FskMemPtrDispose(keyfile);
	}
#endif

#if TARGET_OS_WIN32
	{
	// try to make the path 8.3 safe to avoid nightmares with multibyte character paths, etc.
	UInt16 *nativePath;

	if (kFskErrNone == FskFilePathToNative(calistpath, (char **)&nativePath)) {
		DWORD shortLen;

		shortLen = GetShortPathNameW(nativePath, NULL, 0);
		if (0 != shortLen) {
			UInt16 *eightDotThree;

			if (kFskErrNone == FskMemPtrNewClear(shortLen * 2, (FskMemPtr *)&eightDotThree)) {
				if (0 != GetShortPathNameW(nativePath, eightDotThree, shortLen)) {
					char *utf8;
					UInt32 utf8Len;

					if (kFskErrNone == FskTextUnicode16LEToUTF8(eightDotThree, shortLen * 2, &utf8, &utf8Len)) {
						char *enc;

						if (kFskErrNone == FskTextToPlatform(utf8, utf8Len, &enc, NULL)) {
							FskMemPtrDispose(calistpath);
							calistpath = enc;
						}
						FskMemPtrDispose(utf8);
					}
				}
				FskMemPtrDispose(eightDotThree);
			}
		}
		FskMemPtrDispose(nativePath);
	}
	}
#endif

	if (!(SSL_CTX_load_verify_locations(context, calistpath, 0))) {
		doSSLError("Can't read default CA list");
	}

	SSL_CTX_set_verify_depth(context, 0);

//	SSL_CTX_set_verify(context, SSL_VERIFY_PEER, 0);

	gSSLContext = context;

	return context;
}
Example #10
0
FskErr mp3RefillReadBuffer(mp3Reader state, UInt32 minimumBytesNeeded)
{
	FskErr err = kFskErrNone;
	UInt32 bytesInBuffer = (UInt32)(state->readBufferEnd - state->readBufferPtr);
	UInt32 bytesRead;
	void *buffer;
	Boolean firstTime = true;

	FskMemMove(state->readBuffer, state->readBufferPtr, bytesInBuffer);
	state->readBufferPtr = state->readBuffer;
	state->readBufferEnd = state->readBufferPtr + bytesInBuffer;

	while (true) {
		UInt32 bytesToRead = kMP3ReadBufferSize - bytesInBuffer;

		if (state->spoolerSize && ((state->position + bytesToRead) > state->spoolerSize)) {
			bytesToRead = (UInt32)(state->spoolerSize - state->position);
			if (0 == bytesToRead) {
				err = kFskErrEndOfFile;
				goto bail;
			}
		}

		if (0 != state->icy.metaInt) {
			if (0 != state->icy.metaBytesToCollect) {
				err = FskMediaSpoolerRead(state->spooler, state->position, state->icy.metaBytesToCollect, &buffer, &bytesRead);
				if (kFskErrNone != err) goto readErr;

				state->position += bytesRead;

				err = FskMemPtrRealloc(state->icy.metaBytesCollected + bytesRead + 1, &state->icy.metaBytes);
				if (err) return err;

				FskMemMove(state->icy.metaBytes + state->icy.metaBytesCollected, buffer, bytesRead);
				state->icy.metaBytes[state->icy.metaBytesCollected + bytesRead] = 0;

				state->icy.metaBytesCollected += bytesRead;
				state->icy.metaBytesToCollect -= bytesRead;
				if (0 == state->icy.metaBytesToCollect) {
					if (0 == FskStrCompareCaseInsensitiveWithLength((char *)state->icy.metaBytes, "StreamTitle=", 12)) {
						char *start = (char *)state->icy.metaBytes + 13;
						char *end = start;
						char *dash;
						FskMediaPropertyValueRecord prop;

						while (true) {
							end = FskStrChr(end, start[-1]);
							if (NULL == end) break;
							if ((0 != end[1]) && (';' != end[1])) {
								end += 1;
								continue;
							}
							break;
						}
						if (end)
							*end = 0;

						while (true) {
							if (kFskErrNone != FskMediaMetaDataRemove(state->mi.meta, "FullName", 0))
								break;
						}

						dash = FskStrStr(start, " - ");
						if (NULL != dash) {
							while (true) {
								if (kFskErrNone != FskMediaMetaDataRemove(state->mi.meta, "Artist", 0))
									break;
							}

							*dash = 0;

							prop.type = kFskMediaPropertyTypeString;
							prop.value.str = icyString(start);
							FskMediaMetaDataAdd(state->mi.meta, "Artist", NULL, &prop, kFskMediaMetaDataFlagOwnIt);

							prop.type = kFskMediaPropertyTypeString;
							prop.value.str = icyString(dash + 3);
							FskMediaMetaDataAdd(state->mi.meta, "FullName", NULL, &prop, kFskMediaMetaDataFlagOwnIt);
						}
						else {
							prop.type = kFskMediaPropertyTypeString;
							prop.value.str = icyString(start);
							FskMediaMetaDataAdd(state->mi.meta, "FullName", NULL, &prop, kFskMediaMetaDataFlagOwnIt);
						}

						FskMediaReaderSendEvent(state->reader, kFskEventMediaPlayerMetaDataChanged);
					}
					FskMemPtrDisposeAt((void**)(void*)(&state->icy.metaBytes));
				}
				continue;
			}
			else
			if (state->position == state->icy.nextMetaPosition) {
				err = FskMediaSpoolerRead(state->spooler, state->position, 1, &buffer, &bytesRead);
				if (kFskErrNone != err) goto readErr;

				state->position += 1;
				state->icy.metaBytesToCollect = ((unsigned char *)buffer)[0] * 16;
				state->icy.metaBytesCollected = 0;
				state->icy.nextMetaPosition += 1 + state->icy.metaBytesToCollect + state->icy.metaInt;
				continue;
			}
			else
			if ((state->position <= state->icy.nextMetaPosition) && (state->icy.nextMetaPosition < (state->position + bytesToRead)))
				bytesToRead = (UInt32)(state->icy.nextMetaPosition - state->position);
		}

		err = FskMediaSpoolerRead(state->spooler, state->position, bytesToRead, &buffer, &bytesRead);
readErr:
		if (err) {
			if (false == firstTime) {
				err = kFskErrNone;
				break;
			}
			goto bail;
		}

		FskMemMove(state->readBufferEnd, buffer, bytesRead);

		state->position += bytesRead;
		state->readBufferEnd += bytesRead;
		bytesInBuffer = (UInt32)(state->readBufferEnd - state->readBufferPtr);

		if ((kMP3ReadBufferSize == bytesInBuffer) || (bytesInBuffer >= minimumBytesNeeded))
			break;

		firstTime = false;
	}

	if (bytesInBuffer < minimumBytesNeeded) {
		err = kFskErrNeedMoreTime;
		goto bail;
	}

bail:
	return err;
}
Example #11
0
xsBooleanValue fxIsCommonModule(xsMachine* the, xsStringValue path)
{
	return (FskStrStr(path, "node_modules")) ? 1 : 0;
}
Example #12
0
FskErr FskFSVolumeGetDeviceInfo(UInt32 volumeID, char **vendor, char **product, char **revision, char **vendorSpecific)
{
	FskErr err = kFskErrNone;

	mach_port_t				masterPort	= MACH_PORT_NULL;
	io_service_t			service;
	io_iterator_t			iterator = 0;
	io_object_t				obj;
	char					bsdNode[256];
	CFMutableDictionaryRef properties = NULL;
	Boolean isFound = false;
	char *p;

	if (vendor)
		*vendor = NULL;
	if (product)
		*product = NULL;
	if (revision)
		*revision = NULL;
	if (vendorSpecific)
		*vendorSpecific = NULL;

	if (volumeID >= (UInt32)gNumStatFS)
		return kFskErrInvalidParameter;
	p = gStatFS[volumeID].f_mntfromname;
	if (FskStrStr(p, "/dev/") == p)
		p += 5;
	FskStrCopy(bsdNode, p);

	err = IOMasterPort(MACH_PORT_NULL, &masterPort);
	if (err != kIOReturnSuccess) {
		BAIL(kFskErrUnknown);
	}

	err = IOServiceGetMatchingServices(masterPort, IOBSDNameMatching(masterPort, 0, bsdNode),
									   &iterator);
	if (err != kIOReturnSuccess) {
		BAIL(kFskErrUnknown);
	}

	// There is a 1:1 map from bsd node to IOMedia, so just get the service from the iterator.
	obj = IOIteratorNext(iterator);
	IOObjectRelease(iterator);

	if (obj == 0)
		goto bail;

	// Create an iterator across all parents of the service object passed in.
	err = IORegistryEntryCreateIterator(obj,
										kIOServicePlane,
										kIORegistryIterateRecursively | kIORegistryIterateParents,
										&iterator);
	IOObjectRelease(obj);
	if (KERN_SUCCESS != err) {
		BAIL(kFskErrUnknown);
	}

	while ((service = IOIteratorNext(iterator)) != 0) {
		properties = NULL;

		err = IORegistryEntryCreateCFProperties(service, &properties, kCFAllocatorDefault, kNilOptions);
		if (err == noErr) {
			if (find_and_set_info(properties, CFSTR("Vendor Identification"), vendor)) {
				find_and_set_info(properties, CFSTR("Product Identification"), product);
				find_and_set_info(properties, CFSTR("Product Revision Level"), revision);
				isFound = true;
				goto NextService;
			}

			if (find_and_set_info(properties, CFSTR("device model"), product)) {
				find_and_set_info(properties, CFSTR("device revision"), revision);
				isFound = true;
				goto NextService;
			}
		}

	NextService:
		if (properties)
			CFRelease(properties);

		IOObjectRelease(service);

		if (isFound)
			break;
	}   // while

bail:
	if (iterator)
		IOObjectRelease(iterator);

	if (masterPort)
		mach_port_deallocate(mach_task_self(), masterPort);

	return err;
}
Example #13
0
static void httpProcessRequestHeaders(FskHTTPServerRequest request) {
	char 		*str;
	FskHeaders* headers = request->requestHeaders;
	UInt32 version = FskHeaderHTTPVersion(headers);
	char* host = FskHeaderFind(kFskStrHost, headers);
	char* uri = FskHeaderURI(headers);
	char* filename = FskHeaderFilename(headers);
	
	request->state = kHTTPReadRequestBody;

	if (FskStrCompareWithLength(uri, "http://", 7) == 0) {
		// remove host from filename
		char* p = FskStrStr(filename, "://") + 3;
		p = FskStrChr(p, '/') + 1;
		FskMemMove(filename, p, FskStrLen(p) + 1);
	}
	else {
		if (host) {
			if (FskMemPtrNewClear(FskStrLen(host) + FskStrLen(uri) + 9, &str) != kFskErrNone)
				headers->responseCode = 500;
			else {
				FskStrCat(str, "http://");
				FskStrCat(str, host);
				FskStrCat(str, "/");
				FskStrCat(str, headers->URI);
				FskMemPtrDispose(headers->URI);
				headers->URI = str;
			}
		}
		else if (version >= kFskHTTPVersion1dot1)
			headers->responseCode = 400;
		else if (version == kFskHTTPVersion1dot0) {
			if (FskMemPtrNewClear(FskStrLen(uri) + 9, &str) != kFskErrNone)
				headers->responseCode = 500;
			else {
				FskStrCat(str, "http:///");
				FskStrCat(str, headers->URI);
				FskMemPtrDispose(headers->URI);
				headers->URI = str;
			}
		}
	}
	
	str = FskHeaderFind(kFskStrConnection, request->requestHeaders);
	if (str && FskStrCompareCaseInsensitiveWithLength(str, kFskStrClose, 5) == 0) 
		request->keepAlive = false;
	else
		request->keepAlive = true;

	str = FskHeaderFind(kFskStrContentLength, request->requestHeaders);
	if (str) {
		request->requestBodyContentLength = FskStrToNum(str);
		request->stats.expectedBytesToReceive = FskStrToNum(str);
	}
	else
		request->stats.expectedBytesToReceive = 0;

	str = FskHeaderFind(kFskStrTransferEncoding, request->requestHeaders);
	if (str && (FskStrCompareCaseInsensitiveWithLength(str, kFskStrChunked, FskStrLen(kFskStrChunked)) == 0))
		request->requestBodyChunked = true;
	else
		request->requestBodyChunked = false;
	
	doCallCondition(request->http->callbacks->requestCondition, request, kFskHTTPConditionRequestReceivedRequestHeaders, request->refCon);

	if (NULL != (str = FskHeaderFind(kFskStrExpect, request->requestHeaders))) {
		if (0 == FskStrCompareCaseInsensitive(kFskStr100Continue, str))
			request->state = kHTTPFulfillExpectation;
		else
			request->state = kHTTPDenyExpectation;
	}
}
Example #14
0
// scanProcMount
void scanProcMount() {
	FskErr err;
	FILE *mntFile = NULL;
	char *mntFileBuffer;
	int bufEnd = 0;
	int done = 0;
	int amt;
	char *bufPos, *lineEnd, *path;
	extMount ext = NULL;
	fstabDesc fsDesc = NULL;

	// the default
	addVolume(gAndroidCallbacks->getStaticDataDirCB(), kFskVolumeTypeFixed, 0);
	// and the Jellybean user-space
	addVolume(gAndroidCallbacks->getStaticExternalDirCB(), kFskVolumeTypeSDMemory, 0);

	// read mount file
	err = FskMemPtrNew(MOUNT_BUF_SIZE+1, &mntFileBuffer);
	BAIL_IF_ERR(err);
	bufPos = mntFileBuffer;

	mntFile = FOPEN(LINUX_MOUNT_FILE, "r");
	if (NULL == mntFile) {
		FskAndroidFilesPrintfDebug("opening %s - %d\n", LINUX_MOUNT_FILE, errno);
		return;
	}

	while (!done) {
		// fill the buffer
		amt = fread(mntFileBuffer + bufEnd, 1, MOUNT_BUF_SIZE - bufEnd, mntFile);
		mntFileBuffer[bufEnd + amt + 1] = '\0';

		FskAndroidFilesPrintfDebug("fread %x, %d - got %d\n", mntFileBuffer + bufEnd, MOUNT_BUF_SIZE - bufEnd, amt);
		if (amt > 0)
			bufEnd += amt;
		FskAndroidFilesPrintfDebug("check while(bufpos...) - %p < %p (%d left)\n", bufPos, mntFileBuffer + bufEnd, mntFileBuffer+bufEnd - bufPos);
		while (bufPos < mntFileBuffer + bufEnd) {
			char fsName[256], fsMnt[256], fsType[32];

			// until we have a full line
			if (NULL == (lineEnd = FskStrChr(bufPos, kFskLF)))
				break;

			bufPos = FskStrNCopyUntilSpace(fsName, bufPos, 255);
			bufPos = FskStrNCopyUntilSpace(fsMnt, bufPos, 255);
			bufPos = FskStrNCopyUntilSpace(fsType, bufPos, 31);
			FskAndroidFilesPrintfDebug("got Name: %s Mnt: %s Type: %s\n", fsName, fsMnt, fsType);

			path = fsMnt;
			if ((ext = extMountsContain(path))) {
				FskAndroidFilesPrintfDebug("found path in external mounts %s\n", path);
				fsDesc = extMountToType(ext);
				if (fsDesc)
					addVolume(path, fsDesc->type, fsDesc->removable);
				else
					addVolume(path, kFskVolumeTypeSDMemory, 1);
				goto nextLine;
			}
			FskAndroidFilesPrintfDebug(" - didn't find path in external mounts %s\n", path);

			if (0 == FskStrCompare(fsType, "vfat") || 0 == FskStrCompare(fsType, "fuse")) {
				if (0 != FskStrStr(fsMnt, "emulated")) {
					FskAndroidFilesPrintfDebug(" - emulated - ignore\n");
					goto nextLine;
				}
				path = fsMnt;
				FskAndroidFilesPrintfDebug(" - got a vfat (or fuse) - path is %s\n", path);
				if (0 == FskStrStr(path, "/asec")) {
					FskAndroidFilesPrintfDebug(" - vfat without asec: %s\n", path);
					addVolume(path, kFskVolumeTypeSDMemory, 1);
				}
				else {
					FskAndroidFilesPrintfDebug(" - vfat with asec - ignore - %s\n", path);
				}
			}
nextLine:
			bufPos = lineEnd + 1;
		}

		if (amt == 0) {	// we read no more
			done = 1;
		}
		else {
			// push buffer to beginning
			amt = (mntFileBuffer + bufEnd) - bufPos;
			FskAndroidFilesPrintfDebug("push unread %d bytes to beginning of buffer\n - mntFileBuffer: %d  bufEnd: %d  bufPos: %d\n", amt, mntFileBuffer, bufEnd, bufPos);
			if (amt > 0)
				FskMemCopy(mntFileBuffer, bufPos, amt);
			bufPos = mntFileBuffer;
			bufEnd -= amt;
		}
	}

bail:
	if (NULL != mntFile)
		fclose(mntFile);
}