|
|
|
|
@@ -21,6 +21,83 @@ void handleClient(Block<String> &commands); // handler for client mode
|
|
|
|
|
bool registerSignalHandler(void); // registers a Control-c handler
|
|
|
|
|
void signalHandler(int signal); // The Control-C handler
|
|
|
|
|
|
|
|
|
|
class SSTP;
|
|
|
|
|
|
|
|
|
|
SmartPointer<SSTP> sstp;
|
|
|
|
|
|
|
|
|
|
class SSTP
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SSTP();
|
|
|
|
|
~SSTP();
|
|
|
|
|
void handleServer(Block<String>& arguments);
|
|
|
|
|
void handleClient(Block<String>& arguments);
|
|
|
|
|
private:
|
|
|
|
|
SmartPointer<SocketServer> mSocketServer;
|
|
|
|
|
SmartPointer<ClientSocketSender> mClientSocketSender;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
SSTP::SSTP()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
SSTP::~SSTP()
|
|
|
|
|
{
|
|
|
|
|
mSocketServer.destroy();
|
|
|
|
|
mClientSocketSender.destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// @brief [0]=program [1]=SERVERMODE [2]={port}
|
|
|
|
|
/// @Note Currently this method will never return. The application is terminate with CTRL-C. Ideally, we would exit is some cleaner fashion
|
|
|
|
|
/// perhaps by implementing a CTRL-C hook and then destroying the SocketServer properly by calling it's destructor. See SocketServer::~SocketServer()
|
|
|
|
|
/// @param commands
|
|
|
|
|
inline
|
|
|
|
|
void SSTP::handleServer(Block<String>& commands)
|
|
|
|
|
{
|
|
|
|
|
Profiler profiler;
|
|
|
|
|
|
|
|
|
|
if(commands.size()!=3)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Missing required parameters" << std::endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int port = commands[2].toInt();
|
|
|
|
|
std::cout << commands[1] << ":" << commands[2] << std::endl;
|
|
|
|
|
SocketServer socketServer(commands[2].toInt());
|
|
|
|
|
socketServer.listen();
|
|
|
|
|
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// @brief [0]=program, [1]=CLIENTMODE, [2]=serveripaddress, [3]=serverport, [4]=pathfilename
|
|
|
|
|
/// @param commands
|
|
|
|
|
inline
|
|
|
|
|
void SSTP::handleClient(Block<String>& arguments)
|
|
|
|
|
{
|
|
|
|
|
Profiler profiler;
|
|
|
|
|
if(arguments.size()!=5)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Missing required parameters" << std::endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mClientSocketSender.destroy();
|
|
|
|
|
mClientSocketSender = new ClientSocketSender(arguments[2],arguments[3].toInt());
|
|
|
|
|
bool returnCode = mClientSocketSender->sendFile(arguments[4]);
|
|
|
|
|
if(!returnCode)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "The transfer failed." << std::endl;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Transfer complete" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ****************************************************************************************************************************************************************
|
|
|
|
|
|
|
|
|
|
/// @brief
|
|
|
|
|
/// @param argc
|
|
|
|
|
/// @param argv [0] program. [1] SERVERMODE {port} [2] CLIENTMODE {serveripaddress} {serverport} SEND {FileName}
|
|
|
|
|
@@ -52,15 +129,18 @@ int main(int argc, char **argv)
|
|
|
|
|
String item(argv[index]);
|
|
|
|
|
arguments.insert(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sstp=::new SSTP();
|
|
|
|
|
sstp.disposition(PointerDisposition::Delete);
|
|
|
|
|
std::cout << argv[1] << std::endl;
|
|
|
|
|
if(arguments[1]=="SERVERMODE")
|
|
|
|
|
{
|
|
|
|
|
handleServer(arguments);
|
|
|
|
|
sstp->handleServer(arguments);
|
|
|
|
|
// handleServer(arguments);
|
|
|
|
|
}
|
|
|
|
|
else if(arguments[1]=="CLIENTMODE")
|
|
|
|
|
{
|
|
|
|
|
handleClient(arguments);
|
|
|
|
|
sstp->handleClient(arguments);
|
|
|
|
|
// handleClient(arguments);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
@@ -89,6 +169,7 @@ int main(int argc, char **argv)
|
|
|
|
|
void signalHandler(int signal)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "SSTP Received signal " << signal << std::endl;
|
|
|
|
|
if(sstp.isOkay())sstp.destroy();
|
|
|
|
|
exit(signal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -109,47 +190,46 @@ bool registerSignalHandler(void)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief [0]=program [1]=SERVERMODE [2]={port}
|
|
|
|
|
/// @Note Currently this method will never return. The application is terminate with CTRL-C. Ideally, we would exit is some cleaner fashion
|
|
|
|
|
/// perhaps by implementing a CTRL-C hook and then destroying the SocketServer properly by calling it's destructor. See SocketServer::~SocketServer()
|
|
|
|
|
/// @param commands
|
|
|
|
|
void handleServer(Block<String> &commands)
|
|
|
|
|
{
|
|
|
|
|
Profiler profiler;
|
|
|
|
|
// void handleServer(Block<String> &commands)
|
|
|
|
|
// {
|
|
|
|
|
// Profiler profiler;
|
|
|
|
|
|
|
|
|
|
if(commands.size()!=3)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Missing required parameters" << std::endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int port = commands[2].toInt();
|
|
|
|
|
std::cout << commands[1] << ":" << commands[2] << std::endl;
|
|
|
|
|
SocketServer socketServer(commands[2].toInt());
|
|
|
|
|
socketServer.listen();
|
|
|
|
|
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
// if(commands.size()!=3)
|
|
|
|
|
// {
|
|
|
|
|
// std::cout << "Missing required parameters" << std::endl;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// int port = commands[2].toInt();
|
|
|
|
|
// std::cout << commands[1] << ":" << commands[2] << std::endl;
|
|
|
|
|
// SocketServer socketServer(commands[2].toInt());
|
|
|
|
|
// socketServer.listen();
|
|
|
|
|
// std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/// @brief [0]=program, [1]=CLIENTMODE, [2]=serveripaddress, [3]=serverport, [4]=pathfilename
|
|
|
|
|
/// @param commands
|
|
|
|
|
void handleClient(Block<String> &commands)
|
|
|
|
|
{
|
|
|
|
|
Profiler profiler;
|
|
|
|
|
if(commands.size()!=5)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Missing required parameters" << std::endl;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// void handleClient(Block<String> &commands)
|
|
|
|
|
// {
|
|
|
|
|
// Profiler profiler;
|
|
|
|
|
// if(commands.size()!=5)
|
|
|
|
|
// {
|
|
|
|
|
// std::cout << "Missing required parameters" << std::endl;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
ClientSocketSender clientSocketSender(commands[2],commands[3].toInt());
|
|
|
|
|
bool returnCode = clientSocketSender.sendFile(commands[4]);
|
|
|
|
|
if(!returnCode)
|
|
|
|
|
{
|
|
|
|
|
std::cout << "The transfer failed." << std::endl;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::cout << "Transfer complete" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
|
|
|
|
}
|
|
|
|
|
// ClientSocketSender clientSocketSender(commands[2],commands[3].toInt());
|
|
|
|
|
// bool returnCode = clientSocketSender.sendFile(commands[4]);
|
|
|
|
|
// if(!returnCode)
|
|
|
|
|
// {
|
|
|
|
|
// std::cout << "The transfer failed." << std::endl;
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
// std::cout << "Transfer complete" << std::endl;
|
|
|
|
|
// }
|
|
|
|
|
// std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
|
|
|
|
// }
|
|
|
|
|
|