Esempio n. 1
0
int cache_remove(MDB_txn *txn, MDB_dbi dbi, const knot_dname_t *name)
{
	struct iter it;
	it.cur = cursor_acquire(txn, dbi);
	if (it.cur == NULL) {
		return KNOT_ERROR;
	}

	int ret = cache_iter_begin(&it, name);
	if (ret == 0) {
		ret = remove_entry(it.cur);
	}

	cursor_release(it.cur);
	return ret;
}
Esempio n. 2
0
int cache_insert(MDB_txn *txn, MDB_dbi dbi, const knot_dname_t *name, struct entry *entry)
{
	MDB_cursor *cursor = cursor_acquire(txn, dbi);
	if (cursor == NULL) {
		return KNOT_ERROR;
	}

	MDB_val key = pack_key(name);
	MDB_val data = { 0, malloc(ENTRY_MAXLEN) };

	int ret = pack_entry(&data, entry);
	if (ret != KNOT_EOK) {
		free(data.mv_data);
		return ret;
	}

	ret = mdb_cursor_put(cursor, &key, &data, 0);
	free(data.mv_data);
	cursor_release(cursor);

	return ret;
}
Esempio n. 3
0
static int rosedb_list(struct cache *cache, MDB_txn *txn, int argc, char *argv[])
{
	MDB_cursor *cursor = cursor_acquire(txn, cache->dbi);
	MDB_val key, data;
	char dname_str[KNOT_DNAME_MAXLEN] = {'\0'};
	char type_str[16] = { '\0' };

	int ret = mdb_cursor_get(cursor, &key, &data, MDB_FIRST);
	while (ret == 0) {
		struct entry entry;
		unpack_entry(&data, &entry);
		knot_dname_to_str(dname_str, key.mv_data, sizeof(dname_str));
		knot_rrtype_to_string(entry.data.type, type_str, sizeof(type_str));
		printf("%s\t%s RDATA=%zuB\t%s\t%s\n", dname_str, type_str,
		       knot_rdataset_size(&entry.data.rrs), entry.threat_code, entry.syslog_ip);

		ret = mdb_cursor_get(cursor, &key, &data, MDB_NEXT);
	}

	cursor_release(cursor);

	return KNOT_EOK;
}