summaryrefslogtreecommitdiff
path: root/src/gnsrecord/plugin_gnsrecord_dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnsrecord/plugin_gnsrecord_dns.c')
-rw-r--r--src/gnsrecord/plugin_gnsrecord_dns.c765
1 files changed, 385 insertions, 380 deletions
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c
index 8c39603e3..9a45b5b93 100644
--- a/src/gnsrecord/plugin_gnsrecord_dns.c
+++ b/src/gnsrecord/plugin_gnsrecord_dns.c
@@ -39,177 +39,177 @@
39 * @return NULL on error, otherwise human-readable representation of the value 39 * @return NULL on error, otherwise human-readable representation of the value
40 */ 40 */
41static char * 41static char *
42dns_value_to_string(void *cls, 42dns_value_to_string (void *cls,
43 uint32_t type, 43 uint32_t type,
44 const void *data, 44 const void *data,
45 size_t data_size) 45 size_t data_size)
46{ 46{
47 char *result; 47 char *result;
48 char tmp[INET6_ADDRSTRLEN]; 48 char tmp[INET6_ADDRSTRLEN];
49 49
50 switch (type) 50 switch (type)
51 { 51 {
52 case GNUNET_DNSPARSER_TYPE_A: 52 case GNUNET_DNSPARSER_TYPE_A:
53 if (data_size != sizeof(struct in_addr)) 53 if (data_size != sizeof(struct in_addr))
54 return NULL; 54 return NULL;
55 if (NULL == inet_ntop(AF_INET, data, tmp, sizeof(tmp))) 55 if (NULL == inet_ntop (AF_INET, data, tmp, sizeof(tmp)))
56 return NULL; 56 return NULL;
57 return GNUNET_strdup(tmp); 57 return GNUNET_strdup (tmp);
58 58
59 case GNUNET_DNSPARSER_TYPE_NS: { 59 case GNUNET_DNSPARSER_TYPE_NS: {
60 char *ns; 60 char *ns;
61 size_t off; 61 size_t off;
62 62
63 off = 0; 63 off = 0;
64 ns = GNUNET_DNSPARSER_parse_name(data, data_size, &off); 64 ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
65 if ((NULL == ns) || (off != data_size)) 65 if ((NULL == ns) || (off != data_size))
66 { 66 {
67 GNUNET_break_op(0); 67 GNUNET_break_op (0);
68 GNUNET_free_non_null(ns); 68 GNUNET_free_non_null (ns);
69 return NULL; 69 return NULL;
70 } 70 }
71 return ns; 71 return ns;
72 } 72 }
73 73
74 case GNUNET_DNSPARSER_TYPE_CNAME: { 74 case GNUNET_DNSPARSER_TYPE_CNAME: {
75 char *cname; 75 char *cname;
76 size_t off; 76 size_t off;
77 77
78 off = 0; 78 off = 0;
79 cname = GNUNET_DNSPARSER_parse_name(data, data_size, &off); 79 cname = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
80 if ((NULL == cname) || (off != data_size)) 80 if ((NULL == cname) || (off != data_size))
81 { 81 {
82 GNUNET_break_op(0); 82 GNUNET_break_op (0);
83 GNUNET_free_non_null(cname); 83 GNUNET_free_non_null (cname);
84 return NULL; 84 return NULL;
85 } 85 }
86 return cname; 86 return cname;
87 } 87 }
88 88
89 case GNUNET_DNSPARSER_TYPE_SOA: { 89 case GNUNET_DNSPARSER_TYPE_SOA: {
90 struct GNUNET_DNSPARSER_SoaRecord *soa; 90 struct GNUNET_DNSPARSER_SoaRecord *soa;
91 size_t off; 91 size_t off;
92 92
93 off = 0; 93 off = 0;
94 soa = GNUNET_DNSPARSER_parse_soa(data, data_size, &off); 94 soa = GNUNET_DNSPARSER_parse_soa (data, data_size, &off);
95 if ((NULL == soa) || (off != data_size)) 95 if ((NULL == soa) || (off != data_size))
96 { 96 {
97 GNUNET_break_op(0); 97 GNUNET_break_op (0);
98 if (NULL != soa) 98 if (NULL != soa)
99 GNUNET_DNSPARSER_free_soa(soa); 99 GNUNET_DNSPARSER_free_soa (soa);
100 return NULL; 100 return NULL;
101 } 101 }
102 GNUNET_asprintf(&result, 102 GNUNET_asprintf (&result,
103 "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu", 103 "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu",
104 soa->rname, 104 soa->rname,
105 soa->mname, 105 soa->mname,
106 soa->serial, 106 soa->serial,
107 soa->refresh, 107 soa->refresh,
108 soa->retry, 108 soa->retry,
109 soa->expire, 109 soa->expire,
110 soa->minimum_ttl); 110 soa->minimum_ttl);
111 GNUNET_DNSPARSER_free_soa(soa); 111 GNUNET_DNSPARSER_free_soa (soa);
112 return result; 112 return result;
113 } 113 }
114 114
115 case GNUNET_DNSPARSER_TYPE_PTR: { 115 case GNUNET_DNSPARSER_TYPE_PTR: {
116 char *ptr; 116 char *ptr;
117 size_t off; 117 size_t off;
118 118
119 off = 0; 119 off = 0;
120 ptr = GNUNET_DNSPARSER_parse_name(data, data_size, &off); 120 ptr = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
121 if ((NULL == ptr) || (off != data_size)) 121 if ((NULL == ptr) || (off != data_size))
122 { 122 {
123 GNUNET_break_op(0); 123 GNUNET_break_op (0);
124 GNUNET_free_non_null(ptr); 124 GNUNET_free_non_null (ptr);
125 return NULL; 125 return NULL;
126 } 126 }
127 return ptr; 127 return ptr;
128 } 128 }
129 129
130 case GNUNET_DNSPARSER_TYPE_CERT: { 130 case GNUNET_DNSPARSER_TYPE_CERT: {
131 struct GNUNET_DNSPARSER_CertRecord *cert; 131 struct GNUNET_DNSPARSER_CertRecord *cert;
132 size_t off; 132 size_t off;
133 char *base64; 133 char *base64;
134 int len; 134 int len;
135 135
136 off = 0; 136 off = 0;
137 cert = GNUNET_DNSPARSER_parse_cert(data, data_size, &off); 137 cert = GNUNET_DNSPARSER_parse_cert (data, data_size, &off);
138 if ((NULL == cert) || (off != data_size)) 138 if ((NULL == cert) || (off != data_size))
139 { 139 {
140 GNUNET_break_op(0); 140 GNUNET_break_op (0);
141 GNUNET_DNSPARSER_free_cert(cert); 141 GNUNET_DNSPARSER_free_cert (cert);
142 return NULL; 142 return NULL;
143 } 143 }
144 len = GNUNET_STRINGS_base64_encode(cert->certificate_data, 144 len = GNUNET_STRINGS_base64_encode (cert->certificate_data,
145 cert->certificate_size, 145 cert->certificate_size,
146 &base64); 146 &base64);
147 GNUNET_asprintf(&result, 147 GNUNET_asprintf (&result,
148 "%u %u %u %.*s", 148 "%u %u %u %.*s",
149 cert->cert_type, 149 cert->cert_type,
150 cert->cert_tag, 150 cert->cert_tag,
151 cert->algorithm, 151 cert->algorithm,
152 len, 152 len,
153 base64); 153 base64);
154 GNUNET_free(base64); 154 GNUNET_free (base64);
155 GNUNET_DNSPARSER_free_cert(cert); 155 GNUNET_DNSPARSER_free_cert (cert);
156 return result; 156 return result;
157 } 157 }
158 158
159 case GNUNET_DNSPARSER_TYPE_MX: { 159 case GNUNET_DNSPARSER_TYPE_MX: {
160 struct GNUNET_DNSPARSER_MxRecord *mx; 160 struct GNUNET_DNSPARSER_MxRecord *mx;
161 size_t off; 161 size_t off;
162 162
163 off = 0; 163 off = 0;
164 mx = GNUNET_DNSPARSER_parse_mx(data, data_size, &off); 164 mx = GNUNET_DNSPARSER_parse_mx (data, data_size, &off);
165 if ((NULL == mx) || (off != data_size)) 165 if ((NULL == mx) || (off != data_size))
166 { 166 {
167 GNUNET_break_op(0); 167 GNUNET_break_op (0);
168 GNUNET_DNSPARSER_free_mx(mx); 168 GNUNET_DNSPARSER_free_mx (mx);
169 return NULL; 169 return NULL;
170 } 170 }
171 GNUNET_asprintf(&result, 171 GNUNET_asprintf (&result,
172 "%u,%s", 172 "%u,%s",
173 (unsigned int)mx->preference, 173 (unsigned int) mx->preference,
174 mx->mxhost); 174 mx->mxhost);
175 GNUNET_DNSPARSER_free_mx(mx); 175 GNUNET_DNSPARSER_free_mx (mx);
176 return result; 176 return result;
177 } 177 }
178 178
179 case GNUNET_DNSPARSER_TYPE_TXT: 179 case GNUNET_DNSPARSER_TYPE_TXT:
180 return GNUNET_strndup(data, data_size); 180 return GNUNET_strndup (data, data_size);
181 181
182 case GNUNET_DNSPARSER_TYPE_AAAA: 182 case GNUNET_DNSPARSER_TYPE_AAAA:
183 if (data_size != sizeof(struct in6_addr)) 183 if (data_size != sizeof(struct in6_addr))
184 return NULL; 184 return NULL;
185 if (NULL == inet_ntop(AF_INET6, data, tmp, sizeof(tmp))) 185 if (NULL == inet_ntop (AF_INET6, data, tmp, sizeof(tmp)))
186 return NULL; 186 return NULL;
187 return GNUNET_strdup(tmp); 187 return GNUNET_strdup (tmp);
188 188
189 case GNUNET_DNSPARSER_TYPE_SRV: { 189 case GNUNET_DNSPARSER_TYPE_SRV: {
190 struct GNUNET_DNSPARSER_SrvRecord *srv; 190 struct GNUNET_DNSPARSER_SrvRecord *srv;
191 size_t off; 191 size_t off;
192 192
193 off = 0; 193 off = 0;
194 srv = GNUNET_DNSPARSER_parse_srv(data, data_size, &off); 194 srv = GNUNET_DNSPARSER_parse_srv (data, data_size, &off);
195 if ((NULL == srv) || (off != data_size)) 195 if ((NULL == srv) || (off != data_size))
196 { 196 {
197 GNUNET_break_op(0); 197 GNUNET_break_op (0);
198 if (NULL != srv) 198 if (NULL != srv)
199 GNUNET_DNSPARSER_free_srv(srv); 199 GNUNET_DNSPARSER_free_srv (srv);
200 return NULL; 200 return NULL;
201 } 201 }
202 GNUNET_asprintf(&result, 202 GNUNET_asprintf (&result,
203 "%d %d %d %s", 203 "%d %d %d %s",
204 srv->priority, 204 srv->priority,
205 srv->weight, 205 srv->weight,
206 srv->port, 206 srv->port,
207 srv->target); 207 srv->target);
208 GNUNET_DNSPARSER_free_srv(srv); 208 GNUNET_DNSPARSER_free_srv (srv);
209 return result; 209 return result;
210 } 210 }
211 211
212 case GNUNET_DNSPARSER_TYPE_TLSA: { 212 case GNUNET_DNSPARSER_TYPE_TLSA: {
213 const struct GNUNET_TUN_DnsTlsaRecord *tlsa; 213 const struct GNUNET_TUN_DnsTlsaRecord *tlsa;
214 char *tlsa_str; 214 char *tlsa_str;
215 char *hex; 215 char *hex;
@@ -218,25 +218,25 @@ dns_value_to_string(void *cls,
218 return NULL; /* malformed */ 218 return NULL; /* malformed */
219 tlsa = data; 219 tlsa = data;
220 hex = 220 hex =
221 GNUNET_DNSPARSER_bin_to_hex(&tlsa[1], 221 GNUNET_DNSPARSER_bin_to_hex (&tlsa[1],
222 data_size - 222 data_size
223 sizeof(struct GNUNET_TUN_DnsTlsaRecord)); 223 - sizeof(struct GNUNET_TUN_DnsTlsaRecord));
224 if (0 == GNUNET_asprintf(&tlsa_str, 224 if (0 == GNUNET_asprintf (&tlsa_str,
225 "%u %u %u %s", 225 "%u %u %u %s",
226 (unsigned int)tlsa->usage, 226 (unsigned int) tlsa->usage,
227 (unsigned int)tlsa->selector, 227 (unsigned int) tlsa->selector,
228 (unsigned int)tlsa->matching_type, 228 (unsigned int) tlsa->matching_type,
229 hex)) 229 hex))
230 { 230 {
231 GNUNET_free(hex); 231 GNUNET_free (hex);
232 GNUNET_free(tlsa_str); 232 GNUNET_free (tlsa_str);
233 return NULL; 233 return NULL;
234 } 234 }
235 GNUNET_free(hex); 235 GNUNET_free (hex);
236 return tlsa_str; 236 return tlsa_str;
237 } 237 }
238 238
239 case GNUNET_DNSPARSER_TYPE_CAA: { //RFC6844 239 case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
240 const struct GNUNET_DNSPARSER_CaaRecord *caa; 240 const struct GNUNET_DNSPARSER_CaaRecord *caa;
241 char tag[15]; // between 1 and 15 bytes 241 char tag[15]; // between 1 and 15 bytes
242 char value[data_size]; 242 char value[data_size];
@@ -246,27 +246,27 @@ dns_value_to_string(void *cls,
246 caa = data; 246 caa = data;
247 if ((1 > caa->tag_len) || (15 < caa->tag_len)) 247 if ((1 > caa->tag_len) || (15 < caa->tag_len))
248 return NULL; /* malformed */ 248 return NULL; /* malformed */
249 memset(tag, 0, sizeof(tag)); 249 memset (tag, 0, sizeof(tag));
250 memset(value, 0, data_size); 250 memset (value, 0, data_size);
251 memcpy(tag, &caa[1], caa->tag_len); 251 memcpy (tag, &caa[1], caa->tag_len);
252 memcpy(value, 252 memcpy (value,
253 (char *)&caa[1] + caa->tag_len, 253 (char *) &caa[1] + caa->tag_len,
254 data_size - caa->tag_len - 2); 254 data_size - caa->tag_len - 2);
255 if (0 == GNUNET_asprintf(&caa_str, 255 if (0 == GNUNET_asprintf (&caa_str,
256 "%u %s %s", 256 "%u %s %s",
257 (unsigned int)caa->flags, 257 (unsigned int) caa->flags,
258 tag, 258 tag,
259 value)) 259 value))
260 { 260 {
261 GNUNET_free(caa_str); 261 GNUNET_free (caa_str);
262 return NULL; 262 return NULL;
263 } 263 }
264 return caa_str; 264 return caa_str;
265 } 265 }
266 266
267 default: 267 default:
268 return NULL; 268 return NULL;
269 } 269 }
270} 270}
271 271
272 272
@@ -277,9 +277,10 @@ dns_value_to_string(void *cls,
277 * @return the value, 0 if not found 277 * @return the value, 0 if not found
278 */ 278 */
279static unsigned int 279static unsigned int
280rfc4398_mnemonic_to_value(const char *mnemonic) 280rfc4398_mnemonic_to_value (const char *mnemonic)
281{ 281{
282 static struct { 282 static struct
283 {
283 const char *mnemonic; 284 const char *mnemonic;
284 unsigned int val; 285 unsigned int val;
285 } table[] = { { "PKIX", 1 }, 286 } table[] = { { "PKIX", 1 },
@@ -296,7 +297,7 @@ rfc4398_mnemonic_to_value(const char *mnemonic)
296 unsigned int i; 297 unsigned int i;
297 298
298 for (i = 0; NULL != table[i].mnemonic; i++) 299 for (i = 0; NULL != table[i].mnemonic; i++)
299 if (0 == strcasecmp(mnemonic, table[i].mnemonic)) 300 if (0 == strcasecmp (mnemonic, table[i].mnemonic))
300 return table[i].val; 301 return table[i].val;
301 return 0; 302 return 0;
302} 303}
@@ -309,9 +310,10 @@ rfc4398_mnemonic_to_value(const char *mnemonic)
309 * @return the value, 0 if not found 310 * @return the value, 0 if not found
310 */ 311 */
311static unsigned int 312static unsigned int
312rfc4034_mnemonic_to_value(const char *mnemonic) 313rfc4034_mnemonic_to_value (const char *mnemonic)
313{ 314{
314 static struct { 315 static struct
316 {
315 const char *mnemonic; 317 const char *mnemonic;
316 unsigned int val; 318 unsigned int val;
317 } table[] = { { "RSAMD5", 1 }, 319 } table[] = { { "RSAMD5", 1 },
@@ -326,7 +328,7 @@ rfc4034_mnemonic_to_value(const char *mnemonic)
326 unsigned int i; 328 unsigned int i;
327 329
328 for (i = 0; NULL != table[i].mnemonic; i++) 330 for (i = 0; NULL != table[i].mnemonic; i++)
329 if (0 == strcasecmp(mnemonic, table[i].mnemonic)) 331 if (0 == strcasecmp (mnemonic, table[i].mnemonic))
330 return table[i].val; 332 return table[i].val;
331 return 0; 333 return 0;
332} 334}
@@ -344,11 +346,11 @@ rfc4034_mnemonic_to_value(const char *mnemonic)
344 * @return #GNUNET_OK on success 346 * @return #GNUNET_OK on success
345 */ 347 */
346static int 348static int
347dns_string_to_value(void *cls, 349dns_string_to_value (void *cls,
348 uint32_t type, 350 uint32_t type,
349 const char *s, 351 const char *s,
350 void **data, 352 void **data,
351 size_t *data_size) 353 size_t *data_size)
352{ 354{
353 struct in_addr value_a; 355 struct in_addr value_a;
354 struct in6_addr value_aaaa; 356 struct in6_addr value_aaaa;
@@ -357,61 +359,61 @@ dns_string_to_value(void *cls,
357 if (NULL == s) 359 if (NULL == s)
358 return GNUNET_SYSERR; 360 return GNUNET_SYSERR;
359 switch (type) 361 switch (type)
362 {
363 case GNUNET_DNSPARSER_TYPE_A:
364 if (1 != inet_pton (AF_INET, s, &value_a))
360 { 365 {
361 case GNUNET_DNSPARSER_TYPE_A: 366 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
362 if (1 != inet_pton(AF_INET, s, &value_a)) 367 _ ("Unable to parse IPv4 address `%s'\n"),
363 { 368 s);
364 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 369 return GNUNET_SYSERR;
365 _("Unable to parse IPv4 address `%s'\n"), 370 }
366 s); 371 *data = GNUNET_new (struct in_addr);
367 return GNUNET_SYSERR; 372 GNUNET_memcpy (*data, &value_a, sizeof(value_a));
368 } 373 *data_size = sizeof(value_a);
369 *data = GNUNET_new(struct in_addr); 374 return GNUNET_OK;
370 GNUNET_memcpy(*data, &value_a, sizeof(value_a));
371 *data_size = sizeof(value_a);
372 return GNUNET_OK;
373 375
374 case GNUNET_DNSPARSER_TYPE_NS: { 376 case GNUNET_DNSPARSER_TYPE_NS: {
375 char nsbuf[256]; 377 char nsbuf[256];
376 size_t off; 378 size_t off;
377 379
378 off = 0; 380 off = 0;
379 if (GNUNET_OK != 381 if (GNUNET_OK !=
380 GNUNET_DNSPARSER_builder_add_name(nsbuf, sizeof(nsbuf), &off, s)) 382 GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, s))
381 { 383 {
382 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
383 _("Failed to serialize NS record with value `%s'\n"), 385 _ ("Failed to serialize NS record with value `%s'\n"),
384 s); 386 s);
385 return GNUNET_SYSERR; 387 return GNUNET_SYSERR;
386 } 388 }
387 *data_size = off; 389 *data_size = off;
388 *data = GNUNET_malloc(off); 390 *data = GNUNET_malloc (off);
389 GNUNET_memcpy(*data, nsbuf, off); 391 GNUNET_memcpy (*data, nsbuf, off);
390 return GNUNET_OK; 392 return GNUNET_OK;
391 } 393 }
392 394
393 case GNUNET_DNSPARSER_TYPE_CNAME: { 395 case GNUNET_DNSPARSER_TYPE_CNAME: {
394 char cnamebuf[256]; 396 char cnamebuf[256];
395 size_t off; 397 size_t off;
396 398
397 off = 0; 399 off = 0;
398 if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_name(cnamebuf, 400 if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (cnamebuf,
399 sizeof(cnamebuf), 401 sizeof(cnamebuf),
400 &off, 402 &off,
401 s)) 403 s))
402 { 404 {
403 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
404 _("Failed to serialize CNAME record with value `%s'\n"), 406 _ ("Failed to serialize CNAME record with value `%s'\n"),
405 s); 407 s);
406 return GNUNET_SYSERR; 408 return GNUNET_SYSERR;
407 } 409 }
408 *data_size = off; 410 *data_size = off;
409 *data = GNUNET_malloc(off); 411 *data = GNUNET_malloc (off);
410 GNUNET_memcpy(*data, cnamebuf, off); 412 GNUNET_memcpy (*data, cnamebuf, off);
411 return GNUNET_OK; 413 return GNUNET_OK;
412 } 414 }
413 415
414 case GNUNET_DNSPARSER_TYPE_CERT: { 416 case GNUNET_DNSPARSER_TYPE_CERT: {
415 char *sdup; 417 char *sdup;
416 const char *typep; 418 const char *typep;
417 const char *keyp; 419 const char *keyp;
@@ -424,41 +426,41 @@ dns_string_to_value(void *cls,
424 char *cert_data; 426 char *cert_data;
425 struct GNUNET_DNSPARSER_CertRecord cert; 427 struct GNUNET_DNSPARSER_CertRecord cert;
426 428
427 sdup = GNUNET_strdup(s); 429 sdup = GNUNET_strdup (s);
428 typep = strtok(sdup, " "); 430 typep = strtok (sdup, " ");
429 if ((NULL == typep) || 431 if ((NULL == typep) ||
430 ((0 == (type = rfc4398_mnemonic_to_value(typep))) && 432 ((0 == (type = rfc4398_mnemonic_to_value (typep))) &&
431 ((1 != sscanf(typep, "%u", &type)) || (type > UINT16_MAX)))) 433 ((1 != sscanf (typep, "%u", &type)) || (type > UINT16_MAX))))
432 { 434 {
433 GNUNET_free(sdup); 435 GNUNET_free (sdup);
434 return GNUNET_SYSERR; 436 return GNUNET_SYSERR;
435 } 437 }
436 keyp = strtok(NULL, " "); 438 keyp = strtok (NULL, " ");
437 if ((NULL == keyp) || (1 != sscanf(keyp, "%u", &key)) || 439 if ((NULL == keyp) || (1 != sscanf (keyp, "%u", &key)) ||
438 (key > UINT16_MAX)) 440 (key > UINT16_MAX))
439 { 441 {
440 GNUNET_free(sdup); 442 GNUNET_free (sdup);
441 return GNUNET_SYSERR; 443 return GNUNET_SYSERR;
442 } 444 }
443 alg = 0; 445 alg = 0;
444 algp = strtok(NULL, " "); 446 algp = strtok (NULL, " ");
445 if ((NULL == algp) || 447 if ((NULL == algp) ||
446 ((0 == (type = rfc4034_mnemonic_to_value(typep))) && 448 ((0 == (type = rfc4034_mnemonic_to_value (typep))) &&
447 ((1 != sscanf(algp, "%u", &alg)) || (alg > UINT8_MAX)))) 449 ((1 != sscanf (algp, "%u", &alg)) || (alg > UINT8_MAX))))
448 { 450 {
449 GNUNET_free(sdup); 451 GNUNET_free (sdup);
450 return GNUNET_SYSERR; 452 return GNUNET_SYSERR;
451 } 453 }
452 certp = strtok(NULL, " "); 454 certp = strtok (NULL, " ");
453 if ((NULL == certp) || (0 == strlen(certp))) 455 if ((NULL == certp) || (0 == strlen (certp)))
454 { 456 {
455 GNUNET_free(sdup); 457 GNUNET_free (sdup);
456 return GNUNET_SYSERR; 458 return GNUNET_SYSERR;
457 } 459 }
458 cert_size = GNUNET_STRINGS_base64_decode(certp, 460 cert_size = GNUNET_STRINGS_base64_decode (certp,
459 strlen(certp), 461 strlen (certp),
460 (void **)&cert_data); 462 (void **) &cert_data);
461 GNUNET_free(sdup); 463 GNUNET_free (sdup);
462 cert.cert_type = type; 464 cert.cert_type = type;
463 cert.cert_tag = key; 465 cert.cert_tag = key;
464 cert.algorithm = alg; 466 cert.algorithm = alg;
@@ -469,26 +471,26 @@ dns_string_to_value(void *cls,
469 size_t off; 471 size_t off;
470 472
471 off = 0; 473 off = 0;
472 if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_cert(certbuf, 474 if (GNUNET_OK != GNUNET_DNSPARSER_builder_add_cert (certbuf,
473 sizeof(certbuf), 475 sizeof(certbuf),
474 &off, 476 &off,
475 &cert)) 477 &cert))
476 { 478 {
477 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 479 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
478 _("Failed to serialize CERT record with %u bytes\n"), 480 _ ("Failed to serialize CERT record with %u bytes\n"),
479 (unsigned int)cert_size); 481 (unsigned int) cert_size);
480 GNUNET_free(cert_data); 482 GNUNET_free (cert_data);
481 return GNUNET_SYSERR; 483 return GNUNET_SYSERR;
482 } 484 }
483 *data_size = off; 485 *data_size = off;
484 *data = GNUNET_malloc(off); 486 *data = GNUNET_malloc (off);
485 GNUNET_memcpy(*data, certbuf, off); 487 GNUNET_memcpy (*data, certbuf, off);
486 } 488 }
487 GNUNET_free(cert_data); 489 GNUNET_free (cert_data);
488 return GNUNET_OK; 490 return GNUNET_OK;
489 } 491 }
490 492
491 case GNUNET_DNSPARSER_TYPE_SOA: { 493 case GNUNET_DNSPARSER_TYPE_SOA: {
492 struct GNUNET_DNSPARSER_SoaRecord soa; 494 struct GNUNET_DNSPARSER_SoaRecord soa;
493 char soabuf[540]; 495 char soabuf[540];
494 char soa_rname[253 + 1]; 496 char soa_rname[253 + 1];
@@ -500,97 +502,97 @@ dns_string_to_value(void *cls,
500 unsigned int soa_min; 502 unsigned int soa_min;
501 size_t off; 503 size_t off;
502 504
503 if (7 != sscanf(s, 505 if (7 != sscanf (s,
504 "rname=%253s mname=%253s %u,%u,%u,%u,%u", 506 "rname=%253s mname=%253s %u,%u,%u,%u,%u",
505 soa_rname, 507 soa_rname,
506 soa_mname, 508 soa_mname,
507 &soa_serial, 509 &soa_serial,
508 &soa_refresh, 510 &soa_refresh,
509 &soa_retry, 511 &soa_retry,
510 &soa_expire, 512 &soa_expire,
511 &soa_min)) 513 &soa_min))
512 { 514 {
513 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 515 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
514 _("Unable to parse SOA record `%s'\n"), 516 _ ("Unable to parse SOA record `%s'\n"),
515 s); 517 s);
516 return GNUNET_SYSERR; 518 return GNUNET_SYSERR;
517 } 519 }
518 soa.mname = soa_mname; 520 soa.mname = soa_mname;
519 soa.rname = soa_rname; 521 soa.rname = soa_rname;
520 soa.serial = (uint32_t)soa_serial; 522 soa.serial = (uint32_t) soa_serial;
521 soa.refresh = (uint32_t)soa_refresh; 523 soa.refresh = (uint32_t) soa_refresh;
522 soa.retry = (uint32_t)soa_retry; 524 soa.retry = (uint32_t) soa_retry;
523 soa.expire = (uint32_t)soa_expire; 525 soa.expire = (uint32_t) soa_expire;
524 soa.minimum_ttl = (uint32_t)soa_min; 526 soa.minimum_ttl = (uint32_t) soa_min;
525 off = 0; 527 off = 0;
526 if (GNUNET_OK != 528 if (GNUNET_OK !=
527 GNUNET_DNSPARSER_builder_add_soa(soabuf, sizeof(soabuf), &off, &soa)) 529 GNUNET_DNSPARSER_builder_add_soa (soabuf, sizeof(soabuf), &off, &soa))
528 { 530 {
529 GNUNET_log( 531 GNUNET_log (
530 GNUNET_ERROR_TYPE_ERROR, 532 GNUNET_ERROR_TYPE_ERROR,
531 _("Failed to serialize SOA record with mname `%s' and rname `%s'\n"), 533 _ ("Failed to serialize SOA record with mname `%s' and rname `%s'\n"),
532 soa_mname, 534 soa_mname,
533 soa_rname); 535 soa_rname);
534 return GNUNET_SYSERR; 536 return GNUNET_SYSERR;
535 } 537 }
536 *data_size = off; 538 *data_size = off;
537 *data = GNUNET_malloc(off); 539 *data = GNUNET_malloc (off);
538 GNUNET_memcpy(*data, soabuf, off); 540 GNUNET_memcpy (*data, soabuf, off);
539 return GNUNET_OK; 541 return GNUNET_OK;
540 } 542 }
541 543
542 case GNUNET_DNSPARSER_TYPE_PTR: { 544 case GNUNET_DNSPARSER_TYPE_PTR: {
543 char ptrbuf[256]; 545 char ptrbuf[256];
544 size_t off; 546 size_t off;
545 547
546 off = 0; 548 off = 0;
547 if (GNUNET_OK != 549 if (GNUNET_OK !=
548 GNUNET_DNSPARSER_builder_add_name(ptrbuf, sizeof(ptrbuf), &off, s)) 550 GNUNET_DNSPARSER_builder_add_name (ptrbuf, sizeof(ptrbuf), &off, s))
549 { 551 {
550 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 552 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
551 _("Failed to serialize PTR record with value `%s'\n"), 553 _ ("Failed to serialize PTR record with value `%s'\n"),
552 s); 554 s);
553 return GNUNET_SYSERR; 555 return GNUNET_SYSERR;
554 } 556 }
555 *data_size = off; 557 *data_size = off;
556 *data = GNUNET_malloc(off); 558 *data = GNUNET_malloc (off);
557 GNUNET_memcpy(*data, ptrbuf, off); 559 GNUNET_memcpy (*data, ptrbuf, off);
558 return GNUNET_OK; 560 return GNUNET_OK;
559 } 561 }
560 562
561 case GNUNET_DNSPARSER_TYPE_MX: { 563 case GNUNET_DNSPARSER_TYPE_MX: {
562 struct GNUNET_DNSPARSER_MxRecord mx; 564 struct GNUNET_DNSPARSER_MxRecord mx;
563 char mxbuf[258]; 565 char mxbuf[258];
564 char mxhost[253 + 1]; 566 char mxhost[253 + 1];
565 unsigned int mx_pref; 567 unsigned int mx_pref;
566 size_t off; 568 size_t off;
567 569
568 if (2 != sscanf(s, "%u,%253s", &mx_pref, mxhost)) 570 if (2 != sscanf (s, "%u,%253s", &mx_pref, mxhost))
569 { 571 {
570 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 572 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
571 _("Unable to parse MX record `%s'\n"), 573 _ ("Unable to parse MX record `%s'\n"),
572 s); 574 s);
573 return GNUNET_SYSERR; 575 return GNUNET_SYSERR;
574 } 576 }
575 mx.preference = (uint16_t)mx_pref; 577 mx.preference = (uint16_t) mx_pref;
576 mx.mxhost = mxhost; 578 mx.mxhost = mxhost;
577 off = 0; 579 off = 0;
578 580
579 if (GNUNET_OK != 581 if (GNUNET_OK !=
580 GNUNET_DNSPARSER_builder_add_mx(mxbuf, sizeof(mxbuf), &off, &mx)) 582 GNUNET_DNSPARSER_builder_add_mx (mxbuf, sizeof(mxbuf), &off, &mx))
581 { 583 {
582 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 584 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
583 _("Failed to serialize MX record with hostname `%s'\n"), 585 _ ("Failed to serialize MX record with hostname `%s'\n"),
584 mxhost); 586 mxhost);
585 return GNUNET_SYSERR; 587 return GNUNET_SYSERR;
586 } 588 }
587 *data_size = off; 589 *data_size = off;
588 *data = GNUNET_malloc(off); 590 *data = GNUNET_malloc (off);
589 GNUNET_memcpy(*data, mxbuf, off); 591 GNUNET_memcpy (*data, mxbuf, off);
590 return GNUNET_OK; 592 return GNUNET_OK;
591 } 593 }
592 594
593 case GNUNET_DNSPARSER_TYPE_SRV: { 595 case GNUNET_DNSPARSER_TYPE_SRV: {
594 struct GNUNET_DNSPARSER_SrvRecord srv; 596 struct GNUNET_DNSPARSER_SrvRecord srv;
595 char srvbuf[270]; 597 char srvbuf[270];
596 char srvtarget[253 + 1]; 598 char srvtarget[253 + 1];
@@ -599,111 +601,113 @@ dns_string_to_value(void *cls,
599 unsigned int port; 601 unsigned int port;
600 size_t off; 602 size_t off;
601 603
602 if (4 != sscanf(s, "%u %u %u %253s", &priority, &weight, &port, srvtarget)) 604 if (4 != sscanf (s, "%u %u %u %253s", &priority, &weight, &port,
603 { 605 srvtarget))
604 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 606 {
605 _("Unable to parse SRV record `%s'\n"), 607 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
606 s); 608 _ ("Unable to parse SRV record `%s'\n"),
607 return GNUNET_SYSERR; 609 s);
608 } 610 return GNUNET_SYSERR;
609 srv.priority = (uint16_t)priority; 611 }
610 srv.weight = (uint16_t)weight; 612 srv.priority = (uint16_t) priority;
611 srv.port = (uint16_t)port; 613 srv.weight = (uint16_t) weight;
614 srv.port = (uint16_t) port;
612 srv.target = srvtarget; 615 srv.target = srvtarget;
613 off = 0; 616 off = 0;
614 if (GNUNET_OK != 617 if (GNUNET_OK !=
615 GNUNET_DNSPARSER_builder_add_srv(srvbuf, sizeof(srvbuf), &off, &srv)) 618 GNUNET_DNSPARSER_builder_add_srv (srvbuf, sizeof(srvbuf), &off, &srv))
616 { 619 {
617 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 620 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
618 _("Failed to serialize SRV record with target `%s'\n"), 621 _ ("Failed to serialize SRV record with target `%s'\n"),
619 srvtarget); 622 srvtarget);
620 return GNUNET_SYSERR; 623 return GNUNET_SYSERR;
621 } 624 }
622 *data_size = off; 625 *data_size = off;
623 *data = GNUNET_malloc(off); 626 *data = GNUNET_malloc (off);
624 GNUNET_memcpy(*data, srvbuf, off); 627 GNUNET_memcpy (*data, srvbuf, off);
625 return GNUNET_OK; 628 return GNUNET_OK;
626 } 629 }
627 630
628 case GNUNET_DNSPARSER_TYPE_TXT: 631 case GNUNET_DNSPARSER_TYPE_TXT:
629 *data = GNUNET_strdup(s); 632 *data = GNUNET_strdup (s);
630 *data_size = strlen(s); 633 *data_size = strlen (s);
631 return GNUNET_OK; 634 return GNUNET_OK;
632 635
633 case GNUNET_DNSPARSER_TYPE_AAAA: 636 case GNUNET_DNSPARSER_TYPE_AAAA:
634 if (1 != inet_pton(AF_INET6, s, &value_aaaa)) 637 if (1 != inet_pton (AF_INET6, s, &value_aaaa))
635 { 638 {
636 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 639 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
637 _("Unable to parse IPv6 address `%s'\n"), 640 _ ("Unable to parse IPv6 address `%s'\n"),
638 s); 641 s);
639 return GNUNET_SYSERR; 642 return GNUNET_SYSERR;
640 } 643 }
641 *data = GNUNET_new(struct in6_addr); 644 *data = GNUNET_new (struct in6_addr);
642 *data_size = sizeof(struct in6_addr); 645 *data_size = sizeof(struct in6_addr);
643 GNUNET_memcpy(*data, &value_aaaa, sizeof(value_aaaa)); 646 GNUNET_memcpy (*data, &value_aaaa, sizeof(value_aaaa));
644 return GNUNET_OK; 647 return GNUNET_OK;
645 648
646 case GNUNET_DNSPARSER_TYPE_TLSA: { 649 case GNUNET_DNSPARSER_TYPE_TLSA: {
647 unsigned int usage; 650 unsigned int usage;
648 unsigned int selector; 651 unsigned int selector;
649 unsigned int matching_type; 652 unsigned int matching_type;
650 size_t slen = strlen(s) + 1; 653 size_t slen = strlen (s) + 1;
651 char hex[slen]; 654 char hex[slen];
652 655
653 if (4 != sscanf(s, "%u %u %u %s", &usage, &selector, &matching_type, hex)) 656 if (4 != sscanf (s, "%u %u %u %s", &usage, &selector, &matching_type,
654 { 657 hex))
655 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 658 {
656 _("Unable to parse TLSA record string `%s'\n"), 659 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
657 s); 660 _ ("Unable to parse TLSA record string `%s'\n"),
658 *data_size = 0; 661 s);
659 return GNUNET_SYSERR; 662 *data_size = 0;
660 } 663 return GNUNET_SYSERR;
664 }
661 665
662 *data_size = sizeof(struct GNUNET_TUN_DnsTlsaRecord) + strlen(hex) / 2; 666 *data_size = sizeof(struct GNUNET_TUN_DnsTlsaRecord) + strlen (hex) / 2;
663 *data = tlsa = GNUNET_malloc(*data_size); 667 *data = tlsa = GNUNET_malloc (*data_size);
664 tlsa->usage = (uint8_t)usage; 668 tlsa->usage = (uint8_t) usage;
665 tlsa->selector = (uint8_t)selector; 669 tlsa->selector = (uint8_t) selector;
666 tlsa->matching_type = (uint8_t)matching_type; 670 tlsa->matching_type = (uint8_t) matching_type;
667 if (strlen(hex) / 2 != GNUNET_DNSPARSER_hex_to_bin(hex, &tlsa[1])) 671 if (strlen (hex) / 2 != GNUNET_DNSPARSER_hex_to_bin (hex, &tlsa[1]))
668 { 672 {
669 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 673 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
670 _("Unable to parse TLSA record string `%s'\n"), 674 _ ("Unable to parse TLSA record string `%s'\n"),
671 s); 675 s);
672 GNUNET_free(*data); 676 GNUNET_free (*data);
673 *data = NULL; 677 *data = NULL;
674 *data_size = 0; 678 *data_size = 0;
675 return GNUNET_SYSERR; 679 return GNUNET_SYSERR;
676 } 680 }
677 return GNUNET_OK; 681 return GNUNET_OK;
678 } 682 }
679 683
680 case GNUNET_DNSPARSER_TYPE_CAA: { //RFC6844 684 case GNUNET_DNSPARSER_TYPE_CAA: { // RFC6844
681 struct GNUNET_DNSPARSER_CaaRecord *caa; 685 struct GNUNET_DNSPARSER_CaaRecord *caa;
682 unsigned int flags; 686 unsigned int flags;
683 char tag[15]; //Max tag length 15 687 char tag[15]; // Max tag length 15
684 char value[strlen(s) + 1]; //Should be more than enough 688 char value[strlen (s) + 1]; // Should be more than enough
685 689
686 if (3 != sscanf(s, "%u %s %[^\n]", &flags, tag, value)) 690 if (3 != sscanf (s, "%u %s %[^\n]", &flags, tag, value))
687 { 691 {
688 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 692 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
689 _("Unable to parse CAA record string `%s'\n"), 693 _ ("Unable to parse CAA record string `%s'\n"),
690 s); 694 s);
691 *data_size = 0; 695 *data_size = 0;
692 return GNUNET_SYSERR; 696 return GNUNET_SYSERR;
693 } 697 }
694 *data_size = sizeof(struct GNUNET_DNSPARSER_CaaRecord) + strlen(tag) + 698 *data_size = sizeof(struct GNUNET_DNSPARSER_CaaRecord) + strlen (tag)
695 strlen(value); 699 + strlen (value);
696 *data = caa = GNUNET_malloc(*data_size); 700 *data = caa = GNUNET_malloc (*data_size);
697 caa->flags = flags; 701 caa->flags = flags;
698 memcpy(&caa[1], tag, strlen(tag)); 702 memcpy (&caa[1], tag, strlen (tag));
699 caa->tag_len = strlen(tag); 703 caa->tag_len = strlen (tag);
700 memcpy((char *)&caa[1] + caa->tag_len, value, strlen(value)); 704 memcpy ((char *) &caa[1] + caa->tag_len, value, strlen (value));
701 return GNUNET_OK; 705 return GNUNET_OK;
702 } 706 }
703 707
704 default: 708 default:
705 return GNUNET_SYSERR; 709 return GNUNET_SYSERR;
706 } 710 }
707} 711}
708 712
709 713
@@ -711,7 +715,8 @@ dns_string_to_value(void *cls,
711 * Mapping of record type numbers to human-readable 715 * Mapping of record type numbers to human-readable
712 * record type names. 716 * record type names.
713 */ 717 */
714static struct { 718static struct
719{
715 const char *name; 720 const char *name;
716 uint32_t number; 721 uint32_t number;
717} name_map[] = { { "A", GNUNET_DNSPARSER_TYPE_A }, 722} name_map[] = { { "A", GNUNET_DNSPARSER_TYPE_A },
@@ -737,13 +742,13 @@ static struct {
737 * @return corresponding number, UINT32_MAX on error 742 * @return corresponding number, UINT32_MAX on error
738 */ 743 */
739static uint32_t 744static uint32_t
740dns_typename_to_number(void *cls, const char *dns_typename) 745dns_typename_to_number (void *cls, const char *dns_typename)
741{ 746{
742 unsigned int i; 747 unsigned int i;
743 748
744 i = 0; 749 i = 0;
745 while ((NULL != name_map[i].name) && 750 while ((NULL != name_map[i].name) &&
746 (0 != strcasecmp(dns_typename, name_map[i].name))) 751 (0 != strcasecmp (dns_typename, name_map[i].name)))
747 i++; 752 i++;
748 return name_map[i].number; 753 return name_map[i].number;
749} 754}
@@ -757,7 +762,7 @@ dns_typename_to_number(void *cls, const char *dns_typename)
757 * @return corresponding typestring, NULL on error 762 * @return corresponding typestring, NULL on error
758 */ 763 */
759static const char * 764static const char *
760dns_number_to_typename(void *cls, uint32_t type) 765dns_number_to_typename (void *cls, uint32_t type)
761{ 766{
762 unsigned int i; 767 unsigned int i;
763 768
@@ -775,11 +780,11 @@ dns_number_to_typename(void *cls, uint32_t type)
775 * @return the exported block API 780 * @return the exported block API
776 */ 781 */
777void * 782void *
778libgnunet_plugin_gnsrecord_dns_init(void *cls) 783libgnunet_plugin_gnsrecord_dns_init (void *cls)
779{ 784{
780 struct GNUNET_GNSRECORD_PluginFunctions *api; 785 struct GNUNET_GNSRECORD_PluginFunctions *api;
781 786
782 api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); 787 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
783 api->value_to_string = &dns_value_to_string; 788 api->value_to_string = &dns_value_to_string;
784 api->string_to_value = &dns_string_to_value; 789 api->string_to_value = &dns_string_to_value;
785 api->typename_to_number = &dns_typename_to_number; 790 api->typename_to_number = &dns_typename_to_number;
@@ -795,11 +800,11 @@ libgnunet_plugin_gnsrecord_dns_init(void *cls)
795 * @return NULL 800 * @return NULL
796 */ 801 */
797void * 802void *
798libgnunet_plugin_gnsrecord_dns_done(void *cls) 803libgnunet_plugin_gnsrecord_dns_done (void *cls)
799{ 804{
800 struct GNUNET_GNSRECORD_PluginFunctions *api = cls; 805 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
801 806
802 GNUNET_free(api); 807 GNUNET_free (api);
803 return NULL; 808 return NULL;
804} 809}
805 810