mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-29 05:40:50 +03:00
more crap
This commit is contained in:
21
components/spotify/cspot/bell/src/BellSocket.cpp
Normal file
21
components/spotify/cspot/bell/src/BellSocket.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Kuba Szczodrzyński 2021-12-21.
|
||||
|
||||
#include "BellSocket.h"
|
||||
#include <cstring>
|
||||
|
||||
void bell::Socket::open(const std::string &url) {
|
||||
auto *urlStr = url.c_str();
|
||||
bool https = urlStr[4] == 's';
|
||||
uint16_t port = https ? 443 : 80;
|
||||
auto *hostname = urlStr + (https ? 8 : 7);
|
||||
auto *hostnameEnd = strchr(hostname, ':');
|
||||
auto *path = strchr(hostname, '/');
|
||||
if (hostnameEnd == nullptr) {
|
||||
hostnameEnd = path;
|
||||
} else {
|
||||
port = strtol(hostnameEnd + 1, nullptr, 10);
|
||||
}
|
||||
auto hostnameStr = std::string(hostname, (const char *)hostnameEnd);
|
||||
|
||||
this->open(hostnameStr, port);
|
||||
}
|
||||
Reference in New Issue
Block a user