|
|
@@ -1,4 +1,4 @@
|
|
|
-#define INCLUDE_SSL
|
|
|
+#define INCLUDE_SSL
|
|
|
#include "Client.h"
|
|
|
|
|
|
#ifndef WIN32
|
|
|
@@ -6,7 +6,7 @@
|
|
|
# include <string.h>
|
|
|
# include <sys/select.h>
|
|
|
#endif
|
|
|
-#include <Datei.h>
|
|
|
+#include <File.h>
|
|
|
#include <Key.h>
|
|
|
#include <Logging.h>
|
|
|
|
|
|
@@ -42,8 +42,7 @@ void Client::setSendKeyZ(Encryption::Key* key) // Sets the key for sending
|
|
|
sendKey = key;
|
|
|
}
|
|
|
|
|
|
-void Client::setReceiveKeyZ(
|
|
|
- Encryption::Key* key) // Sets the key for receiving
|
|
|
+void Client::setReceiveKeyZ(Encryption::Key* key) // Sets the key for receiving
|
|
|
{
|
|
|
if (receiveKey) receiveKey->release();
|
|
|
receiveKey = key;
|
|
|
@@ -62,8 +61,7 @@ void Client::setReceiveKey(
|
|
|
receiveKey->setKey(key, len);
|
|
|
}
|
|
|
|
|
|
-bool Client::connect(
|
|
|
- unsigned short port, const char* ip) // connects to server
|
|
|
+bool Client::connect(unsigned short port, const char* ip) // connects to server
|
|
|
{
|
|
|
if (sendKey) sendKey->setPos(0);
|
|
|
if (receiveKey) receiveKey->setPos(0);
|
|
|
@@ -78,7 +76,7 @@ bool Client::connect(
|
|
|
}
|
|
|
memcpy((char*)&server.sin_addr, &sIp, sizeof(sIp));
|
|
|
server.sin_port = htons(port); // port
|
|
|
- if (connect(sock, (struct sockaddr*)&server, sizeof(server))
|
|
|
+ if (::connect(sock, (struct sockaddr*)&server, sizeof(server))
|
|
|
< 0) // connect
|
|
|
{
|
|
|
errorOccured = 1;
|
|
|
@@ -94,9 +92,9 @@ bool Client::send(const char* message, int len) // sends to server
|
|
|
while (len > 0)
|
|
|
{
|
|
|
#ifdef WIN32
|
|
|
- int l = send(sock, message + ll, len, 0);
|
|
|
+ int l = ::send(sock, message + ll, len, 0);
|
|
|
#else
|
|
|
- int l = (int)send(sock, message + ll, len, MSG_NOSIGNAL);
|
|
|
+ int l = (int)::send(sock, message + ll, len, MSG_NOSIGNAL);
|
|
|
#endif
|
|
|
if (l <= 0)
|
|
|
{
|
|
|
@@ -144,15 +142,14 @@ bool Client::sendEncrypted(const char* message, int len) // sends to server
|
|
|
{
|
|
|
if (!sendKey) return send(message, len);
|
|
|
Encryption::Bytes* n = new Encryption::Bytes(message, len);
|
|
|
- sendKey->codieren(
|
|
|
- dynamic_cast<Framework::Encryption::Bytes*>(n->getThis()));
|
|
|
+ sendKey->encode(dynamic_cast<Framework::Encryption::Bytes*>(n->getThis()));
|
|
|
int ll = 0;
|
|
|
while (len > 0)
|
|
|
{
|
|
|
#ifdef WIN32
|
|
|
- int l = send(sock, n->getBytes() + ll, len, 0);
|
|
|
+ int l = ::send(sock, n->getBytes() + ll, len, 0);
|
|
|
#else
|
|
|
- int l = (int)send(sock, n->getBytes() + ll, len, MSG_NOSIGNAL);
|
|
|
+ int l = (int)::send(sock, n->getBytes() + ll, len, MSG_NOSIGNAL);
|
|
|
#endif
|
|
|
if (l <= 0)
|
|
|
{
|
|
|
@@ -174,8 +171,7 @@ bool Client::sendEncrypted(const char* message, int len) // sends to server
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-bool Client::getMessageEncrypted(
|
|
|
- char* message, int len) // receives message
|
|
|
+bool Client::getMessageEncrypted(char* message, int len) // receives message
|
|
|
{
|
|
|
if (!receiveKey) return getMessage(message, len);
|
|
|
int ll = 0;
|
|
|
@@ -198,21 +194,19 @@ bool Client::getMessageEncrypted(
|
|
|
}
|
|
|
Encryption::Bytes* n = new Encryption::Bytes();
|
|
|
n->setBytesZ(message, ll);
|
|
|
- receiveKey->decodieren(n);
|
|
|
+ receiveKey->decode(n);
|
|
|
downStreamBytes += ll;
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-int Client::getDownloadBytes(
|
|
|
- bool reset) // returns the number of received bytes
|
|
|
+int Client::getDownloadBytes(bool reset) // returns the number of received bytes
|
|
|
{
|
|
|
int ret = downStreamBytes;
|
|
|
if (reset) downStreamBytes = 0;
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-int Client::getUploadBytes(
|
|
|
- bool reset) // returns the number of sent bytes
|
|
|
+int Client::getUploadBytes(bool reset) // returns the number of sent bytes
|
|
|
{
|
|
|
int ret = upStreamBytes;
|
|
|
if (reset) upStreamBytes = 0;
|
|
|
@@ -234,12 +228,12 @@ bool Client::disconnect() // Disconnects from server
|
|
|
}
|
|
|
|
|
|
// constant
|
|
|
-bool Client::hasMessage(int time) // Waits for a message for a given time
|
|
|
+bool Client::hasMessage(int waitTime) // Waits for a message for a given time
|
|
|
{
|
|
|
fd_set set;
|
|
|
FD_ZERO(&set);
|
|
|
FD_SET(sock, &set);
|
|
|
- timeval time = {time / 1000, time};
|
|
|
+ timeval time = {waitTime / 1000, waitTime};
|
|
|
int result = select(0, &set, 0, 0, &time);
|
|
|
if (result < 0)
|
|
|
{
|
|
|
@@ -263,7 +257,8 @@ const char* Client::getServerIp() const // returns the IP
|
|
|
return inet_ntoa(server.sin_addr);
|
|
|
}
|
|
|
|
|
|
-bool Client::waitForNextMessage() const // waits until there is something to receive
|
|
|
+bool Client::waitForNextMessage()
|
|
|
+ const // waits until there is something to receive
|
|
|
{
|
|
|
fd_set set;
|
|
|
int rv = 0;
|
|
|
@@ -306,8 +301,7 @@ bool Client::waitForNextMessage() const // waits until there is something to rec
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-bool Client::isConnected()
|
|
|
- const // returns true if a connection exists
|
|
|
+bool Client::isConnected() const // returns true if a connection exists
|
|
|
{
|
|
|
return sock != 0 && !errorOccured;
|
|
|
}
|
|
|
@@ -407,8 +401,7 @@ int SSLClient::getDownloadBytes(
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
-int SSLClient::getUploadBytes(
|
|
|
- bool reset) // returns the number of sent bytes
|
|
|
+int SSLClient::getUploadBytes(bool reset) // returns the number of sent bytes
|
|
|
{
|
|
|
int ret = upStreamBytes;
|
|
|
if (reset) upStreamBytes = 0;
|
|
|
@@ -423,18 +416,16 @@ bool SSLClient::disconnect() // Disconnects from server
|
|
|
}
|
|
|
|
|
|
// constant
|
|
|
-bool SSLClient::hasMessage(
|
|
|
- int time) // Waits for a message for a given time
|
|
|
+bool SSLClient::hasMessage(int waitTime) // Waits for a message for a given time
|
|
|
{
|
|
|
fd_set set;
|
|
|
FD_ZERO(&set);
|
|
|
FD_SET(SSL_get_rfd(ssl), &set);
|
|
|
- timeval time = {time / 1000, time};
|
|
|
+ timeval time = {waitTime / 1000, waitTime};
|
|
|
return SSL_pending(ssl) > 0 || select(0, &set, 0, 0, &time) == 1;
|
|
|
}
|
|
|
|
|
|
-unsigned short
|
|
|
-SSLClient::getServerPort() const // returns the server port
|
|
|
+unsigned short SSLClient::getServerPort() const // returns the server port
|
|
|
{
|
|
|
return port;
|
|
|
}
|