mirror of
				https://github.com/taigrr/arduinolibs
				synced 2025-01-18 04:33:12 -08:00 
			
		
		
		
	Move userid() from LoginShell to Shell
This commit is contained in:
		
							parent
							
								
									d9343243c7
								
							
						
					
					
						commit
						9ec197abdb
					
				| @ -44,7 +44,7 @@ | |||||||
|  * \return Returns zero or greater if the username and password combination |  * \return Returns zero or greater if the username and password combination | ||||||
|  * is correct, negative if incorrect. |  * is correct, negative if incorrect. | ||||||
|  * |  * | ||||||
|  * The return value is reported to the application as LoginShell::userid(), |  * The return value is reported to the application as Shell::userid(), | ||||||
|  * which can be used by the application to restrict the set of commands |  * which can be used by the application to restrict the set of commands | ||||||
|  * that are available to the user, or to restrict the behaviour of |  * that are available to the user, or to restrict the behaviour of | ||||||
|  * those commands when acting on critical resources. |  * those commands when acting on critical resources. | ||||||
| @ -55,7 +55,7 @@ | |||||||
|  * based on failed login attempts. |  * based on failed login attempts. | ||||||
|  * |  * | ||||||
|  * \relates LoginShell |  * \relates LoginShell | ||||||
|  * \sa LoginShell::userid() |  * \sa Shell::userid() | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
| @ -67,7 +67,6 @@ | |||||||
| LoginShell::LoginShell() | LoginShell::LoginShell() | ||||||
|     : machName(0) |     : machName(0) | ||||||
|     , checkFunc(0) |     , checkFunc(0) | ||||||
|     , uid(-1) |  | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -77,15 +76,3 @@ LoginShell::LoginShell() | |||||||
| LoginShell::~LoginShell() | LoginShell::~LoginShell() | ||||||
| { | { | ||||||
| } | } | ||||||
| 
 |  | ||||||
| /**
 |  | ||||||
|  * \fn int LoginShell::userid() const |  | ||||||
|  * \brief Gets the user identifier for the currently logged in user, |  | ||||||
|  * or -1 if there is no user logged in currently. |  | ||||||
|  * |  | ||||||
|  * The user identifier can be used by applications to restrict the set of |  | ||||||
|  * commands that are available to the user, or to restrict the behaviour |  | ||||||
|  * of those commands when acting on critical resources. |  | ||||||
|  * |  | ||||||
|  * \sa ShellPasswordCheckFunc |  | ||||||
|  */ |  | ||||||
|  | |||||||
| @ -39,8 +39,6 @@ public: | |||||||
|     ShellPasswordCheckFunc passwordCheckFunction() const { return checkFunc; } |     ShellPasswordCheckFunc passwordCheckFunction() const { return checkFunc; } | ||||||
|     void setPasswordCheckFunction(ShellPasswordCheckFunc function) { checkFunc = function; } |     void setPasswordCheckFunction(ShellPasswordCheckFunc function) { checkFunc = function; } | ||||||
| 
 | 
 | ||||||
|     int userid() const { return uid; } |  | ||||||
| 
 |  | ||||||
| protected: | protected: | ||||||
|     virtual void beginSession(); |     virtual void beginSession(); | ||||||
|     virtual void printPrompt(); |     virtual void printPrompt(); | ||||||
| @ -49,7 +47,6 @@ protected: | |||||||
| private: | private: | ||||||
|     const char *machName; |     const char *machName; | ||||||
|     ShellPasswordCheckFunc checkFunc; |     ShellPasswordCheckFunc checkFunc; | ||||||
|     int uid; |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -130,6 +130,7 @@ Shell::Shell() | |||||||
|     , prom("$ ") |     , prom("$ ") | ||||||
|     , isClient(false) |     , isClient(false) | ||||||
|     , lineMode(LINEMODE_NORMAL | LINEMODE_ECHO) |     , lineMode(LINEMODE_NORMAL | LINEMODE_ECHO) | ||||||
|  |     , uid(-1) | ||||||
|     , timer(0) |     , timer(0) | ||||||
| { | { | ||||||
| } | } | ||||||
| @ -243,6 +244,7 @@ bool Shell::beginShell(Stream &stream, size_t maxHistory, Terminal::Mode mode) | |||||||
|     curMax = sizeof(buffer); |     curMax = sizeof(buffer); | ||||||
|     historyWrite = 0; |     historyWrite = 0; | ||||||
|     historyRead = 0; |     historyRead = 0; | ||||||
|  |     uid = -1; | ||||||
| 
 | 
 | ||||||
