1.4.10 updates
This commit is contained in:
parent
51d9a002e3
commit
fd8aba2ede
@ -189,7 +189,12 @@ if(HAVE_OPEN_SSL)
|
||||
endif()
|
||||
|
||||
add_library(TeaSpeak STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||
target_link_libraries(TeaSpeak PUBLIC threadpool::static jsoncpp_lib)
|
||||
target_link_libraries(TeaSpeak PUBLIC
|
||||
threadpool::static jsoncpp_lib
|
||||
tomcrypt::static
|
||||
tommath::static
|
||||
)
|
||||
|
||||
target_compile_options(TeaSpeak PRIVATE "-Wall")
|
||||
|
||||
if (TEASPEAK_SERVER)
|
||||
|
@ -90,8 +90,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
public:
|
||||
ChannelId channelId() const override;
|
||||
ChannelId previousChannelId() const override;
|
||||
[[nodiscard]] ChannelId channelId() const override;
|
||||
[[nodiscard]] ChannelId previousChannelId() const override;
|
||||
void setPreviousChannelId(ChannelId id) override;
|
||||
void setParentChannelId(ChannelId id) override;
|
||||
void setLinkedHandle(const std::weak_ptr<TreeView::LinkedTreeEntry> &) override;
|
||||
|
@ -1,119 +0,0 @@
|
||||
#include <execinfo.h> // for backtrace
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <functional>
|
||||
#include <src/log/LogUtils.h>
|
||||
|
||||
#include "TraceUtils.h"
|
||||
#include "../../../music/providers/shared/pstream.h"
|
||||
|
||||
#define READ_BUFFER_SIZE 128
|
||||
|
||||
namespace TraceUtils {
|
||||
static bool addr2line_present = true;
|
||||
inline std::string addr2lineInfo(StackTraceElement *element) {
|
||||
if(!addr2line_present)
|
||||
return "??\n??:0";
|
||||
|
||||
char buffer[READ_BUFFER_SIZE];
|
||||
|
||||
sprintf(buffer, "addr2line -Cif -e %s %p", element->file.c_str(), element->offset); //last parameter is the name of this app
|
||||
redi::pstream stream(buffer, redi::pstream::pstdout | redi::pstream::pstderr);
|
||||
|
||||
std::string result;
|
||||
std::string error;
|
||||
do {
|
||||
|
||||
auto read = stream.err().readsome(buffer, READ_BUFFER_SIZE);
|
||||
if(read > 0) error += string(buffer, read);
|
||||
|
||||
read = stream.out().readsome(buffer, READ_BUFFER_SIZE);
|
||||
if(read > 0) result += string(buffer, read);
|
||||
} while(stream.good());
|
||||
|
||||
if(!error.empty()) {
|
||||
while(!error.empty() && (error.back() == '\n' || error.back() == '\r')) error = error.substr(0, error.length() - 1);
|
||||
logError("Could not resolve symbols. (Error: " + error + ")");
|
||||
addr2line_present = false;
|
||||
return "??\n??:0";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void StackTrace::printStackTrace() {
|
||||
printStackTrace([](StackTraceElement* e) {
|
||||
cerr << " at "+e->getFunctionName()+"( " + e->getSourceFile() + ":" + to_string(e->getSourceLine()) + ")" << endl;
|
||||
});
|
||||
}
|
||||
|
||||
void StackTrace::printStackTrace(std::function<void(StackTraceElement*)> writeMessage) {
|
||||
for (int i = 0; i < stackSize; i++) {
|
||||
writeMessage((StackTraceElement*) elements[i]);
|
||||
}
|
||||
}
|
||||
|
||||
StackTrace backTrace(int size) {
|
||||
int backtraceLength;
|
||||
void *buffer[BT_BUF_SIZE];
|
||||
char **symbols;
|
||||
|
||||
backtraceLength = backtrace(buffer, BT_BUF_SIZE);
|
||||
symbols = backtrace_symbols(buffer, backtraceLength);
|
||||
if (symbols == nullptr) {
|
||||
perror("backtrace_symbols");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
StackTrace out(backtraceLength);
|
||||
|
||||
for (int i = 0; i < backtraceLength; i++) {
|
||||
auto sym = std::string(symbols[i]);
|
||||
string file = "undefined";
|
||||
if (sym.find_first_of('(') != std::string::npos) file = sym.substr(0, sym.find_first_of('('));
|
||||
out.elements[i] = new StackTraceElement{i, buffer[i], file, sym};
|
||||
}
|
||||
|
||||
free(symbols);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
StackTrace::StackTrace(int size) : stackSize(size), elements(static_cast<const StackTraceElement **>(malloc(size * sizeof(void *)))) {}
|
||||
|
||||
StackTrace::~StackTrace() {
|
||||
for (int i = 0; i < this->stackSize; i++)
|
||||
if (this->elements[i]) delete this->elements[i];
|
||||
free(this->elements);
|
||||
}
|
||||
|
||||
void StackTraceElement::loadSymbols() {
|
||||
if (this->symbolLoadState == 0) {
|
||||
auto strInfo = addr2lineInfo(this);
|
||||
this->fnName = strInfo.substr(0, strInfo.find_first_of('\n'));
|
||||
|
||||
auto srcInfo = strInfo.substr(strInfo.find_first_of('\n') + 1);
|
||||
this->srcFile = srcInfo.substr(0, srcInfo.find_first_of(':'));
|
||||
this->srcLine = atoi(srcInfo.substr(srcInfo.find_first_of(':') + 1).c_str());
|
||||
this->symbolLoadState = 1;
|
||||
}
|
||||
}
|
||||
|
||||
string StackTraceElement::getFunctionName() {
|
||||
loadSymbols();
|
||||
return this->fnName;
|
||||
}
|
||||
|
||||
string StackTraceElement::getSourceFile() {
|
||||
loadSymbols();
|
||||
return this->srcFile;
|
||||
}
|
||||
|
||||
int StackTraceElement::getSourceLine() {
|
||||
loadSymbols();
|
||||
return this->srcLine;
|
||||
}
|
||||
|
||||
StackTraceElement::StackTraceElement(int elementIndex, void *offset, string file, string symbol) : elementIndex(elementIndex), offset(offset), file(file), symbol(symbol) {}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#include <execinfo.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
|
||||
#define BT_BUF_SIZE 100
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace TraceUtils {
|
||||
struct StackTraceElement {
|
||||
public:
|
||||
StackTraceElement(int elementIndex, void *offset,string file,string symbol);
|
||||
|
||||
int elementIndex;
|
||||
|
||||
void *offset;
|
||||
string file;
|
||||
|
||||
string symbol;
|
||||
|
||||
|
||||
string getFunctionName();
|
||||
string getSourceFile();
|
||||
int getSourceLine();
|
||||
|
||||
private:
|
||||
int symbolLoadState = 0;
|
||||
|
||||
string fnName;
|
||||
string srcFile;
|
||||
int srcLine;
|
||||
|
||||
void loadSymbols();
|
||||
};
|
||||
|
||||
struct StackTrace {
|
||||
public:
|
||||
explicit StackTrace(int size);
|
||||
~StackTrace();
|
||||
|
||||
const StackTraceElement** elements;
|
||||
const int stackSize;
|
||||
|
||||
void printStackTrace();
|
||||
|
||||
void printStackTrace(std::function<void(StackTraceElement*)> format);
|
||||
};
|
||||
|
||||
extern StackTrace backTrace(int size);
|
||||
};
|
@ -1,17 +1,16 @@
|
||||
#define NO_OPEN_SSL
|
||||
#include "./digest.h"
|
||||
#ifdef NO_OPEN_SSL
|
||||
#include <tomcrypt.h>
|
||||
#include <tomcrypt.h>
|
||||
|
||||
#define DECLARE_DIGEST(name, digestLength) \
|
||||
void digest::tomcrypt::name(const char* input, size_t length, uint8_t* result) { \
|
||||
hash_state hash{}; \
|
||||
\
|
||||
name ##_init(&hash); \
|
||||
name ##_process(&hash, (uint8_t*) input, (unsigned long) length); \
|
||||
name ##_done(&hash, result); \
|
||||
}
|
||||
#define DECLARE_DIGEST(name, digestLength) \
|
||||
void digest::tomcrypt::name(const char* input, size_t length, uint8_t* result) { \
|
||||
hash_state hash{}; \
|
||||
\
|
||||
name ##_init(&hash); \
|
||||
name ##_process(&hash, (uint8_t*) input, (unsigned long) length); \
|
||||
name ##_done(&hash, result); \
|
||||
}
|
||||
|
||||
DECLARE_DIGEST(sha1, SHA_DIGEST_LENGTH)
|
||||
DECLARE_DIGEST(sha256, SHA256_DIGEST_LENGTH)
|
||||
DECLARE_DIGEST(sha512, SHA512_DIGEST_LENGTH)
|
||||
#endif
|
||||
DECLARE_DIGEST(sha1, SHA_DIGEST_LENGTH)
|
||||
DECLARE_DIGEST(sha256, SHA256_DIGEST_LENGTH)
|
||||
DECLARE_DIGEST(sha512, SHA512_DIGEST_LENGTH)
|
@ -35,7 +35,6 @@
|
||||
inline void name(const char* input, size_t length, uint8_t* result) { \
|
||||
tomcrypt::name(input, length, result); \
|
||||
}
|
||||
|
||||
#else
|
||||
#include <openssl/sha.h>
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace memtrack {
|
||||
inline std::string as_mangled() {
|
||||
#ifndef WIN32
|
||||
int status;
|
||||
std::unique_ptr<char[], void (*)(void*)> result(abi::__cxa_demangle(name, 0, 0, &status), std::free);
|
||||
std::unique_ptr<char[], void (*)(void*)> result(abi::__cxa_demangle(name, nullptr, nullptr, &status), std::free);
|
||||
if(status != 0)
|
||||
return "error: " + to_string(status);
|
||||
|
||||
|
@ -15,255 +15,109 @@
|
||||
#include <log/LogUtils.h>
|
||||
#endif
|
||||
|
||||
namespace ts {
|
||||
namespace buffer {
|
||||
struct RawBuffer {
|
||||
public:
|
||||
RawBuffer() : RawBuffer(0) {}
|
||||
RawBuffer(size_t length) : index(0), length(length) {
|
||||
if(length > 0) buffer = (char *) malloc(length);
|
||||
else buffer = nullptr;
|
||||
this->length = length;
|
||||
this->index = 0;
|
||||
}
|
||||
|
||||
RawBuffer(const RawBuffer &other) : RawBuffer(other.length) {
|
||||
if(other.length > 0) memcpy(this->buffer, other.buffer, this->length);
|
||||
this->index = other.index;
|
||||
}
|
||||
|
||||
virtual ~RawBuffer() {
|
||||
if(buffer)
|
||||
free(buffer);
|
||||
this->buffer = nullptr;
|
||||
}
|
||||
|
||||
void slice(size_t length) {
|
||||
char *oldBuff = this->buffer;
|
||||
|
||||
this->buffer = (char *) malloc(length);
|
||||
memcpy(this->buffer, oldBuff, length);
|
||||
this->length = length;
|
||||
|
||||
free(oldBuff);
|
||||
}
|
||||
|
||||
char *buffer = nullptr;
|
||||
size_t length = 0;
|
||||
size_t index = 0;
|
||||
|
||||
TAILQ_ENTRY(ts::buffer::RawBuffer) tail;
|
||||
};
|
||||
|
||||
template <typename PktType>
|
||||
struct SortedBufferQueue {
|
||||
SortedBufferQueue(ts::protocol::PacketTypeInfo type, bool ignoreOrder) : _type(std::move(type)), ignoreOrder(ignoreOrder) {
|
||||
this->current.index = 0;
|
||||
}
|
||||
|
||||
SortedBufferQueue(const SortedBufferQueue &ref) = delete;
|
||||
SortedBufferQueue(SortedBufferQueue&&ref) = delete;
|
||||
|
||||
~SortedBufferQueue() = default;
|
||||
|
||||
ts::protocol::PacketTypeInfo type() { return this->_type; }
|
||||
|
||||
void skipPacket(){
|
||||
threads::MutexLock lock(this->lock);
|
||||
this->current.index++;
|
||||
}
|
||||
|
||||
size_t available(){
|
||||
threads::MutexLock lock(this->lock);
|
||||
if(this->ignoreOrder) return this->packets.size();
|
||||
|
||||
uint16_t index = 0;
|
||||
while(true) {
|
||||
if(!this->find_packet(this->current.index + index))
|
||||
return index;
|
||||
else
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PktType> find_packet(uint32_t pktId){
|
||||
pktId &= 0xFFFF;
|
||||
|
||||
threads::MutexLock lock(this->lock);
|
||||
for(const auto& elm : this->packets)
|
||||
if(elm->packetId() == pktId)
|
||||
return elm;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<PktType> peekNext(uint32_t index) {
|
||||
threads::MutexLock lock(this->lock);
|
||||
if(this->ignoreOrder) {
|
||||
if(this->packets.size() > index)
|
||||
return this->packets[index];
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
return this->find_packet(this->current.index + index);
|
||||
}
|
||||
|
||||
void pop_packets(int32_t count = -1) {
|
||||
if(count == -1) count = 1;
|
||||
|
||||
threads::MutexLock lock(this->lock);
|
||||
if(this->ignoreOrder) {
|
||||
while(count-- > 0 && !this->packets.empty()) this->packets.pop_front();
|
||||
return;
|
||||
}
|
||||
|
||||
auto until = this->current.index + count;
|
||||
while(this->current.index < until) {
|
||||
for(auto it = this->packets.begin(); it != this->packets.end(); it++) {
|
||||
if((*it)->packetId() == this->current.packet_id) {
|
||||
this->packets.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this->current.index++;
|
||||
}
|
||||
}
|
||||
|
||||
bool push_pack(const std::shared_ptr<PktType>& pkt){
|
||||
threads::MutexLock lock(this->lock);
|
||||
if(this->ignoreOrder) {
|
||||
this->packets.push_back(pkt);
|
||||
if(this->current.packet_id > pkt->packetId()) {
|
||||
if(this->current.packet_id > 0xFF00 && pkt->packetId() < 0xFF) {
|
||||
this->current.packet_id = pkt->packetId();
|
||||
this->current.generation++;
|
||||
}
|
||||
} else this->current.packet_id = pkt->packetId();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if(this->current.packet_id > pkt->packetId()) {
|
||||
if(this->current.packet_id < 0xFF00 || pkt->packetId() > 0xFF) {
|
||||
#ifndef NO_LOG
|
||||
debugMessage(0, "Invalid packed pushpack! Current index {} (generation {}) Packet index {}", this->current.packet_id, this->current.generation, pkt->packetId());
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this->packets.push_back(pkt);
|
||||
return true;
|
||||
}
|
||||
|
||||
void reset(){
|
||||
this->current.index = 0;
|
||||
}
|
||||
|
||||
std::unique_lock<std::recursive_mutex> try_lock_queue() {
|
||||
threads::MutexTryLock lock(this->lock);
|
||||
if(!lock) return {};
|
||||
return std::unique_lock(this->lock);
|
||||
}
|
||||
|
||||
std::unique_lock<std::recursive_mutex> try_lock_execute() {
|
||||
threads::MutexTryLock lock(this->execute_lock);
|
||||
if(!lock) return {};
|
||||
return std::unique_lock(this->execute_lock);
|
||||
}
|
||||
|
||||
uint16_t current_packet_id() { return this->current.packet_id; }
|
||||
uint16_t current_generation_id() { return this->current.generation; }
|
||||
|
||||
uint16_t calculate_generation(uint16_t packetId) {
|
||||
if(packetId >= this->current.packet_id) return this->current.generation;
|
||||
|
||||
if(packetId < 0xFF && this->current.packet_id > 0xFF00)
|
||||
return this->current.generation + 1;
|
||||
|
||||
return this->current.generation;
|
||||
}
|
||||
|
||||
union PacketPair {
|
||||
uint32_t index;
|
||||
struct {
|
||||
uint16_t packet_id;
|
||||
uint16_t generation;
|
||||
};
|
||||
};
|
||||
|
||||
PacketPair current{0};
|
||||
private:
|
||||
ts::protocol::PacketTypeInfo _type;
|
||||
bool ignoreOrder = false;
|
||||
std::deque<std::shared_ptr<PktType>> packets{};
|
||||
std::recursive_mutex lock;
|
||||
std::recursive_mutex execute_lock;
|
||||
};
|
||||
|
||||
struct size {
|
||||
enum value : uint8_t {
|
||||
unset,
|
||||
min,
|
||||
Bytes_512 = min,
|
||||
Bytes_1024,
|
||||
Bytes_1536,
|
||||
max
|
||||
};
|
||||
|
||||
static inline size_t byte_length(value size) {
|
||||
switch (size) {
|
||||
case Bytes_512:
|
||||
return 512;
|
||||
case Bytes_1024:
|
||||
return 1024;
|
||||
case Bytes_1536:
|
||||
return 1536;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
namespace ts::buffer {
|
||||
struct RawBuffer {
|
||||
public:
|
||||
RawBuffer() : RawBuffer(0) {}
|
||||
RawBuffer(size_t length) : index(0), length(length) {
|
||||
if(length > 0) buffer = (char *) malloc(length);
|
||||
else buffer = nullptr;
|
||||
this->length = length;
|
||||
this->index = 0;
|
||||
}
|
||||
|
||||
RawBuffer(const RawBuffer &other) : RawBuffer(other.length) {
|
||||
if(other.length > 0) memcpy(this->buffer, other.buffer, this->length);
|
||||
this->index = other.index;
|
||||
}
|
||||
|
||||
virtual ~RawBuffer() {
|
||||
if(buffer)
|
||||
free(buffer);
|
||||
this->buffer = nullptr;
|
||||
}
|
||||
|
||||
void slice(size_t length) {
|
||||
char *oldBuff = this->buffer;
|
||||
|
||||
this->buffer = (char *) malloc(length);
|
||||
memcpy(this->buffer, oldBuff, length);
|
||||
this->length = length;
|
||||
|
||||
free(oldBuff);
|
||||
}
|
||||
|
||||
char *buffer = nullptr;
|
||||
size_t length = 0;
|
||||
size_t index = 0;
|
||||
|
||||
TAILQ_ENTRY(ts::buffer::RawBuffer) tail;
|
||||
};
|
||||
|
||||
struct size {
|
||||
enum value : uint8_t {
|
||||
unset,
|
||||
min,
|
||||
Bytes_512 = min,
|
||||
Bytes_1024,
|
||||
Bytes_1536,
|
||||
max
|
||||
};
|
||||
|
||||
//typedef std::unique_ptr<pipes::buffer, void(*)(pipes::buffer*)> buffer_t;
|
||||
typedef pipes::buffer buffer_t;
|
||||
|
||||
extern buffer_t allocate_buffer(size::value /* size */);
|
||||
inline buffer_t allocate_buffer(size_t length) {
|
||||
pipes::buffer result;
|
||||
if(length <= 512)
|
||||
result = allocate_buffer(size::Bytes_512);
|
||||
else if(length <= 1024)
|
||||
result = allocate_buffer(size::Bytes_1024);
|
||||
else if(length <= 1536)
|
||||
result = allocate_buffer(size::Bytes_1536);
|
||||
else {
|
||||
return pipes::buffer{length};
|
||||
static inline size_t byte_length(value size) {
|
||||
switch (size) {
|
||||
case Bytes_512:
|
||||
return 512;
|
||||
case Bytes_1024:
|
||||
return 1024;
|
||||
case Bytes_1536:
|
||||
return 1536;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
result.resize(length);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
struct cleaninfo {
|
||||
size_t bytes_freed_internal;
|
||||
size_t bytes_freed_buffer;
|
||||
};
|
||||
struct cleanmode {
|
||||
enum value {
|
||||
CHUNKS = 0x01,
|
||||
BLOCKS = 0x02,
|
||||
//typedef std::unique_ptr<pipes::buffer, void(*)(pipes::buffer*)> buffer_t;
|
||||
typedef pipes::buffer buffer_t;
|
||||
|
||||
CHUNKS_BLOCKS = 0x03
|
||||
};
|
||||
};
|
||||
extern cleaninfo cleanup_buffers(cleanmode::value /* mode */);
|
||||
|
||||
struct meminfo {
|
||||
size_t bytes_buffer = 0;
|
||||
size_t bytes_buffer_used = 0;
|
||||
size_t bytes_internal = 0;
|
||||
|
||||
size_t nodes = 0;
|
||||
size_t nodes_full = 0;
|
||||
};
|
||||
extern meminfo buffer_memory();
|
||||
extern buffer_t allocate_buffer(size::value /* size */);
|
||||
inline buffer_t allocate_buffer(size_t length) {
|
||||
pipes::buffer result;
|
||||
if(length <= 512)
|
||||
result = allocate_buffer(size::Bytes_512);
|
||||
else if(length <= 1024)
|
||||
result = allocate_buffer(size::Bytes_1024);
|
||||
else if(length <= 1536)
|
||||
result = allocate_buffer(size::Bytes_1536);
|
||||
else {
|
||||
return pipes::buffer{length};
|
||||
}
|
||||
result.resize(length);
|
||||
return result;
|
||||
}
|
||||
|
||||
struct cleaninfo {
|
||||
size_t bytes_freed_internal;
|
||||
size_t bytes_freed_buffer;
|
||||
};
|
||||
struct cleanmode {
|
||||
enum value {
|
||||
CHUNKS = 0x01,
|
||||
BLOCKS = 0x02,
|
||||
|
||||
CHUNKS_BLOCKS = 0x03
|
||||
};
|
||||
};
|
||||
extern cleaninfo cleanup_buffers(cleanmode::value /* mode */);
|
||||
|
||||
struct meminfo {
|
||||
size_t bytes_buffer = 0;
|
||||
size_t bytes_buffer_used = 0;
|
||||
size_t bytes_internal = 0;
|
||||
|
||||
size_t nodes = 0;
|
||||
size_t nodes_full = 0;
|
||||
};
|
||||
extern meminfo buffer_memory();
|
||||
}
|
Loading…
Reference in New Issue
Block a user