-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproto.h
252 lines (227 loc) · 12.3 KB
/
proto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#ifndef PROTO_H
#define PROTO_H
/*
* Definitions relating to an iterator. An iterator is a object handle that
* allows you to loop over the elements contained in some abstract data
* structure. The properties are dictated by the data structure, e.g. if the
* data structure guarantees a certain order, then the elements are returned
* in order, and whether the elements may be modified is also governed by
* the data structure. An iterator is obtained from the data structure
* related functions. The iterator functions only hide the implementation
* details of the data structure, so that you do not faced whether to follow
* a next pointer or other method to traverse the abstract data structure.
*
* An iterator is a cursor into a set of items. Initial, the cursor is
* placed on the first item. The entire set of items must be iterated over,
* or the end() call must be used to terminate the iteration of elements,
* however it should be assumed performance is directly proportionally with
* the number of items in the set, NOT the actual number of items iterated
* over. Additionally obtaining an iterator should be assumed to have a
* significant performance impact. With both assumptions in mind, you
* should get the right type of iteration in place, which retrieved indeed
* the set of items needed, rather than just one every time or all of the
* items in the data structure.
*
* Two typical usaged could be:
* struct mystruct* item;
* iterator iter = getiterator(...);
* if(iterate(&iter, &item)) {
* printf("%s",item->myname);
* while(advance(&iter, &item)) {
* printf(",%s", item->myname);
* if(need_bail_out()) {
* end(&iter);
* break;
* }
* }
* printf("\n");
* } else
* printf("There are no items\n");
* Or:
* for(iter=getiterator(...); iterate(&iter, &item); advance(&iter,NULL))
* printf("%s\n",item->myname);
*
* The iterate() call returns whether the cursor is not yet beyond the end of
* the set of items in the iteration. If the second argument is not the NULL
* pointer, the current item is returned in it.
*
* The advance() call advances the cursor to the next element in the list.
* If the cursor advances past the last item, the end() call is implicitly
* executed. If the second argument is not NULL, the item pointed to by the
* cursor after advancing is returned in it.
*
* The end() call terminates the iteration prematurely and releases any
* memory or locks implied by the iterator. If will always return
* successful.
*/
typedef struct names_iterator_struct* names_iterator;
int names_iterate(names_iterator*iter, void* item);
int names_advance(names_iterator*iter, void* item);
int names_end(names_iterator*iter);
names_iterator names_iterator_create(size_t size);
void names_iterator_add(names_iterator i, void* ptr);
void names_iterator_addall(names_iterator iter, int count, void* base, size_t memsize, ssize_t offset);
names_iterator names_iterator_array(int count, void* base, size_t memsize, size_t offset);
names_iterator names_iterator_array2(int count, void* base, size_t memsize);
struct marshall_struct;
typedef struct marshall_struct* marshall_handle;
enum marshall_method { marshall_INPUT, marshall_OUTPUT, marshall_APPEND, marshall_PRINT };
marshall_handle marshallcreate(enum marshall_method method, ...);
void marshallclose(marshall_handle h);
int marshallself(marshall_handle h, void* member);
int marshallbyte(marshall_handle h, void* member);
int marshallinteger(marshall_handle h, void* member);
int marshallstring(marshall_handle h, void* member);
int marshallldnsrr(marshall_handle h, void* member);
int marshallstringarray(marshall_handle h, void* member);
int marshalling(marshall_handle h, const char* name, void* members, int *membercount, size_t membersize, int (*memberfunction)(marshall_handle,void*));
extern int* marshall_OPTIONAL;
/* A dictionary is an abstract data structure capable of storing key
* value pairs, where each value is again a dictionary.
* A (sub)dictionary can also have a name.
*
* The purpose is for the moment as placeholder and to be replaced with
* the domain structure, containing the denial, rrset, etcetera structures.
*/
typedef struct item* resourcerecord_t;
typedef struct dictionary_struct* dictionary;
typedef struct names_index_struct* names_index_type;
typedef struct names_table_struct* names_table_type;
typedef struct names_view_struct* names_view_type;
void composestring(char* dst, const char* src, ...);
int composestring2(char** ptr, const char* src, ...);
int composestringf(char** ptr, const char* fmt, ...);
int getset(dictionary d, const char* name, const char** get, const char** set);
dictionary names_recordcreate(char**name);
void annotate(dictionary, const char* apex);
void names_recorddestroy(dictionary);
void names_recordsetmarker(dictionary dict);
int names_recordhasmarker(dictionary dict);
dictionary names_recordcopy(dictionary);
void dispose(dictionary);
const char* names_recordgetid(dictionary dict, const char* name);
int names_recordcompare_namerevision(dictionary a, dictionary b);
int names_recordhasdata(dictionary record, ldns_rr_type recordtype, ldns_rr* rr, int exact);
void names_recordadddata(dictionary, ldns_rr_type, char* data, char* info);
void rrset_add_rr(dictionary d, ldns_rr* rr);
void names_recorddeldata(dictionary d, ldns_rr_type rrtype, ldns_rr* rr);
void names_recorddelall(dictionary, ldns_rr_type rrtype);
names_iterator names_recordalltypes(dictionary);
names_iterator names_recordalltypes2(dictionary);
names_iterator names_recordallvalues(dictionary, ldns_rr_type rrtype);
int names_recordhasvalidupto(dictionary);
int names_recordgetvalidupto(dictionary);
void names_recordsetvalidupto(dictionary, int value);
int names_recordhasvalidfrom(dictionary);
int names_recordgetvalidfrom(dictionary);
void names_recordsetvalidfrom(dictionary, int value);
int names_recordhasexpiry(dictionary);
int names_recordgetexpiry(dictionary);
void names_recordsetexpiry(dictionary, int value);
void names_recordaddsignature(dictionary record, ldns_rr_type rrtype, ldns_rr* rrsig, const char* keylocator, int keyflags);
int names_recordmarshall(dictionary*, marshall_handle);
void names_recordindexfunction(const char* keyname, int (**acceptfunction)(dictionary newitem, dictionary currentitem, int* cmp), int (**comparefunction)(const void *, const void *));
int names_rrcompare(const char* data, resourcerecord_t);
int names_rrcompare2(resourcerecord_t, resourcerecord_t);
void* names_rr2ident(dictionary record, ldns_rr_type rrtype, resourcerecord_t item, size_t header);
char* names_rr2str(dictionary record, ldns_rr_type recordtype, resourcerecord_t);
ldns_rr* names_rr2ldns(dictionary record, const char* recordname, ldns_rr_type recordtype, resourcerecord_t);
char* names_rr2data(ldns_rr* rr, size_t header);
struct dual {
dictionary src;
dictionary dst;
};
int names_indexcreate(names_index_type*, const char* keyname);
dictionary names_indexlookup(names_index_type, dictionary);
dictionary names_indexlookupkey(names_index_type, const char* keyvalue);
int names_indexremove(names_index_type, dictionary);
int names_indexremovekey(names_index_type,const char* keyvalue);
int names_indexinsert(names_index_type, dictionary);
void names_indexdestroy(names_index_type, void (*userfunc)(void* arg, void* key, void* val), void* userarg);
int names_indexaccept(names_index_type, dictionary);
names_iterator names_indexiterator(names_index_type);
names_iterator names_indexrange(names_index_type,const char* selection,...);
names_iterator noexpiry(names_view_type);
names_iterator neighbors(names_view_type);
names_iterator expiring(names_view_type);
/* Table structures are used internally by views to record changes made in
* the view. A table is a set of changes, also dubbed a changelog.
* The table* functions are not to be used outside of the scope of the
* names_ module.
*/
names_table_type names_tablecreate(void);
void names_tabledispose(names_table_type table, void (*userfunc)(void* arg, void* key, void* val), void* userarg);
void* names_tableget(names_table_type table, const char* name);
int names_tabledel(names_table_type table, char* name);
void** names_tableput(names_table_type table, const char* name);
void names_tableconcat(names_table_type* list, names_table_type item);
names_iterator names_tableitems(names_table_type table);
/* The changelog_ functions are also not to be used directly, they
* extend the table functionality in combination with the views.
*/
typedef struct names_commitlog_struct* names_commitlog_type;
void names_commitlogdestroy(names_table_type changelog);
void names_commitlogdestroyall(names_commitlog_type views, marshall_handle* store);
int names_commitlogpoppush(names_commitlog_type, int viewid, names_table_type* previous, names_table_type* mychangelog);
int names_commitlogsubscribe(names_view_type view, names_commitlog_type*);
void names_commitlogpersistincr(names_commitlog_type, names_table_type changelog);
void names_commitlogpersistappend(names_commitlog_type, void (*persistfn)(names_table_type, marshall_handle), marshall_handle store);
int names_commitlogpersistfull(names_commitlog_type, void (*persistfn)(names_table_type, marshall_handle), int viewid, marshall_handle store, marshall_handle* oldstore);
void names_own(names_view_type view, dictionary* record);
void names_amend(names_view_type view, dictionary record);
void* names_place(names_view_type store, const char* name);
void* names_take(names_view_type view, int index, const char* name);
void names_remove(names_view_type view, dictionary record);
names_view_type names_viewcreate(names_view_type base, const char* name, const char** keynames);
void names_viewdestroy(names_view_type view);
names_iterator names_viewiterator(names_view_type view, int index);
names_iterator names_viewiterate(names_view_type view, const char* name, ...);
int names_viewcommit(names_view_type view);
void names_viewreset(names_view_type view);
int names_viewpersist(names_view_type view, int basefd, char* filename);
int names_viewrestore(names_view_type view, const char* apex, int basefd, const char* filename);
int names_viewgetdefaultttl(names_view_type view);
ldns_rr* names_viewgetapex(names_view_type view);
void names_dumprecord(FILE*, dictionary record);
void names_dumpviewinfo(names_view_type view);
void names_dumpviewfull(FILE*, names_view_type view);
struct signconf;
struct signconf* createsignconf(int nkeys);
void locatekeysignconf(struct signconf* signconf, int index, const char* locator, int flags);
void destroysignconf(struct signconf* signconf);
void setupsignconf(struct signconf* signconf);
void teardownsignconf(struct signconf* signconf);
void signrecord(struct signconf* signconf, dictionary record, const char* apex);
void sign(names_view_type view, const char* apex);
void prepare(names_view_type view, int newserial);
int writezone(names_view_type view, const char* filename, const char* apex, int* defaultttl);
enum operation_enum { PLAIN, DELTAMINUS, DELTAPLUS };
int readzone(names_view_type view, enum operation_enum operation, const char* filename, char** apexptr, int* defaultttlptr);
void rr2data(ldns_rr* rr, char** recorddataptr, char** recordinfoptr);
struct names_struct {
names_view_type baseview;
names_view_type inputview;
names_view_type prepareview;
names_view_type signview;
names_view_type outputview;
int basefd;
char* apex;
char* source;
char* persist;
};
#ifdef OPENDNSSEC_CONFIG_DIR
void namedb_nsecify(zone_type* zone, names_view_type view, uint32_t* num_added);
ods_status namedb_update_serial(zone_type* db, const char* zone_name, uint32_t, uint32_t);
const char* rrset_type2str(ldns_rr_type type);
ods_status rrset_sign(signconf_type* signconf, names_view_type view, dictionary domain, hsm_ctx_t* ctx, struct itemset* rrset, time_t signtime);
int eachdomainset();
ods_status rrset_getliteralrr(ldns_rr** dnskey, const char *resourcerecord, uint32_t ttl, ldns_rdf* apex);
ods_status namedb_domain_entize(names_view_type view, dictionary domain, ldns_rdf* apex);
int eachrrr();
#else
int names_docreate(struct names_struct** zoneptr, const char* apex, const char* persist, const char* input);
void names_dodestroy(struct names_struct* names);
void names_docycle(struct names_struct* names, int* serial, const char* filename);
void names_dopersist(struct names_struct* names);
#endif
#endif