VirtualBox

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

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

http-curl.cpp: add a few thin wrappers for some curl options.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use