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( [@]<pSocket>, <pSSL> [, <nTimeout> ] )
                     -> <pSocketSSL>
         hb_socketNewSSL_accept( [@]<pSocket>, <pSSL> [, <nTimeout> ] )
                     -> <pSocketSSL>

  * 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() -> <pSSL>
         hb_SSL_connect_inet( <pSocket>, [ <nTimeOut> ], [ @<cInfo> ] )
                     -> <lConnected>
         hb_SSL_connect_socket( <pSocket>, [ <nTimeOut> ], [ @<cInfo> ] )
                     -> <lConnected>
      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
This commit is contained in:
Przemysław Czerpak
2016-01-13 11:08:23 +01:00
parent 6be1156f7c
commit 05bbf52617
13 changed files with 199 additions and 36 deletions

View File

@@ -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( [@]<pSocket>, <pSSL> [, <nTimeout> ] )
-> <pSocketSSL>
hb_socketNewSSL_accept( [@]<pSocket>, <pSSL> [, <nTimeout> ] )
-> <pSocketSSL>
* 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() -> <pSSL>
hb_SSL_connect_inet( <pSocket>, [ <nTimeOut> ], [ @<cInfo> ] )
-> <lConnected>
hb_SSL_connect_socket( <pSocket>, [ <nTimeOut> ], [ @<cInfo> ] )
-> <lConnected>
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

View File

@@ -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

View File

@@ -38,6 +38,8 @@
hbssl.hbx
ssl_hbcon.prg
ssl_hb.c
ssl_inet.c
ssl_sock.c

View File

@@ -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

View File

@@ -0,0 +1,93 @@
/*
* Harbour Project source code:
* OpenSSL API (SSL) - Harbour extensions
*
* Copyright 2016 Przemyslaw Czerpak <druzus / at / priv.onet.pl>
* 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() -> <pSSL> */
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( <pSocket>, [ <nTimeOut> ], [ @<cInfo> ] ) -> <lConnected> */
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( <pSocket>, [ <nTimeOut> ], [ @<cInfo> ] ) -> <lConnected> */
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.

View File

@@ -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( <pSocket>, <pSSL> [, <nTimeout> ] ) */
/* hb_socketNewSSL_connect( [@]<pSocket>, <pSSL> [, <nTimeout> ] ) */
HB_FUNC( HB_SOCKETNEWSSL_CONNECT )
{
s_sslSocketNew( HB_FALSE );
}
/* hb_socketNewSSL_accept( <pSocket>, <pSSL> [, <nTimeout> ] ) */
/* hb_socketNewSSL_accept( [@]<pSocket>, <pSSL> [, <nTimeout> ] ) */
HB_FUNC( HB_SOCKETNEWSSL_ACCEPT )
{
s_sslSocketNew( HB_TRUE );

View File

@@ -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" ), '"' )

View File

@@ -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

View File

@@ -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,

View File

@@ -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;

View File

@@ -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 );

View File

@@ -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 );

View File

@@ -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 );