Skip to content

Commit

Permalink
2025-01-07 22:49 UTC+0100 Aleksander Czajczynski (hb fki.pl)
Browse files Browse the repository at this point in the history
  * contrib/hbcurl/hbcurl.ch
    * updated HB_CURLOPT_SSL_OPTIONS: HB_CURLSSLOPT_*

    + added HB_CURLMSG_RESP_HANDLE, HB_CURLMSG_RESP_HPOS
      mappings of array elements returned by
      curl_multi_info_read( <hMulti>[, <aHandles> ]) -> <aResults>

  * contrib/hbcurl/core.c
    * adapted @emazv72 contribution from:
      vszakats/hb#344
      Many thanks, it could be useful for managing multiple transfers,
      by extending some kind of Inkey() loop or in many other
      scenarios.

    + added curl lib version guards

    * minor code and code formattings

    + extended function
      curl_multi_info_read( <hMulti>[, <aHandles> ]) -> <aResults>
      with a possibility to return real GC pointer of specific
      transfer related to reported event. <aHandles> should be
      specified if this is expected.

  + contrib/hbcurl/tests/multi.prg
    + demo of the additions
  • Loading branch information
alcz committed Jan 7, 2025
1 parent 6066379 commit c2870ac
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 32 deletions.
28 changes: 28 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@
Entries may not always be in chronological/commit order.
See license at the end of file. */

2025-01-07 22:49 UTC+0100 Aleksander Czajczynski (hb fki.pl)
* contrib/hbcurl/hbcurl.ch
* updated HB_CURLOPT_SSL_OPTIONS: HB_CURLSSLOPT_*

+ added HB_CURLMSG_RESP_HANDLE, HB_CURLMSG_RESP_HPOS
mappings of array elements returned by
curl_multi_info_read( <hMulti>[, <aHandles> ]) -> <aResults>

* contrib/hbcurl/core.c
* adapted @emazv72 contribution from:
https://github.com/vszakats/hb/pull/344
Many thanks, it could be useful for managing multiple transfers,
by extending some kind of Inkey() loop or in many other
scenarios.

+ added curl lib version guards

* minor code and code formattings

+ extended function
curl_multi_info_read( <hMulti>[, <aHandles> ]) -> <aResults>
with a possibility to return real GC pointer of specific
transfer related to reported event. <aHandles> should be
specified if this is expected.

+ contrib/hbcurl/tests/multi.prg
+ demo of the additions

2025-01-07 21:43 UTC+0100 Emanuele Zavallone (emanuele.zavallone gmail.com)
* contrib/hbcurl/easy.c
* contrib/hbcurl/hbcurl.ch
Expand Down
91 changes: 60 additions & 31 deletions contrib/hbcurl/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ typedef struct _HB_CURL

} HB_CURL, * PHB_CURL;

/* Multi interface */
/* --------------- */

#if LIBCURL_VERSION_NUM >= 0x070906
typedef struct _HB_CURLM
{
CURLM * curlm;

} HB_CURLM, * PHB_CURLM;
#endif

/* functions to keep passed string values accessible even if HVM
* destroy them. It's necessary for old CURL versions which do not
Expand Down Expand Up @@ -2499,19 +2509,10 @@ HB_FUNC( CURL_GETDATE )
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}

/* Multi interface */
/* ----------------- */

typedef struct _HB_CURLM
{
CURLM * curlm;

} HB_CURLM, * PHB_CURLM;


/* Constructor/Destructor */
/* ---------------------- */
/* Multi interface Constructor/Destructor */
/* -------------------------------------- */

#if LIBCURL_VERSION_NUM >= 0x070906
static void PHB_CURLM_free( PHB_CURLM hb_curlm )
{
curl_multi_cleanup( hb_curlm->curlm );
Expand Down Expand Up @@ -2574,18 +2575,21 @@ static PHB_CURLM PHB_CURLM_par( int iParam )

return ph ? ( PHB_CURLM ) *ph : NULL;
}
#endif

/* Harbour interface */
/* ----------------- */

/* Harbour multi interface */
/* ----------------------- */

HB_FUNC( CURL_MULTI_INIT )
{
#if LIBCURL_VERSION_NUM >= 0x070906
PHB_CURLM_ret( );
#endif
}

