KiCad PCB EDA Suite
Loading...
Searching...
No Matches
database_lib_settings.h File Reference
#include <json_common.h>
#include <functional>
#include <settings/json_settings.h>
#include <wx/string.h>
#include <map>
#include <memory>

Go to the source code of this file.

Classes

struct  DATABASE_SOURCE
 
struct  DATABASE_FIELD_MAPPING
 
struct  MAPPABLE_SYMBOL_PROPERTIES
 
struct  DATABASE_LIB_TABLE
 A database library table will be mapped to a sub-library provided by the database library entry in the KiCad symbol/footprint library table. More...
 
struct  DATABASE_CACHE_SETTINGS
 
class  DATABASE_LIB_SETTINGS
 
struct  DATABASE_LIB_SETTINGS::LOADED_SCALARS
 Scalar settings as parsed at load, so Store() can tell which ones the caller changed. More...
 

Typedefs

using DATABASE_SECRET_LOOKUP = std::function<bool( const wxString& aService, const wxString& aKey, wxString& aSecret )>
 Keyring lookup signature, matching KIPLATFORM::SECRETS::GetSecretNoPrompt.
 

Enumerations

enum class  DATABASE_SOURCE_TYPE { ODBC , INVALID }
 

Functions

KICOMMON_API std::unique_ptr< DATABASE_LIB_SETTINGS > LoadDatabaseLibSettingsReadOnly (const wxString &aPath, bool *aLoaded=nullptr)
 Loads a database library settings file without allowing the load itself (e.g.
 
KICOMMON_API wxString DefaultDatabaseLibFileName (const wxString &aLibName)
 
KICOMMON_API DATABASE_SECRET_LOOKUP DefaultDatabaseSecretLookup ()
 The lookup used when none is injected, which must never prompt to unlock the keyring.
 
KICOMMON_API bool IsNoPromptSecretLookup (const DATABASE_SECRET_LOOKUP &aLookup)
 
KICOMMON_API bool GetDatabasePassword (const DATABASE_SOURCE &aSource, std::string &aPassword, const DATABASE_SECRET_LOOKUP &aLookup=nullptr)
 DSN passwords that are not saved in the (often shared) library file live in the system keyring, keyed by DSN and user name so every library on the same login shares one entry.
 
KICOMMON_API void ResolveDatabasePassword (DATABASE_SOURCE &aSource, const DATABASE_SECRET_LOOKUP &aLookup=nullptr)
 Fills in the source password from the keyring, but only when the library file did not supply one.
 
KICOMMON_API bool StoreDatabasePassword (const DATABASE_SOURCE &aSource, const std::string &aPassword)
 Stores the password for the source's DSN login in the system keyring, or removes the entry when the password is empty.
 

Typedef Documentation

◆ DATABASE_SECRET_LOOKUP

using DATABASE_SECRET_LOOKUP = std::function<bool( const wxString& aService, const wxString& aKey, wxString& aSecret )>

Keyring lookup signature, matching KIPLATFORM::SECRETS::GetSecretNoPrompt.

Definition at line 124 of file database_lib_settings.h.

Enumeration Type Documentation

◆ DATABASE_SOURCE_TYPE

enum class DATABASE_SOURCE_TYPE
strong
Enumerator
ODBC 
INVALID 

Definition at line 33 of file database_lib_settings.h.

Function Documentation

◆ DefaultDatabaseLibFileName()

KICOMMON_API wxString DefaultDatabaseLibFileName ( const wxString & aLibName)
Returns
a file name without extension for a new settings file, derived from the library name the user typed, or a generic name when that leaves nothing usable

Definition at line 431 of file database_lib_settings.cpp.

References name, and ReplaceIllegalFileNameChars().

Referenced by DIALOG_DATABASE_LIB_SETTINGS::chooseSavePath().

◆ DefaultDatabaseSecretLookup()

KICOMMON_API DATABASE_SECRET_LOOKUP DefaultDatabaseSecretLookup ( )

The lookup used when none is injected, which must never prompt to unlock the keyring.

Definition at line 451 of file database_lib_settings.cpp.

References KIPLATFORM::SECRETS::GetSecretNoPrompt().

Referenced by GetDatabasePassword().

◆ GetDatabasePassword()

KICOMMON_API bool GetDatabasePassword ( const DATABASE_SOURCE & aSource,
std::string & aPassword,
const DATABASE_SECRET_LOOKUP & aLookup = nullptr )

DSN passwords that are not saved in the (often shared) library file live in the system keyring, keyed by DSN and user name so every library on the same login shares one entry.

Parameters
aLookupreplaces the system keyring when set, for tests.
Returns
false when the source has no DSN login or the keyring holds no password for it

Definition at line 474 of file database_lib_settings.cpp.

References DefaultDatabaseSecretLookup(), hasKeyringLogin(), passwordService(), and DATABASE_SOURCE::username.

Referenced by ResolveDatabasePassword(), and DIALOG_DATABASE_LIB_SETTINGS::TransferDataToWindow().

◆ IsNoPromptSecretLookup()

KICOMMON_API bool IsNoPromptSecretLookup ( const DATABASE_SECRET_LOOKUP & aLookup)
Returns
true when aLookup is the system keyring lookup that never prompts to unlock it.

Definition at line 457 of file database_lib_settings.cpp.

References KIPLATFORM::SECRETS::GetSecretNoPrompt().

◆ LoadDatabaseLibSettingsReadOnly()

KICOMMON_API std::unique_ptr< DATABASE_LIB_SETTINGS > LoadDatabaseLibSettingsReadOnly ( const wxString & aPath,
bool * aLoaded = nullptr )

Loads a database library settings file without allowing the load itself (e.g.

a schema migration) to write back to disk. Callers must SetReadOnly( false ) around an explicit save.

Parameters
aLoadedis set to false when the file exists but could not be read; saving such settings would replace the file with defaults

Definition at line 411 of file database_lib_settings.cpp.

References FILEEXT::DatabaseLibraryFileExtension, and path.

Referenced by BOOST_AUTO_TEST_CASE().

◆ ResolveDatabasePassword()

KICOMMON_API void ResolveDatabasePassword ( DATABASE_SOURCE & aSource,
const DATABASE_SECRET_LOOKUP & aLookup = nullptr )

Fills in the source password from the keyring, but only when the library file did not supply one.

Definition at line 491 of file database_lib_settings.cpp.

References GetDatabasePassword(), and DATABASE_SOURCE::password.

Referenced by DATABASE_LIB_SETTINGS::ResolvePassword().

◆ StoreDatabasePassword()

KICOMMON_API bool StoreDatabasePassword ( const DATABASE_SOURCE & aSource,
const std::string & aPassword )

Stores the password for the source's DSN login in the system keyring, or removes the entry when the password is empty.

Definition at line 498 of file database_lib_settings.cpp.

References KIPLATFORM::SECRETS::DeleteSecret(), hasKeyringLogin(), passwordService(), KIPLATFORM::SECRETS::StoreSecret(), and DATABASE_SOURCE::username.

Referenced by DIALOG_DATABASE_LIB_SETTINGS::TransferDataFromWindow().