From b33da89d96dd0b173dd1d6d6c2e560646f1b58a1 Mon Sep 17 00:00:00 2001 From: Norbert Moutarde Date: Mon, 29 Jul 2013 16:49:35 +0200 Subject: [PATCH] I try to make diary get my mail... (or anything else on web) --- alias.sql | 5 +++-- howto-compile.sh | 2 +- main.cpp | 3 ++- sqldb.cpp | 41 +++++++++++++++++++++++++++++++++-------- sqldb.h | 5 +++++ tables1.sql | 9 +++++++++ 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/alias.sql b/alias.sql index b15d644..5773695 100644 --- a/alias.sql +++ b/alias.sql @@ -18,6 +18,7 @@ insert into alias (nom, cmd, argc, help) values ('help', 'select help from alias insert into alias (nom, cmd, argc, help) values ('print', 'select cmd,inf from alias where nom=$1 and argc=$2;', 2, 'print SQL command of an alias (...)'); insert into alias (nom, cmd, argc, inf, help) values ('default', 'INSERT INTO raw (date, texte) VALUES ($1::timestamp, $2::text);', 2 , '1', 'default command'); insert into alias (nom, cmd, argc, inf, help) values ('aliasadd', 'insert into alias (nom, argc, cmd) values ( $1, $2, $3 );', 3, '1', 'add alias (with form : aliasadd "name" "argc" "SQL")'); -insert into alias (nom, cmd, argc, help) values ('getpass', 'select username,password from credential where service=$1;', 1, 'command to retrieve username and password with a service name (perhaps more than one)'); -insert into alias (nom, cmd, argc, help) values ('getpass', 'select distinct service from credential;', 0, 'get a list of service you have credential for'); +insert into alias (nom, cmd, argc, help) values ('get', 'select service,password from credential where username=$1;', 1, 'command to retrieve service and password with a user name (perhaps more than one)'); +insert into alias (nom, cmd, argc, help) values ('get', 'select distinct service from credential;', 0, 'get a list of service you have credential for'); insert into alias (nom, cmd, argc, help) values ('getpass', 'select password from credential where service=$1 and username=$2;', 2, 'retrieve one saved password (as service and user has unique constraint)'); + diff --git a/howto-compile.sh b/howto-compile.sh index fdb115c..9b6cea1 100755 --- a/howto-compile.sh +++ b/howto-compile.sh @@ -1,2 +1,2 @@ rm diary-shell -g++ main.cpp sqldb.cpp -o diary-shell -L /usr/lib -I .. -I/usr/include/postgresql -lpq -fpermissive +g++ main.cpp sqldb.cpp -o diary-shell -L /usr/lib -I .. -I/usr/include/postgresql -lpq -fpermissive -lcrypto -lssl diff --git a/main.cpp b/main.cpp index e8bc072..92c64b6 100644 --- a/main.cpp +++ b/main.cpp @@ -42,7 +42,8 @@ do{ if(words.size()==0)break;//quit else if (words[0]=="p") diary.print(); else if (words[0]=="status") diary.status(); - else if (words[0]=="con") diary.printvar(); + else if (words[0]=="pv") diary.printvar(); + else if ((words[0]=="connect")&&(words.size()==3)) diary.connect(words[1], words[2]); else if (words[0]=="!") { string a=rep.substr(2); diary.exec(a); diff --git a/sqldb.cpp b/sqldb.cpp index b69dbad..922bde0 100644 --- a/sqldb.cpp +++ b/sqldb.cpp @@ -11,16 +11,23 @@ using namespace std; sqlpg::sqlpg() { + /* Load the human readable error strings for libcrypto */ + ERR_load_crypto_strings(); + /* Load all digest and cipher algorithms */ + OpenSSL_add_all_algorithms(); + /* Load config file, and other important initialisation */ + OPENSSL_config(NULL); + EVP_PKEY *EVP_PKEY_new(void); - //connect = "host=postgresql1.alwaysdata.com port=5432 dbname=nothing2do.eu_diary user=nothing2do.eu password=x connect_timeout=10"; + //strconnect = "host=postgresql1.alwaysdata.com port=5432 dbname=nothing2do.eu_diary user=nothing2do.eu password=x connect_timeout=10"; strconnect = "dbname=bob user=bob password=pass connect_timeout=10"; //conn = PQconnectStart(var.c_str()); conn = PQconnectdb(strconnect.c_str()); clog<<"prepare SQL statement\n"; string cmd="select cmd,argc,inf from alias where ((nom = $1) and (argc = $2)) OR ((nom = $1) and (inf<>0) and (argc < $2));"; clog<<"SQL selectalias="<commande : "<commande : "<