|
@@ -16,7 +16,7 @@ __declspec( dllexport ) Frame &Frame::operator+=( const Frame &b ) // baut frame
|
|
{
|
|
{
|
|
char *data = new char[ (int)dataLength ];
|
|
char *data = new char[ (int)dataLength ];
|
|
if( data )
|
|
if( data )
|
|
- memcpy( data, this->data, (int)(dataLength - b.dataLength) );
|
|
|
|
|
|
+ memcpy( data, this->data, (int)( dataLength - b.dataLength ) );
|
|
if( b.data )
|
|
if( b.data )
|
|
memcpy( data + dataLength, b.data, (int)b.dataLength );
|
|
memcpy( data + dataLength, b.data, (int)b.dataLength );
|
|
delete[] this->data;
|
|
delete[] this->data;
|
|
@@ -90,7 +90,7 @@ __declspec( dllexport ) bool WebSocketClient::connect()
|
|
klient = new Klient();
|
|
klient = new Klient();
|
|
if( !klient->verbinde( port, host ) )
|
|
if( !klient->verbinde( port, host ) )
|
|
{
|
|
{
|
|
- klient = klient->release();
|
|
|
|
|
|
+ klient = (Klient *)klient->release();
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
klient->sende( message, message.getLength() );
|
|
klient->sende( message, message.getLength() );
|
|
@@ -113,7 +113,7 @@ __declspec( dllexport ) bool WebSocketClient::connect()
|
|
if( handshakeResponse->getStatusCode() != 101 )
|
|
if( handshakeResponse->getStatusCode() != 101 )
|
|
{
|
|
{
|
|
handshakeResponse->release();
|
|
handshakeResponse->release();
|
|
- klient = klient->release();
|
|
|
|
|
|
+ klient = (Klient *)klient->release();
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
handshakeResponse->release();
|
|
handshakeResponse->release();
|
|
@@ -139,10 +139,10 @@ __declspec( dllexport ) bool WebSocketClient::send( __int64 size, const char *da
|
|
f.dataLength = size;
|
|
f.dataLength = size;
|
|
f.data = new char[ (int)f.dataLength ];
|
|
f.data = new char[ (int)f.dataLength ];
|
|
memcpy( f.data, data, (int)f.dataLength );
|
|
memcpy( f.data, data, (int)f.dataLength );
|
|
- f.key[ 0 ] = (unsigned char)(gen.rand() * 256);
|
|
|
|
- f.key[ 1 ] = (unsigned char)(gen.rand() * 256);
|
|
|
|
- f.key[ 2 ] = (unsigned char)(gen.rand() * 256);
|
|
|
|
- f.key[ 3 ] = (unsigned char)(gen.rand() * 256);
|
|
|
|
|
|
+ f.key[ 0 ] = (unsigned char)( gen.rand() * 256 );
|
|
|
|
+ f.key[ 1 ] = (unsigned char)( gen.rand() * 256 );
|
|
|
|
+ f.key[ 2 ] = (unsigned char)( gen.rand() * 256 );
|
|
|
|
+ f.key[ 3 ] = (unsigned char)( gen.rand() * 256 );
|
|
c.lock();
|
|
c.lock();
|
|
queue->add( f );
|
|
queue->add( f );
|
|
c.unlock();
|
|
c.unlock();
|
|
@@ -175,50 +175,50 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
Frame message;
|
|
Frame message;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.fin = ( byte & 0x80 ) != 0;
|
|
message.fin = ( byte & 0x80 ) != 0;
|
|
message.rsv1 = ( byte & 0x40 ) != 0;
|
|
message.rsv1 = ( byte & 0x40 ) != 0;
|
|
message.rsv2 = ( byte & 0x20 ) != 0;
|
|
message.rsv2 = ( byte & 0x20 ) != 0;
|
|
message.rsv3 = ( byte & 0x10 ) != 0;
|
|
message.rsv3 = ( byte & 0x10 ) != 0;
|
|
message.opcode = byte & 0xF;
|
|
message.opcode = byte & 0xF;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.mask = ( byte & 0x80 ) != 0;
|
|
message.mask = ( byte & 0x80 ) != 0;
|
|
message.dataLength = byte & 0x7F;
|
|
message.dataLength = byte & 0x7F;
|
|
if( message.dataLength == 126 )
|
|
if( message.dataLength == 126 )
|
|
{
|
|
{
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength = byte << 8;
|
|
message.dataLength = byte << 8;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength |= byte;
|
|
message.dataLength |= byte;
|
|
}
|
|
}
|
|
else if( message.dataLength == 127 )
|
|
else if( message.dataLength == 127 )
|
|
{
|
|
{
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength = (__int64)byte << 56;
|
|
message.dataLength = (__int64)byte << 56;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength |= (__int64)byte << 48;
|
|
message.dataLength |= (__int64)byte << 48;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength |= (__int64)byte << 40;
|
|
message.dataLength |= (__int64)byte << 40;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength |= (__int64)byte << 32;
|
|
message.dataLength |= (__int64)byte << 32;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength |= (__int64)byte << 24;
|
|
message.dataLength |= (__int64)byte << 24;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength |= (__int64)byte << 16;
|
|
message.dataLength |= (__int64)byte << 16;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength |= (__int64)byte << 8;
|
|
message.dataLength |= (__int64)byte << 8;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.dataLength |= (__int64)byte;
|
|
message.dataLength |= (__int64)byte;
|
|
}
|
|
}
|
|
if( message.mask )
|
|
if( message.mask )
|
|
{
|
|
{
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.key[ 0 ] = byte;
|
|
message.key[ 0 ] = byte;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.key[ 1 ] = byte;
|
|
message.key[ 1 ] = byte;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.key[ 2 ] = byte;
|
|
message.key[ 2 ] = byte;
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
message.key[ 3 ] = byte;
|
|
message.key[ 3 ] = byte;
|
|
}
|
|
}
|
|
if( !ok )
|
|
if( !ok )
|
|
@@ -228,7 +228,7 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
message.data = new char[ (int)message.dataLength ];
|
|
message.data = new char[ (int)message.dataLength ];
|
|
for( int i = 0; i < message.dataLength; i++ )
|
|
for( int i = 0; i < message.dataLength; i++ )
|
|
{
|
|
{
|
|
- ok &= klient->getNachricht( (char*)&byte, 1 );
|
|
|
|
|
|
+ ok &= klient->getNachricht( (char *)&byte, 1 );
|
|
if( message.mask )
|
|
if( message.mask )
|
|
message.data[ i ] = byte ^ message.key[ i % 4 ];
|
|
message.data[ i ] = byte ^ message.key[ i % 4 ];
|
|
else
|
|
else
|
|
@@ -271,7 +271,7 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
delete[] m.data;
|
|
delete[] m.data;
|
|
c2.lock();
|
|
c2.lock();
|
|
klient->trenne();
|
|
klient->trenne();
|
|
- klient = klient->release();
|
|
|
|
|
|
+ klient = (Klient *)klient->release();
|
|
c2.unlock();
|
|
c2.unlock();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -310,7 +310,7 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
c2.unlock();
|
|
c2.unlock();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = ( f.mask ? 1 : 0 ) << 7;
|
|
byte = ( f.mask ? 1 : 0 ) << 7;
|
|
if( f.dataLength < 126 )
|
|
if( f.dataLength < 126 )
|
|
byte |= (unsigned char)f.dataLength & 0x7F;
|
|
byte |= (unsigned char)f.dataLength & 0x7F;
|
|
@@ -318,46 +318,46 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
byte |= 126;
|
|
byte |= 126;
|
|
else
|
|
else
|
|
byte |= 127;
|
|
byte |= 127;
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
if( f.dataLength >= 126 )
|
|
if( f.dataLength >= 126 )
|
|
{
|
|
{
|
|
if( f.dataLength <= 32767 )
|
|
if( f.dataLength <= 32767 )
|
|
{
|
|
{
|
|
byte = (unsigned char)( f.dataLength >> 8 );
|
|
byte = (unsigned char)( f.dataLength >> 8 );
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)f.dataLength & 0xFF;
|
|
byte = (unsigned char)f.dataLength & 0xFF;
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
byte = (unsigned char)( f.dataLength >> 56 );
|
|
byte = (unsigned char)( f.dataLength >> 56 );
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)( f.dataLength >> 48 );
|
|
byte = (unsigned char)( f.dataLength >> 48 );
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)( f.dataLength >> 40 );
|
|
byte = (unsigned char)( f.dataLength >> 40 );
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)( f.dataLength >> 32 );
|
|
byte = (unsigned char)( f.dataLength >> 32 );
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)( f.dataLength >> 24 );
|
|
byte = (unsigned char)( f.dataLength >> 24 );
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)( f.dataLength >> 16 );
|
|
byte = (unsigned char)( f.dataLength >> 16 );
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)( f.dataLength >> 8 );
|
|
byte = (unsigned char)( f.dataLength >> 8 );
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)f.dataLength & 0xFF;
|
|
byte = (unsigned char)f.dataLength & 0xFF;
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if( f.mask )
|
|
if( f.mask )
|
|
{
|
|
{
|
|
byte = (unsigned char)f.key[ 0 ];
|
|
byte = (unsigned char)f.key[ 0 ];
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)f.key[ 1 ];
|
|
byte = (unsigned char)f.key[ 1 ];
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)f.key[ 2 ];
|
|
byte = (unsigned char)f.key[ 2 ];
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
byte = (unsigned char)f.key[ 3 ];
|
|
byte = (unsigned char)f.key[ 3 ];
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
}
|
|
}
|
|
if( f.dataLength )
|
|
if( f.dataLength )
|
|
{
|
|
{
|
|
@@ -367,7 +367,7 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
byte = (unsigned char)f.data[ i ] ^ f.key[ i % 4 ];
|
|
byte = (unsigned char)f.data[ i ] ^ f.key[ i % 4 ];
|
|
else
|
|
else
|
|
byte = (unsigned char)f.data[ i ];
|
|
byte = (unsigned char)f.data[ i ];
|
|
- klient->sende( (char*)&byte, 1 );
|
|
|
|
|
|
+ klient->sende( (char *)&byte, 1 );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
c2.unlock();
|
|
c2.unlock();
|
|
@@ -381,7 +381,7 @@ __declspec( dllexport ) void WebSocketClient::thread()
|
|
c.unlock();
|
|
c.unlock();
|
|
c2.lock();
|
|
c2.lock();
|
|
klient->trenne();
|
|
klient->trenne();
|
|
- klient = klient->release();
|
|
|
|
|
|
+ klient = (Klient *)klient->release();
|
|
c2.unlock();
|
|
c2.unlock();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -402,7 +402,7 @@ __declspec( dllexport ) void WebSocketClient::disconnect()
|
|
return;
|
|
return;
|
|
c2.lock();
|
|
c2.lock();
|
|
klient->trenne();
|
|
klient->trenne();
|
|
- klient = klient->release();
|
|
|
|
|
|
+ klient = (Klient *)klient->release();
|
|
c2.unlock();
|
|
c2.unlock();
|
|
warteAufThread( 1000 );
|
|
warteAufThread( 1000 );
|
|
}
|
|
}
|
|
@@ -410,14 +410,4 @@ __declspec( dllexport ) void WebSocketClient::disconnect()
|
|
__declspec( dllexport ) bool WebSocketClient::isConnected() const
|
|
__declspec( dllexport ) bool WebSocketClient::isConnected() const
|
|
{
|
|
{
|
|
return klient != 0;
|
|
return klient != 0;
|
|
-}
|
|
|
|
-
|
|
|
|
-// löscht das objekt wenn es nicht mehr gebraucht wird und beendet den Thread
|
|
|
|
-Thread *WebSocketClient::release()
|
|
|
|
-{
|
|
|
|
-#ifdef WIN32
|
|
|
|
- if( ref == 2 && run )
|
|
|
|
- disconnect();
|
|
|
|
-#endif
|
|
|
|
- return Thread::release();
|
|
|
|
}
|
|
}
|