HB_FUNC( CURL_MULTI_CLEANUP )
{
#if LIBCURL_VERSION_NUM >= 0x070906
if( PHB_CURLM_is( 1 ) )
{
void ** ph = ( void ** ) hb_parptrGC( &s_gcCURLMFuncs, 1 );
Expand All @@ -2598,11 +2602,13 @@ HB_FUNC( CURL_MULTI_CLEANUP )
}
}
else
#endif
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}

HB_FUNC( CURL_MULTI_ADD_HANDLE )
{
#if LIBCURL_VERSION_NUM >= 0x070906
if( PHB_CURLM_is( 1 ) && PHB_CURL_is( 2 ) )
{
PHB_CURLM hb_curlm = PHB_CURLM_par( 1 );
Expand All @@ -2611,11 +2617,13 @@ HB_FUNC( CURL_MULTI_ADD_HANDLE )
hb_retnl( hb_curlm && hb_curl ? ( long ) curl_multi_add_handle( hb_curlm->curlm, hb_curl->curl) : HB_CURLM_INTERNAL_ERROR );
}
else
#endif
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}

HB_FUNC( CURL_MULTI_REMOVE_HANDLE )
{
#if LIBCURL_VERSION_NUM >= 0x070906
if( PHB_CURLM_is( 1 ) && PHB_CURL_is( 2 ) )
{
PHB_CURLM hb_curlm = PHB_CURLM_par( 1 );
Expand All @@ -2624,18 +2632,20 @@ HB_FUNC( CURL_MULTI_REMOVE_HANDLE )
hb_retnl( hb_curlm && hb_curl ? ( long ) curl_multi_remove_handle( hb_curlm->curlm, hb_curl->curl) : HB_CURLM_INTERNAL_ERROR );
}
else
#endif
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}

