diff options
Diffstat (limited to 'common/network/TcpSocket.cxx')
-rw-r--r-- | common/network/TcpSocket.cxx | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index ec36b33d..4feab0ae 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -504,13 +504,13 @@ void network::createTcpListeners(std::list<SocketListener*> *listeners, TcpFilter::TcpFilter(const char* spec) { - rfb::CharArray tmp; - tmp.buf = rfb::strDup(spec); - while (tmp.buf) { - rfb::CharArray first; - rfb::strSplit(tmp.buf, ',', &first.buf, &tmp.buf); - if (strlen(first.buf)) - filter.push_back(parsePattern(first.buf)); + std::vector<std::string> patterns; + + patterns = rfb::strSplit(spec, ','); + + for (size_t i = 0; i < patterns.size(); i++) { + if (!patterns[i].empty()) + filter.push_back(parsePattern(patterns[i].c_str())); } } @@ -603,14 +603,16 @@ TcpFilter::verifyConnection(Socket* s) { TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { TcpFilter::Pattern pattern; - rfb::CharArray addr, pref; - bool prefix_specified; + std::vector<std::string> parts; int family; initSockets(); - prefix_specified = rfb::strSplit(&p[1], '/', &addr.buf, &pref.buf); - if (addr.buf[0] == '\0') { + parts = rfb::strSplit(&p[1], '/'); + if (parts.size() > 2) + throw Exception("invalid filter specified"); + + if (parts[0].empty()) { // Match any address memset (&pattern.address, 0, sizeof (pattern.address)); pattern.address.u.sa.sa_family = AF_UNSPEC; @@ -618,22 +620,19 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { } else { struct addrinfo hints; struct addrinfo *ai; - char *p = addr.buf; int result; memset (&hints, 0, sizeof (hints)); hints.ai_family = AF_UNSPEC; hints.ai_flags = AI_NUMERICHOST; // Take out brackets, if present - if (*p == '[') { - size_t len; - p++; - len = strlen (p); - if (len > 0 && p[len - 1] == ']') - p[len - 1] = '\0'; + if (parts[0][0] == '[') { + parts[0].erase(0, 1); + if (!parts[0].empty() && parts[0][parts.size()-1] == ']') + parts[0].erase(parts.size()-1, 1); } - if ((result = getaddrinfo (p, NULL, &hints, &ai)) != 0) { + if ((result = getaddrinfo (parts[0].c_str(), NULL, &hints, &ai)) != 0) { throw GAIException("unable to resolve host by name", result); } @@ -642,14 +641,14 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { family = pattern.address.u.sa.sa_family; - if (prefix_specified) { + if (parts.size() > 1) { if (family == AF_INET && - rfb::strContains(pref.buf, '.')) { + (parts[1].find('.') != std::string::npos)) { throw Exception("mask no longer supported for filter, " "use prefix instead"); } - pattern.prefixlen = (unsigned int) atoi(pref.buf); + pattern.prefixlen = (unsigned int) atoi(parts[1].c_str()); } else { switch (family) { case AF_INET: |