2024-09-16 14:11:01 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "packet.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "client/ui.h"
|
|
|
|
#include "client/db.h"
|
|
|
|
#include "client/user.h"
|
|
|
|
|
2024-09-18 09:41:54 +02:00
|
|
|
static int callback(void *ignore, int argc, char **argv, char **azColName)
|
2024-09-16 14:11:01 +02:00
|
|
|
{
|
2024-09-18 09:41:54 +02:00
|
|
|
char *username = memalloc(MAX_NAME * sizeof(char));
|
2024-09-16 14:11:01 +02:00
|
|
|
strcpy(username, argv[0]);
|
2024-09-18 09:41:54 +02:00
|
|
|
/* Add only if it isn't talking yourself */
|
|
|
|
if (strncmp(username, USERNAME, MAX_NAME))
|
|
|
|
add_username(username);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2024-09-16 14:11:01 +02:00
|
|
|
|
2024-09-18 09:41:54 +02:00
|
|
|
static int get_shared_key(void *ignore, int argc, char **argv, char **column)
|
|
|
|
{
|
2024-09-16 14:11:01 +02:00
|
|
|
for(int i = 0; i < argc; i++) {
|
2024-09-18 09:41:54 +02:00
|
|
|
printf("%s = %s\n", column[i], argv[i] ? argv[i] : "NULL");
|
2024-09-16 14:11:01 +02:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-18 09:41:54 +02:00
|
|
|
|
2024-09-16 14:11:01 +02:00
|
|
|
int sqlite_init()
|
|
|
|
{
|
|
|
|
sqlite3 *db;
|
|
|
|
char *err_msg = 0;
|
|
|
|
|
|
|
|
int rc = sqlite3_open(DATABASE_NAME, &db);
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
|
|
|
|
sqlite3_close(db);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-09-18 09:41:54 +02:00
|
|
|
char *users_statement = "CREATE TABLE IF NOT EXISTS Users(Username TEXT, SharedKey TEXT, Test TEXT);";
|
|
|
|
char *shared_key_statement = "SELECT * FROM Users;";
|
2024-09-16 14:11:01 +02:00
|
|
|
char *messages_statement = "CREATE TABLE IF NOT EXISTS Messages(Username TEXT, );";
|
|
|
|
//"INSERT INTO Users VALUES('night', 'test', '1');";
|
|
|
|
|
|
|
|
rc = sqlite3_exec(db, users_statement, 0, 0, &err_msg);
|
|
|
|
|
|
|
|
if (rc != SQLITE_OK) {
|
|
|
|
error(0, "SQL error: %s", err_msg);
|
|
|
|
sqlite3_free(err_msg);
|
|
|
|
} else {
|
|
|
|
/* error(0, "Table created successfully"); */
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select and print all entries
|
2024-09-18 09:41:54 +02:00
|
|
|
rc = sqlite3_exec(db, "SELECT * FROM Users", callback, NULL, &err_msg);
|
2024-09-16 14:11:01 +02:00
|
|
|
|
2024-09-18 09:41:54 +02:00
|
|
|
if (rc != SQLITE_OK) {
|
2024-09-16 14:11:01 +02:00
|
|
|
error(0, "SQL error: %s\n", err_msg);
|
|
|
|
sqlite3_free(err_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
sqlite3_close(db);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|