]> git.nothing2do.fr Git - diary-shell/commitdiff
I've added some alias (getconninfo, ...) and I try to delete all sql command from...
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Thu, 8 Aug 2013 15:33:49 +0000 (17:33 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Thu, 8 Aug 2013 15:33:49 +0000 (17:33 +0200)
alias.sql
credential.sql
service.sql
sqldb.cpp

index eefc811b74eeca272d2e96cff938283712597d98..77f462470eff640bd65f99fdd689786adb5d6274 100644 (file)
--- a/alias.sql
+++ b/alias.sql
@@ -21,4 +21,5 @@ insert into alias (nom, cmd, argc, inf, help) values ('aliasadd', 'insert into a
 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)');
-insert into alias (nom, cmd, argc, help) values ('info', 'select date from raw where id=$1;', 1, 'retrieve date from a saved entry');
+insert into alias (nom, cmd, argc, help) values ('info', 'select date from raw where id=$1;', 1, 'retrieve date by ID');
+insert into alias (nom, cmd, argc, help) values ('getconninfo', 'select server,port,proto from service where name=$1;', 1, 'retrieve conninfo (server, port and proto)');
index a0fbb539cd1461388f0b0f19729c1e73a44ef36f..b2f86170a7cb0c5de12f5a4d7ba3e365842590b9 100644 (file)
@@ -1 +1 @@
-insert into credential (service, username, password) values ('pop', 'me', 'pass');
+insert into credential (service, username, password) values ('pop', 'user', 'pass');
index f8867ad7a66aaafa416f004c60fc5a9031a8a62f..48634ddb7f4fe27de1c1f2522658f0890ce0e2e1 100644 (file)
@@ -1 +1,2 @@
-insert into service (name, proto, port, server, cmd) values ('gmail', 'https', 443, 'www.gmail.com', '...');
+insert into service (name, port, server, cmd) values ('yahoo.fr', 993, 'imap.mail.yahoo.com', 'login $1@$2')
+insert into service (name, port, server, cmd) values ('yahoo.fr', 993, 'imap.mail.yahoo.com', '')
index 2b9b93b54b8ef1b474ecddb6c68916a9e7f17b30..312b80ef4d4aa8fb50c900cb1274c2a619ac8766 100644 (file)
--- a/sqldb.cpp
+++ b/sqldb.cpp
@@ -7,6 +7,7 @@
 #include <sys/types.h>
 #include <stdlib.h>
 #include <cstring>
+#include "SSL.hpp"
 
 using namespace std;
 
@@ -243,7 +244,7 @@ bool sqlpg::alias(vector<string> a){
     res=PQexecPrepared(conn, "selectalias", argca, valuea, lengtha, binarya, 0);
     testSQL(res);
     if (PQntuples(res)!=1){
-        cerr<<"alias end more than one alias found ! (pqntuples(res)="<<PQntuples(res)<<")\n";
+        cerr<<"alias end, more (or less) than one alias found ! (pqntuples(res)="<<PQntuples(res)<<")\n";
         return 0;
     }
     string cmd2;
@@ -291,7 +292,6 @@ bool sqlpg::alias(vector<string> a){
     res=PQexecPrepared(conn, "execalias", argc, value, length, binary, 0);
     clog<<"PQexecPrepared done.\n";
     testSQL(res);
-    //print();
     exec("DEALLOCATE execalias");
     clog<<"alias() end here\n";
     return 1;
@@ -345,35 +345,29 @@ void sqlpg::getvar(){
 };
 void sqlpg::connect(string service, string name){//I mean "username" but i'm affraid that the string "username" get caught by pgsql ...
     clog<<"connect start here\n";
-    string nom="getpass", as=toString(2), i;
-    int argca=2;//it won't work if I use argca in place of 2 :-(
-    bool inf=0;
-    const char *valuea[2]={nom.c_str(), as.c_str()};
-    int lengtha[2]={nom.size(), as.size()};
-    int binarya[2]={0, 0};
-    res=PQexecPrepared(conn, "selectalias", argca, valuea, lengtha, binarya, 0);
-    testSQL(res);
-    if (PQntuples(res)!=1){
-        cerr<<"getpass ! (pqntuples(res)="<<PQntuples(res)<<")\n";
-        return;
-    }
-    string cmd2;
-    cmd2=PQgetvalue(res, 0, 0);
-    clog<<"connect()|getpass->commande : "<<cmd2<<endl;
-    testSQL(PQprepare(conn, "getpass", cmd2.c_str(), 2, NULL));
-    const char * value[2];
-    int length[2];
-    int binary[2];
-    value[0]=service.c_str();
-    length[0]=service.size();
-    binary[0]=0;
-    value[1]=name.c_str();
-    length[1]=name.size();
-    binary[1]=0;
-    res=PQexecPrepared(conn, "getpass", 2, value, length, binary, 0);
-    testSQL(res);
+    vector<string> tmp;
+    tmp.push_back("getpass");
+    tmp.push_back(service);
+    tmp.push_back(name);
+    alias(tmp);
     string pass=PQgetvalue(res, 0, PQfnumber(res, "password"));
-    clog<<"service="<<service<<" user="<<name<<" pass="<<pass<<endl;
+    //I'll get server and port (from service)
+    tmp.clear();
+    tmp.push_back("getconninfo");
+    tmp.push_back(service);
+    alias(tmp);
+    string server=PQgetvalue(res, 0, PQfnumber(res, "server"));
+    unsigned short int port=PQgetvalue(res, 0, PQfnumber(res, "port"));
+    string proto=PQgetvalue(res, 0, PQfnumber(res, "proto"));
+    clog<<"user="<<name<<" pass="<<pass<<" server="<<server<<" port="<<port<<" proto="<<proto;
+
+    //I'll open connection
+    connection a(server, port);
 
+    /*I've to send credential
+    a.write(user@server)
+    /I've to switch between proto possible value, and I'm bored to learn all protocol
+    a.read(const int)
+    /and to learn possible answer*/
 }
 #endif