[453] | 1 | // Copyright (c) Microsoft. All rights reserved.
|
---|
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
---|
| 3 |
|
---|
| 4 | #ifndef UHTTP_H
|
---|
| 5 | #define UHTTP_H
|
---|
| 6 |
|
---|
| 7 | #ifdef __cplusplus
|
---|
| 8 | extern "C" {
|
---|
| 9 | #include <cstddef>
|
---|
| 10 | #else
|
---|
| 11 | #include <stddef.h>
|
---|
| 12 | #include <stdbool.h>
|
---|
| 13 | #endif /* __cplusplus */
|
---|
| 14 |
|
---|
| 15 | #include "azure_c_shared_utility/httpheaders.h"
|
---|
| 16 | #include "azure_macro_utils/macro_utils.h"
|
---|
| 17 | #include "azure_c_shared_utility/xio.h"
|
---|
| 18 | #include "umock_c/umock_c_prod.h"
|
---|
| 19 |
|
---|
| 20 | typedef struct HTTP_CLIENT_HANDLE_DATA_TAG* HTTP_CLIENT_HANDLE;
|
---|
| 21 |
|
---|
| 22 | #define HTTP_CLIENT_RESULT_VALUES \
|
---|
| 23 | HTTP_CLIENT_OK, \
|
---|
| 24 | HTTP_CLIENT_INVALID_ARG, \
|
---|
| 25 | HTTP_CLIENT_ERROR, \
|
---|
| 26 | HTTP_CLIENT_OPEN_FAILED, \
|
---|
| 27 | HTTP_CLIENT_SEND_FAILED, \
|
---|
| 28 | HTTP_CLIENT_ALREADY_INIT, \
|
---|
| 29 | HTTP_CLIENT_HTTP_HEADERS_FAILED, \
|
---|
| 30 | HTTP_CLIENT_INVALID_STATE \
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | /** @brief Enumeration specifying the possible return values for the APIs in
|
---|
| 34 | * this module.
|
---|
| 35 | */
|
---|
| 36 | MU_DEFINE_ENUM(HTTP_CLIENT_RESULT, HTTP_CLIENT_RESULT_VALUES);
|
---|
| 37 |
|
---|
| 38 | #define HTTP_CLIENT_REQUEST_TYPE_VALUES \
|
---|
| 39 | HTTP_CLIENT_REQUEST_OPTIONS, \
|
---|
| 40 | HTTP_CLIENT_REQUEST_GET, \
|
---|
| 41 | HTTP_CLIENT_REQUEST_POST, \
|
---|
| 42 | HTTP_CLIENT_REQUEST_PUT, \
|
---|
| 43 | HTTP_CLIENT_REQUEST_DELETE, \
|
---|
| 44 | HTTP_CLIENT_REQUEST_PATCH
|
---|
| 45 |
|
---|
| 46 | MU_DEFINE_ENUM(HTTP_CLIENT_REQUEST_TYPE, HTTP_CLIENT_REQUEST_TYPE_VALUES);
|
---|
| 47 |
|
---|
| 48 | #define HTTP_CALLBACK_REASON_VALUES \
|
---|
| 49 | HTTP_CALLBACK_REASON_OK, \
|
---|
| 50 | HTTP_CALLBACK_REASON_OPEN_FAILED, \
|
---|
| 51 | HTTP_CALLBACK_REASON_SEND_FAILED, \
|
---|
| 52 | HTTP_CALLBACK_REASON_ERROR, \
|
---|
| 53 | HTTP_CALLBACK_REASON_PARSING_ERROR, \
|
---|
| 54 | HTTP_CALLBACK_REASON_DESTROY, \
|
---|
| 55 | HTTP_CALLBACK_REASON_DISCONNECTED
|
---|
| 56 |
|
---|
| 57 | MU_DEFINE_ENUM(HTTP_CALLBACK_REASON, HTTP_CALLBACK_REASON_VALUES);
|
---|
| 58 |
|
---|
| 59 | typedef void(*ON_HTTP_OPEN_COMPLETE_CALLBACK)(void* callback_ctx, HTTP_CALLBACK_REASON open_result);
|
---|
| 60 | typedef void(*ON_HTTP_ERROR_CALLBACK)(void* callback_ctx, HTTP_CALLBACK_REASON error_result);
|
---|
| 61 | typedef void(*ON_HTTP_REQUEST_CALLBACK)(void* callback_ctx, HTTP_CALLBACK_REASON request_result, const unsigned char* content, size_t content_length, unsigned int status_code,
|
---|
| 62 | HTTP_HEADERS_HANDLE response_headers);
|
---|
| 63 | typedef void(*ON_HTTP_CLOSED_CALLBACK)(void* callback_ctx);
|
---|
| 64 |
|
---|
| 65 | MOCKABLE_FUNCTION(, HTTP_CLIENT_HANDLE, uhttp_client_create, const IO_INTERFACE_DESCRIPTION*, io_interface_desc, const void*, xio_param, ON_HTTP_ERROR_CALLBACK, on_http_error, void*, callback_ctx);
|
---|
| 66 | MOCKABLE_FUNCTION(, void, uhttp_client_destroy, HTTP_CLIENT_HANDLE, handle);
|
---|
| 67 | MOCKABLE_FUNCTION(, HTTP_CLIENT_RESULT, uhttp_client_open, HTTP_CLIENT_HANDLE, handle, const char*, host, int, port_num, ON_HTTP_OPEN_COMPLETE_CALLBACK, on_connect, void*, callback_ctx);
|
---|
| 68 | MOCKABLE_FUNCTION(, void, uhttp_client_close, HTTP_CLIENT_HANDLE, handle, ON_HTTP_CLOSED_CALLBACK, on_close_callback, void*, callback_ctx);
|
---|
| 69 | MOCKABLE_FUNCTION(, HTTP_CLIENT_RESULT, uhttp_client_execute_request, HTTP_CLIENT_HANDLE, handle, HTTP_CLIENT_REQUEST_TYPE, request_type, const char*, relative_path,
|
---|
| 70 | HTTP_HEADERS_HANDLE, http_header_handle, const unsigned char*, content, size_t, content_length, ON_HTTP_REQUEST_CALLBACK, on_request_callback, void*, callback_ctx);
|
---|
| 71 |
|
---|
| 72 | MOCKABLE_FUNCTION(, void, uhttp_client_dowork, HTTP_CLIENT_HANDLE, handle);
|
---|
| 73 |
|
---|
| 74 | MOCKABLE_FUNCTION(, HTTP_CLIENT_RESULT, uhttp_client_set_trace, HTTP_CLIENT_HANDLE, handle, bool, trace_on, bool, trace_data);
|
---|
| 75 | MOCKABLE_FUNCTION(, HTTP_CLIENT_RESULT, uhttp_client_set_X509_cert, HTTP_CLIENT_HANDLE, handle, bool, ecc_type, const char*, certificate, const char*, private_key);
|
---|
| 76 | MOCKABLE_FUNCTION(, HTTP_CLIENT_RESULT, uhttp_client_set_trusted_cert, HTTP_CLIENT_HANDLE, handle, const char*, certificate);
|
---|
| 77 | MOCKABLE_FUNCTION(, const char*, uhttp_client_get_trusted_cert, HTTP_CLIENT_HANDLE, handle);
|
---|
| 78 | MOCKABLE_FUNCTION(, HTTP_CLIENT_RESULT, uhttp_client_set_option, HTTP_CLIENT_HANDLE, handle, const char*, optionName, const void*, value);
|
---|
| 79 | MOCKABLE_FUNCTION(, XIO_HANDLE, uhttp_client_get_underlying_xio, HTTP_CLIENT_HANDLE, handle);
|
---|
| 80 |
|
---|
| 81 | #ifdef __cplusplus
|
---|
| 82 | }
|
---|
| 83 | #endif /* __cplusplus */
|
---|
| 84 |
|
---|
| 85 | #endif /* UHTTP_H */
|
---|