示例#1
0
FskErr KplVolumeGetInfo(UInt32 volumeID, char **pathOut, char **nameOut, UInt32 *volumeType, Boolean *isRemovable, KplInt64 *capacity, KplInt64 *freeSpace)
{
	volInfoRec *vi;
	FskErr	err = kFskErrOperationFailed;

	if (!volumeList)
		scanVolumes();
	vi = volumeList;
	while (vi) {
		if (volumeID == (UInt32)vi) {
			if (pathOut)
				*pathOut = FskStrDoCopy(vi->mountPoint);
			if (nameOut)
				*nameOut = FskStrDoCopy(vi->name);
			if (volumeType)
				*volumeType = vi->type;
			if (isRemovable)
				*isRemovable = vi->removable;
			if (capacity)
				*capacity = vi->capacity;
			if (freeSpace)
				*freeSpace = vi->remaining;

			err = kFskErrNone;
			break;
		}
		vi = vi->next;
	}

	return err;
}
示例#2
0
// ---------------------------------------------------------------------
FskErr FskFSVolumeIteratorGetNext(FskFSVolumeIterator volIt, UInt32 *id, char **path, char **name)
{
	FskErr ret = kFskErrIteratorComplete;

	if (volIt) {
		pMount theMount = gMounts;
		while (theMount) {
			if (theMount->fsID >= volIt->iter) {
				break;
			}
			theMount = theMount->next;
		}
		if (!theMount) {
			return ret;
		}

		if (id)
			*id = theMount->fsID;

		if (path) *path = FskStrDoCopy(theMount->mountPoint);
		if (name) *name = FskStrDoCopy(theMount->name);

		FskAndroidFilesPrintfDebug("VolIterGetNext iter: %d - path: %s\n", theMount->fsID, theMount->mountPoint);

		volIt->iter = theMount->fsID + 1;
		ret = kFskErrNone;

	}
	return ret;
}
示例#3
0
FskErr KprZeroconfServiceInfoNew(KprZeroconfServiceInfo *it, const char* type, const char* name, const char* host, const char* ip, UInt32 port, const UInt32 interfaceIndex, char* txt)
{
    FskErr err = kFskErrNone;
    KprZeroconfServiceInfo self = NULL;

    bailIfError(FskMemPtrNewClear(sizeof(KprZeroconfServiceInfoRecord), it));
    self = *it;
    self->type = FskStrDoCopy(type);
    bailIfNULL(self->type);
    self->name = FskStrDoCopy(name);
    bailIfNULL(self->name);
    if (host) {
        self->host = FskStrDoCopy(host);
        bailIfNULL(self->host);
    }
    if (ip) {
        self->ip = FskStrDoCopy(ip);
        bailIfNULL(self->ip);
    }
    self->port = port;
    self->interfaceIndex = interfaceIndex;
    if (txt) {
        self->txt = FskStrDoCopy(txt);
        bailIfNULL(self->txt);
    }
    FskInstrumentedItemNew(self, NULL, &KprZeroconfServiceInfoInstrumentation);
bail:
    if (err)
        KprZeroconfServiceInfoDispose(self);
    return err;
}
示例#4
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);
}
示例#5
0
void KPR_debug_file(xsMachine *the)
{
	KprDebug self = xsGetHostData(xsThis);
	KprDebugMachine machine = NULL;
	int command = mxNoCommand;
	char* path = NULL;
	char* value = NULL;
	xsIntegerValue line = -1;
	xsIntegerValue c = xsToInteger(xsArgc);
	xsVars(4);
	if ((c >= 2) && (xsTypeOf(xsArg(0)) == xsStringType) && (xsTypeOf(xsArg(1)) == xsIntegerType)) {
		char* address = xsToString(xsArg(0));
		command = xsToInteger(xsArg(1));
		machine = KprDebugFindMachine(self, address);
	}
	if ((c >= 4) && (xsTypeOf(xsArg(2)) == xsStringType) && (xsTypeOf(xsArg(3)) == xsIntegerType)) {
		path = FskStrDoCopy(xsToString(xsArg(2)));
		line = xsToInteger(xsArg(3));
	}
	if ((c >= 5) && (xsTypeOf(xsArg(4)) == xsStringType)) {
		value = FskStrDoCopy(xsToString(xsArg(4)));
	}
	if (machine && ((command == mxFramesView) || (command == mxFilesView) || (command == mxLogView) || (command == mxBreakpointsView))) {
		xsEnterSandbox();
		KprDebugMachineDispatchCommand(machine, command, path, value, line);
		xsLeaveSandbox();
	}
	else
		xsThrowIfFskErr(kFskErrInvalidParameter);
	FskMemPtrDispose(value);
	FskMemPtrDispose(path);
}
FskErr KprWebSocketEndpointConnect(KprWebSocketEndpoint self, char *url, char *origin)
{
	FskErr err = kFskErrNone;
	
	self->url = FskStrDoCopy(url);
	bailIfNULL(self->url);
	bailIfError(FskStrParseUrl(self->url, &self->parts));
	if (!KprWebSocketEndpointCheckURL(self)) {
		bailIfError(kFskErrInvalidParameter);
	}
	
	self->isSecure = (FskStrCompare(self->parts->scheme, "wss") == 0);
	
	if (origin) {
		self->origin = FskStrDoCopy(origin);
		bailIfNULL(self->origin);
	}
	
	self->state = kKprWebSocketStateConnecting;
	
	INVOKE_AFTER1(KprWebSocketEndpointStartConnect, self);
	
bail:
	return err;
}
示例#7
0
FskErr KprDBStatementNew(KprDBStatement* it, KprDB db, const char* text, char* bindFormat, char* rowFormat)
{
	FskErr err = kFskErrNone;
	KprDBStatement self = NULL;
	SInt32 count, size, i;
	bailIfError(KprMemPtrNewClear(sizeof(KprDBStatementRecord), it));
	self = *it;
	FskInstrumentedItemNew(self, NULL, &KprDBStatementInstrumentation);
	bailIfError(sqlite3_prepare_v2(db->data, text, FskStrLen(text), &self->data, NULL));
	count = sqlite3_bind_parameter_count(self->data);
	if (count && !bindFormat) BAIL(kFskErrInvalidParameter);
	if (!count && bindFormat) BAIL(kFskErrInvalidParameter);
	if (count) {
		if ((SInt32)FskStrLen(bindFormat) != count) BAIL(kFskErrInvalidParameter);
		self->bindFormat = FskStrDoCopy(bindFormat);
		bailIfNULL(self->bindFormat);
	}
	count = sqlite3_column_count(self->data);
	if (count && !rowFormat) BAIL(kFskErrInvalidParameter);
	if (!count && rowFormat) BAIL(kFskErrInvalidParameter);
	if (count) {
		if ((SInt32)FskStrLen(rowFormat) != count) BAIL(kFskErrInvalidParameter);
		self->rowFormat = FskStrDoCopy(rowFormat);
		bailIfNULL(self->rowFormat);
		bailIfError(KprMemPtrNewClear(count * sizeof(char*), &self->keys));
		for (size = 0, i = 0; rowFormat[i]; i++) {
			self->keys[i] = sqlite3_column_name(self->data, i);
			switch (rowFormat[i]) {
				case 'b':
					size += sizeof(void*) + sizeof(UInt32);
					break;
				case 'd':
					size += sizeof(double);
					break;
				case 'i':
					size += sizeof(SInt32);
					break;
				case 'I':
					size += sizeof(FskInt64);
					break;
				case 'r':
					size += sizeof(SInt32);
					break;
				case 't':
					size += sizeof(char*);
					break;
				default:
					BAIL(kFskErrInvalidParameter);
					break;
			}
		}
		bailIfError(KprMemPtrNewClear(size, &self->values));
	}
bail:
	if (err)
		KprDBStatementDispose(self);
	return err;
}
示例#8
0
FskErr FskFSVolumeGetInfo(UInt32 volumeID, char **pathOut, char **nameOut, UInt32 *volumeType, Boolean *isRemovable, FskInt64 *capacity, FskInt64 *freeSpace)
{
	FskInt64 calc, more;
	pMount theMount;
	FskErr	err = kFskErrOperationFailed;
	struct statfs volStat;

	if (!gMounts)
		scanVolumes();
	theMount = gMounts;

	FskAndroidFilesPrintfDebug("FSVolumeGetInfo for id %d\n", volumeID);
	if (capacity)
		*capacity = 0;
	if (freeSpace)
		*freeSpace = 0;

	while (theMount) {
		if (theMount->fsID == (SInt32)volumeID) {
			break;
		}
		theMount = theMount->next;
	}
	if (theMount) {
		if (pathOut)		*pathOut = FskStrDoCopy(theMount->mountPoint);
		if (nameOut)		*nameOut = FskStrDoCopy(theMount->name);
		if (volumeType)		*volumeType = theMount->type;
		if (isRemovable)	*isRemovable = theMount->removable;

		FskAndroidFilesPrintfDebug("getInfo returns - path: %s, name: %s, ", theMount->mountPoint, theMount->name);

		statfs(theMount->mountPoint, &volStat);
		if (capacity) {
			calc = volStat.f_bsize;
			more = volStat.f_blocks;
			calc = calc * more;
			*capacity = calc;

			FskAndroidFilesPrintfDebug("capacity %d,", calc);
		}
		if (freeSpace) {
			calc = volStat.f_bsize;
			more = volStat.f_bavail;
			calc = calc * more;
			*freeSpace = calc;

			FskAndroidFilesPrintfDebug("freeSpace %d", calc);
		}
		err = kFskErrNone;
	}
	else {
		FskAndroidFilesPrintfDebug("getInfo fails\n");
	}

	return err;
}
示例#9
0
FskErr mp3ReaderSniff(const unsigned char *data, UInt32 dataSize, FskHeaders *headers, const char *uri, char **mime)
{
	UInt32 i;

	// check data for ID3 tag (as per section 3.1 of id3 spec)
	if (dataSize >= 10) {
		if (('I' == data[0]) & ('D' == data[1]) & ('3' == data[2])) {
			if ((data[3] != 0xff) && (data[4] != 0xff)) {
				if (0 == (data[5] & 0x1f)) {
					if ((data[6] < 0x80) && (data[7] < 0x80) && (data[8] < 0x80) && (data[9] < 0x80)) {
						*mime = FskStrDoCopy("audio/mpeg");		// could also be AAC depending on codec tag or actual bitstream. but this is enough to get it routed to this media player.
						return kFskErrNone;
					}
				}
			}
		}
	}

	for (i = 0; (i < 2) && (dataSize >= 10); i++) {
		const unsigned char *d = data, *e = data + dataSize - 7;		// - 7 to account for the max header size of mp3 & aac/adts
		UInt32 ds = dataSize;
		Boolean	(*doHeaderParse)(unsigned char *scan, DIDLMusicItem mi);

		doHeaderParse = (0 == i) ? parseMP3Header : parseADTSHeader;

		while (d < e) {
			DIDLMusicItemRecord mi0, mi1, mi2;
			mi0.doExtendedParsing = 0;
			mi1.doExtendedParsing = 0;
			mi2.doExtendedParsing = 0;
			if (true == (doHeaderParse)((unsigned char *)d, &mi0)) {
				if ((d + mi0.frameLength + 7) < e) {
					if (true == (doHeaderParse)((unsigned char *)(d + mi0.frameLength), &mi1)) {
						if ((d + mi0.frameLength + mi1.frameLength + 7) < e) {
							if (true == (doHeaderParse)((unsigned char *)(d + mi0.frameLength + mi1.frameLength), &mi2)) {
								if ((mi0.frequency == mi1.frequency) && (mi0.channelCount == mi1.channelCount) &&
									(mi0.frequency == mi2.frequency) && (mi0.channelCount == mi2.channelCount)) {
									*mime = FskStrDoCopy((0 == i) ? "audio/mpeg" : "audio/vnd.dlna.adts");
									return kFskErrNone;
								}
							}
						}
					}
				}
			}

			d += 1;
			ds -= 1;
		}
	}

	return kFskErrUnknownElement;
}
示例#10
0
FskErr KplVolumeGetDeviceInfo(UInt32 volumeID, char **vendor, char **product, char **revision, char **vendorSpecific) {

	if (vendor)
		*vendor = FskStrDoCopy("vendor");
	if (product)
		*product = FskStrDoCopy("product");
	if (revision)
		*revision = FskStrDoCopy("1.0");
	if (vendorSpecific)
		*vendorSpecific = FskStrDoCopy("vendorSpecific");

	return kFskErrNone;
}
示例#11
0
FskErr KprMessageSetCredentials(KprMessage self, char* user, char* password)
{
	FskErr err = kFskErrNone;
	FskMemPtrDisposeAt(&self->user);
	FskMemPtrDisposeAt(&self->password);
	if (user && password) {
		self->user = FskStrDoCopy(user);
		bailIfNULL(self->user);
		self->password = FskStrDoCopy(password);
		bailIfNULL(self->password);
	}
bail:
	return err;
}
示例#12
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;
}
示例#13
0
void KPR_Message_cancelReferrer(xsMachine* the)
{
	char* url = FskStrDoCopy(xsToString(xsArg(0)));
	xsThrowIfNULL(url);
	KprMessageCancelReferrer(url);
	FskMemPtrDispose(url);
}
示例#14
0
FskErr KprWebSocketEndpointClose(KprWebSocketEndpoint self, UInt16 code, char *reason)
{
	FskErr err = kFskErrNone;
	FskDebugStr("CLOSE: (%d), %s\n", code, reason);
	self->closeCode = code;
	if (reason) {
		FskMemPtrDispose(self->closeReason);
		self->closeReason = FskStrDoCopy(reason);
	}
	
	switch (self->state) {
		case kKprWebSocketStateConnecting:
			bailIfError(KprWebSocketEndpointCancelConnection(self));
			break;
			
		case kKprWebSocketStateOpen:
			bailIfError(KprWebSocketEndpointStartClosingHandshake(self, code, reason));
			break;
			
		case kKprWebSocketStateClosing:
		case kKprWebSocketStateClosed:
		default:
			break;
	}
	
bail:
	return err;
}
示例#15
0
FskErr KprSocketConnect(KprSocket self, const char *host, int port)
{
	FskErr err = kFskErrNone;
	long flags = 0;

	if (self->mode != kKprSocketModeUndefined) return kFskErrBadState;

	self->host = FskStrDoCopy(host);
	bailIfNULL(self->host);

	self->port = port;
	self->mode = kKprSocketModeTCP;
	if (self->secure) {
		FskSSLOption ssl;

		flags |= kConnectFlagsSSLConnection;

		FskNetSSLOptionInitialize(self->host, self->port, flags, kFskNetSocketDefaultPriority, &ssl);

		ssl.protocolVersion = self->tlsProtocolVersion;
		ssl.applicationProtocols = self->applicationProtocols;
		bailIfError(FskNetConnectToSecureHost(&ssl, self->certs, KprSocketOnConnect, self));
	} else {
		bailIfError(FskNetConnectToHost((char *) self->host, self->port, false, KprSocketOnConnect, self, flags, NULL, "KprSocketTCP"));
	}

bail:
	if (err) {
		KprSocketCleanup(self);
	}
	return err;
}
示例#16
0
// ---------------------------------------------------------------------
void sNotifyInterfaceNotifiers(FskNetInterfaceRecord *iface, UInt32 status) {
	FskNetInterfaceNotifier callback = NULL, next;
	FskThread thread = FskThreadGetCurrent();

	callback = (FskNetInterfaceNotifier)FskListMutexGetNext(interfaceChangeCBList, NULL);
	while (callback) {
		next = (FskNetInterfaceNotifier)FskListMutexGetNext(interfaceChangeCBList, callback);
#if 0 && SUPPORT_INSTRUMENTATION
		if (FskInstrumentedItemHasListeners(callback)) {
			FskNetInterfaceRecord *iface = (FskNetInterfaceRecord *)FskNetInterfaceFindByName(ifcName);
			FskInterfaceInstrData data;
			data.notf = callback;
			data.ifc = iface;
			data.status = status;
			FskInstrumentedItemSendMessage(callback, kFskNetInstrMsgInterfaceNotify, &data);
		}
#endif /* SUPPORT_INSTRUMENTATION */
		if (callback->thread != thread) {
			FskNetInterfaceRecord *interFace;
			if (kFskErrNone == FskMemPtrNewFromData(sizeof(FskNetInterfaceRecord), iface, &interFace)) {
				interFace->next = NULL;
				interFace->name = FskStrDoCopy(iface->name);

				// POST notify
				FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, " - posting callback to thread %s for interface %s", callback->thread->name, iface->name);
				FskThreadPostCallback(callback->thread, doNetIfcCallback, (void*)callback->callback, (void*)interFace, (void*)status, (void*)callback->param);
			}
		}
		else {
			FskInstrumentedTypePrintfDebug(&gNetInterfaceNotifierTypeInstrumentation, "callback->thread %s - call", callback->thread->name);
			(callback->callback)(iface, status, callback->param);
		}
		callback = next;
	}
}
示例#17
0
static FskErr sFskNetInterfaceEnumerate(FskNetInterfaceRecord **interfaceList)
{
	FskErr err;
	KplNetInterfaceRecord *kplInterfaceList;

	*interfaceList = NULL;

	err = KplNetInterfaceEnumerate(&kplInterfaceList);
	BAIL_IF_ERR(err);

	while (kplInterfaceList) {
		FskNetInterfaceRecord *nir;
		KplNetInterfaceRecord *next = kplInterfaceList->next;

		err = FskMemPtrNew(sizeof(FskNetInterfaceRecord), (FskMemPtr*)&nir);
		BAIL_IF_ERR(err);

		nir->name = FskStrDoCopy(kplInterfaceList->name);
		nir->ip = kplInterfaceList->ip;
		FskMemMove(nir->MAC, kplInterfaceList->MAC, sizeof(nir->MAC));
		nir->status = kplInterfaceList->status;
		nir->netmask = kplInterfaceList->netmask;

		FskListAppend((FskList*)interfaceList, nir);

		FskMemPtrDispose(kplInterfaceList->name);
		FskMemPtrDispose(kplInterfaceList);

		kplInterfaceList = next;
	}

bail:
	return err;
}
示例#18
0
// ---------------------------------------------------------------------
FskErr FskNetInterfaceDescribe(int idx, FskNetInterfaceRecord **iface)
{
	int i = 0;
	FskErr ret = kFskErrNone;
	FskNetInterfaceRecord *nir;

	FskMutexAcquire(gNetworkInterfaceList->mutex);
	nir = (FskNetInterfaceRecord *)gNetworkInterfaceList->list;

	while (nir) {
		if (i == idx)
			break;
		nir = nir->next;
		i++;
	}

	if (nir) {
		FskNetInterfaceRecord *dup;
		if (kFskErrNone == FskMemPtrNewFromData(sizeof(FskNetInterfaceRecord), nir, &dup)) {
			dup->next = NULL;
			dup->name = FskStrDoCopy(nir->name);
		}
		*iface = dup;
	}
	else {
		*iface = NULL;
		ret = kFskErrNetworkInterfaceNotFound;
	}

	FskMutexRelease(gNetworkInterfaceList->mutex);
	return ret;
}
示例#19
0
FskErr mp3ReaderTrackGetMediaType(void *readerState, void *track, UInt32 propertyID, FskMediaPropertyValue property)
{
	property->type = kFskMediaPropertyTypeString;
	property->value.str = FskStrDoCopy("audio");

	return kFskErrNone;
}
示例#20
0
FskErr KprCoAPClientResolverNew(KprCoAPClientResolver *it, KprCoAPClient client, const char *host, UInt16 port, KprCoAPMessage message)
{
	FskErr err = kFskErrNone;
	KprCoAPClientResolver self = NULL;

	bailIfError(KprMemPtrNewClear(sizeof(KprCoAPClientResolverRecord), &self));

	self->host = FskStrDoCopy(host);
	bailIfNULL(self->host);

	bailIfError(KprCoAPMessageQueueAppend(&self->waiting, message));

	self->client = client;
	self->port = port;

	bailIfError(FskNetHostnameResolveQTAsync((char *) host, 0, KprCoAPClientResolverResolved, self, &self->resolver));

	bailIfError(self->err);

	self->constructed = true;
	*it = self;

bail:
	if (err) {
		KprCoAPClientResolverDispose(self);
	}
	return err;
}
示例#21
0
FskErr KprMQTTClientNew(KprMQTTClient* it, char *clientId, Boolean cleanSession, void *refcon)
{
	FskErr err = kFskErrNone;
	KprMQTTClient self = NULL;

	bailIfError(FskMemPtrNewClear(sizeof(KprMQTTClientRecord), &self));

	bailIfError(KprMQTTQueueNew(&self->queue, 15, KprMQTTClientSendMessageViaDelivery, self));

	FskTimeCallbackNew(&self->pingRequestCallaback);
	bailIfNULL(self->pingRequestCallaback);

	FskTimeCallbackNew(&self->pingResponseCallaback);
	bailIfNULL(self->pingResponseCallaback);

	self->clientIdentifier = FskStrDoCopy(clientId);
	bailIfNULL(self->clientIdentifier);

	self->cleanSession = cleanSession;
	self->refcon = refcon;
	self->state = kKprMQTTStateDisconnected;

	KprMQTTQueueStart(self->queue);

	*it = self;
bail:
	if (err) KprMQTTClientDispose(self);
	return err;
}
示例#22
0
static FskErr KprSocketNewFromFskSocket(FskSocket skt, KprSocketFlags flags, KprSocket *it)
{
	FskErr err = kFskErrNone;
	KprSocket self = NULL;
	UInt32 ipaddr;
	char ipaddrStr[22];

	bailIfError(FskMemPtrNewClear(sizeof(KprSocketRecord), &self));

	bailIfError(FskNetSocketGetLocalAddress(skt, &ipaddr, &self->port));
	FskNetIPandPortToString(ipaddr, 0, ipaddrStr);
	self->host = FskStrDoCopy(ipaddrStr);
	bailIfNULL(self->host);

	self->mode = kKprSocketModeTCP;
	self->proto = kKprSocketProtoTCP;
	self->secure = (Boolean)(flags & kKprSocketFlagsSecure);

	bailIfError(KprSocketOnConnect(skt, self));

	*it = self;

	FskListAppend(&gSockets, self);

bail:
	if (err) {
		KprSocketDispose(self);
	}

	return err;
}
示例#23
0
FskErr KplDirectoryIteratorGetNext(KplDirectoryIterator dirIt, char **name, UInt32 *itemType)
{
	struct dirent *ent;
	FskErr	err;
	KplFileInfo finfo;

	if (!dirIt || !dirIt->theDir)
		return kFskErrInvalidParameter;

	ent = readdir(dirIt->theDir);
	if (!ent) {
		return kFskErrIteratorComplete;
	}

	err = KplFileGetPathInfo((char *)dirIt->root, ent->d_name, &finfo);
	if (err != kFskErrNone)
		return err;

	if (itemType)
		*itemType = finfo.filetype;

    if ('.' == ent->d_name[0]) {
        if ((0 == (dirIt->flags & 1)) ||
            (0 == FskStrCompare(ent->d_name, ".")) ||
            (0 == FskStrCompare(ent->d_name, "..")))
            return KplDirectoryIteratorGetNext(dirIt, name, itemType);        // skip hidden files
    }

    if (name)
        *name = FskStrDoCopy(ent->d_name);

	return kFskErrNone;
}
示例#24
0
static FskErr KprWebSocketServerRequestNew(KprWebSocketServerRequest *it, KprWebSocketServer server, FskSocket skt, const char *interfaceName, int ip) {
	FskErr err = kFskErrNone;
	KprWebSocketServerRequest request = NULL;

	bailIfError(FskMemPtrNewClear(sizeof(KprWebSocketServerRequestRecord), &request));

	request->server = server;
	request->skt = skt;
	skt = NULL;

	request->interfaceName = FskStrDoCopy(interfaceName);
	bailIfNULL(request->interfaceName);
	request->ip = ip;

	FskNetSocketGetRemoteAddress(request->skt, (UInt32 *)&request->requesterAddress, &request->requesterPort);
	FskNetSocketMakeNonblocking(request->skt);
	bailIfError(FskHeaderStructNew(&request->requestHeaders));
	bailIfError(FskHeaderStructNew(&request->responseHeaders));

	request->out.size = 512;
	bailIfError(FskMemPtrNew(request->out.size, &request->out.buffer));

	FskThreadAddDataHandler(&request->dataHandler, (FskThreadDataSource)request->skt, (FskThreadDataReadyCallback)KprWebSocketServerRequestDoRead, true, false, request);
	//	request->state = kHTTPNewSession;
	
	*it = request;

bail:
	if (err) {
		KprWebSocketServerRequestDispose(request);
		FskNetSocketClose(skt);
	}

	return err;
}
示例#25
0
static FskErr
newSSLVM(FskECMAScript *vmp)
{
	FskECMAScript vm;
	FskErr err;

#ifdef KPR_CONFIG
	if ((err = FskMemPtrNewClear(sizeof(FskECMAScriptRecord), &vm)) != kFskErrNone)
		return err;
	if ((vm->the = xsAliasMachine(&anAllocation, gShell->root, "SSL", vm)) == NULL) {
		FskMemPtrDispose(vm);
		return kFskErrMemFull;
	}
#else
	if (gSSLVM == NULL)
		return kFskErrUnimplemented;

	if ((err = FskMemPtrNewFromData(sizeof(FskECMAScriptRecord), gSSLVM, &vm)) != kFskErrNone)
		return err;
	vm->the = NULL;
	vm->context = NULL;
	vm->refcon = NULL;
	vm->libraries = NULL;
	vm->name = FskStrDoCopy("SSL");
	vm->thread = FskThreadGetCurrent();
	vm->id = (UInt32)vm;

	if ((vm->the = xsAliasMachine(&anAllocation, gSSLVM->the, vm->name, vm)) == NULL) {
		FskMemPtrDispose(vm);
		return kFskErrMemFull;
	}
#endif
	*vmp = vm;
	return err;
}
示例#26
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;

	err = FskTextEngineNew(&fte, NULL);
	if (err) goto bail;
	fromDirectory = FskEnvironmentDoApply(FskStrDoCopy(fontsPath));
	if (!fromDirectory) { err = kFskErrMemFull; goto bail; }
	
	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; }
			FskTextAddFontFile(fte, fromPath);
			FskMemPtrDisposeAt(&fromPath);
		}
		FskMemPtrDisposeAt(&name);
	}

