Beispiel #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 );
         }
      }
   }
}
Beispiel #2
0
static TOKEN_ENVIRONMENT sTokGet( int iParam, HB_BOOL fReadOnly )
{
   if( iParam < 0 || ( iParam > 0 && HB_ISCHAR( iParam ) ) )
   {
      if( iParam < 0 || fReadOnly || HB_ISBYREF( iParam ) )
      {
         HB_SIZE nLen;

         if( iParam < 0 )
            iParam = -iParam;

         nLen = hb_parclen( iParam );
         if( nLen >= sizeof( TOKEN_POSITION ) * 2 )
         {
            TOKEN_ENVIRONMENT env = ( TOKEN_ENVIRONMENT ) HB_UNCONST( hb_parc( iParam ) );

            if( sTokEnvGetSize( env ) == nLen )
               return fReadOnly ? env : ( TOKEN_ENVIRONMENT ) hb_xmemdup( env, nLen + 1 );
         }
      }
      return NULL;
   }
   else
      return * ( TOKEN_ENVIRONMENT * ) hb_stackGetTSD( &s_token );
}
Beispiel #3
0
static int sTokSave( TOKEN_ENVIRONMENT sTokenEnvironment, int iParam )
{
   if( iParam != 0 && HB_ISBYREF( iParam ) )
   {
      if( ! hb_storclen_buffer( ( char * ) sTokenEnvironment,
                                sTokEnvGetSize( sTokenEnvironment ), iParam ) )
      {
         sTokEnvDel( sTokenEnvironment );
         return 0;
      }
   }
   else
      sTokSet( sTokenEnvironment );
   return 1;
}
static void s_getPathName( _HB_GETPATHNAME getPathName )
{
   void * hLongPath;
   DWORD length = 0;
   LPCTSTR lpszLongPath = HB_PARSTR( 1, &hLongPath, NULL );

   if( lpszLongPath )
   {
      if( HB_ISBYREF( 2 ) )
      {
         TCHAR buffer[ HB_PATH_MAX ];
         DWORD cchBuffer = ( DWORD ) HB_SIZEOFARRAY( buffer );
         LPTSTR lpszShortPath = buffer;
         HB_BOOL fSize = HB_ISNUM( 3 );

         if( fSize )    /* the size of buffer is limited by user */
         {
            cchBuffer = ( DWORD ) hb_parnl( 3 );
            if( cchBuffer == 0 )
               lpszShortPath = NULL;
            else if( cchBuffer > ( DWORD ) HB_SIZEOFARRAY( buffer ) )
               lpszShortPath = ( LPTSTR ) hb_xgrab( cchBuffer * sizeof( TCHAR ) );
         }

         length = getPathName( lpszLongPath, lpszShortPath, cchBuffer );
         if( ! fSize && length > cchBuffer )  /* default buffer size was too small */
         {
            cchBuffer = length;
            lpszShortPath = ( LPTSTR ) hb_xgrab( cchBuffer * sizeof( TCHAR ) );
            length = getPathName( lpszLongPath, lpszShortPath, cchBuffer );
         }
         hbwapi_SetLastError( GetLastError() );
         HB_STORSTRLEN( lpszShortPath, length > cchBuffer ? 0 : length, 2 );
         if( lpszShortPath && lpszShortPath != buffer )
            hb_xfree( lpszShortPath );
      }
      else if( getPathName )
      {
         length = getPathName( lpszLongPath, NULL, 0 );
         hbwapi_SetLastError( GetLastError() );
      }
   }
   hb_retnl( length );
   hb_strfree( hLongPath );
}
/*
    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 );
    }
}
Beispiel #6
0
/* helper function for the charswap and wordswap functions */
static void do_charswap( int iSwitch )
{
   /* suppress return value ? */
   int iNoRet = ct_getref() && HB_ISBYREF( 1 );

   /* param check */
   if( HB_ISCHAR( 1 ) )
   {
      const char * pcString = hb_parc( 1 );
      HB_SIZE sStrLen = hb_parclen( 1 );
      char * pcRet;
      HB_SIZE sRetIndex = 0;
      int iShift, iMod;
      const char * pcSub;

      if( sStrLen == 0 )
      {
         if( iNoRet )
            hb_ret();
         else
            hb_retc_null();
         return;
      }

      if( iSwitch == DO_CHARSWAP_WORDSWAP )
      {
         iShift = 4;
         if( hb_parl( 2 ) )
            iSwitch = DO_CHARSWAP_WORDSWAP_CHARSWAP;
      }
      else
         iShift = 2;

      pcRet = ( char * ) hb_xgrab( sStrLen );

      for( pcSub = pcString; pcSub < pcString + sStrLen + 1 - iShift; pcSub += iShift )
      {
         switch( iSwitch )
         {
            case DO_CHARSWAP_WORDSWAP:
               pcRet[ sRetIndex++ ] = pcSub[ 2 ];
               pcRet[ sRetIndex++ ] = pcSub[ 3 ];
               pcRet[ sRetIndex++ ] = pcSub[ 0 ];
               pcRet[ sRetIndex++ ] = pcSub[ 1 ];
               break;

            case DO_CHARSWAP_WORDSWAP_CHARSWAP:
               pcRet[ sRetIndex++ ] = pcSub[ 3 ];
               pcRet[ sRetIndex++ ] = pcSub[ 2 ];
               /* no 'break' here !! */
            case DO_CHARSWAP_CHARSWAP:
               pcRet[ sRetIndex++ ] = pcSub[ 1 ];
               pcRet[ sRetIndex++ ] = pcSub[ 0 ];
         }
      }

      /* copy rest of string */
      if( iSwitch == DO_CHARSWAP_WORDSWAP || iSwitch == DO_CHARSWAP_WORDSWAP_CHARSWAP )
         iMod = sStrLen % 4;
      else
         iMod = sStrLen % 2;

      for( pcSub = pcString + sStrLen - iMod; pcSub < pcString + sStrLen; pcSub++ )
         pcRet[ sRetIndex++ ] = *pcSub;

      /* return string */
      hb_storclen( pcRet, sRetIndex, 1 );

      if( iNoRet )
         hb_retl( HB_FALSE );
      else
         hb_retclen( pcRet, sRetIndex );
      hb_xfree( pcRet );
   }
   else
   {
      PHB_ITEM pSubst = NULL;
      int iArgErrorMode = ct_getargerrormode();

      if( iArgErrorMode != CT_ARGERR_IGNORE )
      {
         if( iSwitch == DO_CHARSWAP_CHARSWAP )
            pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                     CT_ERROR_CHARSWAP,
                                     NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE,
                                     HB_ERR_ARGS_BASEPARAMS );
         else
            pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                     CT_ERROR_WORDSWAP,
                                     NULL, HB_ERR_FUNCNAME, 0, EF_CANSUBSTITUTE,
                                     HB_ERR_ARGS_BASEPARAMS );
      }

      if( pSubst != NULL )
         hb_itemReturnRelease( pSubst );
      else if( iNoRet )
         hb_retl( HB_FALSE );
      else
         hb_retc_null();
   }
}
Beispiel #7
0
static void s_inetRecvInternal( int iMode )
{
   PHB_SOCKET_STRUCT socket = HB_PARSOCKET( 1 );
   PHB_ITEM pBuffer = hb_param( 2, HB_IT_STRING );

   if( socket == NULL || pBuffer == NULL || ! HB_ISBYREF( 2 ) )
      hb_inetErrRT();
   else if( ! hb_inetIsOpen( socket ) )
      hb_retni( -1 );
   else
   {
      int iLen, iMaxLen, iReceived, iTimeElapsed;
      char * buffer;
      HB_SIZE nLen;

      if( hb_itemGetWriteCL( pBuffer, &buffer, &nLen ) )
         iLen = ( int ) nLen;
      else
      {
         iLen = 0;
         buffer = NULL;
      }

      if( HB_ISNUM( 3 ) )
      {
         iMaxLen = hb_parni( 3 );
         if( iMaxLen < 0 )
            iMaxLen = 0;
         else if( iLen < iMaxLen )
            iMaxLen = iLen;
      }
      else
         iMaxLen = iLen;

      iReceived = iTimeElapsed = 0;
      socket->iError = HB_INET_ERR_OK;
      do
      {
         iLen = s_inetRecv( socket, buffer + iReceived, iMaxLen - iReceived,
                            HB_FALSE, socket->iTimeout );
         if( iLen >= 0 )
         {
            iReceived += iLen;
            if( iMode == 0 ) /* Called from hb_inetRecv()? */
               break;
         }
         else if( iLen == -1 && s_inetIsTimeout( socket ) )
         {
            /* if we have a pPeriodicBlock, timeLimit is our REAL timeout */
            if( socket->pPeriodicBlock )
            {
               /* timed out; let's see if we have to run a cb routine */
               iTimeElapsed += socket->iTimeout;
               hb_execFromArray( socket->pPeriodicBlock );
               /* do we continue? */
               if( hb_parl( -1 ) && hb_vmRequestQuery() == 0 &&
                   ( socket->iTimeLimit == -1 || iTimeElapsed < socket->iTimeLimit ) )
                  iLen = 1;   /* Declare success to continue loop */
            }
         }
      }
      while( iReceived < iMaxLen && iLen > 0 );

      socket->iCount = iReceived;

      if( iLen == 0 )
         socket->iError = HB_INET_ERR_CLOSEDCONN;
      else if( iLen < 0 )
         hb_inetGetError( socket );

      hb_retni( iReceived > 0 ? iReceived : iLen );
   }
}
Beispiel #8
0
/* helper function for the token function group I */
static void do_token1( int iSwitch )
{
   PCT_TOKEN ct_token = ( PCT_TOKEN ) hb_stackGetTSD( &s_ct_token );

   int iParamCheck = 0;
   int iNoRef = ct_getref() && HB_ISBYREF( 1 );

   switch( iSwitch )
   {
      case DO_TOKEN1_TOKEN:
         ct_token->iPreSeparator = ct_token->iPostSeparator = -1;
         /* no "break" here !! */
      case DO_TOKEN1_ATTOKEN:
      case DO_TOKEN1_NUMTOKEN:
      case DO_TOKEN1_TOKENLOWER:
      case DO_TOKEN1_TOKENUPPER:
         iParamCheck = HB_ISCHAR( 1 );
         break;
   }

   if( iParamCheck )
   {
      const char * pcString = hb_parc( 1 );
      HB_SIZE sStrLen = hb_parclen( 1 );
      const char * pcSeparatorStr;
      HB_SIZE sSeparatorStrLen;
      HB_SIZE nTokenCounter;
      HB_SIZE nSkip;
      const char * pcSubStr;
      char * pcRet = NULL;
      HB_SIZE sSubStrLen;
      HB_SIZE sRetStrLen = 0;
      HB_SIZE nToken = 0;
      HB_SIZE nSkipCnt;
      const char * pc;

      /* separator string */
      sSeparatorStrLen = hb_parclen( 2 );
      if( sSeparatorStrLen != 0 )
         pcSeparatorStr = hb_parc( 2 );
      else
      {
         pcSeparatorStr = sc_pcSeparatorStr;
         sSeparatorStrLen = sc_sSeparatorStrLen;
      }

      if( iSwitch == DO_TOKEN1_NUMTOKEN )
      {
         /* token counter */
         nTokenCounter = HB_SIZE_MAX;
         /* skip width */
         nSkip = hb_parns( 3 );
      }
      else
      {
         /* token counter */
         nTokenCounter = hb_parns( 3 );
         /* skip width */
         nSkip = hb_parns( 4 ); /* HB_EXTENSION for AtToken()/TokenLower()/TokenUpper() */
      }

      if( nTokenCounter == 0 )
         nTokenCounter = HB_SIZE_MAX;
      if( nSkip == 0 )
         nSkip = HB_SIZE_MAX;

      /* prepare return value for TokenUpper()/TokenLower() */
      if( iSwitch == DO_TOKEN1_TOKENLOWER || iSwitch == DO_TOKEN1_TOKENUPPER )
      {
         if( sStrLen == 0 )
         {
            if( iNoRef )
               hb_retl( HB_FALSE );
            else
               hb_retc_null();
            return;
         }
         sRetStrLen = sStrLen;
         pcRet = ( char * ) hb_xgrab( sRetStrLen + 1 );
         hb_xmemcpy( pcRet, pcString, sRetStrLen );
      }

      /* find the <nTokenCounter>th token */
      pcSubStr = pcString;
      sSubStrLen = sStrLen;

      /* scan start condition */
      pc = pcSubStr - 1;

      while( nToken < nTokenCounter )
      {
         HB_SIZE sMatchedPos = sSeparatorStrLen;

         /* Skip the left nSkip successive separators */
         nSkipCnt = 0;
         do
         {
            sSubStrLen -= ( pc - pcSubStr ) + 1;
            pcSubStr = pc + 1;
            pc = ct_at_charset_forward( pcSubStr, sSubStrLen,
                                        pcSeparatorStr, sSeparatorStrLen, &sMatchedPos );
            if( iSwitch == DO_TOKEN1_TOKEN )
            {
               ct_token->iPreSeparator = ct_token->iPostSeparator;
               if( sMatchedPos < sSeparatorStrLen )
                  ct_token->iPostSeparator = pcSeparatorStr[ sMatchedPos ];
               else
                  ct_token->iPostSeparator = -1;
            }
            nSkipCnt++;
         }
         while( nSkipCnt < nSkip && pc == pcSubStr );

         if( sSubStrLen == 0 )
         {
            /* string ends with tokenizer (null string after tokenizer at
               end of string is not a token) */
            switch( iSwitch )
            {
               case DO_TOKEN1_TOKEN:
               {
                  char cRet;

                  hb_retc_null();
                  if( HB_ISBYREF( 5 ) ) /* HB_EXTENSION */
                  {
                     cRet = ( char ) ct_token->iPreSeparator;
                     hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 );
                  }
                  if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */
                  {
                     cRet = ( char ) ct_token->iPostSeparator;
                     hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 );
                  }
                  break;
               }
               case DO_TOKEN1_NUMTOKEN:
                  hb_retns( nToken );
                  break;

               case DO_TOKEN1_ATTOKEN:
                  hb_retns( 0 );
                  break;

               case DO_TOKEN1_TOKENLOWER:
               case DO_TOKEN1_TOKENUPPER:
                  hb_storclen( pcRet, sRetStrLen, 1 );

                  if( iNoRef )
                  {
                     hb_xfree( pcRet );
                     hb_retl( HB_FALSE );
                  }
                  else
                     hb_retclen_buffer( pcRet, sRetStrLen );
                  break;
            }
            return;
         }

         switch( iSwitch )
         {
            case DO_TOKEN1_TOKEN:
            case DO_TOKEN1_NUMTOKEN:
            case DO_TOKEN1_ATTOKEN:
               break;

            case DO_TOKEN1_TOKENLOWER:
               if( pcSubStr != pc )     /* letters can be tokenizers, too,
                                           but they should not be lowercase'd */
                  *( pcRet + ( pcSubStr - pcString ) ) = ( char ) hb_charLower( ( HB_UCHAR ) *pcSubStr );
               break;

            case DO_TOKEN1_TOKENUPPER:
               if( pcSubStr != pc )     /* letters can be tokenizers, too,
                                           but they should not be uppercase'd */
                  *( pcRet + ( pcSubStr - pcString ) ) = ( char ) hb_charUpper( ( HB_UCHAR ) *pcSubStr );
               break;

            default:
               break;
         }

         nToken++;

         if( pc == NULL )
         {
            /* little trick for return values */
            pc = pcSubStr + sSubStrLen;
            /* we must leave the while loop even if we have not
               yet found the <nTokenCounter>th token */
            break;
         }

         /* should we find the last token, but string ends with tokenizer, i.e.
            pc points to the last character at the moment ?
            -> break here ! */
         if( nTokenCounter == HB_SIZE_MAX )
         {
            if( nSkip == HB_SIZE_MAX )
            {
               const char * t;
               HB_BOOL bLast = HB_TRUE;

               for( t = pc + 1; t < pcString + sStrLen; t++ )
               {
                  if( ! memchr( pcSeparatorStr, *t, sSeparatorStrLen ) )
                  {
                     bLast = HB_FALSE;
                     break;
                  }
               }
               if( bLast )
                  break;
            }
            else if( pc + 1 == pcString + sStrLen )
               break;
         }
      }

      switch( iSwitch )
      {
         case DO_TOKEN1_TOKEN:
         {
            char cRet;

            if( nTokenCounter == HB_SIZE_MAX ||
                nToken == nTokenCounter )
               hb_retclen( pcSubStr, pc - pcSubStr );
            else
               hb_retc_null();

            if( HB_ISBYREF( 5 ) ) /* HB_EXTENSION */
            {
               cRet = ( char ) ct_token->iPreSeparator;
               hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 );
            }
            if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */
            {
               cRet = ( char ) ct_token->iPostSeparator;
               hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 );
            }
            break;
         }
         case DO_TOKEN1_NUMTOKEN:
            hb_retns( nToken );
            break;

         case DO_TOKEN1_ATTOKEN:
            if( nTokenCounter == HB_SIZE_MAX ||
                nToken == nTokenCounter )
               hb_retns( pcSubStr - pcString + 1 );
            else
               hb_retns( 0 );
            break;

         case DO_TOKEN1_TOKENLOWER:
         case DO_TOKEN1_TOKENUPPER:
            hb_storclen( pcRet, sRetStrLen, 1 );

            if( iNoRef )
            {
               hb_xfree( pcRet );
               hb_retl( HB_FALSE );
            }
            else
               hb_retclen_buffer( pcRet, sRetStrLen );
            break;
      }
   }
   else
   {
      switch( iSwitch )
      {
         case DO_TOKEN1_TOKEN:
         {
            PHB_ITEM pSubst = NULL;
            int iArgErrorMode = ct_getargerrormode();
            char cRet;

            if( HB_ISBYREF( 5 ) ) /* HB_EXTENSION */
            {
               cRet = ( char ) ct_token->iPreSeparator;
               hb_storclen( &cRet, ( ct_token->iPreSeparator != -1 ? 1 : 0 ), 5 );
            }
            if( HB_ISBYREF( 6 ) ) /* HB_EXTENSION */
            {
               cRet = ( char ) ct_token->iPostSeparator;
               hb_storclen( &cRet, ( ct_token->iPostSeparator != -1 ? 1 : 0 ), 6 );
            }

            if( iArgErrorMode != CT_ARGERR_IGNORE )
               pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                        CT_ERROR_TOKEN, NULL, HB_ERR_FUNCNAME, 0,
                                        EF_CANSUBSTITUTE,
                                        HB_ERR_ARGS_BASEPARAMS );

            if( pSubst != NULL )
               hb_itemReturnRelease( pSubst );
            else if( ! iNoRef )
               hb_retc_null();
            else
               hb_retl( HB_FALSE );
            break;
         }
         case DO_TOKEN1_TOKENLOWER:
         case DO_TOKEN1_TOKENUPPER:
         {
            PHB_ITEM pSubst = NULL;
            int iArgErrorMode = ct_getargerrormode();

            if( iArgErrorMode != CT_ARGERR_IGNORE )
               pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                        iSwitch == DO_TOKEN1_TOKENLOWER ?
                                        CT_ERROR_TOKENLOWER : CT_ERROR_TOKENUPPER,
                                        NULL, HB_ERR_FUNCNAME, 0,
                                        EF_CANSUBSTITUTE,
                                        HB_ERR_ARGS_BASEPARAMS );

            if( pSubst != NULL )
               hb_itemReturnRelease( pSubst );
            else if( ! iNoRef )
               hb_retc_null();
            else
               hb_retl( HB_FALSE );
            break;
         }
         case DO_TOKEN1_NUMTOKEN:
         case DO_TOKEN1_ATTOKEN:
         {
            PHB_ITEM pSubst = NULL;
            int iArgErrorMode = ct_getargerrormode();

            if( iArgErrorMode != CT_ARGERR_IGNORE )
               pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                        iSwitch == DO_TOKEN1_NUMTOKEN ?
                                        CT_ERROR_NUMTOKEN : CT_ERROR_ATTOKEN,
                                        NULL, HB_ERR_FUNCNAME, 0,
                                        EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS );

            if( pSubst != NULL )
               hb_itemReturnRelease( pSubst );
            else
               hb_retns( 0 );
            break;
         }
      }
   }
}
Beispiel #9
0
/* helper function for the replxxx functions */
static void do_replace( int iSwitch )
{
   /* suppressing return value ? */
   int iNoRet = ct_getref() && HB_ISBYREF( 1 );

   /* param check */
   if( HB_ISCHAR( 1 ) && ( hb_parclen( 2 ) > 0 || HB_ISNUM( 2 ) ) )
   {
      const char * pcString = hb_parc( 1 );
      HB_SIZE sStrLen = hb_parclen( 1 );
      char * pcRet, * pc;
      char cSearch, cReplace;

      if( sStrLen == 0 )
      {
         if( iNoRet )
            hb_ret();
         else
            hb_retc_null();
         return;
      }

      if( HB_ISNUM( 2 ) )
         cReplace = ( char ) ( hb_parnl( 2 ) % 256 );
      else
         cReplace = *( ( const char * ) hb_parc( 2 ) );

      if( hb_parclen( 3 ) > 0 )
         cSearch = *( ( const char * ) hb_parc( 3 ) );
      else if( HB_ISNUM( 3 ) )
         cSearch = ( char ) ( hb_parnl( 3 ) % 256 );
      else
         cSearch = 0x20;

      pcRet = ( char * ) hb_xgrab( sStrLen + 1 );
      hb_xmemcpy( pcRet, pcString, sStrLen );

      if( iSwitch != DO_REPLACE_REPLRIGHT )
      {
         pc = pcRet;
         while( *pc == cSearch && pc < pcRet + sStrLen )
         {
            *pc = cReplace;
            pc++;
         }
      }

      if( iSwitch != DO_REPLACE_REPLLEFT )
      {
         pc = pcRet + sStrLen - 1;
         while( *pc == cSearch && pc >= pcRet )
         {
            *pc = cReplace;
            pc--;
         }
      }

      hb_storclen( pcRet, sStrLen, 1 );

      if( iNoRet )
      {
         hb_xfree( pcRet );
         hb_ret();
      }
      else
         hb_retclen_buffer( pcRet, sStrLen );
   }
   else
   {
      PHB_ITEM pSubst = NULL;
      int iArgErrorMode = ct_getargerrormode();

      if( iArgErrorMode != CT_ARGERR_IGNORE )
         pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                  sulErrorSubcodes[ iSwitch ],
                                  NULL, HB_ERR_FUNCNAME, 0,
                                  EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS );

      if( pSubst != NULL )
         hb_itemReturnRelease( pSubst );
      else if( iNoRet )
         hb_ret();
      else
         hb_retc_null();
   }
}
Beispiel #10
0
static amqp_response_type_enum s_process_response( int iParam, amqp_rpc_reply_t x )
{
   if( HB_ISBYREF( iParam ) )
   {
      PHB_ITEM hResponse = hb_hashNew( NULL );

      PHB_ITEM pKey = hb_itemNew( NULL );
      PHB_ITEM pVal = hb_itemNew( NULL );

      char szName[ HB_SYMBOL_NAME_LEN + HB_SYMBOL_NAME_LEN + 5 ];

      hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "cAPI" ), hb_itemPutC( pVal, hb_procname( 0, szName, HB_FALSE ) ) );
      hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReplyType" ), hb_itemPutNI( pVal, ( int ) x.reply_type ) );
      hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nLibraryError" ), hb_itemPutNI( pVal, x.library_error ) );
      hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "cLibraryError" ), hb_itemPutC( pVal, amqp_error_string2( x.library_error ) ) );

      switch( x.reply_type )
      {
         case AMQP_RESPONSE_NORMAL:
            /* fallthrough */
         case AMQP_RESPONSE_LIBRARY_EXCEPTION:
            /* fallthrough */
         case AMQP_RESPONSE_NONE:
            break;
         case AMQP_RESPONSE_SERVER_EXCEPTION:

            hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReplyID" ), hb_itemPutNI( pVal, ( int ) x.reply.id ) );

            switch( x.reply.id )
            {
               case AMQP_CONNECTION_CLOSE_METHOD:
               {
                  amqp_connection_close_t * m = ( amqp_connection_close_t * ) x.reply.decoded;
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_Code" ), hb_itemPutNL( pVal, ( long ) m->reply_code ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_Text" ), hb_itemPutCL( pVal, m->reply_text.bytes, m->reply_text.len ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_ClassID" ), hb_itemPutNL( pVal, ( long ) m->class_id ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_MethodID" ), hb_itemPutNL( pVal, ( long ) m->method_id ) );
                  break;
               }
               case AMQP_CHANNEL_CLOSE_METHOD:
               {
                  amqp_channel_close_t * m = ( amqp_channel_close_t * ) x.reply.decoded;
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_Code" ), hb_itemPutNL( pVal, ( long ) m->reply_code ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_Text" ), hb_itemPutCL( pVal, m->reply_text.bytes, m->reply_text.len ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_ClassID" ), hb_itemPutNL( pVal, ( long ) m->class_id ) );
                  hb_hashAdd( hResponse, hb_itemPutCConst( pKey, "nReply_MethodID" ), hb_itemPutNL( pVal, ( long ) m->method_id ) );
                  break;
               }
            }
            break;
      }

      if( ! hb_itemParamStoreRelease( iParam, hResponse ) )
         hb_itemRelease( hResponse );

      hb_itemRelease( pVal );
      hb_itemRelease( pKey );
   }

   return x.reply_type;
}
Beispiel #11
0
/* helper function for the justxxx() functions */
static void do_justify( int iSwitch )
{
   int iNoRet = ct_getref() && HB_ISBYREF( 1 );

   if( HB_ISCHAR( 1 ) )
   {
      const char * pcString = hb_parc( 1 );
      HB_SIZE sStrLen = hb_parclen( 1 );
      char cJustChar;
      const char * pc;
      char * pcRet, * pcw;
      HB_SIZE sJustOffset;

      if( sStrLen == 0 )
      {
         if( iNoRet )
            hb_ret();
         else
            hb_retc_null();
         return;
      }

      if( hb_parclen( 2 ) > 0 )
         cJustChar = *( hb_parc( 2 ) );
      else if( HB_ISNUM( 2 ) )
         cJustChar = ( char ) ( hb_parnl( 2 ) % 256 );
      else
         cJustChar = 0x20;

      pcRet = ( char * ) hb_xgrab( sStrLen + 1 );

      switch( iSwitch )
      {
         case DO_JUSTIFY_JUSTLEFT:
            pc = pcString;
            sJustOffset = 0;
            while( *pc == cJustChar && pc < ( pcString + sStrLen ) )
            {
               sJustOffset++;
               pc++;
            }

            hb_xmemcpy( pcRet, pcString + sJustOffset, sStrLen - sJustOffset );

            for( pcw = pcRet + sStrLen - sJustOffset; pcw < pcRet + sStrLen; pcw++ )
               *pcw = cJustChar;

            break;

         case DO_JUSTIFY_JUSTRIGHT:
            pc = pcString + sStrLen - 1;
            sJustOffset = 0;
            while( *pc == cJustChar && pc >= pcString )
            {
               sJustOffset++;
               pc--;
            }

            for( pcw = pcRet; pcw < pcRet + sJustOffset; pcw++ )
               *pcw = cJustChar;

            hb_xmemcpy( pcRet + sJustOffset, pcString, sStrLen - sJustOffset );
            break;
      }

      hb_storclen( pcRet, sStrLen, 1 );

      if( iNoRet )
      {
         hb_ret();
         hb_xfree( pcRet );
      }
      else
         hb_retclen_buffer( pcRet, sStrLen );
   }
   else
   {
      PHB_ITEM pSubst = NULL;
      int iArgErrorMode = ct_getargerrormode();

      if( iArgErrorMode != CT_ARGERR_IGNORE )
         pSubst = ct_error_subst( ( HB_USHORT ) iArgErrorMode, EG_ARG,
                                  iSwitch == DO_JUSTIFY_JUSTLEFT ?
                                  CT_ERROR_JUSTLEFT : CT_ERROR_JUSTRIGHT,
                                  NULL, HB_ERR_FUNCNAME, 0,
                                  EF_CANSUBSTITUTE, HB_ERR_ARGS_BASEPARAMS );

      if( pSubst != NULL )
         hb_itemReturnRelease( pSubst );
      else if( iNoRet )
         hb_ret();
      else
         hb_retc_null();
   }
}