BSB Developer Docs
Loading...
Searching...
No Matches
fetch.h File Reference

Library for building fetch-like HTTP clients. More...

#include "fetch_common.h"
#include <toolbox/tls_config.h>

Go to the source code of this file.

Data Structures

struct  FetchRequestHeaders
 Request headers structure. More...
 
struct  FetchRequestBody
 Request body structure. More...
 
struct  FetchRequest
 Request structure. More...
 

Macros

#define FETCH_HEADERS_COUNT_MAX   (12)
 Maximum number of additional request headers.
 

Typedefs

typedef struct Fetch Fetch
 Opaque Fetch structure declaration.
 
typedef void(* FetchRxDataCallback) (const void *data, size_t data_size, void *context)
 Received HTTP data callback function type.
 
typedef void(* FetchHeaderCallback) (const void *data, size_t data_size, void *context)
 Received HTTP headers callback function type.
 
typedef void(* FetchProgressCallback) (const FetchProgress *progress, void *context)
 Progress reporting callback function type.
 
typedef void(* FetchErrorCallback) (const char *error, void *context)
 Error reporting callback function type.
 

Functions

Fetch * fetch_alloc (void)
 Create a Fetch instance.
 
void fetch_free (Fetch *instance)
 Delete the Fetch instance.
 
FetchStatus fetch_run (Fetch *instance, const FetchRequest *request)
 Run the fetch process in the current thread.
 
void fetch_stop (Fetch *instance)
 Request the ongoing fetch process to stop.
 
void fetch_set_callback_context (Fetch *instance, void *context)
 Set the callback context for the Fetch instance.
 
void fetch_set_rx_data_callback (Fetch *instance, FetchRxDataCallback callback)
 Set the callback for received data.
 
void fetch_set_header_callback (Fetch *instance, FetchHeaderCallback callback)
 Set the callback for the header data.
 
void fetch_set_error_callback (Fetch *instance, FetchErrorCallback callback)
 Set the callback for error reporting.
 
void fetch_set_progress_callback (Fetch *instance, FetchProgressCallback callback)
 Sets the callback for status updates.
 

Detailed Description

Library for building fetch-like HTTP clients.

Typedef Documentation

◆ FetchErrorCallback

typedef void(* FetchErrorCallback) (const char *error, void *context)

Error reporting callback function type.

Parameters
[in]errorpointer to a zero-terminated string containing the error description
[in,out]contextpointer to a user-specific object (may be NULL)

◆ FetchHeaderCallback

typedef void(* FetchHeaderCallback) (const void *data, size_t data_size, void *context)

Received HTTP headers callback function type.

Parameters
[in]datapointer to header data
[in]data_sizelength of the header data
[in,out]contextpointer to a user-specific object (may be NULL)

◆ FetchProgressCallback

typedef void(* FetchProgressCallback) (const FetchProgress *progress, void *context)

Progress reporting callback function type.

Parameters
[in]progresspointer to a structure containing the current progress information
[in,out]contextpointer to a user-specific object (may be NULL)

◆ FetchRxDataCallback

typedef void(* FetchRxDataCallback) (const void *data, size_t data_size, void *context)

Received HTTP data callback function type.

Parameters
[in]datapointer to received data
[in]data_sizelength of the received data
[in,out]contextpointer to a user-specific object (may be NULL)

Function Documentation

◆ fetch_alloc()

Fetch * fetch_alloc ( void )

Create a Fetch instance.

Returns
Pointer to the allocated Fetch instance.

◆ fetch_free()

void fetch_free ( Fetch * instance)

Delete the Fetch instance.

Warning
The instance must be not running.
Parameters
[in,out]instancePointer to the Fetch instance to free.

◆ fetch_run()

FetchStatus fetch_run ( Fetch * instance,
const FetchRequest * request )

Run the fetch process in the current thread.

This call will block the calling thread until the fetch process is complete.

The callbacks will be executed in the calling thread's context.

Warning
The caller must ensure that at least 8 KB of stack is available within the context.
Parameters
[in,out]instancePointer to the Fetch instance.
[in]requestPointer to the request to be executed.
Returns
FetchStatusOk on success, any other FetchStatus value otherwise

◆ fetch_set_callback_context()

void fetch_set_callback_context ( Fetch * instance,
void * context )

Set the callback context for the Fetch instance.

Parameters
[in,out]instancePointer to the Fetch instance.
[in,out]contextPointer to the context to set.

◆ fetch_set_error_callback()

void fetch_set_error_callback ( Fetch * instance,
FetchErrorCallback callback )

Set the callback for error reporting.

Parameters
[in,out]instancePointer to the Fetch instance.
[in]callbackFunction pointer to the callback function.

◆ fetch_set_header_callback()

void fetch_set_header_callback ( Fetch * instance,
FetchHeaderCallback callback )

Set the callback for the header data.

Parameters
[in,out]instancePointer to the Fetch instance.
[in]callbackFunction pointer to the callback function.

◆ fetch_set_progress_callback()

void fetch_set_progress_callback ( Fetch * instance,
FetchProgressCallback callback )

Sets the callback for status updates.

Parameters
[in,out]instancePointer to the Fetch instance.
[in]callbackFunction pointer to the callback function.

◆ fetch_set_rx_data_callback()

void fetch_set_rx_data_callback ( Fetch * instance,
FetchRxDataCallback callback )

Set the callback for received data.

Parameters
[in,out]instancePointer to the Fetch instance.
[in]callbackFunction pointer to the callback function.

◆ fetch_stop()

void fetch_stop ( Fetch * instance)

Request the ongoing fetch process to stop.

This function is non-blocking. The execution thread must wait until fetch_exec() returns.

Parameters
[in,out]instancePointer to the Fetch instance.