Skip to content
Snippets Groups Projects
Commit a83c5e2d authored by Daniel Salzman's avatar Daniel Salzman
Browse files

descriptor: remove dependency on common source files

parent 7bc61a46
Branches
Tags
1 merge request!12Make zscanner more independent from common source
......@@ -16,25 +16,19 @@
#include <config.h>
#include "common/descriptor.h"
#include "libknot/util/utils.h" // knot_lookup_table_t
#include <stdio.h> // snprintf
#include <stdlib.h> // strtoul
/*!
* \brief The last RR type number in the descriptors table.
*/
const int KNOT_RRTYPE_LAST = KNOT_RRTYPE_ANY;
#include <strings.h> // strcasecmp
/*!
* \brief Table with DNS classes.
*/
static knot_lookup_table_t dns_classes[] = {
{ KNOT_CLASS_IN, "IN" },
{ KNOT_CLASS_CH, "CH" },
{ KNOT_CLASS_NONE, "NONE" },
{ KNOT_CLASS_ANY, "ANY" },
{ 0, NULL }
static const char* dns_classes[] = {
[KNOT_CLASS_IN] = "IN",
[KNOT_CLASS_CH] = "CH",
[KNOT_CLASS_NONE] = "NONE",
[KNOT_CLASS_ANY] = "ANY"
};
/*!
......@@ -133,12 +127,13 @@ static const rdata_descriptor_t rdata_descriptors[] = {
[KNOT_RRTYPE_AXFR] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "AXFR" },
[KNOT_RRTYPE_ANY] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END }, "ANY" },
KNOT_RDATA_WF_END }, "ANY" }
};
const rdata_descriptor_t *get_rdata_descriptor(const uint16_t type)
{
if (type <= KNOT_RRTYPE_ANY && rdata_descriptors[type].type_name != 0) {
if (type <= KNOT_RRTYPE_ANY &&
rdata_descriptors[type].type_name != NULL) {
return &rdata_descriptors[type];
} else {
return &rdata_descriptors[0];
......@@ -153,7 +148,7 @@ int knot_rrtype_to_string(const uint16_t rrtype,
const rdata_descriptor_t *descr = get_rdata_descriptor(rrtype);
if (descr->type_name != 0) {
if (descr->type_name != NULL) {
ret = snprintf(out, out_len, "%s", descr->type_name);
} else {
ret = snprintf(out, out_len, "TYPE%u", rrtype);
......@@ -173,8 +168,8 @@ int knot_rrtype_from_string(const char *name, uint16_t *num)
unsigned long n;
// Try to find name in descriptors table.
for (i = 0; i <= KNOT_RRTYPE_LAST; i++) {
if (rdata_descriptors[i].type_name != 0 &&
for (i = 0; i <= KNOT_RRTYPE_ANY; i++) {
if (rdata_descriptors[i].type_name != NULL &&
strcasecmp(rdata_descriptors[i].type_name, name) == 0) {
*num = i;
return 0;
......@@ -204,10 +199,8 @@ int knot_rrclass_to_string(const uint16_t rrclass,
{
int ret;
knot_lookup_table_t *entry = knot_lookup_by_id(dns_classes, rrclass);
if (entry != NULL) {
ret = snprintf(out, out_len, "%s", entry->name);
if (rrclass <= KNOT_CLASS_ANY && dns_classes[rrclass] != NULL) {
ret = snprintf(out, out_len, "%s", dns_classes[rrclass]);
} else {
ret = snprintf(out, out_len, "CLASS%u", rrclass);
}
......@@ -221,15 +214,17 @@ int knot_rrclass_to_string(const uint16_t rrclass,
int knot_rrclass_from_string(const char *name, uint16_t *num)
{
int i;
char *end;
unsigned long n;
// Try to find name in lookup table.
knot_lookup_table_t *entry = knot_lookup_by_name(dns_classes, name);
if (entry != NULL) {
*num = entry->id;
return 0;
// Try to find the name in classes table.
for (i = 0; i <= KNOT_CLASS_ANY; i++) {
if (dns_classes[i] != NULL &&
strcasecmp(dns_classes[i], name) == 0) {
*num = i;
return 0;
}
}
// Class name must begin with CLASS.
......
......@@ -16,6 +16,7 @@
/*!
* \file descriptor.h
*
* \author Daniel Salzman <daniel.salzman@nic.cz>
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* \addtogroup common_lib
......@@ -32,6 +33,8 @@
/*!
* \brief Resource record class codes.
*
* http://www.iana.org/assignments/dns-parameters/dns-parameters.xml
*/
enum knot_rr_class {
KNOT_CLASS_IN = 1,
......@@ -121,7 +124,7 @@ enum knot_rdata_wireformat {
KNOT_RDATA_WF_LITERAL_DNAME,
/*!< Initial part of NAPTR record before dname. */
KNOT_RDATA_WF_NAPTR_HEADER,
/*!< Uninteresting final part of a record. */
/*!< Final part of a record. */
KNOT_RDATA_WF_REMAINDER,
/*!< The last descriptor in array. */
KNOT_RDATA_WF_END = 0
......@@ -140,7 +143,7 @@ typedef struct {
/*!
* \brief Gets rdata descriptor for given RR name.
*
* \param name Mnemonic of RR type whose descriptor should be retvaled.
* \param name Mnemonic of RR type whose descriptor should be returned.
*
* \retval RR descriptor for given name, NULL descriptor if
* unknown type.
......
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