VirtualBox

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

Last change on this file since 58803 was 58221, checked in by vboxsync, 9 years ago

doxygen fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1/* $Id: http.h 58221 2015-10-13 16:44:41Z vboxsync $ */
2/** @file
3 * IPRT - Simple HTTP/HTTPS Client API.
4 */
5
6/*
7 * Copyright (C) 2012-2015 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 custom headers.
225 *
226 * @returns iprt status code.
227 *
228 * @param hHttp The HTTP client instance.
229 * @param cHeaders Number of custom headers.
230 * @param papszHeaders Array of headers in form "foo: bar".
231 */
232RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders);
233
234/**
235 * Tells the HTTP client instance to gather system CA certificates into a
236 * temporary file and use it for HTTPS connections.
237 *
238 * This will be called automatically if a 'https' URL is presented and
239 * RTHttpSetCaFile hasn't been called yet.
240 *
241 * @returns IPRT status code.
242 * @param hHttp The HTTP client instance.
243 * @param pErrInfo Where to store additional error/warning information.
244 * Optional.
245 */
246RTR3DECL(int) RTHttpUseTemporaryCaFile(RTHTTP hHttp, PRTERRINFO pErrInfo);
247
248/**
249 * Set a custom certification authority file, containing root certificates.
250 *
251 * @returns iprt status code.
252 *
253 * @param hHttp The HTTP client instance.
254 * @param pszCAFile File name containing root certificates.
255 *
256 * @remarks For portable HTTPS support, use RTHttpGatherCaCertsInFile and pass
257 */
258RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pszCAFile);
259
260/**
261 * Gathers certificates into a cryptographic (certificate) store
262 *
263 * This is a just a combination of RTHttpGatherCaCertsInStore and
264 * RTCrStoreCertExportAsPem.
265 *
266 * @returns IPRT status code.
267 * @param hStore The certificate store to gather the certificates
268 * in.
269 * @param fFlags RTHTTPGATHERCACERT_F_XXX.
270 * @param pErrInfo Where to store additional error/warning information.
271 * Optional.
272 */
273RTR3DECL(int) RTHttpGatherCaCertsInStore(RTCRSTORE hStore, uint32_t fFlags, PRTERRINFO pErrInfo);
274
275/**
276 * Gathers certificates into a file that can be used with RTHttpSetCAFile.
277 *
278 * This is a just a combination of RTHttpGatherCaCertsInStore and
279 * RTCrStoreCertExportAsPem.
280 *
281 * @returns IPRT status code.
282 * @param pszCaFile The output file.
283 * @param fFlags RTHTTPGATHERCACERT_F_XXX.
284 * @param pErrInfo Where to store additional error/warning information.
285 * Optional.
286 */
287RTR3DECL(int) RTHttpGatherCaCertsInFile(const char *pszCaFile, uint32_t fFlags, PRTERRINFO pErrInfo);
288
289/**
290 * Set a callback function which is called during RTHttpGet*()
291 *
292 * @returns IPRT status code.
293 * @param hHttp The HTTP client instance.
294 * @param pfnDownloadProgress Progress function to be called. Set it to
295 * NULL to disable the callback.
296 * @param pvUser Convenience pointer for the callback function.
297 */
298RTR3DECL(int) RTHttpSetDownloadProgressCallback(RTHTTP hHttp, PRTHTTPDOWNLDPROGRCALLBACK pfnDownloadProgress, void *pvUser);
299
300
301/** @} */
302
303RT_C_DECLS_END
304
305#endif
306
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