VirtualBox

source: vbox/trunk/include/iprt/http.h@ 73886

Last change on this file since 73886 was 73886, checked in by vboxsync, 6 years ago

IPRT/http: RTHttpDestroy shall return a status. bugref:9167

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/* $Id: http.h 73886 2018-08-25 09:51:12Z vboxsync $ */
2/** @file
3 * IPRT - Simple HTTP/HTTPS Client API.
4 */
5
6/*
7 * Copyright (C) 2012-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___iprt_http_h
28#define ___iprt_http_h
29
30#include <iprt/types.h>
31
32RT_C_DECLS_BEGIN
33
34/** @defgroup grp_rt_http RTHttp - Simple HTTP/HTTPS Client API
35 * @ingroup grp_rt
36 * @{
37 */
38
39/** @todo the following three definitions may move the iprt/types.h later. */
40/** HTTP/HTTPS client handle. */
41typedef R3PTRTYPE(struct RTHTTPINTERNAL *) RTHTTP;
42/** Pointer to a HTTP/HTTPS client handle. */
43typedef RTHTTP *PRTHTTP;
44/** Nil HTTP/HTTPS client handle. */
45#define NIL_RTHTTP ((RTHTTP)0)
46/** Callback function to be called during RTHttpGet*(). Register it using RTHttpSetDownloadProgressCallback(). */
47typedef DECLCALLBACK(void) FNRTHTTPDOWNLDPROGRCALLBACK(RTHTTP hHttp, void *pvUser, uint64_t cbDownloadTotal, uint64_t cbDownloaded);
48typedef FNRTHTTPDOWNLDPROGRCALLBACK *PFNRTHTTPDOWNLDPROGRCALLBACK;
49
50
51
52/**
53 * Creates a HTTP client instance.
54 *
55 * @returns IPRT status code.
56 * @param phHttp Where to store the HTTP handle.
57 */
58RTR3DECL(int) RTHttpCreate(PRTHTTP phHttp);
59
60/**
61 * Resets a HTTP client instance.
62 *
63 * @returns IPRT status code.
64 * @param hHttp Handle to the HTTP interface.
65 */
66RTR3DECL(int) RTHttpReset(RTHTTP hHttp);
67
68/**
69 * Destroys a HTTP client instance.
70 *
71 * @returns IPRT status code.
72 * @param hHttp Handle to the HTTP interface.
73 */
74RTR3DECL(int) RTHttpDestroy(RTHTTP hHttp);
75
76
77/**
78 * Retrieve the redir location for 301 responses.
79 *
80 * @param hHttp Handle to the HTTP interface.
81 * @param ppszRedirLocation Where to store the string. To be freed with
82 * RTStrFree().
83 */
84RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation);
85
86/**
87 * Perform a simple blocking HTTP GET request.
88 *
89 * This is a just a convenient wrapper around RTHttpGetBinary that returns a
90 * different type and sheds a parameter.
91 *
92 * @returns iprt status code.
93 *
94 * @param hHttp The HTTP client instance.
95 * @param pszUrl URL.
96 * @param ppszNotUtf8 Where to return the pointer to the HTTP response.
97 * The string is of course zero terminated. Use
98 * RTHttpFreeReponseText to free.
99 *
100 * @remarks BIG FAT WARNING!
101 *
102 * This function does not guarantee the that returned string is valid UTF-8 or
103 * any other kind of text encoding!
104 *
105 * The caller must determine and validate the string encoding _before_
106 * passing it along to functions that expect UTF-8!
107 *
108 * Also, this function does not guarantee that the returned string
109 * doesn't have embedded zeros and provides the caller no way of
110 * finding out! If you are worried about the response from the HTTPD
111 * containing embedded zero's, use RTHttpGetBinary instead.
112 */
113RTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
114
115/**
116 * Perform a simple blocking HTTP HEAD request.
117 *
118 * This is a just a convenient wrapper around RTHttpGetBinary that returns a
119 * different type and sheds a parameter.
120 *
121 * @returns iprt status code.
122 *
123 * @param hHttp The HTTP client instance.
124 * @param pszUrl URL.
125 * @param ppszNotUtf8 Where to return the pointer to the HTTP response.
126 * The string is of course zero terminated. Use
127 * RTHttpFreeReponseText to free.
128 *
129 * @remarks BIG FAT WARNING!
130 *
131 * This function does not guarantee the that returned string is valid UTF-8 or
132 * any other kind of text encoding!
133 *
134 * The caller must determine and validate the string encoding _before_
135 * passing it along to functions that expect UTF-8!
136 *
137 * Also, this function does not guarantee that the returned string
138 * doesn't have embedded zeros and provides the caller no way of
139 * finding out! If you are worried about the response from the HTTPD
140 * containing embedded zero's, use RTHttpGetHeaderBinary instead.
141 */
142RTR3DECL(int) RTHttpGetHeaderText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
143
144/**
145 * Frees memory returned by RTHttpGetText.
146 *
147 * @param pszNotUtf8 What RTHttpGetText returned.
148 */
149RTR3DECL(void) RTHttpFreeResponseText(char *pszNotUtf8);
150
151/**
152 * Perform a simple blocking HTTP GET request.
153 *
154 * @returns iprt status code.
155 *
156 * @param hHttp The HTTP client instance.
157 * @param pszUrl The URL.
158 * @param ppvResponse Where to store the HTTP response data. Use
159 * RTHttpFreeResponse to free.
160 * @param pcb Size of the returned buffer.
161 */
162RTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
163
164/**
165 * Perform a simple blocking HTTP HEAD request.
166 *
167 * @returns iprt status code.
168 *
169 * @param hHttp The HTTP client instance.
170 * @param pszUrl The URL.
171 * @param ppvResponse Where to store the HTTP response data. Use
172 * RTHttpFreeResponse to free.
173 * @param pcb Size of the returned buffer.
174 */
175RTR3DECL(int) RTHttpGetHeaderBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
176
177/**
178 * Frees memory returned by RTHttpGetBinary.
179 *
180 * @param pvResponse What RTHttpGetBinary returned.
181 */
182RTR3DECL(void) RTHttpFreeResponse(void *pvResponse);
183
184/**
185 * Perform a simple blocking HTTP request, writing the output to a file.
186 *
187 * @returns iprt status code.
188 *
189 * @param hHttp The HTTP client instance.
190 * @param pszUrl The URL.
191 * @param pszDstFile The destination file name.
192 */
193RTR3DECL(int) RTHttpGetFile(RTHTTP hHttp, const char *pszUrl, const char *pszDstFile);
194
195/**
196 * Abort a pending HTTP request. A blocking RTHttpGet() call will return with
197 * VERR_HTTP_ABORTED. It may take some time (current cURL implementation needs
198 * up to 1 second) before the request is aborted.
199 *
200 * @returns iprt status code.
201 *
202 * @param hHttp The HTTP client instance.
203 */
204RTR3DECL(int) RTHttpAbort(RTHTTP hHttp);
205
206/**
207 * Tells the HTTP interface to use the system proxy configuration.
208 *
209 * @returns iprt status code.
210 * @param hHttp The HTTP client instance.
211 */
212RTR3DECL(int) RTHttpUseSystemProxySettings(RTHTTP hHttp);
213
214/**
215 * Specify proxy settings.
216 *
217 * @returns iprt status code.
218 *
219 * @param hHttp The HTTP client instance.
220 * @param pszProxyUrl URL of the proxy server.
221 * @param uPort port number of the proxy, use 0 for not specifying a port.
222 * @param pszProxyUser Username, pass NULL for no authentication.
223 * @param pszProxyPwd Password, pass NULL for no authentication.
224 *
225 * @todo This API does not allow specifying the type of proxy server... We're
226 * currently assuming it's a HTTP proxy.
227 */
228RTR3DECL(int) RTHttpSetProxy(RTHTTP hHttp, const char *pszProxyUrl, uint32_t uPort,
229 const char *pszProxyUser, const char *pszProxyPwd);
230
231/**
232 * Set follow redirects (3xx)
233 *
234 * @returns iprt status code.
235 *
236 * @param hHttp The HTTP client instance.
237 * @param cMaxRedirects Max number of redirects to follow. Zero if no
238 * redirects should be followed but instead returned
239 * to caller.
240 */
241RTR3DECL(int) RTHttpSetFollowRedirects(RTHTTP hHttp, uint32_t cMaxRedirects);
242
243/**
244 * Set custom headers.
245 *
246 * @returns iprt status code.
247 *
248 * @param hHttp The HTTP client instance.
249 * @param cHeaders Number of custom headers.
250 * @param papszHeaders Array of headers in form "foo: bar".
251 */
252RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders);
253
254/**
255 * Tells the HTTP client instance to gather system CA certificates into a
256 * temporary file and use it for HTTPS connections.
257 *
258 * This will be called automatically if a 'https' URL is presented and
259 * RTHttpSetCaFile hasn't been called yet.
260 *
261 * @returns IPRT status code.
262 * @param hHttp The HTTP client instance.
263 * @param pErrInfo Where to store additional error/warning information.
264 * Optional.
265 */
266RTR3DECL(int) RTHttpUseTemporaryCaFile(RTHTTP hHttp, PRTERRINFO pErrInfo);
267
268/**
269 * Set a custom certification authority file, containing root certificates.
270 *
271 * @returns iprt status code.
272 *
273 * @param hHttp The HTTP client instance.
274 * @param pszCAFile File name containing root certificates.
275 *
276 * @remarks For portable HTTPS support, use RTHttpGatherCaCertsInFile and pass
277 */
278RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pszCAFile);
279
280/**
281 * Gathers certificates into a cryptographic (certificate) store
282 *
283 * This is a just a combination of RTHttpGatherCaCertsInStore and
284 * RTCrStoreCertExportAsPem.
285 *
286 * @returns IPRT status code.
287 * @param hStore The certificate store to gather the certificates
288 * in.
289 * @param fFlags RTHTTPGATHERCACERT_F_XXX.
290 * @param pErrInfo Where to store additional error/warning information.
291 * Optional.
292 */
293RTR3DECL(int) RTHttpGatherCaCertsInStore(RTCRSTORE hStore, uint32_t fFlags, PRTERRINFO pErrInfo);
294
295/**
296 * Gathers certificates into a file that can be used with RTHttpSetCAFile.
297 *
298 * This is a just a combination of RTHttpGatherCaCertsInStore and
299 * RTCrStoreCertExportAsPem.
300 *
301 * @returns IPRT status code.
302 * @param pszCaFile The output file.
303 * @param fFlags RTHTTPGATHERCACERT_F_XXX.
304 * @param pErrInfo Where to store additional error/warning information.
305 * Optional.
306 */
307RTR3DECL(int) RTHttpGatherCaCertsInFile(const char *pszCaFile, uint32_t fFlags, PRTERRINFO pErrInfo);
308
309/**
310 * Set a callback function which is called during RTHttpGet*()
311 *
312 * @returns IPRT status code.
313 * @param hHttp The HTTP client instance.
314 * @param pfnDownloadProgress Progress function to be called. Set it to
315 * NULL to disable the callback.
316 * @param pvUser Convenience pointer for the callback function.
317 */
318RTR3DECL(int) RTHttpSetDownloadProgressCallback(RTHTTP hHttp, PFNRTHTTPDOWNLDPROGRCALLBACK pfnDownloadProgress, void *pvUser);
319
320
321/** @name thin wrappers for setting one or a few related curl options
322 * @remarks Subject to change.
323 * @{ */
324typedef size_t FNRTHTTPREADCALLBACK(void *pbDst, size_t cbItem, size_t cItems, void *pvUser);
325typedef FNRTHTTPREADCALLBACK *PFNRTHTTPREADCALLBACK;
326
327#define RT_HTTP_READCALLBACK_ABORT 0x10000000 /* CURL_READFUNC_ABORT */
328
329RTR3DECL(int) RTHttpSetReadCallback(RTHTTP hHttp, PFNRTHTTPREADCALLBACK pfnRead, void *pvUser);
330
331
332typedef size_t FNRTHTTPWRITECALLBACK(char *pbSrc, size_t cbItem, size_t cItems, void *pvUser);
333typedef FNRTHTTPWRITECALLBACK *PFNRTHTTPWRITECALLBACK;
334
335RTR3DECL(int) RTHttpSetWriteCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACK pfnWrite, void *pvUser);
336RTR3DECL(int) RTHttpSetWriteHeaderCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACK pfnWrite, void *pvUser);
337
338
339RTR3DECL(int) RTHttpRawSetUrl(RTHTTP hHttp, const char *pszUrl);
340
341RTR3DECL(int) RTHttpRawSetGet(RTHTTP hHttp);
342RTR3DECL(int) RTHttpRawSetHead(RTHTTP hHttp);
343RTR3DECL(int) RTHttpRawSetPost(RTHTTP hHttp);
344RTR3DECL(int) RTHttpRawSetPut(RTHTTP hHttp);
345RTR3DECL(int) RTHttpRawSetDelete(RTHTTP hHttp);
346RTR3DECL(int) RTHttpRawSetCustomRequest(RTHTTP hHttp, const char *pszVerb);
347
348RTR3DECL(int) RTHttpRawSetPostFields(RTHTTP hHttp, const void *pv, size_t cb);
349RTR3DECL(int) RTHttpRawSetInfileSize(RTHTTP hHttp, RTFOFF cb);
350
351RTR3DECL(int) RTHttpRawSetVerbose(RTHTTP hHttp, bool fValue);
352RTR3DECL(int) RTHttpRawSetTimeout(RTHTTP hHttp, long sec);
353
354RTR3DECL(int) RTHttpRawPerform(RTHTTP hHttp);
355
356RTR3DECL(int) RTHttpRawGetResponseCode(RTHTTP hHttp, long *plCode);
357/** @} */
358
359/** @} */
360
361RT_C_DECLS_END
362
363#endif
364
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette