pianod2
multisource multiuser scriptable networked music player
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
UserManager Class Reference

Container and manager class for users. More...

#include <users.h>

Inheritance diagram for UserManager:
Inheritance graph
[legend]
Collaboration diagram for UserManager:
Collaboration graph
[legend]

Public Types

enum class  WhichSources { User , Listed , Restorable }
 
using UserSelectionPredicate = std::function< bool(const User *user)>
 
using StoredSourcePair = std::pair< User *, UserData::DataStore * >
 
using StoredSourceList = std::vector< StoredSourcePair >
 
- Public Types inherited from PianodInterpreter
using HelpList = PianodDispatcher::HelpList
 

Public Member Functions

virtual const Parsnip::Parser::DefinitionsgetParserDefinitions () override
 Retrieve the parser definitions handled by the interpreter. More...
 
virtual ~UserManager ()
 
const std::string & shadowUserName () const
 Get the name of the user used as a template for shadow users. More...
 
void shadowUserName (const std::string &who)
 Get a user as a template for shadow users. More...
 
UseraddUser (User &user)
 Add a user to the list of known users. More...
 
Usertryget (const std::string &who)
 Retrieve a user's record. More...
 
Userget (const std::string &who)
 Retrieve a user's record. More...
 
Userauthenticate (const std::string &who, const std::string &password)
 Verify a user's credentials. More...
 
void clearPrivilege (Privilege priv)
 Disable a privilege for all users. More...
 
bool validUserList (Football::Connection *event, char *const *username)
 
std::vector< PianodConnection * > getUserConnections (PianodService &service, const User *user) const
 Retrieve a list of a user's connections. More...
 
UserList getUsers (UserSelectionPredicate predicate=[](const User *) { return true;}) const
 Retrieve a list of users matching some predicate. More...
 
UserList getUsersPresent (PianodService &service, bool use_attribute=false) const
 Retrieve a list of a users connected. More...
 
UserList allUsers (void) const
 
StoredSourceList getStoredSources (WhichSources selection, const User *visibleBy=nullptr) const
 Return a list of persisted datasource parameters. More...
 
RESPONSE_CODE findStoredSource (const std::string &type, const std::string &name, User *forWho, UserData::JSONData **found, User **owner)
 Find stored source parameters for use. More...
 
void createDefaultUser ()
 Add the default 'admin' user to the users list. More...
 
void deleteUser (User *user)
 Remove a user from the registered list of users. More...
 
bool persist ()
 Persist user data to a file. More...
 
void restore ()
 Resubstantiate a user from the XML userdata file. More...
 
float periodic (void)
 Execute periodic tasks: More...
 
- Public Member Functions inherited from PianodInterpreter
virtual void registerInterpreter (PianodDispatcher &dispatcher)
 Register the interpreter with a dispatcher. More...
 
const HelpList getHelp (const std::vector< std::string > &search, std::set< std::string > *option_parsers)
 Search the interpreter's definitions for any definitions matching search criteria. More...
 

Static Public Member Functions

static const Parsnip::Parser::Definitionsparser_definitions ()
 
static const PianodSchema::CommandIdsjson_request_names (PianodSchema &schema)
 Retrieve names for our JSON requests, and make schema revisions. More...
 
static time_t writeTime (void)
 
static bool needWrite (void)
 
- Static Public Member Functions inherited from PianodInterpreter
static bool optionIs (const Parsnip::Data &options, const char *name, const char *expected)
 Check if a string value exists and is case-blind equal to a particular value. More...
 
template<typename ValueType , typename LookupType >
static ValueType optionalValue (const Parsnip::Data &options, const char *name, const LookupType &lookup, const ValueType default_value)
 Retrieve the ID of a string value. More...
 

Private Member Functions

virtual bool authorizedCommand (Parsnip::Parser::CommandId, PianodConnection &conn) override
 Check whether a command is authorized. More...
 
virtual ResponseCollector handleCommand (Parsnip::Parser::CommandId, const Parsnip::Data &options, PianodConnection &conn) override
 Command handler. More...
 

Private Attributes

std::string shadow_user_name
 

Additional Inherited Members

- Protected Types inherited from PianodInterpreter
using StringVector = std::vector< std::string >
 
- Static Protected Attributes inherited from PianodInterpreter
static const Parsnip::Data EmptyDictionary {Parsnip::Data::Dictionary}
 An empty dictionary, often used as a default with Parsnip::Data::getOr. More...
 
static const StringVector EmptyStringVector
 An empty string vector, often used as a default with Parsnip::Data::getOr. More...
 

Detailed Description

Container and manager class for users.

Member Typedef Documentation

◆ StoredSourceList

◆ StoredSourcePair

◆ UserSelectionPredicate

using UserManager::UserSelectionPredicate = std::function<bool (const User *user)>

Member Enumeration Documentation

◆ WhichSources

Enumerator
User 

Sources owned by a specific user.

Listed 

Sources that are publicly known.

Restorable 

Sources for automatic restore.

Constructor & Destructor Documentation

◆ ~UserManager()

UserManager::~UserManager ( )
virtual

Member Function Documentation

◆ addUser()

User * UserManager::addUser ( User user)

Add a user to the list of known users.

Parameters
userA profile for the user to register.
Returns
A pointer to the newly constructed user.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ allUsers()

UserList UserManager::allUsers ( void  ) const
inline
Here is the call graph for this function:
Here is the caller graph for this function:

◆ authenticate()

User * UserManager::authenticate ( const std::string &  who,
const std::string &  password 
)

Verify a user's credentials.

