diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-03-05 16:10:55 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-03-05 16:10:55 +0000 |
commit | 2a23e57e4216593e83e7235e23988564825e4229 (patch) | |
tree | 89cdee0dd816e722214f76f4b9762140416ade20 /src/fs/fs_uri.c | |
parent | dfeb2b787f31255761a808007779c6e992c47591 (diff) | |
download | gnunet-2a23e57e4216593e83e7235e23988564825e4229.tar.gz gnunet-2a23e57e4216593e83e7235e23988564825e4229.zip |
starting major change towards implementing #2564, this breaks some FS tests and FS APIs
Diffstat (limited to 'src/fs/fs_uri.c')
-rw-r--r-- | src/fs/fs_uri.c | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index e76693521..2b7af3c9e 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2003--2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -356,36 +356,30 @@ static struct GNUNET_FS_Uri * | |||
356 | uri_sks_parse (const char *s, char **emsg) | 356 | uri_sks_parse (const char *s, char **emsg) |
357 | { | 357 | { |
358 | struct GNUNET_FS_Uri *ret; | 358 | struct GNUNET_FS_Uri *ret; |
359 | struct GNUNET_HashCode ns; | 359 | struct GNUNET_PseudonymIdentifier id; |
360 | char *identifier; | 360 | size_t pos; |
361 | unsigned int pos; | 361 | char *end; |
362 | size_t slen; | ||
363 | char enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]; | ||
364 | 362 | ||
365 | GNUNET_assert (s != NULL); | 363 | GNUNET_assert (s != NULL); |
366 | slen = strlen (s); | ||
367 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); | 364 | pos = strlen (GNUNET_FS_URI_SKS_PREFIX); |
368 | if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) | 365 | if ((strlen (s) <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos))) |
369 | return NULL; /* not an SKS URI */ | 366 | return NULL; /* not an SKS URI */ |
370 | if ((slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) || | 367 | end = strchr (&s[pos], '/'); |
371 | (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/')) | 368 | if ( (NULL == end) || |
372 | { | 369 | (GNUNET_OK != |
373 | *emsg = GNUNET_strdup (_("Malformed SKS URI")); | 370 | GNUNET_STRINGS_string_to_data (&s[pos], |
374 | return NULL; | 371 | end - &s[pos], |
375 | } | 372 | &id, |
376 | memcpy (enc, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 373 | sizeof (id))) ) |
377 | enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | ||
378 | if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &ns)) | ||
379 | { | 374 | { |
380 | *emsg = GNUNET_strdup (_("Malformed SKS URI")); | 375 | *emsg = GNUNET_strdup (_("Malformed SKS URI")); |
381 | return NULL; | 376 | return NULL; /* malformed */ |
382 | } | 377 | } |
383 | identifier = | 378 | end++; /* skip over '/' */ |
384 | GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]); | ||
385 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 379 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
386 | ret->type = GNUNET_FS_URI_SKS; | 380 | ret->type = GNUNET_FS_URI_SKS; |
387 | ret->data.sks.ns = ns; | 381 | ret->data.sks.ns = id; |
388 | ret->data.sks.identifier = identifier; | 382 | ret->data.sks.identifier = GNUNET_strdup (end); |
389 | return ret; | 383 | return ret; |
390 | } | 384 | } |
391 | 385 | ||
@@ -957,7 +951,7 @@ GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id, | |||
957 | } | 951 | } |
958 | ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 952 | ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
959 | ns_uri->type = GNUNET_FS_URI_SKS; | 953 | ns_uri->type = GNUNET_FS_URI_SKS; |
960 | GNUNET_FS_namespace_get_public_key_hash (ns, &ns_uri->data.sks.ns); | 954 | GNUNET_FS_namespace_get_public_identifier (ns, &ns_uri->data.sks.ns); |
961 | ns_uri->data.sks.identifier = GNUNET_strdup (id); | 955 | ns_uri->data.sks.identifier = GNUNET_strdup (id); |
962 | return ns_uri; | 956 | return ns_uri; |
963 | } | 957 | } |
@@ -966,18 +960,19 @@ GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id, | |||
966 | /** | 960 | /** |
967 | * Create an SKS URI from a namespace ID and an identifier. | 961 | * Create an SKS URI from a namespace ID and an identifier. |
968 | * | 962 | * |
969 | * @param nsid namespace ID | 963 | * @param pseudonym namespace ID |
970 | * @param id identifier | 964 | * @param id identifier |
971 | * @return an FS URI for the given namespace and identifier | 965 | * @return an FS URI for the given namespace and identifier |
972 | */ | 966 | */ |
973 | struct GNUNET_FS_Uri * | 967 | struct GNUNET_FS_Uri * |
974 | GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_HashCode * nsid, const char *id) | 968 | GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_PseudonymIdentifier *pseudonym, |
969 | const char *id) | ||
975 | { | 970 | { |
976 | struct GNUNET_FS_Uri *ns_uri; | 971 | struct GNUNET_FS_Uri *ns_uri; |
977 | 972 | ||
978 | ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); | 973 | ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); |
979 | ns_uri->type = GNUNET_FS_URI_SKS; | 974 | ns_uri->type = GNUNET_FS_URI_SKS; |
980 | ns_uri->data.sks.ns = *nsid; | 975 | ns_uri->data.sks.ns = *pseudonym; |
981 | ns_uri->data.sks.identifier = GNUNET_strdup (id); | 976 | ns_uri->data.sks.identifier = GNUNET_strdup (id); |
982 | return ns_uri; | 977 | return ns_uri; |
983 | } | 978 | } |
@@ -1337,19 +1332,19 @@ GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri) | |||
1337 | * namespace URI. | 1332 | * namespace URI. |
1338 | * | 1333 | * |
1339 | * @param uri the uri to get the namespace ID from | 1334 | * @param uri the uri to get the namespace ID from |
1340 | * @param nsid where to store the ID of the namespace | 1335 | * @param pseudonym where to store the ID of the namespace |
1341 | * @return GNUNET_OK on success | 1336 | * @return GNUNET_OK on success |
1342 | */ | 1337 | */ |
1343 | int | 1338 | int |
1344 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, | 1339 | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, |
1345 | struct GNUNET_HashCode * nsid) | 1340 | struct GNUNET_PseudonymIdentifier *pseudonym) |
1346 | { | 1341 | { |
1347 | if (!GNUNET_FS_uri_test_sks (uri)) | 1342 | if (!GNUNET_FS_uri_test_sks (uri)) |
1348 | { | 1343 | { |
1349 | GNUNET_break (0); | 1344 | GNUNET_break (0); |
1350 | return GNUNET_SYSERR; | 1345 | return GNUNET_SYSERR; |
1351 | } | 1346 | } |
1352 | *nsid = uri->data.sks.ns; | 1347 | *pseudonym = uri->data.sks.ns; |
1353 | return GNUNET_OK; | 1348 | return GNUNET_OK; |
1354 | } | 1349 | } |
1355 | 1350 | ||
@@ -1939,18 +1934,20 @@ uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1939 | static char * | 1934 | static char * |
1940 | uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | 1935 | uri_sks_to_string (const struct GNUNET_FS_Uri *uri) |
1941 | { | 1936 | { |
1942 | const struct GNUNET_HashCode *ns; | ||
1943 | const char *identifier; | ||
1944 | char *ret; | 1937 | char *ret; |
1945 | struct GNUNET_CRYPTO_HashAsciiEncoded nsasc; | 1938 | char buf[1024]; |
1946 | 1939 | ||
1947 | if (uri->type != GNUNET_FS_URI_SKS) | 1940 | if (GNUNET_FS_URI_SKS != uri->type) |
1948 | return NULL; | 1941 | return NULL; |
1949 | ns = &uri->data.sks.ns; | 1942 | ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, |
1950 | identifier = uri->data.sks.identifier; | 1943 | sizeof (struct GNUNET_PseudonymIdentifier), |
1951 | GNUNET_CRYPTO_hash_to_enc (ns, &nsasc); | 1944 | buf, |
1945 | sizeof (buf)); | ||
1946 | GNUNET_assert (NULL != ret); | ||
1947 | ret[0] = '\0'; | ||
1952 | GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX, | 1948 | GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX, |
1953 | GNUNET_FS_URI_SKS_INFIX, (const char *) &nsasc, identifier); | 1949 | GNUNET_FS_URI_SKS_INFIX, buf, |
1950 | uri->data.sks.identifier); | ||
1954 | return ret; | 1951 | return ret; |
1955 | } | 1952 | } |
1956 | 1953 | ||