mirror of
https://github.com/lammertb/libhttp.git
synced 2025-08-06 05:02:40 +03:00
Client contexts now use callbacks
This commit is contained in:
@@ -907,7 +907,7 @@ LIBHTTP_API int httplib_closedir( DIR *dir );
|
|||||||
LIBHTTP_API struct httplib_connection * httplib_connect_client( struct httplib_context *ctx, const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size );
|
LIBHTTP_API struct httplib_connection * httplib_connect_client( struct httplib_context *ctx, const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size );
|
||||||
LIBHTTP_API struct httplib_connection * httplib_connect_client_secure( struct httplib_context *ctx, const struct httplib_client_options *client_options, char *error_buffer, size_t error_buffer_size );
|
LIBHTTP_API struct httplib_connection * httplib_connect_client_secure( struct httplib_context *ctx, const struct httplib_client_options *client_options, char *error_buffer, size_t error_buffer_size );
|
||||||
LIBHTTP_API struct httplib_connection * httplib_connect_websocket_client( struct httplib_context *ctx, const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, httplib_websocket_data_handler data_func, httplib_websocket_close_handler close_func, void *user_data );
|
LIBHTTP_API struct httplib_connection * httplib_connect_websocket_client( struct httplib_context *ctx, const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, const char *path, const char *origin, httplib_websocket_data_handler data_func, httplib_websocket_close_handler close_func, void *user_data );
|
||||||
LIBHTTP_API struct httplib_context * httplib_create_client_context( const struct httplib_option_t *options );
|
LIBHTTP_API struct httplib_context * httplib_create_client_context( const struct httplib_callbacks *callbacks, const struct httplib_option_t *options );
|
||||||
LIBHTTP_API void httplib_cry( enum debug_level_t debug_level, const struct httplib_context *ctx, const struct httplib_connection *conn, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(4, 5);
|
LIBHTTP_API void httplib_cry( enum debug_level_t debug_level, const struct httplib_context *ctx, const struct httplib_connection *conn, PRINTF_FORMAT_STRING(const char *fmt), ...) PRINTF_ARGS(4, 5);
|
||||||
LIBHTTP_API void httplib_destroy_client_context( struct httplib_context *ctx );
|
LIBHTTP_API void httplib_destroy_client_context( struct httplib_context *ctx );
|
||||||
LIBHTTP_API struct httplib_connection * httplib_download( struct httplib_context *ctx, const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, PRINTF_FORMAT_STRING(const char *request_fmt), ...) PRINTF_ARGS(7, 8);
|
LIBHTTP_API struct httplib_connection * httplib_download( struct httplib_context *ctx, const char *host, int port, int use_ssl, char *error_buffer, size_t error_buffer_size, PRINTF_FORMAT_STRING(const char *request_fmt), ...) PRINTF_ARGS(7, 8);
|
||||||
|
@@ -23,7 +23,7 @@
|
|||||||
#include "httplib_main.h"
|
#include "httplib_main.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* struct httplib_context *httplib_create_client_context( const struct httplib_option_t *options );
|
* struct httplib_context *httplib_create_client_context( const struct httplib_callbacks *callbacks, const struct httplib_option_t *options );
|
||||||
*
|
*
|
||||||
* The function httplib_create_client_context() creates a context to be used
|
* The function httplib_create_client_context() creates a context to be used
|
||||||
* for one simultaneous client connection. It is not possible to use one client
|
* for one simultaneous client connection. It is not possible to use one client
|
||||||
@@ -31,16 +31,30 @@
|
|||||||
* contains SSL context information which is specific for one connection.
|
* contains SSL context information which is specific for one connection.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct httplib_context *httplib_create_client_context( const struct httplib_option_t *options ) {
|
struct httplib_context *httplib_create_client_context( const struct httplib_callbacks *callbacks, const struct httplib_option_t *options ) {
|
||||||
|
|
||||||
struct httplib_context *ctx;
|
struct httplib_context *ctx;
|
||||||
|
void (*exit_callback)(const struct httplib_context *ctx);
|
||||||
|
|
||||||
ctx = httplib_calloc( 1, sizeof(struct httplib_context) );
|
exit_callback = NULL;
|
||||||
|
ctx = httplib_calloc( 1, sizeof(struct httplib_context) );
|
||||||
if ( ctx == NULL ) return NULL;
|
if ( ctx == NULL ) return NULL;
|
||||||
|
|
||||||
|
if ( callbacks != NULL ) {
|
||||||
|
|
||||||
|
ctx->callbacks = *callbacks;
|
||||||
|
exit_callback = callbacks->exit_context;
|
||||||
|
ctx->callbacks.exit_context = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if ( XX_httplib_init_options( ctx ) ) return NULL;
|
if ( XX_httplib_init_options( ctx ) ) return NULL;
|
||||||
if ( XX_httplib_process_options( ctx, options ) ) return NULL;
|
if ( XX_httplib_process_options( ctx, options ) ) return NULL;
|
||||||
|
|
||||||
|
if ( ctx->callbacks.init_context != NULL ) ctx->callbacks.init_context( ctx );
|
||||||
|
|
||||||
|
ctx->callbacks.exit_context = exit_callback;
|
||||||
|
ctx->ctx_type = CTX_TYPE_CLIENT;
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
|
|
||||||
} /* httplib_create_client_context */
|
} /* httplib_create_client_context */
|
||||||
|
Reference in New Issue
Block a user