/* --- SDD METHODS --- */ static HB_ERRCODE mysqlConnect( SQLDDCONNECTION * pConnection, PHB_ITEM pItem ) { MYSQL * pMySql; PHB_ITEM pItemUnixSocket = hb_arrayGetItemPtr( pItem, 7 ); pMySql = mysql_init( NULL ); if( ! mysql_real_connect( pMySql, hb_arrayGetCPtr( pItem, 2 ) /* host */, hb_arrayGetCPtr( pItem, 3 ) /* user */, hb_arrayGetCPtr( pItem, 4 ) /* password */, hb_arrayGetCPtr( pItem, 5 ) /* db */, hb_arrayGetNI( pItem, 6 ) /* port */, pItemUnixSocket && HB_IS_STRING( pItemUnixSocket ) ? hb_itemGetCPtr( pItemUnixSocket ) : NULL, hb_arrayGetNI( pItem, 8 ) /* flags*/ ) ) { hb_rddsqlSetError( mysql_errno( pMySql ), mysql_error( pMySql ), NULL, NULL, 0 ); mysql_close( pMySql ); return HB_FAILURE; } pConnection->pSDDConn = hb_xgrab( sizeof( SDDCONN ) ); ( ( SDDCONN * ) pConnection->pSDDConn )->pMySql = pMySql; return HB_SUCCESS; }
//------------------------------- // Manager of signals for windows // static LONG s_signalHandler( int type, int sig, PEXCEPTION_RECORD exc ) { PHB_ITEM pFunction, pExecArray, pRet; ULONG ulPos; UINT uiSig, uiMask; int iRet; // let's find the right signal handler. HB_CRITICAL_LOCK( s_ServiceMutex ); // avoid working if PRG signal handling has been disabled if ( ! bSignalEnabled ) { HB_CRITICAL_UNLOCK( s_ServiceMutex ); return EXCEPTION_EXECUTE_HANDLER; } bSignalEnabled = FALSE; ulPos = hb_arrayLen( sp_hooks ); // subsig not necessary uiSig = (UINT) s_translateSignal( (UINT)type, (UINT)sig ); while( ulPos > 0 ) { pFunction = hb_arrayGetItemPtr( sp_hooks, ulPos ); uiMask = (UINT) hb_arrayGetNI( pFunction, 1 ); if ( (uiMask & uiSig) == uiSig ) { // we don't unlock the mutex now, even if it is // a little dangerous. But we are in a signal hander... // for now just 2 parameters pExecArray = hb_itemArrayNew( 3 ); hb_arraySetForward( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) ); hb_arraySetNI( pExecArray, 2, uiSig ); /* the third parameter is an array: * 1: low-level signal * 2: low-level subsignal * 3: low-level system error * 4: address that rised the signal * 5: process id of the signal riser * 6: UID of the riser */ pRet = hb_arrayGetItemPtr( pExecArray, 3); hb_arrayNew( pRet, 6 ); hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, type ); hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, sig ); //could be meaningless, but does not matter here hb_arraySetNI( pRet, HB_SERVICE_OSERROR, GetLastError() ); if (type == 0 ) //exception { hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, ( void * ) exc->ExceptionAddress ); } else { hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, NULL ); } //TODO: hb_arraySetNI( pRet, HB_SERVICE_PROCESS, GetCurrentThreadId() ); //TODO: hb_arraySetNI( pRet, HB_SERVICE_UID, 0 ); pRet = hb_itemDo( pExecArray, 0 ); iRet = hb_itemGetNI( pRet ); hb_itemRelease( pRet ); hb_itemRelease( pExecArray ); switch( iRet ) { case HB_SERVICE_HANDLED: bSignalEnabled = TRUE; HB_CRITICAL_UNLOCK( s_ServiceMutex ); return EXCEPTION_CONTINUE_EXECUTION; case HB_SERVICE_QUIT: bSignalEnabled = FALSE; HB_CRITICAL_UNLOCK( s_ServiceMutex ); hb_vmRequestQuit(); #ifndef HB_THREAD_SUPPORT hb_vmQuit(); exit(0); #else hb_threadCancelInternal(); #endif } } ulPos--; } bSignalEnabled = TRUE; return EXCEPTION_EXECUTE_HANDLER; }
static void s_signalHandler( int sig, siginfo_t *info, void *v ) #endif { UINT uiMask; UINT uiSig; PHB_ITEM pFunction, pExecArray, pRet; ULONG ulPos; int iRet; #if !( defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) ) HB_SYMBOL_UNUSED(v); #endif // let's find the right signal handler. HB_CRITICAL_LOCK( s_ServiceMutex ); // avoid working if PRG signal handling has been disabled if ( ! bSignalEnabled ) { HB_CRITICAL_UNLOCK( s_ServiceMutex ); return; } bSignalEnabled = FALSE; ulPos = hb_arrayLen( sp_hooks ); // subsig not necessary uiSig = (UINT) s_translateSignal( (UINT)sig, 0 ); while( ulPos > 0 ) { pFunction = hb_arrayGetItemPtr( sp_hooks, ulPos ); uiMask = (UINT) hb_arrayGetNI( pFunction, 1 ); if ( uiMask & uiSig) { // we don't unlock the mutex now, even if it is // a little dangerous. But we are in a signal hander... // for now just 2 parameters pExecArray = hb_itemArrayNew( 3 ); hb_arraySet( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) ); hb_arraySetNI( pExecArray, 2, uiSig ); // the third parameter is an array: pRet = hb_arrayGetItemPtr( pExecArray, 3); #if defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) hb_arrayNew( pRet, 1 ); #elif defined( HB_OS_BSD ) hb_arrayNew( pRet, info ? 6 : 1 ); #else hb_arrayNew( pRet, 6 ); #endif hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, sig ); #if !( defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) ) #if defined( HB_OS_BSD ) if (info) #endif { hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, info->si_code ); hb_arraySetNI( pRet, HB_SERVICE_OSERROR, info->si_errno ); hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, (void *) info->si_addr ); hb_arraySetNI( pRet, HB_SERVICE_PROCESS, info->si_pid ); hb_arraySetNI( pRet, HB_SERVICE_UID, info->si_uid ); } #endif pRet = hb_itemDo( pExecArray, 0 ); iRet = hb_itemGetNI( pRet ); hb_itemRelease( pRet ); hb_itemRelease( pExecArray ); switch( iRet ) { case HB_SERVICE_HANDLED: bSignalEnabled = TRUE; HB_CRITICAL_UNLOCK( s_ServiceMutex ); return; case HB_SERVICE_QUIT: bSignalEnabled = FALSE; HB_CRITICAL_UNLOCK( s_ServiceMutex ); //TODO: A service cleanup routine hb_vmRequestQuit(); #ifndef HB_THREAD_SUPPORT hb_vmQuit(); exit(0); #else /* Allow signals to go through pthreads */ s_serviceSetDflSig(); /* NOTICE: should be pthread_exit(0), but a bug in linuxthread prevents it: calling pthread exit from a signal handler will cause infinite wait for restart signal. This solution is rude, while the other would allow clean VM termination... but it works. */ exit(0); #endif } } ulPos--; } bSignalEnabled = TRUE; /*s_serviceSetHBSig();*/ /* TODO if ( uiSig != HB_SIGNAL_UNKNOWN ) { if ( sa_oldAction[ sig ].sa_flags & SA_SIGINFO ) { sa_oldAction[ sig ].sa_sigaction( sig, info, v ); } else { sa_oldAction[ sig ].sa_handler( sig ); } }*/ }
HB_USHORT hb_errGetFlags( PHB_ITEM pError ) { HB_TRACE( HB_TR_DEBUG, ( "hb_errGetFlags(%p)", pError ) ); return ( HB_USHORT ) hb_arrayGetNI( pError, HB_TERROR_FLAGS ); }
HB_ERRCODE hb_errGetSubCode( PHB_ITEM pError ) { HB_TRACE( HB_TR_DEBUG, ( "hb_errGetSubCode(%p)", pError ) ); return ( HB_ERRCODE ) hb_arrayGetNI( pError, HB_TERROR_SUBCODE ); }
HB_USHORT hb_errGetSeverity( PHB_ITEM pError ) { HB_TRACE( HB_TR_DEBUG, ( "hb_errGetSeverity(%p)", pError ) ); return ( HB_USHORT ) hb_arrayGetNI( pError, HB_TERROR_SEVERITY ); }
LOGFONT * hbwapi_par_LOGFONT( LOGFONT * p, int iParam, HB_BOOL bMandatory ) { PHB_ITEM pStru = hb_param( iParam, HB_IT_ANY ); void * hfFaceName; LPCTSTR pfFaceName; HB_SIZE nLen; memset( p, 0, sizeof( LOGFONT ) ); if( pStru && HB_IS_HASH( pStru ) ) { p->lfHeight = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfHeight" ) ); p->lfWidth = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfWidth" ) ); p->lfEscapement = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfEscapement" ) ); p->lfOrientation = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfOrientation" ) ); p->lfWeight = ( LONG ) hb_itemGetNL( hb_hashGetCItemPtr( pStru, "lfWeight" ) ); p->lfItalic = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfItalic" ) ); p->lfUnderline = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfUnderline" ) ); p->lfStrikeOut = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfStrikeOut" ) ); p->lfCharSet = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfCharSet" ) ); p->lfOutPrecision = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfOutPrecision" ) ); p->lfClipPrecision = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfClipPrecision" ) ); p->lfQuality = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfQuality" ) ); p->lfPitchAndFamily = ( BYTE ) hb_itemGetNI( hb_hashGetCItemPtr( pStru, "lfPitchAndFamily" ) ); pfFaceName = HB_ITEMGETSTR( hb_hashGetCItemPtr( pStru, "lfFaceName" ), &hfFaceName, &nLen ); if( nLen > ( LF_FACESIZE - 1 ) ) nLen = LF_FACESIZE - 1; memcpy( p->lfFaceName, pfFaceName, nLen * sizeof( TCHAR ) ); p->lfFaceName[ nLen ] = TEXT( '\0' ); hb_strfree( hfFaceName ); return p; } else if( pStru && HB_IS_ARRAY( pStru ) && hb_arrayLen( pStru ) >= 14 ) { p->lfHeight = ( LONG ) hb_arrayGetNL( pStru, 1 ); p->lfWidth = ( LONG ) hb_arrayGetNL( pStru, 2 ); p->lfEscapement = ( LONG ) hb_arrayGetNL( pStru, 3 ); p->lfOrientation = ( LONG ) hb_arrayGetNL( pStru, 4 ); p->lfWeight = ( LONG ) hb_arrayGetNL( pStru, 5 ); p->lfItalic = ( BYTE ) hb_arrayGetNI( pStru, 6 ); p->lfUnderline = ( BYTE ) hb_arrayGetNI( pStru, 7 ); p->lfStrikeOut = ( BYTE ) hb_arrayGetNI( pStru, 8 ); p->lfCharSet = ( BYTE ) hb_arrayGetNI( pStru, 9 ); p->lfOutPrecision = ( BYTE ) hb_arrayGetNI( pStru, 10 ); p->lfClipPrecision = ( BYTE ) hb_arrayGetNI( pStru, 11 ); p->lfQuality = ( BYTE ) hb_arrayGetNI( pStru, 12 ); p->lfPitchAndFamily = ( BYTE ) hb_arrayGetNI( pStru, 13 ); pfFaceName = HB_ARRAYGETSTR( pStru, 14, &hfFaceName, &nLen ); if( nLen > ( LF_FACESIZE - 1 ) ) nLen = LF_FACESIZE - 1; memcpy( p->lfFaceName, pfFaceName, nLen * sizeof( TCHAR ) ); p->lfFaceName[ nLen ] = TEXT( '\0' ); hb_strfree( hfFaceName ); return p; } else if( bMandatory ) return p; return NULL; }
/* Manager of signals for windows */ static LONG s_signalHandler( int type, int sig, PEXCEPTION_RECORD exc ) { HB_SIZE nPos; HB_UINT uiSig; /* let's find the right signal handler. */ hb_threadEnterCriticalSectionGC( &s_ServiceMutex ); /* avoid working if PRG signal handling has been disabled */ if( ! s_bSignalEnabled ) { hb_threadLeaveCriticalSection( &s_ServiceMutex ); return EXCEPTION_EXECUTE_HANDLER; } s_bSignalEnabled = HB_FALSE; nPos = hb_arrayLen( s_pHooks ); /* subsig not necessary */ uiSig = ( HB_UINT ) s_translateSignal( ( HB_UINT ) type, ( HB_UINT ) sig ); while( nPos > 0 ) { PHB_ITEM pFunction; HB_UINT uiMask; pFunction = hb_arrayGetItemPtr( s_pHooks, nPos ); uiMask = ( HB_UINT ) hb_arrayGetNI( pFunction, 1 ); if( ( uiMask & uiSig ) == uiSig ) { PHB_ITEM pExecArray, pRet; int iRet; /* we don't unlock the mutex now, even if it is a little dangerous. But we are in a signal hander... for now just 2 parameters */ pExecArray = hb_itemArrayNew( 3 ); hb_arraySetForward( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) ); hb_arraySetNI( pExecArray, 2, uiSig ); /* the third parameter is an array: * 1: low-level signal * 2: low-level subsignal * 3: low-level system error * 4: address that rose the signal * 5: process id of the signal riser * 6: UID of the riser */ pRet = hb_arrayGetItemPtr( pExecArray, 3 ); hb_arrayNew( pRet, 6 ); hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, type ); hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, sig ); /* could be meaningless, but does not matter here */ hb_arraySetNI( pRet, HB_SERVICE_OSERROR, GetLastError() ); if( type == 0 ) /* exception */ hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, ( void * ) exc->ExceptionAddress ); else hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, NULL ); /* TODO: */ hb_arraySetNI( pRet, HB_SERVICE_PROCESS, GetCurrentThreadId() ); /* TODO: */ hb_arraySetNI( pRet, HB_SERVICE_UID, 0 ); pRet = hb_itemDo( pExecArray, 0 ); iRet = hb_itemGetNI( pRet ); hb_itemRelease( pRet ); hb_itemRelease( pExecArray ); switch( iRet ) { case HB_SERVICE_HANDLED: s_bSignalEnabled = HB_TRUE; hb_threadLeaveCriticalSection( &s_ServiceMutex ); return EXCEPTION_CONTINUE_EXECUTION; case HB_SERVICE_QUIT: s_bSignalEnabled = HB_FALSE; hb_threadLeaveCriticalSection( &s_ServiceMutex ); hb_vmRequestQuit(); #ifndef HB_THREAD_SUPPORT hb_vmQuit(); exit( 0 ); #else hb_threadCancelInternal(); #endif } } nPos--; } s_bSignalEnabled = HB_TRUE; return EXCEPTION_EXECUTE_HANDLER; }
static void s_signalHandler( int sig, siginfo_t * info, void * v ) #endif { HB_UINT uiSig; HB_SIZE nPos; #if ! ( defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) ) HB_SYMBOL_UNUSED( v ); #endif /* let's find the right signal handler. */ hb_threadEnterCriticalSectionGC( &s_ServiceMutex ); /* avoid working if PRG signal handling has been disabled */ if( ! s_bSignalEnabled ) { hb_threadLeaveCriticalSection( &s_ServiceMutex ); return; } s_bSignalEnabled = HB_FALSE; nPos = hb_arrayLen( s_pHooks ); /* subsig not necessary */ uiSig = ( HB_UINT ) s_translateSignal( ( HB_UINT ) sig, 0 ); while( nPos > 0 ) { PHB_ITEM pFunction; HB_UINT uiMask; pFunction = hb_arrayGetItemPtr( s_pHooks, nPos ); uiMask = ( HB_UINT ) hb_arrayGetNI( pFunction, 1 ); if( uiMask & uiSig ) { PHB_ITEM pExecArray, pRet; int iRet; /* we don't unlock the mutex now, even if it is a little dangerous. But we are in a signal hander... for now just 2 parameters */ pExecArray = hb_itemArrayNew( 3 ); hb_arraySet( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) ); hb_arraySetNI( pExecArray, 2, uiSig ); /* the third parameter is an array: */ pRet = hb_arrayGetItemPtr( pExecArray, 3 ); #if defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) hb_arrayNew( pRet, 1 ); #elif defined( HB_OS_BSD ) hb_arrayNew( pRet, info ? 6 : 1 ); #else hb_arrayNew( pRet, 6 ); #endif hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, sig ); #if ! ( defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ ) ) #if defined( HB_OS_BSD ) if( info ) #endif { hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, info->si_code ); #if ! defined( HB_OS_VXWORKS ) hb_arraySetNI( pRet, HB_SERVICE_OSERROR, info->si_errno ); hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, ( void * ) info->si_addr ); hb_arraySetNI( pRet, HB_SERVICE_PROCESS, info->si_pid ); hb_arraySetNI( pRet, HB_SERVICE_UID, info->si_uid ); #endif } #endif pRet = hb_itemDo( pExecArray, 0 ); iRet = hb_itemGetNI( pRet ); hb_itemRelease( pRet ); hb_itemRelease( pExecArray ); switch( iRet ) { case HB_SERVICE_HANDLED: s_bSignalEnabled = HB_TRUE; hb_threadLeaveCriticalSection( &s_ServiceMutex ); return; case HB_SERVICE_QUIT: s_bSignalEnabled = HB_FALSE; hb_threadLeaveCriticalSection( &s_ServiceMutex ); /* TODO: A service cleanup routine */ hb_vmRequestQuit(); /* Allow signals to go through pthreads */ s_serviceSetDflSig(); /* NOTICE: should be pthread_exit(0), but a bug in Linux threading prevents it: calling pthread exit from a signal handler will cause infinite wait for restart signal. This solution is rude, while the other would allow clean VM termination... but it works. */ exit( 0 ); } } nPos--; } s_bSignalEnabled = HB_TRUE; #if 0 s_serviceSetHBSig(); #endif #if 0 if( uiSig != HB_SIGNAL_UNKNOWN ) { if( s_aOldAction[ sig ].sa_flags & SA_SIGINFO ) s_aOldAction[ sig ].sa_sigaction( sig, info, v ); else s_aOldAction[ sig ].sa_handler( sig ); } #endif }