VirtualBox

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

Last change on this file since 78415 was 78066, checked in by vboxsync, 6 years ago

IPRT,GUI: Workaround for certificate downloads getting redirected to https.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.4 KB
Line 
1/* $Id: http.h 78066 2019-04-09 16:02:32Z vboxsync $ */
2/** @file
3 * IPRT - Simple HTTP/HTTPS Client API.
4 */
5
6/*
7 * Copyright (C) 2012-2019 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_INCLUDED_http_h
28#define IPRT_INCLUDED_http_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <iprt/types.h>
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_rt_http RTHttp - Simple HTTP/HTTPS Client API
38 * @ingroup grp_rt
39 * @{
40 */
41
42/** @todo the following three definitions may move the iprt/types.h later. */
43/** HTTP/HTTPS client handle. */
44typedef R3PTRTYPE(struct RTHTTPINTERNAL *) RTHTTP;
45/** Pointer to a HTTP/HTTPS client handle. */
46typedef RTHTTP *PRTHTTP;
47/** Nil HTTP/HTTPS client handle. */
48#define NIL_RTHTTP ((RTHTTP)0)
49
50
51/**
52 * Creates a HTTP client instance.
53 *
54 * @returns IPRT status code.
55 * @param phHttp Where to store the HTTP handle.
56 */
57RTR3DECL(int) RTHttpCreate(PRTHTTP phHttp);
58
59/**
60 * Resets a HTTP client instance.
61 *
62 * @returns IPRT status code.
63 * @param hHttp Handle to the HTTP interface.
64 * @param fFlags Flags, RTHTTP_RESET_F_XXX.
65 */
66RTR3DECL(int) RTHttpReset(RTHTTP hHttp, uint32_t fFlags);
67
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
77/**
78 * Destroys a HTTP client instance.
79 *
80 * @returns IPRT status code.
81 * @param hHttp Handle to the HTTP interface.
82 */
83RTR3DECL(int) RTHttpDestroy(RTHTTP hHttp);
84
85
86/**
87 * Retrieve the redir location for 301 responses.
88 *
89 * @param hHttp Handle to the HTTP interface.
90 * @param ppszRedirLocation Where to store the string. To be freed with
91 * RTStrFree().
92 */
93RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation);
94
95/**
96 * Perform a simple blocking HTTP GET request.
97 *
98 * This is a just a convenient wrapper around RTHttpGetBinary that returns a
99 * different type and sheds a parameter.
100 *
101 * @returns iprt status code.
102 *
103 * @param hHttp The HTTP client handle.
104 * @param pszUrl URL.
105 * @param ppszNotUtf8 Where to return the pointer to the HTTP response.
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.
121 */
122RTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
123
124/**
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 *
132 * @param hHttp The HTTP client handle.
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 */
151RTR3DECL(int) RTHttpGetHeaderText(RTHTTP hHttp, const char *pszUrl, char **ppszNotUtf8);
152
153/**
154 * Frees memory returned by RTHttpGetText.
155 *
156 * @param pszNotUtf8 What RTHttpGetText returned.
157 */
158RTR3DECL(void) RTHttpFreeResponseText(char *pszNotUtf8);
159
160/**
161 * Perform a simple blocking HTTP GET request.
162 *
163 * @returns iprt status code.
164 *
165 * @param hHttp The HTTP client handle.
166 * @param pszUrl The URL.
167 * @param ppvResponse Where to store the HTTP response data. Use
168 * RTHttpFreeResponse to free.
169 * @param pcb Size of the returned buffer.
170 */
171RTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
172
173/**
174 * Perform a simple blocking HTTP HEAD request.
175 *
176 * @returns iprt status code.
177 *
178 * @param hHttp The HTTP client handle.
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 */
184RTR3DECL(int) RTHttpGetHeaderBinary(RTHTTP hHttp, const char *pszUrl, void **ppvResponse, size_t *pcb);
185
186/**
187 * Frees memory returned by RTHttpGetBinary.
188 *
189 * @param pvResponse What RTHttpGetBinary returned.
190 */
191RTR3DECL(void) RTHttpFreeResponse(void *pvResponse);
192
193/**
194 * Perform a simple blocking HTTP request, writing the output to a file.
195 *
196 * @returns iprt status code.
197 *
198 * @param hHttp The HTTP client handle.
199 * @param pszUrl The URL.
200 * @param pszDstFile The destination file name.
201 */
202RTR3DECL(int) RTHttpGetFile(RTHTTP hHttp, const char *pszUrl, const char *pszDstFile);
203
204/** HTTP methods. */
205typedef 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
220/**
221 * Returns the name of the HTTP method.
222 * @returns Read only string.
223 * @param enmMethod The HTTP method to name.
224 */
225RTR3DECL(const char *) RTHttpMethodName(RTHTTPMETHOD enmMethod);
226
227/**
228 * Performs generic blocking HTTP request, optionally returning the body and headers.
229 *
230 * @returns IPRT status code.
231 * @param hHttp The HTTP client handle.
232 * @param pszUrl The URL.
233 * @param enmMethod The HTTP method for the request.
234 * @param pvReqBody Pointer to the request body. NULL if none.
235 * @param cbReqBody Size of the request body. Zero if none.
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 */
242RTR3DECL(int) RTHttpPerform(RTHTTP hHttp, const char *pszUrl, RTHTTPMETHOD enmMethod, void const *pvReqBody, size_t cbReqBody,
243 uint32_t *puHttpStatus, void **ppvHeaders, size_t *pcbHeaders, void **ppvBody, size_t *pcbBody);
244
245
246/**
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 *
253 * @param hHttp The HTTP client handle.
254 */
255RTR3DECL(int) RTHttpAbort(RTHTTP hHttp);
256
257/**
258 * Tells the HTTP interface to use the system proxy configuration.
259 *
260 * @returns iprt status code.
261 * @param hHttp The HTTP client handle.
262 */
263RTR3DECL(int) RTHttpUseSystemProxySettings(RTHTTP hHttp);
264
265/**
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 */
287RTR3DECL(int) RTHttpSetProxyByUrl(RTHTTP hHttp, const char *pszUrl);
288
289/**
290 * Specify proxy settings.
291 *
292 * @returns iprt status code.
293 *
294 * @param hHttp The HTTP client handle.
295 * @param pszProxyUrl URL of the proxy server.
296 * @param uPort port number of the proxy, use 0 for not specifying a port.
297 * @param pszProxyUser Username, pass NULL for no authentication.
298 * @param pszProxyPwd Password, pass NULL for no authentication.
299 *
300 * @todo This API does not allow specifying the type of proxy server... We're
301 * currently assuming it's a HTTP proxy.
302 *
303 * @deprecated Use RTHttpSetProxyByUrl.
304 */
305RTR3DECL(int) RTHttpSetProxy(RTHTTP hHttp, const char *pszProxyUrl, uint32_t uPort,
306 const char *pszProxyUser, const char *pszProxyPwd);
307
308/**
309 * Set follow redirects (3xx)
310 *
311 * @returns iprt status code.
312 *
313 * @param hHttp The HTTP client handle.
314 * @param cMaxRedirects Max number of redirects to follow. Zero if no
315 * redirects should be followed but instead returned
316 * to caller.
317 */
318RTR3DECL(int) RTHttpSetFollowRedirects(RTHTTP hHttp, uint32_t cMaxRedirects);
319
320/**
321 * Gets the follow redirect setting.
322 *
323 * @returns cMaxRedirects value, 0 means not to follow.
324 * @param hHttp The HTTP client handle.
325 */
326RTR3DECL(uint32_t) RTHttpGetFollowRedirects(RTHTTP hHttp);
327
328/**
329 * Set custom raw headers.
330 *
331 * @returns iprt status code.
332 *
333 * @param hHttp The HTTP client handle.
334 * @param cHeaders Number of custom headers.
335 * @param papszHeaders Array of headers in form "foo: bar".
336 */
337RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders);
338
339/** @name RTHTTPADDHDR_F_XXX - Flags for RTHttpAddRawHeader and RTHttpAddHeader
340 * @{ */
341#define RTHTTPADDHDR_F_BACK UINT32_C(0) /**< Append the header. */
342#define RTHTTPADDHDR_F_FRONT UINT32_C(1) /**< Prepend the header. */
343/** @} */
344
345/**
346 * Adds a raw header.
347 *
348 * @returns IPRT status code.
349 * @param hHttp The HTTP client handle.
350 * @param pszHeader Header string on the form "foo: bar".
351 * @param fFlags RTHTTPADDHDR_F_FRONT or RTHTTPADDHDR_F_BACK.
352 */
353RTR3DECL(int) RTHttpAddRawHeader(RTHTTP hHttp, const char *pszHeader, uint32_t fFlags);
354
355/**
356 * Adds a header field and value.
357 *
358 * @returns IPRT status code.
359 * @param hHttp The HTTP client handle.
360 * @param pszField The header field name.
361 * @param pszValue The header field value.
362 * @param cchValue The value length or RTSTR_MAX.
363 * @param fFlags Only RTHTTPADDHDR_F_FRONT or RTHTTPADDHDR_F_BACK,
364 * may be extended with encoding controlling flags if
365 * needed later.
366 */
367RTR3DECL(int) RTHttpAddHeader(RTHTTP hHttp, const char *pszField, const char *pszValue, size_t cchValue, uint32_t fFlags);
368
369/**
370 * Gets a header previously added using RTHttpSetHeaders, RTHttpAppendRawHeader
371 * or RTHttpAppendHeader.
372 *
373 * @returns Pointer to the header value on if found, otherwise NULL.
374 * @param hHttp The HTTP client handle.
375 * @param pszField The field name (no colon).
376 * @param cchField The length of the field name or RTSTR_MAX.
377 */
378RTR3DECL(const char *) RTHttpGetHeader(RTHTTP hHttp, const char *pszField, size_t cchField);
379
380/**
381 * Gets the number of headers specified by RTHttpAddHeader, RTHttpAddRawHeader or RTHttpSetHeaders.
382 *
383 * @returns Number of headers.
384 * @param hHttp The HTTP client handle.
385 * @note This can be slow and is only really intended for test cases and debugging!
386 */
387RTR3DECL(size_t) RTHttpGetHeaderCount(RTHTTP hHttp);
388
389/**
390 * Gets a header by ordinal.
391 *
392 * Can be used together with RTHttpGetHeaderCount by test case and debug code to
393 * iterate headers specified by RTHttpAddHeader, RTHttpAddRawHeader or RTHttpSetHeaders.
394 *
395 * @returns The header string ("field: value").
396 * @param hHttp The HTTP client handle.
397 * @param iOrdinal The number of the header to get.
398 * @note This can be slow and is only really intended for test cases and debugging!
399 */
400RTR3DECL(const char *) RTHttpGetByOrdinal(RTHTTP hHttp, size_t iOrdinal);
401
402/**
403 * Sign all headers present according to pending "Signing HTTP Messages" RFC.
404 *
405 * Currently hardcoded RSA-SHA-256 algorithm choice.
406 *
407 * @returns IPRT status code.
408 * @param hHttp The HTTP client handle.
409 * @param enmMethod The HTTP method that will be used for the request.
410 * @param pszUrl The target URL for the request.
411 * @param hKey The RSA key to use when signing.
412 * @param pszKeyId The key ID string corresponding to @a hKey.
413 * @param fFlags Reserved for future, MBZ.
414 *
415 * @note Caller is responsible for making all desired fields are present before
416 * making the call.
417 *
418 * @remarks Latest RFC draft at the time of writing:
419 * https://tools.ietf.org/html/draft-cavage-http-signatures-10
420 */
421RTR3DECL(int) RTHttpSignHeaders(RTHTTP hHttp, RTHTTPMETHOD enmMethod, const char *pszUrl,
422 RTCRKEY hKey, const char *pszKeyId, uint32_t fFlags);
423
424/**
425 * Tells the HTTP client instance to gather system CA certificates into a
426 * temporary file and use it for HTTPS connections.
427 *
428 * This will be called automatically if a 'https' URL is presented and
429 * RTHttpSetCaFile hasn't been called yet.
430 *
431 * @returns IPRT status code.
432 * @param hHttp The HTTP client handle.
433 * @param pErrInfo Where to store additional error/warning information.
434 * Optional.
435 */
436RTR3DECL(int) RTHttpUseTemporaryCaFile(RTHTTP hHttp, PRTERRINFO pErrInfo);
437
438/**
439 * Set a custom certification authority file, containing root certificates.
440 *
441 * @returns iprt status code.
442 *
443 * @param hHttp The HTTP client handle.
444 * @param pszCAFile File name containing root certificates.
445 *
446 * @remarks For portable HTTPS support, use RTHttpGatherCaCertsInFile and pass
447 */
448RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pszCAFile);
449
450/**
451 * Gathers certificates into a cryptographic (certificate) store
452 *
453 * This is a just a combination of RTHttpGatherCaCertsInStore and
454 * RTCrStoreCertExportAsPem.
455 *
456 * @returns IPRT status code.
457 * @param hStore The certificate store to gather the certificates
458 * in.
459 * @param fFlags RTHTTPGATHERCACERT_F_XXX.
460 * @param pErrInfo Where to store additional error/warning information.
461 * Optional.
462 */
463RTR3DECL(int) RTHttpGatherCaCertsInStore(RTCRSTORE hStore, uint32_t fFlags, PRTERRINFO pErrInfo);
464
465/**
466 * Gathers certificates into a file that can be used with RTHttpSetCAFile.
467 *
468 * This is a just a combination of RTHttpGatherCaCertsInStore and
469 * RTCrStoreCertExportAsPem.
470 *
471 * @returns IPRT status code.
472 * @param pszCaFile The output file.
473 * @param fFlags RTHTTPGATHERCACERT_F_XXX.
474 * @param pErrInfo Where to store additional error/warning information.
475 * Optional.
476 */
477RTR3DECL(int) RTHttpGatherCaCertsInFile(const char *pszCaFile, uint32_t fFlags, PRTERRINFO pErrInfo);
478
479/**
480 * Set whether to verify the peer's SSL certificate.
481 *
482 * The default is to verify it. It can however sometimes be useful or even
483 * necessary to skip this.
484 *
485 * @returns iprt status code.
486 *
487 * @param hHttp The HTTP client handle.
488 * @param fVerify Verify the certificate if @a true.
489 */
490RTR3DECL(int) RTHttpSetVerifyPeer(RTHTTP hHttp, bool fVerify);
491
492/**
493 * Get the state of the peer's SSL certificate setting.
494 *
495 * @returns true if we verify the SSL certificate, false if not.
496 * @param hHttp The HTTP client handle.
497 */
498RTR3DECL(bool) RTHttpGetVerifyPeer(RTHTTP hHttp);
499
500/**
501 * Callback function to be called during RTHttpGet*().
502 *
503 * Register it using RTHttpSetDownloadProgressCallback().
504 *
505 * @param hHttp The HTTP client handle.
506 * @param pvUser The user parameter specified when registering the callback.
507 * @param cbDowloadTotal The content-length value, if available.
508 * Warning! Not entirely clear what it will be if
509 * unavailable, probably 0.
510 * @param cbDowloaded How much was downloaded thus far.
511 */
512typedef DECLCALLBACK(void) FNRTHTTPDOWNLDPROGRCALLBACK(RTHTTP hHttp, void *pvUser, uint64_t cbDownloadTotal, uint64_t cbDownloaded);
513/** Pointer to a download progress callback. */
514typedef FNRTHTTPDOWNLDPROGRCALLBACK *PFNRTHTTPDOWNLDPROGRCALLBACK;
515
516/**
517 * Set the callback function which is called during (GET)
518 *
519 * @returns IPRT status code.
520 * @param hHttp The HTTP client handle.
521 * @param pfnCallback Progress function to be called. Set it to
522 * NULL to disable the callback.
523 * @param pvUser Convenience pointer for the callback function.
524 */
525RTR3DECL(int) RTHttpSetDownloadProgressCallback(RTHTTP hHttp, PFNRTHTTPDOWNLDPROGRCALLBACK pfnCallback, void *pvUser);
526
527/**
528 * Callback function for receiving body data.
529 *
530 * @returns IPRT status code.
531 * @param hHttp The HTTP client handle.
532 * @param pvBuf Pointer to buffer with body bytes.
533 * @param cbBuf Number of bytes in the buffer.
534 * @param uHttpStatus The HTTP status code.
535 * @param offContent The byte offset corresponding to the start of @a pvBuf.
536 * @param cbContent The content length field value, UINT64_MAX if not available.
537 * @param pvUser The user parameter.
538 *
539 * @note The @a offContent parameter does not imply random access or anthing
540 * like that, it is just a convenience provided by the caller. The
541 * value is the sum of the previous @a cbBuf values.
542 */
543typedef DECLCALLBACK(int) FNRTHTTPDOWNLOADCALLBACK(RTHTTP hHttp, void const *pvBuf, size_t cbBuf, uint32_t uHttpStatus,
544 uint64_t offContent, uint64_t cbContent, void *pvUser);
545/** Pointer to a download data receiver callback. */
546typedef FNRTHTTPDOWNLOADCALLBACK *PFNRTHTTPDOWNLOADCALLBACK;
547
548/**
549 * Set the callback function for downloading data (HTTP GET).
550 *
551 * @returns IPRT status code.
552 * @param hHttp The HTTP client handle.
553 * @param fFlags RTHTTPDOWNLOAD_F_XXX.
554 * @param pfnCallback The callback function. Pass NULL to reset the callback.
555 * @param pvUser Convenience pointer for the callback function.
556 *
557 * @remarks There can only be one download callback, so it is not possible to
558 * call this method for different status codes. Only the last one
559 * with be honored.
560 *
561 * @note This only works reliably with RTHttpPerform at the moment.
562 */
563RTR3DECL(int) RTHttpSetDownloadCallback(RTHTTP hHttp, uint32_t fFlags, PFNRTHTTPDOWNLOADCALLBACK pfnCallback, void *pvUser);
564
565/** @name RTHTTPDOWNLOAD_F_XXX */
566/** The lower 10 bits gives the HTTP status required by the callback.
567 * For all other status codes, any body data will be returned via the
568 * RTHttpPerform ppvBody/pcbBody return parameters. */
569#define RTHTTPDOWNLOAD_F_ONLY_STATUS_MASK UINT32_C(0x000003ff)
570/** Callback requires no special HTTP status. */
571#define RTHTTPDOWNLOAD_F_ANY_STATUS UINT32_C(0x000003ff)
572/** @} */
573
574
575/**
576 * Callback function for producing body data for uploading.
577 *
578 * @returns IPRT status code.
579 * @param hHttp The HTTP client handle.
580 * @param pvBuf Where to put the data to upload
581 * @param cbBuf Max number of bytes to provide.
582 * @param offContent The byte offset corresponding to the start of @a pvBuf.
583 * @param pcbActual Actual number of bytes provided.
584 * @param pvUser The user parameter.
585 *
586 * @note The @a offContent parameter does not imply random access or anthing
587 * like that, it is just a convenience provided by the caller. The
588 * value is the sum of the previously returned @a *pcbActual values.
589 */
590typedef DECLCALLBACK(int) FNRTHTTPUPLOADCALLBACK(RTHTTP hHttp, void *pvBuf, size_t cbBuf, uint64_t offContent,
591 size_t *pcbActual, void *pvUser);
592/** Pointer to an upload data producer callback. */
593typedef FNRTHTTPUPLOADCALLBACK *PFNRTHTTPUPLOADCALLBACK;
594
595/**
596 * Set the callback function for providing upload data (HTTP PUT / POST).
597 *
598 * @returns IPRT status code.
599 * @param hHttp The HTTP client handle.
600 * @param cbContent The content length, UINT64_MAX if not know or specified separately.
601 * @param pfnCallback The callback function. Pass NULL to reset the callback.
602 * @param pvUser Convenience pointer for the callback function.
603 *
604 * @note This only works reliably with RTHttpPerform at the moment.
605 */
606RTR3DECL(int) RTHttpSetUploadCallback(RTHTTP hHttp, uint64_t cbContent, PFNRTHTTPUPLOADCALLBACK pfnCallback, void *pvUser);
607
608
609/**
610 * Callback for consuming header fields.
611 *
612 * @returns IPRT status code.
613 * @param hHttp The HTTP client handle.
614 * @param uMatchWord Match word constructed by RTHTTP_MAKE_HDR_MATCH_WORD
615 * @param pchField The field name (not zero terminated).
616 * Not necessarily valid UTF-8!
617 * @param cchField The length of the field.
618 * @param pchValue The field value (not zero terminated).
619 * Not necessarily valid UTF-8!
620 * @param cchValue The length of the value.
621 * @param pvUser The user parameter.
622 *
623 * @remarks This is called with two fictitious header fields too:
624 * - ':http-status-line' -- the HTTP/{version} {status-code} stuff.
625 * - ':end-of-headers' -- marks the end of header callbacks.
626 */
627typedef DECLCALLBACK(int) FNRTHTTPHEADERCALLBACK(RTHTTP hHttp, uint32_t uMatchWord, const char *pchField, size_t cchField,
628 const char *pchValue, size_t cchValue, void *pvUser);
629/** Pointer to a header field consumer callback. */
630typedef FNRTHTTPHEADERCALLBACK *PFNRTHTTPHEADERCALLBACK;
631
632/**
633 * Forms a fast header match word.
634 *
635 * @returns Fast header match word.
636 * @param a_cchField The length of the header field name.
637 * @param a_chLower1 The first character in the name, lowercased.
638 * @param a_chLower2 The second character in the name, lowercased.
639 * @param a_chLower3 The third character in the name, lowercased.
640 */
641#define RTHTTP_MAKE_HDR_MATCH_WORD(a_cchField, a_chLower1, a_chLower2, a_chLower3) \
642 RT_MAKE_U32_FROM_U8(a_cchField, a_chLower1, a_chLower2, a_chLower3)
643
644/**
645 * Set the callback function for processing header fields in the response.
646 *
647 * @returns IPRT status code.
648 * @param hHttp The HTTP client handle.
649 * @param pfnCallback The callback function. Pass NULL to reset the callback.
650 * @param pvUser Convenience pointer for the callback function.
651 *
652 * @note This only works reliably with RTHttpPerform at the moment.
653 */
654RTR3DECL(int) RTHttpSetHeaderCallback(RTHTTP hHttp, PFNRTHTTPHEADERCALLBACK pfnCallback, void *pvUser);
655
656
657/** @name thin wrappers for setting one or a few related curl options
658 * @remarks Temporary. Will not be included in the 6.0 release!
659 * @{ */
660typedef size_t FNRTHTTPREADCALLBACKRAW(void *pbDst, size_t cbItem, size_t cItems, void *pvUser);
661typedef FNRTHTTPREADCALLBACKRAW *PFNRTHTTPREADCALLBACKRAW;
662#define RT_HTTP_READCALLBACK_ABORT 0x10000000 /* CURL_READFUNC_ABORT */
663RTR3DECL(int) RTHttpRawSetReadCallback(RTHTTP hHttp, PFNRTHTTPREADCALLBACKRAW pfnRead, void *pvUser);
664
665typedef size_t FNRTHTTPWRITECALLBACKRAW(char *pbSrc, size_t cbItem, size_t cItems, void *pvUser);
666typedef FNRTHTTPWRITECALLBACKRAW *PFNRTHTTPWRITECALLBACKRAW;
667RTR3DECL(int) RTHttpRawSetWriteCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACKRAW pfnWrite, void *pvUser);
668RTR3DECL(int) RTHttpRawSetWriteHeaderCallback(RTHTTP hHttp, PFNRTHTTPWRITECALLBACKRAW pfnWrite, void *pvUser);
669
670RTR3DECL(int) RTHttpRawSetUrl(RTHTTP hHttp, const char *pszUrl);
671
672RTR3DECL(int) RTHttpRawSetGet(RTHTTP hHttp);
673RTR3DECL(int) RTHttpRawSetHead(RTHTTP hHttp);
674RTR3DECL(int) RTHttpRawSetPost(RTHTTP hHttp);
675RTR3DECL(int) RTHttpRawSetPut(RTHTTP hHttp);
676RTR3DECL(int) RTHttpRawSetDelete(RTHTTP hHttp);
677RTR3DECL(int) RTHttpRawSetCustomRequest(RTHTTP hHttp, const char *pszVerb);
678
679RTR3DECL(int) RTHttpRawSetPostFields(RTHTTP hHttp, const void *pv, size_t cb);
680RTR3DECL(int) RTHttpRawSetInfileSize(RTHTTP hHttp, RTFOFF cb);
681
682RTR3DECL(int) RTHttpRawSetVerbose(RTHTTP hHttp, bool fValue);
683RTR3DECL(int) RTHttpRawSetTimeout(RTHTTP hHttp, long sec);
684
685RTR3DECL(int) RTHttpRawPerform(RTHTTP hHttp);
686
687RTR3DECL(int) RTHttpRawGetResponseCode(RTHTTP hHttp, long *plCode);
688/** @} */
689
690/** @} */
691
692RT_C_DECLS_END
693
694#endif /* !IPRT_INCLUDED_http_h */
695
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