std::shared_ptr<AccessPoint> AccessPoint::create(folly::StringPiece apString, mc_protocol_t defaultProtocol, bool defaultUseSsl, uint16_t portOverride) { if (apString.empty()) { return nullptr; } folly::StringPiece host; if (apString[0] == '[') { // IPv6 auto closing = apString.find(']'); if (closing == std::string::npos) { return nullptr; } host = apString.subpiece(1, closing - 1); apString.advance(closing + 1); } else { // IPv4 or hostname auto colon = apString.find(':'); if (colon == std::string::npos) { host = apString; apString = ""; } else { host = apString.subpiece(0, colon); apString.advance(colon); } } if (host.empty()) { return nullptr; } try { folly::StringPiece port, protocol, encr; parseParts(apString, port, protocol, encr); return std::make_shared<AccessPoint>( host, portOverride != 0 ? portOverride : folly::to<uint16_t>(port), protocol.empty() ? defaultProtocol : parseProtocol(protocol), encr.empty() ? defaultUseSsl : parseSsl(encr)); } catch (const std::exception&) { return nullptr; } }
std::shared_ptr<AccessPoint> AccessPoint::create( folly::StringPiece apString, mc_protocol_t defaultProtocol, SecurityMech defaultMech, uint16_t portOverride, bool defaultCompressed) { if (apString.empty()) { return nullptr; } folly::StringPiece host; bool unixDomainSocket = false; if (apString[0] == '[') { // IPv6 auto closing = apString.find(']'); if (closing == std::string::npos) { return nullptr; } host = apString.subpiece(1, closing - 1); apString.advance(closing + 1); } else { // IPv4 or hostname or UNIX domain socket if (apString.subpiece(0, 5) == "unix:") { // Unix domain socket unixDomainSocket = true; apString.advance(5); } auto colon = apString.find(':'); if (colon == std::string::npos) { host = apString; apString = ""; } else { host = apString.subpiece(0, colon); apString.advance(colon); } } if (host.empty()) { return nullptr; } try { folly::StringPiece port, protocol, encr, comp; if (unixDomainSocket) { port = "0"; parseParts(apString, protocol, encr, comp); // Unix Domain Sockets with SSL is not supported. if (!encr.empty() && parseSecurityMech(encr) != SecurityMech::NONE) { return nullptr; } } else { parseParts(apString, port, protocol, encr, comp); } return std::make_shared<AccessPoint>( host, portOverride != 0 ? portOverride : folly::to<uint16_t>(port), protocol.empty() ? defaultProtocol : parseProtocol(protocol), encr.empty() ? defaultMech : parseSecurityMech(encr), comp.empty() ? defaultCompressed : parseCompressed(comp), unixDomainSocket); } catch (const std::exception&) { return nullptr; } }