X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Fdb%2Fpsql.cpp;h=053f11be95879646ae6a5093f90339a03e65687a;hb=bcc67d8ce710641222a9ec2d726fdbda42a81e45;hp=c2a282e4adf8347abe3c30c6cef3091dc495b37c;hpb=90a79f28e095c7e368971ee5408ba8a10e0043c9;p=cassiopeia.git diff --git a/src/db/psql.cpp b/src/db/psql.cpp index c2a282e..053f11b 100644 --- a/src/db/psql.cpp +++ b/src/db/psql.cpp @@ -5,6 +5,7 @@ #include #include +#include PostgresJobProvider::PostgresJobProvider( const std::string& server, const std::string& user, const std::string& password, const std::string& database ): c("dbname="+database+" host="+server+" user="+user+" password=" + password + " client_encoding=UTF-8 application_name=cassiopeia-client"){ @@ -43,7 +44,7 @@ void PostgresJobProvider::finishJob( std::shared_ptr job ) { pqxx::result r = txn.exec(q); if( r.affected_rows() != 1 ) { - throw "No database entry found."; + throw std::runtime_error("No database entry found."); } txn.commit(); } @@ -55,7 +56,7 @@ void PostgresJobProvider::failJob( std::shared_ptr job ) { pqxx::result r = txn.exec(q); if( r.affected_rows() != 1 ) { - throw "No database entry found."; + throw std::runtime_error("No database entry found."); } txn.commit(); } @@ -67,7 +68,7 @@ std::shared_ptr PostgresJobProvider::fetchTBSCert( std::shared_p pqxx::result r = txn.exec(q); if( r.size() != 1 ) { - throw "Error, no or multiple certs found"; + throw std::runtime_error("Error, no or multiple certs found"); } auto ro = r[0]; @@ -124,18 +125,21 @@ void PostgresJobProvider::writeBack( std::shared_ptr job, std::shared_ptr(); } std::string serial = res->serial; std::transform(serial.begin(), serial.end(), serial.begin(), ::tolower); + if(serial[0] == '0'){ + serial = serial.substr(1); + } std::string q = "UPDATE certs SET crt_name=" + txn.quote( res->crt_name ) + ", serial=" + txn.quote( serial ) + ", \"caid\" = " + txn.quote( read_id ) + ", created=" + txn.quote( pgTime(res->before) ) + ", expire=" + txn.quote( pgTime(res->after) ) + " WHERE id=" + txn.quote( job->target ); // TODO write more thingies back r = txn.exec( q ); if( r.affected_rows() != 1 ){ - throw "Only one row should be updated."; + throw std::runtime_error("Only one row should be updated."); } txn.commit(); } @@ -146,7 +150,7 @@ std::pair PostgresJobProvider::getRevocationInfo( std: pqxx::result r = txn.exec( q ); if( r.size() != 1) { - throw "Only one row expected but multiple found."; + throw std::runtime_error("Only one row expected but multiple found."); } @@ -154,14 +158,14 @@ std::pair PostgresJobProvider::getRevocationInfo( std: } void PostgresJobProvider::writeBackRevocation( std::shared_ptr job, std::string date ) { - logger::errorf( "Revoking at " + date); + logger::notef( "Revoking at %s", date); pqxx::work txn(c); - logger::errorf( "executing" ); + logger::note( "executing" ); pqxx::result r = txn.exec( "UPDATE certs SET revoked = " + txn.quote( pgTime( date ) ) + " WHERE id = " + txn.quote( job->target ) ); if( r.affected_rows() != 1 ){ - throw "Only one row should be updated."; + throw std::runtime_error("Only one row should be updated."); } - logger::errorf( "committing" ); + logger::note( "committing" ); txn.commit(); - logger::errorf( "committed" ); + logger::note( "committed" ); }