コード例 #1
0
ファイル: hbi18n1.c プロジェクト: JamesLinus/core
static PHB_ITEM hb_i18n_serialize( PHB_I18N_TRANS pI18N )
{
   if( pI18N )
   {
      HB_SIZE nSize;
      HB_U32 ulCRC;
      char * pBuffer = hb_itemSerialize( pI18N->table, 0, &nSize );
      char * pI18Nbuffer;
      PHB_ITEM pKey, pValue;

      ulCRC = hb_crc32( 0, pBuffer, nSize );
      pI18Nbuffer = ( char * ) memset( hb_xgrab( nSize + HB_I18N_HEADER_SIZE + 1 ),
                                       0, HB_I18N_HEADER_SIZE );
      memcpy( pI18Nbuffer + HB_I18N_HEADER_SIZE, pBuffer, nSize );
      hb_xfree( pBuffer );

      memcpy( pI18Nbuffer, s_signature, HB_I18N_SIG_SIZE );
      HB_PUT_LE_UINT32( &pI18Nbuffer[ HB_I18N_SIZE_OFFSET ], nSize );
      HB_PUT_LE_UINT32( &pI18Nbuffer[ HB_I18N_CRC_OFFSET ], ulCRC );

      pKey = hb_itemPutCConst( NULL, "DESCRIPTION" );
      pValue = hb_hashGetItemPtr( pI18N->table, pKey, 0 );
      if( pValue )
         hb_strncpy( &pI18Nbuffer[ HB_I18N_TXT_OFFSET ],
                     hb_itemGetCPtr( pValue ), HB_I18N_TXT_SIZE );

      return hb_itemPutCLPtr( pKey, pI18Nbuffer, nSize + HB_I18N_HEADER_SIZE );
   }

   return NULL;
}
コード例 #2
0
ファイル: netiosrv.c プロジェクト: abebuch/core
static HB_BOOL s_netio_login_accept( PHB_CONSRV conn )
{
   if( conn && conn->sd != HB_NO_SOCKET && ! conn->stop && ! conn->login )
   {
      HB_BYTE msgbuf[ NETIO_MSGLEN ];

      if( s_srvRecvAll( conn, msgbuf, NETIO_MSGLEN ) == NETIO_MSGLEN &&
          HB_GET_LE_INT32( msgbuf ) == NETIO_LOGIN )
      {
         long len = HB_GET_LE_INT16( &msgbuf[ 4 ] );

         if( len < ( long ) sizeof( msgbuf ) &&
             len == ( long ) strlen( NETIO_LOGINSTRID ) &&
             s_srvRecvAll( conn, msgbuf, len ) == len )
         {
            if( memcmp( NETIO_LOGINSTRID, msgbuf, len ) == 0 )
            {
               HB_PUT_LE_UINT32( &msgbuf[ 0 ], NETIO_LOGIN );
               HB_PUT_LE_UINT32( &msgbuf[ 4 ], NETIO_CONNECTED );
               memset( msgbuf + 8, '\0', NETIO_MSGLEN - 8 );
               if( s_srvSendAll( conn, msgbuf, NETIO_MSGLEN ) == NETIO_MSGLEN )
                  conn->login = HB_TRUE;
            }
         }
      }
      if( ! conn->login )
         s_consrv_disconnect( conn );

      return conn->login;
   }

   return HB_FALSE;
}
コード例 #3
0
ファイル: nortl.c プロジェクト: AmericoBalboa/core
void * hb_xrealloc( void * pMem, HB_SIZE nSize )       /* reallocates memory */
{
#ifdef HB_FM_STATISTICS
   PHB_MEMINFO pMemBlock;
   HB_SIZE nMemSize;
   void * pResult;

   if( nSize == 0 )
   {
      if( pMem )
         hb_xfree( pMem );
      return NULL;
   }
   else if( ! pMem )
      return hb_xgrab( nSize );

   pMemBlock = ( PHB_MEMINFO ) ( ( HB_BYTE * ) pMem - HB_MEMINFO_SIZE );
   nMemSize = pMemBlock->nSize;

   if( pMemBlock->Signature != HB_MEMINFO_SIGNATURE )
      hb_errInternal( HB_EI_XREALLOCINV, "hb_xrealloc called with an invalid pointer", NULL, NULL );

   if( HB_GET_LE_UINT32( ( ( HB_BYTE * ) pMem ) + nMemSize ) != HB_MEMINFO_SIGNATURE )
      hb_errInternal( HB_EI_XMEMOVERFLOW, "Memory buffer overflow", NULL, NULL );

   HB_PUT_LE_UINT32( ( ( HB_BYTE * ) pMem ) + nMemSize, 0 );

   pResult = realloc( pMemBlock, nSize + HB_MEMINFO_SIZE + sizeof( HB_U32 ) );
   if( pResult )
   {
      if( s_pMemBlocks == pMemBlock )
         s_pMemBlocks = ( PHB_MEMINFO ) pResult;
      else
         ( ( PHB_MEMINFO ) pResult )->pPrevBlock->pNextBlock = ( PHB_MEMINFO ) pResult;

      if( ( ( PHB_MEMINFO ) pResult )->pNextBlock )
         ( ( PHB_MEMINFO ) pResult )->pNextBlock->pPrevBlock = ( PHB_MEMINFO ) pResult;
      s_nMemoryConsumed += ( nSize - nMemSize );

      if( s_nMemoryMaxConsumed < s_nMemoryConsumed )
         s_nMemoryMaxConsumed = s_nMemoryConsumed;

      ( ( PHB_MEMINFO ) pResult )->nSize = nSize;  /* size of the memory block */
      HB_PUT_LE_UINT32( ( ( HB_BYTE * ) pResult ) + nSize + HB_MEMINFO_SIZE, HB_MEMINFO_SIGNATURE );
      pResult = ( HB_BYTE * ) pResult + HB_MEMINFO_SIZE;
   }
#else
   void * pResult = realloc( pMem, nSize );
#endif

   if( ! pResult && nSize )
      hb_errInternal( HB_EI_XREALLOC, "hb_xrealloc can't reallocate memory", NULL, NULL );

   return pResult;
}
コード例 #4
0
ファイル: nortl.c プロジェクト: AmericoBalboa/core
void hb_xfree( void * pMem )            /* frees fixed memory */
{
   if( pMem )
   {
#ifdef HB_FM_STATISTICS
      PHB_MEMINFO pMemBlock = ( PHB_MEMINFO ) ( ( HB_BYTE * ) pMem - HB_MEMINFO_SIZE );

      if( pMemBlock->Signature != HB_MEMINFO_SIGNATURE )
         hb_errInternal( HB_EI_XFREEINV, "hb_xfree called with an invalid pointer", NULL, NULL );

      if( HB_GET_LE_UINT32( ( ( HB_BYTE * ) pMem ) + pMemBlock->nSize ) != HB_MEMINFO_SIGNATURE )
         hb_errInternal( HB_EI_XMEMOVERFLOW, "Memory buffer overflow", NULL, NULL );

      s_nMemoryConsumed -= pMemBlock->nSize;
      s_nMemoryBlocks--;
      if( s_pMemBlocks == pMemBlock )
         s_pMemBlocks = pMemBlock->pNextBlock;
      else
         pMemBlock->pPrevBlock->pNextBlock = pMemBlock->pNextBlock;

      if( pMemBlock->pNextBlock )
         pMemBlock->pNextBlock->pPrevBlock = pMemBlock->pPrevBlock;

      pMemBlock->Signature = 0;
      HB_PUT_LE_UINT32( ( ( HB_BYTE * ) pMem ) + pMemBlock->nSize, 0 );
      pMem = ( HB_BYTE * ) pMem - HB_MEMINFO_SIZE;
#endif
      free( pMem );
   }
   else
      hb_errInternal( HB_EI_XFREENULL, "hb_xfree called with a NULL pointer", NULL, NULL );
}
コード例 #5
0
ファイル: c_scrypt.c プロジェクト: jlsiug/harbour-core
/**
 * salsa20_8(B):
 * Apply the salsa20/8 core to the provided block.
 */
