VirtualBox

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

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

IPRT: Added RTHttpSetFollowRedirects (translates to CURLOPT_FOLLOWLOCATION+CURLOPT_MAXREDIRS) and make use of it RTDbgCfg and RTHttp[.exe]. This should fix the current pdb download issues as we're getting 302 redirects from the servers. Also, changed RTHttp to return VERR_HTTP_REDIRECTED when receiving 302, 303, 307 & 308 HTTP statuses.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1/* $Id: http.h 73334 2018-07-23 16:52:04Z 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) RTHTTPDOWNLDPROGRCALLBACK(RTHTTP hHttp, void *pvUser, uint64_t cbDownloadTotal, uint64_t cbDownloaded);
48typedef RTHTTPDOWNLDPROGRCALLBACK *PRTHTTPDOWNLDPROGRCALLBACK;
49
50
51
52/**
53 * Creates a HTTP client instance.
54 *
55 * @returns iprt status code.
56 *
57 * @param phHttp Where to store the HTTP handle.
58 */
59RTR3DECL(int) RTHttpCreate(PRTHTTP phHttp);
60
61/**
62 * Destroys a HTTP client instance.
63 *
64 * @param hHttp Handle to the HTTP interface.
65 */
66RTR3DECL(void) RTHttpDestroy(RTHTTP hHttp);
67
68
69/**
70 * Retrieve the redir location for 301 responses.
71 *
72 * @param hHttp Handle to the HTTP interface.
73 * @param ppszRedirLocation Where to store the string. To be freed with
74 * RTStrFree().
75 */
76RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation);
77
78/**
79 * Perform a simple blocking HTTP GET request.
80 *
81 * This is a just a convenient wrapper around RTHttpGetBinary that returns a
82 * different type and sheds a parameter.
83 *
84 * @returns iprt status code.
85 *
86 * @param hHttp The HTTP client instance.
87 * @param pszUrl URL.
88 * @param ppszNotUtf8 Where to return the pointer to the HTTP response.
89 * The string is of course zero terminated. Use
90 * RTHttpFreeReponseText to free.
91 *
92 * @remarks BIG FAT WARNING!
93 *
94 * This function does not guarantee the that returned string is valid UTF-8 or
95 * any other kind of text encoding!
96 *
97 * The caller must determine and validate the string encoding _before_
98 * passing it along to functions that expect UTF-8!
99 *
100 * Also, this function does not guarantee that the returned string
101 * doesn't have embedded zeros and provides the caller no way of
102 * finding out! If you are worried about the response from the HTTPD
103 * containing embedded zero's, use RTHttpGetBinary instead.
104 */
105RTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
106
107/**
108 * Perform a simple blocking HTTP HEAD request.
109 *
110 * This is a just a convenient wrapper around RTHttpGetBinary that returns a
111 * different type and sheds a parameter.
112 *
113 * @returns iprt status code.
114 *
115 * @param hHttp The HTTP client instance.
116 * @param pszUrl URL.
117 * @param ppszNotUtf8 Where to return the pointer to the HTTP response.
118 * The string is of course zero terminated. Use
119 * RTHttpFreeReponseText to free.
120 *
121 * @remarks BIG FAT WARNING!
122 *
123 * This function does not guarantee the that returned string is valid UTF-8 or
124 * any other kind of text encoding!
125 *
126 * The caller must determine and validate the string encoding _before_
127 * passing it along to functions that expect UTF-8!
128 *
129 * Also, this function does not guarantee that the returned string
130 * doesn't have embedded zeros and provides the caller no way of
131 * finding out! If you are worried about the response from the HTTPD
132 * containing embedded zero's, use RTHttpGetHeaderBinary instead.
133 */
134RTR3DECL(int) RTHttpGetHeaderText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
135
136/**
137 * Frees memory returned by RTHttpGetText.
138 *
139 * @param pszNotUtf8 What RTHttpGetText returned.
140 */
141RTR3DECL(void) RTHttpFreeResponseText(char *pszNotUtf8);
142
143/**
144 * Perform a simple blocking HTTP GET request.
145 *
146 * @returns iprt status code.
147 *
148 * @param hHttp The HTTP client instance.
149 * @param pszUrl The URL.
150 * @param ppvResponse Where to store the HTTP response data. Use
151 * RTHttpFreeResponse to free.
152 * @param pcb Size of the returned buffer.
153 */
154RTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
155
156/**
157 * Perform a simple blocking HTTP HEAD request.
158 *
159 * @returns iprt status code.
160 *
161 * @param hHttp The HTTP client instance.
162 * @param pszUrl The URL.
163 * @param ppvResponse Where to store the HTTP response data. Use
164 * RTHttpFreeResponse to free.
165 * @param pcb Size of the returned buffer.
166 */
167RTR3DECL(int) RTHttpGetHeaderBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
168
169/**
170 * Frees memory returned by RTHttpGetBinary.
171 *
172 * @param pvResponse What RTHttpGetBinary returned.
173 */
174RTR3DECL(void) RTHttpFreeResponse(void *pvResponse);
175
176/**
177 * Perform a simple blocking HTTP request, writing the output to a file.
178 *
179 * @returns iprt status code.
180 *
181 * @param hHttp The HTTP client instance.
182 * @param pszUrl The URL.
183 * @param pszDstFile The destination file name.
184 */
185RTR3DECL(int) RTHttpGetFile(RTHTTP hHttp, const char *pszUrl, const char *pszDstFile);
186
187/**
188 * Abort a pending HTTP request. A blocking RTHttpGet() call will return with
189 * VERR_HTTP_ABORTED. It may take some time (current cURL implementation needs
190 * up to 1 second) before the request is aborted.
191 *
192 * @returns iprt status code.
193 *
194 * @param hHttp The HTTP client instance.
195 */
196RTR3DECL(int) RTHttpAbort(RTHTTP hHttp);
197
198/**
199 * Tells the HTTP interface to use the system proxy configuration.
200 *
201 * @returns iprt status code.
202 * @param hHttp The HTTP client instance.
203 */
204RTR3DECL(int) RTHttpUseSystemProxySettings(RTHTTP hHttp);
205
206/**
207 * Specify proxy settings.
208 *
209 * @returns iprt status code.
210 *
211 * @param hHttp The HTTP client instance.
212 * @param pszProxyUrl URL of the proxy server.
213 * @param uPort port number of the proxy, use 0 for not specifying a port.
214 * @param pszProxyUser Username, pass NULL for no authentication.
215 * @param pszProxyPwd Password, pass NULL for no authentication.
216 *
217 * @todo This API does not allow specifying the type of proxy server... We're
218 * currently assuming it's a HTTP proxy.
219 */
220RTR3DECL(int) RTHttpSetProxy(RTHTTP hHttp, const char *pszProxyUrl, uint32_t uPort,
221 const char *pszProxyUser, const char *pszProxyPwd);
222
223/**
224 * Set follow redirects (3xx)
225 *
226 * @returns iprt status code.
227 *
228 * @param hHttp The HTTP client instance.
229 * @param cMaxRedirects Max number of redirects to follow. Zero if no
230 * redirects should be followed but instead returned
231 * to caller.
232 */
233RTR3DECL(int) RTHttpSetFollowRedirects(RTHTTP hHttp, uint32_t cMaxRedirects);
234
235/**
236 * Set custom headers.
237 *
238 * @returns iprt status code.
239 *
240 * @param hHttp The HTTP client instance.
241 * @param cHeaders Number of custom headers.
242 * @param papszHeaders Array of headers in form "foo: bar".
243 */
244RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders);
245
246/**
247 * Tells the HTTP client instance to gather system CA certificates into a
248 * temporary file and use it for HTTPS connections.
249 *
250 * This will be called automatically if a 'https' URL is presented and
251 * RTHttpSetCaFile hasn't been called yet.
252 *
253 * @returns IPRT status code.
254 * @param hHttp The HTTP client instance.
255 * @param pErrInfo Where to store additional error/warning information.
256 * Optional.
257 */
258RTR3DECL(int) RTHttpUseTemporaryCaFile(RTHTTP hHttp, PRTERRINFO pErrInfo);
259
260/**
261 * Set a custom certification authority file, containing root certificates.
262 *
263 * @returns iprt status code.
264 *
265 * @param hHttp The HTTP client instance.
266 * @param pszCAFile File name containing root certificates.
267 *
268 * @remarks For portable HTTPS support, use RTHttpGatherCaCertsInFile and pass
269 */
270RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pszCAFile);
271
272/**
273 * Gathers certificates into a cryptographic (certificate) store
274 *
275 * This is a just a combination of RTHttpGatherCaCertsInStore and
276 * RTCrStoreCertExportAsPem.
277 *
278 * @returns IPRT status code.
279 * @param hStore The certificate store to gather the certificates
280 * in.
281 * @param fFlags RTHTTPGATHERCACERT_F_XXX.
282 * @param pErrInfo Where to store additional error/warning information.
283 * Optional.
284 */
285RTR3DECL(int) RTHttpGatherCaCertsInStore(RTCRSTORE hStore, uint32_t fFlags, PRTERRINFO pErrInfo);
286
287/**
288 * Gathers certificates into a file that can be used with RTHttpSetCAFile.
289 *
290 * This is a just a combination of RTHttpGatherCaCertsInStore and
291 * RTCrStoreCertExportAsPem.
292 *
293 * @returns IPRT status code.
294 * @param pszCaFile The output file.
295 * @param fFlags RTHTTPGATHERCACERT_F_XXX.
296 * @param pErrInfo Where to store additional error/warning information.
297 * Optional.
298 */
299RTR3DECL(int) RTHttpGatherCaCertsInFile(const char *pszCaFile, uint32_t fFlags, PRTERRINFO pErrInfo);
300
301/**
302 * Set a callback function which is called during RTHttpGet*()
303 *
304 * @returns IPRT status code.
305 * @param hHttp The HTTP client instance.
306 * @param pfnDownloadProgress Progress function to be called. Set it to
307 * NULL to disable the callback.
308 * @param pvUser Convenience pointer for the callback function.
309 */
310RTR3DECL(int) RTHttpSetDownloadProgressCallback(RTHTTP hHttp, PRTHTTPDOWNLDPROGRCALLBACK pfnDownloadProgress, void *pvUser);
311
312
313/** @} */
314
315RT_C_DECLS_END
316
317#endif
318
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