VirtualBox

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

最後變更 在這個檔案從58199是 58199,由 vboxsync 提交於 9 年 前

Runtime/http-curl: introduced RTHttpGetHeaderText() and RTHttpGetHeaderBinary()

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

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