|     // Begins the login session.
 |     // Begins the login session.
 | ||||||
|     beginSession(); |     beginSession(); | ||||||
| @ -271,6 +273,7 @@ void Shell::end() | |||||||
|     historySize = 0; |     historySize = 0; | ||||||
|     isClient = false; |     isClient = false; | ||||||
|     lineMode = LINEMODE_NORMAL | LINEMODE_ECHO; |     lineMode = LINEMODE_NORMAL | LINEMODE_ECHO; | ||||||
|  |     uid = -1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @cond */ | /** @cond */ | ||||||
| @ -507,6 +510,32 @@ void Shell::registerCommand(ShellCommandRegister *cmd) | |||||||
|  * \sa prompt() |  * \sa prompt() | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
|  | /**
 | ||||||
|  |  * \fn int Shell::userid() const | ||||||
|  |  * \brief Gets the user identifier for the currently logged in user, | ||||||
|  |  * or -1 if there is no user logged in currently. | ||||||
|  |  * | ||||||
|  |  * The user identifier can be used by applications to restrict the set of | ||||||
|  |  * commands that are available to the user, or to restrict the behaviour | ||||||
|  |  * of those commands when acting on critical resources. | ||||||
|  |  * | ||||||
|  |  * \sa setUserid(), ShellPasswordCheckFunc | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | /**
 | ||||||
|  |  * \fn void Shell::setUserid(int userid) | ||||||
|  |  * \brief Sets the user identifier for the currently logged in user. | ||||||
|  |  * | ||||||
|  |  * \param userid The new user identifier to set, or -1 if there is no | ||||||
|  |  * user logged in currently. | ||||||
|  |  * | ||||||
|  |  * Normally the user identifier is set when LoginShell detects a | ||||||
|  |  * successful login.  This function can be used to alter the access | ||||||
|  |  * rights of the logged-in user after login. | ||||||
|  |  * | ||||||
|  |  * \sa userid(), ShellPasswordCheckFunc | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * \brief Displays help for all supported commands. |  * \brief Displays help for all supported commands. | ||||||
|  */ |  */ | ||||||
| @ -548,6 +577,7 @@ void Shell::help() | |||||||
| void Shell::exit() | void Shell::exit() | ||||||
| { | { | ||||||
|     Stream *stream = this->stream(); |     Stream *stream = this->stream(); | ||||||
|  |     uid = -1; | ||||||
|     if (isClient) { |     if (isClient) { | ||||||
|         end(); |         end(); | ||||||
|         ((Client *)stream)->stop(); |         ((Client *)stream)->stop(); | ||||||
| @ -931,7 +961,6 @@ void LoginShell::beginSession() | |||||||
|     curStart = 0; |     curStart = 0; | ||||||
|     curLen = 0; |     curLen = 0; | ||||||
|     curMax = sizeof(buffer) / 2; |     curMax = sizeof(buffer) / 2; | ||||||
|     uid = -1; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  | |||||||
| @ -76,6 +76,9 @@ public: | |||||||
|     const char *prompt() const { return prom; } |     const char *prompt() const { return prom; } | ||||||
|     void setPrompt(const char *prompt) { prom = prompt; } |     void setPrompt(const char *prompt) { prom = prompt; } | ||||||
| 
 | 
 | ||||||
|  |     int userid() const { return uid; } | ||||||
|  |     void setUserid(int userid) { uid = userid; } | ||||||
|  | 
 | ||||||
|     void help(); |     void help(); | ||||||
|     void exit(); |     void exit(); | ||||||
| 
 | 
 | ||||||
| @ -96,6 +99,7 @@ private: | |||||||
|     const char *prom; |     const char *prom; | ||||||
|     bool isClient; |     bool isClient; | ||||||
|     uint8_t lineMode; |     uint8_t lineMode; | ||||||
|  |     int uid; | ||||||
|     unsigned long timer; |     unsigned long timer; | ||||||
| 
 | 
 | ||||||
|     // Disable copy constructor and operator=().
 |     // Disable copy constructor and operator=().
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user