bail:
	FskTextEngineDispose(fte);
	FskMemPtrDispose(fromDirectory);
	FskDirectoryIteratorDispose(iterator);

	return err;
}
示例#27
0
static FskErr KprMQTTClientCreatePublishMessage(KprMQTTClient self, char *topic, void *payload, UInt32 payloadLength, UInt8 qos, Boolean retain, KprMQTTMessage *it)
{
	FskErr err;
	KprMQTTMessage message = NULL;

	bailIfError(KprMQTTMessageNewWithType(&message, kKprMQTTMessageTypePUBLISH));

	message->qualityOfService = qos;
	message->isRetained = retain;

	if (qos > 0) {
		message->messageId = KprMQTTQueueNextId(self->queue);
	}

	message->t.publish.topic = FskStrDoCopy(topic);
	bailIfNULL(message->t.publish.topic);

	bailIfError(KprMemoryBufferNewFromData(payloadLength, payload, &message->t.publish.payload));

	*it = message;
	message = NULL;

bail:
	KprMQTTMessageDispose(message);
	return err;
}
示例#28
0
void KprZeroconfServiceDiscover(KprService self, char* authority, char* id, Boolean useEnvironment)
{
	FskErr err = kFskErrNone;
	char* type = NULL;
	KprZeroconfBrowser browser = NULL;
	if (useEnvironment ? KprEnvironmentGetUInt32("useZeroconf", 0) : true) {
		bailIfError(KprZeroconfServiceNewType(id, &type));
		browser = KprZeroconfBrowserFind(gKprZeroconfBrowsers, type);
		if (!browser) {
			bailIfError(KprZeroconfBrowserNew(&browser, type));
			browser->serviceUpCallback = KprZeroconfServiceServiceUpCallback;
			browser->serviceDownCallback = KprZeroconfServiceServiceDownCallback;
			browser->authority = FskStrDoCopy(authority);
			bailIfError(KprZeroconfBrowserStart(browser));
			FskListAppend(&gKprZeroconfBrowsers, browser);
		}
	}
bail:
	if (err)
		KprZeroconfBrowserDispose(browser);
	FskMemPtrDispose(type);
	FskMemPtrDispose(authority);
	FskMemPtrDispose(id);
	return;
}
示例#29
0
FskErr KprMQTTClientConnect(KprMQTTClient self, char *host, UInt16 port, KprMQTTClientConnectOptions *options)
{
	FskErr err = kFskErrNone;

	if (self->state != kKprMQTTStateDisconnected) {
		return kFskErrBadState;
	}

	FskMemPtrDisposeAt(&self->host);
	self->host = FskStrDoCopy(host);
	bailIfNULL(self->host);
	self->port = port;
	self->cancelConnection = false;

	KprMQTTMessageDispose(self->connectMessage);
	self->connectMessage = NULL;
	bailIfError(KprMQTTClientCreateConnectMessage(self, options, &self->connectMessage));

	self->keepAlive = options->keepAlive;

	bailIfError(KprMQTTClientReconnect(self));

bail:
	return err;
}
示例#30
0
FskErr latmPacketParserGetInfo(RTPPacketParser parser, UInt32 selector, void *info, UInt32 *infoSize)
{
	LATMPacketParser latmPacketParser = (LATMPacketParser)parser->handlerRefCon;
	FskErr err = 0;

	switch(selector) {
		case kRTPPacketParserSelectorESDS:
			*(UInt8**)info = latmPacketParser->esds;
			if (infoSize)
				*infoSize = latmPacketParser->esdsSize;
			break;

		case kRTPPacketParserSelectorRTPTimeScale:
		case kRTPPacketParserSelectorAudioSampleRate:
			*(UInt32*)info = latmPacketParser->sampleRate;
			break;
		case kRTPPacketParserSelectorAudioChannels:
			*(UInt32*)info = latmPacketParser->nChannels;
			break;
		case kRTPPacketParserSelectorAudioBitsPerSample:
			*(UInt32*)info = latmPacketParser->bitsPerSample;
			break;
		case kRTPPacketParserSelectorMediaFormat:
			*(UInt32*)info = latmPacketParser->mediaFormat;
			break;
		case kRTPPacketParserSelectorEncodingName:
			*(UInt8**)info = (UInt8*)FskStrDoCopy("MP4A-LATM");
			break;

		default:
			err = kFskErrInvalidParameter;
			break;
	}
	return err;
}