-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathazure_iot_http.h
145 lines (133 loc) · 5.58 KB
/
azure_iot_http.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License. */
/**
* @file azure_iot_http.h
*
* @brief The port file for HTTP APIs.
*
* Used in ADU.
*
*/
#ifndef AZURE_IOT_HTTP_H
#define AZURE_IOT_HTTP_H
#include <stdint.h>
#include "azure_iot_http_port.h"
#include "azure_iot_transport_interface.h"
/**
* @brief Value to request the end of the file.
*
*/
#define azureiothttpHttpRangeRequestEndOfFile -1
/**
* @brief The handle for the Azure HTTP client.
*
*/
typedef AzureIoTHTTP_t * AzureIoTHTTPHandle_t;
/**
* @brief Azure HTTP return codes.
*
*/
typedef enum AzureIoTHTTPResult
{
eAzureIoTHTTPSuccess = 0,
eAzureIoTHTTPInvalidParameter,
eAzureIoTHTTPNetworkError,
eAzureIoTHTTPPartialResponse,
eAzureIoTHTTPNoResponse,
eAzureIoTHTTPInsufficientMemory,
eAzureIoTHTTPSecurityAlertResponseHeadersSizeLimitExceeded,
eAzureIoTHTTPSecurityAlertExtraneousResponseData,
eAzureIoTHTTPSecurityAlertInvalidChunkHeader,
eAzureIoTHTTPSecurityAlertInvalidProtocolVersion,
eAzureIoTHTTPSecurityAlertInvalidStatusCode,
eAzureIoTHTTPSecurityAlertInvalidCharacter,
eAzureIoTHTTPSecurityAlertInvalidContentLength,
eAzureIoTHTTPParserInternalError,
eAzureIoTHTTPHeaderNotFound,
eAzureIoTHTTPInvalidResponse,
eAzureIoTHTTPError
} AzureIoTHTTPResult_t;
/**
* @brief Initialize the Azure HTTP client.
*
* @param[in] xHTTPHandle The HTTP handle to use for this operation.
* @param[in] pxHTTPTransport The Azure IoT Transport interface to use for this operation.
* @param[in] pucURL The URL to use for this request.
* @param[in] ulURLLength The length \p pucURL.
* @param[in] pucPath The path to use for this request.
* @param[in] ulPathLength The length \p pucPath.
* @param[out] pucHeaderBuffer The buffer into which the headers for the request will be placed.
* @param[in] ulHeaderBufferLength The length of \p pucHeaderBuffer.
* @return AzureIoTHTTPResult_t
*/
AzureIoTHTTPResult_t AzureIoTHTTP_Init( AzureIoTHTTPHandle_t xHTTPHandle,
AzureIoTTransportInterface_t * pxHTTPTransport,
const char * pucURL,
uint32_t ulURLLength,
const char * pucPath,
uint32_t ulPathLength,
char * pucHeaderBuffer,
uint32_t ulHeaderBufferLength );
/**
* @brief Send an HTTP GET request.
*
* @param[in] xHTTPHandle The HTTP handle to use for this operation.
* @param[in] lRangeStart The start point for the request payload.
* @param[in] lRangeEnd The end point for the request payload.
* @param[out] pucDataBuffer The buffer into which the response header and payload will be placed.
* @param[in] ulDataBufferLength The length of \p pucDataBuffer.
* @param[out] ppucOutData The pointer to the point in the buffer where the payload starts.
* @param[out] pulOutDataLength The length of the payload returned by \p ppucOutData.
* @return AzureIoTHTTPResult_t
*/
AzureIoTHTTPResult_t AzureIoTHTTP_Request( AzureIoTHTTPHandle_t xHTTPHandle,
int32_t lRangeStart,
int32_t lRangeEnd,
char * pucDataBuffer,
uint32_t ulDataBufferLength,
char ** ppucOutData,
uint32_t * pulOutDataLength );
/**
* @brief Initialize a size request.
*
* @param[in] xHTTPHandle The HTTP handle to use for this operation.
* @param[in] pxHTTPTransport The Azure IoT Transport interface to use for this operation.
* @param[in] pucURL The URL to use for this request.
* @param[in] ulURLLength The length \p pucURL.
* @param[in] pucPath The path to use for this request.
* @param[in] ulPathLength The length \p pucPath.
* @param[out] pucHeaderBuffer The buffer into which the response will be placed.
* @param[in] ulHeaderBufferLength The size of \p pucHeaderBuffer.
* @return AzureIoTHTTPResult_t
*/
AzureIoTHTTPResult_t AzureIoTHTTP_RequestSizeInit( AzureIoTHTTPHandle_t xHTTPHandle,
AzureIoTTransportInterface_t * pxHTTPTransport,
const char * pucURL,
uint32_t ulURLLength,
const char * pucPath,
uint32_t ulPathLength,
char * pucHeaderBuffer,
uint32_t ulHeaderBufferLength );
/**
* @brief Send a size request.
*
* @param[in] xHTTPHandle The HTTP handle to use for this operation.
* @param[out] pucDataBuffer The buffer where the response will be placed.
* @param[in] ulDataBufferLength The size of \p pucDataBuffer.
* @return int32_t
* @retval The size of the file if success.
* @retval -1 if failure.
*/
int32_t AzureIoTHTTP_RequestSize( AzureIoTHTTPHandle_t xHTTPHandle,
char * pucDataBuffer,
uint32_t ulDataBufferLength );
/**
* @brief Deinitialize the Azure HTTP client.
*
* @param[in] xHTTPHandle The HTTP handle to use for this operation.
* @return AzureIoTHTTPResult_t
* @retval eAzureIoTHTTPSuccess if success.
* @retval Otherwise if failure.
*/
AzureIoTHTTPResult_t AzureIoTHTTP_Deinit( AzureIoTHTTPHandle_t xHTTPHandle );
#endif /* AZURE_IOT_HTTP_H */