#ifndef LLDB_UTILITY_URIPARSER_H
#define LLDB_UTILITY_URIPARSER_H
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
namespace lldb_private {
// RETURN VALUE
// if url is valid, function returns true and
// scheme/hostname/port/path are set to the parsed values
- // port it set to -1 if it is not included in the URL
+ // port it set to llvm::None if it is not included in the URL
//
// if the url is invalid, function returns false and
// output parameters remain unchanged
static bool Parse(llvm::StringRef uri, llvm::StringRef &scheme,
- llvm::StringRef &hostname, int &port,
+ llvm::StringRef &hostname, llvm::Optional<uint16_t> &port,
llvm::StringRef &path);
};
}
if (!m_remote_platform_sp)
m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
- int port;
+ llvm::Optional<uint16_t> port;
llvm::StringRef scheme, host, path;
const char *url = args.GetArgumentAtIndex(0);
if (!url)
return Status(
"\"platform connect\" takes a single argument: <connect-url>");
- int remote_port;
+ llvm::Optional<uint16_t> remote_port;
llvm::StringRef scheme, host, path;
const char *url = args.GetArgumentAtIndex(0);
if (!url)
m_socket_namespace = AdbClient::UnixSocketNamespaceAbstract;
std::string connect_url;
- auto error =
- MakeConnectURL(g_remote_platform_pid, (remote_port < 0) ? 0 : remote_port,
- path, connect_url);
+ auto error = MakeConnectURL(g_remote_platform_pid, remote_port.getValueOr(0),
+ path, connect_url);
if (error.Fail())
return error;
// any other valid pid on android.
static lldb::pid_t s_remote_gdbserver_fake_pid = 0xffffffffffffffffULL;
- int remote_port;
+ llvm::Optional<uint16_t> remote_port;
llvm::StringRef scheme, host, path;
if (!UriParser::Parse(connect_url, scheme, host, remote_port, path)) {
error.SetErrorStringWithFormat("Invalid URL: %s",
std::string new_connect_url;
error = MakeConnectURL(s_remote_gdbserver_fake_pid--,
- (remote_port < 0) ? 0 : remote_port, path,
- new_connect_url);
+ remote_port.getValueOr(0), path, new_connect_url);
if (error.Fail())
return nullptr;
if (!url)
return Status("URL is null.");
- int port;
+ llvm::Optional<uint16_t> port;
llvm::StringRef scheme, hostname, pathname;
if (!UriParser::Parse(url, scheme, hostname, port, pathname))
return Status("Invalid URL: %s", url);
#include "lldb/Utility/State.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/UnimplementedError.h"
-#include "lldb/Utility/UriParser.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/ScopedPrinter.h"
if (m_socket_protocol == Socket::ProtocolTcp) {
llvm::StringRef platform_scheme;
llvm::StringRef platform_ip;
- int platform_port;
+ llvm::Optional<uint16_t> platform_port;
llvm::StringRef platform_path;
std::string platform_uri = GetConnection()->GetURI();
bool ok = UriParser::Parse(platform_uri, platform_scheme, platform_ip,
// UriParser::Parse
bool UriParser::Parse(llvm::StringRef uri, llvm::StringRef &scheme,
- llvm::StringRef &hostname, int &port,
+ llvm::StringRef &hostname, llvm::Optional<uint16_t> &port,
llvm::StringRef &path) {
llvm::StringRef tmp_scheme, tmp_hostname, tmp_path;
return false;
port = port_value;
} else
- port = -1;
+ port = llvm::None;
scheme = tmp_scheme;
hostname = tmp_hostname;
error.Clear();
Socket::SocketProtocol socket_protocol = Socket::ProtocolUnixDomain;
- int port;
+ llvm::Optional<uint16_t> port;
StringRef scheme, host, path;
// Try to match socket name as URL - e.g., tcp://localhost:5555
if (UriParser::Parse(name, scheme, host, port, path)) {
llvm::StringRef scheme;
llvm::StringRef hostname;
- int port;
+ llvm::Optional<uint16_t> port;
llvm::StringRef path;
std::string uri(connection_file_descriptor.GetURI());
EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path));
EXPECT_EQ(ip, hostname);
- EXPECT_EQ(socket->GetRemotePortNumber(), port);
+ EXPECT_EQ(socket->GetRemotePortNumber(), port.getValue());
}
};
llvm::StringRef scheme;
llvm::StringRef hostname;
- int port;
+ llvm::Optional<uint16_t> port;
llvm::StringRef path;
std::string uri(socket_a_up->GetRemoteConnectionURI());
EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path));
llvm::StringRef scheme;
llvm::StringRef hostname;
- int port;
+ llvm::Optional<uint16_t> port;
llvm::StringRef path;
std::string uri = socket.get()->GetRemoteConnectionURI();
EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path));
llvm::StringRef scheme;
llvm::StringRef hostname;
- int port;
+ llvm::Optional<uint16_t> port;
llvm::StringRef path;
std::string uri(socket_a_up->GetRemoteConnectionURI());
EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path));
class UriTestCase {
public:
UriTestCase(const char *uri, const char *scheme, const char *hostname,
- int port, const char *path)
+ llvm::Optional<uint16_t> port, const char *path)
: m_uri(uri), m_result(true), m_scheme(scheme), m_hostname(hostname),
m_port(port), m_path(path) {}
bool m_result;
const char *m_scheme;
const char *m_hostname;
- int m_port;
+ llvm::Optional<uint16_t> m_port;
const char *m_path;
};
#define VALIDATE \
llvm::StringRef scheme(kAsdf); \
llvm::StringRef hostname(kAsdf); \
- int port(1138); \
+ llvm::Optional<uint16_t> port(1138); \
llvm::StringRef path(kAsdf); \
EXPECT_EQ(testCase.m_result, \
UriParser::Parse(testCase.m_uri, scheme, hostname, port, path)); \
EXPECT_STREQ(testCase.m_path, path.str().c_str());
TEST(UriParserTest, Minimal) {
- const UriTestCase testCase("x://y", "x", "y", -1, "/");
+ const UriTestCase testCase("x://y", "x", "y", llvm::None, "/");
VALIDATE
}
const UriTestCase testCase("x://y:1", "x", "y", 1, "/");
llvm::StringRef scheme(kAsdf);
llvm::StringRef hostname(kAsdf);
- int port(1138);
+ llvm::Optional<uint16_t> port(1138);
llvm::StringRef path(kAsdf);
bool result = UriParser::Parse(testCase.m_uri, scheme, hostname, port, path);
EXPECT_EQ(testCase.m_result, result);
}
TEST(UriParserTest, MinimalPath) {
- const UriTestCase testCase("x://y/", "x", "y", -1, "/");
+ const UriTestCase testCase("x://y/", "x", "y", llvm::None, "/");
VALIDATE
}
}
TEST(UriParserTest, LongPath) {
- const UriTestCase testCase("x://y/abc/def/xyz", "x", "y", -1, "/abc/def/xyz");
+ const UriTestCase testCase("x://y/abc/def/xyz", "x", "y", llvm::None,
+ "/abc/def/xyz");
VALIDATE
}
"192.168.100.132", 5432, "/");
llvm::StringRef scheme(kAsdf);
llvm::StringRef hostname(kAsdf);
- int port(1138);
+ llvm::Optional<uint16_t> port(1138);
llvm::StringRef path(kAsdf);
bool result = UriParser::Parse(testCase.m_uri, scheme, hostname, port, path);
EXPECT_EQ(testCase.m_result, result);
TEST(UriParserTest, BracketedHostname) {
const UriTestCase testCase("connect://[192.168.100.132]", "connect",
- "192.168.100.132", -1, "/");
+ "192.168.100.132", llvm::None, "/");
VALIDATE
}
TEST(UriParserTest, BracketedHostnameWithPortIPv4) {
// Android device over IPv4: port is a part of the hostname.
const UriTestCase testCase("connect://[192.168.100.132:1234]", "connect",
- "192.168.100.132:1234", -1, "/");
+ "192.168.100.132:1234", llvm::None, "/");
VALIDATE
}
// Android device over IPv6: port is a part of the hostname.
const UriTestCase testCase(
"connect://[[2601:600:107f:db64:a42b:4faa:284]:1234]", "connect",
- "[2601:600:107f:db64:a42b:4faa:284]:1234", -1, "/");
+ "[2601:600:107f:db64:a42b:4faa:284]:1234", llvm::None, "/");
VALIDATE
}