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)');
-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', '')
#include <sys/types.h>
#include <stdlib.h>
#include <cstring>
+#include "SSL.hpp"
using namespace std;
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;
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;
};
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