Commit 949f7c19 authored by Daniel Salzman's avatar Daniel Salzman

Adapt to trie API change

parent 09ddfdf2
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -832,7 +832,7 @@ static void upd_changes(
}
// Get zone status or create new.
trie_val_t *val = trie_get_ins(zones, (const char *)io->id, io->id_len);
trie_val_t *val = trie_get_ins(zones, io->id, io->id_len);
conf_io_type_t *current = (conf_io_type_t *)val;
switch (type) {
......@@ -850,7 +850,7 @@ static void upd_changes(
case CONF_IO_TUNSET:
if (*current & CONF_IO_TSET) {
// Remove inserted zone -> no change.
trie_del(zones, (const char *)io->id, io->id_len, NULL);
trie_del(zones, io->id, io->id_len, NULL);
} else {
// Remove existing zone.
*current |= type;
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -119,7 +119,7 @@ static int add_view_to_trie(knot_dname_t *owner, geo_view_t *view, geoip_ctx_t *
knot_dname_storage_t lf_storage;
uint8_t *lf = knot_dname_lf(owner, lf_storage);
assert(lf);
trie_val_t *val = trie_get_ins(ctx->geo_trie, (char *)lf + 1, *lf);
trie_val_t *val = trie_get_ins(ctx->geo_trie, lf + 1, *lf);
geo_trie_val_t *cur_val = *val;
if (cur_val == NULL) {
......@@ -542,7 +542,7 @@ static knotd_in_state_t geoip_process(knotd_in_state_t state, knot_pkt_t *pkt,
if (lf == NULL) {
return state;
}
trie_val_t *val = trie_get_try(ctx->geo_trie, (char *)lf + 1, *lf);
trie_val_t *val = trie_get_try(ctx->geo_trie, lf + 1, *lf);
if (val == NULL) {
// Nothing to do in this module.
return state;
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -38,7 +38,7 @@ int zone_tree_insert(zone_tree_t *tree, zone_node_t *node)
uint8_t *lf = knot_dname_lf(node->owner, lf_storage);
assert(lf);
*trie_get_ins(tree, (char *)lf + 1, *lf) = node;
*trie_get_ins(tree, lf + 1, *lf) = node;
return KNOT_EOK;
}
......@@ -57,7 +57,7 @@ zone_node_t *zone_tree_get(zone_tree_t *tree, const knot_dname_t *owner)
uint8_t *lf = knot_dname_lf(owner, lf_storage);
assert(lf);
trie_val_t *val = trie_get_try(tree, (char *)lf + 1, *lf);
trie_val_t *val = trie_get_try(tree, lf + 1, *lf);
if (val == NULL) {
return NULL;
}
......@@ -83,7 +83,7 @@ int zone_tree_get_less_or_equal(zone_tree_t *tree,
assert(lf);
trie_val_t *fval = NULL;
int ret = trie_get_leq(tree, (char *)lf + 1, *lf, &fval);
int ret = trie_get_leq(tree, lf + 1, *lf, &fval);
if (fval != NULL) {
*found = (zone_node_t *)(*fval);
}
......@@ -124,9 +124,9 @@ void zone_tree_remove_node(zone_tree_t *tree, const knot_dname_t *owner)
uint8_t *lf = knot_dname_lf(owner, lf_storage);
assert(lf);
trie_val_t *rval = trie_get_try(tree, (char *)lf + 1, *lf);
trie_val_t *rval = trie_get_try(tree, lf + 1, *lf);
if (rval != NULL) {
trie_del(tree, (char *)lf + 1, *lf, NULL);
trie_del(tree, lf + 1, *lf, NULL);
}
}
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -73,7 +73,7 @@ int knot_zonedb_insert(knot_zonedb_t *db, zone_t *zone)
uint8_t *lf = knot_dname_lf(zone->name, lf_storage);
assert(lf);
*trie_get_ins(db->trie, (char *)lf + 1, *lf) = zone;
*trie_get_ins(db->trie, lf + 1, *lf) = zone;
return KNOT_EOK;
}
......@@ -88,12 +88,12 @@ int knot_zonedb_del(knot_zonedb_t *db, const knot_dname_t *zone_name)
uint8_t *lf = knot_dname_lf(zone_name, lf_storage);
assert(lf);
trie_val_t *rval = trie_get_try(db->trie, (char *)lf + 1, *lf);
trie_val_t *rval = trie_get_try(db->trie, lf + 1, *lf);
if (rval == NULL) {
return KNOT_ENOENT;
}
return trie_del(db->trie, (char *)lf + 1, *lf, NULL);
return trie_del(db->trie, lf + 1, *lf, NULL);
}
zone_t *knot_zonedb_find(knot_zonedb_t *db, const knot_dname_t *zone_name)
......@@ -106,7 +106,7 @@ zone_t *knot_zonedb_find(knot_zonedb_t *db, const knot_dname_t *zone_name)
uint8_t *lf = knot_dname_lf(zone_name, lf_storage);
assert(lf);
trie_val_t *val = trie_get_try(db->trie, (char *)lf + 1, *lf);
trie_val_t *val = trie_get_try(db->trie, lf + 1, *lf);
if (val == NULL) {
return NULL;
}
......@@ -125,7 +125,7 @@ zone_t *knot_zonedb_find_suffix(knot_zonedb_t *db, const knot_dname_t *zone_name
uint8_t *lf = knot_dname_lf(zone_name, lf_storage);
assert(lf);
trie_val_t *val = trie_get_try(db->trie, (char *)lf + 1, *lf);
trie_val_t *val = trie_get_try(db->trie, lf + 1, *lf);
if (val != NULL) {
return *val;
} else if (zone_name[0] == 0) {
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -80,7 +80,7 @@ int lookup_insert(lookup_t *lookup, const char *str, void *data)
return KNOT_EINVAL;
}
trie_val_t *val = trie_get_ins(lookup->trie, str, str_len);
trie_val_t *val = trie_get_ins(lookup->trie, (const trie_key_t *)str, str_len);
if (val == NULL) {
return KNOT_ENOMEM;
}
......@@ -121,7 +121,7 @@ int lookup_search(lookup_t *lookup, const char *str, size_t str_len)
trie_it_t *it = trie_it_begin(lookup->trie);
for (; !trie_it_finished(it); trie_it_next(it)) {
size_t len;
const char *key = trie_it_key(it, &len);
const char *key = (const char *)trie_it_key(it, &len);
// Compare with a shorter key.
if (len < str_len) {
......@@ -196,7 +196,7 @@ void lookup_list(lookup_t *lookup)
trie_it_next(lookup->iter.it);
size_t len;
const char *key = trie_it_key(lookup->iter.it, &len);
const char *key = (const char *)trie_it_key(lookup->iter.it, &len);
int ret = set_key(lookup, &lookup->found.key, key, len);
if (ret == KNOT_EOK) {
......@@ -208,7 +208,7 @@ void lookup_list(lookup_t *lookup)
lookup->iter.it = trie_it_begin(lookup->trie);
while (!trie_it_finished(lookup->iter.it)) {
size_t len;
const char *key = trie_it_key(lookup->iter.it, &len);
const char *key = (const char *)trie_it_key(lookup->iter.it, &len);
if (strncmp(key, lookup->iter.first_key, len) == 0) {
int ret = set_key(lookup, &lookup->found.key, key, len);
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -71,13 +71,13 @@ static int insert_dname_into_table(trie_t *table, const knot_dname_t *d,
{
size_t d_size = knot_dname_size(d);
trie_val_t *val = trie_get_try(table, (char *)d, d_size);
trie_val_t *val = trie_get_try(table, d, d_size);
if (val == NULL) {
// Create new dummy node to use for this dname
*dummy_node = malloc(sizeof(list_t));
assert(dummy_node != NULL);
init_list(*dummy_node);
*trie_get_ins(table, (char *)d, d_size) = *dummy_node;
*trie_get_ins(table, d, d_size) = *dummy_node;
return 0;
} else {
// Return previously found dummy node
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
Copyright (C) 2018 Tony Finch <dot@dotat.at>
This program is free software: you can redistribute it and/or modify
......@@ -79,7 +79,7 @@ grow_leaves(size_t maxlen, size_t leaves)
"abcdefghijklmnopqrstuvwxyz"
[prng(62)];
str[len] = '\0';
valp = trie_get_ins(trie, str, (uint32_t)len);
valp = trie_get_ins(trie, (uint8_t *)str, (uint32_t)len);
if (!valp) bail("trie_get_ins");
} while (*valp != NULL);
*valp = &leaf[i];
......@@ -101,7 +101,7 @@ dead_leaves(struct cowleaf *leaf, size_t leaves)
}
static void
mark_cb(trie_val_t val, const char *key, size_t len, void *d)
mark_cb(trie_val_t val, const uint8_t *key, size_t len, void *d)
{
struct cowleaf *leaf = val;
assert(leaf->cowstate == cow_unmarked &&
......@@ -113,7 +113,7 @@ mark_cb(trie_val_t val, const char *key, size_t len, void *d)
}
static void
commit_rollback(trie_val_t val, const char *key, size_t len, void *d)
commit_rollback(trie_val_t val, const uint8_t *key, size_t len, void *d)
{
struct cowleaf *leaf = val;
int *commit = d;
......@@ -136,7 +136,7 @@ del_cow(trie_cow_t *x, struct cowleaf *leaf)
{
trie_val_t val;
assert(KNOT_EOK == trie_del_cow(x,
leaf->key,
(uint8_t *)leaf->key,
(uint32_t)leaf->len,
&val));
assert(val == leaf);
......@@ -203,8 +203,8 @@ main(int argc, char *argv[])
case(cow_absent): {
trie_val_t *val =
trie_get_cow(x,
leaf[i].key,
(uint32_t)leaf[i].len);
(uint8_t *)leaf[i].key,
(uint32_t)leaf[i].len);
if (!val) sysbail("trie_get_cow");
assert(*val == NULL && "new leaf");
*val = &leaf[i];
......
/* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -69,13 +69,13 @@ static bool str_key_get_leq(trie_t *trie, char **keys, size_t i, size_t size)
/* Before current key. */
key_buf[key_len - 2] -= 1;
if (i < first_key_count) {
ret = trie_get_leq(trie, key_buf, key_len, &val);
ret = trie_get_leq(trie, (uint8_t *)key_buf, key_len, &val);
if (ret != KNOT_ENOENT) {
diag("%s: leq for key BEFORE %zu/'%s' ret = %d", __func__, i, keys[i], ret);
return false; /* No key before first. */
}
} else {
ret = trie_get_leq(trie, key_buf, key_len, &val);
ret = trie_get_leq(trie, (uint8_t *)key_buf, key_len, &val);
if (ret < KNOT_EOK || strcmp(*val, key_buf) > 0) {
diag("%s: '%s' is not before the key %zu/'%s'", __func__, (char*)*val, i, keys[i]);
return false; /* Found key must be LEQ than searched. */
......@@ -84,7 +84,7 @@ static bool str_key_get_leq(trie_t *trie, char **keys, size_t i, size_t size)
/* Current key. */
key_buf[key_len - 2] += 1;
ret = trie_get_leq(trie, key_buf, key_len, &val);
ret = trie_get_leq(trie, (uint8_t *)key_buf, key_len, &val);
if (! (ret == KNOT_EOK && val && strcmp(*val, key_buf) == 0)) {
diag("%s: leq for key %zu/'%s' ret = %d", __func__, i, keys[i], ret);
return false; /* Must find equal match. */
......@@ -92,7 +92,7 @@ static bool str_key_get_leq(trie_t *trie, char **keys, size_t i, size_t size)
/* After the current key. */
key_buf[key_len - 2] += 1;
ret = trie_get_leq(trie, key_buf, key_len, &val);
ret = trie_get_leq(trie, (uint8_t *)key_buf, key_len, &val);
if (! (ret >= KNOT_EOK && strcmp(*val, key_buf) <= 0)) {
diag("%s: leq for key AFTER %zu/'%s' ret = %d %s", __func__, i, keys[i], ret, (char*)*val);
return false; /* Every key must have its LEQ match. */
......@@ -128,7 +128,7 @@ int main(int argc, char *argv[])
bool passed = true;
size_t inserted = 0;
for (unsigned i = 0; i < key_count; ++i) {
val = trie_get_ins(trie, keys[i], strlen(keys[i]) + 1);
val = trie_get_ins(trie, (uint8_t *)keys[i], strlen(keys[i]) + 1);
if (!val) {
passed = false;
break;
......@@ -146,7 +146,7 @@ int main(int argc, char *argv[])
/* Lookup all keys */
passed = true;
for (unsigned i = 0; i < key_count; ++i) {
val = trie_get_try(trie, keys[i], strlen(keys[i]) + 1);
val = trie_get_try(trie, (uint8_t *)keys[i], strlen(keys[i]) + 1);
if (val && (*val == keys[i] || strcmp(*val, keys[i]) == 0)) {
continue;
} else {
......@@ -180,7 +180,7 @@ int main(int argc, char *argv[])
trie_it_t *it = trie_it_begin(trie);
while (!trie_it_finished(it)) {
size_t cur_key_len = 0;
const char *cur_key = trie_it_key(it, &cur_key_len);
const char *cur_key = (const char *)trie_it_key(it, &cur_key_len);
if (iterated > 0) { /* Only if previous exists. */
if (strcmp(key_buf, cur_key) > 0) {
diag("'%s' <= '%s' FAIL\n", key_buf, cur_key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment