diff --git a/db.c b/db.c index d6d1aa1..0ea5ddc 100644 --- a/db.c +++ b/db.c @@ -9,6 +9,7 @@ //#include #include #include +#include #include "db.h" #include "node_settings.h" @@ -561,3 +562,39 @@ int dbSaveMonitors(char *name) return result; } + +int dbInsertHistory(char *login, char *host) +{ + int result = 0; + + if (!(login && strlen(login)) || !(host && strlen(host))) + return -1; + + sqlite3 *db = dbGetBase(getPathDB(NULL)); + + if (!db) + { + return -2; + } + + sqlite3_stmt *res; + char *sql = "INSERT INTO `history` (`login`, `host`, `time`) VALUES (?, ?, ?)"; + if (sqlite3_prepare_v2(db, sql, -1, &res, 0) == SQLITE_OK) + { + sqlite3_bind_text(res, 1, login, -1, 0); + sqlite3_bind_text(res, 2, host, -1, 0); + sqlite3_bind_int(res, 3, (unsigned)time(NULL)); + } + + if (sqlite3_step(res) == SQLITE_DONE) + { + sqlite3_finalize(res); + sqlite3_close(db); + return 0; + } + + sqlite3_finalize(res); + sqlite3_close(db); + + return result; +} diff --git a/db.h b/db.h index 89c7e1c..6b528ca 100644 --- a/db.h +++ b/db.h @@ -52,5 +52,6 @@ bool dbWriteParameter(Parameter name, bool set); bool dbWriteValue(Value name, bool set); bool dbSetUserNameCurrent(char *current); int dbAddServer(char *ip, char *dns); +int dbInsertHistory(char *login, char *host); #endif /* DB_H_ */ diff --git a/freerdp.db b/freerdp.db index 1b31d00..7c0f798 100644 Binary files a/freerdp.db and b/freerdp.db differ diff --git a/gui.c b/gui.c index 4c2356a..4ad1325 100644 --- a/gui.c +++ b/gui.c @@ -27,13 +27,15 @@ static int guiExit(Ihandle *self) static int guiConnect(Ihandle *self) { - char *result = getHostIP(IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE")); + char *host = IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"); + char *login = IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE"); + char *result = getHostIP(host); if (!result) return IUP_DEFAULT; setParameterValue(PARAMETER_SERVER, VALUE_SERVER, result); - setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE")); + setParameterValue(PARAMETER_USERNAME, VALUE_USERNAME, login); setParameterValue(PARAMETER_PASSWORD, VALUE_PASSWORD, IupGetAttribute(IupGetDialogChild(self, "PASSWORD"), "LINEVALUE")); Arguments args; @@ -45,11 +47,12 @@ static int guiConnect(Ihandle *self) // if (free_rdp_connect(args.argc, args.argv) != XF_EXIT_DNS_NAME_NOT_FOUND) // { - if (!dbAddServer(result, IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE"))) + dbInsertHistory(login, host); + if (!dbAddServer(result, host)) { - IupSetAttribute(IupGetDialogChild(self, "SERVER"), "APPENDITEM", IupGetAttribute(IupGetDialogChild(self, "SERVER"), "VALUE")); + IupSetAttribute(IupGetDialogChild(self, "SERVER"), "APPENDITEM", host); } - dbSetUserNameCurrent(IupGetAttribute(IupGetDialogChild(self, "USER"), "LINEVALUE")); + dbSetUserNameCurrent(login); // } freeArguments(&args);