static void
salsa20_8(uint8_t B[64])
{
	uint32_t B32[16];
	uint32_t x[16];
	size_t i;

	/* Convert little-endian values in. */
	for (i = 0; i < 16; i++)
		B32[i] = HB_GET_LE_UINT32(&B[i * 4]);

	/* Compute x = doubleround^4(B32). */
	for (i = 0; i < 16; i++)
		x[i] = B32[i];
	for (i = 0; i < 8; i += 2) {
#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
		/* Operate on columns. */
		x[ 4] ^= R(x[ 0]+x[12], 7);  x[ 8] ^= R(x[ 4]+x[ 0], 9);
		x[12] ^= R(x[ 8]+x[ 4],13);  x[ 0] ^= R(x[12]+x[ 8],18);

		x[ 9] ^= R(x[ 5]+x[ 1], 7);  x[13] ^= R(x[ 9]+x[ 5], 9);
		x[ 1] ^= R(x[13]+x[ 9],13);  x[ 5] ^= R(x[ 1]+x[13],18);

		x[14] ^= R(x[10]+x[ 6], 7);  x[ 2] ^= R(x[14]+x[10], 9);
		x[ 6] ^= R(x[ 2]+x[14],13);  x[10] ^= R(x[ 6]+x[ 2],18);

		x[ 3] ^= R(x[15]+x[11], 7);  x[ 7] ^= R(x[ 3]+x[15], 9);
		x[11] ^= R(x[ 7]+x[ 3],13);  x[15] ^= R(x[11]+x[ 7],18);

		/* Operate on rows. */
		x[ 1] ^= R(x[ 0]+x[ 3], 7);  x[ 2] ^= R(x[ 1]+x[ 0], 9);
		x[ 3] ^= R(x[ 2]+x[ 1],13);  x[ 0] ^= R(x[ 3]+x[ 2],18);

		x[ 6] ^= R(x[ 5]+x[ 4], 7);  x[ 7] ^= R(x[ 6]+x[ 5], 9);
		x[ 4] ^= R(x[ 7]+x[ 6],13);  x[ 5] ^= R(x[ 4]+x[ 7],18);

		x[11] ^= R(x[10]+x[ 9], 7);  x[ 8] ^= R(x[11]+x[10], 9);
		x[ 9] ^= R(x[ 8]+x[11],13);  x[10] ^= R(x[ 9]+x[ 8],18);

		x[12] ^= R(x[15]+x[14], 7);  x[13] ^= R(x[12]+x[15], 9);
		x[14] ^= R(x[13]+x[12],13);  x[15] ^= R(x[14]+x[13],18);
#undef R
	}

	/* Compute B32 = B32 + x. */
	for (i = 0; i < 16; i++)
		B32[i] += x[i];

	/* Convert little-endian values out. */
	for (i = 0; i < 16; i++)
		HB_PUT_LE_UINT32(&B[4 * i], B32[i]);
}
コード例 #6
0
ファイル: hblpp.c プロジェクト: JamesLinus/core
HB_BOOL hb_lppSend( PHB_LPP pSocket, const void * data, HB_SIZE len, HB_MAXINT timeout )
{
   HB_MAXINT  nTime = 0;
   long       lSend;

   if( ! pSocket->pSendBuffer )
   {
      pSocket->pSendBuffer = ( char * ) hb_xgrab( len + 4 );
      HB_PUT_LE_UINT32( pSocket->pSendBuffer, len );
      hb_xmemcpy( pSocket->pSendBuffer + 4, data, len );
      pSocket->nSendLen = len + 4;
      pSocket->nSendPos = 0;
   }

   if( timeout > 0 )
      nTime = ( HB_MAXINT ) hb_dateMilliSeconds() + timeout;

   for( ;; )
   {
      if( pSocket->nSendLen - pSocket->nSendPos < ( HB_SIZE ) LONG_MAX )
         lSend = ( long ) ( pSocket->nSendLen - pSocket->nSendPos );
      else
         lSend = LONG_MAX;

      lSend = hb_socketSend( pSocket->sd, pSocket->pSendBuffer + pSocket->nSendPos, lSend, 0, timeout );
      if( lSend == -1 )
      {
         pSocket->iError = hb_socketGetError();
         return HB_FALSE;
      }
      pSocket->nSendPos += lSend;
      if( pSocket->nSendPos == pSocket->nSendLen )
      {
         hb_xfree( pSocket->pSendBuffer );
         pSocket->pSendBuffer = NULL;
         pSocket->iError = 0;
         return HB_TRUE;
      }
      if( timeout == 0 ||
          ( timeout > 0 && ( timeout = nTime - ( HB_MAXINT ) hb_dateMilliSeconds() ) <= 0 ) )
      {
         pSocket->iError = HB_SOCKET_ERR_TIMEOUT;
         return HB_FALSE;
      }
   }
}
コード例 #7
0
ファイル: nortl.c プロジェクト: AmericoBalboa/core
void * hb_xgrab( HB_SIZE nSize )        /* allocates fixed memory, exits on failure */
{
   void * pMem;

   if( nSize == 0 )
      hb_errInternal( HB_EI_XGRABNULLSIZE, "hb_xgrab requested to allocate zero bytes", NULL, NULL );

#ifdef HB_FM_STATISTICS
   pMem = malloc( nSize + HB_MEMINFO_SIZE + sizeof( HB_U32 ) );
   if( pMem )
   {
      if( s_pMemBlocks )
         s_pMemBlocks->pPrevBlock = ( PHB_MEMINFO ) pMem;
      ( ( PHB_MEMINFO ) pMem )->pNextBlock = s_pMemBlocks;
      ( ( PHB_MEMINFO ) pMem )->pPrevBlock = NULL;
      s_pMemBlocks = ( PHB_MEMINFO ) pMem;
      ( ( PHB_MEMINFO ) pMem )->nSize = nSize;
      ( ( PHB_MEMINFO ) pMem )->Signature = HB_MEMINFO_SIGNATURE;
      HB_PUT_LE_UINT32( ( ( HB_BYTE * ) pMem ) + HB_MEMINFO_SIZE + nSize, HB_MEMINFO_SIGNATURE );

      s_nMemoryConsumed += nSize;
      if( s_nMemoryMaxConsumed < s_nMemoryConsumed )
         s_nMemoryMaxConsumed = s_nMemoryConsumed;
      s_nMemoryBlocks++;
      if( s_nMemoryMaxBlocks < s_nMemoryBlocks )
         s_nMemoryMaxBlocks = s_nMemoryBlocks;
      pMem = ( HB_BYTE * ) pMem + HB_MEMINFO_SIZE;
   }
   else
#else
   pMem = malloc( nSize );
   if( ! pMem )
#endif
      hb_errInternal( HB_EI_XGRABALLOC, "hb_xgrab can't allocate memory", NULL, NULL );

   return pMem;
}
コード例 #8
0
ファイル: genhrb.c プロジェクト: AmericoBalboa/core
void hb_compGenBufPortObj( HB_COMP_DECL, HB_BYTE ** pBufPtr, HB_SIZE * pnSize )
{
   PHB_HFUNC pFunc;
   PHB_HSYMBOL pSym;
   HB_ULONG ulSymbols, ulFunctions;
   HB_SIZE nLen;
   HB_BYTE * ptr;

   *pnSize = hb_compHrbSize( HB_COMP_PARAM, &ulSymbols, &ulFunctions );
   /* additional 0 byte is for passing buffer directly as string item */
   ptr = *pBufPtr = ( HB_BYTE * ) hb_xgrab( *pnSize + 1 );

   /* signature */
   *ptr++ = 0xC0;
   *ptr++ = 'H';
   *ptr++ = 'R';
   *ptr++ = 'B';
   HB_PUT_LE_UINT16( ptr, 2 );   /* version number */
   ptr += 2;

   HB_PUT_LE_UINT32( ptr, ulSymbols ); /* number of symbols */
   ptr += 4;
   /* generate the symbol table */
   pSym = HB_COMP_PARAM->symbols.pFirst;
   while( pSym )
   {
      nLen = strlen( pSym->szName ) + 1;
      memcpy( ptr, pSym->szName, nLen );
      ptr += nLen;
      /* TOFIX: this conversion strips upper byte from symbol scope
       *        Now we added workaround for it by using some strict
       *        bit order and restoring some others at runtime when
       *        .hrb file is loaded but we should create new format
       *        for .hrb files in which this field will have at least
       *        16bit [druzus]
       */
      *ptr++ = ( HB_BYTE ) pSym->cScope;
      /* symbol type */
      if( pSym->cScope & HB_FS_LOCAL )
         *ptr++ = SYM_FUNC;      /* function defined in this module */
      else if( pSym->cScope & HB_FS_DEFERRED )
         *ptr++ = SYM_DEFERRED;  /* lately bound function */
      else if( pSym->iFunc )
         *ptr++ = SYM_EXTERN;    /* external function */
      else
         *ptr++ = SYM_NOLINK;    /* other symbol */
      pSym = pSym->pNext;
   }

   HB_PUT_LE_UINT32( ptr, ulFunctions );  /* number of functions */
   ptr += 4;
   /* generate functions data */
   pFunc = HB_COMP_PARAM->functions.pFirst;
   while( pFunc )
   {
      if( ( pFunc->funFlags & HB_FUNF_FILE_DECL ) == 0 )
      {
         nLen = strlen( pFunc->szName ) + 1;
         memcpy( ptr, pFunc->szName, nLen );
         ptr += nLen;
         HB_PUT_LE_UINT32( ptr, pFunc->nPCodePos );      /* function size */
         ptr += 4;
         memcpy( ptr, pFunc->pCode, pFunc->nPCodePos );  /* function body */
         ptr += pFunc->nPCodePos;
      }
      pFunc = pFunc->pNext;
   }
}