From 05bbf52617ffe3c5611c856167a68792c85f4f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Wed, 13 Jan 2016 11:08:23 +0100 Subject: [PATCH] 2016-01-13 11:08 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/hbsocket.h * src/rtl/hbsockhb.c + added new C function: HB_BOOL hb_sockexItemReplace( PHB_ITEM pItem, PHB_SOCKEX pSock ); * contrib/hbssl/ssl_sock.c + replace passed socket structure to hb_socketNewSSL_connect() and hb_socketNewSSL_accept() with new one using SSL filter if it was passed by reference, current syntax is: hb_socketNewSSL_connect( [@], [, ] ) -> hb_socketNewSSL_accept( [@], [, ] ) -> * contrib/hbssl/hbssl.hbm * contrib/hbssl/hbssl.hbx + contrib/hbssl/ssl_hbcon.prg + added new PRG functions which can be used for fast initialization of SSL connection: hb_SSL_new() -> hb_SSL_connect_inet( , [ ], [ @ ] ) -> hb_SSL_connect_socket( , [ ], [ @ ] ) -> They do not need any addiitonal initialization code and can be called as first and the only SSL functions in user code. * contrib/hbtip/mail.prg ! fixed bug reported by Lorenzo - thanks * use hb_MemoWrit() in :detachFile() to honor Harbour File IO API * cleanup * src/common/hbffind.c * src/rtl/gtos2/gtos2.c * src/rtl/hbproces.c * cleaned DosAllocMem() flags * src/common/hbfsapi.c * src/rtl/hbproces.c * pacified OS2 GCC warnings * config/global.mk * show information about HB_MT build parameter if set by user --- ChangeLog.txt | 45 ++++++++++++++++++ config/global.mk | 9 ++++ contrib/hbssl/hbssl.hbm | 2 + contrib/hbssl/hbssl.hbx | 3 ++ contrib/hbssl/ssl_hbcon.prg | 93 +++++++++++++++++++++++++++++++++++++ contrib/hbssl/ssl_sock.c | 15 ++++-- contrib/hbtip/mail.prg | 31 ++++--------- include/hbsocket.h | 1 + src/common/hbffind.c | 3 +- src/common/hbfsapi.c | 8 ++-- src/rtl/gtos2/gtos2.c | 2 +- src/rtl/hbproces.c | 9 ++-- src/rtl/hbsockhb.c | 14 ++++++ 13 files changed, 199 insertions(+), 36 deletions(-) create mode 100644 contrib/hbssl/ssl_hbcon.prg diff --git a/ChangeLog.txt b/ChangeLog.txt index 51d16bd46a..4e46fab5a5 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,51 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2016-01-13 11:08 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * include/hbsocket.h + * src/rtl/hbsockhb.c + + added new C function: + HB_BOOL hb_sockexItemReplace( PHB_ITEM pItem, PHB_SOCKEX pSock ); + + * contrib/hbssl/ssl_sock.c + + replace passed socket structure to hb_socketNewSSL_connect() and + hb_socketNewSSL_accept() with new one using SSL filter if it was + passed by reference, current syntax is: + hb_socketNewSSL_connect( [@], [, ] ) + -> + hb_socketNewSSL_accept( [@], [, ] ) + -> + + * contrib/hbssl/hbssl.hbm + * contrib/hbssl/hbssl.hbx + + contrib/hbssl/ssl_hbcon.prg + + added new PRG functions which can be used for fast initialization of + SSL connection: + hb_SSL_new() -> + hb_SSL_connect_inet( , [ ], [ @ ] ) + -> + hb_SSL_connect_socket( , [ ], [ @ ] ) + -> + They do not need any addiitonal initialization code and can be called + as first and the only SSL functions in user code. + + * contrib/hbtip/mail.prg + ! fixed bug reported by Lorenzo - thanks + * use hb_MemoWrit() in :detachFile() to honor Harbour File IO API + * cleanup + + * src/common/hbffind.c + * src/rtl/gtos2/gtos2.c + * src/rtl/hbproces.c + * cleaned DosAllocMem() flags + + * src/common/hbfsapi.c + * src/rtl/hbproces.c + * pacified OS2 GCC warnings + + * config/global.mk + * show information about HB_MT build parameter if set by user + 2016-01-12 21:13 UTC+0100 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * contrib/hbtip/encurlc.c ! fixed url decoding - thanks to Lorenzo for reporting the problem diff --git a/config/global.mk b/config/global.mk index 2ed9bcbde6..a1d0e65523 100644 --- a/config/global.mk +++ b/config/global.mk @@ -162,6 +162,12 @@ ifeq ($(HB_INIT_DONE),) $(warning ! Warning: HB_INSTALL_IMPLIB option has an effect only if 'install' is requested.) endif endif + + ifneq ($(HB_MT),) + ifeq ($(filter $(HB_MT),yes no),) + export HB_MT := + endif + endif endif # Make platform detection @@ -273,6 +279,9 @@ ifeq ($(HB_INIT_DONE),) ifneq ($(HB_INSTALL_IMPLIB),) $(info ! HB_INSTALL_IMPLIB: $(HB_INSTALL_IMPLIB)) endif + ifneq ($(HB_MT),) + $(info ! HB_MT: $(HB_MT)) + endif endif # Shell detection diff --git a/contrib/hbssl/hbssl.hbm b/contrib/hbssl/hbssl.hbm index d98d07d28d..756f03c2a4 100644 --- a/contrib/hbssl/hbssl.hbm +++ b/contrib/hbssl/hbssl.hbm @@ -38,6 +38,8 @@ hbssl.hbx +ssl_hbcon.prg + ssl_hb.c ssl_inet.c ssl_sock.c diff --git a/contrib/hbssl/hbssl.hbx b/contrib/hbssl/hbssl.hbx index 75ae9bb2dd..e998618dca 100644 --- a/contrib/hbssl/hbssl.hbx +++ b/contrib/hbssl/hbssl.hbx @@ -176,6 +176,9 @@ DYNAMIC hb_inetSSL_accept DYNAMIC hb_inetSSL_connect DYNAMIC hb_socketNewSSL_accept DYNAMIC hb_socketNewSSL_connect +DYNAMIC hb_SSL_connect_inet +DYNAMIC hb_SSL_connect_socket +DYNAMIC hb_SSL_new DYNAMIC hb_SSL_read_all DYNAMIC hb_SSL_read_line DYNAMIC OpenSSL_add_all_algorithms diff --git a/contrib/hbssl/ssl_hbcon.prg b/contrib/hbssl/ssl_hbcon.prg new file mode 100644 index 0000000000..42780978cf --- /dev/null +++ b/contrib/hbssl/ssl_hbcon.prg @@ -0,0 +1,93 @@ +/* + * Harbour Project source code: + * OpenSSL API (SSL) - Harbour extensions + * + * Copyright 2016 Przemyslaw Czerpak + * www - http://harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING.txt. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +/* hb_SSL_new() -> */ +FUNCTION hb_SSL_new() + + STATIC s_onceControl + + /* initialize SSL library */ + hb_threadOnce( @s_onceControl, {|| SSL_init(), ; + RAND_seed( hb_randStr( 20 ) + hb_TToS( hb_DateTime() ) ) } ) + + /* create a new SSL structure for a connection */ + RETURN SSL_new( SSL_CTX_new() ) + +/* hb_SSL_connect_socket( , [ ], [ @ ] ) -> */ +FUNCTION hb_SSL_connect_socket( pSocket, nTimeout, cInfo ) + + LOCAL nErr + LOCAL ssl + + ssl := hb_SSL_new() + IF !Empty( pSocket := hb_socketNewSSL_connect( @pSocket, ssl, nTimeout ) ) + cInfo := "SSL connected with " + SSL_get_cipher( ssl ) + " encryption." + RETURN .T. + ENDIF + + nErr := ERR_get_error() + cInfo := hb_StrFormat( "SSL connection error [%d] %s", ; + nErr, ERR_error_string( nErr ) ) + RETURN .F. + +/* hb_SSL_connect_inet( , [ ], [ @ ] ) -> */ +FUNCTION hb_SSL_connect_inet( pInetSock, nTimeout, cInfo ) + + LOCAL nResult, nErr + LOCAL ssl + + ssl := hb_SSL_new() + IF ( nResult := hb_inetSSL_CONNECT( pInetSock, ssl, nTimeout ) ) == 1 + cInfo := "SSL connected with " + SSL_get_cipher( ssl ) + " encryption." + RETURN .T. + ENDIF + + nErr := ERR_get_error() + cInfo := hb_StrFormat( "SSL connection error [%d:%d] %s", ; + nResult, nErr, ERR_error_string( nErr ) ) + RETURN .F. diff --git a/contrib/hbssl/ssl_sock.c b/contrib/hbssl/ssl_sock.c index 759161085a..0d3455d61d 100644 --- a/contrib/hbssl/ssl_sock.c +++ b/contrib/hbssl/ssl_sock.c @@ -568,19 +568,26 @@ static void s_sslSocketNew( HB_BOOL fServer ) if( pSock ) { - hb_socketItemClear( hb_param( 1, HB_IT_POINTER ) ); - hb_sockexItemPut( hb_param( -1, HB_IT_ANY ), 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 ); + } } } } -/* hb_socketNewSSL_connect( , [, ] ) */ +/* hb_socketNewSSL_connect( [@], [, ] ) */ HB_FUNC( HB_SOCKETNEWSSL_CONNECT ) { s_sslSocketNew( HB_FALSE ); } -/* hb_socketNewSSL_accept( , [, ] ) */ +/* hb_socketNewSSL_accept( [@], [, ] ) */ HB_FUNC( HB_SOCKETNEWSSL_ACCEPT ) { s_sslSocketNew( HB_TRUE ); diff --git a/contrib/hbtip/mail.prg b/contrib/hbtip/mail.prg index 724e423b4e..76b2b12614 100644 --- a/contrib/hbtip/mail.prg +++ b/contrib/hbtip/mail.prg @@ -619,23 +619,20 @@ METHOD setHeader( cSubject, cFrom, xTo, xCC, xBCC ) CLASS TIPMail METHOD attachFile( cFileName ) CLASS TIPMail LOCAL cContent := hb_MemoRead( cFileName ) - LOCAL cMimeType := tip_FileMimeType( cFileName ) - LOCAL cDelim := hb_ps() - + LOCAL cBaseName LOCAL oAttach - IF Empty( cContent ) + IF HB_ISNULL( cContent ) RETURN .F. ENDIF oAttach := TIPMail():new( cContent, "base64" ) - cFileName := SubStr( cFileName, RAt( cFileName, cDelim ) + 1 ) - - oAttach:setFieldPart( "Content-Type", cMimeType ) - oAttach:setFieldOption( "Content-Type", "name", cFileName ) + cBaseName := hb_FNameNameExt( cFileName ) + oAttach:setFieldPart( "Content-Type", tip_FileMimeType( cFileName ) ) + oAttach:setFieldOption( "Content-type", "name", cBaseName ) oAttach:setFieldPart( "Content-Disposition", "attachment" ) - oAttach:setFieldOption( "Content-Disposition", "filename", cFileName ) + oAttach:setFieldOption( "Content-Disposition", "filename", cBaseName ) RETURN ::attach( oAttach ) @@ -643,26 +640,16 @@ METHOD detachFile( cPath ) CLASS TIPMail LOCAL cContent := ::getBody() LOCAL cFileName := ::getFileName() - LOCAL cDelim := hb_ps() - LOCAL nFileHandle - IF Empty( cFileName ) + IF HB_ISNULL( cFileName ) RETURN .F. ENDIF IF HB_ISSTRING( cPath ) - cFileName := StrTran( cPath + cDelim + cFileName, cDelim + cDelim, cDelim ) + cFileName := hb_DirSepAdd( cPath ) + cFileName ENDIF - nFileHandle := FCreate( cFileName ) - IF FError() != 0 - RETURN .F. - ENDIF - - FWrite( nFileHandle, cContent ) - FClose( nFileHandle ) - - RETURN FError() == 0 + RETURN hb_MemoWrit( cFileName, cContent ) METHOD getFileName() CLASS TIPMail RETURN StrTran( ::getFieldOption( "Content-Type", "name" ), '"' ) diff --git a/include/hbsocket.h b/include/hbsocket.h index c918eacf65..7c2d9cf26c 100644 --- a/include/hbsocket.h +++ b/include/hbsocket.h @@ -199,6 +199,7 @@ extern HB_EXPORT PHB_SOCKEX hb_sockexParam( int iParam ); extern HB_EXPORT PHB_SOCKEX hb_sockexItemGet( PHB_ITEM pItem ); extern HB_EXPORT PHB_ITEM hb_sockexItemPut( PHB_ITEM pItem, PHB_SOCKEX pSock ); extern HB_EXPORT void hb_sockexItemClear( PHB_ITEM pItem ); +extern HB_EXPORT HB_BOOL hb_sockexItemReplace( PHB_ITEM pItem, PHB_SOCKEX pSock ); extern HB_EXPORT HB_BOOL hb_sockexItemSetFilter( PHB_ITEM pItem, const char * pszFilter, PHB_ITEM pParams ); HB_EXTERN_END diff --git a/src/common/hbffind.c b/src/common/hbffind.c index ab06e53fa7..e7eb45f422 100644 --- a/src/common/hbffind.c +++ b/src/common/hbffind.c @@ -515,7 +515,8 @@ static HB_BOOL hb_fsFindNextLow( PHB_FFIND ffind ) info->hFindFile = HDIR_CREATE; info->findCount = info->findInitCnt; - ret = DosAllocMem( &info->entry, info->findSize, OBJ_TILE | PAG_COMMIT | PAG_WRITE ); + ret = DosAllocMem( &info->entry, info->findSize, + PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE ); if( ret == NO_ERROR ) { ret = DosFindFirst( ( PCSZ ) ffind->pszFileMask, diff --git a/src/common/hbfsapi.c b/src/common/hbfsapi.c index 8922f1535b..8baa2e95fc 100644 --- a/src/common/hbfsapi.c +++ b/src/common/hbfsapi.c @@ -341,13 +341,13 @@ HB_BOOL hb_isWSeB( void ) ret = DosLoadModule( NULL, 0, ( PCSZ ) "DOSCALL1", &hModule ); #endif if( ret == NO_ERROR ) - ret = DosQueryProcAddr( hModule, 981, NULL, ( PFN * ) &s_DosOpenL ); + ret = DosQueryProcAddr( hModule, 981, NULL, ( PFN * ) ( void * ) &s_DosOpenL ); if( ret == NO_ERROR ) - ret = DosQueryProcAddr( hModule, 986, NULL, ( PFN * ) &s_DosSetFileLocksL ); + ret = DosQueryProcAddr( hModule, 986, NULL, ( PFN * ) ( void * ) &s_DosSetFileLocksL ); if( ret == NO_ERROR ) - ret = DosQueryProcAddr( hModule, 988, NULL, ( PFN * ) &s_DosSetFilePtrL ); + ret = DosQueryProcAddr( hModule, 988, NULL, ( PFN * ) ( void * ) &s_DosSetFilePtrL ); if( ret == NO_ERROR ) - ret = DosQueryProcAddr( hModule, 989, NULL, ( PFN * ) &s_DosSetFileSizeL ); + ret = DosQueryProcAddr( hModule, 989, NULL, ( PFN * ) ( void * ) &s_DosSetFileSizeL ); s_iWSeB = ret == NO_ERROR; } return s_iWSeB; diff --git a/src/rtl/gtos2/gtos2.c b/src/rtl/gtos2/gtos2.c index 27921ef261..3246d4dd84 100644 --- a/src/rtl/gtos2/gtos2.c +++ b/src/rtl/gtos2/gtos2.c @@ -594,7 +594,7 @@ static PVOID hb_gt_os2_allocMem( int iSize ) APIRET rc; /* return code from DosXXX api call */ PVOID pMem; - rc = DosAllocMem( &pMem, iSize, PAG_COMMIT | OBJ_TILE | PAG_WRITE ); + rc = DosAllocMem( &pMem, iSize, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE ); if( rc != NO_ERROR ) hb_errInternal( HB_EI_XGRABALLOC, "hb_gt_os2_allocMem() memory allocation failure.", NULL, NULL ); diff --git a/src/rtl/hbproces.c b/src/rtl/hbproces.c index 743e1f944f..32130ea3e4 100644 --- a/src/rtl/hbproces.c +++ b/src/rtl/hbproces.c @@ -101,8 +101,9 @@ static char * hb_buildArgsOS2( const char *pszFileName, APIRET * ret ) { PHB_FNAME pFilepath; char szFileBuf[ HB_PATH_MAX ]; - char * pArgs, * pszFree = NULL, cQuote = 0, c; + char * pArgs = NULL, * pszFree = NULL, cQuote = 0, c; HB_SIZE nLen = 0, nLen2; + void * pMem; while( HB_ISSPACE( *pszFileName ) ) ++pszFileName; @@ -145,15 +146,15 @@ static char * hb_buildArgsOS2( const char *pszFileName, APIRET * ret ) } hb_xfree( pFilepath ); - *ret = DosAllocMem( ( PPVOID ) &pArgs, nLen + nLen2 + 3, OBJ_TILE | PAG_COMMIT | PAG_WRITE ); + *ret = DosAllocMem( &pMem, nLen + nLen2 + 3, + PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE ); if( *ret == NO_ERROR ) { + pArgs = ( char * ) pMem; memcpy( pArgs, szFileBuf, nLen + 1 ); memcpy( pArgs + nLen + 1, pszFileName, nLen2 + 1 ); pArgs[ nLen + nLen2 + 2 ] = '\0'; } - else - pArgs = NULL; if( pszFree ) hb_xfree( pszFree ); diff --git a/src/rtl/hbsockhb.c b/src/rtl/hbsockhb.c index 7250a535d9..297fe8994e 100644 --- a/src/rtl/hbsockhb.c +++ b/src/rtl/hbsockhb.c @@ -446,6 +446,20 @@ void hb_sockexItemClear( PHB_ITEM pItem ) *pSockPtr = NULL; } +HB_BOOL hb_sockexItemReplace( PHB_ITEM pItem, PHB_SOCKEX pSock ) +{ + PHB_SOCKEX * pSockPtr = ( PHB_SOCKEX * ) hb_itemGetPtrGC( pItem, &s_gcSocketFuncs ); + + if( pSockPtr ) + { + if( *pSockPtr ) + hb_sockexClose( *pSockPtr, HB_FALSE ); + *pSockPtr = pSock; + return HB_TRUE; + } + return HB_FALSE; +} + HB_BOOL hb_sockexItemSetFilter( PHB_ITEM pItem, const char * pszFilter, PHB_ITEM pParams ) { PHB_SOCKEX * pSockPtr = ( PHB_SOCKEX * ) hb_itemGetPtrGC( pItem, &s_gcSocketFuncs );