<commit_before>/* --------------------------------------------------------------------------

   libmusicbrainz4 - Client library to access MusicBrainz

   Copyright (C) 2011 <NAME>

   This file is part of libmusicbrainz4.

   This library is free software; you can redistribute it and/or
   modify it under the terms of v2 of the GNU Lesser General Public
   License as published by the Free Software Foundation.

   libmusicbrainz4 is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this library.  If not, see <http://www.gnu.org/licenses/>.

     $Id$

----------------------------------------------------------------------------*/

#include "config.h"
#include "coverart/defines.h"

#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <sstream>

#include <ne_uri.h>

#include "coverart/CoverArt.h"
#include "coverart/HTTPFetch.h"

class CoverArtArchive::CCoverArtPrivate
{
	public:
		CCoverArtPrivate()
		:	m_ProxyPort(0)
		{
		}

		std::string m_UserAgent;
		std::string m_ProxyHost;
		int m_ProxyPort;
		std::string m_ProxyUserName;
		std::string m_ProxyPassword;
};

CoverArtArchive::CCoverArt::CCoverArt(const std::string& UserAgent)
:	m_d(new CCoverArtPrivate)
{
	m_d->m_UserAgent=UserAgent;

	for (std::string::size_type Pos=0;Pos<m_d->m_UserAgent.length();Pos++)
		if (m_d->m_UserAgent[Pos]=='-')
			m_d->m_UserAgent[Pos]='/';

	// Parse http_proxy environmnent variable
	const char *http_proxy = getenv("http_proxy");
	if (http_proxy)
	{
		ne_uri uri;
		if (!ne_uri_parse(http_proxy, &uri))
		{
			if (uri.host)
				m_d->m_ProxyHost = uri.host;
			if (uri.port)
				m_d->m_ProxyPort = uri.port;

			if (uri.userinfo)
			{
				char *pos = strchr(uri.userinfo, ':');
				if (pos)
				{
					*pos = '\0';
					m_d->m_ProxyUserName = uri.userinfo;
					m_d->m_ProxyPassword = pos + 1;
				}
				else
				{
					m_d->m_ProxyUserName = uri.userinfo;
				}
			}
		}

		ne_uri_free(&uri);
	}
}

CoverArtArchive::CCoverArt::~CCoverArt()
{
	delete m_d;<commit_msg>Don't parse proxy environment variable, HTTPFetch will do that<commit_after>/* --------------------------------------------------------------------------

   libmusicbrainz4 - Client library to access MusicBrainz

   Copyright (C) 2011 <NAME>

   This file is part of libmusicbrainz4.

   This library is free software; you can redistribute it and/or
   modify it under the terms of v2 of the GNU Lesser General Public
   License as published by the Free Software Foundation.

   libmusicbrainz4 is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this library.  If not, see <http://www.gnu.org/licenses/>.

     $Id$

----------------------------------------------------------------------------*/

#include "config.h"
#include "coverart/defines.h"

#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <sstream>

#include "coverart/CoverArt.h"
#include "coverart/HTTPFetch.h"

class CoverArtArchive::CCoverArtPrivate
{
	public:
		CCoverArtPrivate()
		:	m_ProxyPort(0)
		{
		}

		std::string m_UserAgent;
		std::string m_ProxyHost;
		int m_ProxyPort;
		std::string m_ProxyUserName;
		std::string m_ProxyPassword;
};

CoverArtArchive::CCoverArt::CCoverArt(const std::string& UserAgent)
:	m_d(new CCoverArtPrivate)
{
	m_d->m_UserAgent=UserAgent;

	for (std::string::size_type Pos=0;Pos<m_d->m_UserAgent.length();Pos++)
		if (m_d->m_UserAgent[Pos]=='-')
			m_d->m_UserAgent[Pos]='/';
}

CoverArtArchive::CCoverArt::~CCoverArt()
{
	delete m_d;
{'fraction_non_alphanumeric': 0.1771356783919598, 'fraction_numerical': 0.005527638190954774, 'mean_word_length': 2.805927342256214, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1597178', 'n_tokens_mistral': 1407, 'n_tokens_neox': 1270, 'n_words': 356}