Index: /trunk/include/iprt/err.h
===================================================================
--- /trunk/include/iprt/err.h	(revision 43644)
+++ /trunk/include/iprt/err.h	(revision 43645)
@@ -1564,4 +1564,14 @@
 /** @} */
 
+/** @name HTTP status codes
+ * @{ */
+/** The server has not found anything matching the URI given. */
+#define VERR_HTTP_NOT_FOUND                     (-885)
+/** The request is for something forbidden. Authorization will not help. */
+#define VERR_HTTP_ACCESS_DENIED                 (-886)
+/** The server did not understand the request due to bad syntax. */
+#define VERR_HTTP_BAD_REQUEST                   (-887)
+
+
 /** @name RTManifest status codes
  * @{ */
Index: /trunk/include/iprt/http.h
===================================================================
--- /trunk/include/iprt/http.h	(revision 43645)
+++ /trunk/include/iprt/http.h	(revision 43645)
@@ -0,0 +1,80 @@
+/* $Id$ */
+/** @file
+ * IPRT - Simple 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;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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.
+ */
+
+#ifndef ___iprt_http_h
+#define ___iprt_http_h
+
+#include <iprt/types.h>
+
+RT_C_DECLS_BEGIN
+
+/** @defgroup grp_rt_http   RTHttp - Simple HTTP API
+ * @ingroup grp_rt
+ * @{
+ */
+
+/** @todo the following three definitions may move the iprt/types.h later. */
+/** RTHTTP interface handle. */
+typedef R3PTRTYPE(struct RTHTTPINTERNAL *)      RTHTTP;
+/** Pointer to a RTHTTP interface handle. */
+typedef RTHTTP                                  *PRTHTTP;
+/** Nil RTHTTP interface handle. */
+#define NIL_RTHTTP                              ((RTHTTP)0)
+
+
+/**
+ * Creates a HTTP interface handle.
+ *
+ * @returns iprt status code.
+ *
+ * @param   phHttp      Where to store the HTTP handle.
+ */
+RTR3DECL(int) RTHttpCreate(PRTHTTP phHttp);
+
+/**
+ * Destroys a HTTP interface handle.
+ *
+ * @param   hHttp       Handle to the HTTP interface.
+ */
+RTR3DECL(void) RTHttpDestroy(RTHTTP hHttp);
+
+/**
+ * Perform a simple blocking HTTP request.
+ *
+ * @returns iprt status code.
+ *
+ * @param    hHttp         HTTP interface handle.
+ * @param    pcszUrl       URL.
+ * @param    ppszResponse  HTTP response.
+ */
+RTR3DECL(int) RTHttpGet(RTHTTP hHttp, const char *pcszUrl, char **ppszResponse);
+
+/** @} */
+
+RT_C_DECLS_END
+
+#endif
+
Index: /trunk/src/VBox/Runtime/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/Makefile.kmk	(revision 43644)
+++ /trunk/src/VBox/Runtime/Makefile.kmk	(revision 43645)
@@ -1327,4 +1327,5 @@
 ifdef VBOX_WITH_LIBCURL
  VBoxRT_SOURCES               += common/misc/s3.cpp
+ VBoxRT_SOURCES               += common/misc/http.cpp
 endif
 VBoxRT_SOURCES.$(KBUILD_TARGET) = $(RuntimeR3_SOURCES.$(KBUILD_TARGET))
