41 using std::ostringstream ;
43 #include "PPTClient.h" 44 #include "TcpSocket.h" 45 #include "UnixSocket.h" 46 #include "PPTProtocol.h" 47 #include "BESInternalError.h" 48 #include "BESSyntaxUserError.h" 49 #include "TheBESKeys.h" 52 #if defined HAVE_OPENSSL && defined NOTTHERE 53 #include "SSLClient.h" 56 PPTClient::PPTClient(
const string &hostStr,
int portVal,
int timeout )
63 _mySock =
new TcpSocket( hostStr, portVal ) ;
65 _connected = _mySock->isConnected();
68 PPTClient::PPTClient(
const string &unix_socket,
int timeout )
79 PPTClient::get_secure_files()
83 if( !found || _cfile.empty() )
85 string err =
"Unable to determine client certificate file." ;
91 if( !found || _cafile.empty() )
93 string err =
"Unable to determine client certificate authority file." ;
99 if( !found || _kfile.empty() )
101 string err =
"Unable to determine client key file." ;
106 PPTClient::~PPTClient()
120 PPTClient::initConnection()
124 send( PPTProtocol::PPTCLIENT_TESTING_CONNECTION ) ;
128 string msg =
"Failed to initialize connection to server\n" ;
135 const int ppt_buffer_size = 64 ;
136 char *inBuff =
new char[ppt_buffer_size+1] ;
137 int bytesRead = readBufferNonBlocking( inBuff, ppt_buffer_size ) ;
141 string err =
"Could not connect to server, server may be down or busy" ;
145 if( bytesRead > ppt_buffer_size )
146 bytesRead = ppt_buffer_size ;
147 inBuff[bytesRead] =
'\0' ;
148 string status( inBuff, 0, bytesRead ) ;
151 if( status == PPTProtocol::PPT_PROTOCOL_UNDEFINED )
153 string err =
"Could not connect to server, server may be down or busy" ;
157 if( status == PPTProtocol::PPTSERVER_AUTHENTICATE )
159 authenticateWithServer() ;
161 else if( status != PPTProtocol::PPTSERVER_CONNECTION_OK )
163 string err =
"Server reported an invalid connection, \"" 170 PPTClient::authenticateWithServer()
172 #if defined HAVE_OPENSSL && defined NOTTHERE 177 send( PPTProtocol::PPTCLIENT_REQUEST_AUTHPORT ) ;
182 const int ppt_buffer_size = 64 ;
183 char *inBuff =
new char[ppt_buffer_size+1] ;
184 int bytesRead = readBufferNonBlocking( inBuff, ppt_buffer_size ) ;
188 string err =
"Expecting secure port number response" ;
192 if( bytesRead > ppt_buffer_size )
194 bytesRead = ppt_buffer_size ;
196 inBuff[bytesRead] =
'\0' ;
197 ostringstream portResponse( inBuff ) ;
200 int portVal = atoi( portResponse.str().c_str() ) ;
203 string err =
"Expecting valid secure port number response" ;
208 SSLClient client( _host, portVal, _cfile, _cafile, _kfile ) ;
209 client.initConnection() ;
210 client.closeConnection() ;
215 throw BESInternalError(
"Server has requested authentication, but OpenSSL is not built into this client", __FILE__, __LINE__ ) ;
220 PPTClient::closeConnection()
232 cerr <<
"Failed to inform server that the client is exiting, " 233 <<
"continuing" << endl ;
241 _brokenPipe = false ;
254 strm << BESIndent::LMarg <<
"PPTClient::dump - (" 255 << (
void *)
this <<
")" << endl ;
256 BESIndent::Indent() ;
257 strm << BESIndent::LMarg <<
"connected? " << _connected << endl ;
258 strm << BESIndent::LMarg <<
"host: " << _host << endl ;
260 BESIndent::UnIndent() ;
exception thrown if inernal error encountered
virtual std::string get_message()
get the error message for this exception
error thrown if there is a user syntax error in the request or any other user error ...
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
virtual void dump(ostream &strm) const
dumps information about this object
virtual void dump(ostream &strm) const
dumps information about this object
static BESKeys * TheKeys()