Ejemplo n.º 1
0
static void s_sslSocketNew( HB_BOOL fServer )
{
   HB_SOCKET sd = hb_socketParam( 1 );

   if( sd != HB_NO_SOCKET )
   {
      PHB_SOCKEX pSock = NULL;
      SSL * ssl = hb_SSL_par( 2 );

      if( ssl )
         pSock = hb_sockexNewSSL( sd, ssl, fServer, hb_parnintdef( 3, - 1 ), hb_param( 2, HB_IT_ANY ) );
      else if( HB_ISHASH( 2 ) )
         pSock = hb_sockexNew( sd, s_sockFilter.pszName, hb_param( 2, HB_IT_ANY ) );
      else
         hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );

      if( pSock )
      {
         PHB_ITEM pSockItm = hb_param( 1, HB_IT_POINTER );

         if( HB_ISBYREF( 1 ) && hb_sockexItemReplace( pSockItm, pSock ) )
            hb_itemReturn( pSockItm );
         else
         {
            hb_socketItemClear( pSockItm );
            hb_sockexItemPut( hb_param( -1, HB_IT_ANY ), pSock );
         }
      }
   }
}
Ejemplo n.º 2
0
static void hb_inetConnectInternal( HB_BOOL fResolve )
{
   const char * szHost = hb_parc( 1 );
   char * szAddr = NULL;
   PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 3 );
   PHB_ITEM pSocket = NULL;
   int iPort = hb_parni( 2 );

   if( szHost == NULL || iPort == 0 || ( socket == NULL && ! HB_ISNIL( 3 ) ) )
      hb_inetErrRT();
   else
   {
      if( ! socket )
         HB_SOCKET_INIT( socket, pSocket );
      else if( socket->sd != HB_NO_SOCKET )
         hb_inetCloseSocket( socket, HB_FALSE );

      if( fResolve )
         szHost = szAddr = hb_socketResolveAddr( szHost, HB_SOCKET_AF_INET );

      if( fResolve && ! szAddr )
      {
         hb_inetGetError( socket );
         if( socket->iError == 0 )
            socket->iError = HB_SOCKET_ERR_WRONGADDR;
      }
      else
      {
         /* Creates comm socket */
         socket->sd = hb_socketOpen( HB_SOCKET_PF_INET, HB_SOCKET_PT_STREAM, 0 );
         if( socket->sd == HB_NO_SOCKET )
            hb_inetGetError( socket );
         else
         {
            if( socket->remote )
               hb_xfree( socket->remote );
            if( hb_socketInetAddr( &socket->remote, &socket->remotelen,
                                   szHost, iPort ) )
            {
               hb_socketSetKeepAlive( socket->sd, HB_TRUE );
               if( hb_socketConnect( socket->sd, socket->remote, socket->remotelen,
                                     socket->iTimeout ) != 0 )
                  hb_inetGetError( socket );
               else
                  socket->iError = HB_INET_ERR_OK;
            }
            else
               hb_inetGetError( socket );
         }
         if( szAddr )
            hb_xfree( szAddr );
      }
      if( pSocket )
         hb_itemReturnRelease( pSocket );
      else
         hb_itemReturn( hb_param( 3, HB_IT_ANY ) );
   }
}
Ejemplo n.º 3
0
HB_EXTERN_END

