diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:54:06 +0000 |
commit | 5746309cb4be2073d550ad7a6885e918631dbc38 (patch) | |
tree | 89455bc4aadf977816b38df13f990372cd81d71a /src/fs/fs_uri.c | |
parent | 6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff) | |
download | gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip |
indentation
Diffstat (limited to 'src/fs/fs_uri.c')
-rw-r--r-- | src/fs/fs_uri.c | 111 |
1 files changed, 48 insertions, 63 deletions
diff --git a/src/fs/fs_uri.c b/src/fs/fs_uri.c index 5d5d24ca8..22dab4955 100644 --- a/src/fs/fs_uri.c +++ b/src/fs/fs_uri.c | |||
@@ -419,15 +419,12 @@ uri_chk_parse (const char *s, char **emsg) | |||
419 | } | 419 | } |
420 | memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 420 | memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
421 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 421 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
422 | memcpy (h2, | 422 | memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], |
423 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], | ||
424 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 423 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
425 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 424 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
426 | 425 | ||
427 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, | 426 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) || |
428 | &fi.chk.key)) || | 427 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) || |
429 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, | ||
430 | &fi.chk.query)) || | ||
431 | (1 != | 428 | (1 != |
432 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 429 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
433 | "%llu", &flen))) | 430 | "%llu", &flen))) |
@@ -567,15 +564,12 @@ uri_loc_parse (const char *s, char **emsg) | |||
567 | } | 564 | } |
568 | memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 565 | memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
569 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 566 | h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
570 | memcpy (h2, | 567 | memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], |
571 | &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)], | ||
572 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 568 | sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
573 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; | 569 | h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0'; |
574 | 570 | ||
575 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, | 571 | if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) || |
576 | &ass.fi.chk.key)) || | 572 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) || |
577 | (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, | ||
578 | &ass.fi.chk.query)) || | ||
579 | (1 != | 573 | (1 != |
580 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], | 574 | SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2], |
581 | "%llu", &flen))) | 575 | "%llu", &flen))) |
@@ -594,9 +588,9 @@ uri_loc_parse (const char *s, char **emsg) | |||
594 | goto ERR; | 588 | goto ERR; |
595 | } | 589 | } |
596 | npos++; | 590 | npos++; |
597 | ret = enc2bin (&s[npos], | 591 | ret = |
598 | &ass.peer, | 592 | enc2bin (&s[npos], &ass.peer, |
599 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 593 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
600 | if (ret == -1) | 594 | if (ret == -1) |
601 | { | 595 | { |
602 | *emsg = | 596 | *emsg = |
@@ -769,8 +763,8 @@ GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, | |||
769 | * @param is_mandatory is this keyword mandatory? | 763 | * @param is_mandatory is this keyword mandatory? |
770 | */ | 764 | */ |
771 | void | 765 | void |
772 | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, | 766 | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword, |
773 | const char *keyword, int is_mandatory) | 767 | int is_mandatory) |
774 | { | 768 | { |
775 | unsigned int i; | 769 | unsigned int i; |
776 | const char *old; | 770 | const char *old; |
@@ -896,8 +890,8 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, | |||
896 | if (baseUri->type != chk) | 890 | if (baseUri->type != chk) |
897 | return NULL; | 891 | return NULL; |
898 | if (GNUNET_OK != | 892 | if (GNUNET_OK != |
899 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 893 | GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY", |
900 | "GNUNETD", "HOSTKEY", &keyfile)) | 894 | &keyfile)) |
901 | { | 895 | { |
902 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 896 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
903 | _("Lacking key configuration settings.\n")); | 897 | _("Lacking key configuration settings.\n")); |
@@ -924,8 +918,7 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, | |||
924 | uri->data.loc.expirationTime = expiration_time; | 918 | uri->data.loc.expirationTime = expiration_time; |
925 | uri->data.loc.peer = my_public_key; | 919 | uri->data.loc.peer = my_public_key; |
926 | GNUNET_assert (GNUNET_OK == | 920 | GNUNET_assert (GNUNET_OK == |
927 | GNUNET_CRYPTO_rsa_sign (my_private_key, | 921 | GNUNET_CRYPTO_rsa_sign (my_private_key, &ass.purpose, |
928 | &ass.purpose, | ||
929 | &uri->data.loc.contentSignature)); | 922 | &uri->data.loc.contentSignature)); |
930 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | 923 | GNUNET_CRYPTO_rsa_key_free (my_private_key); |
931 | return uri; | 924 | return uri; |
@@ -941,8 +934,8 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri, | |||
941 | * @return an FS URI for the given namespace and identifier | 934 | * @return an FS URI for the given namespace and identifier |
942 | */ | 935 | */ |
943 | struct GNUNET_FS_Uri * | 936 | struct GNUNET_FS_Uri * |
944 | GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, | 937 | GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id, |
945 | const char *id, char **emsg) | 938 | char **emsg) |
946 | { | 939 | { |
947 | struct GNUNET_FS_Uri *ns_uri; | 940 | struct GNUNET_FS_Uri *ns_uri; |
948 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; | 941 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; |
@@ -1166,8 +1159,8 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) | |||
1166 | } | 1159 | } |
1167 | if (ret->data.ksk.keywordCount > 0) | 1160 | if (ret->data.ksk.keywordCount > 0) |
1168 | { | 1161 | { |
1169 | ret->data.ksk.keywords | 1162 | ret->data.ksk.keywords = |
1170 | = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *)); | 1163 | GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *)); |
1171 | for (i = 0; i < ret->data.ksk.keywordCount; i++) | 1164 | for (i = 0; i < ret->data.ksk.keywordCount; i++) |
1172 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); | 1165 | ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]); |
1173 | } | 1166 | } |
@@ -1315,8 +1308,7 @@ GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) | |||
1315 | /* allow URI to be given as one and only keyword and | 1308 | /* allow URI to be given as one and only keyword and |
1316 | * handle accordingly */ | 1309 | * handle accordingly */ |
1317 | emsg = NULL; | 1310 | emsg = NULL; |
1318 | if ((argc == 1) && | 1311 | if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && |
1319 | (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) && | ||
1320 | (0 == | 1312 | (0 == |
1321 | strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX))) | 1313 | strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX))) |
1322 | && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) | 1314 | && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg)))) |
@@ -1371,14 +1363,14 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
1371 | switch (u1->type) | 1363 | switch (u1->type) |
1372 | { | 1364 | { |
1373 | case chk: | 1365 | case chk: |
1374 | if (0 == memcmp (&u1->data.chk, | 1366 | if (0 == |
1375 | &u2->data.chk, sizeof (struct FileIdentifier))) | 1367 | memcmp (&u1->data.chk, &u2->data.chk, sizeof (struct FileIdentifier))) |
1376 | return GNUNET_YES; | 1368 | return GNUNET_YES; |
1377 | return GNUNET_NO; | 1369 | return GNUNET_NO; |
1378 | case sks: | 1370 | case sks: |
1379 | if ((0 == memcmp (&u1->data.sks.namespace, | 1371 | if ((0 == |
1380 | &u2->data.sks.namespace, | 1372 | memcmp (&u1->data.sks.namespace, &u2->data.sks.namespace, |
1381 | sizeof (GNUNET_HashCode))) && | 1373 | sizeof (GNUNET_HashCode))) && |
1382 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) | 1374 | (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier))) |
1383 | 1375 | ||
1384 | return GNUNET_YES; | 1376 | return GNUNET_YES; |
@@ -1402,12 +1394,12 @@ GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, | |||
1402 | } | 1394 | } |
1403 | return GNUNET_YES; | 1395 | return GNUNET_YES; |
1404 | case loc: | 1396 | case loc: |
1405 | if (memcmp (&u1->data.loc, | 1397 | if (memcmp |
1406 | &u2->data.loc, | 1398 | (&u1->data.loc, &u2->data.loc, |
1407 | sizeof (struct FileIdentifier) + | 1399 | sizeof (struct FileIdentifier) + |
1408 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | 1400 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + |
1409 | sizeof (struct GNUNET_TIME_Absolute) + | 1401 | sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) + |
1410 | sizeof (unsigned short) + sizeof (unsigned short)) != 0) | 1402 | sizeof (unsigned short)) != 0) |
1411 | return GNUNET_NO; | 1403 | return GNUNET_NO; |
1412 | return GNUNET_YES; | 1404 | return GNUNET_YES; |
1413 | default: | 1405 | default: |
@@ -1584,10 +1576,8 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) | |||
1584 | * @return 0 (always) | 1576 | * @return 0 (always) |
1585 | */ | 1577 | */ |
1586 | static int | 1578 | static int |
1587 | gather_uri_data (void *cls, | 1579 | gather_uri_data (void *cls, const char *plugin_name, |
1588 | const char *plugin_name, | 1580 | enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, |
1589 | enum EXTRACTOR_MetaType type, | ||
1590 | enum EXTRACTOR_MetaFormat format, | ||
1591 | const char *data_mime_type, const char *data, size_t data_len) | 1581 | const char *data_mime_type, const char *data, size_t data_len) |
1592 | { | 1582 | { |
1593 | struct GNUNET_FS_Uri *uri = cls; | 1583 | struct GNUNET_FS_Uri *uri = cls; |
@@ -1643,8 +1633,9 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData | |||
1643 | static int | 1633 | static int |
1644 | needs_percent (char c) | 1634 | needs_percent (char c) |
1645 | { | 1635 | { |
1646 | return (!((isalnum ((unsigned char) c)) || | 1636 | return (! |
1647 | (c == '-') || (c == '_') || (c == '.') || (c == '~'))); | 1637 | ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') || |
1638 | (c == '.') || (c == '~'))); | ||
1648 | } | 1639 | } |
1649 | 1640 | ||
1650 | 1641 | ||
@@ -1737,9 +1728,7 @@ uri_sks_to_string (const struct GNUNET_FS_Uri *uri) | |||
1737 | namespace = &uri->data.sks.namespace; | 1728 | namespace = &uri->data.sks.namespace; |
1738 | identifier = uri->data.sks.identifier; | 1729 | identifier = uri->data.sks.identifier; |
1739 | GNUNET_CRYPTO_hash_to_enc (namespace, &ns); | 1730 | GNUNET_CRYPTO_hash_to_enc (namespace, &ns); |
1740 | GNUNET_asprintf (&ret, | 1731 | GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX, |
1741 | "%s%s%s/%s", | ||
1742 | GNUNET_FS_URI_PREFIX, | ||
1743 | GNUNET_FS_URI_SKS_INFIX, (const char *) &ns, identifier); | 1732 | GNUNET_FS_URI_SKS_INFIX, (const char *) &ns, identifier); |
1744 | return ret; | 1733 | return ret; |
1745 | } | 1734 | } |
@@ -1765,11 +1754,8 @@ uri_chk_to_string (const struct GNUNET_FS_Uri *uri) | |||
1765 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); | 1754 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash); |
1766 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); | 1755 | GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash); |
1767 | 1756 | ||
1768 | GNUNET_asprintf (&ret, | 1757 | GNUNET_asprintf (&ret, "%s%s%s.%s.%llu", GNUNET_FS_URI_PREFIX, |
1769 | "%s%s%s.%s.%llu", | 1758 | GNUNET_FS_URI_CHK_INFIX, (const char *) &keyhash, |
1770 | GNUNET_FS_URI_PREFIX, | ||
1771 | GNUNET_FS_URI_CHK_INFIX, | ||
1772 | (const char *) &keyhash, | ||
1773 | (const char *) &queryhash, GNUNET_ntohll (fi->file_length)); | 1759 | (const char *) &queryhash, GNUNET_ntohll (fi->file_length)); |
1774 | return ret; | 1760 | return ret; |
1775 | } | 1761 | } |
@@ -1839,18 +1825,17 @@ uri_loc_to_string (const struct GNUNET_FS_Uri *uri) | |||
1839 | 1825 | ||
1840 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); | 1826 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash); |
1841 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); | 1827 | GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash); |
1842 | peerId = bin2enc (&uri->data.loc.peer, | 1828 | peerId = |
1843 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 1829 | bin2enc (&uri->data.loc.peer, |
1844 | peerSig = bin2enc (&uri->data.loc.contentSignature, | 1830 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
1845 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); | 1831 | peerSig = |
1846 | GNUNET_asprintf (&ret, | 1832 | bin2enc (&uri->data.loc.contentSignature, |
1847 | "%s%s%s.%s.%llu.%s.%s.%llu", | 1833 | sizeof (struct GNUNET_CRYPTO_RsaSignature)); |
1848 | GNUNET_FS_URI_PREFIX, | 1834 | GNUNET_asprintf (&ret, "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX, |
1849 | GNUNET_FS_URI_LOC_INFIX, | 1835 | GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash, |
1850 | (const char *) &keyhash, | ||
1851 | (const char *) &queryhash, | 1836 | (const char *) &queryhash, |
1852 | (unsigned long long) GNUNET_ntohll (uri->data.loc. | 1837 | (unsigned long long) GNUNET_ntohll (uri->data.loc.fi. |
1853 | fi.file_length), peerId, | 1838 | file_length), peerId, |
1854 | peerSig, | 1839 | peerSig, |
1855 | (unsigned long long) uri->data.loc.expirationTime.abs_value); | 1840 | (unsigned long long) uri->data.loc.expirationTime.abs_value); |
1856 | GNUNET_free (peerSig); | 1841 | GNUNET_free (peerSig); |