http.cpp revision 194b1350067bed46156efacc6a39044fc3fa64db
/* $Id$ */
/** @file
* IPRT - HTTP communication API.
*/
/*
* Copyright (C) 2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct RTHTTPINTERNAL
{
long lLastResp;
struct curl_slist *pHeaders;
typedef RTHTTPINTERNAL *PRTHTTPINTERNAL;
typedef struct RTHTTPMEMCHUNK
{
char *pszMem;
typedef RTHTTPMEMCHUNK *PRTHTTPMEMCHUNK;
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Validates a handle and returns VERR_INVALID_HANDLE if not valid. */
do { \
} while (0)
/** Validates a handle and returns VERR_INVALID_HANDLE if not valid. */
/** Validates a handle and returns (void) if not valid. */
#define RTHTTP_VALID_RETURN_VOID(hHttp) \
do { \
} while (0)
{
if (CURL_FAILED(rcCurl))
return VERR_INTERNAL_ERROR;
if (!pCurl)
return VERR_INTERNAL_ERROR;
if (!pHttpInt)
return VERR_NO_MEMORY;
return VINF_SUCCESS;
}
{
if (!hHttp)
return;
}
{
{
}
return cbAll;
}
const char *pcszProxyUser, const char *pcszProxyPwd)
{
if (CURL_FAILED(rcCurl))
return VERR_INVALID_PARAMETER;
if (uPort != 0)
{
if (CURL_FAILED(rcCurl))
return VERR_INVALID_PARAMETER;
}
if (pcszProxyUser && pcszProxyPwd)
{
if (CURL_FAILED(rcCurl))
return VERR_INVALID_PARAMETER;
if (CURL_FAILED(rcCurl))
return VERR_INVALID_PARAMETER;
}
return VINF_SUCCESS;
}
{
if (!cHeaders)
{
return VINF_SUCCESS;
}
for (unsigned i = 0; i < cHeaders; i++)
if (CURL_FAILED(rcCurl))
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
}
{
if (CURL_FAILED(rcCurl))
return VERR_INVALID_PARAMETER;
#if 0
if (CURL_FAILED(rcCurl))
return VERR_INVALID_PARAMETER;
#endif
/* XXX */
if (CURL_FAILED(rcCurl))
return VERR_INTERNAL_ERROR;
if (CURL_FAILED(rcCurl))
return VERR_INTERNAL_ERROR;
if (CURL_FAILED(rcCurl))
return VERR_INTERNAL_ERROR;
int rc = VERR_INTERNAL_ERROR;
{
{
case 200:
/* OK, request was fulfilled */
case 204:
/* empty response */
rc = VINF_SUCCESS;
break;
case 400:
/* bad request */
break;
case 403:
/* forbidden, authorization will not help */
break;
case 404:
/* URL not found */
break;
}
}
else
{
switch (rcCurl)
{
case CURLE_URL_MALFORMAT:
break;
default:
break;
}
}
return rc;
}