diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 01f8211d53..784dbd6390 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,28 @@ The license applies to all entries newer than 2009-04-28. */ +2011-01-11 23:06 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) + * contrib/hbmxml/tests/reminder.prg + * contrib/hbmxml/tests/test.prg + ! Fixed warnings and errors preventing these + tests from building. + + * contrib/hbexpat/hbexpat.c + * contrib/hbcurl/hbcurl.c + * contrib/hbssl/ssl.c + * contrib/hbssl/pem.c + + Added support also for function pointers where codeblocks + were accepted. Please test it. + NOTE: It was easy change because PHB_ITEM was already + used to store the callback value and official Eval API + was used to call the callbacks. + + * contrib/hbssl/tests/pem.prg + + Added example for function pointer callback. + + * contrib/hbssl/pem.c + % Minor optimization. + 2011-01-11 19:35 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbsqlit3/hbsqlit3.c + Switched to use codeblocks for callbacks (instead of function diff --git a/harbour/contrib/hbcurl/hbcurl.c b/harbour/contrib/hbcurl/hbcurl.c index 4801d9dcde..ccb24a03d0 100644 --- a/harbour/contrib/hbcurl/hbcurl.c +++ b/harbour/contrib/hbcurl/hbcurl.c @@ -116,7 +116,7 @@ typedef struct _HB_CURL size_t dl_len; size_t dl_pos; - PHB_ITEM pProgressBlock; + PHB_ITEM pProgressCallback; HB_HASH_TABLE_PTR pHash; @@ -519,10 +519,10 @@ static void PHB_CURL_free( PHB_CURL hb_curl, HB_BOOL bFree ) hb_curl_buff_ul_free( hb_curl ); hb_curl_buff_dl_free( hb_curl ); - if( hb_curl->pProgressBlock ) + if( hb_curl->pProgressCallback ) { - hb_itemRelease( hb_curl->pProgressBlock ); - hb_curl->pProgressBlock = NULL; + hb_itemRelease( hb_curl->pProgressCallback ); + hb_curl->pProgressCallback = NULL; } if( hb_curl->pHash ) @@ -586,8 +586,8 @@ static HB_GARBAGE_FUNC( PHB_CURL_mark ) { PHB_CURL hb_curl = * hb_curl_ptr; - if( hb_curl->pProgressBlock ) - hb_gcMark( hb_curl->pProgressBlock ); + if( hb_curl->pProgressCallback ) + hb_gcMark( hb_curl->pProgressCallback ); } } @@ -1589,25 +1589,25 @@ HB_FUNC( CURL_EASY_SETOPT ) case HB_CURLOPT_PROGRESSBLOCK: { - PHB_ITEM pProgressBlock = hb_param( 3, HB_IT_BLOCK ); + PHB_ITEM pProgressCallback = hb_param( 3, HB_IT_BLOCK | HB_IT_SYMBOL ); - if( hb_curl->pProgressBlock ) + if( hb_curl->pProgressCallback ) { curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSFUNCTION, NULL ); curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSDATA, NULL ); - hb_itemRelease( hb_curl->pProgressBlock ); - hb_curl->pProgressBlock = NULL; + hb_itemRelease( hb_curl->pProgressCallback ); + hb_curl->pProgressCallback = NULL; } - if( pProgressBlock ) + if( pProgressCallback ) { - hb_curl->pProgressBlock = hb_itemNew( pProgressBlock ); + hb_curl->pProgressCallback = hb_itemNew( pProgressCallback ); /* unlock the item so GC will not mark them as used */ - hb_gcUnlock( hb_curl->pProgressBlock ); + hb_gcUnlock( hb_curl->pProgressCallback ); curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSFUNCTION, hb_curl_progress_callback ); - res = curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSDATA, hb_curl->pProgressBlock ); + res = curl_easy_setopt( hb_curl->curl, CURLOPT_PROGRESSDATA, hb_curl->pProgressCallback ); } } break; diff --git a/harbour/contrib/hbexpat/hbexpat.c b/harbour/contrib/hbexpat/hbexpat.c index 2f654f253f..313aeefdcf 100644 --- a/harbour/contrib/hbexpat/hbexpat.c +++ b/harbour/contrib/hbexpat/hbexpat.c @@ -118,7 +118,7 @@ typedef struct _HB_EXPAT { \ PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 ); \ \ - hb_expat_setvar( hb_expat, _VAR_b##_name_, hb_param( 2, HB_IT_BLOCK ) ); \ + hb_expat_setvar( hb_expat, _VAR_b##_name_, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) ); \ \ XML_Set##_name_ ( hb_expat->parser, hb_expat->pVar[ _VAR_b##_name_ ] ? hb_expat_##_name_ : NULL ); \ \ @@ -854,8 +854,8 @@ HB_FUNC( XML_SETELEMENTHANDLER ) { PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 ); - hb_expat_setvar( hb_expat, _VAR_bStartElementHandler, hb_param( 2, HB_IT_BLOCK ) ); - hb_expat_setvar( hb_expat, _VAR_bEndElementHandler, hb_param( 3, HB_IT_BLOCK ) ); + hb_expat_setvar( hb_expat, _VAR_bStartElementHandler, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) ); + hb_expat_setvar( hb_expat, _VAR_bEndElementHandler, hb_param( 3, HB_IT_BLOCK | HB_IT_SYMBOL ) ); XML_SetElementHandler( hb_expat->parser, hb_expat->pVar[ _VAR_bStartElementHandler ] ? hb_expat_StartElementHandler : NULL, @@ -873,8 +873,8 @@ HB_FUNC( XML_SETCDATASECTIONHANDLER ) { PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 ); - hb_expat_setvar( hb_expat, _VAR_bStartCdataSectionHandler, hb_param( 2, HB_IT_BLOCK ) ); - hb_expat_setvar( hb_expat, _VAR_bEndCdataSectionHandler, hb_param( 3, HB_IT_BLOCK ) ); + hb_expat_setvar( hb_expat, _VAR_bStartCdataSectionHandler, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) ); + hb_expat_setvar( hb_expat, _VAR_bEndCdataSectionHandler, hb_param( 3, HB_IT_BLOCK | HB_IT_SYMBOL ) ); XML_SetCdataSectionHandler( hb_expat->parser, hb_expat->pVar[ _VAR_bStartCdataSectionHandler ] ? hb_expat_StartCdataSectionHandler : NULL, @@ -892,8 +892,8 @@ HB_FUNC( XML_SETNAMESPACEDECLHANDLER ) { PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 ); - hb_expat_setvar( hb_expat, _VAR_bStartNamespaceDeclHandler, hb_param( 2, HB_IT_BLOCK ) ); - hb_expat_setvar( hb_expat, _VAR_bEndNamespaceDeclHandler, hb_param( 3, HB_IT_BLOCK ) ); + hb_expat_setvar( hb_expat, _VAR_bStartNamespaceDeclHandler, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) ); + hb_expat_setvar( hb_expat, _VAR_bEndNamespaceDeclHandler, hb_param( 3, HB_IT_BLOCK | HB_IT_SYMBOL ) ); XML_SetNamespaceDeclHandler( hb_expat->parser, hb_expat->pVar[ _VAR_bStartNamespaceDeclHandler ] ? hb_expat_StartNamespaceDeclHandler : NULL, @@ -911,7 +911,7 @@ HB_FUNC( XML_SETUNKNOWNENCODINGHANDLER ) { PHB_EXPAT hb_expat = PHB_EXPAT_par( 1 ); - hb_expat_setvar( hb_expat, _VAR_bUnknownEncodingHandler, hb_param( 2, HB_IT_BLOCK ) ); + hb_expat_setvar( hb_expat, _VAR_bUnknownEncodingHandler, hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ) ); hb_expat_setvar( hb_expat, _VAR_xEncodingHandlerData, hb_param( 3, HB_IT_ANY ) ); XML_SetUnknownEncodingHandler( hb_expat->parser, diff --git a/harbour/contrib/hbmxml/tests/reminder.prg b/harbour/contrib/hbmxml/tests/reminder.prg index 6d814a663f..b2ab498a5b 100644 --- a/harbour/contrib/hbmxml/tests/reminder.prg +++ b/harbour/contrib/hbmxml/tests/reminder.prg @@ -13,7 +13,7 @@ PROCEDURE main() IF hb_fileExists( 'rem.xml' ) xml := simplexml_load_file( 'rem.xml' ) ELSE - RETURN -1 + RETURN ENDIF IF ! s_mxml_error @@ -27,6 +27,8 @@ PROCEDURE main() IF s_mxml_error OutErr( "hbmxml:", s_mxml_error_msg, hb_eol() ) + ELSE + OutStd( asXML( xml ), hb_eol() ) ENDIF ENDIF @@ -56,7 +58,7 @@ STATIC FUNCTION asXML( xml ) subnode := mxmlGetFirstChild( node ) DO WHILE ! Empty( subnode := mxmlGetNextSibling( subnode ) ) - IF mxmlGetType( subnode ) == MXML_ELEMENT + IF mxmlGetType( subnode ) == MXML_ELEMENT IF mxmlGetElement( subnode ) == "body" c := mxmlGetOpaque( subnode ) ELSE @@ -64,7 +66,7 @@ STATIC FUNCTION asXML( xml ) ENDIF cText += ( c + " " ) ENDIF - ENDDO + ENDDO RETURN cText @@ -74,7 +76,7 @@ FUNCTION type_cb( node ) LOCAL cType /* You can lookup attributes and/or use the element name, hierarchy, etc... */ - + IF Empty( cType := mxmlElementGetAttr( node, "type" ) ) cType := mxmlGetElement( node ) ENDIF diff --git a/harbour/contrib/hbmxml/tests/test.prg b/harbour/contrib/hbmxml/tests/test.prg index 542468a681..68dc7ce0ea 100644 --- a/harbour/contrib/hbmxml/tests/test.prg +++ b/harbour/contrib/hbmxml/tests/test.prg @@ -5,17 +5,19 @@ #include "hbmxml.ch" #include "hbinkey.ch" -STATIC event_counts +STATIC s_event_counts FUNCTION main( cFile ) LOCAL tree LOCAL node, tmpnode LOCAL index - LOCAL nType, nLen, nFile + LOCAL nType LOCAL cBuffer LOCAL whitespace := 1 + LOCAL i + OutStd( hb_mxmlVersion(), hb_eol() ) mxmlSetErrorCallback( @my_mxmlError() ) @@ -413,11 +415,11 @@ FUNCTION main( cFile ) OutStd( cBuffer + hb_eol() ) mxmlDelete( tree ) - cBuffer := mxmlSaveAllocString( node, 0 ) + cBuffer := mxmlSaveAllocString( node, 0 ) IF Len( cBuffer ) > 0 hb_memoWrit( "test3.xml", cBuffer ) ENDIF - + IF mxmlSaveFile( node, "test4.xml" ) < 0 OutErr( "ERROR: Can't execute mxmlSaveFile()!", hb_eol() ) ENDIF @@ -430,53 +432,53 @@ FUNCTION main( cFile ) IF mxmlSetUserData( node, whitespace ) > -1 OutStd( mxmlGetUserData( node ), hb_eol() ) ENDIF - + mxmlDelete( node ) /* * Test SAX methods... */ - event_counts := Array( 6 ) ; AFill( event_counts, 0 ) - + s_event_counts := Array( 6 ) ; AFill( s_event_counts, 0 ) + /* mxmlSAXLoadString( NIL, hb_memoRead( "test.xml" ), @type_cb(), @sax_cb() ) */ mxmlSAXLoadFile( NIL, "test.xml", @type_cb(), @sax_cb() ) - IF event_counts[ MXML_SAX_CDATA ] != 1 + IF s_event_counts[ MXML_SAX_CDATA ] != 1 OutErr( hb_strFormat( e"MXML_SAX_CDATA seen %d times, expected 1 times!\n", ; - event_counts[ MXML_SAX_CDATA ] ) ) + s_event_counts[ MXML_SAX_CDATA ] ) ) RETURN -6 - ENDIF + ENDIF - IF event_counts[ MXML_SAX_COMMENT ] != 1 + IF s_event_counts[ MXML_SAX_COMMENT ] != 1 OutErr( hb_strFormat( e"MXML_SAX_COMMENT seen %d times, expected 1 times!\n", ; - event_counts[ MXML_SAX_COMMENT ] ) ) + s_event_counts[ MXML_SAX_COMMENT ] ) ) RETURN -6 - ENDIF + ENDIF - IF event_counts[ MXML_SAX_DATA ] != 61 + IF s_event_counts[ MXML_SAX_DATA ] != 61 OutErr( hb_strFormat( e"MXML_SAX_DATA seen %d times, expected 61 times!\n", ; - event_counts[ MXML_SAX_DATA ] ) ) + s_event_counts[ MXML_SAX_DATA ] ) ) RETURN -6 - ENDIF + ENDIF - IF event_counts[ MXML_SAX_DIRECTIVE ] != 1 + IF s_event_counts[ MXML_SAX_DIRECTIVE ] != 1 OutErr( hb_strFormat( e"MXML_SAX_DIRECTIVE seen %d times, expected 1 times!\n", ; - event_counts[ MXML_SAX_DIRECTIVE ] ) ) + s_event_counts[ MXML_SAX_DIRECTIVE ] ) ) RETURN -6 - ENDIF + ENDIF - IF event_counts[ MXML_SAX_ELEMENT_CLOSE ] != 20 + IF s_event_counts[ MXML_SAX_ELEMENT_CLOSE ] != 20 OutErr( hb_strFormat( e"MXML_SAX_ELEMENT_CLOSE seen %d times, expected 20 times!\n", ; - event_counts[ MXML_SAX_ELEMENT_CLOSE ] ) ) + s_event_counts[ MXML_SAX_ELEMENT_CLOSE ] ) ) RETURN -6 - ENDIF + ENDIF - IF event_counts[ MXML_SAX_ELEMENT_OPEN ] != 20 + IF s_event_counts[ MXML_SAX_ELEMENT_OPEN ] != 20 OutErr( hb_strFormat( e"MXML_SAX_ELEMENT_OPEN seen %d times, expected 20 times!\n", ; - event_counts[ MXML_SAX_ELEMENT_OPEN ] ) ) + s_event_counts[ MXML_SAX_ELEMENT_OPEN ] ) ) RETURN -6 - ENDIF + ENDIF OutStd( "--- The End! ---", hb_eol() ) @@ -502,7 +504,7 @@ FUNCTION type_cb( node ) LOCAL cType /* You can lookup attributes and/or use the element name, hierarchy, etc... */ - + IF Empty( cType := mxmlElementGetAttr( node, "type" ) ) cType := mxmlGetElement( node ) ENDIF @@ -530,7 +532,7 @@ FUNCTION type_cb( node ) /* mxmlSaveString */ -FUNCTION whitespace_cb( node, where ) +FUNCTION whitespace_cb( node, where ) LOCAL parent /* Parent node */ LOCAL nLevel := -1 /* Indentation level */ @@ -547,8 +549,8 @@ FUNCTION whitespace_cb( node, where ) SWITCH Lower( name ) CASE "html" CASE "head" - CASE "body" - CASE "pre" + CASE "body" + CASE "pre" CASE "p" CASE "h1" CASE "h2" @@ -571,7 +573,7 @@ FUNCTION whitespace_cb( node, where ) ENDIF EXIT - CASE "dd" + CASE "dd" CASE "dt" CASE "li" /* Put a tab before
  • 's,
    's, and
    's, and a newline after them... */ @@ -584,7 +586,7 @@ FUNCTION whitespace_cb( node, where ) ENDSWITCH IF Left( name, 4 ) == "?xml" - IF where == MXML_WS_AFTER_OPEN + IF where == MXML_WS_AFTER_OPEN RETURN hb_eol() ELSE RETURN NIL @@ -600,9 +602,9 @@ FUNCTION whitespace_cb( node, where ) parent := mxmlGetParent( parent ) ENDDO - IF nLevel > 8 + IF nLevel > 8 nLevel := 8 - ELSEIF nLevel < 0 + ELSEIF nLevel < 0 nLevel := 0 ENDIF @@ -625,8 +627,9 @@ PROCEDURE sax_cb( node, sax_event, user_data ) /* mxmlRetain( node ) */ + HB_SYMBOL_UNUSED( node ) HB_SYMBOL_UNUSED( user_data ) - event_counts[ sax_event ] += 1 + s_event_counts[ sax_event ] += 1 RETURN diff --git a/harbour/contrib/hbssl/pem.c b/harbour/contrib/hbssl/pem.c index 4b2e8fd1cc..1aecda9466 100644 --- a/harbour/contrib/hbssl/pem.c +++ b/harbour/contrib/hbssl/pem.c @@ -112,12 +112,11 @@ static void hb_PEM_read_bio( PEM_READ_BIO * func ) if( bio ) { - PHB_ITEM pPassBlock = NULL; + PHB_ITEM pPassCallback = hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ); - if( HB_ISBLOCK( 2 ) ) + if( pPassCallback ) { - pPassBlock = hb_itemNew( hb_param( 2, HB_IT_BLOCK ) ); - hb_retptr( ( * func )( bio, NULL, hb_ssl_pem_password_cb, pPassBlock ) ); + hb_retptr( ( * func )( bio, NULL, hb_ssl_pem_password_cb, pPassCallback ) ); } else if( HB_ISCHAR( 2 ) ) { @@ -125,9 +124,6 @@ static void hb_PEM_read_bio( PEM_READ_BIO * func ) hb_retptr( ( * func )( bio, NULL, NULL, ( void * ) hb_parc( 2 ) ) ); } - if( pPassBlock ) - hb_itemRelease( pPassBlock ); - if( ! HB_ISPOINTER( 1 ) ) BIO_free( bio ); } diff --git a/harbour/contrib/hbssl/ssl.c b/harbour/contrib/hbssl/ssl.c index 947f322481..1a80fea9e4 100644 --- a/harbour/contrib/hbssl/ssl.c +++ b/harbour/contrib/hbssl/ssl.c @@ -1511,10 +1511,12 @@ HB_FUNC( SSL_SET_MSG_CALLBACK ) if( ssl ) { - if( HB_ISBLOCK( 2 ) ) + PHB_ITEM pCallback = hb_param( 2, HB_IT_BLOCK | HB_IT_SYMBOL ); + + if( pCallback ) { - PHB_ITEM pPassBlock = hb_itemNew( hb_param( 2, HB_IT_BLOCK ) ); - SSL_set_msg_callback_arg( ssl, pPassBlock ); + PHB_ITEM pPassCallback = hb_itemNew( pCallback ); + SSL_set_msg_callback_arg( ssl, pPassCallback ); SSL_set_msg_callback( ssl, hb_ssl_msg_callback ); } else diff --git a/harbour/contrib/hbssl/tests/pem.prg b/harbour/contrib/hbssl/tests/pem.prg index 3b6ea244a0..9573fbe7a3 100644 --- a/harbour/contrib/hbssl/tests/pem.prg +++ b/harbour/contrib/hbssl/tests/pem.prg @@ -21,11 +21,13 @@ PROCEDURE Main() bioe := BIO_new_fd( 1, HB_BIO_NOCLOSE ) - ? PEM_READ_BIO_RSAPRIVATEKEY( "privkey.pem", {| lWrite | QOut( "Callback", lWrite, hb_eol() ), "test" } ) + ? PEM_READ_BIO_RSAPRIVATEKEY( "privkey.pem", {| lWrite | QOut( "Callback (block)", lWrite, hb_eol() ), "test" } ) + ? ; ERR_print_errors( bioe ) + ? PEM_READ_BIO_RSAPRIVATEKEY( "privkey.pem", @cb_function() ) ? ; ERR_print_errors( bioe ) ? PEM_READ_BIO_RSAPRIVATEKEY( "privkey.pem", "test" ) ? ; ERR_print_errors( bioe ) - ? PEM_READ_BIO_RSAPUBLICKEY( "privkey.pem", {| lWrite | QOut( "Callback", lWrite, hb_eol() ), "test" } ) + ? PEM_READ_BIO_RSAPUBLICKEY( "privkey.pem", {| lWrite | QOut( "Callback (block)", lWrite, hb_eol() ), "test" } ) ? ; ERR_print_errors( bioe ) ? PEM_READ_BIO_RSAPUBLICKEY( "privkey.pem", "test" ) ? ; ERR_print_errors( bioe ) @@ -64,3 +66,7 @@ ENDTEXT BIO_free( bioe ) RETURN + +STATIC FUNCTION cb_function( lWrite ) + QOut( "Callback (func)", lWrite, hb_eol() ) + RETURN "test"