1.4.10 updates

This commit is contained in:
WolverinDEV 2020-02-28 11:24:02 +01:00
parent 51d9a002e3
commit fd8aba2ede
8 changed files with 119 additions and 437 deletions

View File

@ -189,7 +189,12 @@ if(HAVE_OPEN_SSL)
endif() endif()
add_library(TeaSpeak STATIC ${SOURCE_FILES} ${HEADER_FILES}) 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") target_compile_options(TeaSpeak PRIVATE "-Wall")
if (TEASPEAK_SERVER) if (TEASPEAK_SERVER)

View File

@ -90,8 +90,8 @@ namespace ts {
} }
public: public:
ChannelId channelId() const override; [[nodiscard]] ChannelId channelId() const override;
ChannelId previousChannelId() const override; [[nodiscard]] ChannelId previousChannelId() const override;
void setPreviousChannelId(ChannelId id) override; void setPreviousChannelId(ChannelId id) override;
void setParentChannelId(ChannelId id) override; void setParentChannelId(ChannelId id) override;
void setLinkedHandle(const std::weak_ptr<TreeView::LinkedTreeEntry> &) override; void setLinkedHandle(const std::weak_ptr<TreeView::LinkedTreeEntry> &) override;

View File

@ -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) {}
}

View File

@ -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);
};

View File

@ -1,5 +1,5 @@
#define NO_OPEN_SSL
#include "./digest.h" #include "./digest.h"
#ifdef NO_OPEN_SSL
#include <tomcrypt.h> #include <tomcrypt.h>
#define DECLARE_DIGEST(name, digestLength) \ #define DECLARE_DIGEST(name, digestLength) \
@ -14,4 +14,3 @@
DECLARE_DIGEST(sha1, SHA_DIGEST_LENGTH) DECLARE_DIGEST(sha1, SHA_DIGEST_LENGTH)
DECLARE_DIGEST(sha256, SHA256_DIGEST_LENGTH) DECLARE_DIGEST(sha256, SHA256_DIGEST_LENGTH)
DECLARE_DIGEST(sha512, SHA512_DIGEST_LENGTH) DECLARE_DIGEST(sha512, SHA512_DIGEST_LENGTH)
#endif

View File

@ -35,7 +35,6 @@
inline void name(const char* input, size_t length, uint8_t* result) { \ inline void name(const char* input, size_t length, uint8_t* result) { \
tomcrypt::name(input, length, result); \ tomcrypt::name(input, length, result); \
} }
#else #else
#include <openssl/sha.h> #include <openssl/sha.h>

View File

@ -67,7 +67,7 @@ namespace memtrack {
inline std::string as_mangled() { inline std::string as_mangled() {
#ifndef WIN32 #ifndef WIN32
int status; 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) if(status != 0)
return "error: " + to_string(status); return "error: " + to_string(status);

View File

@ -15,8 +15,7 @@
#include <log/LogUtils.h> #include <log/LogUtils.h>
#endif #endif
namespace ts { namespace ts::buffer {
namespace buffer {
struct RawBuffer { struct RawBuffer {
public: public:
RawBuffer() : RawBuffer(0) {} RawBuffer() : RawBuffer(0) {}
@ -55,150 +54,6 @@ namespace ts {
TAILQ_ENTRY(ts::buffer::RawBuffer) tail; 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 { struct size {
enum value : uint8_t { enum value : uint8_t {
unset, unset,
@ -266,4 +121,3 @@ namespace ts {
}; };
extern meminfo buffer_memory(); extern meminfo buffer_memory();
} }
}