Repository: xbmc/xbmc
File: xbmc/filesystem/CurlFile.cpp (C++)

Code before:
#include <cassert>
#include <climits>
#include <vector>

#ifdef TARGET_POSIX
#include <errno.h>
#include <inttypes.h>
#include "platform/posix/ConvUtils.h"
#endif

#include "DllLibCurl.h"
#include "ShoutcastFile.h"
#include "utils/CharsetConverter.h"
#include "utils/log.h"
#include "utils/StringUtils.h"

using namespace XFILE;
using namespace XCURL;

using namespace std::chrono_literals;

#define FITS_INT(a) (((a) <= INT_MAX) && ((a) >= INT_MIN))

namespace
{
const auto proxyType2CUrlProxyType{std::unordered_map<XFILE::CCurlFile::ProxyType, int>{
    {CCurlFile::ProxyType::HTTP, CURLPROXY_HTTP},
    {CCurlFile::ProxyType::SOCKS4, CURLPROXY_SOCKS4},
    {CCurlFile::ProxyType::SOCKS4A, CURLPROXY_SOCKS4A},
    {CCurlFile::ProxyType::SOCKS5, CURLPROXY_SOCKS5},
    {CCurlFile::ProxyType::SOCKS5_REMOTE, CURLPROXY_SOCKS5_HOSTNAME},
    {CCurlFile::ProxyType::HTTPS, CURLPROXY_HTTPS},
}};

std::vector<uint8_t> cachedCaCertsBlob; // cached CA certs file

} // unnamed namespace

#define FILLBUFFER_OK         0
#define FILLBUFFER_NO_DATA    1
#define FILLBUFFER_FAIL       2

// curl calls this routine to debug
extern "C" int debug_callback(CURL_HANDLE *handle, curl_infotype info, char *output, size_t size, void *data)
{
  if (info == CURLINFO_DATA_IN || info == CURLINFO_DATA_OUT)
    return 0;

  if (!CServiceBroker::GetLogging().CanLogComponent(LOGCURL))
    return 0;


Review comment (suggestion):
If you feel like it you can also switch this to our own `CMap` and make it `constexpr`:
```cpp
constexpr auto proxyType2CUrlProxyType{make_map<XFILE::CCurlFile::ProxyType, int>({
    {CCurlFile::ProxyType::HTTP, CURLPROXY_HTTP},
    {CCurlFile::ProxyType::SOCKS4, CURLPROXY_SOCKS4},
    {CCurlFile::ProxyType::SOCKS4A, CURLPROXY_SOCKS4A},
    {CCurlFile::ProxyType::SOCKS5, CURLPROXY_SOCKS5},
    {CCurlFile::ProxyType::SOCKS5_REMOTE, CURLPROXY_SOCKS5_HOSTNAME},
    {CCurlFile::ProxyType::HTTPS, CURLPROXY_HTTPS},
})};
```

Code after:
#include <algorithm>
#include <cassert>
#include <climits>
#include <vector>

#ifdef TARGET_POSIX
#include <errno.h>
#include <inttypes.h>
#include "platform/posix/ConvUtils.h"
#endif

#include "DllLibCurl.h"
#include "ShoutcastFile.h"
#include "utils/CharsetConverter.h"
#include "utils/log.h"
#include "utils/StringUtils.h"

using namespace XFILE;
using namespace XCURL;

using namespace std::chrono_literals;

#define FITS_INT(a) (((a) <= INT_MAX) && ((a) >= INT_MIN))

namespace
{
constexpr auto proxyType2CUrlProxyType{make_map<XFILE::CCurlFile::ProxyType, int>({
    {CCurlFile::ProxyType::HTTP, CURLPROXY_HTTP},
    {CCurlFile::ProxyType::SOCKS4, CURLPROXY_SOCKS4},
    {CCurlFile::ProxyType::SOCKS4A, CURLPROXY_SOCKS4A},
    {CCurlFile::ProxyType::SOCKS5, CURLPROXY_SOCKS5},
    {CCurlFile::ProxyType::SOCKS5_REMOTE, CURLPROXY_SOCKS5_HOSTNAME},
    {CCurlFile::ProxyType::HTTPS, CURLPROXY_HTTPS},
})};

std::vector<uint8_t> cachedCaCertsBlob; // cached CA certs file

} // unnamed namespace

#define FILLBUFFER_OK         0
#define FILLBUFFER_NO_DATA    1
#define FILLBUFFER_FAIL       2

// curl calls this routine to debug
extern "C" int debug_callback(CURL_HANDLE *handle, curl_infotype info, char *output, size_t size, void *data)
{
  if (info == CURLINFO_DATA_IN || info == CURLINFO_DATA_OUT)
    return 0;

  if (!CServiceBroker::GetLogging().CanLogComponent(LOGCURL))
    return 0;