Newer
Older
/*
This file is part of SLS.
Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>
SLS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
SLS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SLS; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "sls.hh"
#include "option.hh"
#include "client_console.hh"
/*******************************************************************************
** Public methods
*******************************************************************************/
/**
* Entry point for a console backend
*/
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
while (1) {
// receive line
string cmd = c_.recvln();
// Print info
if (O.verbose) std::cout << "Cid " << c_.getid() << ": Receive: " << cmd << ".\n";
else std::cout << "Cid " << c_.getid() << ": Receive request.\n";
// call parser
try { parse(cmd); }
catch (const Error &e) {
if (e.code() == ERR_PARSE) {
// Print info
if (O.verbose) std::cout << "Cid " << c_.getid() << ": Parse error: " << e << ".\n";
else std::cout << "Cid " << c_.getid() << ": Invalid command.\n";
}
else throw;
}
}
}
/*******************************************************************************
** Protected methods
*******************************************************************************/
/**
* Constructor
*
* @param c Attached connection
*/
Console::Console(Connection &c) : Client(c) {}
/**
* Check if login and pass are valid user
* and register login and pass are logged in DB
*
* @param login user login
* @param pass user pass
*
* @return if user is logged or not
*/
bool Console::trust(const char *login, const char *pass) {
assert(login);
assert(pass);
// check login and password in DB
// store username
login_ = login;
// register as logged in DB
/**
* Return public type of backend
*/
string Console::type() {
return "User";
}
/**
* Parse and execute
*
* @param cmd string to parse
*/
void Console::parse(const string &cmd) {
throw Error(ERR_PARSE, "Empty command");
// FIXME