Update model to look like database, add method to query server list

This commit is contained in:
oupson 2023-02-27 18:53:26 +01:00
parent a04bb393a4
commit 9a145dd94e
Signed by: oupson
GPG Key ID: 3BD88615552EFCB7
4 changed files with 63 additions and 45 deletions

View File

@ -20,16 +20,16 @@
namespace Footerm.Model {
public class Server {
public string name;
public string hostname;
public ushort port;
public string username;
public string password;
public Server(string hostname, ushort port, string username, string password) {
public Server(string name, string hostname, ushort port, string username) {
this.name = name;
this.hostname = hostname;
this.port = port;
this.username = username;
this.password = password;
}
}
}

View File

@ -52,7 +52,7 @@ namespace Footerm {
// Port is invalid
}
this.on_new_server(new Footerm.Model.Server(hostname, (ushort)port, username, password));
// this.on_new_server(new Footerm.Model.Server(hostname, (ushort)port, username, password));
}
}
}

View File

@ -107,5 +107,22 @@ namespace Footerm.Services {
return true;
}
public List<Footerm.Model.Server> get_server_list() throws ConfigError {
List<Footerm.Model.Server> list = new List<Footerm.Model.Server> ();
var stm_str = "SELECT (serverId, serverName, serverHostName, serverPort) FROM SERVER";
Sqlite.Statement stm;
var ec = this.db.prepare_v2(stm_str, stm_str.length, out stm);
if (ec != Sqlite.OK) {
throw new ConfigError.DATABASE(@"Can't fetch server list: $(db.errcode ()): $(db.errmsg ())");
}
while (stm.step() == Sqlite.ROW) {
list.append(new Footerm.Model.Server(stm.column_text(0), stm.column_text(1), (ushort) stm.column_int(2), stm.column_text(3)));
}
return list;
}
}
}

View File

@ -72,7 +72,8 @@ namespace Footerm {
}
stdout.printf("\n");
if (session.auth_password(this.server.username, this.server.password) != SSH2.Error.NONE) {
// TODO QUERY PASSWORD FROM libsecret
if (session.auth_password(this.server.username, null) != SSH2.Error.NONE) {
stdout.printf("\tAuthentication by password failed!\n");
session.disconnect("Normal Shutdown, Thank you for playing");
session = null;