File hashing (not finished)

This commit is contained in:
2025-10-27 17:33:39 +02:00
parent 24c4e75943
commit 76dff7dafb
9 changed files with 421 additions and 86 deletions
+12 -57
View File
@@ -45,7 +45,7 @@ static void processNotice(void *arg, const char *message) {
// do nothing
}
int init_connection() {
int init_db_connection() {
// TODO: get from external configs
conn = PQconnectdb("user=postgres password=dobro host=127.0.0.1 dbname=bbs");
@@ -56,20 +56,20 @@ int init_connection() {
char *user = PQuser(conn);
char *db_name = PQdb(conn);
printf("Connection established! server version: %d, user: %s, db: %s\n", server_ver,
user, db_name);
printf("Connection established! server version: %d, user: %s, db: %s\n",
server_ver, user, db_name);
return exit_query(0);
}
int db_user_auth(i_auth_t *credentials, o_auth_t *response) {
char query[Q_LEN];
response->is_logged = 0;
sprintf(query,
"SELECT username, password, privileges "
"FROM users "
"WHERE username= '%s'",
credentials->name);
res = PQexec(conn, query);
const char *paramValues[1];
paramValues[0] = credentials->name;
res = PQexecParams(conn,
"SELECT username, password, privileges "
"FROM users "
"WHERE username= $1", 1,
NULL, paramValues, NULL, NULL, 0);
if (PQresultStatus(res) != PGRES_TUPLES_OK && !PQntuples(res))
return exit_query(1);
@@ -81,49 +81,4 @@ int db_user_auth(i_auth_t *credentials, o_auth_t *response) {
return exit_query(0);
}
return exit_query(2);
}
/*s
int f_main() {
int libpq_ver = PQlibVersion();
printf("Version of libpq: %d\n", libpq_ver);
conn = PQconnectdb("user=postgres password=dobro host=127.0.0.1 dbname=bbs");
if (PQstatus(conn) != CONNECTION_OK)
terminate(1);
PQsetNoticeProcessor(conn, processNotice, NULL);
int server_ver = PQserverVersion(conn);
char *user = PQuser(conn);
char *db_name = PQdb(conn);
printf("Server version: %d\n", server_ver);
printf("User: %s\n", user);
printf("Database name: %s\n", db_name);
res = PQexec(conn, "SELECT id, username, privileges, email "
"FROM users");
if (PQresultStatus(res) != PGRES_TUPLES_OK)
terminate(1);
int nrows = PQntuples(res);
for (int i = 0; i < nrows; i++) {
char *id = PQgetvalue(res, i, 0);
char *name = PQgetvalue(res, i, 1);
char *privileges = PQgetvalue(res, i, 2);
char *email = PQgetvalue(res, i, 3);
printf("Id: %s, Name: %s, Privileges: %d, Email: %s, \n", id, name,
privileges[0], email);
}
printf("Total: %d rows\n", nrows);
clearRes();
terminate(0);
return 0;
}
*/
}