HB_FUNC( CURL_MULTI_PERFORM )
{
#if LIBCURL_VERSION_NUM >= 0x070906
if( PHB_CURLM_is( 1 ) && HB_ISBYREF( 2 ) )
{

CURLMcode res = ( CURLMcode ) HB_CURLM_INTERNAL_ERROR;
PHB_CURLM hb_curlm = PHB_CURLM_par( 1 );

if ( hb_curlm )
if( hb_curlm )
{
int running_handles = 0;
res = curl_multi_perform( hb_curlm->curlm, &running_handles);
Expand All @@ -2646,18 +2656,20 @@ HB_FUNC( CURL_MULTI_PERFORM )

}
else
#endif
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}

HB_FUNC( CURL_MULTI_POLL )
{
#if LIBCURL_VERSION_NUM >= 0x074200
if( PHB_CURLM_is( 1 ) && HB_ISNUM( 2 ) )
{

CURLMcode res = ( CURLMcode ) HB_CURLM_INTERNAL_ERROR;
PHB_CURLM hb_curlm = PHB_CURLM_par( 1 );

if ( hb_curlm )
if( hb_curlm )
{
res = curl_multi_poll( hb_curlm->curlm,
NULL,
Expand All @@ -2670,54 +2682,71 @@ HB_FUNC( CURL_MULTI_POLL )

}
else
#endif
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}


HB_FUNC( CURL_MULTI_INFO_READ )
{
#if LIBCURL_VERSION_NUM >= 0x070906
if( PHB_CURLM_is( 1 ) )
{

PHB_ITEM pReturn = NULL;
PHB_CURLM hb_curlm = PHB_CURLM_par( 1 );

if ( hb_curlm )
if( hb_curlm )
{
int msgs_in_queue = 0;
long response_code = 0;
struct CURLMsg * msg = curl_multi_info_read( hb_curlm->curlm, &msgs_in_queue );

struct CURLMsg *msg = curl_multi_info_read( hb_curlm->curlm, &msgs_in_queue );
if ( msg )
if( msg && curl_easy_getinfo( msg->easy_handle, CURLINFO_RESPONSE_CODE, &response_code ) == CURLE_OK )
{

CURLcode res = ( CURLcode ) HB_CURLE_ERROR;
long response_code = 0;
res = curl_easy_getinfo( msg->easy_handle, CURLINFO_RESPONSE_CODE, &response_code );

PHB_ITEM pHandles = hb_param( 2, HB_IT_ARRAY );
pReturn = hb_itemArrayNew( HB_CURLMSG_RESP_LAST );

hb_arraySetNL( pReturn, HB_CURLMSG_RESP_LEN, ( long ) msgs_in_queue );
hb_arraySetNL( pReturn, HB_CURLMSG_RESP_RESPONSE_CODE, ( long ) response_code );
hb_arraySetNL( pReturn, HB_CURLMSG_RESP_MSG, ( long ) msg->msg );
hb_arraySetNL( pReturn, HB_CURLMSG_RESP_RESULT, ( long ) msg->data.result );
hb_arraySetNI( pReturn, HB_CURLMSG_RESP_HPOS, 0 );

if( pHandles )
{
HB_SIZE handles_count = hb_arrayLen( pHandles );
HB_SIZE i;

for( i = 1; i <= handles_count; i++ )
{
void ** ph = hb_arrayGetPtrGC( pHandles, i, &s_gcCURLFuncs );
if( ph && *ph )
{
PHB_CURL hbcurl = ( PHB_CURL ) *ph;
if( hbcurl->curl == msg->easy_handle )
{
hb_arraySetNL( pReturn, HB_CURLMSG_RESP_HPOS, ( long ) i );
hb_arraySet( pReturn, HB_CURLMSG_RESP_HANDLE, hb_arrayGetItemPtr( pHandles, i ) );
}
}
}
}
}
}

if ( pReturn )
if( pReturn )
hb_itemReturnRelease( pReturn );
else
hb_ret();

}
else
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );

#endif
}

/* Harbour interface (session independent) */

/* NOTE: Obsolete, superceded by curl_easy_escape() */
/* NOTE: Obsolete, superseded by curl_easy_escape() */
HB_FUNC( CURL_ESCAPE )
{
if( HB_ISCHAR( 1 ) )
Expand All @@ -2730,7 +2759,7 @@ HB_FUNC( CURL_ESCAPE )
hb_errRT_BASE( EG_ARG, 2010, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}

/* NOTE: Obsolete, superceded by curl_easy_unescape() */
/* NOTE: Obsolete, superseded by curl_easy_unescape() */
HB_FUNC( CURL_UNESCAPE )
{
if( HB_ISCHAR( 1 ) )
Expand Down
9 changes: 8 additions & 1 deletion contrib/hbcurl/hbcurl.ch
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@

/* HB_CURLOPT_SSL_OPTIONS values */
#define HB_CURLSSLOPT_ALLOW_BEAST hb_bitShift( 1, 0 )
#define HB_CURLSSLOPT_NO_REVOKE hb_bitShift( 1, 1 )
#define HB_CURLSSLOPT_NO_PARTIALCHAIN hb_bitShift( 1, 2 )
#define HB_CURLSSLOPT_REVOKE_BEST_EFFORT hb_bitShift( 1, 3 )
#define HB_CURLSSLOPT_NATIVE_CA hb_bitShift( 1, 4 )
#define HB_CURLSSLOPT_AUTO_CLIENT_CERT hb_bitShift( 1, 5 )

/* HB_CURLOPT_HTTPAUTH option */
#define HB_CURLAUTH_NONE 0 /* nothing */
Expand Down Expand Up @@ -604,6 +609,8 @@
#define HB_CURLMSG_RESP_RESPONSE_CODE 2 /* curl_easy_getinfo( msg->easy_handle, CURLINFO_RESPONSE_CODE ) */
#define HB_CURLMSG_RESP_MSG 3 /* CURLMSG */
#define HB_CURLMSG_RESP_RESULT 4 /* CURLcode */
#define HB_CURLMSG_RESP_LAST HB_CURLMSG_RESP_RESULT
#define HB_CURLMSG_RESP_HANDLE 5 /* handle to original curl_easy_init */
#define HB_CURLMSG_RESP_HPOS 6 /* position in handle <array> passed to curl_multi_info_read(, <array> ) */
#define HB_CURLMSG_RESP_LAST HB_CURLMSG_RESP_HPOS

#endif /* HBCURL_CH_ */
Loading

0 comments on commit c2870ac

Please sign in to comment.