#ifndef DOOR_CONTROLLER_MAIN_HTTP_H_ #define DOOR_CONTROLLER_MAIN_HTTP_H_ #include #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_