41using std::ostringstream ;
46#include "UnixSocket.h"
47#include "PPTProtocolNames.h"
48#include "BESInternalError.h"
49#include "BESSyntaxUserError.h"
50#include "TheBESKeys.h"
53#if defined HAVE_OPENSSL && defined NOTTHERE
57PPTClient::PPTClient(
const string &hostStr,
int portVal,
int timeout )
64 _mySock =
new TcpSocket( hostStr, portVal ) ;
66 _connected = _mySock->isConnected();
69PPTClient::PPTClient(
const string &unix_socket,
int timeout )
80PPTClient::get_secure_files()
84 if( !found || _cfile.empty() )
86 string err =
"Unable to determine client certificate file." ;
92 if( !found || _cafile.empty() )
94 string err =
"Unable to determine client certificate authority file." ;
100 if( !found || _kfile.empty() )
102 string err =
"Unable to determine client key file." ;
107PPTClient::~PPTClient()
121PPTClient::initConnection()
125 send(PPT_CLIENT_TESTING_CONNECTION ) ;
129 string msg =
"Failed to initialize connection to server\n" ;
136 const int ppt_buffer_size = 64 ;
137 char *inBuff =
new char[ppt_buffer_size+1] ;
142 string err =
"Could not connect to server, server may be down or busy" ;
146 if( bytesRead > ppt_buffer_size )
147 bytesRead = ppt_buffer_size ;
148 inBuff[bytesRead] =
'\0' ;
149 string status( inBuff, 0, bytesRead ) ;
152 if( status == PPT_PROTOCOL_UNDEFINED )
154 string err =
"Could not connect to server, server may be down or busy" ;
158 if(status == PPT_SERVER_AUTHENTICATE )
160 authenticateWithServer() ;
162 else if(status != PPT_SERVER_CONNECTION_OK )
164 string err =
"Server reported an invalid connection, \""
171PPTClient::authenticateWithServer()
173#if defined HAVE_OPENSSL && defined NOTTHERE
178 send(PPT_CLIENT_REQUEST_AUTHPORT ) ;
183 const int ppt_buffer_size = 64 ;
184 char *inBuff =
new char[ppt_buffer_size+1] ;
189 string err =
"Expecting secure port number response" ;
193 if( bytesRead > ppt_buffer_size )
195 bytesRead = ppt_buffer_size ;
197 inBuff[bytesRead] =
'\0' ;
198 ostringstream portResponse( inBuff ) ;
201 int portVal = atoi( portResponse.str().c_str() ) ;
204 string err =
"Expecting valid secure port number response" ;
209 SSLClient client( _host, portVal, _cfile, _cafile, _kfile ) ;
210 client.initConnection() ;
211 client.closeConnection() ;
216 throw BESInternalError(
"Server has requested authentication, but OpenSSL is not built into this client", __FILE__, __LINE__ ) ;
221PPTClient::closeConnection()
233 cerr <<
"Failed to inform server that the client is exiting, "
234 <<
"continuing" << endl ;
242 _brokenPipe = false ;
255 strm << BESIndent::LMarg <<
"PPTClient::dump - ("
256 << (
void *)
this <<
")" << endl ;
257 BESIndent::Indent() ;
258 strm << BESIndent::LMarg <<
"connected? " << _connected << endl ;
259 strm << BESIndent::LMarg <<
"host: " << _host << endl ;
261 BESIndent::UnIndent() ;
std::string get_message() const
get the error message for this exception
exception thrown if internal error encountered
error thrown if there is a user syntax error in the request or any other user error
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void sendExit()
Send the exit token as an extension.
virtual void send(const std::string &buffer)
sends the buffer to the socket
virtual int readBufferNonBlocking(char *inBuff, const int buff_size)
read a buffer of data from the socket without blocking
virtual void dump(std::ostream &strm) const
dumps information about this object
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()