2014-06-14 17:02:50 +00:00
|
|
|
#include "qtsslsocket.h"
|
|
|
|
|
2014-06-18 23:44:46 +00:00
|
|
|
|
|
|
|
bool qtsslsocket::makeConnect(std::string server,int port)
|
|
|
|
{
|
|
|
|
if (this->socket != NULL) //already connected?
|
|
|
|
{
|
|
|
|
socket->close();
|
|
|
|
socket = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->socket == NULL) //if was connected, we deleted it and remake it
|
|
|
|
socket = new QSslSocket();
|
|
|
|
|
|
|
|
|
|
|
|
if (this->socket != NULL) //now we will connect it to host
|
|
|
|
{
|
|
|
|
socket->connectToHostEncrypted(server.c_str(), port);
|
|
|
|
if (socket->waitForEncrypted()) //waiting for encryption
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isCon(); //return true/false upon isCon function
|
|
|
|
}
|
|
|
|
|
|
|
|
qtsslsocket::qtsslsocket() : flag(false)
|
2014-06-14 17:02:50 +00:00
|
|
|
{
|
|
|
|
socket = new QSslSocket();
|
2014-06-18 23:44:46 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 17:02:50 +00:00
|
|
|
|
2014-06-18 23:44:46 +00:00
|
|
|
qtsslsocket::~qtsslsocket() {
|
|
|
|
socket->close();
|
|
|
|
socket = NULL;
|
2014-06-14 17:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool qtsslsocket::isCon()
|
|
|
|
{
|
2014-06-18 23:44:46 +00:00
|
|
|
return ((flag) && (this->socket != NULL));
|
2014-06-14 17:02:50 +00:00
|
|
|
|
|
|
|
}
|
2014-06-18 23:44:46 +00:00
|
|
|
//need to fix the method
|
2014-06-14 17:02:50 +00:00
|
|
|
bool qtsslsocket::send(std::string str)
|
|
|
|
{
|
2014-06-18 23:44:46 +00:00
|
|
|
int status;
|
2014-06-18 18:42:46 +00:00
|
|
|
bool flag = isCon();
|
2014-06-18 23:44:46 +00:00
|
|
|
if (flag) //if connected
|
|
|
|
{
|
|
|
|
status = socket->write(str.c_str(),str.length());
|
|
|
|
while (socket->waitForBytesWritten());
|
|
|
|
}
|
2014-06-14 17:02:50 +00:00
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
bool qtsslsocket::recieve(std::string &str)
|
|
|
|
{
|
|
|
|
bool flag = false;
|
|
|
|
QString s = "";
|
|
|
|
while (socket->waitForReadyRead(milisTimeOut))
|
2014-06-18 23:44:46 +00:00
|
|
|
s.append(socket->readAll());
|
|
|
|
|
2014-06-14 17:02:50 +00:00
|
|
|
str = s.toStdString();
|
|
|
|
if (s.size() > 0)
|
|
|
|
flag = true;
|
2014-06-18 23:44:46 +00:00
|
|
|
|
2014-06-14 17:02:50 +00:00
|
|
|
return flag;
|
|
|
|
}
|