mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-28 21:30:54 +03:00
22 lines
583 B
C++
22 lines
583 B
C++
// 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);
|
|
}
|