diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c3529cf224..8d10b42fdd 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,77 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-07-22 11:48 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * contrib/xhb/xhbfunc.c + + Added HB_F_EOF() xhb compatibility function. + + * contrib/hbssl/Makefile + - contrib/hbssl/sslx509.c + + contrib/hbssl/x509.c + - contrib/hbssl/sslrand.c + + contrib/hbssl/rand.c + - contrib/hbssl/sslbio.c + + contrib/hbssl/bio.c + - contrib/hbssl/sslerr.c + + contrib/hbssl/err.c + * Renamed a few source files. + * SSL_RAND_*() functions renamed to RAND_*() to have + the exact same name as in OpenSSL. + * contrib/hbssl/tests/test.prg + + * contrib/hbssl/Makefile + * contrib/hbssl/bio.c + + contrib/hbssl/tests/bio.prg + * contrib/hbssl/hbssl.ch + + Added lots of new BIO functions: + BIO_NEW() + BIO_SET() + BIO_CLEAR_FLAGS() + BIO_SET_FLAGS() + BIO_GET_FLAGS() + BIO_TEST_FLAGS() + BIO_SET_FD() + BIO_GET_FD() + BIO_GET_RETRY_REASON() + BIO_SET_RETRY_SPECIAL() + BIO_SET_RETRY_READ() + BIO_SET_RETRY_WRITE() + BIO_SHOULD_READ() + BIO_SHOULD_WRITE() + BIO_SHOULD_IO_SPECIAL() + BIO_RETRY_TYPE() + BIO_SHOULD_RETRY() + BIO_CTRL_PENDING() + BIO_CTRL_WPENDING() + BIO_FLUSH() + BIO_SEEK() + BIO_TELL() + BIO_RESET() + BIO_EOF() + BIO_SET_CLOSE() + BIO_GET_CLOSE() + BIO_NEW_FILE() + BIO_NEW_MEM_BUF() + BIO_READ() + BIO_GETS() + BIO_WRITE() + BIO_PUTS() + BIO_VFREE() + BIO_FREE_ALL() + BIO_NEW_CONNECT() + BIO_NEW_ACCEPT() + BIO_SET_CONN_HOSTNAME() + BIO_SET_CONN_PORT() + BIO_SET_CONN_INT_PORT() + BIO_SET_CONN_IP() + BIO_GET_CONN_HOSTNAME() + BIO_GET_CONN_PORT() + BIO_GET_CONN_IP() + BIO_GET_CONN_INT_PORT() + BIO_SET_NBIO() + BIO_DO_CONNECT() + ERR_LOAD_BIO_STRINGS() + 2009-07-22 01:00 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * config/instsh.cf * config/dirsh.cf diff --git a/harbour/contrib/hbssl/Makefile b/harbour/contrib/hbssl/Makefile index 87200f0068..6a5416ed2d 100644 --- a/harbour/contrib/hbssl/Makefile +++ b/harbour/contrib/hbssl/Makefile @@ -27,19 +27,19 @@ HB_USER_CFLAGS += $(foreach d, $(HB_INC_OPENSSL_OK), -I$(d)) C_SOURCES=\ hbssl.c \ + bio.c \ + err.c \ evp.c \ evpciph.c \ evpenc.c \ evpmd.c \ evppkey.c \ + rand.c \ ssl.c \ - sslbio.c \ sslciph.c \ sslctx.c \ - sslerr.c \ - sslrand.c \ sslsess.c \ - sslx509.c \ + x509.c \ PRG_HEADERS=\ hbssl.ch \ diff --git a/harbour/contrib/hbssl/bio.c b/harbour/contrib/hbssl/bio.c new file mode 100644 index 0000000000..021978d9f7 --- /dev/null +++ b/harbour/contrib/hbssl/bio.c @@ -0,0 +1,724 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * OpenSSL API (BIO) - Harbour interface. + * + * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.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. 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. + * + */ + +#include "hbapi.h" +#include "hbapierr.h" + +#include "hbssl.h" + +void * hb_BIO_is( int iParam ) +{ + return hb_parptr( iParam ); +} + +BIO * hb_BIO_par( int iParam ) +{ + return ( BIO * ) hb_parptr( iParam ); +} + +static int hb_BIO_METHOD_is( int iParam ) +{ + return HB_ISCHAR( iParam ); +} + +static BIO_METHOD * hb_BIO_METHOD_par( int iParam ) +{ + BIO_METHOD * method; + + switch( hb_parni( iParam ) ) + { + case HB_BIO_METHOD_S_NULL : method = BIO_s_null(); break; +#ifndef OPENSSL_NO_FP_API + case HB_BIO_METHOD_S_FILE : method = BIO_s_file(); break; +#endif + case HB_BIO_METHOD_S_MEM : method = BIO_s_mem(); break; + case HB_BIO_METHOD_S_SOCKET : method = BIO_s_socket(); break; + case HB_BIO_METHOD_S_CONNECT : method = BIO_s_connect(); break; + case HB_BIO_METHOD_S_ACCEPT : method = BIO_s_accept(); break; + case HB_BIO_METHOD_S_FD : method = BIO_s_fd(); break; +#ifndef OPENSSL_SYS_OS2 + case HB_BIO_METHOD_S_LOG : method = BIO_s_log(); break; +#endif + case HB_BIO_METHOD_S_BIO : method = BIO_s_bio(); break; +#ifndef OPENSSL_NO_DGRAM + case HB_BIO_METHOD_S_DATAGRAM : method = BIO_s_datagram(); break; +#endif + case HB_BIO_METHOD_F_NULL : method = BIO_f_null(); break; + case HB_BIO_METHOD_F_BUFFER : method = BIO_f_buffer(); break; +#ifdef OPENSSL_SYS_VMS + case HB_BIO_METHOD_F_LINEBUFFER : method = BIO_f_linebuffer(); break; +#endif + case HB_BIO_METHOD_F_NBIO_TEST : method = BIO_f_nbio_test(); break; + default : method = NULL; + } + + return method; +} + +#if 0 +/* NOTE: Unused yet. Commented to avoid warning */ +static int hb_BIO_METHOD_ptr_to_id( const BIO_METHOD * method ) +{ + int n; + + if( method == BIO_s_null() ) n = HB_BIO_METHOD_S_NULL; +#ifndef OPENSSL_NO_FP_API + else if( method == BIO_s_file() ) n = HB_BIO_METHOD_S_FILE; +#endif + else if( method == BIO_s_mem() ) n = HB_BIO_METHOD_S_MEM; + else if( method == BIO_s_socket() ) n = HB_BIO_METHOD_S_SOCKET; + else if( method == BIO_s_connect() ) n = HB_BIO_METHOD_S_CONNECT; + else if( method == BIO_s_accept() ) n = HB_BIO_METHOD_S_ACCEPT; + else if( method == BIO_s_fd() ) n = HB_BIO_METHOD_S_FD; +#ifndef OPENSSL_SYS_OS2 + else if( method == BIO_s_log() ) n = HB_BIO_METHOD_S_LOG; +#endif + else if( method == BIO_s_bio() ) n = HB_BIO_METHOD_S_BIO; +#ifndef OPENSSL_NO_DGRAM + else if( method == BIO_s_datagram() ) n = HB_BIO_METHOD_S_DATAGRAM; +#endif + else if( method == BIO_f_null() ) n = HB_BIO_METHOD_F_NULL; + else if( method == BIO_f_buffer() ) n = HB_BIO_METHOD_F_BUFFER; +#ifdef OPENSSL_SYS_VMS + else if( method == BIO_f_linebuffer() ) n = HB_BIO_METHOD_F_LINEBUFFER; +#endif + else if( method == BIO_f_nbio_test() ) n = HB_BIO_METHOD_F_NBIO_TEST; + else n = HB_BIO_METHOD_UNSUPPORTED; + + return n; +} +#endif + +HB_FUNC( BIO_NEW ) +{ + if( hb_BIO_METHOD_is( 1 ) ) + hb_retptr( BIO_new( hb_BIO_METHOD_par( 1 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio && hb_BIO_METHOD_is( 2 ) ) + hb_retni( BIO_set( bio, hb_BIO_METHOD_par( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_CLEAR_FLAGS ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + BIO_clear_flags( bio, hb_parni( 2 ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_FLAGS ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + BIO_set_flags( bio, hb_parni( 2 ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_GET_FLAGS ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_get_flags( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_TEST_FLAGS ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_test_flags( bio, hb_parni( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_FD ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_set_fd( bio, hb_parnl( 2 ), HB_ISNUM( 3 ) ? hb_parni( 3 ) : BIO_NOCLOSE ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_GET_FD ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retnl( BIO_get_fd( bio, NULL ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_GET_RETRY_REASON ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_get_retry_reason( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_RETRY_SPECIAL ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + BIO_set_retry_special( bio ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_RETRY_READ ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + BIO_set_retry_read( bio ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_RETRY_WRITE ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + BIO_set_retry_write( bio ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SHOULD_READ ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_should_read( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SHOULD_WRITE ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_should_write( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SHOULD_IO_SPECIAL ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_should_io_special( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_RETRY_TYPE ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_retry_type( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SHOULD_RETRY ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_should_retry( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_CTRL_PENDING ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retnint( BIO_ctrl_pending( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_CTRL_WPENDING ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retnint( BIO_ctrl_wpending( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_FLUSH ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_flush( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SEEK ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retnl( BIO_seek( bio, hb_parnl( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_TELL ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retnl( BIO_tell( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_RESET ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_reset( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_EOF ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_eof( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_CLOSE ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_set_close( bio, HB_ISNUM( 2 ) ? hb_parni( 2 ) : BIO_NOCLOSE ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_GET_CLOSE ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_get_close( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_NEW_SOCKET ) +{ + if( HB_ISNUM( 1 ) ) + hb_retptr( BIO_new_socket( hb_parni( 1 ), HB_ISNUM( 2 ) ? hb_parni( 2 ) : BIO_NOCLOSE ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_NEW_DGRAM ) +{ + if( HB_ISNUM( 1 ) ) + hb_retptr( BIO_new_dgram( hb_parni( 1 ), HB_ISNUM( 2 ) ? hb_parni( 2 ) : BIO_NOCLOSE ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_NEW_FD ) +{ + if( HB_ISNUM( 1 ) ) + hb_retptr( BIO_new_fd( hb_parnl( 1 ), HB_ISNUM( 2 ) ? hb_parni( 2 ) : BIO_NOCLOSE ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_NEW_FILE ) +{ + if( HB_ISCHAR( 1 ) ) + hb_retptr( BIO_new_file( hb_parc( 1 ), hb_parcx( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_NEW_MEM_BUF ) +{ + if( HB_ISCHAR( 1 ) ) + /* NOTE: Discarding 'const' */ + hb_retptr( BIO_new_mem_buf( ( char * ) hb_parc( 1 ), hb_parclen( 1 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_READ ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + { + int size = HB_ISNUM( 3 ) ? hb_parni( 3 ) : ( int ) hb_parclen( 2 ); + + if( size > 0 ) + { + char * buffer = ( char * ) hb_xgrab( size ); + + hb_retni( size = BIO_read( bio, buffer, size ) ); + + if( ! hb_storclen( buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + { + hb_retni( 0 ); + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_GETS ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + { + int size = HB_ISNUM( 3 ) ? hb_parni( 3 ) : ( int ) hb_parclen( 2 ); + + if( size > 0 ) + { + char * buffer = ( char * ) hb_xgrab( size ); + + hb_retni( size = BIO_gets( bio, buffer, size ) ); + + if( ! hb_storclen( buffer, size, 2 ) ) + hb_xfree( buffer ); + } + else + { + hb_retni( 0 ); + hb_storc( NULL, 2 ); + } + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_WRITE ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + { + int size = ( int ) hb_parclen( 2 ); + + if( HB_ISNUM( 3 ) ) + { + int towrite = hb_parni( 3 ); + if( towrite >= 0 && towrite < size ) + size = towrite; + } + + hb_retni( BIO_write( bio, hb_parcx( 2 ), size ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_PUTS ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_puts( bio, hb_parcx( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_VFREE ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + BIO_vfree( bio ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_FREE ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_free( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_FREE_ALL ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + BIO_free_all( bio ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +/* ------------ connect ------------ */ + +HB_FUNC( BIO_NEW_CONNECT ) +{ + if( HB_ISCHAR( 1 ) ) + /* NOTE: Discarding 'const' */ + hb_retptr( BIO_new_connect( ( char * ) hb_parc( 1 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_NEW_ACCEPT ) +{ + if( HB_ISCHAR( 1 ) ) + /* NOTE: Discarding 'const' */ + hb_retptr( BIO_new_accept( ( char * ) hb_parc( 1 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_CONN_HOSTNAME ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio && HB_ISCHAR( 2 ) ) + hb_retnl( BIO_set_conn_hostname( bio, hb_parc( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_CONN_PORT ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio && HB_ISCHAR( 2 ) ) + hb_retnl( BIO_set_conn_port( bio, hb_parc( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_CONN_INT_PORT ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio && HB_ISNUM( 2 ) ) + { + int port = hb_parni( 2 ); + hb_retnl( BIO_set_conn_port( bio, &port ) ); + } + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_SET_CONN_IP ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio && HB_ISCHAR( 2 ) && hb_parclen( 2 ) == 4 ) + hb_retnl( BIO_set_conn_ip( bio, hb_parc( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_GET_CONN_HOSTNAME ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retc( BIO_get_conn_hostname( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_GET_CONN_PORT ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retc( BIO_get_conn_port( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_GET_CONN_IP ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retc( BIO_get_conn_ip( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +#if 0 +/* Commented due to bugs in OpenSSL declaration. Bug report sent. */ +HB_FUNC( BIO_GET_CONN_INT_PORT ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retnl( BIO_get_conn_int_port( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} +#endif + +HB_FUNC( BIO_SET_NBIO ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retnl( BIO_set_nbio( bio, hb_parni( 2 ) ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( BIO_DO_CONNECT ) +{ + BIO * bio = hb_BIO_par( 1 ); + + if( bio ) + hb_retni( BIO_do_connect( bio ) ); + else + hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + +HB_FUNC( ERR_LOAD_BIO_STRINGS ) +{ + ERR_load_BIO_strings(); +} + +#if 0 + +#define BIO_set_url(b,url) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,0,(char *)(url)) +#define BIO_set_proxies(b,p) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,1,(char *)(p)) +/* BIO_set_nbio(b,n) */ +#define BIO_set_filter_bio(b,s) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,2,(char *)(s)) +/* BIO *BIO_get_filter_bio(BIO *bio); */ +#define BIO_set_proxy_cb(b,cb) BIO_callback_ctrl(b,BIO_C_SET_PROXY_PARAM,3,(void *(*cb)())) +#define BIO_set_proxy_header(b,sk) BIO_ctrl(b,BIO_C_SET_PROXY_PARAM,4,(char *)sk) +#define BIO_set_no_connect_return(b,bool) BIO_int_ctrl(b,BIO_C_SET_PROXY_PARAM,5,bool) + +#define BIO_get_proxy_header(b,skp) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,0,(char *)skp) +#define BIO_get_proxies(b,pxy_p) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,1,(char *)(pxy_p)) +#define BIO_get_url(b,url) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,2,(char *)(url)) +#define BIO_get_no_connect_return(b) BIO_ctrl(b,BIO_C_GET_PROXY_PARAM,5,NULL) + +#define BIO_set_fp(b,fp,c) BIO_ctrl(b,BIO_C_SET_FILE_PTR,c,(char *)fp) +#define BIO_get_fp(b,fpp) BIO_ctrl(b,BIO_C_GET_FILE_PTR,0,(char *)fpp) + +int BIO_indent(BIO *b,int indent,int max); +long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); +long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)); +char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); +long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg); +BIO * BIO_push(BIO *b,BIO *append); +BIO * BIO_pop(BIO *b); +BIO * BIO_find_type(BIO *b,int bio_type); +BIO * BIO_next(BIO *b); +BIO * BIO_get_retry_BIO(BIO *bio, int *reason); +BIO * BIO_dup_chain(BIO *in); + +int BIO_nread0(BIO *bio, char **buf); +int BIO_nread(BIO *bio, char **buf, int num); +int BIO_nwrite0(BIO *bio, char **buf); +int BIO_nwrite(BIO *bio, char **buf, int num); + +BIO *BIO_new_mem_buf(void *buf, int len); + +#endif diff --git a/harbour/contrib/hbssl/sslerr.c b/harbour/contrib/hbssl/err.c similarity index 100% rename from harbour/contrib/hbssl/sslerr.c rename to harbour/contrib/hbssl/err.c diff --git a/harbour/contrib/hbssl/hbssl.ch b/harbour/contrib/hbssl/hbssl.ch index 0733ca074c..30b094dccb 100644 --- a/harbour/contrib/hbssl/hbssl.ch +++ b/harbour/contrib/hbssl/hbssl.ch @@ -174,7 +174,7 @@ #define HB_X509_V_ERR_UNNESTED_RESOURCE 44 #define HB_X509_V_ERR_APPLICATION_VERIFICATION 50 -#define HB_EVP_MD_UNSUPPORTED -1 +#define HB_EVP_MD_UNSUPPORTED ( -1 ) #define HB_EVP_MD_MD_NULL 0 #define HB_EVP_MD_MD2 1 #define HB_EVP_MD_MD4 2 @@ -191,7 +191,7 @@ #define HB_EVP_MD_MDC2 13 #define HB_EVP_MD_RIPEMD160 14 -#define HB_EVP_CIPHER_UNSUPPORTED -1 +#define HB_EVP_CIPHER_UNSUPPORTED ( -1 ) #define HB_EVP_CIPHER_ENC_NULL 0 #define HB_EVP_CIPHER_DES_ECB 1 #define HB_EVP_CIPHER_DES_EDE 2 @@ -292,4 +292,20 @@ #define HB_EVP_CIPHER_SEED_CFB 97 #define HB_EVP_CIPHER_SEED_OFB 98 +#define HB_BIO_METHOD_UNSUPPORTED ( -1 ) +#define HB_BIO_METHOD_S_NULL 0 +#define HB_BIO_METHOD_S_FILE 1 +#define HB_BIO_METHOD_S_MEM 2 +#define HB_BIO_METHOD_S_SOCKET 3 +#define HB_BIO_METHOD_S_CONNECT 4 +#define HB_BIO_METHOD_S_ACCEPT 5 +#define HB_BIO_METHOD_S_FD 6 +#define HB_BIO_METHOD_S_LOG 7 +#define HB_BIO_METHOD_S_BIO 8 +#define HB_BIO_METHOD_S_DATAGRAM 10 +#define HB_BIO_METHOD_F_NULL 50 +#define HB_BIO_METHOD_F_BUFFER 51 +#define HB_BIO_METHOD_F_LINEBUFFER 52 +#define HB_BIO_METHOD_F_NBIO_TEST 53 + #endif /* HBSSL_CH_ */ diff --git a/harbour/contrib/hbssl/sslrand.c b/harbour/contrib/hbssl/rand.c similarity index 95% rename from harbour/contrib/hbssl/sslrand.c rename to harbour/contrib/hbssl/rand.c index b2a9d13b7b..5a2ed2f465 100644 --- a/harbour/contrib/hbssl/sslrand.c +++ b/harbour/contrib/hbssl/rand.c @@ -55,22 +55,22 @@ #include -HB_FUNC( SSL_RAND_SEED ) +HB_FUNC( RAND_SEED ) { RAND_seed( hb_parcx( 1 ), hb_parclen( 1 ) ); } -HB_FUNC( SSL_RAND_ADD ) +HB_FUNC( RAND_ADD ) { RAND_add( hb_parcx( 1 ), hb_parclen( 1 ), hb_parnd( 2 ) ); } -HB_FUNC( SSL_RAND_STATUS ) +HB_FUNC( RAND_STATUS ) { hb_retni( RAND_status() ); } -HB_FUNC( SSL_RAND_EVENT ) +HB_FUNC( RAND_EVENT ) { #if defined( HB_OS_WIN ) && ! defined( __CYGWIN__ ) hb_retni( RAND_event( hb_parni( 1 ), ( WPARAM ) hb_parnint( 2 ), ( LPARAM ) hb_parnint( 3 ) ) ); @@ -79,7 +79,7 @@ HB_FUNC( SSL_RAND_EVENT ) #endif } -HB_FUNC( SSL_RAND_SCREEN ) +HB_FUNC( RAND_SCREEN ) { #if defined( HB_OS_WIN ) && ! defined( __CYGWIN__ ) RAND_screen(); diff --git a/harbour/contrib/hbssl/sslbio.c b/harbour/contrib/hbssl/sslbio.c deleted file mode 100644 index 4a90fa35bc..0000000000 --- a/harbour/contrib/hbssl/sslbio.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * OpenSSL API (BIO) - Harbour interface. - * - * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu) - * www - http://www.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. 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. - * - */ - -#include "hbapi.h" -#include "hbapierr.h" - -#include "hbssl.h" - -void * hb_BIO_is( int iParam ) -{ - return hb_parptr( iParam ); -} - -BIO * hb_BIO_par( int iParam ) -{ - return ( BIO * ) hb_parptr( iParam ); -} - -HB_FUNC( BIO_NEW_SOCKET ) -{ - if( HB_ISNUM( 1 ) ) - hb_retptr( BIO_new_socket( hb_parni( 1 ), HB_ISNUM( 2 ) ? hb_parni( 2 ) : BIO_NOCLOSE ) ); - else - hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); -} - -HB_FUNC( BIO_NEW_DGRAM ) -{ - if( HB_ISNUM( 1 ) ) - hb_retptr( BIO_new_dgram( hb_parni( 1 ), HB_ISNUM( 2 ) ? hb_parni( 2 ) : BIO_NOCLOSE ) ); - else - hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); -} - -HB_FUNC( BIO_NEW_FD ) -{ - if( HB_ISNUM( 1 ) ) - hb_retptr( BIO_new_fd( hb_parni( 1 ), HB_ISNUM( 2 ) ? hb_parni( 2 ) : BIO_NOCLOSE ) ); - else - hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); -} - -HB_FUNC( BIO_FREE ) -{ - BIO * bio = hb_BIO_par( 1 ); - - if( bio ) - hb_retni( BIO_free( bio ) ); - else - hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); -} diff --git a/harbour/contrib/hbssl/tests/bio.prg b/harbour/contrib/hbssl/tests/bio.prg new file mode 100644 index 0000000000..4c178bd514 --- /dev/null +++ b/harbour/contrib/hbssl/tests/bio.prg @@ -0,0 +1,28 @@ +/* + * $Id$ + */ + +/* + * Copyright 2009 Viktor Szakats (harbour.01 syenar.hu) + * www - http://www.harbour-project.org + */ + +#include "simpleio.ch" + +#include "hbssl.ch" + +PROCEDURE Main() + + LOCAL bio + + ? bio := BIO_new_fd( 1, HB_BIO_NOCLOSE ) + ? "BIO_WRITE", BIO_write( bio, "Hello world!" + hb_osNewLine() ) + ? "BIO_FLUSH", BIO_flush( bio ) + ? "BIO_FREE", BIO_free( bio ) + + ? bio := BIO_new_file( "bio_test.txt", "a+" ) + ? "BIO_WRITE", BIO_write( bio, "Hello world!" + hb_osNewLine() ) + ? "BIO_FLUSH", BIO_flush( bio ) + ? "BIO_FREE", BIO_free( bio ) + + RETURN diff --git a/harbour/contrib/hbssl/tests/test.prg b/harbour/contrib/hbssl/tests/test.prg index bde0fb7f44..40c71c60ae 100644 --- a/harbour/contrib/hbssl/tests/test.prg +++ b/harbour/contrib/hbssl/tests/test.prg @@ -59,7 +59,7 @@ PROCEDURE Main() ? SSLEAY_VERSION( HB_SSLEAY_PLATFORM ) ? SSLEAY_VERSION( HB_SSLEAY_DIR ) - ? "SSL_RAND_SEED", SSL_RAND_seed( "some entropy" ) + ? "RAND_SEED", RAND_seed( "some entropy" ) ? "SSL_CTX_NEW", ssl_ctx := SSL_CTX_NEW() diff --git a/harbour/contrib/hbssl/sslx509.c b/harbour/contrib/hbssl/x509.c similarity index 100% rename from harbour/contrib/hbssl/sslx509.c rename to harbour/contrib/hbssl/x509.c diff --git a/harbour/contrib/xhb/xhbfunc.c b/harbour/contrib/xhb/xhbfunc.c index fa6e5dfec2..f7dffa8eb2 100644 --- a/harbour/contrib/xhb/xhbfunc.c +++ b/harbour/contrib/xhb/xhbfunc.c @@ -51,6 +51,7 @@ */ #include "hbapi.h" +#include "hbapifs.h" #include "hbapigt.h" #include "hbapiitm.h" #include "hbapigt.h" @@ -200,6 +201,21 @@ HB_FUNC( HB_CHECKSUM ) HB_FUNC_EXEC( HB_ADLER32 ); } +HB_FUNC( HB_F_EOF ) +{ + USHORT uiError = 6; + + if( HB_ISNUM( 1 ) ) + { + hb_retl( hb_fsEof( hb_numToHandle( hb_parnint( 1 ) ) ) ); + uiError = hb_fsError(); + } + else + { + hb_retl( TRUE ); + } + hb_fsSetFError( uiError ); +} HB_FUNC_EXTERN( HB_CSTR );