If password shadowing is enabled and the user is not known to pianod, checks for a known, eligible system user with the name and adds them if found.

Parameters
whoThe username to retrieve. Case insensitive.
passwordThe password to try.
Returns
The record, if the users exists and the password is valid.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ authorizedCommand()

bool UserManager::authorizedCommand ( Parsnip::Parser::CommandId  command_id,
PianodConnection context 
)
overrideprivatevirtual

Check whether a command is authorized.

Parameters
command_idThe command requesting execution.
contextConnection details, including authentication state and privileges.
Returns
True if allowed, false otherwise.

Implements PianodInterpreter.

Here is the call graph for this function:

◆ clearPrivilege()

void UserManager::clearPrivilege ( Privilege  priv)

Disable a privilege for all users.

Parameters
privThe privilege to clear.
Here is the caller graph for this function:

◆ createDefaultUser()

void UserManager::createDefaultUser ( )

Add the default 'admin' user to the users list.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteUser()

void UserManager::deleteUser ( User user)

Remove a user from the registered list of users.

Parameters
userThe user to remove. The passed pointer is invalidated by this call.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ findStoredSource()

RESPONSE_CODE UserManager::findStoredSource ( const std::string &  type,
const std::string &  name,
User forWho,
UserData::JSONData **  found,
User **  owner 
)

Find stored source parameters for use.

Success requires the stored source exists and is eligible for use by the requester.

Parameters
typeThe type of source.
nameThe name of the source.
forWhoThe user that wants to use the source.
[out]foundThe source parameters retrieved.
[out]ownerThe owner of the retrieved source.
Returns
S_OK on success, or an appropriate error code.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get()

User * UserManager::get ( const std::string &  who)

Retrieve a user's record.

Parameters
whoThe username to retrieve. Case insensitive.
Returns
The record.
Exceptions
CommandErrorif the specified user is not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getParserDefinitions()

const Parsnip::Parser::Definitions & UserManager::getParserDefinitions ( )
overridevirtual

Retrieve the parser definitions handled by the interpreter.

Returns
Parser definitions.

Implements PianodInterpreter.

Here is the call graph for this function:

◆ getStoredSources()

UserManager::StoredSourceList UserManager::getStoredSources ( UserManager::WhichSources  selection,
const User requester = nullptr 
) const

Return a list of persisted datasource parameters.

Parameters
selectionWhich selection criteria to apply in creating list.
requesterIf specified, return only the requester's sources.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUserConnections()

std::vector< PianodConnection * > UserManager::getUserConnections ( PianodService service,
const User user 
) const

Retrieve a list of a user's connections.

Parameters
serviceThe football service to search.
userThe user to find.
Returns
A list of connections, empty if none found.

◆ getUsers()

UserList UserManager::getUsers ( UserSelectionPredicate  predicate = [] (const User *) { return true; }) const

Retrieve a list of users matching some predicate.

Here is the caller graph for this function:

◆ getUsersPresent()

UserList UserManager::getUsersPresent ( PianodService service,
bool  use_attribute = false 
) const

Retrieve a list of a users connected.

Parameters
serviceThe football service to search.
use_attributeIf true, then the Present attribute is considered in determining presence. If false, active sessions indicate presence.
Returns
A list of users, empty if none online/present.
Here is the caller graph for this function:

◆ handleCommand()

ResponseCollector UserManager::handleCommand ( Parsnip::Parser::CommandId  command_id,
const Parsnip::Data parameters,
PianodConnection context 
)
overrideprivatevirtual

Command handler.

Parameters
command_idCommand to execute.
parametersCommand parameters.
contextConnection details, including authentication state and privileges.
Returns
Data or success/failure indications.
Exceptions
CommandErroror other exception if an error occurs.

Implements PianodInterpreter.

Here is the call graph for this function:

◆ json_request_names()

const PianodSchema::CommandIds & UserManager::json_request_names ( PianodSchema schema)
static

Retrieve names for our JSON requests, and make schema revisions.

Parameters
schemaThe schemaset containing our requests.
Returns
Request name to command ID mappings.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ needWrite()

static bool UserManager::needWrite ( void  )
inlinestatic

◆ parser_definitions()

const Parsnip::Parser::Definitions & UserManager::parser_definitions ( void  )
static
Here is the caller graph for this function:

◆ periodic()

float UserManager::periodic ( void  )

Execute periodic tasks:

  • If the user data file is scheduled for write, persist it now.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ persist()

bool UserManager::persist ( void  )

Persist user data to a file.

Write to a new file, then carefully move the old one out/new one in in such a way as to minimize risk.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restore()

void UserManager::restore ( )

Resubstantiate a user from the XML userdata file.

Exceptions
bad_alloc,whichwill leave class in indeterminate state.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shadowUserName() [1/2]

const std::string & UserManager::shadowUserName ( ) const

Get the name of the user used as a template for shadow users.

Here is the caller graph for this function:

◆ shadowUserName() [2/2]

void UserManager::shadowUserName ( const std::string &  who)

Get a user as a template for shadow users.

Here is the call graph for this function:

◆ tryget()

User * UserManager::tryget ( const std::string &  who)

Retrieve a user's record.

Parameters
whoThe username to retrieve. Case insensitive.
Returns
The record, or nullptr if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ validUserList()

bool UserManager::validUserList ( Football::Connection event,
char *const *  username 
)

◆ writeTime()

static time_t UserManager::writeTime ( void  )
inlinestatic

Member Data Documentation

◆ shadow_user_name

std::string UserManager::shadow_user_name
private

The documentation for this class was generated from the following files: