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 , SQLITE , ACCESS , 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 std::string DatabasePathForStorage (const wxString &aPath, const wxString &aBaseDir)
 
KICOMMON_API wxString DatabasePathFromInput (const wxString &aInput, const wxString &aBaseDir)
 
int DatabaseFileWaitSeconds (int aTimeoutSeconds)
 
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.
 

Variables

constexpr int DEFAULT_DATABASE_TIMEOUT_SECONDS = 2
 The source timeout a library file gets when it sets none.
 

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 139 of file database_lib_settings.h.

Enumeration Type Documentation

◆ DATABASE_SOURCE_TYPE

enum class DATABASE_SOURCE_TYPE
strong
Enumerator
ODBC 
SQLITE 
ACCESS 
INVALID 

Definition at line 33 of file database_lib_settings.h.

Function Documentation

◆ DatabaseFileWaitSeconds()

int DatabaseFileWaitSeconds ( int aTimeoutSeconds)
inline
Returns
the seconds a caller waits on a database source with the given timeout before giving up, which is the timeout plus 10 s for the worker, or 30 s when the timeout is 0

Definition at line 240 of file database_lib_settings.h.

Referenced by DB_WORKER_THREAD::CallerBound(), describeFailure(), and SCH_IO_DATABASE::loadSettingsBounded().

◆ DatabasePathForStorage()

KICOMMON_API std::string DatabasePathForStorage ( const wxString & aPath,
const wxString & aBaseDir )
Returns
aPath as ${CWD}/<relative> when it lies in aBaseDir or below it, so a library moves with its database file; any other path is returned unchanged

Definition at line 661 of file database_lib_settings.cpp.

Referenced by DIALOG_DATABASE_LIB_SETTINGS::storeSource().

◆ DatabasePathFromInput()

KICOMMON_API wxString DatabasePathFromInput ( const wxString & aInput,
const wxString & aBaseDir )
Returns
the path a user typed or pasted as an absolute path, with ${CWD} expanded and a relative path taken from aBaseDir; never touches the file system, so a path on an unreachable share costs nothing

Definition at line 702 of file database_lib_settings.cpp.

References source.

Referenced by DIALOG_DATABASE_LIB_SETTINGS::OnBrowseFile(), and DIALOG_DATABASE_LIB_SETTINGS::OnFileTextChanged().

◆ 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 647 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 734 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 758 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 740 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 628 of file database_lib_settings.cpp.

References 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 775 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 782 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().

Variable Documentation

◆ DEFAULT_DATABASE_TIMEOUT_SECONDS

int DEFAULT_DATABASE_TIMEOUT_SECONDS = 2
inlineconstexpr

The source timeout a library file gets when it sets none.

Definition at line 234 of file database_lib_settings.h.

Referenced by DATABASE_LIB_SETTINGS::DATABASE_LIB_SETTINGS().