Commit Diff
Diff:
f549e738b964101e3cf308750d793891478075a3
2232fe09978cfeab10096e4c4a1242d931f7e9bb
Commit:
2232fe09978cfeab10096e4c4a1242d931f7e9bb
Tree:
d97fcf5fed5a13150586aa7ded964a75c3474f39
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Tue Feb 19 11:49:54 2019 UTC
Message:
Before this change, the db wasn't really needed, but I had it on anyways, for good reason, because now db is needed to access any form of database, it's not global anymore. This paves way to have several db's if we wish.
blob - 411beeca9e0d5dc6ccfd4841555039b4c948bc78
blob + 02818668e483a78f24add75fe15cbc7a9407781c
--- axfr.c
+++ axfr.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: axfr.c,v 1.20 2019/02/15 15:11:34 pjp Exp $
+ * $Id: axfr.c,v 1.21 2019/02/19 11:49:54 pjp Exp $
*/
#include "ddd-include.h"
@@ -69,6 +69,7 @@ extern struct rrset * find_rr(struct rbtree *rbt, u_in
extern int display_rr(struct rrset *rrset);
extern int rotate_rr(struct rrset *rrset);
+extern int domaincmp(struct node *e1, struct node *e2);
int notify = 0; /* do not notify when set to 0 */
@@ -111,11 +112,7 @@ static struct notifyentry {
extern int domaincmp(struct node *e1, struct node *e2);
static int check_notifyreply(struct dns_header *, struct question *, struct sockaddr_storage *, int, struct notifyentry *, int);
-RB_HEAD(domaintree, node) rbhead;
-RB_PROTOTYPE_STATIC(domaintree, node, rbentry, domaincmp)
-RB_GENERATE_STATIC(domaintree, node, rbentry, domaincmp)
-
/*
* INIT_AXFR - initialize the axfr singly linked list
*/
@@ -905,7 +902,7 @@ axfr_connection(int so, char *address, int is_ipv6, dd
outlen = build_soa(db, (reply + 2), outlen, soa, question);
rrcount = 1;
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rs = n->datalen;
if ((rbt = calloc(1, sizeof(struct rbtree))) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
@@ -1294,7 +1291,7 @@ gather_notifydomains(ddDB *db)
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rbt = (struct rbtree *)n->data;
if ((rrset = find_rr(rbt, DNS_TYPE_SOA)) != NULL) {
blob - 5dc7eba4423b92ad5295171cf24451648d625246
blob + 50f1820fac53ab56eae5c0633162e7746fa7719d
--- db.c
+++ db.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: db.c,v 1.9 2019/02/19 07:31:31 pjp Exp $
+ * $Id: db.c,v 1.10 2019/02/19 11:49:54 pjp Exp $
*/
#include "ddd-include.h"
@@ -44,7 +44,10 @@ int rotate_rr(struct rrset *rrset);
extern void dolog(int, char *, ...);
extern char * convert_name(char *, int);
+int domaincmp(struct node *e1, struct node *e2);
+
+
int
domaincmp(struct node *e1, struct node *e2)
{
@@ -58,12 +61,6 @@ domaincmp(struct node *e1, struct node *e2)
}
-RB_HEAD(domaintree, node) rbhead = RB_INITIALIZER(&rbhead);
-RB_PROTOTYPE(domaintree, node, rbentry, domaincmp)
-RB_GENERATE(domaintree, node, rbentry, domaincmp)
-
-
-
ddDB *
dddbopen(void)
{
@@ -79,6 +76,8 @@ dddbopen(void)
db->get = dddbget;
db->close = dddbclose;
db->offset = 0;
+
+ RB_INIT(&db->head);
return (db);
}
@@ -92,7 +91,7 @@ dddbput(ddDB *db, ddDBT *key, ddDBT *data)
strlcpy(find.domainname, key->data, sizeof(find.domainname));
find.len = key->size;
- res = RB_FIND(domaintree, &rbhead, &find);
+ res = RB_FIND(domaintree, &db->head, &find);
if (res == NULL) {
/* does not exist, create it */
@@ -112,7 +111,7 @@ dddbput(ddDB *db, ddDBT *key, ddDBT *data)
n->datalen = data->size;
memcpy(map, data->data, data->size);
- RB_INSERT(domaintree, &rbhead, n);
+ RB_INSERT(domaintree, &db->head, n);
} else {
if (res->datalen != data->size)
return -1;
@@ -132,7 +131,7 @@ dddbget(ddDB *db, ddDBT *key, ddDBT *data)
strlcpy(find.domainname, key->data, sizeof(find.domainname));
find.len = key->size;
- res = RB_FIND(domaintree, &rbhead, &find);
+ res = RB_FIND(domaintree, &db->head, &find);
if (res == NULL) {
return -1;
}
blob - 4551229264aa8574990b12c427a9bd95de02682e
blob + 4b24c6c3e33216ba4772cdbc4a7341c785c57607
--- ddd-db.h
+++ ddd-db.h
@@ -27,7 +27,7 @@
*/
/*
- * $Id: ddd-db.h,v 1.14 2019/02/15 19:46:58 pjp Exp $
+ * $Id: ddd-db.h,v 1.15 2019/02/19 11:49:54 pjp Exp $
*/
#ifndef _DB_H
@@ -280,6 +280,19 @@ typedef struct {
char *data;
} ddDBT;
+struct node {
+ RB_ENTRY(node) rbentry; /* the node entry */
+ char domainname[DNS_MAXNAME + 1]; /* domain name key name */
+ int len; /* length of domain name */
+ char *data; /* data it points to */
+ size_t datalen; /* the length of the data */
+};
+
+
+extern int domaincmp(struct node *e1, struct node *e2);
+
+RB_HEAD(domaintree, node);
+RB_GENERATE_STATIC(domaintree, node, rbentry, domaincmp)
typedef struct __dddb {
int (*put)(struct __dddb *, ddDBT *, ddDBT *);
int (*get)(struct __dddb *, ddDBT *, ddDBT *);
@@ -288,6 +301,7 @@ typedef struct __dddb {
size_t offset;
size_t size;
char *nodes;
+ struct domaintree head;
} ddDB;
@@ -311,14 +325,6 @@ struct rbtree {
char humanname[DNS_MAXNAME + 1];
TAILQ_HEAD(, rrset) rrset_head;
-};
-
-struct node {
- RB_ENTRY(node) rbentry; /* the node entry */
- char domainname[DNS_MAXNAME + 1]; /* domain name key name */
- int len; /* length of domain name */
- char *data; /* data it points to */
- size_t datalen; /* the length of the data */
};
struct rrtab {
blob - e104ef97095a1ac0cc17d1fbd70b4f101e5c14c6
blob + 8fc03bd16f62abc3fc700021564a2d682d8dd945
--- dddctl.c
+++ dddctl.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: dddctl.c,v 1.52 2019/02/19 11:24:50 pjp Exp $
+ * $Id: dddctl.c,v 1.53 2019/02/19 11:49:54 pjp Exp $
*/
#include "ddd-include.h"
@@ -287,11 +287,6 @@ extern int memcasecmp(u_char *, u
extern int dnssec;
-extern int domaincmp(struct node *e1, struct node *e2);
-RB_HEAD(domaintree, node) rbhead;
-RB_GENERATE_STATIC(domaintree, node, rbentry, domaincmp)
-
-
static struct raxfr_logic {
int rrtype;
int dnssec;
@@ -1040,7 +1035,7 @@ dump_db(ddDB *db, FILE *of, char *zonename)
memset(&data, 0, sizeof(data));
j = 0;
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rs = n->datalen;
if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
@@ -1422,7 +1417,7 @@ calculate_rrsigs(ddDB *db, char *zonename, int expiry)
j = 0;
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rs = n->datalen;
if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
@@ -6117,7 +6112,7 @@ construct_nsec3(ddDB *db, char *zone, int iterations,
j = 0;
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rs = n->datalen;
if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
@@ -6210,7 +6205,7 @@ construct_nsec3(ddDB *db, char *zone, int iterations,
/* check ENT's which we'll create */
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rs = n->datalen;
if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
@@ -7860,7 +7855,7 @@ dump_db_bind(ddDB *db, FILE *of, char *zonename)
memset(&data, 0, sizeof(data));
j = 0;
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rs = n->datalen;
if ((rbt0 = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
@@ -8423,7 +8418,7 @@ count_db(ddDB *db)
int count = 0;
int rs;
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rs = n->datalen;
if ((rbt = calloc(1, rs)) == NULL) {
dolog(LOG_INFO, "calloc: %s\n", strerror(errno));
blob - 37c6ebcdf55e934453a54f46c3b8716fae0c01d5
blob + 4b619966415aa0c67304c5fafe4daa4d4dceef5d
--- ent.c
+++ ent.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: ent.c,v 1.8 2019/02/15 15:11:34 pjp Exp $
+ * $Id: ent.c,v 1.9 2019/02/19 11:49:54 pjp Exp $
*/
/*
@@ -59,10 +59,6 @@ static struct ententry {
extern int domaincmp(struct node *e1, struct node *e2);
-RB_HEAD(domaintree, node) rbhead;
-RB_PROTOTYPE_STATIC(domaintree, node, rbentry, domaincmp)
-RB_GENERATE_STATIC(domaintree, node, rbentry, domaincmp)
-
/*
* INIT_ENTLIST - initialize the ent singly linked list
*/
@@ -75,7 +71,7 @@ init_entlist(ddDB *db)
SLIST_INIT(&enthead);
- RB_FOREACH_SAFE(n, domaintree, &rbhead, nx) {
+ RB_FOREACH_SAFE(n, domaintree, &db->head, nx) {
rbt = (struct rbtree *)n->data;
ent2 = malloc(sizeof(struct ententry));
if (ent2 == NULL) {
repomaster@centroid.eu