-
Notifications
You must be signed in to change notification settings - Fork 589
/
Copy pathcurl4nx.h
310 lines (268 loc) · 9.66 KB
/
curl4nx.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/****************************************************************************
* apps/include/netutils/curl4nx.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __APPS_INCLUDE_NETUTILS_CURL4NX_H
#define __APPS_INCLUDE_NETUTILS_CURL4NX_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Public Defines
****************************************************************************/
enum curl4nxerrors_e
{
CURL4NXE_OK,
CURL4NXE_UNSUPPORTED_PROTOCOL,
CURL4NXE_FAILED_INIT,
CURL4NXE_URL_MALFORMAT,
CURL4NXE_NOT_BUILT_IN,
CURL4NXE_COULDNT_RESOLVE_HOST,
CURL4NXE_COULDNT_CONNECT,
CURL4NXE_HTTP2,
CURL4NXE_PARTIAL_FILE,
CURL4NXE_HTTP_RETURNED_ERROR,
CURL4NXE_WRITE_ERROR,
CURL4NXE_UPLOAD_FAILED,
CURL4NXE_READ_ERROR,
CURL4NXE_OUT_OF_MEMORY,
CURL4NXE_OPERATION_TIMEDOUT,
CURL4NXE_RANGE_ERROR,
CURL4NXE_HTTP_POST_ERROR,
CURL4NXE_SSL_CONNECT_ERROR,
CURL4NXE_BAD_DOWNLOAD_RESUME,
CURL4NXE_FUNCTION_NOT_FOUND,
CURL4NXE_ABORTED_BY_CALLBACK,
CURL4NXE_BAD_FUNCTION_ARGUMENT,
CURL4NXE_TOO_MANY_REDIRECTS,
CURL4NXE_UNKNOWN_OPTION,
CURL4NXE_GOT_NOTHING,
CURL4NXE_SEND_ERROR,
CURL4NXE_RECV_ERROR,
CURL4NXE_SSL_CERTPROBLEM,
CURL4NXE_SSL_CIPHER,
CURL4NXE_PEER_FAILED_VERIFICATION,
CURL4NXE_BAD_CONTENT_ENCODING,
CURL4NXE_LOGIN_DENIED,
CURL4NXE_REMOTE_DISK_FULL,
CURL4NXE_REMOTE_FILE_EXISTS,
CURL4NXE_SSL_CACERT_BADFILE,
CURL4NXE_REMOTE_FILE_NOT_FOUND,
CURL4NXE_AGAIN,
CURL4NXE_SSL_ISSUER_ERROR,
CURL4NXE_CHUNK_FAILED,
CURL4NXE_SSL_PINNEDPUBKEYNOTMATCH,
CURL4NXE_SSL_INVALIDCERTSTATUS,
CURL4NXE_HTTP2_STREAM,
CURL4NXE_RECURSIVE_API_CALL,
};
enum curl4nxopt_e
{
/* Options that are currently implemented */
CURL4NXOPT_URL,
CURL4NXOPT_PORT,
CURL4NXOPT_BUFFERSIZE,
CURL4NXOPT_HEADERFUNCTION,
CURL4NXOPT_HEADERDATA,
CURL4NXOPT_FAILONERROR,
CURL4NXOPT_FOLLOWLOCATION,
CURL4NXOPT_MAXREDIRS,
CURL4NXOPT_VERBOSE,
/* Options that will be implemented */
CURL4NXOPT_HEADER,
CURL4NXOPT_NOPROGRESS,
CURL4NXOPT_WRITEFUNCTION,
CURL4NXOPT_WRITEDATA,
CURL4NXOPT_READFUNCTION,
CURL4NXOPT_READDATA,
CURL4NXOPT_XFERINFOFUNCTION,
CURL4NXOPT_XFERINFODATA,
CURL4NXOPT_KEEP_SENDING_ON_ERROR,
CURL4NXOPT_PATH_AS_IS,
CURL4NXOPT_TCP_KEEPALIVE,
CURL4NXOPT_TCP_KEEPIDLE,
CURL4NXOPT_TCP_KEEPINTVL,
CURL4NXOPT_PUT,
CURL4NXOPT_POST,
CURL4NXOPT_POSTFIELDS,
CURL4NXOPT_POSTFIELDSIZE,
CURL4NXOPT_COPYPOSTFIELDS,
CURL4NXOPT_HTTPPOST,
CURL4NXOPT_REFERER,
CURL4NXOPT_USERAGENT,
CURL4NXOPT_HTTPHEADER,
CURL4NXOPT_HEADEROPT,
CURL4NXOPT_HTTPGET,
CURL4NXOPT_HTTP_VERSION,
/* Options that will be implemented later */
CURL4NXOPT_SSL_CTX_FUNCTION,
CURL4NXOPT_SSL_CTX_DATA,
CURL4NXOPT_USERNAME,
CURL4NXOPT_PASSWORD,
CURL4NXOPT_HTTPAUTH,
CURL4NXOPT_POSTREDIR,
CURL4NXOPT_COOKIE,
CURL4NXOPT_COOKIEFILE,
CURL4NXOPT_COOKIEJAR,
CURL4NXOPT_COOKIESESSION,
CURL4NXOPT_COOKIELIST,
CURL4NXOPT_IGNORE_CONTENT_LENGTH,
CURL4NXOPT_RANGE,
CURL4NXOPT_RESUME_FROM,
CURL4NXOPT_CUSTOMREQUEST,
CURL4NXOPT_UPLOAD,
CURL4NXOPT_UPLOAD_BUFFERSIZE,
CURL4NXOPT_TIMEOUT,
CURL4NXOPT_TIMEOUT_MS,
CURL4NXOPT_FRESH_CONNECT,
CURL4NXOPT_CONNECTTIMEOUT,
CURL4NXOPT_CONNECTTIMEOUT_MS,
CURL4NXOPT_USE_SSL,
CURL4NXOPT_SSLCERT,
CURL4NXOPT_SSLKEY,
CURL4NXOPT_KEYPASSWD,
CURL4NXOPT_SSLVERSION,
CURL4NXOPT_SSL_VERIFYHOST,
CURL4NXOPT_SSL_VERIFYPEER,
CURL4NXOPT_SSL_VERIFYSTATUS,
CURL4NXOPT_CAPATH,
CURL4NXOPT_PINNEDPUBLICKEY,
CURL4NXOPT_RANDOM_FILE,
CURL4NXOPT_SSL_CIPHER_LIST,
CURL4NXOPT_TLS13_CIPHERS,
CURL4NXOPT_SSL_OPTIONS,
};
/* For CURL4NXOPT_HTTP_VERSION */
#define CURL4NX_HTTP_VERSION_1_0 0x10
#define CURL4NX_HTTP_VERSION_1_1 0x11
#define CURL4NX_HTTP_VERSION_2_0 0x20 /* Unsupported! */
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Name: curl4nx_iofunction_f
*
* Description: Type of the callback function used with
* CURL4NXOPT_WRITEFUNCTION and CURL4NXOPT_READFUNCTION.
*
****************************************************************************/
typedef size_t (*curl4nx_iofunc_f)(FAR char *ptr, size_t size,
size_t nmemb, FAR void *userdata);
/****************************************************************************
* Name: curl4nx_easy_strerror()
*
* Description: Return a textual description for an error code.
*
****************************************************************************/
typedef int (*curl4nx_xferinfofunc_f)(FAR void *clientp,
uint64_t dltotal, uint64_t dlnow,
uint64_t ultotal, uint64_t ulnow);
#ifdef __cplusplus
extern "C"
{
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: curl4nx_easy_strerror()
*
* Description: Return a textual description for an error code.
*
****************************************************************************/
FAR const char *curl4nx_easy_strerror(int errornum);
/****************************************************************************
* Name: curl4nx_easy_init()
*
* Description: Initialize a context for curl4nx operations.
*
****************************************************************************/
FAR struct curl4nx_s *curl4nx_easy_init(void);
/****************************************************************************
* Name: curl4nx_easy_escape()
*
* Description: Escape an URL to remove any forbidden character. Returned
* string MUST be released using free().
*
****************************************************************************/
FAR char *curl4nx_easy_escape(FAR struct curl4nx_s *handle,
FAR const char *string, int length);
/****************************************************************************
* Name: curl4nx_easy_unescape()
*
* Description: Unescape an escaped URL to replace all escaped characters.
* Returned string MUST be released using free().
*
****************************************************************************/
FAR char *curl4nx_easy_unescape(FAR struct curl4nx_s *handle,
FAR const char *url, int inlength,
FAR int *outlength);
/****************************************************************************
* Name: curl4nx_easy_setopt()
*
* Description: Define an option in the given curl4nx context.
*
****************************************************************************/
int curl4nx_easy_setopt(FAR struct curl4nx_s *handle, int option,
FAR void *optionptr);
/****************************************************************************
* Name: curl4nx_easy_reset()
*
* Description:
* Reset all operations that were set using curl4nx_easy_setopt()
* to their default values.
*
****************************************************************************/
void curl4nx_easy_reset(FAR struct curl4nx_s *handle);
/****************************************************************************
* Name: curl4nx_easy_duphandle()
*
* Description: Clone the current state of a handle.
*
****************************************************************************/
FAR struct curl4nx_s *curl4nx_easy_duphandle(FAR struct curl4nx_s *handle);
/****************************************************************************
* Name: curl4nx_easy_perform()
*
* Description: Perform the http operation that was set up in this curl4nx
* context.
*
****************************************************************************/
int curl4nx_easy_perform(FAR struct curl4nx_s *handle);
/****************************************************************************
* Name: curl4nx_easy_getinfo()
*
* Description: Get information about the current transfer.
*
****************************************************************************/
int curl4nx_easy_getinfo(FAR struct curl4nx_s *handle, int info,
FAR void *infoptr);
/****************************************************************************
* Name: curl4nx_easy_cleanup()
*
* Description: Cleanup any resource allocated within a curl4nx context.
*
****************************************************************************/
void curl4nx_easy_cleanup(FAR struct curl4nx_s *handle);
#ifdef __cplusplus
}
#endif
#endif /* __APPS_INCLUDE_NETUTILS_BASE64_H */