37 #include <sys/types.h>
46 using std::ostringstream;
61 #if defined HAVE_OPENSSL && defined NOTTHERE
62 #include "SSLServer.h"
65 #define PPT_SERVER_DEFAULT_TIMEOUT 1
72 string err(
"Null handler passed to PPTServer");
76 string err(
"Null listener passed to PPTServer");
79 #if !defined HAVE_OPENSSL && defined NOTTHERE
82 string err(
"Server requested to be secure but OpenSSL is not built in");
97 void PPTServer::get_secure_files()
101 if (!found || _cfile.empty()) {
102 string err =
"Unable to determine server certificate file.";
108 if (!found || _cafile.empty()) {
109 string err =
"Unable to determine server certificate authority file.";
115 if (!found || _kfile.empty()) {
116 string err =
"Unable to determine server key file.";
123 if (!found || portstr.empty()) {
124 string err =
"Unable to determine secure connection port.";
127 _securePort = atoi(portstr.c_str());
129 string err = (string)
"Unable to determine secure connection port " +
"from string " + portstr;
146 BESDEBUG(
"ppt2",
"PPTServer::initConnection() - Calling welcomeClient()" << endl);
147 if (welcomeClient() != -1) {
163 BESDEBUG(
"ppt2",
"PPTServer::initConnection() - allowConnection() is FALSE! Closing Socket. " << endl);
174 int PPTServer::welcomeClient()
176 const unsigned int ppt_buffer_size = 64;
177 char inBuff[ppt_buffer_size + 1];
192 int bytesRead =
readBuffer(inBuff, ppt_buffer_size);
194 BESDEBUG(
"ppt2",
"In welcomeClient; bytesRead: " << bytesRead << endl);
197 if (bytesRead == -1) {
202 string status(inBuff, bytesRead);
210 string err =
"PPT cannot negotiate, client started the connection with " + status;
212 BESDEBUG(
"ppt",
"Sent '" << err <<
"' to PPT client." << endl);
229 authenticateClient();
235 void PPTServer::authenticateClient()
237 #if defined HAVE_OPENSSL && defined NOTTHERE
238 BESDEBUG(
"ppt",
"requiring secure connection: port = " << _securePort << endl );
245 const unsigned int ppt_buffer_size = 64;
247 char inBuff[ppt_buffer_size];
249 string portRequest( inBuff, bytesRead );
252 throw BESInternalError(
string(
"Secure connection ... expecting request for port client requested ") + portRequest, __FILE__, __LINE__ );
255 ostringstream portResponse;
257 send( portResponse.str() );
260 SSLServer server( _securePort, _cfile, _cafile, _kfile );
261 server.initConnection();
262 server.closeConnection();
267 throw BESInternalError(
"Authentication requested for this server but OpenSSL is not built into the server", __FILE__, __LINE__);
279 strm <<
BESIndent::LMarg <<
"PPTServer::dump - (" << (
void *)
this <<
")" << endl;
284 _handler->
dump(strm);
293 _listener->
dump(strm);
static string PPTCLIENT_REQUEST_AUTHPORT
exception thrown if inernal error encountered
static string PPT_COMPLETE_DATA_TRANSMITION
static string PPTCLIENT_TESTING_CONNECTION
virtual bool allowConnection()=0
#define PPT_SERVER_DEFAULT_TIMEOUT
error thrown if there is a user syntax error in the request or any other user error ...
static string PPTSERVER_AUTHENTICATE
virtual void initConnection()
Using the info passed into the SocketLister, wait for an inbound request (see SocketListener::accept(...
PPTServer(ServerHandler *handler, SocketListener *listener, bool isSecure)
virtual void closeConnection()
virtual void handle(Connection *c)=0
virtual Socket * accept()
Use the select() system call to wait for an incoming connection.
static ostream & LMarg(ostream &strm)
virtual int readBuffer(char *inBuff, const unsigned int buff_size)
read a buffer of data from the socket
virtual int receive(char *inBuff, const int inSize)
virtual void dump(ostream &strm) const
dumps information about this object
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 =0
dump the contents of this object to the specified ostream
virtual void dump(ostream &strm) const
dumps information about this object
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
static BESKeys * TheKeys()
virtual void send(const string &buffer)
sends the buffer to the socket
static string PPTSERVER_CONNECTION_OK
virtual void dump(ostream &strm) const
dumps information about this object