OpenDNSSEC-signer  1.3.16
adapi.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (c) 2009-2011 NLNet Labs. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
34 #include "config.h"
35 #include "adapter/adapi.h"
36 #include "shared/duration.h"
37 #include "shared/log.h"
38 #include "shared/status.h"
39 #include "shared/util.h"
40 #include "signer/zone.h"
41 
42 #include <ldns/ldns.h>
43 
44 static const char* adapi_str = "adapter";
45 
46 
51 uint32_t
53 {
54  if (!zone || !zone->zonedata) {
55  ods_log_error("[%s] unable to get serial: "
56  "no zone data", adapi_str);
57  return 0;
58  }
59  ods_log_assert(zone);
60  ods_log_assert(zone->zonedata);
61  return zone->zonedata->inbound_serial;
62 }
63 
64 
69 void
70 adapi_set_serial(zone_type* zone, uint32_t serial)
71 {
72  if (!zone || !zone->zonedata) {
73  ods_log_error("[%s] unable to set serial: "
74  "no zone data", adapi_str);
75  return;
76  }
77  ods_log_assert(zone);
78  ods_log_assert(zone->zonedata);
79  zone->zonedata->inbound_serial = serial;
80  return;
81 }
82 
83 
88 ldns_rdf*
90 {
91  if (!zone) {
92  ods_log_error("[%s] unable to get origin: "
93  "no zone", adapi_str);
94  return NULL;
95  }
96  ods_log_assert(zone);
97  return zone->dname;
98 }
99 
100 
105 uint32_t
107 {
108  if (!zone || !zone->zonedata) {
109  ods_log_error("[%s] unable to get ttl: "
110  "no zone data", adapi_str);
111  return 0;
112  }
113  ods_log_assert(zone);
114  ods_log_assert(zone->zonedata);
115  return zone->zonedata->default_ttl;
116 }
117 
118 
119 /*
120  * Do full zone transaction.
121  *
122  */
125 {
126  if (!zone || !zone->zonedata) {
127  ods_log_error("[%s] unable to start full zone transaction: "
128  "no zone data", adapi_str);
129  return ODS_STATUS_ASSERT_ERR;
130  }
131  ods_log_assert(zone);
132  ods_log_assert(zone->zonedata);
133  if (!zone->signconf) {
134  ods_log_error("[%s] unable to start full zone transaction: "
135  "no signer configuration", adapi_str);
136  return ODS_STATUS_ASSERT_ERR;
137  }
138  ods_log_assert(zone->signconf);
139 
140  return zonedata_diff(zone->zonedata, zone->signconf->keys);
141 }
142 
143 
144 /*
145  * Do incremental zone transaction.
146  *
147  */
150 {
151  if (!zone || !zone->zonedata) {
152  ods_log_error("[%s] unable to start incremental zone transaction: "
153  "no zone data", adapi_str);
154  return ODS_STATUS_ASSERT_ERR;
155  }
156  ods_log_assert(zone);
157  ods_log_assert(zone->zonedata);
158 
159  return ODS_STATUS_OK;
160 }
161 
162 
168 adapi_add_rr(zone_type* zone, ldns_rr* rr)
169 {
170  return zone_add_rr(zone, rr, 1);
171 }
172 
173 
179 adapi_del_rr(zone_type* zone, ldns_rr* rr)
180 {
181  return zone_del_rr(zone, rr, 1);
182 }
uint32_t adapi_get_serial(zone_type *zone)
Definition: adapi.c:52
keylist_type * keys
Definition: signconf.h:71
enum ods_enum_status ods_status
Definition: status.h:64
ldns_rdf * dname
Definition: zone.h:59
void ods_log_error(const char *format,...)
Definition: log.c:349
ods_status adapi_trans_full(zone_type *zone)
Definition: adapi.c:124
ods_status adapi_add_rr(zone_type *zone, ldns_rr *rr)
Definition: adapi.c:168
void adapi_set_serial(zone_type *zone, uint32_t serial)
Definition: adapi.c:70
ods_status zonedata_diff(zonedata_type *zd, keylist_type *kl)
Definition: zonedata.c:658
signconf_type * signconf
Definition: zone.h:81
ldns_rdf * adapi_get_origin(zone_type *zone)
Definition: adapi.c:89
ods_status zone_add_rr(zone_type *zone, ldns_rr *rr, int do_stats)
Definition: zone.c:144
ods_status adapi_trans_diff(zone_type *zone)
Definition: adapi.c:149
uint32_t default_ttl
Definition: zonedata.h:65
ods_status zone_del_rr(zone_type *zone, ldns_rr *rr, int do_stats)
Definition: zone.c:271
uint32_t inbound_serial
Definition: zonedata.h:66
uint32_t adapi_get_ttl(zone_type *zone)
Definition: adapi.c:106
ods_status adapi_del_rr(zone_type *zone, ldns_rr *rr)
Definition: adapi.c:179
zonedata_type * zonedata
Definition: zone.h:85
#define ods_log_assert(x)
Definition: log.h:141