Skip to content

Commit 86ff243

Browse files
committed
Update
1 parent b92489a commit 86ff243

File tree

5 files changed

+90
-10
lines changed

5 files changed

+90
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
server/
22
client/
33
test/main
4+
test/test.db

client.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ class project {
184184
void set() {
185185
char buffer[1024];
186186
do {
187-
/*printw("Path to your project: ");
187+
printw("Path to your project: ");
188188
getstr(buffer);
189-
prjPath = buffer;*/
189+
prjPath = buffer;
190190
} while (!fs::exists(prjPath) && !fs::is_directory(prjPath));
191-
prjPath = "/home/jomm/Documents/kurwa/client/test/";
191+
// prjPath = "/home/jomm/Documents/kurwa/client/test/";
192192
do {
193193
printw("Name of your project: ");
194194
getstr(buffer);

server.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <netinet/in.h>
22
#include <openssl/sha.h>
33
#include <openssl/ssl.h>
4+
#include <signal.h>
45
#include <sqlite3.h>
56
#include <sys/socket.h>
67
#include <sys/un.h>
@@ -243,6 +244,7 @@ void handleClient(client client, sqlite3* db, string path) {
243244
}
244245

245246
int main(int argc, char* argv[]) {
247+
signal(SIGPIPE, SIG_IGN);
246248
string path = fs::canonical(argv[0]).parent_path().string() + '/';
247249

248250
sqlite3* db;

test/comtest.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using namespace std;
1616
namespace fs = std::filesystem;
1717

18-
const int numClients = 1;
18+
const unsigned short numClients = 1;
1919
string path;
2020

2121
void progressBar(const long &prog, const long &total) {
@@ -119,19 +119,25 @@ class client {
119119
string msg = sock.recv();
120120
printw("%s\n", msg.c_str());
121121
sock.send(msg);
122-
sock.recvFile("/home/jomm/Documents/kurwa/client/test/Asakusa1.png");
123-
sock.sendFile("/home/jomm/Documents/kurwa/client/test/Asakusa1.png");
122+
if (numClients == 1) {
123+
sock.recvFile(
124+
"/home/jomm/Documents/kurwa/client/test/Asakusa1.png");
125+
sock.sendFile(
126+
"/home/jomm/Documents/kurwa/client/test/Asakusa1.png");
127+
}
124128
}
125129
void testClient() {
126130
string msg = "Hello, world!";
127131
sock.send(msg);
128132
msg = "";
129133
msg = sock.recv();
130134
printw("%s\n", msg.c_str());
131-
sock.sendFile("/home/jomm/Documents/kurwa/client/test/Asakusa.png",
132-
progressBar);
133-
sock.recvFile("/home/jomm/Documents/kurwa/client/test/Asakusa2.png",
134-
progressBar);
135+
if (numClients == 1) {
136+
sock.sendFile("/home/jomm/Documents/kurwa/client/test/Asakusa.png",
137+
progressBar);
138+
sock.recvFile("/home/jomm/Documents/kurwa/client/test/Asakusa2.png",
139+
progressBar);
140+
}
135141
}
136142

137143
client(SSL *ssl) : sock(ssl) {}

test/dbtest.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <sqlite3.h>
2+
#include <stdarg.h>
3+
4+
#include <filesystem>
5+
#include <iostream>
6+
#include <unordered_map>
7+
8+
using namespace std;
9+
namespace fs = std::filesystem;
10+
11+
class clsDb {
12+
private:
13+
sqlite3 *db;
14+
unordered_map<string, unordered_map<string, string>> dbMap;
15+
16+
void setDbMap() {
17+
sqlite3_stmt *stmt;
18+
sqlite3_prepare_v2(db,
19+
"select name from sqlite_master where type='table'",
20+
-1, &stmt, 0);
21+
while (sqlite3_step(stmt) == SQLITE_ROW) {
22+
string table = (const char *)sqlite3_column_text(stmt, 0);
23+
sqlite3_stmt *stmt2;
24+
sqlite3_prepare_v2(db, ("pragma table_info(" + table + ")").c_str(),
25+
-1, &stmt2, 0);
26+
while (sqlite3_step(stmt2) == SQLITE_ROW)
27+
dbMap[table][(const char *)sqlite3_column_text(stmt2, 1)] =
28+
(const char *)sqlite3_column_text(stmt2, 2);
29+
30+
sqlite3_finalize(stmt2);
31+
}
32+
sqlite3_finalize(stmt);
33+
}
34+
35+
public:
36+
void insert(const string &table, const string &columns, ...) {
37+
va_list args;
38+
va_start(args, columns);
39+
short n = 0;
40+
for (int i = 0; i < columns.length(); i++)
41+
if (columns[i] == ',') n++;
42+
43+
string command = "insert into users (" + columns + ") values (";
44+
for (int i = 0; i < n; i++) command += "?, ";
45+
command += "?);";
46+
cout << command << endl;
47+
48+
sqlite3_stmt *stmt;
49+
sqlite3_prepare_v2(db, command.c_str(), -1, &stmt, 0);
50+
51+
sqlite3_finalize(stmt);
52+
53+
va_end(args);
54+
}
55+
clsDb(const string &path, const string &command) {
56+
sqlite3_open(path.c_str(), &db);
57+
sqlite3_exec(db, command.c_str(), 0, 0, 0);
58+
setDbMap();
59+
}
60+
};
61+
62+
int main(int argc, char *argv[]) {
63+
string path = fs::canonical(argv[0]).parent_path().string() + '/';
64+
65+
clsDb db(
66+
path + "test.db", //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
67+
"create table if not exists users(id integer primary key, username "
68+
"text, password blob); create table if not exists projects(id integer "
69+
"primary key, ownerId integer, prjName text, dir text, dirTree text)");
70+
db.insert("table", "username, password", "kurwa", "aboba");
71+
}

0 commit comments

Comments
 (0)