Remove useless includes and more fixes to avoid including curl.h in files, when not mandatory.
This commit is contained in:
parent
6ea6c7219a
commit
8c70681b31
|
@ -27,13 +27,8 @@
|
|||
// conflicts for some defines, at least on Windows
|
||||
#include <kicad_curl/kicad_curl.h>
|
||||
|
||||
#include <wx/log.h>
|
||||
#include <wx/dynlib.h>
|
||||
|
||||
#include <macros.h>
|
||||
#include <fctsys.h>
|
||||
#include <ki_mutex.h> // MUTEX and MUTLOCK
|
||||
#include <richio.h>
|
||||
#include <ki_exception.h> // THROW_IO_ERROR
|
||||
|
||||
|
||||
|
||||
|
@ -58,8 +53,6 @@ static void lock_callback( int mode, int type, const char* file, int line )
|
|||
|
||||
wxASSERT( s_crypto_locks && unsigned( type ) < unsigned( CRYPTO_num_locks() ) );
|
||||
|
||||
//DBG( printf( "%s: mode=0x%x type=%d file=%s line=%d\n", __func__, mode, type, file, line );)
|
||||
|
||||
if( mode & CRYPTO_LOCK )
|
||||
{
|
||||
s_crypto_locks[ type ].lock();
|
||||
|
@ -150,7 +143,7 @@ void KICAD_CURL::Init()
|
|||
|
||||
init_locks();
|
||||
|
||||
wxLogDebug( "Using %s", GetVersion() );
|
||||
//wxLogDebug( "Using %s", GetVersion() );
|
||||
|
||||
s_initialized = true;
|
||||
}
|
||||
|
|
|
@ -22,13 +22,14 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <kicad_curl/kicad_curl.h>
|
||||
#include <kicad_curl/kicad_curl_easy.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <exception>
|
||||
#include <stdarg.h>
|
||||
#include <sstream>
|
||||
#include <richio.h>
|
||||
#include <ki_exception.h> // THROW_IO_ERROR
|
||||
|
||||
|
||||
static size_t write_callback( void* contents, size_t size, size_t nmemb, void* userp )
|
||||
|
@ -87,8 +88,57 @@ void KICAD_CURL_EASY::Perform()
|
|||
|
||||
if( res != CURLE_OK )
|
||||
{
|
||||
std::string msg = StrPrintf( "curl_easy_perform()=%d: %s",
|
||||
res, GetErrorText( res ).c_str() );
|
||||
std::string msg = "curl_easy_perform()=";
|
||||
msg += (int)res; msg += " "; msg += GetErrorText( res ).c_str();
|
||||
THROW_IO_ERROR( msg );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KICAD_CURL_EASY::SetHeader( const std::string& aName, const std::string& aValue )
|
||||
{
|
||||
std::string header = aName + ':' + aValue;
|
||||
m_headers = curl_slist_append( m_headers, header.c_str() );
|
||||
}
|
||||
|
||||
|
||||
template <typename T> int KICAD_CURL_EASY::setOption( int aOption, T aArg )
|
||||
{
|
||||
return curl_easy_setopt( m_CURL, (CURLoption)aOption, aArg );
|
||||
}
|
||||
|
||||
|
||||
const std::string KICAD_CURL_EASY::GetErrorText( int aCode )
|
||||
{
|
||||
return curl_easy_strerror( (CURLcode)aCode );
|
||||
}
|
||||
|
||||
|
||||
bool KICAD_CURL_EASY::SetUserAgent( const std::string& aAgent )
|
||||
{
|
||||
if( setOption<const char*>( CURLOPT_USERAGENT, aAgent.c_str() ) == CURLE_OK )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool KICAD_CURL_EASY::SetURL( const std::string& aURL )
|
||||
{
|
||||
if( setOption<const char *>( CURLOPT_URL, aURL.c_str() ) == CURLE_OK )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool KICAD_CURL_EASY::SetFollowRedirects( bool aFollow )
|
||||
{
|
||||
if( setOption<long>( CURLOPT_FOLLOWLOCATION , (aFollow ? 1 : 0) ) == CURLE_OK )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -26,13 +26,16 @@
|
|||
|
||||
/*
|
||||
* KICAD_CURL_EASY.h must included before wxWidgets because on Windows,
|
||||
* because kicad_curl.h includes curl.h, wxWidgets ends up including windows.h
|
||||
* before winsocks2.h inside curl and this causes build warnings
|
||||
* kicad_curl.h does not include curl.h, because wxWidgets ends up including windows.h
|
||||
* before winsocks2.h inside curl and curl.h causes build warnings if included before and wxxxx.h
|
||||
*
|
||||
* so including kicad_curl.h could be needed in a few sources
|
||||
*/
|
||||
|
||||
#include <kicad_curl/kicad_curl.h>
|
||||
#include <string>
|
||||
|
||||
typedef void CURL;
|
||||
struct curl_slist;
|
||||
|
||||
/**
|
||||
* Class KICAD_CURL_EASY
|
||||
|
@ -51,6 +54,8 @@
|
|||
* curl.Perform();
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
|
||||
class KICAD_CURL_EASY
|
||||
{
|
||||
public:
|
||||
|
@ -73,11 +78,7 @@ public:
|
|||
* @param aName is the left hand side of the header, i.e. Accept without the colon
|
||||
* @param aValue is the right hand side of the header, i.e. application/json
|
||||
*/
|
||||
void SetHeader( const std::string& aName, const std::string& aValue )
|
||||
{
|
||||
std::string header = aName + ':' + aValue;
|
||||
m_headers = curl_slist_append( m_headers, header.c_str() );
|
||||
}
|
||||
void SetHeader( const std::string& aName, const std::string& aValue );
|
||||
|
||||
/**
|
||||
* Function SetUserAgent
|
||||
|
@ -86,14 +87,7 @@ public:
|
|||
* @param aAgent is the string to set for the user agent
|
||||
* @return bool - True if successful, false if not
|
||||
*/
|
||||
bool SetUserAgent( const std::string& aAgent )
|
||||
{
|
||||
if( SetOption<const char*>( CURLOPT_USERAGENT, aAgent.c_str() ) == CURLE_OK )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool SetUserAgent( const std::string& aAgent );
|
||||
|
||||
/**
|
||||
* Function SetURL
|
||||
|
@ -102,14 +96,7 @@ public:
|
|||
* @param aURL is the URL
|
||||
* @return bool - True if successful, false if not
|
||||
*/
|
||||
bool SetURL( const std::string& aURL )
|
||||
{
|
||||
if( SetOption<const char *>( CURLOPT_URL, aURL.c_str() ) == CURLE_OK )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool SetURL( const std::string& aURL );
|
||||
|
||||
/**
|
||||
* Function SetFollowRedirects
|
||||
|
@ -119,14 +106,7 @@ public:
|
|||
* @param aFollow is a boolean where true will enable following redirects
|
||||
* @return bool - True if successful, false if not
|
||||
*/
|
||||
bool SetFollowRedirects( bool aFollow )
|
||||
{
|
||||
if( SetOption<long>( CURLOPT_FOLLOWLOCATION , (aFollow ? 1 : 0) ) == CURLE_OK )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool SetFollowRedirects( bool aFollow );
|
||||
|
||||
/**
|
||||
* Function GetErrorText
|
||||
|
@ -135,23 +115,7 @@ public:
|
|||
* @param aCode is CURL error code
|
||||
* @return const std::string - the corresponding error string for the given code
|
||||
*/
|
||||
const std::string GetErrorText( CURLcode aCode )
|
||||
{
|
||||
return curl_easy_strerror( aCode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Function SetOption
|
||||
* sets a curl option, only supports single parameter curl options
|
||||
*
|
||||
* @param aOption is CURL option, see CURL manual for options
|
||||
* @param aArg is the argument being passed to CURL, ensure it is the right type per manual
|
||||
* @return CURLcode - CURL error code, will return CURLE_OK unless a problem was encountered
|
||||
*/
|
||||
template <typename T> CURLcode SetOption( CURLoption aOption, T aArg )
|
||||
{
|
||||
return curl_easy_setopt( m_CURL, aOption, aArg );
|
||||
}
|
||||
const std::string GetErrorText( int aCode );
|
||||
|
||||
/**
|
||||
* Function GetBuffer
|
||||
|
@ -163,6 +127,17 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Function setOption
|
||||
* sets a curl option, only supports single parameter curl options
|
||||
*
|
||||
* @param aOption is CURL option, see CURL manual for options
|
||||
* @param aArg is the argument being passed to CURL, ensure it is the right type per manual
|
||||
* @return int - a CURL error code, will return CURLE_OK unless a problem was encountered
|
||||
*/
|
||||
template <typename T> int setOption( int aOption, T aArg );
|
||||
|
||||
|
||||
CURL* m_CURL;
|
||||
curl_slist* m_headers;
|
||||
std::string m_buffer;
|
||||
|
|
Loading…
Reference in New Issue