mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-13 15:07:01 +03:00
idf overriding method to bring back SPDIF and fix SPI + new CSPOT (which crashes)
This commit is contained in:
@@ -65,7 +65,7 @@ void bell::HTTPServer::registerHandler(RequestType requestType,
|
||||
}
|
||||
|
||||
void bell::HTTPServer::listen() {
|
||||
BELL_LOG(info, "http", "Starting configuration server at port %d",
|
||||
BELL_LOG(info, "http", "Starting server at port %d",
|
||||
this->serverPort);
|
||||
|
||||
// setup address
|
||||
@@ -170,8 +170,8 @@ void bell::HTTPServer::readFromClient(int clientFd) {
|
||||
if (line.find("Content-Length: ") != std::string::npos) {
|
||||
conn.contentLength =
|
||||
std::stoi(line.substr(16, line.size() - 1));
|
||||
BELL_LOG(info, "http", "Content-Length: %d",
|
||||
conn.contentLength);
|
||||
//BELL_LOG(info, "http", "Content-Length: %d",
|
||||
// conn.contentLength);
|
||||
}
|
||||
if (line.size() == 0) {
|
||||
if (conn.contentLength != 0) {
|
||||
@@ -201,7 +201,7 @@ void bell::HTTPServer::writeResponseEvents(int connFd) {
|
||||
|
||||
std::stringstream stream;
|
||||
stream << "HTTP/1.1 200 OK\r\n";
|
||||
stream << "Server: EUPHONIUM\r\n";
|
||||
stream << "Server: bell-http\r\n";
|
||||
stream << "Connection: keep-alive\r\n";
|
||||
stream << "Content-type: text/event-stream\r\n";
|
||||
stream << "Cache-Control: no-cache\r\n";
|
||||
@@ -229,7 +229,7 @@ void bell::HTTPServer::writeResponse(const HTTPResponse &response) {
|
||||
|
||||
std::stringstream stream;
|
||||
stream << "HTTP/1.1 " << response.status << " OK\r\n";
|
||||
stream << "Server: EUPHONIUM\r\n";
|
||||
stream << "Server: bell-http\r\n";
|
||||
stream << "Connection: close\r\n";
|
||||
stream << "Content-type: " << response.contentType << "\r\n";
|
||||
|
||||
@@ -270,7 +270,6 @@ void bell::HTTPServer::writeResponse(const HTTPResponse &response) {
|
||||
} while (read > 0);
|
||||
}
|
||||
|
||||
BELL_LOG(info, "HTTP", "Closing connection");
|
||||
this->closeConnection(response.connectionFd);
|
||||
}
|
||||
|
||||
@@ -282,7 +281,7 @@ void bell::HTTPServer::redirectTo(const std::string & url, int connectionFd) {
|
||||
std::lock_guard lock(this->responseMutex);
|
||||
std::stringstream stream;
|
||||
stream << "HTTP/1.1 301 Moved Permanently\r\n";
|
||||
stream << "Server: EUPHONIUM\r\n";
|
||||
stream << "Server: bell-http\r\n";
|
||||
stream << "Connection: close\r\n";
|
||||
stream << "Location: " << url << "\r\n\r\n";
|
||||
auto responseStr = stream.str();
|
||||
@@ -314,11 +313,11 @@ std::map<std::string, std::string>
|
||||
bell::HTTPServer::parseQueryString(const std::string &queryString) {
|
||||
std::map<std::string, std::string> query;
|
||||
auto prefixedString = "&" + queryString;
|
||||
while (prefixedString.find("&") != std::string::npos) {
|
||||
auto keyStart = prefixedString.find("&");
|
||||
auto keyEnd = prefixedString.find("=");
|
||||
while (prefixedString.find('&') != std::string::npos) {
|
||||
auto keyStart = prefixedString.find('&');
|
||||
auto keyEnd = prefixedString.find('=');
|
||||
// Find second occurence of "&" in prefixedString
|
||||
auto valueEnd = prefixedString.find("&", keyStart + 1);
|
||||
auto valueEnd = prefixedString.find('&', keyStart + 1);
|
||||
if (valueEnd == std::string::npos) {
|
||||
valueEnd = prefixedString.size();
|
||||
}
|
||||
@@ -336,12 +335,11 @@ void bell::HTTPServer::findAndHandleRoute(std::string &url, std::string &body,
|
||||
int connectionFd) {
|
||||
std::map<std::string, std::string> pathParams;
|
||||
std::map<std::string, std::string> queryParams;
|
||||
BELL_LOG(info, "http", "URL %s", url.c_str());
|
||||
|
||||
if (url.find("OPTIONS /") != std::string::npos) {
|
||||
std::stringstream stream;
|
||||
stream << "HTTP/1.1 200 OK\r\n";
|
||||
stream << "Server: EUPHONIUM\r\n";
|
||||
stream << "Server: bell-http\r\n";
|
||||
stream << "Allow: OPTIONS, GET, HEAD, POST\r\n";
|
||||
stream << "Connection: close\r\n";
|
||||
stream << "Access-Control-Allow-Origin: *\r\n";
|
||||
@@ -377,9 +375,9 @@ void bell::HTTPServer::findAndHandleRoute(std::string &url, std::string &body,
|
||||
continue;
|
||||
}
|
||||
|
||||
path = path.substr(0, path.find(" "));
|
||||
path = path.substr(0, path.find(' '));
|
||||
|
||||
if (path.find("?") != std::string::npos) {
|
||||
if (path.find('?') != std::string::npos) {
|
||||
auto urlEncodedSplit = splitUrl(path, '?');
|
||||
path = urlEncodedSplit[0];
|
||||
queryParams = this->parseQueryString(urlEncodedSplit[1]);
|
||||
@@ -406,19 +404,20 @@ void bell::HTTPServer::findAndHandleRoute(std::string &url, std::string &body,
|
||||
matches = false;
|
||||
}
|
||||
|
||||
if (routeSplit.back().find("*") != std::string::npos &&
|
||||
if (routeSplit.back().find('*') != std::string::npos &&
|
||||
urlSplit[1] == routeSplit[1]) {
|
||||
matches = true;
|
||||
}
|
||||
|
||||
if (matches) {
|
||||
if (body.find("&") != std::string::npos) {
|
||||
if (body.find('&') != std::string::npos) {
|
||||
queryParams = this->parseQueryString(body);
|
||||
}
|
||||
|
||||
HTTPRequest req = {.urlParams = pathParams,
|
||||
.queryParams = queryParams,
|
||||
.body = body,
|
||||
.url = path,
|
||||
.handlerId = 0,
|
||||
.connection = connectionFd};
|
||||
|
||||
|
||||
@@ -21,25 +21,10 @@ bell::TLSSocket::TLSSocket()
|
||||
}
|
||||
}
|
||||
|
||||
void bell::TLSSocket::open(std::string url)
|
||||
void bell::TLSSocket::open(std::string hostUrl, uint16_t port)
|
||||
{
|
||||
// initialize
|
||||
int ret;
|
||||
url.erase(0, url.find("://") + 3);
|
||||
std::string hostUrl = url.substr(0, url.find('/'));
|
||||
std::string pathUrl = url.substr(url.find('/'));
|
||||
|
||||
std::string portString = "443";
|
||||
// check if hostUrl contains ':'
|
||||
if (hostUrl.find(':') != std::string::npos)
|
||||
{
|
||||
// split by ':'
|
||||
std::string host = hostUrl.substr(0, hostUrl.find(':'));
|
||||
portString = hostUrl.substr(hostUrl.find(':') + 1);
|
||||
hostUrl = host;
|
||||
}
|
||||
|
||||
if ((ret = mbedtls_net_connect(&server_fd, hostUrl.c_str(), "443",
|
||||
if ((ret = mbedtls_net_connect(&server_fd, hostUrl.c_str(), std::to_string(port).c_str(),
|
||||
MBEDTLS_NET_PROTO_TCP)) != 0)
|
||||
{
|
||||
BELL_LOG(error, "http_tls", "failed! connect returned %d\n", ret);
|
||||
@@ -82,6 +67,10 @@ size_t bell::TLSSocket::write(uint8_t *buf, size_t len)
|
||||
return mbedtls_ssl_write(&ssl, buf, len);
|
||||
}
|
||||
|
||||
size_t bell::TLSSocket::poll() {
|
||||
return mbedtls_ssl_get_bytes_avail(&ssl);
|
||||
}
|
||||
|
||||
void bell::TLSSocket::close()
|
||||
{
|
||||
mbedtls_net_free(&server_fd);
|
||||
|
||||
@@ -11,7 +11,7 @@ bell::TLSSocket::TLSSocket() {
|
||||
ctx = SSL_CTX_new(SSLv23_client_method());
|
||||
}
|
||||
|
||||
void bell::TLSSocket::open(std::string url) {
|
||||
void bell::TLSSocket::open(std::string host, uint16_t port) {
|
||||
|
||||
/* We'd normally set some stuff like the verify paths and
|
||||
* mode here because as things stand this will connect to
|
||||
@@ -23,21 +23,8 @@ void bell::TLSSocket::open(std::string url) {
|
||||
BIO_get_ssl(sbio, &ssl);
|
||||
SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
|
||||
|
||||
url.erase(0, url.find("://") + 3);
|
||||
std::string hostUrl = url.substr(0, url.find('/'));
|
||||
std::string pathUrl = url.substr(url.find('/'));
|
||||
|
||||
std::string portString = "443";
|
||||
// check if hostUrl contains ':'
|
||||
if (hostUrl.find(':') != std::string::npos) {
|
||||
// split by ':'
|
||||
std::string host = hostUrl.substr(0, hostUrl.find(':'));
|
||||
portString = hostUrl.substr(hostUrl.find(':') + 1);
|
||||
hostUrl = host;
|
||||
}
|
||||
|
||||
BELL_LOG(info, "http_tls", "Connecting with %s", hostUrl.c_str());
|
||||
BIO_set_conn_hostname(sbio, std::string(hostUrl + ":443").c_str());
|
||||
BELL_LOG(info, "http_tls", "Connecting with %s", host.c_str());
|
||||
BIO_set_conn_hostname(sbio, std::string(host + ":" + std::to_string(port)).c_str());
|
||||
|
||||
out = BIO_new_fp(stdout, BIO_NOCLOSE);
|
||||
if (BIO_do_connect(sbio) <= 0) {
|
||||
@@ -63,6 +50,10 @@ size_t bell::TLSSocket::write(uint8_t *buf, size_t len) {
|
||||
return BIO_write(sbio, buf, len);
|
||||
}
|
||||
|
||||
size_t bell::TLSSocket::poll() {
|
||||
return BIO_pending(sbio);
|
||||
}
|
||||
|
||||
void bell::TLSSocket::close() {
|
||||
if (!isClosed) {
|
||||
BIO_free_all(sbio);
|
||||
|
||||
Reference in New Issue
Block a user