more crap

This commit is contained in:
Philippe G
2022-01-04 17:22:32 -08:00
parent 47ad526890
commit 54440e87b6
10 changed files with 294 additions and 626 deletions

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