aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_uri.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs_uri.c')
-rw-r--r--src/fs/fs_uri.c109
1 files changed, 43 insertions, 66 deletions
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c
index 78b5459fd..e0bdc7ed6 100644
--- a/src/fs/fs_uri.c
+++ b/src/fs/fs_uri.c
@@ -95,10 +95,11 @@
95 * into HashMaps. The key may change between FS implementations. 95 * into HashMaps. The key may change between FS implementations.
96 * 96 *
97 * @param uri uri to convert to a unique key 97 * @param uri uri to convert to a unique key
98 * @param key wherer to store the unique key 98 * @param key where to store the unique key
99 */ 99 */
100void 100void
101GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, struct GNUNET_HashCode * key) 101GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri,
102 struct GNUNET_HashCode *key)
102{ 103{
103 switch (uri->type) 104 switch (uri->type)
104 { 105 {
@@ -144,7 +145,7 @@ GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri)
144 char **keywords; 145 char **keywords;
145 unsigned int keywordCount; 146 unsigned int keywordCount;
146 147
147 if ((uri == NULL) || (uri->type != GNUNET_FS_URI_KSK)) 148 if ((NULL == uri) || (GNUNET_FS_URI_KSK != uri->type))
148 { 149 {
149 GNUNET_break (0); 150 GNUNET_break (0);
150 return NULL; 151 return NULL;
@@ -269,7 +270,7 @@ uri_ksk_parse (const char *s, char **emsg)
269 char *dup; 270 char *dup;
270 int saw_quote; 271 int saw_quote;
271 272
272 GNUNET_assert (s != NULL); 273 GNUNET_assert (NULL != s);
273 slen = strlen (s); 274 slen = strlen (s);
274 pos = strlen (GNUNET_FS_URI_KSK_PREFIX); 275 pos = strlen (GNUNET_FS_URI_KSK_PREFIX);
275 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos))) 276 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos)))
@@ -329,7 +330,7 @@ uri_ksk_parse (const char *s, char **emsg)
329 goto CLEANUP; 330 goto CLEANUP;
330 GNUNET_assert (max == 0); 331 GNUNET_assert (max == 0);
331 GNUNET_free (dup); 332 GNUNET_free (dup);
332 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 333 ret = GNUNET_new (struct GNUNET_FS_Uri);
333 ret->type = GNUNET_FS_URI_KSK; 334 ret->type = GNUNET_FS_URI_KSK;
334 ret->data.ksk.keywordCount = iret; 335 ret->data.ksk.keywordCount = iret;
335 ret->data.ksk.keywords = keywords; 336 ret->data.ksk.keywords = keywords;
@@ -356,7 +357,7 @@ static struct GNUNET_FS_Uri *
356uri_sks_parse (const char *s, char **emsg) 357uri_sks_parse (const char *s, char **emsg)
357{ 358{
358 struct GNUNET_FS_Uri *ret; 359 struct GNUNET_FS_Uri *ret;
359 struct GNUNET_FS_PseudonymIdentifier id; 360 struct GNUNET_CRYPTO_EccPublicKey ns;
360 size_t pos; 361 size_t pos;
361 char *end; 362 char *end;
362 363
@@ -369,16 +370,16 @@ uri_sks_parse (const char *s, char **emsg)
369 (GNUNET_OK != 370 (GNUNET_OK !=
370 GNUNET_STRINGS_string_to_data (&s[pos], 371 GNUNET_STRINGS_string_to_data (&s[pos],
371 end - &s[pos], 372 end - &s[pos],
372 &id, 373 &ns,
373 sizeof (id))) ) 374 sizeof (ns))) )
374 { 375 {
375 *emsg = GNUNET_strdup (_("Malformed SKS URI")); 376 *emsg = GNUNET_strdup (_("Malformed SKS URI"));
376 return NULL; /* malformed */ 377 return NULL; /* malformed */
377 } 378 }
378 end++; /* skip over '/' */ 379 end++; /* skip over '/' */
379 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 380 ret = GNUNET_new (struct GNUNET_FS_Uri);
380 ret->type = GNUNET_FS_URI_SKS; 381 ret->type = GNUNET_FS_URI_SKS;
381 ret->data.sks.ns = id; 382 ret->data.sks.ns = ns;
382 ret->data.sks.identifier = GNUNET_strdup (end); 383 ret->data.sks.identifier = GNUNET_strdup (end);
383 return ret; 384 return ret;
384} 385}
@@ -434,7 +435,7 @@ uri_chk_parse (const char *s, char **emsg)
434 return NULL; 435 return NULL;
435 } 436 }
436 fi.file_length = GNUNET_htonll (flen); 437 fi.file_length = GNUNET_htonll (flen);
437 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 438 ret = GNUNET_new (struct GNUNET_FS_Uri);
438 ret->type = GNUNET_FS_URI_CHK; 439 ret->type = GNUNET_FS_URI_CHK;
439 ret->data.chk = fi; 440 ret->data.chk = fi;
440 return ret; 441 return ret;
@@ -505,24 +506,36 @@ enc2bin (const char *input, void *data, size_t size)
505} 506}
506 507
507 508
509GNUNET_NETWORK_STRUCT_BEGIN
508/** 510/**
509 * Structure that defines how the 511 * Structure that defines how the contents of a location URI must be
510 * contents of a location URI must be 512 * assembled in memory to create or verify the signature of a location
511 * assembled in memory to create or
512 * verify the signature of a location
513 * URI. 513 * URI.
514 */ 514 */
515struct LocUriAssembly 515struct LocUriAssembly
516{ 516{
517 /**
518 * What is being signed (rest of this struct).
519 */
517 struct GNUNET_CRYPTO_EccSignaturePurpose purpose; 520 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
518 521
522 /**
523 * Expiration time of the offer.
524 */
519 struct GNUNET_TIME_AbsoluteNBO exptime; 525 struct GNUNET_TIME_AbsoluteNBO exptime;
520 526
527 /**
528 * File being offered.
529 */
521 struct FileIdentifier fi; 530 struct FileIdentifier fi;
522 531
532 /**
533 * Peer offering the file.
534 */
523 struct GNUNET_CRYPTO_EccPublicKey peer; 535 struct GNUNET_CRYPTO_EccPublicKey peer;
524 536
525}; 537};
538GNUNET_NETWORK_STRUCT_END
526 539
527 540
528#define GNUNET_FS_URI_LOC_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX 541#define GNUNET_FS_URI_LOC_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX
@@ -635,7 +648,7 @@ uri_loc_parse (const char *s, char **emsg)
635 GNUNET_strdup (_("SKS URI malformed (signature failed validation)")); 648 GNUNET_strdup (_("SKS URI malformed (signature failed validation)"));
636 goto ERR; 649 goto ERR;
637 } 650 }
638 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 651 uri = GNUNET_new (struct GNUNET_FS_Uri);
639 uri->type = GNUNET_FS_URI_LOC; 652 uri->type = GNUNET_FS_URI_LOC;
640 uri->data.loc.fi = ass.fi; 653 uri->data.loc.fi = ass.fi;
641 uri->data.loc.peer = ass.peer; 654 uri->data.loc.peer = ass.peer;
@@ -862,7 +875,7 @@ GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri)
862 875
863 if (uri->type != GNUNET_FS_URI_LOC) 876 if (uri->type != GNUNET_FS_URI_LOC)
864 return NULL; 877 return NULL;
865 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 878 ret = GNUNET_new (struct GNUNET_FS_Uri);
866 ret->type = GNUNET_FS_URI_CHK; 879 ret->type = GNUNET_FS_URI_CHK;
867 ret->data.chk = uri->data.loc.fi; 880 ret->data.chk = uri->data.loc.fi;
868 return ret; 881 return ret;
@@ -912,7 +925,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
912 ass.exptime = GNUNET_TIME_absolute_hton (expiration_time); 925 ass.exptime = GNUNET_TIME_absolute_hton (expiration_time);
913 ass.fi = baseUri->data.chk; 926 ass.fi = baseUri->data.chk;
914 ass.peer = my_public_key; 927 ass.peer = my_public_key;
915 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 928 uri = GNUNET_new (struct GNUNET_FS_Uri);
916 uri->type = GNUNET_FS_URI_LOC; 929 uri->type = GNUNET_FS_URI_LOC;
917 uri->data.loc.fi = baseUri->data.chk; 930 uri->data.loc.fi = baseUri->data.chk;
918 uri->data.loc.expirationTime = expiration_time; 931 uri->data.loc.expirationTime = expiration_time;
@@ -926,57 +939,21 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
926 939
927 940
928/** 941/**
929 * Create an SKS URI from a namespace and an identifier.
930 *
931 * @param ns namespace
932 * @param id identifier
933 * @param emsg where to store an error message
934 * @return an FS URI for the given namespace and identifier
935 */
936struct GNUNET_FS_Uri *
937GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
938 char **emsg)
939{
940 struct GNUNET_FS_Uri *ns_uri;
941
942 if (NULL == id)
943 {
944 if (NULL != emsg)
945 *emsg = GNUNET_strdup (_("identifier is NULL!"));
946 return NULL;
947 }
948 else if ('\0' == id[0])
949 {
950 if (NULL != emsg)
951 *emsg = GNUNET_strdup (_("identifier has zero length!"));
952 return NULL;
953 }
954 if (NULL != emsg)
955 *emsg = NULL;
956 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
957 ns_uri->type = GNUNET_FS_URI_SKS;
958 GNUNET_FS_namespace_get_public_identifier (ns, &ns_uri->data.sks.ns);
959 ns_uri->data.sks.identifier = GNUNET_strdup (id);
960 return ns_uri;
961}
962
963
964/**
965 * Create an SKS URI from a namespace ID and an identifier. 942 * Create an SKS URI from a namespace ID and an identifier.
966 * 943 *
967 * @param pseudonym namespace ID 944 * @param ns namespace ID
968 * @param id identifier 945 * @param id identifier
969 * @return an FS URI for the given namespace and identifier 946 * @return an FS URI for the given namespace and identifier
970 */ 947 */
971struct GNUNET_FS_Uri * 948struct GNUNET_FS_Uri *
972GNUNET_FS_uri_sks_create_from_nsid (struct GNUNET_FS_PseudonymIdentifier *pseudonym, 949GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EccPublicKey *ns,
973 const char *id) 950 const char *id)
974{ 951{
975 struct GNUNET_FS_Uri *ns_uri; 952 struct GNUNET_FS_Uri *ns_uri;
976 953
977 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 954 ns_uri = GNUNET_new (struct GNUNET_FS_Uri);
978 ns_uri->type = GNUNET_FS_URI_SKS; 955 ns_uri->type = GNUNET_FS_URI_SKS;
979 ns_uri->data.sks.ns = *pseudonym; 956 ns_uri->data.sks.ns = *ns;
980 ns_uri->data.sks.identifier = GNUNET_strdup (id); 957 ns_uri->data.sks.identifier = GNUNET_strdup (id);
981 return ns_uri; 958 return ns_uri;
982} 959}
@@ -1033,7 +1010,7 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
1033 if (0 == found) 1010 if (0 == found)
1034 kl[kc++] = GNUNET_strdup (kp); 1011 kl[kc++] = GNUNET_strdup (kp);
1035 } 1012 }
1036 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 1013 ret = GNUNET_new (struct GNUNET_FS_Uri);
1037 ret->type = GNUNET_FS_URI_KSK; 1014 ret->type = GNUNET_FS_URI_KSK;
1038 ret->data.ksk.keywordCount = kc; 1015 ret->data.ksk.keywordCount = kc;
1039 ret->data.ksk.keywords = kl; 1016 ret->data.ksk.keywords = kl;
@@ -1055,7 +1032,7 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
1055 1032
1056 if (uri == NULL) 1033 if (uri == NULL)
1057 return NULL; 1034 return NULL;
1058 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 1035 ret = GNUNET_new (struct GNUNET_FS_Uri);
1059 memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri)); 1036 memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri));
1060 switch (ret->type) 1037 switch (ret->type)
1061 { 1038 {
@@ -1224,7 +1201,7 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv)
1224 && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) 1201 && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
1225 return uri; 1202 return uri;
1226 GNUNET_free_non_null (emsg); 1203 GNUNET_free_non_null (emsg);
1227 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 1204 uri = GNUNET_new (struct GNUNET_FS_Uri);
1228 uri->type = GNUNET_FS_URI_KSK; 1205 uri->type = GNUNET_FS_URI_KSK;
1229 uri->data.ksk.keywordCount = argc; 1206 uri->data.ksk.keywordCount = argc;
1230 uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *)); 1207 uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *));
@@ -1280,7 +1257,7 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1280 case GNUNET_FS_URI_SKS: 1257 case GNUNET_FS_URI_SKS:
1281 if ((0 == 1258 if ((0 ==
1282 memcmp (&u1->data.sks.ns, &u2->data.sks.ns, 1259 memcmp (&u1->data.sks.ns, &u2->data.sks.ns,
1283 sizeof (struct GNUNET_FS_PseudonymIdentifier))) && 1260 sizeof (struct GNUNET_CRYPTO_EccPublicKey))) &&
1284 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) 1261 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier)))
1285 1262
1286 return GNUNET_YES; 1263 return GNUNET_YES;
@@ -1341,7 +1318,7 @@ GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri)
1341 */ 1318 */
1342int 1319int
1343GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, 1320GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
1344 struct GNUNET_FS_PseudonymIdentifier *pseudonym) 1321 struct GNUNET_CRYPTO_EccPublicKey *pseudonym)
1345{ 1322{
1346 if (!GNUNET_FS_uri_test_sks (uri)) 1323 if (!GNUNET_FS_uri_test_sks (uri))
1347 { 1324 {
@@ -1812,7 +1789,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1812 1789
1813 if (md == NULL) 1790 if (md == NULL)
1814 return NULL; 1791 return NULL;
1815 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri)); 1792 ret = GNUNET_new (struct GNUNET_FS_Uri);
1816 ret->type = GNUNET_FS_URI_KSK; 1793 ret->type = GNUNET_FS_URI_KSK;
1817 ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL); 1794 ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
1818 if (ent > 0) 1795 if (ent > 0)
@@ -1944,7 +1921,7 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1944 if (GNUNET_FS_URI_SKS != uri->type) 1921 if (GNUNET_FS_URI_SKS != uri->type)
1945 return NULL; 1922 return NULL;
1946 ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns, 1923 ret = GNUNET_STRINGS_data_to_string (&uri->data.sks.ns,
1947 sizeof (struct GNUNET_FS_PseudonymIdentifier), 1924 sizeof (struct GNUNET_CRYPTO_EccPublicKey),
1948 buf, 1925 buf,
1949 sizeof (buf)); 1926 sizeof (buf));
1950 GNUNET_assert (NULL != ret); 1927 GNUNET_assert (NULL != ret);