mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-10 13:37:03 +03:00
big merge
This commit is contained in:
71
components/spotify/cspot/bell/include/platform/TLSSocket.h
Normal file
71
components/spotify/cspot/bell/include/platform/TLSSocket.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef BELL_TLS_SOCKET_H
|
||||
#define BELL_TLS_SOCKET_H
|
||||
|
||||
#include "BellLogger.h"
|
||||
#include "BellSocket.h"
|
||||
#include <cstring>
|
||||
#include <ctype.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#ifdef BELL_USE_MBEDTLS
|
||||
|
||||
#include "mbedtls/net_sockets.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include "mbedtls/debug.h"
|
||||
#else
|
||||
#include <openssl/bio.h>
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/ssl.h>
|
||||
#endif
|
||||
|
||||
namespace bell {
|
||||
class TLSSocket : public bell::Socket {
|
||||
private:
|
||||
#ifdef BELL_USE_MBEDTLS
|
||||
mbedtls_net_context server_fd;
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
mbedtls_ssl_context ssl;
|
||||
mbedtls_ssl_config conf;
|
||||
#else
|
||||
|
||||
BIO *sbio, *out;
|
||||
int len;
|
||||
char tmpbuf[1024];
|
||||
SSL_CTX *ctx;
|
||||
SSL *ssl;
|
||||
|
||||
int sockFd;
|
||||
int sslFd;
|
||||
#endif
|
||||
|
||||
bool isClosed = false;
|
||||
public:
|
||||
TLSSocket();
|
||||
~TLSSocket() { close(); };
|
||||
|
||||
void open(std::string host);
|
||||
|
||||
size_t read(uint8_t *buf, size_t len);
|
||||
size_t write(uint8_t *buf, size_t len);
|
||||
|
||||
void close();
|
||||
};
|
||||
|
||||
} // namespace bell
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,5 @@
|
||||
#ifdef _WIN32
|
||||
#include "win32/WrappedMutex.h"
|
||||
#else
|
||||
#include "unixlike/WrappedMutex.h"
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef WRAPPEDSEMAPHORE_H
|
||||
#define WRAPPEDSEMAPHORE_H
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#elif __APPLE__
|
||||
#include <dispatch/dispatch.h>
|
||||
#else
|
||||
#include <semaphore.h>
|
||||
#endif
|
||||
|
||||
class WrappedSemaphore
|
||||
{
|
||||
private:
|
||||
#ifdef ESP_PLATFORM
|
||||
xSemaphoreHandle semaphoreHandle;
|
||||
#elif __APPLE__
|
||||
dispatch_semaphore_t semaphoreHandle;
|
||||
#else
|
||||
sem_t semaphoreHandle;
|
||||
#endif
|
||||
public:
|
||||
WrappedSemaphore(int maxVal = 200);
|
||||
~WrappedSemaphore();
|
||||
|
||||
int wait();
|
||||
int twait(long milliseconds = 10);
|
||||
void give();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef UNIXLIKE_WRAPPED_MUTEX_H
|
||||
#define UNIXLIKE_WRAPPED_MUTEX_H
|
||||
#include <pthread.h>
|
||||
|
||||
/**
|
||||
* Wraps a mutex on unixlike patforms (linux, macOS, esp32 etc.).
|
||||
* Header only since all the methods call one function, we want them to be inlined
|
||||
**/
|
||||
class WrappedMutex
|
||||
{
|
||||
public:
|
||||
WrappedMutex()
|
||||
{
|
||||
pthread_mutex_init(&this->_mutex, NULL);
|
||||
}
|
||||
|
||||
~WrappedMutex()
|
||||
{
|
||||
pthread_mutex_destroy(&this->_mutex);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
pthread_mutex_lock(&this->_mutex);
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
pthread_mutex_unlock(&this->_mutex);
|
||||
}
|
||||
|
||||
private:
|
||||
pthread_mutex_t _mutex;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef WIN32_WRAPPED_MUTEX_H
|
||||
#define WIN32_WRAPPED_MUTEX_H
|
||||
#include <Windows.h>
|
||||
|
||||
/**
|
||||
* Wraps a windows mutex.
|
||||
* Header only since all the methods call one function, we want them to be inlined
|
||||
**/
|
||||
class WrappedMutex
|
||||
{
|
||||
public:
|
||||
WrappedMutex()
|
||||
{
|
||||
this->_mutex = CreateMutex(
|
||||
NULL, // default security attributes
|
||||
FALSE, // initially not owned
|
||||
NULL); // unnamed mutex
|
||||
}
|
||||
|
||||
~WrappedMutex()
|
||||
{
|
||||
CloseHandle(_mutex);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
WaitForSingleObject(_mutex, INFINITE);
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
ReleaseMutex(_mutex);
|
||||
}
|
||||
|
||||
private:
|
||||
HANDLE _mutex;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user