Beispiel #1
0
/**
 * Create new LocFile structure and read file data from BufString
 *
 * @param path pointer to char table with path
 * @param bs pointer to BufString with file data
 * @return pointer to new LocFile when success, otherwise NULL
 */
LocFile* LocFileNewFromBuf( char* path, BufString *bs )
{
	if( path == NULL )
	{
		FERROR("File path is null\n");
		return NULL;
	}
	if( bs == NULL )
	{
		FERROR("BufString is NULL\n" );
		return NULL;
	}
	
	LocFile* fo = (LocFile*) FCalloc( 1, sizeof(LocFile) );
	if( fo != NULL )
	{
		fo->lf_PathLength = strlen( path );
		fo->lf_Path = StringDuplicateN( path, fo->lf_PathLength );
		//fo->lf_Filename = StringDuplicateN( path, fo->lf_PathLength );//StringDuplicate( GetFileNamePtr( path, len ) );
		MURMURHASH3( fo->lf_Path, fo->lf_PathLength, fo->hash );
		
		DEBUG("PATH: %s \n", fo->lf_Path );

		fo->lf_FileSize = bs->bs_Size;
		
		if( ( fo->lf_Buffer = FMalloc( fo->lf_FileSize ) ) != NULL )
		{
			memcpy( fo->lf_Buffer, bs->bs_Buffer, fo->lf_FileSize );
		}
	}
	else
	{
		FERROR("Cannot allocate memory for LocFile\n");
	}
	
	return fo;
}
FStringAllocator::FStringAllocator( UI32 iPoolSize ) : iPoolSize( iPoolSize ), iCurAddr( 0 ), lpStringPool( NULL )
{
	lpStringPool = (CHAR_ *)FMalloc( iPoolSize );
}
Beispiel #3
0
int AppSessionSendMessage( AppSession *as, UserSession *sender, char *msg, int length, char *dstusers )
{
	int msgsndsize = 0;
	if( as == NULL || sender == NULL )
	{
		DEBUG("[AppSession] AppSession or sender parameter are empty\n");
		return -1;
	}

	time_t ntime = time( NULL );
	DEBUG("[AppSession] OLD TIME %lld NEW TIME %lld\n", (long long)as->as_Timer, (long long)ntime );
	if( ( ntime - as->as_Timer ) > TIMEOUT_APP_SESSION )
	{
		as->as_Obsolete = TRUE;
	}
	as->as_Timer = ntime;
	
	if( dstusers == NULL )
	{
		SASUList *ali = as->as_UserSessionList;
		while( ali != NULL )
		{
			if( ali->usersession == sender )
			{
				// sender should receive response
				DEBUG("[AppSession] SENDER AUTHID %s\n", ali->authid );
			}
			else
			{
				char *newmsg = NULL;
				
				if( ( newmsg = FCalloc( length+256, sizeof(char) ) ) != NULL )
				{
					User *usend = sender->us_User;
					
					DEBUG("[AppSession] Sendmessage AUTHID %s\n", ali->authid );
					
					int newmsgsize = sprintf( newmsg, WS_MESSAGE_TEMPLATE_USER, ali->authid, as->as_SASID, usend->u_Name, msg );
					
					msgsndsize += WebSocketSendMessageInt( ali->usersession, newmsg, newmsgsize );
					DEBUG("[AppSession] FROM %s  TO %s  MESSAGE SIZE %d\n", usend->u_Name, ali->usersession->us_User->u_Name, msgsndsize );
					FFree( newmsg );
				}
				else
				{
					FERROR("Cannot allocate memory for message\n");
				}
			}
			ali = (SASUList *) ali->node.mln_Succ;
		}
	}
	else  // dstusers != NULL
	{
		int dstuserssize = strlen( dstusers );
		char *quotaName = FMalloc( dstuserssize );
		
		SASUList *ali = as->as_UserSessionList;
		while( ali != NULL )
		{
			if( ali->usersession == sender )
			{
				// sender should receive response
				DEBUG("[AppSession] SENDER AUTHID %s\n", ali->authid );
			}
			else
			{
				UserSession *locusrsess = (UserSession *)ali->usersession;
				User *usr = locusrsess->us_User;
				
				if( usr != NULL )
				{
					int size = strlen( usr->u_Name );
					quotaName[ 0 ] = quotaName[ size+1 ] = '\"';
					quotaName[ size+2 ] = 0;
					memcpy( &quotaName[ 1 ], usr->u_Name, size );
					
					char *newmsg = NULL;
					
					if( strstr( dstusers, quotaName ) != NULL &&  ( newmsg = FCalloc( length+256, sizeof(char) ) ) != NULL )
					{
						User *usend = sender->us_User;
						
						DEBUG("[AppSession] Sendmessage AUTHID %s\n", ali->authid );
						
						int newmsgsize = sprintf( newmsg, WS_MESSAGE_TEMPLATE_USER, ali->authid, as->as_SASID, usend->u_Name, msg );
						
						msgsndsize += WebSocketSendMessageInt( ali->usersession, newmsg, newmsgsize );
						DEBUG("[AppSession] FROM %s  TO %s  MESSAGE SIZE %d\n", usend->u_Name, ali->usersession->us_User->u_Name, msgsndsize );
						FFree( newmsg );
					}
					else
					{
						//FERROR("Cannot allocate memory for message\n");
					}
				}
			}
			ali = (SASUList *) ali->node.mln_Succ;
		}
		
		FFree( quotaName );
	}
	
	return msgsndsize;
}
Beispiel #4
0
void FTGAResource::Decode( void * lpDataSrc, UI32 iDataLen )
{
	TGAHeader * lpHeader = (TGAHeader *) lpDataSrc;

	iWidth = lpHeader->iWidth;
	iHeight = lpHeader->iHeight;
	lpData = FMalloc( iWidth*iHeight*sizeof( RGBA ) );
	RGBA * lpDst = (RGBA *)lpData;
	UI8 * lpSrc = (UI8 *)lpDataSrc + sizeof( TGAHeader ) + lpHeader->cIdLength;

	if( lpHeader->cDataType == UNPACKED_DATA )
	{
		for( I32 i = 0;i < iWidth*iHeight;i++, lpDst++ )
		{
			lpDst->b = *lpSrc++;
			lpDst->g = *lpSrc++;
			lpDst->r = *lpSrc++;
			if( lpHeader->cBpp == 32 )
				lpDst->a = *lpSrc++;
			else
				lpDst->a = 255;
		}
	}
	else if( lpHeader->cDataType == PACKED_DATA )
	{
		for( I32 i = 0;i < iWidth*iHeight;)
		{
			UI8 cPackedBlock = *lpSrc & PACKED_BLOCK_MASK;
			UI8 cBlockLength = *lpSrc++ & BLOCK_LENGTH_MASK;
			if( cPackedBlock )
			{
				UI8 b = *lpSrc++,
					g = *lpSrc++,
					r = *lpSrc++,
					a = 255;

				if( lpHeader->cBpp == 32 )
					a = *lpSrc++;

				for( I32 j = 0;j < cBlockLength;j++, lpDst++, i++ )
				{
					lpDst->r = r;
					lpDst->g = g;
					lpDst->b = b;
					lpDst->a = a;
				}
			}
			else
			{
				lpDst->r = *lpSrc++;
				lpDst->g = *lpSrc++;
				lpDst->b = *lpSrc++;
				if( lpHeader->cBpp == 32 )
					lpDst->a = *lpSrc++;
				else
					lpDst->a = 255;
				lpDst++;
				i++;
			}
		}
	}

	iFormat = IMAGE_RGBA;
}