- // Make sure we have the Metacube sync header at the start.
- // We may need to skip over junk data (it _should_ not happen, though).
- if (!has_metacube_header) {
- char *ptr = static_cast<char *>(
- memmem(pending_data.data(), pending_data.size(),
- METACUBE_SYNC, strlen(METACUBE_SYNC)));
- if (ptr == NULL) {
- // OK, so we didn't find the sync marker. We know then that
- // we do not have the _full_ marker in the buffer, but we
- // could have N-1 bytes. Drop everything before that,
- // and then give up.
- drop_pending_data(pending_data.size() - (strlen(METACUBE_SYNC) - 1));
- return;
- } else {
- // Yay, we found the header. Drop everything (if anything) before it.
- drop_pending_data(ptr - pending_data.data());
- has_metacube_header = true;
-
- // Re-check that we have the entire header; we could have dropped data.
- if (pending_data.size() < sizeof(metacube_block_header)) {
- return;
- }
+ // Split at the first slash, or the first colon that's not within [].
+ bool within_brackets = false;
+ for (split = 0; split < rest.size(); ++split) {
+ if (rest[split] == '[') {
+ if (within_brackets) {
+ // Can't nest brackets.
+ return false;
+ }
+ within_brackets = true;
+ } else if (rest[split] == ']') {
+ if (!within_brackets) {
+ // ] without matching [.
+ return false;