Code cleaning.
This commit is contained in:
parent
58dceb143f
commit
ad1ee958b0
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Mark Roszko <mark.roszko@gmail.com>
|
* Copyright (C) 2015 Mark Roszko <mark.roszko@gmail.com>
|
||||||
* Copyright (C) 2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
* Copyright (C) 2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
||||||
* Copyright (C) 2015-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
|
* Copyright (C) 2015-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -132,11 +132,13 @@ std::string KICAD_CURL::GetSimpleVersion()
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string GetKicadCurlVersion()
|
std::string GetKicadCurlVersion()
|
||||||
{
|
{
|
||||||
return KICAD_CURL::GetVersion();
|
return KICAD_CURL::GetVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string GetCurlLibVersion()
|
std::string GetCurlLibVersion()
|
||||||
{
|
{
|
||||||
return LIBCURL_VERSION;
|
return LIBCURL_VERSION;
|
||||||
|
|
|
@ -63,6 +63,7 @@ static size_t write_callback( void* contents, size_t size, size_t nmemb, void* u
|
||||||
return realsize;
|
return realsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static size_t stream_write_callback( void* contents, size_t size, size_t nmemb, void* userp )
|
static size_t stream_write_callback( void* contents, size_t size, size_t nmemb, void* userp )
|
||||||
{
|
{
|
||||||
size_t realsize = size * nmemb;
|
size_t realsize = size * nmemb;
|
||||||
|
@ -92,6 +93,7 @@ static int xferinfo( void* p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t u
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KICAD_CURL_EASY::KICAD_CURL_EASY() : m_headers( nullptr )
|
KICAD_CURL_EASY::KICAD_CURL_EASY() : m_headers( nullptr )
|
||||||
{
|
{
|
||||||
// Call KICAD_CURL::Init() from in here every time, but only the first time
|
// Call KICAD_CURL::Init() from in here every time, but only the first time
|
||||||
|
@ -224,7 +226,6 @@ std::string KICAD_CURL_EASY::Escape( const std::string& aUrl )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool KICAD_CURL_EASY::SetTransferCallback( const TRANSFER_CALLBACK& aCallback, size_t aInterval )
|
bool KICAD_CURL_EASY::SetTransferCallback( const TRANSFER_CALLBACK& aCallback, size_t aInterval )
|
||||||
{
|
{
|
||||||
progress = std::make_unique<CURL_PROGRESS>( this, aCallback, (curl_off_t) aInterval );
|
progress = std::make_unique<CURL_PROGRESS>( this, aCallback, (curl_off_t) aInterval );
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Mark Roszko <mark.roszko@gmail.com>
|
* Copyright (C) 2015 Mark Roszko <mark.roszko@gmail.com>
|
||||||
* Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors.
|
* Copyright (C) 2015, 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -58,36 +58,30 @@ struct DYN_LOOKUP;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* KICAD_CURL
|
* Simple wrapper class to call curl_global_init and curl_global_cleanup for KiCad.
|
||||||
* simple wrapper class to call curl_global_init and curl_global_cleanup for KiCad.
|
|
||||||
*/
|
*/
|
||||||
class KICAD_CURL
|
class KICAD_CURL
|
||||||
{
|
{
|
||||||
friend class KICAD_CURL_EASY;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Function Init
|
* Call curl_global_init for the application. It must be used only once
|
||||||
* calls curl_global_init for the application. It must be used only once
|
|
||||||
* and before any curl functions that perform requests.
|
* and before any curl functions that perform requests.
|
||||||
*
|
*
|
||||||
* @return bool - True if successful, false if CURL returned an error
|
* @return True if successful, false if CURL returned an error.
|
||||||
* @throw IO_ERROR on failure, hopefully with helpful text in it.
|
* @throw IO_ERROR on failure, hopefully with helpful text in it.
|
||||||
*/
|
*/
|
||||||
static void Init();
|
static void Init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function Cleanup
|
* Call curl_global_cleanup for the application. It must be used only after
|
||||||
* calls curl_global_cleanup for the application. It must be used only after
|
|
||||||
* curl_global_init was called.
|
* curl_global_init was called.
|
||||||
*/
|
*/
|
||||||
static void Cleanup();
|
static void Cleanup();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetVersion
|
* Wrapper for curl_version(). Reports back a short string of loaded libraries.
|
||||||
* wrapper for curl_version(). Reports back a short string of loaded libraries.
|
|
||||||
*
|
*
|
||||||
* @return const char* - String reported by libcurl and owned by it.
|
* @return String reported by libcurl and owned by it.
|
||||||
* @throw IO_ERROR on failure, hopefully with helpful text in it.
|
* @throw IO_ERROR on failure, hopefully with helpful text in it.
|
||||||
*/
|
*/
|
||||||
static const char* GetVersion()
|
static const char* GetVersion()
|
||||||
|
@ -97,12 +91,14 @@ public:
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetSimpleVersion
|
* Report back curl version only and SSL library support.
|
||||||
* Reports back curl version only and SSL library support
|
|
||||||
*
|
*
|
||||||
* @return std::string - Generated version string
|
* @return Generated version string.
|
||||||
*/
|
*/
|
||||||
static std::string GetSimpleVersion();
|
static std::string GetSimpleVersion();
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class KICAD_CURL_EASY;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KICAD_CURL_H_
|
#endif // KICAD_CURL_H_
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Mark Roszko <mark.roszko@gmail.com>
|
* Copyright (C) 2015 Mark Roszko <mark.roszko@gmail.com>
|
||||||
* Copyright (C) 2015 KiCad Developers, see CHANGELOG.TXT for contributors.
|
* Copyright (C) 2015, 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
|
@ -42,8 +42,7 @@ typedef void CURL;
|
||||||
struct curl_slist;
|
struct curl_slist;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* KICAD_CURL_EASY
|
* Wrapper interface around the curl_easy API/
|
||||||
* wrapper interface around the curl_easy API
|
|
||||||
*
|
*
|
||||||
* Handling of using the curl_easy API to make a request and save the response to
|
* Handling of using the curl_easy API to make a request and save the response to
|
||||||
* a memory buffer
|
* a memory buffer
|
||||||
|
@ -71,63 +70,55 @@ public:
|
||||||
~KICAD_CURL_EASY();
|
~KICAD_CURL_EASY();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function perform
|
* Equivalent to curl_easy_perform. Executes the request that was previously setup.
|
||||||
* equivalent to curl_easy_perform. Executes the request
|
|
||||||
* that was previously setup.
|
|
||||||
*/
|
*/
|
||||||
int Perform();
|
int Perform();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetHeader
|
* Set an arbitrary header for the HTTP(s) request.
|
||||||
* sets an arbitrary header for the HTTP(s) request.
|
|
||||||
*
|
*
|
||||||
* @param aName is the left hand side of the header, i.e. Accept without the colon
|
* @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
|
* @param aValue is the right hand side of the header, i.e. application/json.
|
||||||
*/
|
*/
|
||||||
void SetHeader( const std::string& aName, const std::string& aValue );
|
void SetHeader( const std::string& aName, const std::string& aValue );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetUserAgent
|
* Set the request user agent.
|
||||||
* sets the request user agent
|
|
||||||
*
|
*
|
||||||
* @param aAgent is the string to set for the user agent
|
* @param aAgent is the string to set for the user agent.
|
||||||
* @return bool - True if successful, false if not
|
* @return True if successful, false if not.
|
||||||
*/
|
*/
|
||||||
bool SetUserAgent( const std::string& aAgent );
|
bool SetUserAgent( const std::string& aAgent );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetURL
|
* Set the request URL.
|
||||||
* sets the request URL
|
|
||||||
*
|
*
|
||||||
* @param aURL is the URL
|
* @param aURL is the URL.
|
||||||
* @return bool - True if successful, false if not
|
* @return True if successful, false if not.
|
||||||
*/
|
*/
|
||||||
bool SetURL( const std::string& aURL );
|
bool SetURL( const std::string& aURL );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function SetFollowRedirects
|
* Enable the following of HTTP(s) and other redirects, by default curl
|
||||||
* enables the following of HTTP(s) and other redirects, by default curl
|
|
||||||
* does not follow redirects.
|
* does not follow redirects.
|
||||||
*
|
*
|
||||||
* @param aFollow is a boolean where true will enable following redirects
|
* @param aFollow is a boolean where true will enable following redirects.
|
||||||
* @return bool - True if successful, false if not
|
* @return True if successful, false if not.
|
||||||
*/
|
*/
|
||||||
bool SetFollowRedirects( bool aFollow );
|
bool SetFollowRedirects( bool aFollow );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetErrorText
|
* Fetch CURL's "friendly" error string for a given error code.
|
||||||
* fetches CURL's "friendly" error string for a given error code
|
|
||||||
*
|
*
|
||||||
* @param aCode is CURL error code
|
* @param aCode is CURL error code.
|
||||||
* @return const std::string - the corresponding error string for the given code
|
* @return The corresponding error string for the given code.
|
||||||
*/
|
*/
|
||||||
const std::string GetErrorText( int aCode );
|
const std::string GetErrorText( int aCode );
|
||||||
|
|
||||||
int GetTransferTotal( uint64_t& aDownloadedBytes ) const;
|
int GetTransferTotal( uint64_t& aDownloadedBytes ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function GetBuffer
|
* Return a reference to the received data buffer.
|
||||||
* returns a const reference to the received data buffer
|
|
||||||
*/
|
*/
|
||||||
const std::string& GetBuffer() { return m_buffer; }
|
const std::string& GetBuffer() { return m_buffer; }
|
||||||
|
|
||||||
|
@ -143,18 +134,15 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Function setOption
|
* Set a curl option, only supports single parameter curl options.
|
||||||
* sets a curl option, only supports single parameter curl options
|
|
||||||
*
|
*
|
||||||
* @param aOption is CURL option, see CURL manual for 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
|
* @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
|
* @return A CURL error code, will return CURLE_OK unless a problem was encountered.
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
int setOption( int aOption, T aArg );
|
int setOption( int aOption, T aArg );
|
||||||
|
|
||||||
//static int xferinfo( void*, curl_off_t, curl_off_t, curl_off_t, curl_off_t );
|
|
||||||
|
|
||||||
CURL* m_CURL;
|
CURL* m_CURL;
|
||||||
curl_slist* m_headers;
|
curl_slist* m_headers;
|
||||||
std::string m_buffer;
|
std::string m_buffer;
|
||||||
|
|
|
@ -76,7 +76,8 @@ PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER( wxWindow* aParent ) : m_dialog(
|
||||||
catch( std::exception& e )
|
catch( std::exception& e )
|
||||||
{
|
{
|
||||||
if( !schema_file.FileExists() )
|
if( !schema_file.FileExists() )
|
||||||
wxLogError( wxString::Format( _( "schema file '%s' not found" ), schema_file.GetFullPath() ) );
|
wxLogError( wxString::Format( _( "schema file '%s' not found" ),
|
||||||
|
schema_file.GetFullPath() ) );
|
||||||
else
|
else
|
||||||
wxLogError( wxString::Format( _( "Error loading schema: %s" ), e.what() ) );
|
wxLogError( wxString::Format( _( "Error loading schema: %s" ), e.what() ) );
|
||||||
}
|
}
|
||||||
|
@ -174,6 +175,7 @@ bool PLUGIN_CONTENT_MANAGER::DownloadToStream( const wxString& aUrl, std::ostrea
|
||||||
if( aSizeLimit > 0 && ( dltotal > aSizeLimit || dlnow > aSizeLimit ) )
|
if( aSizeLimit > 0 && ( dltotal > aSizeLimit || dlnow > aSizeLimit ) )
|
||||||
{
|
{
|
||||||
size_exceeded = true;
|
size_exceeded = true;
|
||||||
|
|
||||||
// Non zero return means abort.
|
// Non zero return means abort.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -188,6 +190,7 @@ bool PLUGIN_CONTENT_MANAGER::DownloadToStream( const wxString& aUrl, std::ostrea
|
||||||
{
|
{
|
||||||
reporter->SetCurrentProgress( 0.0 );
|
reporter->SetCurrentProgress( 0.0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return !reporter->KeepRefreshing();
|
return !reporter->KeepRefreshing();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -226,6 +229,7 @@ bool PLUGIN_CONTENT_MANAGER::FetchRepository( const wxString& aUrl, PCM_REPOSITO
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json repository_json;
|
nlohmann::json repository_json;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
repository_stream >> repository_json;
|
repository_stream >> repository_json;
|
||||||
|
@ -257,6 +261,7 @@ bool PLUGIN_CONTENT_MANAGER::fetchPackages( const wxString& aUr
|
||||||
std::vector<PCM_PACKAGE>& aPackages )
|
std::vector<PCM_PACKAGE>& aPackages )
|
||||||
{
|
{
|
||||||
std::stringstream packages_stream;
|
std::stringstream packages_stream;
|
||||||
|
|
||||||
if( !DownloadToStream( aUrl, &packages_stream, _( "Fetching repository packages" ) ) )
|
if( !DownloadToStream( aUrl, &packages_stream, _( "Fetching repository packages" ) ) )
|
||||||
{
|
{
|
||||||
wxLogError( _( "Unable to load repository packages url." ) );
|
wxLogError( _( "Unable to load repository packages url." ) );
|
||||||
|
|
Loading…
Reference in New Issue