bool entity_addrvec_t::parse(const char *s, const char **end)
{
+ const char *orig_s = s;
const char *static_end;
if (!end) {
end = &static_end;
*end = s;
}
v.clear();
+ bool brackets = false;
+ if (*s == '[') {
+ // weirdness: make sure this isn't an IPV6 addr!
+ entity_addr_t a;
+ const char *p;
+ if (!a.parse(s, &p) || !a.is_ipv6()) {
+ // it's not
+ brackets = true;
+ ++s;
+ }
+ }
while (*s) {
entity_addr_t a;
bool r = a.parse(s, end);
if (!r) {
+ if (brackets) {
+ v.clear();
+ *end = orig_s;
+ return false;
+ }
break;
}
v.push_back(a);
}
++s;
}
+ if (brackets) {
+ if (*s == ']') {
+ ++s;
+ *end = s;
+ } else {
+ *end = orig_s;
+ v.clear();
+ return false;
+ }
+ }
return !v.empty();
}
}
const char *addrvec_parse_checks[][3] = {
+ { "", "", "" },
+ { "foo", "", "foo" },
+ { " foo", "", " foo" },
{ "127.0.0.1", "v2:127.0.0.1:0/0", "" },
{ "127.0.0.1 foo", "v2:127.0.0.1:0/0", " foo" },
{ "127.0.0.1,1.2.3.4 foo", "[v2:127.0.0.1:0/0,v2:1.2.3.4:0/0]", " foo" },
{ "127.0.0.1,::,- foo", "[v2:127.0.0.1:0/0,v2:[::]:0/0,-]", " foo" },
+ { "[127.0.0.1,::,-] foo", "[v2:127.0.0.1:0/0,v2:[::]:0/0,-]", " foo" },
+ { "[127.0.0.1,::],- foo", "[v2:127.0.0.1:0/0,v2:[::]:0/0]", ",- foo" },
+ { "[1.2.3.4,::,foo]", "", "[1.2.3.4,::,foo]" },
+ { "[1.2.3.4,::,- foo", "", "[1.2.3.4,::,- foo" },
+ { "[[::],1.2.3.4]", "[v2:[::]:0/0,v2:1.2.3.4:0/0]", "" },
+ { "[::],1.2.3.4", "[v2:[::]:0/0,v2:1.2.3.4:0/0]", "" },
{ NULL, NULL, NULL },
};