line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* rdata.c |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* rdata implementation |
5
|
|
|
|
|
|
|
* |
6
|
|
|
|
|
|
|
* a Net::DNS like library for C |
7
|
|
|
|
|
|
|
* |
8
|
|
|
|
|
|
|
* (c) NLnet Labs, 2004-2006 |
9
|
|
|
|
|
|
|
* |
10
|
|
|
|
|
|
|
* See the file LICENSE for the license |
11
|
|
|
|
|
|
|
*/ |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#include |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#include |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
/* |
18
|
|
|
|
|
|
|
* Access functions |
19
|
|
|
|
|
|
|
* do this as functions to get type checking |
20
|
|
|
|
|
|
|
*/ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
/* read */ |
23
|
|
|
|
|
|
|
size_t |
24
|
4127
|
|
|
|
|
|
ldns_rdf_size(const ldns_rdf *rd) |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
assert(rd != NULL); |
27
|
4127
|
|
|
|
|
|
return rd->_size; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
ldns_rdf_type |
31
|
1854
|
|
|
|
|
|
ldns_rdf_get_type(const ldns_rdf *rd) |
32
|
|
|
|
|
|
|
{ |
33
|
|
|
|
|
|
|
assert(rd != NULL); |
34
|
1854
|
|
|
|
|
|
return rd->_type; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
uint8_t * |
38
|
3614
|
|
|
|
|
|
ldns_rdf_data(const ldns_rdf *rd) |
39
|
|
|
|
|
|
|
{ |
40
|
|
|
|
|
|
|
assert(rd != NULL); |
41
|
3614
|
|
|
|
|
|
return rd->_data; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
/* write */ |
45
|
|
|
|
|
|
|
void |
46
|
2449
|
|
|
|
|
|
ldns_rdf_set_size(ldns_rdf *rd, size_t size) |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
assert(rd != NULL); |
49
|
2449
|
|
|
|
|
|
rd->_size = size; |
50
|
2449
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
void |
53
|
2671
|
|
|
|
|
|
ldns_rdf_set_type(ldns_rdf *rd, ldns_rdf_type type) |
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
assert(rd != NULL); |
56
|
2671
|
|
|
|
|
|
rd->_type = type; |
57
|
2671
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
void |
60
|
631
|
|
|
|
|
|
ldns_rdf_set_data(ldns_rdf *rd, void *data) |
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
/* only copy the pointer */ |
63
|
|
|
|
|
|
|
assert(rd != NULL); |
64
|
631
|
|
|
|
|
|
rd->_data = data; |
65
|
631
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
/* for types that allow it, return |
68
|
|
|
|
|
|
|
* the native/host order type */ |
69
|
|
|
|
|
|
|
uint8_t |
70
|
49
|
|
|
|
|
|
ldns_rdf2native_int8(const ldns_rdf *rd) |
71
|
|
|
|
|
|
|
{ |
72
|
|
|
|
|
|
|
uint8_t data; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
/* only allow 8 bit rdfs */ |
75
|
49
|
50
|
|
|
|
|
if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_BYTE) { |
76
|
0
|
|
|
|
|
|
return 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
49
|
|
|
|
|
|
memcpy(&data, ldns_rdf_data(rd), sizeof(data)); |
80
|
49
|
|
|
|
|
|
return data; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
uint16_t |
84
|
25
|
|
|
|
|
|
ldns_rdf2native_int16(const ldns_rdf *rd) |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
uint16_t data; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
/* only allow 16 bit rdfs */ |
89
|
25
|
50
|
|
|
|
|
if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_WORD) { |
90
|
0
|
|
|
|
|
|
return 0; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
25
|
|
|
|
|
|
memcpy(&data, ldns_rdf_data(rd), sizeof(data)); |
94
|
25
|
|
|
|
|
|
return ntohs(data); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
uint32_t |
98
|
10
|
|
|
|
|
|
ldns_rdf2native_int32(const ldns_rdf *rd) |
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
uint32_t data; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
/* only allow 32 bit rdfs */ |
103
|
10
|
50
|
|
|
|
|
if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_DOUBLEWORD) { |
104
|
0
|
|
|
|
|
|
return 0; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
10
|
|
|
|
|
|
memcpy(&data, ldns_rdf_data(rd), sizeof(data)); |
108
|
10
|
|
|
|
|
|
return ntohl(data); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
time_t |
112
|
6
|
|
|
|
|
|
ldns_rdf2native_time_t(const ldns_rdf *rd) |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
uint32_t data; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
/* only allow 32 bit rdfs */ |
117
|
12
|
|
|
|
|
|
if (ldns_rdf_size(rd) != LDNS_RDF_SIZE_DOUBLEWORD || |
118
|
6
|
|
|
|
|
|
ldns_rdf_get_type(rd) != LDNS_RDF_TYPE_TIME) { |
119
|
0
|
|
|
|
|
|
return 0; |
120
|
|
|
|
|
|
|
} |
121
|
6
|
|
|
|
|
|
memcpy(&data, ldns_rdf_data(rd), sizeof(data)); |
122
|
6
|
|
|
|
|
|
return (time_t)ntohl(data); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
ldns_rdf * |
126
|
0
|
|
|
|
|
|
ldns_native2rdf_int8(ldns_rdf_type type, uint8_t value) |
127
|
|
|
|
|
|
|
{ |
128
|
0
|
|
|
|
|
|
return ldns_rdf_new_frm_data(type, LDNS_RDF_SIZE_BYTE, &value); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
ldns_rdf * |
132
|
0
|
|
|
|
|
|
ldns_native2rdf_int16(ldns_rdf_type type, uint16_t value) |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
|
|
|
uint16_t *rdf_data = LDNS_XMALLOC(uint16_t, 1); |
135
|
|
|
|
|
|
|
ldns_rdf* rdf; |
136
|
0
|
0
|
|
|
|
|
if (!rdf_data) { |
137
|
0
|
|
|
|
|
|
return NULL; |
138
|
|
|
|
|
|
|
} |
139
|
0
|
|
|
|
|
|
ldns_write_uint16(rdf_data, value); |
140
|
0
|
|
|
|
|
|
rdf = ldns_rdf_new(type, LDNS_RDF_SIZE_WORD, rdf_data); |
141
|
0
|
0
|
|
|
|
|
if(!rdf) |
142
|
0
|
|
|
|
|
|
LDNS_FREE(rdf_data); |
143
|
0
|
|
|
|
|
|
return rdf; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
ldns_rdf * |
147
|
0
|
|
|
|
|
|
ldns_native2rdf_int32(ldns_rdf_type type, uint32_t value) |
148
|
|
|
|
|
|
|
{ |
149
|
0
|
|
|
|
|
|
uint32_t *rdf_data = LDNS_XMALLOC(uint32_t, 1); |
150
|
|
|
|
|
|
|
ldns_rdf* rdf; |
151
|
0
|
0
|
|
|
|
|
if (!rdf_data) { |
152
|
0
|
|
|
|
|
|
return NULL; |
153
|
|
|
|
|
|
|
} |
154
|
0
|
|
|
|
|
|
ldns_write_uint32(rdf_data, value); |
155
|
0
|
|
|
|
|
|
rdf = ldns_rdf_new(type, LDNS_RDF_SIZE_DOUBLEWORD, rdf_data); |
156
|
0
|
0
|
|
|
|
|
if(!rdf) |
157
|
0
|
|
|
|
|
|
LDNS_FREE(rdf_data); |
158
|
0
|
|
|
|
|
|
return rdf; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
ldns_rdf * |
162
|
0
|
|
|
|
|
|
ldns_native2rdf_int16_data(size_t size, uint8_t *data) |
163
|
|
|
|
|
|
|
{ |
164
|
0
|
|
|
|
|
|
uint8_t *rdf_data = LDNS_XMALLOC(uint8_t, size + 2); |
165
|
|
|
|
|
|
|
ldns_rdf* rdf; |
166
|
0
|
0
|
|
|
|
|
if (!rdf_data) { |
167
|
0
|
|
|
|
|
|
return NULL; |
168
|
|
|
|
|
|
|
} |
169
|
0
|
|
|
|
|
|
ldns_write_uint16(rdf_data, size); |
170
|
0
|
|
|
|
|
|
memcpy(rdf_data + 2, data, size); |
171
|
0
|
|
|
|
|
|
rdf = ldns_rdf_new(LDNS_RDF_TYPE_INT16_DATA, size + 2, rdf_data); |
172
|
0
|
0
|
|
|
|
|
if(!rdf) |
173
|
0
|
|
|
|
|
|
LDNS_FREE(rdf_data); |
174
|
0
|
|
|
|
|
|
return rdf; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
/* note: data must be allocated memory */ |
178
|
|
|
|
|
|
|
ldns_rdf * |
179
|
617
|
|
|
|
|
|
ldns_rdf_new(ldns_rdf_type type, size_t size, void *data) |
180
|
|
|
|
|
|
|
{ |
181
|
|
|
|
|
|
|
ldns_rdf *rd; |
182
|
617
|
|
|
|
|
|
rd = LDNS_MALLOC(ldns_rdf); |
183
|
617
|
50
|
|
|
|
|
if (!rd) { |
184
|
0
|
|
|
|
|
|
return NULL; |
185
|
|
|
|
|
|
|
} |
186
|
617
|
|
|
|
|
|
ldns_rdf_set_size(rd, size); |
187
|
617
|
|
|
|
|
|
ldns_rdf_set_type(rd, type); |
188
|
617
|
|
|
|
|
|
ldns_rdf_set_data(rd, data); |
189
|
617
|
|
|
|
|
|
return rd; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
ldns_rdf * |
193
|
1818
|
|
|
|
|
|
ldns_rdf_new_frm_data(ldns_rdf_type type, size_t size, const void *data) |
194
|
|
|
|
|
|
|
{ |
195
|
|
|
|
|
|
|
ldns_rdf *rdf; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
/* if the size is too big, fail */ |
198
|
1818
|
50
|
|
|
|
|
if (size > LDNS_MAX_RDFLEN) { |
199
|
0
|
|
|
|
|
|
return NULL; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
/* allocate space */ |
203
|
1818
|
|
|
|
|
|
rdf = LDNS_MALLOC(ldns_rdf); |
204
|
1818
|
50
|
|
|
|
|
if (!rdf) { |
205
|
0
|
|
|
|
|
|
return NULL; |
206
|
|
|
|
|
|
|
} |
207
|
1818
|
|
|
|
|
|
rdf->_data = LDNS_XMALLOC(uint8_t, size); |
208
|
1818
|
50
|
|
|
|
|
if (!rdf->_data) { |
209
|
0
|
|
|
|
|
|
LDNS_FREE(rdf); |
210
|
0
|
|
|
|
|
|
return NULL; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
/* set the values */ |
214
|
1818
|
|
|
|
|
|
ldns_rdf_set_type(rdf, type); |
215
|
1818
|
|
|
|
|
|
ldns_rdf_set_size(rdf, size); |
216
|
1818
|
|
|
|
|
|
memcpy(rdf->_data, data, size); |
217
|
|
|
|
|
|
|
|
218
|
1818
|
|
|
|
|
|
return rdf; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
ldns_rdf * |
222
|
1052
|
|
|
|
|
|
ldns_rdf_clone(const ldns_rdf *rd) |
223
|
|
|
|
|
|
|
{ |
224
|
|
|
|
|
|
|
assert(rd != NULL); |
225
|
1052
|
|
|
|
|
|
return (ldns_rdf_new_frm_data( ldns_rdf_get_type(rd), |
226
|
1052
|
|
|
|
|
|
ldns_rdf_size(rd), ldns_rdf_data(rd))); |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
void |
230
|
2531
|
|
|
|
|
|
ldns_rdf_deep_free(ldns_rdf *rd) |
231
|
|
|
|
|
|
|
{ |
232
|
2531
|
100
|
|
|
|
|
if (rd) { |
233
|
2425
|
50
|
|
|
|
|
if (rd->_data) { |
234
|
2425
|
|
|
|
|
|
LDNS_FREE(rd->_data); |
235
|
|
|
|
|
|
|
} |
236
|
2425
|
|
|
|
|
|
LDNS_FREE(rd); |
237
|
|
|
|
|
|
|
} |
238
|
2531
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
void |
241
|
0
|
|
|
|
|
|
ldns_rdf_free(ldns_rdf *rd) |
242
|
|
|
|
|
|
|
{ |
243
|
0
|
0
|
|
|
|
|
if (rd) { |
244
|
0
|
|
|
|
|
|
LDNS_FREE(rd); |
245
|
|
|
|
|
|
|
} |
246
|
0
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
ldns_rdf * |
249
|
245
|
|
|
|
|
|
ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str) |
250
|
|
|
|
|
|
|
{ |
251
|
245
|
|
|
|
|
|
ldns_rdf *rdf = NULL; |
252
|
|
|
|
|
|
|
ldns_status status; |
253
|
|
|
|
|
|
|
|
254
|
245
|
|
|
|
|
|
switch (type) { |
255
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_DNAME: |
256
|
115
|
|
|
|
|
|
status = ldns_str2rdf_dname(&rdf, str); |
257
|
115
|
|
|
|
|
|
break; |
258
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_INT8: |
259
|
10
|
|
|
|
|
|
status = ldns_str2rdf_int8(&rdf, str); |
260
|
10
|
|
|
|
|
|
break; |
261
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_INT16: |
262
|
11
|
|
|
|
|
|
status = ldns_str2rdf_int16(&rdf, str); |
263
|
11
|
|
|
|
|
|
break; |
264
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_INT32: |
265
|
4
|
|
|
|
|
|
status = ldns_str2rdf_int32(&rdf, str); |
266
|
4
|
|
|
|
|
|
break; |
267
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_A: |
268
|
40
|
|
|
|
|
|
status = ldns_str2rdf_a(&rdf, str); |
269
|
40
|
|
|
|
|
|
break; |
270
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_AAAA: |
271
|
32
|
|
|
|
|
|
status = ldns_str2rdf_aaaa(&rdf, str); |
272
|
32
|
|
|
|
|
|
break; |
273
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_STR: |
274
|
2
|
|
|
|
|
|
status = ldns_str2rdf_str(&rdf, str); |
275
|
2
|
|
|
|
|
|
break; |
276
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_APL: |
277
|
0
|
|
|
|
|
|
status = ldns_str2rdf_apl(&rdf, str); |
278
|
0
|
|
|
|
|
|
break; |
279
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_B64: |
280
|
4
|
|
|
|
|
|
status = ldns_str2rdf_b64(&rdf, str); |
281
|
4
|
|
|
|
|
|
break; |
282
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_B32_EXT: |
283
|
0
|
|
|
|
|
|
status = ldns_str2rdf_b32_ext(&rdf, str); |
284
|
0
|
|
|
|
|
|
break; |
285
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_HEX: |
286
|
0
|
|
|
|
|
|
status = ldns_str2rdf_hex(&rdf, str); |
287
|
0
|
|
|
|
|
|
break; |
288
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NSEC: |
289
|
3
|
|
|
|
|
|
status = ldns_str2rdf_nsec(&rdf, str); |
290
|
3
|
|
|
|
|
|
break; |
291
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_TYPE: |
292
|
1
|
|
|
|
|
|
status = ldns_str2rdf_type(&rdf, str); |
293
|
1
|
|
|
|
|
|
break; |
294
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_CLASS: |
295
|
0
|
|
|
|
|
|
status = ldns_str2rdf_class(&rdf, str); |
296
|
0
|
|
|
|
|
|
break; |
297
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_CERT_ALG: |
298
|
0
|
|
|
|
|
|
status = ldns_str2rdf_cert_alg(&rdf, str); |
299
|
0
|
|
|
|
|
|
break; |
300
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_ALG: |
301
|
4
|
|
|
|
|
|
status = ldns_str2rdf_alg(&rdf, str); |
302
|
4
|
|
|
|
|
|
break; |
303
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_UNKNOWN: |
304
|
0
|
|
|
|
|
|
status = ldns_str2rdf_unknown(&rdf, str); |
305
|
0
|
|
|
|
|
|
break; |
306
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_TIME: |
307
|
2
|
|
|
|
|
|
status = ldns_str2rdf_time(&rdf, str); |
308
|
2
|
|
|
|
|
|
break; |
309
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_PERIOD: |
310
|
12
|
|
|
|
|
|
status = ldns_str2rdf_period(&rdf, str); |
311
|
12
|
|
|
|
|
|
break; |
312
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_HIP: |
313
|
0
|
|
|
|
|
|
status = ldns_str2rdf_hip(&rdf, str); |
314
|
0
|
|
|
|
|
|
break; |
315
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_SERVICE: |
316
|
0
|
|
|
|
|
|
status = ldns_str2rdf_service(&rdf, str); |
317
|
0
|
|
|
|
|
|
break; |
318
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_LOC: |
319
|
0
|
|
|
|
|
|
status = ldns_str2rdf_loc(&rdf, str); |
320
|
0
|
|
|
|
|
|
break; |
321
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_WKS: |
322
|
0
|
|
|
|
|
|
status = ldns_str2rdf_wks(&rdf, str); |
323
|
0
|
|
|
|
|
|
break; |
324
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NSAP: |
325
|
0
|
|
|
|
|
|
status = ldns_str2rdf_nsap(&rdf, str); |
326
|
0
|
|
|
|
|
|
break; |
327
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_ATMA: |
328
|
0
|
|
|
|
|
|
status = ldns_str2rdf_atma(&rdf, str); |
329
|
0
|
|
|
|
|
|
break; |
330
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_IPSECKEY: |
331
|
0
|
|
|
|
|
|
status = ldns_str2rdf_ipseckey(&rdf, str); |
332
|
0
|
|
|
|
|
|
break; |
333
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NSEC3_SALT: |
334
|
3
|
|
|
|
|
|
status = ldns_str2rdf_nsec3_salt(&rdf, str); |
335
|
3
|
|
|
|
|
|
break; |
336
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: |
337
|
2
|
|
|
|
|
|
status = ldns_str2rdf_b32_ext(&rdf, str); |
338
|
2
|
|
|
|
|
|
break; |
339
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_ILNP64: |
340
|
0
|
|
|
|
|
|
status = ldns_str2rdf_ilnp64(&rdf, str); |
341
|
0
|
|
|
|
|
|
break; |
342
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_EUI48: |
343
|
0
|
|
|
|
|
|
status = ldns_str2rdf_eui48(&rdf, str); |
344
|
0
|
|
|
|
|
|
break; |
345
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_EUI64: |
346
|
0
|
|
|
|
|
|
status = ldns_str2rdf_eui64(&rdf, str); |
347
|
0
|
|
|
|
|
|
break; |
348
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_TAG: |
349
|
0
|
|
|
|
|
|
status = ldns_str2rdf_tag(&rdf, str); |
350
|
0
|
|
|
|
|
|
break; |
351
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_LONG_STR: |
352
|
0
|
|
|
|
|
|
status = ldns_str2rdf_long_str(&rdf, str); |
353
|
0
|
|
|
|
|
|
break; |
354
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_CERTIFICATE_USAGE: |
355
|
0
|
|
|
|
|
|
status = ldns_str2rdf_certificate_usage(&rdf, str); |
356
|
0
|
|
|
|
|
|
break; |
357
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_SELECTOR: |
358
|
0
|
|
|
|
|
|
status = ldns_str2rdf_selector(&rdf, str); |
359
|
0
|
|
|
|
|
|
break; |
360
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_MATCHING_TYPE: |
361
|
0
|
|
|
|
|
|
status = ldns_str2rdf_matching_type(&rdf, str); |
362
|
0
|
|
|
|
|
|
break; |
363
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_NONE: |
364
|
|
|
|
|
|
|
default: |
365
|
|
|
|
|
|
|
/* default default ??? */ |
366
|
0
|
|
|
|
|
|
status = LDNS_STATUS_ERR; |
367
|
0
|
|
|
|
|
|
break; |
368
|
|
|
|
|
|
|
} |
369
|
245
|
100
|
|
|
|
|
if (LDNS_STATUS_OK == status) { |
370
|
236
|
|
|
|
|
|
ldns_rdf_set_type(rdf, type); |
371
|
236
|
|
|
|
|
|
return rdf; |
372
|
|
|
|
|
|
|
} |
373
|
9
|
50
|
|
|
|
|
if (rdf) { |
374
|
0
|
|
|
|
|
|
LDNS_FREE(rdf); |
375
|
|
|
|
|
|
|
} |
376
|
245
|
|
|
|
|
|
return NULL; |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
ldns_status |
380
|
0
|
|
|
|
|
|
ldns_rdf_new_frm_fp(ldns_rdf **rdf, ldns_rdf_type type, FILE *fp) |
381
|
|
|
|
|
|
|
{ |
382
|
0
|
|
|
|
|
|
return ldns_rdf_new_frm_fp_l(rdf, type, fp, NULL); |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
ldns_status |
386
|
0
|
|
|
|
|
|
ldns_rdf_new_frm_fp_l(ldns_rdf **rdf, ldns_rdf_type type, FILE *fp, int *line_nr) |
387
|
|
|
|
|
|
|
{ |
388
|
|
|
|
|
|
|
char *line; |
389
|
|
|
|
|
|
|
ldns_rdf *r; |
390
|
|
|
|
|
|
|
ssize_t t; |
391
|
|
|
|
|
|
|
|
392
|
0
|
|
|
|
|
|
line = LDNS_XMALLOC(char, LDNS_MAX_LINELEN + 1); |
393
|
0
|
0
|
|
|
|
|
if (!line) { |
394
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
395
|
|
|
|
|
|
|
} |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
/* read an entire line in from the file */ |
398
|
0
|
0
|
|
|
|
|
if ((t = ldns_fget_token_l(fp, line, LDNS_PARSE_SKIP_SPACE, 0, line_nr)) == -1 || t == 0) { |
|
|
0
|
|
|
|
|
|
399
|
0
|
|
|
|
|
|
LDNS_FREE(line); |
400
|
0
|
|
|
|
|
|
return LDNS_STATUS_SYNTAX_RDATA_ERR; |
401
|
|
|
|
|
|
|
} |
402
|
0
|
|
|
|
|
|
r = ldns_rdf_new_frm_str(type, (const char*) line); |
403
|
0
|
|
|
|
|
|
LDNS_FREE(line); |
404
|
0
|
0
|
|
|
|
|
if (rdf) { |
405
|
0
|
|
|
|
|
|
*rdf = r; |
406
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
407
|
|
|
|
|
|
|
} else { |
408
|
0
|
|
|
|
|
|
return LDNS_STATUS_NULL; |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
} |
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
ldns_rdf * |
413
|
2
|
|
|
|
|
|
ldns_rdf_address_reverse(ldns_rdf *rd) |
414
|
|
|
|
|
|
|
{ |
415
|
|
|
|
|
|
|
uint8_t buf_4[LDNS_IP4ADDRLEN]; |
416
|
|
|
|
|
|
|
uint8_t buf_6[LDNS_IP6ADDRLEN * 2]; |
417
|
|
|
|
|
|
|
ldns_rdf *rev; |
418
|
|
|
|
|
|
|
ldns_rdf *in_addr; |
419
|
|
|
|
|
|
|
ldns_rdf *ret_dname; |
420
|
|
|
|
|
|
|
uint8_t octet; |
421
|
|
|
|
|
|
|
uint8_t nnibble; |
422
|
|
|
|
|
|
|
uint8_t nibble; |
423
|
|
|
|
|
|
|
uint8_t i, j; |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
char *char_dname; |
426
|
|
|
|
|
|
|
int nbit; |
427
|
|
|
|
|
|
|
|
428
|
2
|
|
|
|
|
|
if (ldns_rdf_get_type(rd) != LDNS_RDF_TYPE_A && |
429
|
0
|
|
|
|
|
|
ldns_rdf_get_type(rd) != LDNS_RDF_TYPE_AAAA) { |
430
|
0
|
|
|
|
|
|
return NULL; |
431
|
|
|
|
|
|
|
} |
432
|
|
|
|
|
|
|
|
433
|
2
|
|
|
|
|
|
in_addr = NULL; |
434
|
2
|
|
|
|
|
|
ret_dname = NULL; |
435
|
|
|
|
|
|
|
|
436
|
2
|
|
|
|
|
|
switch(ldns_rdf_get_type(rd)) { |
437
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_A: |
438
|
|
|
|
|
|
|
/* the length of the buffer is 4 */ |
439
|
2
|
|
|
|
|
|
buf_4[3] = ldns_rdf_data(rd)[0]; |
440
|
2
|
|
|
|
|
|
buf_4[2] = ldns_rdf_data(rd)[1]; |
441
|
2
|
|
|
|
|
|
buf_4[1] = ldns_rdf_data(rd)[2]; |
442
|
2
|
|
|
|
|
|
buf_4[0] = ldns_rdf_data(rd)[3]; |
443
|
2
|
|
|
|
|
|
in_addr = ldns_dname_new_frm_str("in-addr.arpa."); |
444
|
2
|
50
|
|
|
|
|
if (!in_addr) { |
445
|
0
|
|
|
|
|
|
return NULL; |
446
|
|
|
|
|
|
|
} |
447
|
|
|
|
|
|
|
/* make a new rdf and convert that back */ |
448
|
2
|
|
|
|
|
|
rev = ldns_rdf_new_frm_data( LDNS_RDF_TYPE_A, |
449
|
|
|
|
|
|
|
LDNS_IP4ADDRLEN, (void*)&buf_4); |
450
|
2
|
50
|
|
|
|
|
if (!rev) { |
451
|
0
|
|
|
|
|
|
LDNS_FREE(in_addr); |
452
|
0
|
|
|
|
|
|
return NULL; |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
/* convert rev to a string */ |
456
|
2
|
|
|
|
|
|
char_dname = ldns_rdf2str(rev); |
457
|
2
|
50
|
|
|
|
|
if (!char_dname) { |
458
|
0
|
|
|
|
|
|
LDNS_FREE(in_addr); |
459
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(rev); |
460
|
0
|
|
|
|
|
|
return NULL; |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
/* transform back to rdf with type dname */ |
463
|
2
|
|
|
|
|
|
ret_dname = ldns_dname_new_frm_str(char_dname); |
464
|
2
|
50
|
|
|
|
|
if (!ret_dname) { |
465
|
0
|
|
|
|
|
|
LDNS_FREE(in_addr); |
466
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(rev); |
467
|
0
|
|
|
|
|
|
LDNS_FREE(char_dname); |
468
|
0
|
|
|
|
|
|
return NULL; |
469
|
|
|
|
|
|
|
} |
470
|
|
|
|
|
|
|
/* not needed anymore */ |
471
|
2
|
|
|
|
|
|
ldns_rdf_deep_free(rev); |
472
|
2
|
|
|
|
|
|
LDNS_FREE(char_dname); |
473
|
2
|
|
|
|
|
|
break; |
474
|
|
|
|
|
|
|
case LDNS_RDF_TYPE_AAAA: |
475
|
|
|
|
|
|
|
/* some foo magic to reverse the nibbles ... */ |
476
|
|
|
|
|
|
|
|
477
|
0
|
0
|
|
|
|
|
for (nbit = 127; nbit >= 0; nbit = nbit - 4) { |
478
|
|
|
|
|
|
|
/* calculate octett (8 bit) */ |
479
|
0
|
|
|
|
|
|
octet = ( ((unsigned int) nbit) & 0x78) >> 3; |
480
|
|
|
|
|
|
|
/* calculate nibble */ |
481
|
0
|
|
|
|
|
|
nnibble = ( ((unsigned int) nbit) & 0x04) >> 2; |
482
|
|
|
|
|
|
|
/* extract nibble */ |
483
|
0
|
|
|
|
|
|
nibble = (ldns_rdf_data(rd)[octet] & ( 0xf << (4 * (1 - |
484
|
0
|
|
|
|
|
|
nnibble)) ) ) >> ( 4 * (1 - |
485
|
|
|
|
|
|
|
nnibble)); |
486
|
|
|
|
|
|
|
|
487
|
0
|
|
|
|
|
|
buf_6[(LDNS_IP6ADDRLEN * 2 - 1) - |
488
|
0
|
|
|
|
|
|
(octet * 2 + nnibble)] = |
489
|
0
|
|
|
|
|
|
(uint8_t)ldns_int_to_hexdigit((int)nibble); |
490
|
|
|
|
|
|
|
} |
491
|
|
|
|
|
|
|
|
492
|
0
|
|
|
|
|
|
char_dname = LDNS_XMALLOC(char, (LDNS_IP6ADDRLEN * 4)); |
493
|
0
|
0
|
|
|
|
|
if (!char_dname) { |
494
|
0
|
|
|
|
|
|
return NULL; |
495
|
|
|
|
|
|
|
} |
496
|
0
|
|
|
|
|
|
char_dname[LDNS_IP6ADDRLEN * 4 - 1] = '\0'; /* closure */ |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
/* walk the string and add . 's */ |
499
|
0
|
0
|
|
|
|
|
for (i = 0, j = 0; i < LDNS_IP6ADDRLEN * 2; i++, j = j + 2) { |
500
|
0
|
|
|
|
|
|
char_dname[j] = (char)buf_6[i]; |
501
|
0
|
0
|
|
|
|
|
if (i != LDNS_IP6ADDRLEN * 2 - 1) { |
502
|
0
|
|
|
|
|
|
char_dname[j + 1] = '.'; |
503
|
|
|
|
|
|
|
} |
504
|
|
|
|
|
|
|
} |
505
|
0
|
|
|
|
|
|
in_addr = ldns_dname_new_frm_str("ip6.arpa."); |
506
|
0
|
0
|
|
|
|
|
if (!in_addr) { |
507
|
0
|
|
|
|
|
|
LDNS_FREE(char_dname); |
508
|
0
|
|
|
|
|
|
return NULL; |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
/* convert rev to a string */ |
512
|
0
|
|
|
|
|
|
ret_dname = ldns_dname_new_frm_str(char_dname); |
513
|
0
|
|
|
|
|
|
LDNS_FREE(char_dname); |
514
|
0
|
0
|
|
|
|
|
if (!ret_dname) { |
515
|
0
|
|
|
|
|
|
ldns_rdf_deep_free(in_addr); |
516
|
0
|
|
|
|
|
|
return NULL; |
517
|
|
|
|
|
|
|
} |
518
|
0
|
|
|
|
|
|
break; |
519
|
|
|
|
|
|
|
default: |
520
|
0
|
|
|
|
|
|
break; |
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
/* add the suffix */ |
523
|
2
|
|
|
|
|
|
rev = ldns_dname_cat_clone(ret_dname, in_addr); |
524
|
|
|
|
|
|
|
|
525
|
2
|
|
|
|
|
|
ldns_rdf_deep_free(ret_dname); |
526
|
2
|
|
|
|
|
|
ldns_rdf_deep_free(in_addr); |
527
|
2
|
|
|
|
|
|
return rev; |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
ldns_status |
531
|
0
|
|
|
|
|
|
ldns_rdf_hip_get_alg_hit_pk(ldns_rdf *rdf, uint8_t* alg, |
532
|
|
|
|
|
|
|
uint8_t *hit_size, uint8_t** hit, |
533
|
|
|
|
|
|
|
uint16_t *pk_size, uint8_t** pk) |
534
|
|
|
|
|
|
|
{ |
535
|
|
|
|
|
|
|
uint8_t *data; |
536
|
|
|
|
|
|
|
size_t rdf_size; |
537
|
|
|
|
|
|
|
|
538
|
0
|
0
|
|
|
|
|
if (! rdf || ! alg || ! hit || ! hit_size || ! pk || ! pk_size) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
539
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_POINTER; |
540
|
0
|
0
|
|
|
|
|
} else if (ldns_rdf_get_type(rdf) != LDNS_RDF_TYPE_HIP) { |
541
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_RDF_TYPE; |
542
|
0
|
0
|
|
|
|
|
} else if ((rdf_size = ldns_rdf_size(rdf)) < 6) { |
543
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
544
|
|
|
|
|
|
|
} |
545
|
0
|
|
|
|
|
|
data = ldns_rdf_data(rdf); |
546
|
0
|
|
|
|
|
|
*hit_size = data[0]; |
547
|
0
|
|
|
|
|
|
*alg = data[1]; |
548
|
0
|
|
|
|
|
|
*pk_size = ldns_read_uint16(data + 2); |
549
|
0
|
|
|
|
|
|
*hit = data + 4; |
550
|
0
|
|
|
|
|
|
*pk = data + 4 + *hit_size; |
551
|
0
|
0
|
|
|
|
|
if (*hit_size == 0 || *pk_size == 0 || |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
552
|
0
|
|
|
|
|
|
rdf_size < (size_t) *hit_size + *pk_size + 4) { |
553
|
0
|
|
|
|
|
|
return LDNS_STATUS_WIRE_RDATA_ERR; |
554
|
|
|
|
|
|
|
} |
555
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
556
|
|
|
|
|
|
|
} |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
ldns_status |
559
|
0
|
|
|
|
|
|
ldns_rdf_hip_new_frm_alg_hit_pk(ldns_rdf** rdf, uint8_t alg, |
560
|
|
|
|
|
|
|
uint8_t hit_size, uint8_t *hit, |
561
|
|
|
|
|
|
|
uint16_t pk_size, uint8_t *pk) |
562
|
|
|
|
|
|
|
{ |
563
|
|
|
|
|
|
|
uint8_t *data; |
564
|
|
|
|
|
|
|
|
565
|
0
|
0
|
|
|
|
|
if (! rdf) { |
566
|
0
|
|
|
|
|
|
return LDNS_STATUS_INVALID_POINTER; |
567
|
|
|
|
|
|
|
} |
568
|
0
|
0
|
|
|
|
|
if (4 + hit_size + pk_size > LDNS_MAX_RDFLEN) { |
569
|
0
|
|
|
|
|
|
return LDNS_STATUS_RDATA_OVERFLOW; |
570
|
|
|
|
|
|
|
} |
571
|
0
|
|
|
|
|
|
data = LDNS_XMALLOC(uint8_t, 4 + hit_size + pk_size); |
572
|
0
|
0
|
|
|
|
|
if (data == NULL) { |
573
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
574
|
|
|
|
|
|
|
} |
575
|
0
|
|
|
|
|
|
data[0] = hit_size; |
576
|
0
|
|
|
|
|
|
data[1] = alg; |
577
|
0
|
|
|
|
|
|
ldns_write_uint16(data + 2, pk_size); |
578
|
0
|
|
|
|
|
|
memcpy(data + 4, hit, hit_size); |
579
|
0
|
|
|
|
|
|
memcpy(data + 4 + hit_size, pk, pk_size); |
580
|
0
|
|
|
|
|
|
*rdf = ldns_rdf_new(LDNS_RDF_TYPE_HIP, 4 + hit_size + pk_size, data); |
581
|
0
|
0
|
|
|
|
|
if (! *rdf) { |
582
|
0
|
|
|
|
|
|
LDNS_FREE(data); |
583
|
0
|
|
|
|
|
|
return LDNS_STATUS_MEM_ERR; |
584
|
|
|
|
|
|
|
} |
585
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
ldns_status |
589
|
0
|
|
|
|
|
|
ldns_octet(char *word, size_t *length) |
590
|
|
|
|
|
|
|
{ |
591
|
|
|
|
|
|
|
char *s; |
592
|
|
|
|
|
|
|
char *p; |
593
|
0
|
|
|
|
|
|
*length = 0; |
594
|
|
|
|
|
|
|
|
595
|
0
|
0
|
|
|
|
|
for (s = p = word; *s != '\0'; s++,p++) { |
596
|
0
|
|
|
|
|
|
switch (*s) { |
597
|
|
|
|
|
|
|
case '.': |
598
|
0
|
0
|
|
|
|
|
if (s[1] == '.') { |
599
|
0
|
|
|
|
|
|
return LDNS_STATUS_EMPTY_LABEL; |
600
|
|
|
|
|
|
|
} |
601
|
0
|
|
|
|
|
|
*p = *s; |
602
|
0
|
|
|
|
|
|
(*length)++; |
603
|
0
|
|
|
|
|
|
break; |
604
|
|
|
|
|
|
|
case '\\': |
605
|
0
|
0
|
|
|
|
|
if ('0' <= s[1] && s[1] <= '9' && |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
606
|
0
|
0
|
|
|
|
|
'0' <= s[2] && s[2] <= '9' && |
|
|
0
|
|
|
|
|
|
607
|
0
|
0
|
|
|
|
|
'0' <= s[3] && s[3] <= '9') { |
608
|
|
|
|
|
|
|
/* \DDD seen */ |
609
|
0
|
|
|
|
|
|
int val = ((s[1] - '0') * 100 + |
610
|
0
|
|
|
|
|
|
(s[2] - '0') * 10 + (s[3] - '0')); |
611
|
|
|
|
|
|
|
|
612
|
0
|
0
|
|
|
|
|
if (0 <= val && val <= 255) { |
|
|
0
|
|
|
|
|
|
613
|
|
|
|
|
|
|
/* this also handles \0 */ |
614
|
0
|
|
|
|
|
|
s += 3; |
615
|
0
|
|
|
|
|
|
*p = val; |
616
|
0
|
|
|
|
|
|
(*length)++; |
617
|
|
|
|
|
|
|
} else { |
618
|
0
|
|
|
|
|
|
return LDNS_STATUS_DDD_OVERFLOW; |
619
|
|
|
|
|
|
|
} |
620
|
|
|
|
|
|
|
} else { |
621
|
|
|
|
|
|
|
/* an espaced character, like \ ? |
622
|
|
|
|
|
|
|
* remove the '\' keep the rest */ |
623
|
0
|
|
|
|
|
|
*p = *++s; |
624
|
0
|
|
|
|
|
|
(*length)++; |
625
|
|
|
|
|
|
|
} |
626
|
0
|
|
|
|
|
|
break; |
627
|
|
|
|
|
|
|
case '\"': |
628
|
|
|
|
|
|
|
/* non quoted " Is either first or the last character in |
629
|
|
|
|
|
|
|
* the string */ |
630
|
|
|
|
|
|
|
|
631
|
0
|
|
|
|
|
|
*p = *++s; /* skip it */ |
632
|
0
|
|
|
|
|
|
(*length)++; |
633
|
|
|
|
|
|
|
/* I'm not sure if this is needed in libdns... MG */ |
634
|
0
|
0
|
|
|
|
|
if ( *s == '\0' ) { |
635
|
|
|
|
|
|
|
/* ok, it was the last one */ |
636
|
0
|
|
|
|
|
|
*p = '\0'; |
637
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
638
|
|
|
|
|
|
|
} |
639
|
0
|
|
|
|
|
|
break; |
640
|
|
|
|
|
|
|
default: |
641
|
0
|
|
|
|
|
|
*p = *s; |
642
|
0
|
|
|
|
|
|
(*length)++; |
643
|
0
|
|
|
|
|
|
break; |
644
|
|
|
|
|
|
|
} |
645
|
|
|
|
|
|
|
} |
646
|
0
|
|
|
|
|
|
*p = '\0'; |
647
|
0
|
|
|
|
|
|
return LDNS_STATUS_OK; |
648
|
|
|
|
|
|
|
} |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
int |
651
|
21
|
|
|
|
|
|
ldns_rdf_compare(const ldns_rdf *rd1, const ldns_rdf *rd2) |
652
|
|
|
|
|
|
|
{ |
653
|
|
|
|
|
|
|
uint16_t i1, i2, i; |
654
|
|
|
|
|
|
|
uint8_t *d1, *d2; |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
/* only when both are not NULL we can say anything about them */ |
657
|
21
|
50
|
|
|
|
|
if (!rd1 && !rd2) { |
|
|
0
|
|
|
|
|
|
658
|
0
|
|
|
|
|
|
return 0; |
659
|
|
|
|
|
|
|
} |
660
|
21
|
50
|
|
|
|
|
if (!rd1 || !rd2) { |
|
|
50
|
|
|
|
|
|
661
|
0
|
|
|
|
|
|
return -1; |
662
|
|
|
|
|
|
|
} |
663
|
21
|
|
|
|
|
|
i1 = ldns_rdf_size(rd1); |
664
|
21
|
|
|
|
|
|
i2 = ldns_rdf_size(rd2); |
665
|
|
|
|
|
|
|
|
666
|
21
|
100
|
|
|
|
|
if (i1 < i2) { |
667
|
18
|
|
|
|
|
|
return -1; |
668
|
3
|
50
|
|
|
|
|
} else if (i1 > i2) { |
669
|
0
|
|
|
|
|
|
return +1; |
670
|
|
|
|
|
|
|
} else { |
671
|
3
|
|
|
|
|
|
d1 = (uint8_t*)ldns_rdf_data(rd1); |
672
|
3
|
|
|
|
|
|
d2 = (uint8_t*)ldns_rdf_data(rd2); |
673
|
20
|
100
|
|
|
|
|
for(i = 0; i < i1; i++) { |
674
|
18
|
50
|
|
|
|
|
if (d1[i] < d2[i]) { |
675
|
0
|
|
|
|
|
|
return -1; |
676
|
18
|
100
|
|
|
|
|
} else if (d1[i] > d2[i]) { |
677
|
1
|
|
|
|
|
|
return +1; |
678
|
|
|
|
|
|
|
} |
679
|
|
|
|
|
|
|
} |
680
|
|
|
|
|
|
|
} |
681
|
2
|
|
|
|
|
|
return 0; |
682
|
|
|
|
|
|
|
} |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
uint32_t |
685
|
68
|
|
|
|
|
|
ldns_str2period(const char *nptr, const char **endptr) |
686
|
|
|
|
|
|
|
{ |
687
|
68
|
|
|
|
|
|
int sign = 0; |
688
|
68
|
|
|
|
|
|
uint32_t i = 0; |
689
|
68
|
|
|
|
|
|
uint32_t seconds = 0; |
690
|
|
|
|
|
|
|
|
691
|
189
|
100
|
|
|
|
|
for(*endptr = nptr; **endptr; (*endptr)++) { |
692
|
164
|
|
|
|
|
|
switch (**endptr) { |
693
|
|
|
|
|
|
|
case ' ': |
694
|
|
|
|
|
|
|
case '\t': |
695
|
0
|
|
|
|
|
|
break; |
696
|
|
|
|
|
|
|
case '-': |
697
|
0
|
0
|
|
|
|
|
if(sign == 0) { |
698
|
0
|
|
|
|
|
|
sign = -1; |
699
|
|
|
|
|
|
|
} else { |
700
|
0
|
|
|
|
|
|
return seconds; |
701
|
|
|
|
|
|
|
} |
702
|
0
|
|
|
|
|
|
break; |
703
|
|
|
|
|
|
|
case '+': |
704
|
0
|
0
|
|
|
|
|
if(sign == 0) { |
705
|
0
|
|
|
|
|
|
sign = 1; |
706
|
|
|
|
|
|
|
} else { |
707
|
0
|
|
|
|
|
|
return seconds; |
708
|
|
|
|
|
|
|
} |
709
|
0
|
|
|
|
|
|
break; |
710
|
|
|
|
|
|
|
case 's': |
711
|
|
|
|
|
|
|
case 'S': |
712
|
0
|
|
|
|
|
|
seconds += i; |
713
|
0
|
|
|
|
|
|
i = 0; |
714
|
0
|
|
|
|
|
|
break; |
715
|
|
|
|
|
|
|
case 'm': |
716
|
|
|
|
|
|
|
case 'M': |
717
|
1
|
|
|
|
|
|
seconds += i * 60; |
718
|
1
|
|
|
|
|
|
i = 0; |
719
|
1
|
|
|
|
|
|
break; |
720
|
|
|
|
|
|
|
case 'h': |
721
|
|
|
|
|
|
|
case 'H': |
722
|
0
|
|
|
|
|
|
seconds += i * 60 * 60; |
723
|
0
|
|
|
|
|
|
i = 0; |
724
|
0
|
|
|
|
|
|
break; |
725
|
|
|
|
|
|
|
case 'd': |
726
|
|
|
|
|
|
|
case 'D': |
727
|
0
|
|
|
|
|
|
seconds += i * 60 * 60 * 24; |
728
|
0
|
|
|
|
|
|
i = 0; |
729
|
0
|
|
|
|
|
|
break; |
730
|
|
|
|
|
|
|
case 'w': |
731
|
|
|
|
|
|
|
case 'W': |
732
|
0
|
|
|
|
|
|
seconds += i * 60 * 60 * 24 * 7; |
733
|
0
|
|
|
|
|
|
i = 0; |
734
|
0
|
|
|
|
|
|
break; |
735
|
|
|
|
|
|
|
case '0': |
736
|
|
|
|
|
|
|
case '1': |
737
|
|
|
|
|
|
|
case '2': |
738
|
|
|
|
|
|
|
case '3': |
739
|
|
|
|
|
|
|
case '4': |
740
|
|
|
|
|
|
|
case '5': |
741
|
|
|
|
|
|
|
case '6': |
742
|
|
|
|
|
|
|
case '7': |
743
|
|
|
|
|
|
|
case '8': |
744
|
|
|
|
|
|
|
case '9': |
745
|
120
|
|
|
|
|
|
i *= 10; |
746
|
120
|
|
|
|
|
|
i += (**endptr - '0'); |
747
|
120
|
|
|
|
|
|
break; |
748
|
|
|
|
|
|
|
default: |
749
|
43
|
|
|
|
|
|
seconds += i; |
750
|
|
|
|
|
|
|
/* disregard signedness */ |
751
|
43
|
|
|
|
|
|
return seconds; |
752
|
|
|
|
|
|
|
} |
753
|
|
|
|
|
|
|
} |
754
|
25
|
|
|
|
|
|
seconds += i; |
755
|
|
|
|
|
|
|
/* disregard signedness */ |
756
|
25
|
|
|
|
|
|
return seconds; |
757
|
|
|
|
|
|
|
} |