http.h 1.55 KB
Newer Older
Jacob Priddy's avatar
Jacob Priddy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#ifndef DOOR_CONTROLLER_MAIN_HTTP_H_
#define DOOR_CONTROLLER_MAIN_HTTP_H_

#include <stdbool.h>

#define DOOR_HTTP_SUCCESS 0
#define DOOR_HTTP_ERR_FAIL -1
#define DOOR_HTTP_ERR_TIMEOUT -2

/**
 * @brief return false if something goes wrong. Can be called multiple times on one request because of chunked data
 */
typedef bool (* door_http_process_data_cb)(const void* data, const int len);

typedef struct
{
	door_http_process_data_cb data_handler;
} door_http_callback_t;

/**
 * @brief Initializes the door http system
 * @param[in] token The API token to use
 * @return < 0 on failure
 */
int door_http_initialize(const char* token);

/**
 * @brief De-initalizes the http system. If it is to be used again, door_http_init must be called again
 */
void door_http_destroy(void);

/**
 * @brief Performs a get request to the door code server. door_http_free_buffer must be called
 * 			when the callee is done with the data before the next request
 * @param[in] path the path of the url to make the request to
 * @param[in] callbacks http request callbacks to handle getting data etc...
 * @return
 * 		- status code on success
 * 		- < 0 on fail
 */
int door_http_get(const char* path, door_http_callback_t* callbacks);

/**
 * @brief Downloads and updates the next OTA partition from the server.
 * 			Will return false if not connected to WiFi
 * @param[in] api_token the api token to use for authentication/authorization/identification
 * @return
 * 		- true on success
 * 		- false otherwise
 */
bool door_http_ota_update(const char* api_token);

#endif //DOOR_CONTROLLER_MAIN_HTTP_H_