1 | /* $Id: http.h 57926 2015-09-28 14:05:58Z 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 |
|
---|
32 | RT_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. */
|
---|
41 | typedef R3PTRTYPE(struct RTHTTPINTERNAL *) RTHTTP;
|
---|
42 | /** Pointer to a HTTP/HTTPS client handle. */
|
---|
43 | typedef 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 | */
|
---|
55 | RTR3DECL(int) RTHttpCreate(PRTHTTP phHttp);
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Destroys a HTTP client instance.
|
---|
59 | *
|
---|
60 | * @param hHttp Handle to the HTTP interface.
|
---|
61 | */
|
---|
62 | RTR3DECL(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 | */
|
---|
72 | RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation);
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Perform a simple blocking HTTP 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 poitner 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 | */
|
---|
101 | RTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Frees memory returned by RTHttpGetText.
|
---|
105 | *
|
---|
106 | * @param pszNotUtf8 What RTHttpGetText returned.
|
---|
107 | */
|
---|
108 | RTR3DECL(void) RTHttpFreeResponseText(char *pszNotUtf8);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Perform a simple blocking HTTP request.
|
---|
112 | *
|
---|
113 | * @returns iprt status code.
|
---|
114 | *
|
---|
115 | * @param hHttp The HTTP client instance.
|
---|
116 | * @param pszUrl The URL.
|
---|
117 | * @param ppvResponse Where to store the HTTP response data. Use
|
---|
118 | * RTHttpFreeResponse to free.
|
---|
119 | * @param pcb Size of the returned buffer.
|
---|
120 | */
|
---|
121 | RTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Frees memory returned by RTHttpGetBinary.
|
---|
125 | *
|
---|
126 | * @param pvResponse What RTHttpGetBinary returned.
|
---|
127 | */
|
---|
128 | RTR3DECL(void) RTHttpFreeResponse(void *pvResponse);
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Perform a simple blocking HTTP request, writing the output to a file.
|
---|
132 | *
|
---|
133 | * @returns iprt status code.
|
---|
134 | *
|
---|
135 | * @param hHttp The HTTP client instance.
|
---|
136 | * @param pszUrl The URL.
|
---|
137 | * @param pszDstFile The destination file name.
|
---|
138 | */
|
---|
139 | RTR3DECL(int) RTHttpGetFile(RTHTTP hHttp, const char *pszUrl, const char *pszDstFile);
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Abort a pending HTTP request. A blocking RTHttpGet() call will return with
|
---|
143 | * VERR_HTTP_ABORTED. It may take some time (current cURL implementation needs
|
---|
144 | * up to 1 second) before the request is aborted.
|
---|
145 | *
|
---|
146 | * @returns iprt status code.
|
---|
147 | *
|
---|
148 | * @param hHttp The HTTP client instance.
|
---|
149 | */
|
---|
150 | RTR3DECL(int) RTHttpAbort(RTHTTP hHttp);
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Tells the HTTP interface to use the system proxy configuration.
|
---|
154 | *
|
---|
155 | * @returns iprt status code.
|
---|
156 | * @param hHttp The HTTP client instance.
|
---|
157 | */
|
---|
158 | RTR3DECL(int) RTHttpUseSystemProxySettings(RTHTTP hHttp);
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Specify proxy settings.
|
---|
162 | *
|
---|
163 | * @returns iprt status code.
|
---|
164 | *
|
---|
165 | * @param hHttp The HTTP client instance.
|
---|
166 | * @param pszProxyUrl URL of the proxy server.
|
---|
167 | * @param uPort port number of the proxy, use 0 for not specifying a port.
|
---|
168 | * @param pszProxyUser Username, pass NULL for no authentication.
|
---|
169 | * @param pszProxyPwd Password, pass NULL for no authentication.
|
---|
170 | *
|
---|
171 | * @todo This API does not allow specifying the type of proxy server... We're
|
---|
172 | * currently assuming it's a HTTP proxy.
|
---|
173 | */
|
---|
174 | RTR3DECL(int) RTHttpSetProxy(RTHTTP hHttp, const char *pszProxyUrl, uint32_t uPort,
|
---|
175 | const char *pszProxyUser, const char *pszProxyPwd);
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Set custom headers.
|
---|
179 | *
|
---|
180 | * @returns iprt status code.
|
---|
181 | *
|
---|
182 | * @param hHttp The HTTP client instance.
|
---|
183 | * @param cHeaders Number of custom headers.
|
---|
184 | * @param papszHeaders Array of headers in form "foo: bar".
|
---|
185 | */
|
---|
186 | RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders);
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Tells the HTTP client instance to gather system CA certificates into a
|
---|
190 | * temporary file and use it for HTTPS connections.
|
---|
191 | *
|
---|
192 | * This will be called automatically if a 'https' URL is presented and
|
---|
193 | * RTHttpSetCaFile hasn't been called yet.
|
---|
194 | *
|
---|
195 | * @returns IPRT status code.
|
---|
196 | * @param hHttp The HTTP client instance.
|
---|
197 | * @param pErrInfo Where to store additional error/warning information.
|
---|
198 | * Optional.
|
---|
199 | */
|
---|
200 | RTR3DECL(int) RTHttpUseTemporaryCaFile(RTHTTP hHttp, PRTERRINFO pErrInfo);
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Set a custom certification authority file, containing root certificates.
|
---|
204 | *
|
---|
205 | * @returns iprt status code.
|
---|
206 | *
|
---|
207 | * @param hHttp The HTTP client instance.
|
---|
208 | * @param pszCAFile File name containing root certificates.
|
---|
209 | *
|
---|
210 | * @remarks For portable HTTPS support, use RTHttpGatherCaCertsInFile and pass
|
---|
211 | */
|
---|
212 | RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pszCAFile);
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Gathers certificates into a cryptographic (certificate) store
|
---|
216 | *
|
---|
217 | * This is a just a combination of RTHttpGatherCaCertsInStore and
|
---|
218 | * RTCrStoreCertExportAsPem.
|
---|
219 | *
|
---|
220 | * @returns IPRT status code.
|
---|
221 | * @param hStore The certificate store to gather the certificates
|
---|
222 | * in.
|
---|
223 | * @param fFlags RTHTTPGATHERCACERT_F_XXX.
|
---|
224 | * @param pErrInfo Where to store additional error/warning information.
|
---|
225 | * Optional.
|
---|
226 | */
|
---|
227 | RTR3DECL(int) RTHttpGatherCaCertsInStore(RTCRSTORE hStore, uint32_t fFlags, PRTERRINFO pErrInfo);
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * Gathers certificates into a file that can be used with RTHttpSetCAFile.
|
---|
231 | *
|
---|
232 | * This is a just a combination of RTHttpGatherCaCertsInStore and
|
---|
233 | * RTCrStoreCertExportAsPem.
|
---|
234 | *
|
---|
235 | * @returns IPRT status code.
|
---|
236 | * @param pszCaFile The output file.
|
---|
237 | * @param fFlags RTHTTPGATHERCACERT_F_XXX.
|
---|
238 | * @param pErrInfo Where to store additional error/warning information.
|
---|
239 | * Optional.
|
---|
240 | */
|
---|
241 | RTR3DECL(int) RTHttpGatherCaCertsInFile(const char *pszCaFile, uint32_t fFlags, PRTERRINFO pErrInfo);
|
---|
242 |
|
---|
243 | /** @} */
|
---|
244 |
|
---|
245 | RT_C_DECLS_END
|
---|
246 |
|
---|
247 | #endif
|
---|
248 |
|
---|