Index: /trunk/src/VBox/Runtime/common/misc/http.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/misc/http.cpp	(revision 43645)
+++ /trunk/src/VBox/Runtime/common/misc/http.cpp	(revision 43645)
@@ -0,0 +1,204 @@
+
+/* $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;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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                                                               *
+*******************************************************************************/
+#include <iprt/http.h>
+#include <iprt/assert.h>
+#include <iprt/err.h>
+#include <iprt/mem.h>
+#include <iprt/string.h>
+
+#include <curl/curl.h>
+#include "internal/magics.h"
+
+
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
+typedef struct RTHTTPINTERNAL
+{
+    uint32_t u32Magic;
+    CURL *pCurl;
+    long lLastResp;
+} RTHTTPINTERNAL;
+typedef RTHTTPINTERNAL *PRTHTTPINTERNAL;
+
+typedef struct RTHTTPMEMCHUNK
+{
+    char *pszMem;
+    size_t cb;
+} RTHTTPMEMCHUNK;
+typedef RTHTTPMEMCHUNK *PRTHTTPMEMCHUNK;
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+#define CURL_FAILED(rcCurl) (RT_UNLIKELY(rcCurl != CURLE_OK))
+
+/** Validates a handle and returns VERR_INVALID_HANDLE if not valid. */
+#define RTHTTP_VALID_RETURN_RC(hHttp, rcCurl) \
+    do { \
+        AssertPtrReturn((hHttp), (rcCurl)); \
+        AssertReturn((hHttp)->u32Magic == RTHTTP_MAGIC, (rcCurl)); \
+    } while (0)
+
+/** Validates a handle and returns VERR_INVALID_HANDLE if not valid. */
+#define RTHTTP_VALID_RETURN(hHTTP) RTHTTP_VALID_RETURN_RC((hHttp), VERR_INVALID_HANDLE)
+
+/** Validates a handle and returns (void) if not valid. */
+#define RTHTTP_VALID_RETURN_VOID(hHttp) \
+    do { \
+        AssertPtrReturnVoid(hHttp); \
+        AssertReturnVoid((hHttp)->u32Magic == RTHTTP_MAGIC); \
+    } while (0)
+
+
+RTR3DECL(int) RTHttpCreate(PRTHTTP phHttp)
+{
+    AssertPtrReturn(phHttp, VERR_INVALID_PARAMETER);
+
+    CURLcode rcCurl = curl_global_init(CURL_GLOBAL_ALL);
+    if (CURL_FAILED(rcCurl))
+        return VERR_INTERNAL_ERROR;
+
+    CURL* pCurl = curl_easy_init();
+    if (!pCurl)
+        return VERR_INTERNAL_ERROR;
+
+    PRTHTTPINTERNAL pHttpInt = (PRTHTTPINTERNAL)RTMemAllocZ(sizeof(PRTHTTPINTERNAL));
+    if (!pHttpInt)
+        return VERR_NO_MEMORY;
+
+    pHttpInt->u32Magic = RTHTTP_MAGIC;
+    pHttpInt->pCurl = pCurl;
+
+    *phHttp = (RTHTTP)pHttpInt;
+
+    return VINF_SUCCESS;
+}
+
+RTR3DECL(void) RTHttpDestroy(RTHTTP hHttp)
+{
+    if (!hHttp)
+        return;
+
+    PRTHTTPINTERNAL pHttpInt = hHttp;
+    RTHTTP_VALID_RETURN_VOID(pHttpInt);
+
+    pHttpInt->u32Magic = RTHTTP_MAGIC_DEAD;
+
+    curl_easy_cleanup(pHttpInt->pCurl);
+
+    RTMemFree(pHttpInt);
+
+    curl_global_cleanup();
+}
+
+static size_t rtHttpWriteData(void *pvBuf, size_t cb, size_t n, void *pvUser)
+{
+    PRTHTTPMEMCHUNK pMem = (PRTHTTPMEMCHUNK)pvUser;
+    size_t cbAll = cb * n;
+
+    pMem->pszMem = (char*)RTMemRealloc(pMem->pszMem, pMem->cb + cbAll + 1);
+    if (pMem->pszMem)
+    {
+        memcpy(&pMem->pszMem[pMem->cb], pvBuf, cbAll);
+        pMem->cb += cbAll;
+        pMem->pszMem[pMem->cb] = '\0';
+    }
+    return cbAll;
+}
+
+RTR3DECL(int) RTHttpGet(RTHTTP hHttp, const char *pcszUrl, char **ppszResponse)
+{
+    PRTHTTPINTERNAL pHttpInt = hHttp;
+    RTHTTP_VALID_RETURN(pHttpInt);
+
+    int rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_URL, pcszUrl);
+    if (CURL_FAILED(rcCurl))
+        return VERR_INVALID_PARAMETER;
+
+    /* XXX */
+    rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_CAINFO, "/etc/ssl/certs/ca-certificates.crt");
+    if (CURL_FAILED(rcCurl))
+        return VERR_INTERNAL_ERROR;
+
+    RTHTTPMEMCHUNK chunk = { NULL, 0 };
+    rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEFUNCTION, &rtHttpWriteData);
+    if (CURL_FAILED(rcCurl))
+        return VERR_INTERNAL_ERROR;
+    rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEDATA, (void*)&chunk);
+    if (CURL_FAILED(rcCurl))
+        return VERR_INTERNAL_ERROR;
+
+    rcCurl = curl_easy_perform(pHttpInt->pCurl);
+    int rc = VERR_INTERNAL_ERROR;
+    if (rcCurl == CURLE_OK)
+    {
+        curl_easy_getinfo(pHttpInt->pCurl, CURLINFO_RESPONSE_CODE, &pHttpInt->lLastResp);
+        switch (pHttpInt->lLastResp)
+        {
+            case 200:
+                /* OK, request was fulfilled */
+            case 204:
+                /* empty response */
+                rc = VINF_SUCCESS;
+                break;
+            case 400:
+                /* bad request */
+                rc = VERR_HTTP_BAD_REQUEST;
+                break;
+            case 403:
+                /* forbidden, authorization will not help */
+                rc = VERR_HTTP_ACCESS_DENIED;
+                break;
+            case 404:
+                /* URL not found */
+                rc = VERR_HTTP_NOT_FOUND;
+                break;
+        }
+    }
+    else
+    {
+        switch (rcCurl)
+        {
+            case CURLE_URL_MALFORMAT:
+            case CURLE_COULDNT_RESOLVE_HOST:
+                rc = VERR_HTTP_NOT_FOUND; 
+                break;
+            default:
+                break;
+        }
+    }
+
+    *ppszResponse = chunk.pszMem;
+
+    return rc;
+}
Index: /trunk/src/VBox/Runtime/include/internal/magics.h
===================================================================
--- /trunk/src/VBox/Runtime/include/internal/magics.h	(revision 43644)
+++ /trunk/src/VBox/Runtime/include/internal/magics.h	(revision 43645)
@@ -69,4 +69,8 @@
 /** Magic number for RTHEAPSIMPLEINTERNAL::uMagic. (Kyoichi Katayama) */
 #define RTHEAPSIMPLE_MAGIC              UINT32_C(0x19590105)
