[43645] | 1 | /* $Id: http.h 76585 2019-01-01 06:31:29Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[57613] | 3 | * IPRT - Simple HTTP/HTTPS Client API.
|
---|
[43645] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[76553] | 7 | * Copyright (C) 2012-2019 Oracle Corporation
|
---|
[43645] | 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 |
|
---|
[76557] | 27 | #ifndef IPRT_INCLUDED_http_h
|
---|
| 28 | #define IPRT_INCLUDED_http_h
|
---|
[76507] | 29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 30 | # pragma once
|
---|
| 31 | #endif
|
---|
[43645] | 32 |
|
---|
| 33 | #include <iprt/types.h>
|
---|
| 34 |
|
---|
| 35 | RT_C_DECLS_BEGIN
|
---|
| 36 |
|
---|
[57613] | 37 | /** @defgroup grp_rt_http RTHttp - Simple HTTP/HTTPS Client API
|
---|
[43645] | 38 | * @ingroup grp_rt
|
---|
| 39 | * @{
|
---|
| 40 | */
|
---|
| 41 |
|
---|
| 42 | /** @todo the following three definitions may move the iprt/types.h later. */
|
---|
[57613] | 43 | /** HTTP/HTTPS client handle. */
|
---|
[43645] | 44 | typedef R3PTRTYPE(struct RTHTTPINTERNAL *) RTHTTP;
|
---|
[57613] | 45 | /** Pointer to a HTTP/HTTPS client handle. */
|
---|
| 46 | typedef RTHTTP *PRTHTTP;
|
---|
| 47 | /** Nil HTTP/HTTPS client handle. */
|
---|
[43645] | 48 | #define NIL_RTHTTP ((RTHTTP)0)
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
[57613] | 52 | * Creates a HTTP client instance.
|
---|
[43645] | 53 | *
|
---|
[73886] | 54 | * @returns IPRT status code.
|
---|
[43645] | 55 | * @param phHttp Where to store the HTTP handle.
|
---|
| 56 | */
|
---|
| 57 | RTR3DECL(int) RTHttpCreate(PRTHTTP phHttp);
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
[73699] | 60 | * Resets a HTTP client instance.
|
---|
| 61 | *
|
---|
[73886] | 62 | * @returns IPRT status code.
|
---|
[75108] | 63 | * @param hHttp Handle to the HTTP interface.
|
---|
| 64 | * @param fFlags Flags, RTHTTP_RESET_F_XXX.
|
---|
[73699] | 65 | */
|
---|
[75108] | 66 | RTR3DECL(int) RTHttpReset(RTHTTP hHttp, uint32_t fFlags);
|
---|
[73699] | 67 |
|
---|
[75108] | 68 | /** @name RTHTTP_RESET_F_XXX - Flags for RTHttpReset.
|
---|
| 69 | * @{ */
|
---|
| 70 | /** Keep the headers. */
|
---|
| 71 | #define RTHTTP_RESET_F_KEEP_HEADERS RT_BIT_32(0)
|
---|
| 72 | /** Mask containing the valid flags. */
|
---|
| 73 | #define RTHTTP_RESET_F_VALID_MASK UINT32_C(0x00000001)
|
---|
| 74 | /** @} */
|
---|
| 75 |
|
---|
| 76 |
|
---|
[73699] | 77 | /**
|
---|
[57613] | 78 | * Destroys a HTTP client instance.
|
---|
[43645] | 79 | *
|
---|
[73886] | 80 | * @returns IPRT status code.
|
---|
[43645] | 81 | * @param hHttp Handle to the HTTP interface.
|
---|
| 82 | */
|
---|
[73886] | 83 | RTR3DECL(int) RTHttpDestroy(RTHTTP hHttp);
|
---|
[43645] | 84 |
|
---|
[51705] | 85 |
|
---|
[43645] | 86 | /**
|
---|
[51705] | 87 | * Retrieve the redir location for 301 responses.
|
---|
| 88 | *
|
---|
[57577] | 89 | * @param hHttp Handle to the HTTP interface.
|
---|
| 90 | * @param ppszRedirLocation Where to store the string. To be freed with
|
---|
[51705] | 91 | * RTStrFree().
|
---|
| 92 | */
|
---|
| 93 | RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation);
|
---|
| 94 |
|
---|
| 95 | /**
|
---|
[58199] | 96 | * Perform a simple blocking HTTP GET request.
|
---|
[43645] | 97 | *
|
---|
[57577] | 98 | * This is a just a convenient wrapper around RTHttpGetBinary that returns a
|
---|
| 99 | * different type and sheds a parameter.
|
---|
| 100 | *
|
---|
[43645] | 101 | * @returns iprt status code.
|
---|
| 102 | *
|
---|
[74046] | 103 | * @param hHttp The HTTP client handle.
|
---|
[57613] | 104 | * @param pszUrl URL.
|
---|
[58199] | 105 | * @param ppszNotUtf8 Where to return the pointer to the HTTP response.
|
---|
[57577] | 106 | * The string is of course zero terminated. Use
|
---|
| 107 | * RTHttpFreeReponseText to free.
|
---|
| 108 | *
|
---|
| 109 | * @remarks BIG FAT WARNING!
|
---|
| 110 | *
|
---|
| 111 | * This function does not guarantee the that returned string is valid UTF-8 or
|
---|
| 112 | * any other kind of text encoding!
|
---|
| 113 | *
|
---|
| 114 | * The caller must determine and validate the string encoding _before_
|
---|
| 115 | * passing it along to functions that expect UTF-8!
|
---|
| 116 | *
|
---|
| 117 | * Also, this function does not guarantee that the returned string
|
---|
| 118 | * doesn't have embedded zeros and provides the caller no way of
|
---|
| 119 | * finding out! If you are worried about the response from the HTTPD
|
---|
| 120 | * containing embedded zero's, use RTHttpGetBinary instead.
|
---|
[43645] | 121 | */
|
---|
[57613] | 122 | RTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
|
---|
[43645] | 123 |
|
---|
[43679] | 124 | /**
|
---|
[58199] | 125 | * Perform a simple blocking HTTP HEAD request.
|
---|
| 126 | *
|
---|
| 127 | * This is a just a convenient wrapper around RTHttpGetBinary that returns a
|
---|
| 128 | * different type and sheds a parameter.
|
---|
| 129 | *
|
---|
| 130 | * @returns iprt status code.
|
---|
| 131 | *
|
---|
[74046] | 132 | * @param hHttp The HTTP client handle.
|
---|
[58199] | 133 | * @param pszUrl URL.
|
---|
| 134 | * @param ppszNotUtf8 Where to return the pointer to the HTTP response.
|
---|
| 135 | * The string is of course zero terminated. Use
|
---|
| 136 | * RTHttpFreeReponseText to free.
|
---|
| 137 | *
|
---|
| 138 | * @remarks BIG FAT WARNING!
|
---|
| 139 | *
|
---|
| 140 | * This function does not guarantee the that returned string is valid UTF-8 or
|
---|
| 141 | * any other kind of text encoding!
|
---|
| 142 | *
|
---|
| 143 | * The caller must determine and validate the string encoding _before_
|
---|
| 144 | * passing it along to functions that expect UTF-8!
|
---|
| 145 | *
|
---|
| 146 | * Also, this function does not guarantee that the returned string
|
---|
| 147 | * doesn't have embedded zeros and provides the caller no way of
|
---|
| 148 | * finding out! If you are worried about the response from the HTTPD
|
---|
| 149 | * containing embedded zero's, use RTHttpGetHeaderBinary instead.
|
---|
| 150 | */
|
---|
| 151 | RTR3DECL(int) RTHttpGetHeaderText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
|
---|
| 152 |
|
---|
| 153 | /**
|
---|
[57577] | 154 | * Frees memory returned by RTHttpGetText.
|
---|
| 155 | *
|
---|
| 156 | * @param pszNotUtf8 What RTHttpGetText returned.
|
---|
| 157 | */
|
---|
| 158 | RTR3DECL(void) RTHttpFreeResponseText(char *pszNotUtf8);
|
---|
| 159 |
|
---|
| 160 | /**
|
---|
[58199] | 161 | * Perform a simple blocking HTTP GET request.
|
---|
[51635] | 162 | *
|
---|
| 163 | * @returns iprt status code.
|
---|
| 164 | *
|
---|
[74046] | 165 | * @param hHttp The HTTP client handle.
|
---|
[57613] | 166 | * @param pszUrl The URL.
|
---|
[57577] | 167 | * @param ppvResponse Where to store the HTTP response data. Use
|
---|
| 168 | * RTHttpFreeResponse to free.
|
---|
| 169 | * @param pcb Size of the returned buffer.
|
---|
[51635] | 170 | */
|
---|
[57613] | 171 | RTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
|
---|
[51635] | 172 |
|
---|
| 173 | /**
|
---|
[58199] | 174 | * Perform a simple blocking HTTP HEAD request.
|
---|
| 175 | *
|
---|
| 176 | * @returns iprt status code.
|
---|
| 177 | *
|
---|
[74046] | 178 | * @param hHttp The HTTP client handle.
|
---|
[58199] | 179 | * @param pszUrl The URL.
|
---|
| 180 | * @param ppvResponse Where to store the HTTP response data. Use
|
---|
| 181 | * RTHttpFreeResponse to free.
|
---|
| 182 | * @param pcb Size of the returned buffer.
|
---|
| 183 | */
|
---|
| 184 | RTR3DECL(int) RTHttpGetHeaderBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
|
---|
| 185 |
|
---|
| 186 | /**
|
---|
[57577] | 187 | * Frees memory returned by RTHttpGetBinary.
|
---|
| 188 | *
|
---|
| 189 | * @param pvResponse What RTHttpGetBinary returned.
|
---|
| 190 | */
|
---|
| 191 | RTR3DECL(void) RTHttpFreeResponse(void *pvResponse);
|
---|
| 192 |
|
---|
| 193 | /**
|
---|
[46050] | 194 | * Perform a simple blocking HTTP request, writing the output to a file.
|
---|
| 195 | *
|
---|
| 196 | * @returns iprt status code.
|
---|
| 197 | *
|
---|
[74046] | 198 | * @param hHttp The HTTP client handle.
|
---|
[57577] | 199 | * @param pszUrl The URL.
|
---|
[46050] | 200 | * @param pszDstFile The destination file name.
|
---|
| 201 | */
|
---|
| 202 | RTR3DECL(int) RTHttpGetFile(RTHTTP hHttp, const char *pszUrl, const char *pszDstFile);
|
---|
| 203 |
|
---|
[73899] | 204 | /** HTTP methods. */
|
---|
| 205 | typedef enum RTHTTPMETHOD
|
---|
| 206 | {
|
---|
| 207 | RTHTTPMETHOD_INVALID = 0,
|
---|
| 208 | RTHTTPMETHOD_GET,
|
---|
| 209 | RTHTTPMETHOD_PUT,
|
---|
| 210 | RTHTTPMETHOD_POST,
|
---|
| 211 | RTHTTPMETHOD_PATCH,
|
---|
| 212 | RTHTTPMETHOD_DELETE,
|
---|
| 213 | RTHTTPMETHOD_HEAD,
|
---|
| 214 | RTHTTPMETHOD_OPTIONS,
|
---|
| 215 | RTHTTPMETHOD_TRACE,
|
---|
| 216 | RTHTTPMETHOD_END,
|
---|
| 217 | RTHTTPMETHOD_32BIT_HACK = 0x7fffffff
|
---|
| 218 | } RTHTTPMETHOD;
|
---|
| 219 |
|
---|
[46050] | 220 | /**
|
---|
[73977] | 221 | * Returns the name of the HTTP method.
|
---|
| 222 | * @returns Read only string.
|
---|
| 223 | * @param enmMethod The HTTP method to name.
|
---|
| 224 | */
|
---|
| 225 | RTR3DECL(const char *) RTHttpMethodName(RTHTTPMETHOD enmMethod);
|
---|
| 226 |
|
---|
| 227 | /**
|
---|
[73899] | 228 | * Performs generic blocking HTTP request, optionally returning the body and headers.
|
---|
| 229 | *
|
---|
| 230 | * @returns IPRT status code.
|
---|
[74046] | 231 | * @param hHttp The HTTP client handle.
|
---|
[73899] | 232 | * @param pszUrl The URL.
|
---|
| 233 | * @param enmMethod The HTTP method for the request.
|
---|
[73967] | 234 | * @param pvReqBody Pointer to the request body. NULL if none.
|
---|
| 235 | * @param cbReqBody Size of the request body. Zero if none.
|
---|
[73899] | 236 | * @param puHttpStatus Where to return the HTTP status code. Optional.
|
---|
| 237 | * @param ppvHeaders Where to return the headers. Optional.
|
---|
| 238 | * @param pcbHeaders Where to return the header size.
|
---|
| 239 | * @param ppvBody Where to return the body. Optional.
|
---|
| 240 | * @param pcbBody Where to return the body size.
|
---|
| 241 | */
|
---|
[73967] | 242 | RTR3DECL(int) RTHttpPerform(RTHTTP hHttp, const char *pszUrl, RTHTTPMETHOD enmMethod, void const *pvReqBody, size_t cbReqBody,
|
---|
[73899] | 243 | uint32_t *puHttpStatus, void **ppvHeaders, size_t *pcbHeaders, void **ppvBody, size_t *pcbBody);
|
---|
| 244 |
|
---|
| 245 |
|
---|
| 246 | /**
|
---|
[45454] | 247 | * Abort a pending HTTP request. A blocking RTHttpGet() call will return with
|
---|
| 248 | * VERR_HTTP_ABORTED. It may take some time (current cURL implementation needs
|
---|
| 249 | * up to 1 second) before the request is aborted.
|
---|
| 250 | *
|
---|
| 251 | * @returns iprt status code.
|
---|
| 252 | *
|
---|
[74046] | 253 | * @param hHttp The HTTP client handle.
|
---|
[45454] | 254 | */
|
---|
| 255 | RTR3DECL(int) RTHttpAbort(RTHTTP hHttp);
|
---|
| 256 |
|
---|
| 257 | /**
|
---|
[46070] | 258 | * Tells the HTTP interface to use the system proxy configuration.
|
---|
| 259 | *
|
---|
| 260 | * @returns iprt status code.
|
---|
[74046] | 261 | * @param hHttp The HTTP client handle.
|
---|
[46070] | 262 | */
|
---|
| 263 | RTR3DECL(int) RTHttpUseSystemProxySettings(RTHTTP hHttp);
|
---|
| 264 |
|
---|
| 265 | /**
|
---|
[74377] | 266 | * Sets up the proxy according to the specified URL.
|
---|
| 267 | *
|
---|
| 268 | * @returns IPRT status code.
|
---|
| 269 | * @retval VWRN_WRONG_TYPE if the type isn't known/supported and we defaulted to 'http'.
|
---|
| 270 | *
|
---|
| 271 | * @param hHttp The HTTP client handle.
|
---|
| 272 | * @param pszUrl The proxy URL (libproxy style):
|
---|
| 273 | *
|
---|
| 274 | * [{type}"://"][{userid}[@{password}]:]{server}[":"{port}]
|
---|
| 275 | *
|
---|
| 276 | * Valid proxy types are: http (default), https, socks4, socks4a,
|
---|
| 277 | * socks5, socks5h and direct. Support for the socks and https
|
---|
| 278 | * ones depends on the HTTP library we use.
|
---|
| 279 | *
|
---|
| 280 | * The port number defaults to 80 for http, 443 for https and 1080
|
---|
| 281 | * for the socks ones.
|
---|
| 282 | *
|
---|
| 283 | * If this starts with "direct://", then no proxy will be used.
|
---|
| 284 | * An empty or NULL string is equivalent to calling
|
---|
| 285 | * RTHttpUseSystemProxySettings().
|
---|
| 286 | */
|
---|
| 287 | RTR3DECL(int) RTHttpSetProxyByUrl(RTHTTP hHttp, const char *pszUrl);
|
---|
| 288 |
|
---|
| 289 | /**
|
---|
[43679] | 290 | * Specify proxy settings.
|
---|
| 291 | *
|
---|
| 292 | * @returns iprt status code.
|
---|
| 293 | *
|
---|
[74046] | 294 | * @param hHttp The HTTP client handle.
|
---|
[57926] | 295 | * @param pszProxyUrl URL of the proxy server.
|
---|
[57577] | 296 | * @param uPort port number of the proxy, use 0 for not specifying a port.
|
---|
[57613] | 297 | * @param pszProxyUser Username, pass NULL for no authentication.
|
---|
| 298 | * @param pszProxyPwd Password, pass NULL for no authentication.
|
---|
[57926] | 299 | *
|
---|
| 300 | * @todo This API does not allow specifying the type of proxy server... We're
|
---|
| 301 | * currently assuming it's a HTTP proxy.
|
---|
[74377] | 302 | *
|
---|
| 303 | * @deprecated Use RTHttpSetProxyByUrl.
|
---|
[43679] | 304 | */
|
---|
[57613] | 305 | RTR3DECL(int) RTHttpSetProxy(RTHTTP hHttp, const char *pszProxyUrl, uint32_t uPort,
|
---|
| 306 | const char *pszProxyUser, const char *pszProxyPwd);
|
---|
[43679] | 307 |
|
---|
[43713] | 308 | /**
|
---|
[73334] | 309 | * Set follow redirects (3xx)
|
---|
| 310 | *
|
---|
| 311 | * @returns iprt status code.
|
---|
| 312 | *
|
---|
[74046] | 313 | * @param hHttp The HTTP client handle.
|
---|
[73334] | 314 | * @param cMaxRedirects Max number of redirects to follow. Zero if no
|
---|
| 315 | * redirects should be followed but instead returned
|
---|
| 316 | * to caller.
|
---|
| 317 | */
|
---|
| 318 | RTR3DECL(int) RTHttpSetFollowRedirects(RTHTTP hHttp, uint32_t cMaxRedirects);
|
---|
| 319 |
|
---|
| 320 | /**
|
---|
[73888] | 321 | * Set custom raw headers.
|
---|
[43713] | 322 | *
|
---|
| 323 | * @returns iprt status code.
|
---|
| 324 | *
|
---|
[74046] | 325 | * @param hHttp The HTTP client handle.
|
---|
[57577] | 326 | * @param cHeaders Number of custom headers.
|
---|
[57613] | 327 | * @param papszHeaders Array of headers in form "foo: bar".
|
---|
[43713] | 328 | */
|
---|
[46050] | 329 | RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders);
|
---|
[45331] | 330 |
|
---|
[74060] | 331 | /** @name RTHTTPADDHDR_F_XXX - Flags for RTHttpAddRawHeader and RTHttpAddHeader
|
---|
| 332 | * @{ */
|
---|
| 333 | #define RTHTTPADDHDR_F_BACK UINT32_C(0) /**< Append the header. */
|
---|
| 334 | #define RTHTTPADDHDR_F_FRONT UINT32_C(1) /**< Prepend the header. */
|
---|
| 335 | /** @} */
|
---|
| 336 |
|
---|
[45331] | 337 | /**
|
---|
[74060] | 338 | * Adds a raw header.
|
---|
[73888] | 339 | *
|
---|
| 340 | * @returns IPRT status code.
|
---|
[74046] | 341 | * @param hHttp The HTTP client handle.
|
---|
[73888] | 342 | * @param pszHeader Header string on the form "foo: bar".
|
---|
[74060] | 343 | * @param fFlags RTHTTPADDHDR_F_FRONT or RTHTTPADDHDR_F_BACK.
|
---|
[73888] | 344 | */
|
---|
[74060] | 345 | RTR3DECL(int) RTHttpAddRawHeader(RTHTTP hHttp, const char *pszHeader, uint32_t fFlags);
|
---|
[73888] | 346 |
|
---|
| 347 | /**
|
---|
[74060] | 348 | * Adds a header field and value.
|
---|
[73888] | 349 | *
|
---|
| 350 | * @returns IPRT status code.
|
---|
[74046] | 351 | * @param hHttp The HTTP client handle.
|
---|
[73888] | 352 | * @param pszField The header field name.
|
---|
| 353 | * @param pszValue The header field value.
|
---|
[74070] | 354 | * @param cchValue The value length or RTSTR_MAX.
|
---|
[74060] | 355 | * @param fFlags Only RTHTTPADDHDR_F_FRONT or RTHTTPADDHDR_F_BACK,
|
---|
| 356 | * may be extended with encoding controlling flags if
|
---|
| 357 | * needed later.
|
---|
[73888] | 358 | */
|
---|
[74070] | 359 | RTR3DECL(int) RTHttpAddHeader(RTHTTP hHttp, const char *pszField, const char *pszValue, size_t cchValue, uint32_t fFlags);
|
---|
[73888] | 360 |
|
---|
| 361 | /**
|
---|
[74046] | 362 | * Gets a header previously added using RTHttpSetHeaders, RTHttpAppendRawHeader
|
---|
| 363 | * or RTHttpAppendHeader.
|
---|
| 364 | *
|
---|
| 365 | * @returns Pointer to the header value on if found, otherwise NULL.
|
---|
| 366 | * @param hHttp The HTTP client handle.
|
---|
| 367 | * @param pszField The field name (no colon).
|
---|
| 368 | * @param cchField The length of the field name or RTSTR_MAX.
|
---|
| 369 | */
|
---|
| 370 | RTR3DECL(const char *) RTHttpGetHeader(RTHTTP hHttp, const char *pszField, size_t cchField);
|
---|
| 371 |
|
---|
| 372 | /**
|
---|
[74202] | 373 | * Gets the number of headers specified by RTHttpAddHeader, RTHttpAddRawHeader or RTHttpSetHeaders.
|
---|
| 374 | *
|
---|
| 375 | * @returns Number of headers.
|
---|
| 376 | * @param hHttp The HTTP client handle.
|
---|
| 377 | * @note This can be slow and is only really intended for test cases and debugging!
|
---|
| 378 | */
|
---|
| 379 | RTR3DECL(size_t) RTHttpGetHeaderCount(RTHTTP hHttp);
|
---|
| 380 |
|
---|
| 381 | /**
|
---|
| 382 | * Gets a header by ordinal.
|
---|
| 383 | *
|
---|
| 384 | * Can be used together with RTHttpGetHeaderCount by test case and debug code to
|
---|
| 385 | * iterate headers specified by RTHttpAddHeader, RTHttpAddRawHeader or RTHttpSetHeaders.
|
---|
| 386 | *
|
---|
[74203] | 387 | * @returns The header string ("field: value").
|
---|
[74202] | 388 | * @param hHttp The HTTP client handle.
|
---|
[74203] | 389 | * @param iOrdinal The number of the header to get.
|
---|
[74202] | 390 | * @note This can be slow and is only really intended for test cases and debugging!
|
---|
| 391 | */
|
---|
| 392 | RTR3DECL(const char *) RTHttpGetByOrdinal(RTHTTP hHttp, size_t iOrdinal);
|
---|
| 393 |
|
---|
| 394 | /**
|
---|
[74064] | 395 | * Sign all headers present according to pending "Signing HTTP Messages" RFC.
|
---|
| 396 | *
|
---|
| 397 | * Currently hardcoded RSA-SHA-256 algorithm choice.
|
---|
| 398 | *
|
---|
| 399 | * @returns IPRT status code.
|
---|
| 400 | * @param hHttp The HTTP client handle.
|
---|
| 401 | * @param enmMethod The HTTP method that will be used for the request.
|
---|
| 402 | * @param pszUrl The target URL for the request.
|
---|
| 403 | * @param hKey The RSA key to use when signing.
|
---|
| 404 | * @param pszKeyId The key ID string corresponding to @a hKey.
|
---|
| 405 | * @param fFlags Reserved for future, MBZ.
|
---|
| 406 | *
|
---|
| 407 | * @note Caller is responsible for making all desired fields are present before
|
---|
| 408 | * making the call.
|
---|
| 409 | *
|
---|
| 410 | * @remarks Latest RFC draft at the time of writing:
|
---|
| 411 | * https://tools.ietf.org/html/draft-cavage-http-signatures-10
|
---|
| 412 | */
|
---|
| 413 | RTR3DECL(int) RTHttpSignHeaders(RTHTTP hHttp, RTHTTPMETHOD enmMethod, const char *pszUrl,
|
---|
| 414 | RTCRKEY hKey, const char *pszKeyId, uint32_t fFlags);
|
---|
| 415 |
|
---|
| 416 | /**
|
---|
[57613] | 417 | * Tells the HTTP client instance to gather system CA certificates into a
|
---|
| 418 | * temporary file and use it for HTTPS connections.
|
---|
| 419 | *
|
---|
| 420 | * This will be called automatically if a 'https' URL is presented and
|
---|
| 421 | * RTHttpSetCaFile hasn't been called yet.
|
---|
| 422 | *
|
---|
| 423 | * @returns IPRT status code.
|
---|
[74046] | 424 | * @param hHttp The HTTP client handle.
|
---|
[57613] | 425 | * @param pErrInfo Where to store additional error/warning information.
|
---|
| 426 | * Optional.
|
---|
| 427 | */
|
---|
| 428 | RTR3DECL(int) RTHttpUseTemporaryCaFile(RTHTTP hHttp, PRTERRINFO pErrInfo);
|
---|
| 429 |
|
---|
| 430 | /**
|
---|
[45331] | 431 | * Set a custom certification authority file, containing root certificates.
|
---|
| 432 | *
|
---|
| 433 | * @returns iprt status code.
|
---|
| 434 | *
|
---|
[74046] | 435 | * @param hHttp The HTTP client handle.
|
---|
[57613] | 436 | * @param pszCAFile File name containing root certificates.
|
---|
| 437 | *
|
---|
| 438 | * @remarks For portable HTTPS support, use RTHttpGatherCaCertsInFile and pass
|
---|
[45331] | 439 | */
|
---|
[57613] | 440 | RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pszCAFile);
|
---|
[43645] | 441 |
|
---|
[57613] | 442 | /**
|
---|
| 443 | * Gathers certificates into a cryptographic (certificate) store
|
---|
| 444 | *
|
---|
| 445 | * This is a just a combination of RTHttpGatherCaCertsInStore and
|
---|
| 446 | * RTCrStoreCertExportAsPem.
|
---|
| 447 | *
|
---|
| 448 | * @returns IPRT status code.
|
---|
| 449 | * @param hStore The certificate store to gather the certificates
|
---|
| 450 | * in.
|
---|
| 451 | * @param fFlags RTHTTPGATHERCACERT_F_XXX.
|
---|
| 452 | * @param pErrInfo Where to store additional error/warning information.
|
---|
| 453 | * Optional.
|
---|
| 454 | */
|
---|
| 455 | RTR3DECL(int) RTHttpGatherCaCertsInStore(RTCRSTORE hStore, uint32_t fFlags, PRTERRINFO pErrInfo);
|
---|
[45339] | 456 |
|
---|
[57613] | 457 | /**
|
---|
| 458 | * Gathers certificates into a file that can be used with RTHttpSetCAFile.
|
---|
| 459 | *
|
---|
| 460 | * This is a just a combination of RTHttpGatherCaCertsInStore and
|
---|
| 461 | * RTCrStoreCertExportAsPem.
|
---|
| 462 | *
|
---|
| 463 | * @returns IPRT status code.
|
---|
| 464 | * @param pszCaFile The output file.
|
---|
| 465 | * @param fFlags RTHTTPGATHERCACERT_F_XXX.
|
---|
| 466 | * @param pErrInfo Where to store additional error/warning information.
|
---|
| 467 | * Optional.
|
---|
| 468 | */
|
---|
| 469 | RTR3DECL(int) RTHttpGatherCaCertsInFile(const char *pszCaFile, uint32_t fFlags, PRTERRINFO pErrInfo);
|
---|
| 470 |
|
---|
[58217] | 471 | /**
|
---|
[74077] | 472 | * Callback function to be called during RTHttpGet*().
|
---|
| 473 | *
|
---|
| 474 | * Register it using RTHttpSetDownloadProgressCallback().
|
---|
| 475 | *
|
---|
| 476 | * @param hHttp The HTTP client handle.
|
---|
| 477 | * @param pvUser The user parameter specified when registering the callback.
|
---|
| 478 | * @param cbDowloadTotal The content-length value, if available.
|
---|
| 479 | * Warning! Not entirely clear what it will be if
|
---|
| 480 | * unavailable, probably 0.
|
---|
| 481 | * @param cbDowloaded How much was downloaded thus far.
|
---|
| 482 | */
|
---|
| 483 | typedef DECLCALLBACK(void) FNRTHTTPDOWNLDPROGRCALLBACK(RTHTTP hHttp, void *pvUser, uint64_t cbDownloadTotal, uint64_t cbDownloaded);
|
---|
| 484 | /** Pointer to a download progress callback. */
|
---|
| 485 | typedef FNRTHTTPDOWNLDPROGRCALLBACK *PFNRTHTTPDOWNLDPROGRCALLBACK;
|
---|
| 486 |
|
---|
| 487 | /**
|
---|
[74090] | 488 | * Set the callback function which is called during (GET)
|
---|
[58217] | 489 | *
|
---|
| 490 | * @returns IPRT status code.
|
---|
[74046] | 491 | * @param hHttp The HTTP client handle.
|
---|
[74077] | 492 | * @param pfnCallback Progress function to be called. Set it to
|
---|
[58217] | 493 | * NULL to disable the callback.
|
---|
[58221] | 494 | * @param pvUser Convenience pointer for the callback function.
|
---|
[58217] | 495 | */
|
---|
[74077] | 496 | RTR3DECL(int) RTHttpSetDownloadProgressCallback(RTHTTP hHttp, PFNRTHTTPDOWNLDPROGRCALLBACK pfnCallback, void *pvUser);
|
---|
[58217] | 497 |
|
---|
[74090] | 498 | /**
|
---|
| 499 | * Callback function for receiving body data.
|
---|
| 500 | *
|
---|
| 501 | * @returns IPRT status code.
|
---|
| 502 | * @param hHttp The HTTP client handle.
|
---|
| 503 | * @param pvBuf Pointer to buffer with body bytes.
|
---|
| 504 | * @param cbBuf Number of bytes in the buffer.
|
---|
| 505 | * @param uHttpStatus The HTTP status code.
|
---|
| 506 | * @param offContent The byte offset corresponding to the start of @a pvBuf.
|
---|
| 507 | * @param cbContent The content length field value, UINT64_MAX if not available.
|
---|
| 508 | * @param pvUser The user parameter.
|
---|
[74224] | 509 | *
|
---|
| 510 | * @note The @a offContent parameter does not imply random access or anthing
|
---|
| 511 | * like that, it is just a convenience provided by the caller. The
|
---|
| 512 | * value is the sum of the previous @a cbBuf values.
|
---|
[74090] | 513 | */
|
---|
| 514 | typedef DECLCALLBACK(int) FNRTHTTPDOWNLOADCALLBACK(RTHTTP hHttp, void const *pvBuf, size_t cbBuf, uint32_t uHttpStatus,
|
---|
| 515 | uint64_t offContent, uint64_t cbContent, void *pvUser);
|
---|
| 516 | /** Pointer to a download data receiver callback. */
|
---|
| 517 | typedef FNRTHTTPDOWNLOADCALLBACK *PFNRTHTTPDOWNLOADCALLBACK;
|
---|
[58217] | 518 |
|
---|
[74090] | 519 | /**
|
---|
| 520 | * Set the callback function for downloading data (HTTP GET).
|
---|
| 521 | *
|
---|
| 522 | * @returns IPRT status code.
|
---|
| 523 | * @param hHttp The HTTP client handle.
|
---|
| 524 | * @param fFlags RTHTTPDOWNLOAD_F_XXX.
|
---|
| 525 | * @param pfnCallback The callback function. Pass NULL to reset the callback.
|
---|
| 526 | * @param pvUser Convenience pointer for the callback function.
|
---|
| 527 | *
|
---|
| 528 | * @remarks There can only be one download callback, so it is not possible to
|
---|
| 529 | * call this method for different status codes. Only the last one
|
---|
| 530 | * with be honored.
|
---|
[74091] | 531 | *
|
---|
| 532 | * @note This only works reliably with RTHttpPerform at the moment.
|
---|
[74090] | 533 | */
|
---|
| 534 | RTR3DECL(int) RTHttpSetDownloadCallback(RTHTTP hHttp, uint32_t fFlags, PFNRTHTTPDOWNLOADCALLBACK pfnCallback, void *pvUser);
|
---|
[73699] | 535 |
|
---|
[74090] | 536 | /** @name RTHTTPDOWNLOAD_F_XXX */
|
---|
| 537 | /** The lower 10 bits gives the HTTP status required by the callback.
|
---|
| 538 | * For all other status codes, any body data will be returned via the
|
---|
| 539 | * RTHttpPerform ppvBody/pcbBody return parameters. */
|
---|
[74126] | 540 | #define RTHTTPDOWNLOAD_F_ONLY_STATUS_MASK UINT32_C(0x000003ff)
|
---|
[74090] | 541 | /** Callback requires no special HTTP status. */
|
---|
[74126] | 542 | #define RTHTTPDOWNLOAD_F_ANY_STATUS UINT32_C(0x000003ff)
|
---|
[74090] | 543 | /** @} */
|
---|
[73699] | 544 |
|
---|
| 545 |
|
---|
[74090] | 546 | /**
|
---|
| 547 | * Callback function for producing body data for uploading.
|
---|
| 548 | *
|
---|
| 549 | * @returns IPRT status code.
|
---|
| 550 | * @param hHttp The HTTP client handle.
|
---|
| 551 | * @param pvBuf Where to put the data to upload
|
---|
| 552 | * @param cbBuf Max number of bytes to provide.
|
---|
| 553 | * @param offContent The byte offset corresponding to the start of @a pvBuf.
|
---|
| 554 | * @param pcbActual Actual number of bytes provided.
|
---|
| 555 | * @param pvUser The user parameter.
|
---|
[74224] | 556 | *
|
---|
| 557 | * @note The @a offContent parameter does not imply random access or anthing
|
---|
| 558 | * like that, it is just a convenience provided by the caller. The
|
---|
| 559 | * value is the sum of the previously returned @a *pcbActual values.
|
---|
[74090] | 560 | */
|
---|
| 561 | typedef DECLCALLBACK(int) FNRTHTTPUPLOADCALLBACK(RTHTTP hHttp, void *pvBuf, size_t cbBuf, uint64_t offContent,
|
---|
| 562 | size_t *pcbActual, void *pvUser);
|
---|
| 563 | /** Pointer to an upload data producer callback. */
|
---|
| 564 | typedef FNRTHTTPUPLOADCALLBACK *PFNRTHTTPUPLOADCALLBACK;
|
---|
[73699] | 565 |
|
---|
[74090] | 566 | /**
|
---|
| 567 | * Set the callback function for providing upload data (HTTP PUT / POST).
|
---|
| 568 | *
|
---|
| 569 | * @returns IPRT status code.
|
---|
| 570 | * @param hHttp The HTTP client handle.
|
---|
| 571 | * @param cbContent The content length, UINT64_MAX if not know or specified separately.
|
---|
| 572 | * @param pfnCallback The callback function. Pass NULL to reset the callback.
|
---|
| 573 | * @param pvUser Convenience pointer for the callback function.
|
---|
[74091] | 574 | *
|
---|
| 575 | * @note This only works reliably with RTHttpPerform at the moment.
|
---|
[74090] | 576 | */
|
---|
| 577 | RTR3DECL(int) RTHttpSetUploadCallback(RTHTTP hHttp, uint64_t cbContent, PFNRTHTTPUPLOADCALLBACK pfnCallback, void *pvUser);
|
---|
[73699] | 578 |
|
---|
| 579 |
|
---|
[74090] | 580 | /**
|
---|
| 581 | * Callback for consuming header fields.
|
---|
| 582 | *
|
---|
| 583 | * @returns IPRT status code.
|
---|
| 584 | * @param hHttp The HTTP client handle.
|
---|
[74222] | 585 | * @param uMatchWord Match word constructed by RTHTTP_MAKE_HDR_MATCH_WORD
|
---|
| 586 | * @param pchField The field name (not zero terminated).
|
---|
[74250] | 587 | * Not necessarily valid UTF-8!
|
---|
[74090] | 588 | * @param cchField The length of the field.
|
---|
[74222] | 589 | * @param pchValue The field value (not zero terminated).
|
---|
[74250] | 590 | * Not necessarily valid UTF-8!
|
---|
[74090] | 591 | * @param cchValue The length of the value.
|
---|
| 592 | * @param pvUser The user parameter.
|
---|
[74250] | 593 | *
|
---|
| 594 | * @remarks This is called with two fictitious header fields too:
|
---|
| 595 | * - ':http-status-line' -- the HTTP/{version} {status-code} stuff.
|
---|
| 596 | * - ':end-of-headers' -- marks the end of header callbacks.
|
---|
[74090] | 597 | */
|
---|
[74222] | 598 | typedef DECLCALLBACK(int) FNRTHTTPHEADERCALLBACK(RTHTTP hHttp, uint32_t uMatchWord, const char *pchField, size_t cchField,
|
---|
| 599 | const char *pchValue, size_t cchValue, void *pvUser);
|
---|
[74090] | 600 | /** Pointer to a header field consumer callback. */
|
---|
| 601 | typedef FNRTHTTPHEADERCALLBACK *PFNRTHTTPHEADERCALLBACK;
|
---|
[73699] | 602 |
|
---|
[74090] | 603 | /**
|
---|
[74222] | 604 | * Forms a fast header match word.
|
---|
| 605 | *
|
---|
| 606 | * @returns Fast header match word.
|
---|
| 607 | * @param a_cchField The length of the header field name.
|
---|
| 608 | * @param a_chLower1 The first character in the name, lowercased.
|
---|
| 609 | * @param a_chLower2 The second character in the name, lowercased.
|
---|
| 610 | * @param a_chLower3 The third character in the name, lowercased.
|
---|
| 611 | */
|
---|
| 612 | #define RTHTTP_MAKE_HDR_MATCH_WORD(a_cchField, a_chLower1, a_chLower2, a_chLower3) \
|
---|
| 613 | RT_MAKE_U32_FROM_U8(a_cchField, a_chLower1, a_chLower2, a_chLower3)
|
---|
| 614 |
|
---|
| 615 | /**
|
---|
[74090] | 616 | * Set the callback function for processing header fields in the response.
|
---|
| 617 | *
|
---|
| 618 | * @returns IPRT status code.
|
---|
| 619 | * @param hHttp The HTTP client handle.
|
---|
| 620 | * @param pfnCallback The callback function. Pass NULL to reset the callback.
|
---|
| 621 | * @param pvUser Convenience pointer for the callback function.
|
---|
[74091] | 622 | *
|
---|
| 623 | * @note This only works reliably with RTHttpPerform at the moment.
|
---|
[74090] | 624 | */
|
---|
| 625 | RTR3DECL(int) RTHttpSetHeaderCallback(RTHTTP hHttp, PFNRTHTTPHEADERCALLBACK pfnCallback, void *pvUser);
|
---|
| 626 |
|
---|
| 627 |
|
---|
| 628 | /** @name thin wrappers for setting one or a few related curl options
|
---|
| 629 | * @remarks Temporary. Will not be included in the 6.0 release!
|
---|
| 630 | * @{ */
|
---|
| 631 | typedef size_t FNRTHTTPREADCALLBACKRAW(void *pbDst, size_t cbItem, size_t cItems, void *pvUser);
|
---|
| 632 | typedef FNRTHTTPREADCALLBACKRAW *PFNRTHTTPREADCALLBACKRAW;
|
---|
| 633 | #define RT_HTTP_READCALLBACK_ABORT 0x10000000 /* CURL_READFUNC_ABORT */
|
---|
| 634 | RTR3DECL(int) RTHttpRawSetReadCallback(RTHTTP hHttp, PFNRTHTTPREADCALLBACKRAW pfnRead, void *pvUser);
|
---|
| 635 |
|
---|
| 636 | typedef size_t FNRTHTTPWRITECALLBACKRAW(char *pbSrc, size_t cbItem, size_t cItems, void *pvUser);
|
---|
| 637 | typedef FNRTHTTPWRITECALLBACKRAW *PFNRTHTTPWRITECALLBACKRAW;
|
---|
| 638 | RTR3DECL(int) RTHttpRawSetWriteCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACKRAW pfnWrite, void *pvUser);
|
---|
| 639 | RTR3DECL(int) RTHttpRawSetWriteHeaderCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACKRAW pfnWrite, void *pvUser);
|
---|
| 640 |
|
---|
[73699] | 641 | RTR3DECL(int) RTHttpRawSetUrl(RTHTTP hHttp, const char *pszUrl);
|
---|
| 642 |
|
---|
| 643 | RTR3DECL(int) RTHttpRawSetGet(RTHTTP hHttp);
|
---|
| 644 | RTR3DECL(int) RTHttpRawSetHead(RTHTTP hHttp);
|
---|
| 645 | RTR3DECL(int) RTHttpRawSetPost(RTHTTP hHttp);
|
---|
| 646 | RTR3DECL(int) RTHttpRawSetPut(RTHTTP hHttp);
|
---|
| 647 | RTR3DECL(int) RTHttpRawSetDelete(RTHTTP hHttp);
|
---|
| 648 | RTR3DECL(int) RTHttpRawSetCustomRequest(RTHTTP hHttp, const char *pszVerb);
|
---|
| 649 |
|
---|
| 650 | RTR3DECL(int) RTHttpRawSetPostFields(RTHTTP hHttp, const void *pv, size_t cb);
|
---|
| 651 | RTR3DECL(int) RTHttpRawSetInfileSize(RTHTTP hHttp, RTFOFF cb);
|
---|
| 652 |
|
---|
| 653 | RTR3DECL(int) RTHttpRawSetVerbose(RTHTTP hHttp, bool fValue);
|
---|
| 654 | RTR3DECL(int) RTHttpRawSetTimeout(RTHTTP hHttp, long sec);
|
---|
| 655 |
|
---|
| 656 | RTR3DECL(int) RTHttpRawPerform(RTHTTP hHttp);
|
---|
| 657 |
|
---|
| 658 | RTR3DECL(int) RTHttpRawGetResponseCode(RTHTTP hHttp, long *plCode);
|
---|
[73857] | 659 | /** @} */
|
---|
[73699] | 660 |
|
---|
[46050] | 661 | /** @} */
|
---|
| 662 |
|
---|
[43645] | 663 | RT_C_DECLS_END
|
---|
| 664 |
|
---|
[76585] | 665 | #endif /* !IPRT_INCLUDED_http_h */
|
---|
[43645] | 666 |
|
---|