HB_FUNC( HB_DBG_VMVARLGET )
{
   int iLevel = hb_parni( 1 ) + 1;
   int iLocal = hb_parni( 2 );
   PHB_ITEM pLocal = hb_dbg_vmVarLGet( iLevel, iLocal );

   if( pLocal )
   {
      hb_itemReturn( pLocal );
   }
   else
   {
      hb_errRT_BASE( EG_ARG, 9999, NULL, "HB_DBG_VMVARLGET", 2, hb_paramError( 1 ), hb_paramError( 2 ) );
   }
}
Ejemplo n.º 4
0
/*
    wxSocketBase_ReadBase
    Teo. Mexico 2009
*/
void wxSocketBase_ReadBase( HB_BYTE type )
{
    PHB_ITEM pSelf = hb_stackSelfItem();
    wx_SocketBase* socketBase = (wx_SocketBase*) xho_itemListGet_XHO( pSelf );

    PHB_ITEM pBuffer = hb_param( 1, HB_IT_STRING );

    if( pBuffer == NULL || !HB_ISBYREF( 1 ) )
    {
        hb_errRT_BASE_SubstR( EG_ARG, WXH_ERRBASE + 10, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
        return;
    }

    if( socketBase )
    {
        pBuffer = hb_itemUnShareString( pBuffer );

        wxUint32 nbytes = HB_ISNIL( 2 ) ?  hb_itemGetCLen( pBuffer ) : hb_parnl( 2 );

        if( nbytes > 0 )
        {
            if( nbytes > hb_itemGetCLen( pBuffer ) )
                hb_itemReSizeString( pBuffer, nbytes );

            if( type == '0' )
                socketBase->Read( (char *) hb_itemGetCPtr( pBuffer ), nbytes );
            else
                socketBase->ReadMsg( (char *) hb_itemGetCPtr( pBuffer ), nbytes );

            wxUint32 uiLastCount = socketBase->LastCount();

            if( uiLastCount < hb_itemGetCLen( pBuffer ) )
//         hb_itemGetCLen( pBuffer ) = uiLastCount;
                hb_itemReSizeString( pBuffer, uiLastCount );

        }else
            hb_errRT_BASE_SubstR( EG_ARG, WXH_ERRBASE + 10, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );

        hb_itemReturn( pSelf );
    }
}
Ejemplo n.º 5
0
static void sk_add( PHB_SETKEY * sk_list_ptr, HB_BOOL bReturn,
                    int iKeyCode, PHB_ITEM pAction, PHB_ITEM pIsActive )
{
   if( iKeyCode )
   {
      PHB_SETKEY sk_list_tmp, sk_list_end;

      if( pIsActive && ! HB_IS_EVALITEM( pIsActive ) )
         pIsActive = NULL;
      if( pAction && ! HB_IS_EVALITEM( pAction ) )
         pAction = NULL;

      sk_list_tmp = sk_findkey( iKeyCode, *sk_list_ptr, &sk_list_end );
      if( sk_list_tmp == NULL )
      {
         if( pAction )
         {
            sk_list_tmp = ( PHB_SETKEY ) hb_xgrab( sizeof( HB_SETKEY ) );
            sk_list_tmp->next = NULL;
            sk_list_tmp->iKeyCode = iKeyCode;
            sk_list_tmp->pAction = hb_itemNew( pAction );
            sk_list_tmp->pIsActive = pIsActive ? hb_itemNew( pIsActive ) : NULL;

            if( sk_list_end == NULL )
               *sk_list_ptr = sk_list_tmp;
            else
               sk_list_end->next = sk_list_tmp;
         }
      }
      else
      {
         /* Return the previous value */

         if( bReturn )
            hb_itemReturn( sk_list_tmp->pAction );

         /* Free the previous values */

         hb_itemRelease( sk_list_tmp->pAction );
         if( sk_list_tmp->pIsActive )
         {
            hb_itemRelease( sk_list_tmp->pIsActive );
         }
         /* Set the new values or free the entry */

         if( pAction )
         {
            sk_list_tmp->pAction = hb_itemNew( pAction );
            sk_list_tmp->pIsActive = pIsActive ? hb_itemNew( pIsActive ) : NULL;
         }
         else
         {
            /* if this is true, then the key found is the first key in the list */
            if( sk_list_end == NULL )
            {
               sk_list_tmp = *sk_list_ptr;
               *sk_list_ptr = sk_list_tmp->next;
               hb_xfree( sk_list_tmp );
            }
            else
            {
               sk_list_end->next = sk_list_tmp->next;
               hb_xfree( sk_list_tmp );
            }
         }
      }
   }
}
Ejemplo n.º 6
0
static void s_xhb_bitOper( int iOper )
{
   PHB_ITEM pItem1 = hb_param( 1, HB_IT_ANY ),
            pItem2 = hb_param( 2, HB_IT_ANY );
   HB_SIZE nLen1 = hb_itemGetCLen( pItem1 ),
           nLen2 = hb_itemGetCLen( pItem2 );

   if( pItem1 && pItem2 )
   {
      if( HB_IS_NUMERIC( pItem1 ) && ( HB_IS_NUMERIC( pItem2 ) || nLen2 == 1 ) )
      {
         HB_MAXINT nVal1 = hb_itemGetNInt( pItem1 ),
                   nVal2 = nLen2 == 1 ? ( HB_BYTE ) hb_itemGetCPtr( pItem1 )[ 0 ] :
                                        hb_itemGetNInt( pItem2 );
         switch( iOper )
         {
            case XHB_AND:
               nVal1 &= nVal2;
               break;
            case XHB_OR:
               nVal1 |= nVal2;
               break;
            default: /* XHB_XOR */
               nVal1 ^= nVal2;
               break;
         }
         hb_retnint( nVal1 );
         return;
      }

      if( HB_IS_STRING( pItem1 ) && HB_IS_STRING( pItem2 ) )
      {
         if( ( nLen1 | nLen2 ) != 0 )
         {
            const char * pStr1 = hb_itemGetCPtr( pItem1 ),
                       * pStr2 = hb_itemGetCPtr( pItem2 );
            char * pRet = ( char * ) hb_xmemdup( pStr1, nLen1 + 1 );
            HB_SIZE n1, n2;

            switch( iOper )
            {
               case XHB_AND:
                  for( n1 = n2 = 0; n1 < nLen1; n1++ )
                  {
                     pRet[ n1 ] &= pStr2[ n2 ];
                     if( ++n2 == nLen2 )
                        n2 = 0;
                  }
                  break;
               case XHB_OR:
                  for( n1 = n2 = 0; n1 < nLen1; n1++ )
                  {
                     pRet[ n1 ] |= pStr2[ n2 ];
                     if( ++n2 == nLen2 )
                        n2 = 0;
                  }
                  break;
               default: /* XHB_XOR */
                  for( n1 = n2 = 0; n1 < nLen1; n1++ )
                  {
                     pRet[ n1 ] ^= pStr2[ n2 ];
                     if( ++n2 == nLen2 )
                        n2 = 0;
                  }
                  break;
            }
            hb_retclen_buffer( pRet, nLen1 );
         }
         else
            hb_itemReturn( pItem1 );
         return;
      }

      if( HB_IS_STRING( pItem1 ) && ( HB_IS_NUMERIC( pItem2 ) || nLen2 == 1 ) )
      {
         if( nLen1 )
         {
            const char * pStr = hb_itemGetCPtr( pItem1 );
            char * pRet = ( char * ) hb_xmemdup( pStr, nLen1 + 1 );
            char cVal = nLen2 == 1 ? hb_itemGetCPtr( pItem2 )[ 0 ] :
                                     ( char ) hb_itemGetNI( pItem2 );

            nLen2 = nLen1;
            switch( iOper )
            {
               case XHB_AND:
                  while( nLen2-- )
                     pRet[ nLen2 ] &= cVal;
                  break;
               case XHB_OR:
                  while( nLen2-- )
                     pRet[ nLen2 ] |= cVal;
                  break;
               default: /* XHB_XOR */
                  while( nLen2-- )
                     pRet[ nLen2 ] ^= cVal;
                  break;
            }
            hb_retclen_buffer( pRet, nLen1 );
         }
         else
            hb_itemReturn( pItem1 );
         return;
      }

      if( ( HB_IS_NUMERIC( pItem1 ) || nLen1 == 1 ) && HB_IS_STRING( pItem2 ) )
      {
         const char * pStr = hb_itemGetCPtr( pItem2 );
         int iVal = nLen1 == 1 ? hb_itemGetCPtr( pItem1 )[ 0 ] :
                                 hb_itemGetNI( pItem1 );

         switch( iOper )
         {
            case XHB_AND:
               while( nLen2 )
                  iVal &= ( HB_UCHAR ) pStr[ --nLen2 ];
               break;
            case XHB_OR:
               while( nLen2 )
                  iVal |= ( HB_UCHAR ) pStr[ --nLen2 ];
               break;
            default: /* XHB_XOR */
               while( nLen2 )
                  iVal ^= ( HB_UCHAR ) pStr[ --nLen2 ];
               break;
         }
         hb_retni( iVal );
         return;
      }
   }

   hb_errRT_BASE_SubstR( EG_ARG, 1088, NULL,
                         iOper == XHB_AND ? "&" : ( iOper == XHB_OR ? "|" : "^^" ),
                         2, pItem1, pItem2 );
}
Ejemplo n.º 7
0
static void sk_add( BOOL bReturn, SHORT iKeyCode, PHB_ITEM pAction, PHB_ITEM pIsActive )
{
   if( iKeyCode )
   {
      PHB_SETKEY sk_list_tmp, sk_list_end;

      // Verify to allow only codeblock in pIsActive
      pIsActive   = ( pIsActive && HB_IS_BLOCK( pIsActive ) ) ? pIsActive : NULL;

      sk_list_tmp = sk_findkey( iKeyCode, &sk_list_end );
      if( sk_list_tmp == NULL )
      {
         if( pAction )
         {
            sk_list_tmp             = ( PHB_SETKEY ) hb_xgrab( sizeof( HB_SETKEY ) );
            sk_list_tmp->next       = NULL;
            sk_list_tmp->iKeyCode   = iKeyCode;
            sk_list_tmp->pAction    = hb_itemNew( pAction );
            sk_list_tmp->pIsActive  = pIsActive ? hb_itemNew( pIsActive ) : NULL;

            if( sk_list_end == NULL )
            {
               s_sk_list = sk_list_tmp;
            }
            else
            {
               sk_list_end->next = sk_list_tmp;
            }
         }
      }
      else
      {
         /* Return the previous value */

         if( bReturn )
            hb_itemReturn( sk_list_tmp->pAction );

         /* Free the previous values */

         hb_itemRelease( sk_list_tmp->pAction );
         if( sk_list_tmp->pIsActive )
         {
            hb_itemRelease( sk_list_tmp->pIsActive );
         }
         /* Set the new values or free the entry */

         if( pAction )
         {
            sk_list_tmp->pAction    = hb_itemNew( pAction );
            sk_list_tmp->pIsActive  = pIsActive ? hb_itemNew( pIsActive ) : NULL;
         }
         else
         {
            /* if this is true, then the key found is the first key in the list */
            if( sk_list_end == NULL )
            {
               sk_list_tmp = s_sk_list->next;
               hb_xfree( s_sk_list );
               s_sk_list   = sk_list_tmp;
            }
            else
            {
               sk_list_end->next = sk_list_tmp->next;
               hb_xfree( sk_list_tmp );
            }
         }
      }
   }
}