Fixed compile issues under linux.

master
Hannes Matuschek 11 years ago
parent 5ded7135d0
commit 589f2e5d7c

@ -184,9 +184,15 @@ Server::_listen_main(void *ctx) {
try { self->_connections.insert(new Connection(self, socket)); } try { self->_connections.insert(new Connection(self, socket)); }
catch (...) { } catch (...) { }
// Free closed connections // Free closed connections
std::list<Connection *> closed_connections;
std::set<Connection *>::iterator item = self->_connections.begin(); std::set<Connection *>::iterator item = self->_connections.begin();
for (; item != self->_connections.end(); item++) { for (; item != self->_connections.end(); item++) {
if ((*item)->isClosed()) { delete *item; item = self->_connections.erase(item); } if ((*item)->isClosed()) { closed_connections.push_back(*item); }
}
std::list<Connection *>::iterator citem = closed_connections.begin();
for (; citem != closed_connections.end(); citem++) {
self->_connections.erase(*citem);
delete *citem;
} }
} }
return 0; return 0;
@ -252,7 +258,7 @@ Connection::close(bool wait) {
Logger::get().log(msg); Logger::get().log(msg);
::close(socket); ::close(socket);
} }
if (wait && (0 == pthread_kill(_thread, 0))) { if (wait) {
// Wait for the thread to exit. // Wait for the thread to exit.
void *ret = 0; void *ret = 0;
pthread_join(_thread, &ret); pthread_join(_thread, &ret);
@ -261,7 +267,7 @@ Connection::close(bool wait) {
bool bool
Connection::isClosed() const { Connection::isClosed() const {
return ((-1 == _socket) && (0 != pthread_kill(_thread, 0))); return (-1 == _socket);
} }
void * void *

@ -45,12 +45,12 @@ sdr::sha1_init(sha1 *s) {
} }
uint32_t uint32_t
sdr::sha1_rol32(uint32_t number, uint8_t bits) { sha1_rol32(uint32_t number, uint8_t bits) {
return ((number << bits) | (number >> (32-bits))); return ((number << bits) | (number >> (32-bits)));
} }
void void
sdr::sha1_hashBlock(sha1 *s) { sha1_hashBlock(sha1 *s) {
uint8_t i; uint8_t i;
uint32_t a,b,c,d,e,t; uint32_t a,b,c,d,e,t;
@ -88,7 +88,7 @@ sdr::sha1_hashBlock(sha1 *s) {
} }
void void
sdr::sha1_addUncounted(sha1 *s, uint8_t data) { sha1_addUncounted(sha1 *s, uint8_t data) {
uint8_t * const b = (uint8_t*) s->buffer; uint8_t * const b = (uint8_t*) s->buffer;
#ifdef SHA_BIG_ENDIAN #ifdef SHA_BIG_ENDIAN
b[s->bufferOffset] = data; b[s->bufferOffset] = data;
@ -114,7 +114,7 @@ sdr::sha1_write(sha1 *s, const char *data, size_t len) {
} }
void void
sdr::sha1_pad(sha1 *s) { sha1_pad(sha1 *s) {
// Implement SHA-1 padding (fips180-2 §5.1.1) // Implement SHA-1 padding (fips180-2 §5.1.1)
// Pad with 0x80 followed by 0x00 until the end of the block // Pad with 0x80 followed by 0x00 until the end of the block
@ -159,19 +159,19 @@ sdr::sha1_result(sha1 *s) {
void void
sdr::sha1_initHmac(sha1 *s, const uint8_t* key, int keyLength) { sdr::sha1_initHmac(sha1 *s, const uint8_t* key, int keyLength) {
uint8_t i; uint8_t i;
memset(s->keyBuffer, 0,SDR_SHA1_BLOCK_LENGTHH); memset(s->keyBuffer, 0,SDR_SHA1_BLOCK_LENGTH);
if (keyLength >SDR_SHA1_BLOCK_LENGTHH) { if (keyLength >SDR_SHA1_BLOCK_LENGTH) {
// Hash long keys // Hash long keys
sha1_init(s); sha1_init(s);
for (;keyLength--;) sha1_writebyte(s, *key++); for (;keyLength--;) sha1_writebyte(s, *key++);
memcpy(s->keyBuffer, sha1_result(s),SDR_SHA1_HASH_LENGTHH); memcpy(s->keyBuffer, sha1_result(s),SDR_SHA1_HASH_LENGTH);
} else { } else {
// Block length keys are used as is // Block length keys are used as is
memcpy(s->keyBuffer, key, keyLength); memcpy(s->keyBuffer, key, keyLength);
} }
// Start inner hash // Start inner hash
sha1_init(s); sha1_init(s);
for (i=0; iSDR_SHA1_BLOCK_LENGTHH; i++) { for (i=0; i<SDR_SHA1_BLOCK_LENGTH; i++) {
sha1_writebyte(s, s->keyBuffer[i] ^ HMAC_IPAD); sha1_writebyte(s, s->keyBuffer[i] ^ HMAC_IPAD);
} }
} }
@ -180,10 +180,10 @@ uint8_t*
sdr::sha1_resultHmac(sha1 *s) { sdr::sha1_resultHmac(sha1 *s) {
uint8_t i; uint8_t i;
// Complete inner hash // Complete inner hash
memcpy(s->innerHash,sha1_result(s)SDR_SHA1_HASH_LENGTHH); memcpy(s->innerHash,sha1_result(s), SDR_SHA1_HASH_LENGTH);
// Calculate outer hash // Calculate outer hash
sha1_init(s); sha1_init(s);
for (i=0; iSDR_SHA1_BLOCK_LENGTHH; i++) sha1_writebyte(s, s->keyBuffer[i] ^ HMAC_OPAD); for (i=0; i<SDR_SHA1_BLOCK_LENGTH; i++) sha1_writebyte(s, s->keyBuffer[i] ^ HMAC_OPAD);
for (i=0; iSDR_SHA1_HASH_LENGTHH; i++) sha1_writebyte(s, s->innerHash[i]); for (i=0; i<SDR_SHA1_HASH_LENGTH; i++) sha1_writebyte(s, s->innerHash[i]);
return sha1_result(s); return sha1_result(s);
} }

@ -1,7 +1,8 @@
#ifndef __SDR_SHA1_HH__ #ifndef __SDR_SHA1_HH__
#define __SDR_SHA1_HH__ #define __SDR_SHA1_HH__
#include <stdint.h> #include <memory.h>
#include <inttypes.h>
namespace sdr { namespace sdr {

Loading…
Cancel
Save