From 0cd2603335632f615707a959b56d7c349451d7bc Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 31 May 2008 11:18:00 +0000 Subject: [PATCH] 2008-05-31 13:15 UTC+0100 Viktor Szakats (harbour.01 syenar hu) * contrib/hbcurl/hbcurl.c * contrib/hbcurl/tests/ftp_uldl.prg + Using Harbour FS API. ! Minor fix in uploaded file name. * contrib/make_b32_all.bat * contrib/make_gcc_all.sh * contrib/make_vc_all.bat + Added to 'all' makefiles. --- harbour/ChangeLog | 11 +++ harbour/contrib/hbcurl/hbcurl.c | 111 ++++++++++++---------- harbour/contrib/hbcurl/tests/ftp_uldl.prg | 2 +- harbour/contrib/make_b32_all.bat | 1 + harbour/contrib/make_gcc_all.sh | 1 + harbour/contrib/make_vc_all.bat | 1 + 6 files changed, 75 insertions(+), 52 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e9f0608937..bfacb26b38 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,17 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-05-31 13:15 UTC+0100 Viktor Szakats (harbour.01 syenar hu) + * contrib/hbcurl/hbcurl.c + * contrib/hbcurl/tests/ftp_uldl.prg + + Using Harbour FS API. + ! Minor fix in uploaded file name. + + * contrib/make_b32_all.bat + * contrib/make_gcc_all.sh + * contrib/make_vc_all.bat + + Added to 'all' makefiles. + 2008-05-31 12:46 UTC+0100 Viktor Szakats (harbour.01 syenar hu) + contrib/hbcurl + contrib/hbcurl/Makefile diff --git a/harbour/contrib/hbcurl/hbcurl.c b/harbour/contrib/hbcurl/hbcurl.c index 8fc604260d..b75fda308e 100644 --- a/harbour/contrib/hbcurl/hbcurl.c +++ b/harbour/contrib/hbcurl/hbcurl.c @@ -59,10 +59,9 @@ #include "hbapi.h" #include "hbapiitm.h" +#include "hbapifs.h" #include "hbvm.h" -#include - #include "hbcurl.ch" #define HB_CURL_OPT_BOOL( n ) ( ISLOG( n ) ? ( long ) hb_parl( n ) : hb_parnl( n ) ) @@ -70,8 +69,8 @@ typedef struct _FTPFILE { - char * name; - FILE * handle; + BYTE * name; + FHANDLE handle; } FTPFILE, * PFTPFILE; typedef struct _CURLHANDLE @@ -107,44 +106,44 @@ HB_FUNC( CURL_GLOBAL_CLEANUP ) /* ---------------------------- */ -int hb_curlReadFunction( void * buffer, size_t size, size_t nmemb, void * Cargo ) +size_t hb_curlReadFunction( void * buffer, size_t size, size_t nmemb, void * Cargo ) { if( Cargo ) { PFTPFILE pfile_ul = ( PFTPFILE ) Cargo; + size_t ret; - if( ! pfile_ul->handle ) + if( pfile_ul->handle == FS_ERROR ) { - pfile_ul->handle = fopen( pfile_ul->name, "rb" ); + pfile_ul->handle = hb_fsOpen( pfile_ul->name, FO_READ ); - if( ! pfile_ul->handle ) + if( pfile_ul->handle == FS_ERROR ) return -1; } - if( ferror( pfile_ul->handle ) ) - return CURL_READFUNC_ABORT; - else - return fread( buffer, size, nmemb, pfile_ul->handle ) * size; + ret = ( size_t ) hb_fsRead( pfile_ul->handle, ( BYTE * ) buffer, size * nmemb ); + + return hb_fsError() ? CURL_READFUNC_ABORT : ret; } return -1; } -int hb_curlWriteFunction( void * buffer, size_t size, size_t nmemb, void * Cargo ) +size_t hb_curlWriteFunction( void * buffer, size_t size, size_t nmemb, void * Cargo ) { if( Cargo ) { PFTPFILE pfile_dl = ( PFTPFILE ) Cargo; - if( ! pfile_dl->handle ) + if( pfile_dl->handle == FS_ERROR ) { - pfile_dl->handle = fopen( pfile_dl->name, "wb" ); + pfile_dl->handle = hb_fsCreate( pfile_dl->name, FC_NORMAL ); - if( ! pfile_dl->handle ) + if( pfile_dl->handle == FS_ERROR ) return -1; } - return fwrite( buffer, size, nmemb, pfile_dl->handle ); + return hb_fsWrite( pfile_dl->handle, ( BYTE * ) buffer, size * nmemb ); } return -1; @@ -213,16 +212,20 @@ static void PCURLHANDLE_free( PCURLHANDLE pConn ) curl_slist_free_all( pConn->sPreQuote ); if( pConn->file_ul.name ) + { hb_xfree( pConn->file_ul.name ); - if( pConn->file_ul.handle ) - fclose( pConn->file_ul.handle); + if( pConn->file_ul.handle != FS_ERROR ) + hb_fsClose( pConn->file_ul.handle ); + } if( pConn->file_dl.name ) + { hb_xfree( pConn->file_dl.name ); - if( pConn->file_dl.handle ) - fclose( pConn->file_dl.handle); + if( pConn->file_dl.handle != FS_ERROR ) + hb_fsClose( pConn->file_dl.handle ); + } if( pConn->pProgress ) hb_itemRelease( pConn->pProgress ); @@ -791,15 +794,16 @@ HB_FUNC( CURL_EASY_SETOPT ) { hb_xfree( pConn->file_ul.name ); pConn->file_ul.name = NULL; + + if( pConn->file_ul.handle != FS_ERROR ) + { + hb_fsClose( pConn->file_ul.handle ); + pConn->file_ul.handle = FS_ERROR; + } } - if( pConn->file_ul.handle ) - { - fclose( pConn->file_ul.handle ); - pConn->file_ul.handle = NULL; - } - - pConn->file_ul.name = hb_strdup( hb_parc( 3 ) ); + pConn->file_ul.name = ( BYTE * ) hb_strdup( hb_parc( 3 ) ); + pConn->file_ul.handle = FS_ERROR; curl_easy_setopt( pConn->curl, CURLOPT_READFUNCTION, hb_curlReadFunction ); res = curl_easy_setopt( pConn->curl, CURLOPT_READDATA, ( void * ) &pConn->file_ul ); @@ -812,17 +816,19 @@ HB_FUNC( CURL_EASY_SETOPT ) { hb_xfree( pConn->file_ul.name ); pConn->file_ul.name = NULL; - } - if( pConn->file_ul.handle ) - { - fclose( pConn->file_ul.handle ); - pConn->file_ul.handle = NULL; - - res = CURLE_OK; + if( pConn->file_ul.handle != FS_ERROR ) + { + hb_fsClose( pConn->file_ul.handle ); + pConn->file_ul.handle = FS_ERROR; + + res = CURLE_OK; + } + else + res = ( CURLcode ) -1; } else - res = ( CURLcode ) -1; + res = CURLE_OK; } break; @@ -832,15 +838,16 @@ HB_FUNC( CURL_EASY_SETOPT ) { hb_xfree( pConn->file_dl.name ); pConn->file_dl.name = NULL; + + if( pConn->file_dl.handle != FS_ERROR ) + { + hb_fsClose( pConn->file_dl.handle ); + pConn->file_dl.handle = FS_ERROR; + } } - if( pConn->file_dl.handle ) - { - fclose( pConn->file_dl.handle ); - pConn->file_dl.handle = NULL; - } - - pConn->file_dl.name = hb_strdup( hb_parc( 3 ) ); + pConn->file_dl.name = ( BYTE * ) hb_strdup( hb_parc( 3 ) ); + pConn->file_dl.handle = FS_ERROR; curl_easy_setopt( pConn->curl, CURLOPT_WRITEFUNCTION, hb_curlWriteFunction ); res = curl_easy_setopt( pConn->curl, CURLOPT_WRITEDATA, ( void * ) &pConn->file_dl ); @@ -853,17 +860,19 @@ HB_FUNC( CURL_EASY_SETOPT ) { hb_xfree( pConn->file_dl.name ); pConn->file_dl.name = NULL; - } - if( pConn->file_dl.handle ) - { - fclose( pConn->file_dl.handle ); - pConn->file_dl.handle = NULL; - - res = CURLE_OK; + if( pConn->file_dl.handle != FS_ERROR ) + { + hb_fsClose( pConn->file_dl.handle ); + pConn->file_dl.handle = FS_ERROR; + + res = CURLE_OK; + } + else + res = ( CURLcode ) -1; } else - res = ( CURLcode ) -1; + res = CURLE_OK; } break; diff --git a/harbour/contrib/hbcurl/tests/ftp_uldl.prg b/harbour/contrib/hbcurl/tests/ftp_uldl.prg index bb9d7efcfd..32e4ef2e82 100644 --- a/harbour/contrib/hbcurl/tests/ftp_uldl.prg +++ b/harbour/contrib/hbcurl/tests/ftp_uldl.prg @@ -6,7 +6,7 @@ #include "hbcurl.ch" -#define LOCAL_FILE "ftp_up.prg" +#define LOCAL_FILE "ftp_uldl.prg" #define UPLOAD_FILE_AS "ftp_upped.prg" #define REMOTE_URL "ftp://harbour:power@localhost/" + UPLOAD_FILE_AS #define RENAME_FILE_TO "ftp_upped_renamed.prg" diff --git a/harbour/contrib/make_b32_all.bat b/harbour/contrib/make_b32_all.bat index 522b00e3a1..bbc3ab2d93 100644 --- a/harbour/contrib/make_b32_all.bat +++ b/harbour/contrib/make_b32_all.bat @@ -54,6 +54,7 @@ if not "%HB_DIR_MYSQL%" == "" set _HB_DIRS=%_HB_DIRS% hbmysql if not "%HB_DIR_PGSQL%" == "" set _HB_DIRS=%_HB_DIRS% hbpgsql if not "%HB_DIR_ADS%" == "" set _HB_DIRS=%_HB_DIRS% rddads if not "%HB_DIR_LIBHARU%" == "" set _HB_DIRS=%_HB_DIRS% hbhpdf +if not "%HB_DIR_CURL%" == "" set _HB_DIRS=%_HB_DIRS% hbcurl for %%n in ( %_HB_DIRS% ) do %COMSPEC% /c %_HB_BATWORKER% %%n %1 %2 %3 %4 %5 %6 %7 %8 %9 rem ******************************************************* diff --git a/harbour/contrib/make_gcc_all.sh b/harbour/contrib/make_gcc_all.sh index d9e8944899..3937892cf4 100755 --- a/harbour/contrib/make_gcc_all.sh +++ b/harbour/contrib/make_gcc_all.sh @@ -56,6 +56,7 @@ if [ "${HB_INC_MYSQL}" != "" ]; then _HB_DIRS="${_HB_DIRS} hbmysql "; fi; if [ "${HB_INC_PGSQL}" != "" ]; then _HB_DIRS="${_HB_DIRS} hbpgsql "; fi; if [ "${HB_INC_ADS}" != "" ]; then _HB_DIRS="${_HB_DIRS} rddads "; fi; if [ "${HB_INC_LIBHARU}" != "" ]; then _HB_DIRS="${_HB_DIRS} hbhpdf "; fi; +if [ "${HB_INC_CURL}" != "" ]; then _HB_DIRS="${_HB_DIRS} hbcurl "; fi; _HB_DIRS="${_HB_DIRS} ${_HB_DIRS_ADD}" diff --git a/harbour/contrib/make_vc_all.bat b/harbour/contrib/make_vc_all.bat index f4bcbf6134..069733d1cf 100644 --- a/harbour/contrib/make_vc_all.bat +++ b/harbour/contrib/make_vc_all.bat @@ -54,6 +54,7 @@ if not "%HB_DIR_MYSQL%" == "" set _HB_DIRS=%_HB_DIRS% hbmysql if not "%HB_DIR_PGSQL%" == "" set _HB_DIRS=%_HB_DIRS% hbpgsql if not "%HB_DIR_ADS%" == "" set _HB_DIRS=%_HB_DIRS% rddads if not "%HB_DIR_LIBHARU%" == "" set _HB_DIRS=%_HB_DIRS% hbhpdf +if not "%HB_DIR_CURL%" == "" set _HB_DIRS=%_HB_DIRS% hbcurl for %%n in ( %_HB_DIRS% ) do %COMSPEC% /c %_HB_BATWORKER% %%n %1 %2 %3 %4 %5 %6 %7 %8 %9 rem *******************************************************