thistle-sdk
Thistle SDK documentation
|
#include <stdint.h>
Go to the source code of this file.
Typedefs | |
typedef enum tsc_result | tsc_result |
typedef struct tsc_http_request | tsc_http_request |
typedef struct tsc_http_response | tsc_http_response |
typedef struct tsc_http_session | tsc_http_session |
Enumerations | |
enum | tsc_result { TSC_RESULT_OK = 1000 , TSC_RESULT_INVALID_URL = 1001 , TSC_RESULT_UTF8_VALIDATION_FAILURE = 1002 , TSC_RESULT_TOO_MANY_REDIRECTS = 1003 , TSC_RESULT_TIMED_OUT = 1004 , TSC_RESULT_RESPONSE_ERROR = 1005 , TSC_RESULT_UNEXPECTED_ERROR = 1006 , TSC_RESULT_DNS_LOOKUP_FAILURE = 1007 , TSC_RESULT_CONNECTION_FAILED = 1008 , TSC_RESULT_CONNECTION_ABORTED = 1009 , TSC_RESULT_CONNECTION_REFUSED = 1010 , TSC_RESULT_CONNECTION_RESET = 1011 , TSC_RESULT_BAD_HEADER = 1012 , TSC_RESULT_BAD_STATUS = 1013 , TSC_RESULT_NO_PROXY_SUPPORT = 1014 , TSC_RESULT_NO_HTTPS = 1015 } |
typedef struct tsc_http_request tsc_http_request |
Struct for HTTP requests
typedef struct tsc_http_response tsc_http_response |
Struct for the HTTP response
typedef struct tsc_http_session tsc_http_session |
Struct for HTTP sessions
typedef enum tsc_result tsc_result |
Enumeration for different possible errors
enum tsc_result |
Enumeration for different possible errors
void tsc_http_request_free | ( | struct tsc_http_request * | request | ) |
Deallocate a request. This function should be called when the request is no longer in use.
request | A pointer to a request which was returned from tsc_http_session_get() , tsc_http_session_put() , tsc_http_session_patch() , tsc_http_session_delete() , or tsc_http_session_post() . |
Referenced by main().
enum tsc_result tsc_http_request_get_headers | ( | const struct tsc_http_request * | request, |
void(*)(const char *, size_t, const char *, size_t, void *) | callback, | ||
void * | userdata | ||
) |
Get the current headers set for the request
request | A pointer to a request which was returned from tsc_http_session_get() , tsc_http_session_put() , tsc_http_session_patch() , tsc_http_session_delete() , or tsc_http_session_post() . |
callback | A function pointer which will be called for each key/value pair along with the corresponding sizes and a pointer to 'userdata' |
userdata | A pointer to allow access to shared data operated on by the callback function. |
tsc_http_response_free()
is called. enum tsc_result tsc_http_request_send | ( | struct tsc_http_request * | request, |
struct tsc_http_response ** | response | ||
) |
Issue the request to the network and get back a response. This function call will block until the request has succeeded, failed, or timed out. The status of the call can be read from the return value. If the function call returns TSC_RESULT_OK then the response is valid, otherwise the response should be not be used.
request | A pointer to a request which was returned from tsc_http_session_get() , tsc_http_session_put() , tsc_http_session_patch() , tsc_http_session_delete() , or tsc_http_session_post() . |
response | An unallocated pointer to a response struct. This function will allocate the response struct. After use the response struct should be unallocated by calling tsc_http_response_free() . The struct will only be allocated if the function is successful. |
Referenced by main().
enum tsc_result tsc_http_request_send_bytes | ( | struct tsc_http_request * | request, |
const uint8_t * | data, | ||
uintptr_t | data_length, | ||
struct tsc_http_response ** | response | ||
) |
Issue the request to the network and get back a response. This request will upload data with the request. The 'Content-Length' header is implicitly set to data_length. This function call will block until the request has succeeded, failed, or timed out. The status of the call can be read from the return value. If the function call returns TSC_RESULT_OK then the response is valid, otherwise the response should be not be used.
request | A pointer to a request which was returned from tsc_http_session_get() , tsc_http_session_put() , tsc_http_session_patch() , tsc_http_session_delete() , or tsc_http_session_post() . |
data | A pointer to the data to send. This is often a file or JSON document. |
data_length | The length of the buffer pointed to by data. |
response | An unallocated pointer to a response struct. This function will allocate the response struct. After use the response struct should be unallocated by calling tsc_http_response_free() . The struct will only be allocated if the function is successful. |
enum tsc_result tsc_http_request_set_header | ( | struct tsc_http_request * | request, |
const char * | name, | ||
const char * | value | ||
) |
Issue the request to the network and get back a response. This request will upload data with the request. The 'Content-Length' header is implicitly set to data_length. This function call will block until the request has succeeded, failed, or timed out. The status of the call can be read from the return value. If the function call returns TSC_RESULT_OK then the response is valid, otherwise the response should be not be used.
request | A pointer to a request which was returned from tsc_http_session_get() , tsc_http_session_put() , tsc_http_session_patch() , tsc_http_session_delete() , or tsc_http_session_post() . |
name | A pointer to a null terminated string which containing the name of the HTTP header to set |
value | A pointer to a null terminated string containing the value of the HTTP header to set |
const unsigned char * tsc_http_response_body | ( | const struct tsc_http_response * | response, |
uintptr_t * | len | ||
) |
Get the body of the response. This function will return a pointer to the internal buffer holding the response.
response | A pointer to an http_response returned from tsc_http_request_send() |
length | Returns the length in bytes of the body |
tsc_http_response_free()
is called. Referenced by main().
void tsc_http_response_free | ( | struct tsc_http_response * | response | ) |
Deallocate the response once it is no longer in use. Any pointers to data within the response will become invalid.
response | A pointer to an http_response returned from tsc_http_request_send() or tsc_http_request_send_bytes() |
Referenced by main().
enum tsc_result tsc_http_response_get_headers | ( | const struct tsc_http_response * | response, |
void(*)(const char *, size_t, const char *, size_t, void *) | callback, | ||
void * | userdata | ||
) |
Get the headers in the response. The callback function will be called for each header and will be passed a pointer to userdata.
response | A pointer to an http_response returned from tsc_http_request_send() |
callback | A function pointer which will be called for each key/value pair along with the corresponding sizes and a pointer to 'userdata' |
userdata | A pointer to allow access to shared data operated on by the callback function. |
tsc_http_response_free()
is called. uint16_t tsc_http_response_get_status | ( | const struct tsc_http_response * | response | ) |
Get the HTTP status code from the response.
response | A pointer to an http_response returned from tsc_http_request_send() |
const unsigned char * tsc_http_response_get_status_text | ( | const struct tsc_http_response * | response | ) |
Get the status text from the response. This function will return a pointer to the internal buffer holding the status text. ///
response | A pointer to an http_response returned from tsc_http_request_send() |
struct tsc_http_request * tsc_http_session_delete | ( | struct tsc_http_session * | session | ) |
Create an HTTP DELETE request. This type of request is often used to delete a resource on a server.
session | A pointer to a session which was allocated from tsc_http_session_new() |
tsc_http_request
structure. This request can be freed by calling tsc_http_request_free()
. void tsc_http_session_free | ( | struct tsc_http_session * | session | ) |
Free a secure HTTP session. This function will deallocate the tsc_http_session and any allocated requests or responses that have not already been freed.
session | A pointer to session which was allocated from tsc_http_session_new() . |
Referenced by main().
struct tsc_http_request * tsc_http_session_get | ( | struct tsc_http_session * | session | ) |
Create an HTTP GET request. This type of request is often used to request data from a server.
session | A pointer to a session which was allocated from tsc_http_session_new() |
tsc_http_request
structure. This request can be freed by calling tsc_http_request_free()
. Referenced by main().
struct tsc_http_session * tsc_http_session_new | ( | void | ) |
Create a new secure HTTP session. This function will return a pointer to an internally allocated struct for managing the HTTP session. This struct will manage settings and internal memory usage. The first call to this function may initialize some globally shared internal memory.
tsc_http_session_free
when no longer in use. Referenced by main().
struct tsc_http_request * tsc_http_session_patch | ( | struct tsc_http_session * | session | ) |
Create an HTTP PATCH request. This type of request is often used to modify a resource on a server.
session | A pointer to a session which was allocated from tsc_http_session_new() |
tsc_http_request
structure. This request can be freed by calling tsc_http_request_free()
. struct tsc_http_request * tsc_http_session_post | ( | struct tsc_http_session * | session | ) |
Create an HTTP POST request. This type of request is often used to send data to a server.
session | A pointer to a session which was allocated from tsc_http_session_new() |
tsc_http_request
structure. This request can be freed by calling tsc_http_request_free()
. struct tsc_http_request * tsc_http_session_put | ( | struct tsc_http_session * | session | ) |
Create an HTTP PUT request. This type of request is often used to send data to a server in an idempotent way.
session | A pointer to a session which was allocated from tsc_http_session_new() |
tsc_http_request
structure. This request can be freed by calling tsc_http_request_free()
. void tsc_http_session_set_max_redirects | ( | struct tsc_http_session * | session, |
uint32_t | redirects | ||
) |
Set the max number of HTTP redirects for this session.
session | A pointer to session which was allocated from tsc_http_session_new() . |
redirects | The max number of redirects allowed |
void tsc_http_session_set_timeout | ( | struct tsc_http_session * | session, |
uint64_t | timeout | ||
) |
Set timeout for all connections in this session. Note: this does not include the connect timeout.
session | A pointer to session which was allocated from tsc_http_session_new() . |
timeout | The length of time in seconds allowed before a connection will timeout. |
void tsc_http_session_set_timeout_connect | ( | struct tsc_http_session * | session, |
uint64_t | timeout | ||
) |
Set the connect timeout for all connections in this session. Note: this only includes the initial connect timeout, not the timeout for the overall connection.
session | A pointer to session which was allocated from tsc_http_session_new() . |
timeout | The length of time in seconds allowed before a connection will timeout. |
enum tsc_result tsc_http_session_set_url | ( | struct tsc_http_session * | session, |
const char * | url | ||
) |
Set the URL future requests will use. The URL must start with HTTPS. All requests made after calling this function will use this URL until this function is called again.
session | A pointer to a session which was allocated from tsc_http_session_new() |
url | A pointer to a valid URL starting with https://. |
Referenced by main().
void tsc_http_session_set_user_agent | ( | struct tsc_http_session * | session, |
const char * | user_agent | ||
) |
The user agent string will be copied so it can be freed after use
session | A pointer to session which was allocated from tsc_http_session_new() . |
user_agent | A string to specify the user agent. |
const char * tsc_strerror | ( | enum tsc_result | error | ) |