55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/* $Id$ */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/** @file
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * IPRT - Simple HTTP Communication API.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/*
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync * Copyright (C) 2012-2013 Oracle Corporation
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync *
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * available from http://www.virtualbox.org. This file is free software;
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * you can redistribute it and/or modify it under the terms of the GNU
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * General Public License (GPL) as published by the Free Software
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync *
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * The contents of this file may alternatively be used under the terms
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * of the Common Development and Distribution License Version 1.0
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * VirtualBox OSE distribution, in which case the provisions of the
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * CDDL are applicable instead of those of the GPL.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync *
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * You may elect to license modified versions of this file under the
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * terms and conditions of either the GPL or the CDDL or both.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync#ifndef ___iprt_http_h
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync#define ___iprt_http_h
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync#include <iprt/types.h>
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsyncRT_C_DECLS_BEGIN
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/** @defgroup grp_rt_http RTHttp - Simple HTTP API
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * @ingroup grp_rt
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * @{
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/** @todo the following three definitions may move the iprt/types.h later. */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/** RTHTTP interface handle. */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsynctypedef R3PTRTYPE(struct RTHTTPINTERNAL *) RTHTTP;
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/** Pointer to a RTHTTP interface handle. */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsynctypedef RTHTTP *PRTHTTP;
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/** Nil RTHTTP interface handle. */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync#define NIL_RTHTTP ((RTHTTP)0)
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/**
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * Creates a HTTP interface handle.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync *
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * @returns iprt status code.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync *
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * @param phHttp Where to store the HTTP handle.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsyncRTR3DECL(int) RTHttpCreate(PRTHTTP phHttp);
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/**
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * Destroys a HTTP interface handle.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync *
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * @param hHttp Handle to the HTTP interface.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync */
55870b5b46ea9754616dcc3663a110ce71927a0evboxsyncRTR3DECL(void) RTHttpDestroy(RTHTTP hHttp);
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync/**
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync * Retrieve the redir location for 301 responses.
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync *
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync * @param hHttp Handle to the HTTP interface.
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync * @para ppszRedirLocation Where to store the string. To be freed with
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync * RTStrFree().
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync */
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsyncRTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation);
4d5a5dc972ba3130f1a63039de4db726064ba718vboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync/**
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * Perform a simple blocking HTTP request.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync *
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * @returns iprt status code.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync *
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * @param hHttp HTTP interface handle.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync * @param pcszUrl URL.
480487d29a2272cd678c7674d3fce0820d7f7d0dvboxsync * @param ppszResponse HTTP response. It is guaranteed that this string is
480487d29a2272cd678c7674d3fce0820d7f7d0dvboxsync * '\0'-terminated.
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync */
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsyncRTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pcszUrl, char **ppszResponse);
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync/**
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync * Perform a simple blocking HTTP request.
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync *
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync * @returns iprt status code.
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync *
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync * @param hHttp HTTP interface handle.
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync * @param pcszUrl URL.
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync * @param ppvResponse HTTP response.
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync * @param pcb Size of the returned buffer.
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsync */
62fb024c605bcbe2d5fefd31d391cd9fee484150vboxsyncRTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pcszUrl, void **ppvResponse, size_t *pcb);
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync/**
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync * Perform a simple blocking HTTP request, writing the output to a file.
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync *
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync * @returns iprt status code.
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync *
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync * @param hHttp HTTP interface handle.
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync * @param pszUrl URL.
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync * @param pszDstFile The destination file name.
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync */
0109a2240391a89f6556b1545e6cc57f9efab060vboxsyncRTR3DECL(int) RTHttpGetFile(RTHTTP hHttp, const char *pszUrl, const char *pszDstFile);
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync
c7c179e9f819b2616cde22eaf988500140760069vboxsync/**
c7c179e9f819b2616cde22eaf988500140760069vboxsync * Abort a pending HTTP request. A blocking RTHttpGet() call will return with
c7c179e9f819b2616cde22eaf988500140760069vboxsync * VERR_HTTP_ABORTED. It may take some time (current cURL implementation needs
c7c179e9f819b2616cde22eaf988500140760069vboxsync * up to 1 second) before the request is aborted.
c7c179e9f819b2616cde22eaf988500140760069vboxsync *
c7c179e9f819b2616cde22eaf988500140760069vboxsync * @returns iprt status code.
c7c179e9f819b2616cde22eaf988500140760069vboxsync *
c7c179e9f819b2616cde22eaf988500140760069vboxsync * @param hHttp HTTP interface handle.
c7c179e9f819b2616cde22eaf988500140760069vboxsync */
c7c179e9f819b2616cde22eaf988500140760069vboxsyncRTR3DECL(int) RTHttpAbort(RTHTTP hHttp);
c7c179e9f819b2616cde22eaf988500140760069vboxsync
fa6dbd9c9e9645298cca864aa561382469907905vboxsync/**
fa6dbd9c9e9645298cca864aa561382469907905vboxsync * Tells the HTTP interface to use the system proxy configuration.
fa6dbd9c9e9645298cca864aa561382469907905vboxsync *
fa6dbd9c9e9645298cca864aa561382469907905vboxsync * @returns iprt status code.
fa6dbd9c9e9645298cca864aa561382469907905vboxsync * @param hHttp HTTP interface handle.
fa6dbd9c9e9645298cca864aa561382469907905vboxsync */
fa6dbd9c9e9645298cca864aa561382469907905vboxsyncRTR3DECL(int) RTHttpUseSystemProxySettings(RTHTTP hHttp);
fa6dbd9c9e9645298cca864aa561382469907905vboxsync
caee579e589670f6a9444912e548b74ed0764439vboxsync/**
caee579e589670f6a9444912e548b74ed0764439vboxsync * Specify proxy settings.
caee579e589670f6a9444912e548b74ed0764439vboxsync *
caee579e589670f6a9444912e548b74ed0764439vboxsync * @returns iprt status code.
caee579e589670f6a9444912e548b74ed0764439vboxsync *
caee579e589670f6a9444912e548b74ed0764439vboxsync * @param hHttp HTTP interface handle.
caee579e589670f6a9444912e548b74ed0764439vboxsync * @param pcszProxy URL of the proxy
caee579e589670f6a9444912e548b74ed0764439vboxsync * @param uPort port number of the proxy, use 0 for not specifying a port.
caee579e589670f6a9444912e548b74ed0764439vboxsync * @param pcszUser username, pass NULL for no authentication
caee579e589670f6a9444912e548b74ed0764439vboxsync * @param pcszPwd password, pass NULL for no authentication
caee579e589670f6a9444912e548b74ed0764439vboxsync */
caee579e589670f6a9444912e548b74ed0764439vboxsyncRTR3DECL(int) RTHttpSetProxy(RTHTTP hHttp, const char *pcszProxyUrl, uint32_t uPort,
caee579e589670f6a9444912e548b74ed0764439vboxsync const char *pcszProxyUser, const char *pcszProxyPwd);
caee579e589670f6a9444912e548b74ed0764439vboxsync
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync/**
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync * Set custom headers.
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync *
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync * @returns iprt status code.
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync *
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync * @param hHttp HTTP interface handle.
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync * @param cHeaders number of custom headers.
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync * @param pcszHeaders array of headers in form "foo: bar".
194b1350067bed46156efacc6a39044fc3fa64dbvboxsync */
0109a2240391a89f6556b1545e6cc57f9efab060vboxsyncRTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders);
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync/**
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync * Set a custom certification authority file, containing root certificates.
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync *
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync * @returns iprt status code.
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync *
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync * @param hHttp HTTP interface handle.
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync * @param pcszCAFile File name containing root certificates.
a018f30f22605aaa1f809d77716cbb148a732a32vboxsync */
a018f30f22605aaa1f809d77716cbb148a732a32vboxsyncRTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pcszCAFile);
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync/**
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * Determine the digest (fingerprint) of a certificate. Allocate memory for
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * storing the SHA1 fingerprint as well as the SHA512 fingerprint. This
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * memory has to be freed by RTMemFree().
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync *
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @todo Move this function to somewhere else.
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync *
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @returns iprt status code.
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync *
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @param hHttp HTTP interface handle (ignored).
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @param pcszCert The certificate in PEM format.
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @param cbCert Size of the certificate.
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @param pabSha1 Where to store the pointer to the SHA1 fingerprint.
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @param pcbSha1 Where to store the size of the SHA1 fingerprint.
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @param pabSha512 Where to store the pointer to the SHA512 fingerprint.
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync * @param pcbSha512 Where to store the size of the SHA512 fingerprint.
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync */
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsyncRTR3DECL(int) RTHttpCertDigest(RTHTTP hHttp, char *pcszCert, size_t cbCert,
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync uint8_t **pabSha1, size_t *pcbSha1,
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync uint8_t **pabSha512, size_t *pcbSha512);
121ef584b01ad0df6b8f1fcf6b2e9cca69506f59vboxsync
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync/** @} */
0109a2240391a89f6556b1545e6cc57f9efab060vboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsyncRT_C_DECLS_END
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync#endif
55870b5b46ea9754616dcc3663a110ce71927a0evboxsync