+/** The magic value for RTHTTPINTERNAL::u32Magic. (Karl May) */
+#define RTHTTP_MAGIC                    UINT32_C(0x18420225)
+/** The value of RTHTTPINTERNAL::u32Magic after close. */
+#define RTHTTP_MAGIC_DEAD               UINT32_C(0x19120330)
 /** The magic value for RTLDRMODINTERNAL::u32Magic. (Alan Moore) */
 #define RTLDRMOD_MAGIC                  UINT32_C(0x19531118)
Index: /trunk/src/VBox/Runtime/testcase/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/testcase/Makefile.kmk	(revision 43644)
+++ /trunk/src/VBox/Runtime/testcase/Makefile.kmk	(revision 43645)
@@ -65,4 +65,5 @@
 	tstFileLock \
 	tstFork \
+	tstHttp \
 	tstRTFsQueries \
 	tstRTFilesystem \
@@ -225,4 +226,8 @@
 tstRTDigest_SOURCES = tstRTDigest.cpp
 
+tstHttp_TEMPLATE = VBOXR3TSTEXE
+tstHttp_SOURCES = tstHttp.cpp
+tstHttp_SDKS = VBOX_LIBCURL
+
 tstDir_TEMPLATE = VBOXR3TSTEXE
 tstDir_SOURCES = tstDir.cpp
Index: /trunk/src/VBox/Runtime/testcase/tstHttp.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstHttp.cpp	(revision 43645)
+++ /trunk/src/VBox/Runtime/testcase/tstHttp.cpp	(revision 43645)
@@ -0,0 +1,56 @@
+/* $Id$ */
+/** @file
+ * IPRT Testcase - Simple cURL testcase.
+ */
+
+/*
+ * 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;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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                                                               *
+*******************************************************************************/
+#include <iprt/err.h>
+#include <iprt/http.h>
+#include <iprt/mem.h>
+#include <iprt/stream.h>
+#include <iprt/initterm.h>
+#include <iprt/thread.h>
+
+int main()
+{
+    unsigned cErrors = 0;
+
+    RTR3InitExeNoArguments(RTR3INIT_FLAGS_SUPLIB);
+
+    RTHTTP hHttp;
+    int rc = RTHttpCreate(&hHttp);
+    char *pszBuf = NULL;
+    if (RT_SUCCESS(rc))
+        rc = RTHttpGet(hHttp,
+                       "https://update.virtualbox.org/query.php?platform=LINUX_32BITS_UBUNTU_12_04&version=4.1.18",
+                       &pszBuf);
+    RTHttpDestroy(hHttp);
+
+    RTPrintf("Error code: %Rrc\nGot: %s\n", rc, pszBuf);
+    RTMemFree(pszBuf);
+
+    return !!cErrors;
+}
