diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-03-07 09:59:36 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-03-07 09:59:36 +0000 |
commit | 2deb334f33e65baa4b0009c67ba1df53448ab5ce (patch) | |
tree | c4e13b187e808653c3d1d878b2340878199d7fb9 | |
parent | 1eb6660144445bd81396eea0bf49d42efc07e5ed (diff) | |
download | gnunet-2deb334f33e65baa4b0009c67ba1df53448ab5ce.tar.gz gnunet-2deb334f33e65baa4b0009c67ba1df53448ab5ce.zip |
-additional namestore conversion APIs added
-rw-r--r-- | src/include/gnunet_namestore_service.h | 61 | ||||
-rw-r--r-- | src/namestore/gnunet-namestore.c | 97 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 35 | ||||
-rw-r--r-- | src/namestore/namestore_common.c | 155 |
4 files changed, 237 insertions, 111 deletions
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index a50243d09..f2f314bfc 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -74,15 +74,6 @@ struct GNUNET_NAMESTORE_ZoneIterator; | |||
74 | #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) | 74 | #define GNUNET_NAMESTORE_MAX_VALUE_SIZE (63 * 1024) |
75 | 75 | ||
76 | 76 | ||
77 | /** | ||
78 | * Convert a type name (i.e. "AAAA") to the corresponding number. | ||
79 | * | ||
80 | * @param typename name to convert | ||
81 | * @return corresponding number, UINT32_MAX on error | ||
82 | */ | ||
83 | uint32_t | ||
84 | GNUNET_NAMESTORE_typename_to_number (const char *typename); | ||
85 | |||
86 | 77 | ||
87 | /** | 78 | /** |
88 | * Connect to the namestore service. | 79 | * Connect to the namestore service. |
@@ -450,6 +441,58 @@ GNUNET_NAMESTORE_records_deserialize (size_t len, | |||
450 | struct GNUNET_NAMESTORE_RecordData *dest); | 441 | struct GNUNET_NAMESTORE_RecordData *dest); |
451 | 442 | ||
452 | 443 | ||
444 | |||
445 | /** | ||
446 | * Convert the 'value' of a record to a string. | ||
447 | * | ||
448 | * @param type type of the record | ||
449 | * @param data value in binary encoding | ||
450 | * @param data_size number of bytes in data | ||
451 | * @return NULL on error, otherwise human-readable representation of the value | ||
452 | */ | ||
453 | char * | ||
454 | GNUNET_NAMESTORE_value_to_string (uint32_t type, | ||
455 | const void *data, | ||
456 | size_t data_size); | ||
457 | |||
458 | |||
459 | /** | ||
460 | * Convert human-readable version of a 'value' of a record to the binary | ||
461 | * representation. | ||
462 | * | ||
463 | * @param type type of the record | ||
464 | * @param s human-readable string | ||
465 | * @param data set to value in binary encoding (will be allocated) | ||
466 | * @param data_size set to number of bytes in data | ||
467 | * @return GNUNET_OK on success | ||
468 | */ | ||
469 | int | ||
470 | GNUNET_NAMESTORE_string_to_value (uint32_t type, | ||
471 | const char *s, | ||
472 | void **data, | ||
473 | size_t *data_size); | ||
474 | |||
475 | |||
476 | /** | ||
477 | * Convert a type name (i.e. "AAAA") to the corresponding number. | ||
478 | * | ||
479 | * @param typename name to convert | ||
480 | * @return corresponding number, UINT32_MAX on error | ||
481 | */ | ||
482 | uint32_t | ||
483 | GNUNET_NAMESTORE_typename_to_number (const char *typename); | ||
484 | |||
485 | |||
486 | /** | ||
487 | * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A") | ||
488 | * | ||
489 | * @param type number of a type to convert | ||
490 | * @return corresponding typestring, NULL on error | ||
491 | */ | ||
492 | const char * | ||
493 | GNUNET_NAMESTORE_number_to_typename (uint32_t type); | ||
494 | |||
495 | |||
453 | #if 0 /* keep Emacsens' auto-indent happy */ | 496 | #if 0 /* keep Emacsens' auto-indent happy */ |
454 | { | 497 | { |
455 | #endif | 498 | #endif |
diff --git a/src/namestore/gnunet-namestore.c b/src/namestore/gnunet-namestore.c index a80f88052..f48d1c23d 100644 --- a/src/namestore/gnunet-namestore.c +++ b/src/namestore/gnunet-namestore.c | |||
@@ -205,6 +205,10 @@ display_record (void *cls, | |||
205 | const struct GNUNET_NAMESTORE_RecordData *rd, | 205 | const struct GNUNET_NAMESTORE_RecordData *rd, |
206 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 206 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
207 | { | 207 | { |
208 | const char *typestring; | ||
209 | char *s; | ||
210 | unsigned int i; | ||
211 | |||
208 | if (NULL == name) | 212 | if (NULL == name) |
209 | { | 213 | { |
210 | list_it = NULL; | 214 | list_it = NULL; |
@@ -213,7 +217,25 @@ display_record (void *cls, | |||
213 | GNUNET_SCHEDULER_shutdown (); | 217 | GNUNET_SCHEDULER_shutdown (); |
214 | return; | 218 | return; |
215 | } | 219 | } |
216 | // FIXME: display record! | 220 | FPRINTF (stdout, |
221 | "%s:\n", | ||
222 | name); | ||
223 | for (i=0;i<rd_len;i++) | ||
224 | { | ||
225 | typestring = GNUNET_NAMESTORE_number_to_typename (rd[i].record_type); | ||
226 | s = GNUNET_NAMESTORE_value_to_string (rd[i].record_type, | ||
227 | rd[i].data, | ||
228 | rd[i].data_size); | ||
229 | if (NULL == s) | ||
230 | { | ||
231 | FPRINTF (stdout, _("\tCorrupt or unsupported record of type %u\n"), | ||
232 | (unsigned int) rd[i].record_type); | ||
233 | continue; | ||
234 | } | ||
235 | FPRINTF (stdout, "\t%s: %s\n", typestring, s); | ||
236 | GNUNET_free (s); | ||
237 | } | ||
238 | FPRINTF (stdout, "%s", "\n"); | ||
217 | GNUNET_NAMESTORE_zone_iterator_next (list_it); | 239 | GNUNET_NAMESTORE_zone_iterator_next (list_it); |
218 | } | 240 | } |
219 | 241 | ||
@@ -232,10 +254,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
232 | { | 254 | { |
233 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 255 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
234 | uint32_t type; | 256 | uint32_t type; |
235 | const void *data; | 257 | void *data = NULL; |
236 | size_t data_size; | 258 | size_t data_size = 0; |
237 | struct in_addr value_a; | ||
238 | struct in6_addr value_aaaa; | ||
239 | struct GNUNET_TIME_Relative etime; | 259 | struct GNUNET_TIME_Relative etime; |
240 | struct GNUNET_NAMESTORE_RecordData rd; | 260 | struct GNUNET_NAMESTORE_RecordData rd; |
241 | 261 | ||
@@ -294,53 +314,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
294 | } | 314 | } |
295 | if (NULL != value) | 315 | if (NULL != value) |
296 | { | 316 | { |
297 | switch (type) | 317 | if (GNUNET_OK != |
298 | { | 318 | GNUNET_NAMESTORE_string_to_value (type, |
299 | case 0: | 319 | value, |
300 | fprintf (stderr, _("Need a record type to interpret value `%s'\n"), value); | 320 | &data, |
301 | GNUNET_SCHEDULER_shutdown (); | 321 | &data_size)) |
302 | break; | ||
303 | case GNUNET_DNSPARSER_TYPE_A: | ||
304 | if (1 != inet_pton (AF_INET, value, &value_a)) | ||
305 | { | ||
306 | fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), | ||
307 | value, | ||
308 | typestring); | ||
309 | GNUNET_SCHEDULER_shutdown (); | ||
310 | return; | ||
311 | } | ||
312 | data = &value_a; | ||
313 | data_size = sizeof (value_a); | ||
314 | break; | ||
315 | case GNUNET_DNSPARSER_TYPE_NS: | ||
316 | data = value; | ||
317 | data_size = strlen (value); | ||
318 | break; | ||
319 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
320 | data = value; | ||
321 | data_size = strlen (value); | ||
322 | break; | ||
323 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
324 | // FIXME | ||
325 | fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); | ||
326 | GNUNET_SCHEDULER_shutdown (); | ||
327 | return; | ||
328 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
329 | // FIXME | ||
330 | fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); | ||
331 | GNUNET_SCHEDULER_shutdown (); | ||
332 | return; | ||
333 | case GNUNET_DNSPARSER_TYPE_MX: | ||
334 | // FIXME | ||
335 | fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); | ||
336 | GNUNET_SCHEDULER_shutdown (); | ||
337 | return; | ||
338 | case GNUNET_DNSPARSER_TYPE_TXT: | ||
339 | data = value; | ||
340 | data_size = strlen (value); | ||
341 | break; | ||
342 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
343 | if (1 != inet_pton (AF_INET6, value, &value_aaaa)) | ||
344 | { | 322 | { |
345 | fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), | 323 | fprintf (stderr, _("Value `%s' invalid for record type `%s'\n"), |
346 | value, | 324 | value, |
@@ -348,20 +326,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
348 | GNUNET_SCHEDULER_shutdown (); | 326 | GNUNET_SCHEDULER_shutdown (); |
349 | return; | 327 | return; |
350 | } | 328 | } |
351 | data = &value_aaaa; | ||
352 | data_size = sizeof (value_aaaa); | ||
353 | break; | ||
354 | case GNUNET_NAMESTORE_TYPE_PKEY: | ||
355 | fprintf (stderr, _("Record type `%s' not implemented yet\n"), typestring); | ||
356 | GNUNET_SCHEDULER_shutdown (); | ||
357 | return; | ||
358 | case GNUNET_NAMESTORE_TYPE_PSEU: | ||
359 | data = value; | ||
360 | data_size = strlen (value); | ||
361 | break; | ||
362 | default: | ||
363 | GNUNET_assert (0); | ||
364 | } | ||
365 | } else if (add | del) | 329 | } else if (add | del) |
366 | { | 330 | { |
367 | fprintf (stderr, | 331 | fprintf (stderr, |
@@ -442,6 +406,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
442 | &display_record, | 406 | &display_record, |
443 | NULL); | 407 | NULL); |
444 | } | 408 | } |
409 | GNUNET_free_non_null (data); | ||
445 | } | 410 | } |
446 | 411 | ||
447 | 412 | ||
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index fbf4711ae..64db49375 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -204,41 +204,6 @@ struct GNUNET_NAMESTORE_SimpleRecord | |||
204 | 204 | ||
205 | 205 | ||
206 | /** | 206 | /** |
207 | * Convert a type name (i.e. "AAAA") to the corresponding number. | ||
208 | * | ||
209 | * @param typename name to convert | ||
210 | * @return corresponding number, UINT32_MAX on error | ||
211 | */ | ||
212 | uint32_t | ||
213 | GNUNET_NAMESTORE_typename_to_number (const char *typename) | ||
214 | { | ||
215 | static struct { | ||
216 | const char *name; | ||
217 | uint32_t number; | ||
218 | } map[] = { | ||
219 | { "A", GNUNET_DNSPARSER_TYPE_A }, | ||
220 | { "NS", GNUNET_DNSPARSER_TYPE_NS }, | ||
221 | { "CNAME", GNUNET_DNSPARSER_TYPE_CNAME }, | ||
222 | { "SOA", GNUNET_DNSPARSER_TYPE_SOA }, | ||
223 | { "PTR", GNUNET_DNSPARSER_TYPE_PTR }, | ||
224 | { "MX", GNUNET_DNSPARSER_TYPE_MX }, | ||
225 | { "TXT", GNUNET_DNSPARSER_TYPE_TXT }, | ||
226 | { "AAAA", GNUNET_DNSPARSER_TYPE_AAAA }, | ||
227 | { "PKEY", GNUNET_NAMESTORE_TYPE_PKEY }, | ||
228 | { "PSEU", GNUNET_NAMESTORE_TYPE_PSEU }, | ||
229 | { NULL, UINT32_MAX } | ||
230 | }; | ||
231 | unsigned int i; | ||
232 | |||
233 | i=0; | ||
234 | while ( (map[i].name != NULL) && | ||
235 | (0 != strcasecmp (typename, map[i].name)) ) | ||
236 | i++; | ||
237 | return map[i].number; | ||
238 | } | ||
239 | |||
240 | |||
241 | /** | ||
242 | * Disconnect from service and then reconnect. | 207 | * Disconnect from service and then reconnect. |
243 | * | 208 | * |
244 | * @param h our handle | 209 | * @param h our handle |
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c index aa4603232..b865b0b79 100644 --- a/src/namestore/namestore_common.c +++ b/src/namestore/namestore_common.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "gnunet_signatures.h" | 31 | #include "gnunet_signatures.h" |
32 | #include "gnunet_arm_service.h" | 32 | #include "gnunet_arm_service.h" |
33 | #include "gnunet_namestore_service.h" | 33 | #include "gnunet_namestore_service.h" |
34 | #include "gnunet_dnsparser_lib.h" | ||
34 | #include "namestore.h" | 35 | #include "namestore.h" |
35 | #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING | 36 | #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING |
36 | 37 | ||
@@ -251,4 +252,156 @@ GNUNET_NAMESTORE_create_signature (const struct GNUNET_CRYPTO_RsaPrivateKey *key | |||
251 | return sig; | 252 | return sig; |
252 | } | 253 | } |
253 | 254 | ||
254 | /* end of namestore_api.c */ | 255 | |
256 | /** | ||
257 | * Convert the 'value' of a record to a string. | ||
258 | * | ||
259 | * @param type type of the record | ||
260 | * @param data value in binary encoding | ||
261 | * @param data_size number of bytes in data | ||
262 | * @return NULL on error, otherwise human-readable representation of the value | ||
263 | */ | ||
264 | char * | ||
265 | GNUNET_NAMESTORE_value_to_string (uint32_t type, | ||
266 | const void *data, | ||
267 | size_t data_size) | ||
268 | { | ||
269 | GNUNET_break (0); // not implemented | ||
270 | return NULL; | ||
271 | } | ||
272 | |||
273 | |||
274 | /** | ||
275 | * Convert human-readable version of a 'value' of a record to the binary | ||
276 | * representation. | ||
277 | * | ||
278 | * @param type type of the record | ||
279 | * @param s human-readable string | ||
280 | * @param data set to value in binary encoding (will be allocated) | ||
281 | * @param data_size set to number of bytes in data | ||
282 | * @return GNUNET_OK on success | ||
283 | */ | ||
284 | int | ||
285 | GNUNET_NAMESTORE_string_to_value (uint32_t type, | ||
286 | const char *s, | ||
287 | void **data, | ||
288 | size_t *data_size) | ||
289 | { | ||
290 | struct in_addr value_a; | ||
291 | struct in6_addr value_aaaa; | ||
292 | |||
293 | switch (type) | ||
294 | { | ||
295 | case 0: | ||
296 | return GNUNET_SYSERR; | ||
297 | break; | ||
298 | case GNUNET_DNSPARSER_TYPE_A: | ||
299 | if (1 != inet_pton (AF_INET, s, &value_a)) | ||
300 | return GNUNET_SYSERR; | ||
301 | *data = GNUNET_malloc (sizeof (struct in_addr)); | ||
302 | memcpy (*data, &value_a, sizeof (value_a)); | ||
303 | *data_size = sizeof (value_a); | ||
304 | break; | ||
305 | case GNUNET_DNSPARSER_TYPE_NS: | ||
306 | *data = GNUNET_strdup (s); | ||
307 | *data_size = strlen (s); | ||
308 | break; | ||
309 | case GNUNET_DNSPARSER_TYPE_CNAME: | ||
310 | *data = GNUNET_strdup (s); | ||
311 | *data_size = strlen (s); | ||
312 | break; | ||
313 | case GNUNET_DNSPARSER_TYPE_SOA: | ||
314 | GNUNET_break (0); | ||
315 | // FIXME | ||
316 | return GNUNET_SYSERR; | ||
317 | case GNUNET_DNSPARSER_TYPE_PTR: | ||
318 | GNUNET_break (0); | ||
319 | // FIXME | ||
320 | return GNUNET_SYSERR; | ||
321 | case GNUNET_DNSPARSER_TYPE_MX: | ||
322 | GNUNET_break (0); | ||
323 | // FIXME | ||
324 | return GNUNET_SYSERR; | ||
325 | case GNUNET_DNSPARSER_TYPE_TXT: | ||
326 | *data = GNUNET_strdup (s); | ||
327 | *data_size = strlen (s); | ||
328 | break; | ||
329 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
330 | if (1 != inet_pton (AF_INET6, s, &value_aaaa)) | ||
331 | return GNUNET_SYSERR; | ||
332 | *data = GNUNET_malloc (sizeof (struct in6_addr)); | ||
333 | memcpy (*data, &value_aaaa, sizeof (value_aaaa)); | ||
334 | break; | ||
335 | case GNUNET_NAMESTORE_TYPE_PKEY: | ||
336 | GNUNET_break (0); | ||
337 | // FIXME | ||
338 | return GNUNET_SYSERR; | ||
339 | case GNUNET_NAMESTORE_TYPE_PSEU: | ||
340 | *data = GNUNET_strdup (s); | ||
341 | *data_size = strlen (s); | ||
342 | break; | ||
343 | default: | ||
344 | GNUNET_break (0); | ||
345 | } | ||
346 | return GNUNET_SYSERR; | ||
347 | } | ||
348 | |||
349 | |||
350 | static struct { | ||
351 | const char *name; | ||
352 | uint32_t number; | ||
353 | } name_map[] = { | ||
354 | { "A", GNUNET_DNSPARSER_TYPE_A }, | ||
355 | { "NS", GNUNET_DNSPARSER_TYPE_NS }, | ||
356 | { "CNAME", GNUNET_DNSPARSER_TYPE_CNAME }, | ||
357 | { "SOA", GNUNET_DNSPARSER_TYPE_SOA }, | ||
358 | { "PTR", GNUNET_DNSPARSER_TYPE_PTR }, | ||
359 | { "MX", GNUNET_DNSPARSER_TYPE_MX }, | ||
360 | { "TXT", GNUNET_DNSPARSER_TYPE_TXT }, | ||
361 | { "AAAA", GNUNET_DNSPARSER_TYPE_AAAA }, | ||
362 | { "PKEY", GNUNET_NAMESTORE_TYPE_PKEY }, | ||
363 | { "PSEU", GNUNET_NAMESTORE_TYPE_PSEU }, | ||
364 | { NULL, UINT32_MAX } | ||
365 | }; | ||
366 | |||
367 | |||
368 | /** | ||
369 | * Convert a type name (i.e. "AAAA") to the corresponding number. | ||
370 | * | ||
371 | * @param typename name to convert | ||
372 | * @return corresponding number, UINT32_MAX on error | ||
373 | */ | ||
374 | uint32_t | ||
375 | GNUNET_NAMESTORE_typename_to_number (const char *typename) | ||
376 | { | ||
377 | unsigned int i; | ||
378 | |||
379 | i=0; | ||
380 | while ( (name_map[i].name != NULL) && | ||
381 | (0 != strcasecmp (typename, name_map[i].name)) ) | ||
382 | i++; | ||
383 | return name_map[i].number; | ||
384 | } | ||
385 | |||
386 | |||
387 | /** | ||
388 | * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A") | ||
389 | * | ||
390 | * @param type number of a type to convert | ||
391 | * @return corresponding typestring, NULL on error | ||
392 | */ | ||
393 | const char * | ||
394 | GNUNET_NAMESTORE_number_to_typename (uint32_t type) | ||
395 | { | ||
396 | unsigned int i; | ||
397 | |||
398 | i=0; | ||
399 | while ( (name_map[i].name != NULL) && | ||
400 | (type != name_map[i].number) ) | ||
401 | i++; | ||
402 | return name_map[i].name; | ||
403 | } | ||
404 | |||
405 | |||
406 | |||
407 | /* end of namestore_common.c */ | ||