zoneset.cc 809 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include "zoneset.h"

// see findClosest()
static bool
stripLabel(isc::dns::Name& n) {
    std::string str = n.toText(false);
    size_t pos = str.find('.');
    if (pos + 1 < str.size()) {
        n = isc::dns::Name(str.substr(pos+1));
        return true;
    } else {
        return false;
    }
}

bool
ZoneSet::findClosest(const isc::dns::Name& n, isc::dns::Name& closest) {

    // name compare doesnt work in this branch, so we convert and
    // strip labels
    isc::dns::Name cur = n;
    if (contains(n)) {
        closest = n;
        return true;
    }

    bool labels_left = stripLabel(cur);
    while(labels_left) {
        if (contains(cur)) {
            closest = cur;
            return true;
        } else {
            labels_left = stripLabel(cur);
        }
    }
    return false;
}