2 This file is part of GNUnet.
3 (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors)
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
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
23 * @brief Parses and produces uri strings.
24 * @author Igor Wronsky, Christian Grothoff
26 * GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER".
27 * The specific structure of "IDENTIFIER" depends on the module and
28 * maybe differenciated into additional subcategories if applicable.
29 * This module only deals with fs identifiers (MODULE = "fs").
32 * This module only parses URIs for the AFS module. The FS URIs fall
33 * into four categories, "chk", "sks", "ksk" and "loc". The first three
34 * categories were named in analogy (!) to Freenet, but they do NOT
35 * work in exactly the same way. They are very similar from the user's
36 * point of view (unique file identifier, subspace, keyword), but the
37 * implementation is rather different in pretty much every detail.
38 * The concrete URI formats are:
42 * First, there are URIs that identify a file. They have the format
43 * "gnunet://fs/chk/HEX1.HEX2.SIZE". These URIs can be used to
44 * download the file. The description, filename, mime-type and other
45 * meta-data is NOT part of the file-URI since a URI uniquely
46 * identifies a resource (and the contents of the file would be the
47 * same even if it had a different description).
51 * The second category identifies entries in a namespace. The format
52 * is "gnunet://fs/sks/NAMESPACE/IDENTIFIER" where the namespace
53 * should be given in HEX. Applications may allow using a nickname
54 * for the namespace if the nickname is not ambiguous. The identifier
55 * can be either an ASCII sequence or a HEX-encoding. If the
56 * identifier is in ASCII but the format is ambiguous and could denote
57 * a HEX-string a "/" is appended to indicate ASCII encoding.
61 * The third category identifies ordinary searches. The format is
62 * "gnunet://fs/ksk/KEYWORD[+KEYWORD]*". Using the "+" syntax
63 * it is possible to encode searches with the boolean "AND" operator.
64 * "+" is used since it indicates a commutative 'and' operation and
65 * is unlikely to be used in a keyword by itself.
69 * The last category identifies a datum on a specific machine. The
70 * format is "gnunet://fs/loc/HEX1.HEX2.SIZE.PEER.SIG.EXPTIME". PEER is
71 * the BinName of the public key of the peer storing the datum. The
72 * signature (SIG) certifies that this peer has this content.
73 * HEX1, HEX2 and SIZE correspond to a 'chk' URI.
77 * The encoding for hexadecimal values is defined in the hashing.c
78 * module in the gnunetutil library and discussed there.
82 #include "gnunet_fs_service.h"
83 #include "gnunet_signatures.h"
88 * Get a unique key from a URI. This is for putting URIs
89 * into HashMaps. The key may change between FS implementations.
91 * @param uri uri to convert to a unique key
92 * @param key wherer to store the unique key
95 GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, GNUNET_HashCode * key)
100 *key = uri->data.chk.chk.query;
103 GNUNET_CRYPTO_hash (uri->data.sks.identifier,
104 strlen (uri->data.sks.identifier), key);
107 if (uri->data.ksk.keywordCount > 0)
108 GNUNET_CRYPTO_hash (uri->data.ksk.keywords[0],
109 strlen (uri->data.ksk.keywords[0]), key);
112 GNUNET_CRYPTO_hash (&uri->data.loc.fi,
113 sizeof (struct FileIdentifier) +
114 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
118 memset (key, 0, sizeof (GNUNET_HashCode));
125 * Convert keyword URI to a human readable format
126 * (i.e. the search query that was used in the first place)
128 * @param uri ksk uri to convert to a string
129 * @return string with the keywords
132 GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri)
139 unsigned int keywordCount;
141 if ((uri == NULL) || (uri->type != ksk))
146 keywords = uri->data.ksk.keywords;
147 keywordCount = uri->data.ksk.keywordCount;
148 n = keywordCount + 1;
149 for (i = 0; i < keywordCount; i++)
151 keyword = keywords[i];
152 n += strlen (keyword) - 1;
153 if (NULL != strstr (&keyword[1], " "))
155 if (keyword[0] == '+')
158 ret = GNUNET_malloc (n);
160 for (i = 0; i < keywordCount; i++)
162 keyword = keywords[i];
163 if (NULL != strstr (&keyword[1], " "))
166 if (keyword[0] == '+')
167 strcat (ret, keyword);
169 strcat (ret, &keyword[1]);
174 if (keyword[0] == '+')
175 strcat (ret, keyword);
177 strcat (ret, &keyword[1]);
186 * Given a keyword with %-encoding (and possibly quotes to protect
187 * spaces), return a copy of the keyword without %-encoding and
188 * without double-quotes (%22). Also, add a space at the beginning
189 * if there is not a '+'.
191 * @param in string with %-encoding
192 * @param emsg where to store the parser error message (if any)
193 * @return decodded string with leading space (or preserved plus)
196 percent_decode_keyword (const char *in, char **emsg)
204 out = GNUNET_strdup (in);
207 while (out[rpos] != '\0')
209 if (out[rpos] == '%')
211 if (1 != sscanf (&out[rpos + 1], "%2X", &hx))
214 *emsg = GNUNET_strdup (_("`%' must be followed by HEX number"));
219 continue; /* skip double quote */
220 out[wpos++] = (char) hx;
224 out[wpos++] = out[rpos++];
230 ret = GNUNET_strdup (out);
234 /* need to prefix with space */
235 ret = GNUNET_malloc (strlen (out) + 2);
243 #define GNUNET_FS_URI_KSK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_KSK_INFIX
248 * @param s an uri string
249 * @param emsg where to store the parser error message (if any)
250 * @return NULL on error, otherwise the KSK URI
252 static struct GNUNET_FS_Uri *
253 uri_ksk_parse (const char *s, char **emsg)
255 struct GNUNET_FS_Uri *ret;
265 GNUNET_assert (s != NULL);
267 pos = strlen (GNUNET_FS_URI_KSK_PREFIX);
268 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_KSK_PREFIX, pos)))
269 return NULL; /* not KSK URI */
270 if ((s[slen - 1] == '+') || (s[pos] == '+'))
273 GNUNET_strdup (_("Malformed KSK URI (must not begin or end with `+')"));
278 for (i = pos; i < slen; i++)
280 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
282 saw_quote = (saw_quote + 1) % 2;
286 if ((s[i] == '+') && (saw_quote == 0))
291 *emsg = GNUNET_strdup (_("`++' not allowed in KSK URI"));
298 *emsg = GNUNET_strdup (_("Quotes not balanced in KSK URI"));
302 dup = GNUNET_strdup (s);
303 keywords = GNUNET_malloc (max * sizeof (char *));
304 for (i = slen - 1; i >= pos; i--)
306 if ((s[i] == '%') && (&s[i] == strstr (&s[i], "%22")))
308 saw_quote = (saw_quote + 1) % 2;
312 if ((dup[i] == '+') && (saw_quote == 0))
314 keywords[--max] = percent_decode_keyword (&dup[i + 1], emsg);
315 if (NULL == keywords[max])
320 keywords[--max] = percent_decode_keyword (&dup[pos], emsg);
321 if (NULL == keywords[max])
323 GNUNET_assert (max == 0);
325 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
327 ret->data.ksk.keywordCount = iret;
328 ret->data.ksk.keywords = keywords;
331 for (i = 0; i < max; i++)
332 GNUNET_free_non_null (keywords[i]);
333 GNUNET_free (keywords);
339 #define GNUNET_FS_URI_SKS_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX
344 * @param s an uri string
345 * @param emsg where to store the parser error message (if any)
346 * @return NULL on error, SKS URI otherwise
348 static struct GNUNET_FS_Uri *
349 uri_sks_parse (const char *s, char **emsg)
351 struct GNUNET_FS_Uri *ret;
352 GNUNET_HashCode namespace;
356 char enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
358 GNUNET_assert (s != NULL);
360 pos = strlen (GNUNET_FS_URI_SKS_PREFIX);
361 if ((slen <= pos) || (0 != strncmp (s, GNUNET_FS_URI_SKS_PREFIX, pos)))
362 return NULL; /* not an SKS URI */
363 if ((slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) ||
364 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/'))
366 *emsg = GNUNET_strdup (_("Malformed SKS URI"));
369 memcpy (enc, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
370 enc[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
371 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (enc, &namespace))
373 *emsg = GNUNET_strdup (_("Malformed SKS URI"));
377 GNUNET_strdup (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)]);
378 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
380 ret->data.sks.namespace = namespace;
381 ret->data.sks.identifier = identifier;
385 #define GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX
391 * @param s an uri string
392 * @param emsg where to store the parser error message (if any)
393 * @return NULL on error, CHK URI otherwise
395 static struct GNUNET_FS_Uri *
396 uri_chk_parse (const char *s, char **emsg)
398 struct GNUNET_FS_Uri *ret;
399 struct FileIdentifier fi;
401 unsigned long long flen;
403 char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
404 char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
408 GNUNET_assert (s != NULL);
410 pos = strlen (GNUNET_FS_URI_CHK_PREFIX);
411 if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
412 (0 != strncmp (s, GNUNET_FS_URI_CHK_PREFIX, pos)))
413 return NULL; /* not a CHK URI */
414 if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
415 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
417 *emsg = GNUNET_strdup (_("Malformed CHK URI"));
420 memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
421 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
422 memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
423 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
424 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
426 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &fi.chk.key)) ||
427 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &fi.chk.query)) ||
429 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
432 *emsg = GNUNET_strdup (_("Malformed CHK URI"));
435 fi.file_length = GNUNET_htonll (flen);
436 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
444 * Convert a character back to the binary value
445 * that it represents (given base64-encoding).
447 * @param a character to convert
448 * @return offset in the "tbl" array
451 c2v (unsigned char a)
453 if ((a >= '0') && (a <= '9'))
455 if ((a >= 'A') && (a <= 'Z'))
456 return (a - 'A' + 10);
457 if ((a >= 'a') && (a <= 'z'))
458 return (a - 'a' + 36);
468 * Convert string back to binary data.
470 * @param input '\\0'-terminated string
471 * @param data where to write binary data
472 * @param size how much data should be converted
473 * @return number of characters processed from input,
477 enc2bin (const char *input, void *data, size_t size)
485 if (((size * 8) % 6) != 0)
487 if (strlen (input) < len)
488 return -1; /* error! */
492 for (pos = 0; pos < size; pos++)
496 bits |= (c2v (input[len++]) << hbits);
499 (((unsigned char *) data)[pos]) = (unsigned char) bits;
508 * Structure that defines how the
509 * contents of a location URI must be
510 * assembled in memory to create or
511 * verify the signature of a location
514 struct LocUriAssembly
516 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
518 struct GNUNET_TIME_AbsoluteNBO exptime;
520 struct FileIdentifier fi;
522 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded peer;
527 #define GNUNET_FS_URI_LOC_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX
531 * Also verifies validity of the location URI.
533 * @param s an uri string
534 * @param emsg where to store the parser error message (if any)
535 * @return NULL on error, valid LOC URI otherwise
537 static struct GNUNET_FS_Uri *
538 uri_loc_parse (const char *s, char **emsg)
540 struct GNUNET_FS_Uri *uri;
541 char h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
542 char h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)];
545 unsigned long long exptime;
546 unsigned long long flen;
547 struct GNUNET_TIME_Absolute et;
548 struct GNUNET_CRYPTO_RsaSignature sig;
549 struct LocUriAssembly ass;
553 GNUNET_assert (s != NULL);
555 pos = strlen (GNUNET_FS_URI_LOC_PREFIX);
556 if ((slen < pos + 2 * sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
557 (0 != strncmp (s, GNUNET_FS_URI_LOC_PREFIX, pos)))
558 return NULL; /* not an SKS URI */
559 if ((s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '.') ||
560 (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2 - 1] != '.'))
562 *emsg = GNUNET_strdup (_("SKS URI malformed"));
565 memcpy (h1, &s[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
566 h1[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
567 memcpy (h2, &s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)],
568 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
569 h2[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
571 if ((GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h1, &ass.fi.chk.key)) ||
572 (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (h2, &ass.fi.chk.query)) ||
574 SSCANF (&s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2],
577 *emsg = GNUNET_strdup (_("SKS URI malformed"));
580 ass.fi.file_length = GNUNET_htonll (flen);
582 npos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) * 2;
583 while ((s[npos] != '\0') && (s[npos] != '.'))
587 *emsg = GNUNET_strdup (_("SKS URI malformed"));
592 enc2bin (&s[npos], &ass.peer,
593 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
597 GNUNET_strdup (_("SKS URI malformed (could not decode public key)"));
601 if (s[npos++] != '.')
603 *emsg = GNUNET_strdup (_("SKS URI malformed (could not find signature)"));
606 ret = enc2bin (&s[npos], &sig, sizeof (struct GNUNET_CRYPTO_RsaSignature));
609 *emsg = GNUNET_strdup (_("SKS URI malformed (could not decode signature)"));
613 if (s[npos++] != '.')
615 *emsg = GNUNET_strdup (_("SKS URI malformed"));
618 if (1 != SSCANF (&s[npos], "%llu", &exptime))
622 ("SKS URI malformed (could not parse expiration time)"));
625 ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
626 ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
627 et.abs_value = exptime;
628 ass.exptime = GNUNET_TIME_absolute_hton (et);
630 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT,
631 &ass.purpose, &sig, &ass.peer))
634 GNUNET_strdup (_("SKS URI malformed (signature failed validation)"));
637 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
639 uri->data.loc.fi = ass.fi;
640 uri->data.loc.peer = ass.peer;
641 uri->data.loc.expirationTime = et;
642 uri->data.loc.contentSignature = sig;
651 * Convert a UTF-8 String to a URI.
653 * @param uri string to parse
654 * @param emsg where to store the parser error message (if any)
655 * @return NULL on error
657 struct GNUNET_FS_Uri *
658 GNUNET_FS_uri_parse (const char *uri, char **emsg)
660 struct GNUNET_FS_Uri *ret;
666 if ((NULL != (ret = uri_chk_parse (uri, emsg))) ||
667 (NULL != (ret = uri_ksk_parse (uri, emsg))) ||
668 (NULL != (ret = uri_sks_parse (uri, emsg))) ||
669 (NULL != (ret = uri_loc_parse (uri, emsg))))
672 *emsg = GNUNET_strdup (_("Unrecognized URI type"));
682 * @param uri uri to free
685 GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri)
689 GNUNET_assert (uri != NULL);
693 for (i = 0; i < uri->data.ksk.keywordCount; i++)
694 GNUNET_free (uri->data.ksk.keywords[i]);
695 GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount, 0);
698 GNUNET_free (uri->data.sks.identifier);
710 * How many keywords are ANDed in this keyword URI?
712 * @param uri ksk uri to get the number of keywords from
713 * @return 0 if this is not a keyword URI
716 GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri)
718 if (uri->type != ksk)
720 return uri->data.ksk.keywordCount;
725 * Iterate over all keywords in this keyword URI.
727 * @param uri ksk uri to get the keywords from
728 * @param iterator function to call on each keyword
729 * @param iterator_cls closure for iterator
730 * @return -1 if this is not a keyword URI, otherwise number of
731 * keywords iterated over until iterator aborted
734 GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri,
735 GNUNET_FS_KeywordIterator iterator,
741 if (uri->type != ksk)
743 if (iterator == NULL)
744 return uri->data.ksk.keywordCount;
745 for (i = 0; i < uri->data.ksk.keywordCount; i++)
747 keyword = uri->data.ksk.keywords[i];
748 /* first character of keyword indicates
749 * if it is mandatory or not */
750 if (GNUNET_OK != iterator (iterator_cls, &keyword[1], keyword[0] == '+'))
758 * Add the given keyword to the set of keywords represented by the URI.
759 * Does nothing if the keyword is already present.
761 * @param uri ksk uri to modify
762 * @param keyword keyword to add
763 * @param is_mandatory is this keyword mandatory?
766 GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword,
773 GNUNET_assert (uri->type == ksk);
774 for (i = 0; i < uri->data.ksk.keywordCount; i++)
776 old = uri->data.ksk.keywords[i];
777 if (0 == strcmp (&old[1], keyword))
780 GNUNET_asprintf (&n, is_mandatory ? "+%s" : " %s", keyword);
781 GNUNET_array_append (uri->data.ksk.keywords, uri->data.ksk.keywordCount, n);
786 * Remove the given keyword from the set of keywords represented by the URI.
787 * Does nothing if the keyword is not present.
789 * @param uri ksk uri to modify
790 * @param keyword keyword to add
793 GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri,
799 GNUNET_assert (uri->type == ksk);
800 for (i = 0; i < uri->data.ksk.keywordCount; i++)
802 old = uri->data.ksk.keywords[i];
803 if (0 == strcmp (&old[1], keyword))
805 uri->data.ksk.keywords[i] =
806 uri->data.ksk.keywords[uri->data.ksk.keywordCount - 1];
807 GNUNET_array_grow (uri->data.ksk.keywords, uri->data.ksk.keywordCount,
808 uri->data.ksk.keywordCount - 1);
817 * Obtain the identity of the peer offering the data
819 * @param uri the location URI to inspect
820 * @param peer where to store the identify of the peer (presumably) offering the content
821 * @return GNUNET_SYSERR if this is not a location URI, otherwise GNUNET_OK
824 GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri,
825 struct GNUNET_PeerIdentity *peer)
827 if (uri->type != loc)
828 return GNUNET_SYSERR;
829 GNUNET_CRYPTO_hash (&uri->data.loc.peer,
830 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
837 * Obtain the expiration of the LOC URI.
839 * @param uri location URI to get the expiration from
840 * @return expiration time of the URI
842 struct GNUNET_TIME_Absolute
843 GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri)
845 GNUNET_assert (uri->type == loc);
846 return uri->data.loc.expirationTime;
852 * Obtain the URI of the content itself.
854 * @param uri location URI to get the content URI from
855 * @return NULL if argument is not a location URI
857 struct GNUNET_FS_Uri *
858 GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri)
860 struct GNUNET_FS_Uri *ret;
862 if (uri->type != loc)
864 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
866 ret->data.chk = uri->data.loc.fi;
872 * Construct a location URI (this peer will be used for the location).
874 * @param baseUri content offered by the sender
875 * @param cfg configuration information (used to find our hostkey)
876 * @param expiration_time how long will the content be offered?
877 * @return the location URI, NULL on error
879 struct GNUNET_FS_Uri *
880 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
881 const struct GNUNET_CONFIGURATION_Handle *cfg,
882 struct GNUNET_TIME_Absolute expiration_time)
884 struct GNUNET_FS_Uri *uri;
885 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
886 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
888 struct LocUriAssembly ass;
890 if (baseUri->type != chk)
893 GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
896 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
897 _("Lacking key configuration settings.\n"));
900 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
901 if (my_private_key == NULL)
903 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
904 _("Could not access hostkey file `%s'.\n"), keyfile);
905 GNUNET_free (keyfile);
908 GNUNET_free (keyfile);
909 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
910 ass.purpose.size = htonl (sizeof (struct LocUriAssembly));
911 ass.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
912 ass.exptime = GNUNET_TIME_absolute_hton (expiration_time);
913 ass.fi = baseUri->data.chk;
914 ass.peer = my_public_key;
915 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
917 uri->data.loc.fi = baseUri->data.chk;
918 uri->data.loc.expirationTime = expiration_time;
919 uri->data.loc.peer = my_public_key;
920 GNUNET_assert (GNUNET_OK ==
921 GNUNET_CRYPTO_rsa_sign (my_private_key, &ass.purpose,
922 &uri->data.loc.contentSignature));
923 GNUNET_CRYPTO_rsa_key_free (my_private_key);
929 * Create an SKS URI from a namespace and an identifier.
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
936 struct GNUNET_FS_Uri *
937 GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns, const char *id,
940 struct GNUNET_FS_Uri *ns_uri;
941 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk;
943 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
945 GNUNET_CRYPTO_rsa_key_get_public (ns->key, &pk);
946 GNUNET_CRYPTO_hash (&pk, sizeof (pk), &ns_uri->data.sks.namespace);
947 ns_uri->data.sks.identifier = GNUNET_strdup (id);
953 * Create an SKS URI from a namespace ID and an identifier.
955 * @param nsid namespace ID
956 * @param id identifier
957 * @return an FS URI for the given namespace and identifier
959 struct GNUNET_FS_Uri *
960 GNUNET_FS_uri_sks_create_from_nsid (GNUNET_HashCode * nsid, const char *id)
962 struct GNUNET_FS_Uri *ns_uri;
964 ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
966 ns_uri->data.sks.namespace = *nsid;
967 ns_uri->data.sks.identifier = GNUNET_strdup (id);
973 * Canonicalize a keyword.
975 * @param in input string (the keyword)
976 * @return canonicalized keyword
979 canonicalize_keyword (const char *in)
985 ret = GNUNET_strdup (in);
988 while ('\0' != *rpos)
990 switch (tolower ((unsigned char) *rpos))
1001 /* skip characters listed above */
1023 /* convert characters listed above to lower case */
1024 *wpos = tolower ((unsigned char) *rpos);
1031 /* keep characters listed above without changes */
1036 if (isspace ((unsigned char) *rpos) ||
1037 isdigit ((unsigned char) *rpos) )
1039 /* replace characters listed above with '_' */
1052 * Canonicalize keyword URI. Performs operations such
1053 * as decapitalization and removal of certain characters.
1054 * (useful for search).
1056 * @param uri the URI to canonicalize
1057 * @return canonicalized version of the URI, NULL on error
1059 struct GNUNET_FS_Uri *
1060 GNUNET_FS_uri_ksk_canonicalize (const struct GNUNET_FS_Uri *uri)
1062 struct GNUNET_FS_Uri *ret;
1070 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1072 kc = uri->data.ksk.keywordCount;
1073 for (i = 0; i < kc; i++)
1075 in = uri->data.ksk.keywords[i];
1076 GNUNET_FS_uri_ksk_add_keyword (ret,
1078 (in[0] == '+') ? GNUNET_YES : GNUNET_NO);
1079 sb = GNUNET_strdup (&in[1]);
1080 #define DELIMS " \\|\"'`/&@-_,.;!?+-*^$#~=[]{}()<>"
1081 for (tok = strtok (sb, DELIMS); NULL != tok; tok = strtok (NULL, DELIMS))
1084 if (strlen(tok) < 3)
1086 GNUNET_FS_uri_ksk_add_keyword (ret,
1089 cc = canonicalize_keyword (tok);
1090 if (strlen (cc) > 2)
1091 GNUNET_FS_uri_ksk_add_keyword (ret,
1102 * Merge the sets of keywords from two KSK URIs.
1103 * (useful for merging the canonicalized keywords with
1104 * the original keywords for sharing).
1106 * @param u1 first uri
1107 * @param u2 second uri
1108 * @return merged URI, NULL on error
1110 struct GNUNET_FS_Uri *
1111 GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
1112 const struct GNUNET_FS_Uri *u2)
1114 struct GNUNET_FS_Uri *ret;
1122 if ((u1 == NULL) && (u2 == NULL))
1125 return GNUNET_FS_uri_dup (u2);
1127 return GNUNET_FS_uri_dup (u1);
1128 if ((u1->type != ksk) || (u2->type != ksk))
1133 kc = u1->data.ksk.keywordCount;
1134 kl = GNUNET_malloc ((kc + u2->data.ksk.keywordCount) * sizeof (char *));
1135 for (i = 0; i < u1->data.ksk.keywordCount; i++)
1136 kl[i] = GNUNET_strdup (u1->data.ksk.keywords[i]);
1137 for (i = 0; i < u2->data.ksk.keywordCount; i++)
1139 kp = u2->data.ksk.keywords[i];
1141 for (j = 0; j < u1->data.ksk.keywordCount; j++)
1142 if (0 == strcmp (kp + 1, kl[j] + 1))
1150 kl[kc++] = GNUNET_strdup (kp);
1152 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1154 ret->data.ksk.keywordCount = kc;
1155 ret->data.ksk.keywords = kl;
1163 * @param uri the URI to duplicate
1164 * @return copy of the URI
1166 struct GNUNET_FS_Uri *
1167 GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
1169 struct GNUNET_FS_Uri *ret;
1174 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1175 memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri));
1179 if (ret->data.ksk.keywordCount >=
1180 GNUNET_MAX_MALLOC_CHECKED / sizeof (char *))
1186 if (ret->data.ksk.keywordCount > 0)
1188 ret->data.ksk.keywords =
1189 GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
1190 for (i = 0; i < ret->data.ksk.keywordCount; i++)
1191 ret->data.ksk.keywords[i] = GNUNET_strdup (uri->data.ksk.keywords[i]);
1194 ret->data.ksk.keywords = NULL; /* just to be sure */
1197 ret->data.sks.identifier = GNUNET_strdup (uri->data.sks.identifier);
1209 * Create an FS URI from a single user-supplied string of keywords.
1210 * The string is broken up at spaces into individual keywords.
1211 * Keywords that start with "+" are mandatory. Double-quotes can
1212 * be used to prevent breaking up strings at spaces (and also
1213 * to specify non-mandatory keywords starting with "+").
1215 * Keywords must contain a balanced number of double quotes and
1216 * double quotes can not be used in the actual keywords (for
1217 * example, the string '""foo bar""' will be turned into two
1218 * "OR"ed keywords 'foo' and 'bar', not into '"foo bar"'.
1220 * @param keywords the keyword string
1221 * @param emsg where to store an error message
1222 * @return an FS URI for the given keywords, NULL
1223 * if keywords is not legal (i.e. empty).
1225 struct GNUNET_FS_Uri *
1226 GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg)
1229 unsigned int num_Words;
1232 struct GNUNET_FS_Uri *uri;
1236 if (keywords == NULL)
1238 *emsg = GNUNET_strdup (_("No keywords specified!\n"));
1242 searchString = GNUNET_strdup (keywords);
1247 while ('\0' != *pos)
1249 if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
1253 else if (0 == inWord)
1259 saw_quote = (saw_quote + 1) % 2;
1264 GNUNET_free (searchString);
1265 *emsg = GNUNET_strdup (_("No keywords specified!\n"));
1270 GNUNET_free (searchString);
1271 *emsg = GNUNET_strdup (_("Number of double-quotes not balanced!\n"));
1274 keywordarr = GNUNET_malloc (num_Words * sizeof (char *));
1278 while ('\0' != *pos)
1280 if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
1285 else if (0 == inWord)
1287 keywordarr[num_Words] = pos;
1292 saw_quote = (saw_quote + 1) % 2;
1296 GNUNET_FS_uri_ksk_create_from_args (num_Words,
1297 (const char **) keywordarr);
1298 GNUNET_free (keywordarr);
1299 GNUNET_free (searchString);
1305 * Create an FS URI from a user-supplied command line of keywords.
1306 * Arguments should start with "+" to indicate mandatory
1309 * @param argc number of keywords
1310 * @param argv keywords (double quotes are not required for
1311 * keywords containing spaces; however, double
1312 * quotes are required for keywords starting with
1313 * "+"); there is no mechanism for having double
1314 * quotes in the actual keywords (if the user
1315 * did specifically specify double quotes, the
1316 * caller should convert each double quote
1317 * into two single quotes).
1318 * @return an FS URI for the given keywords, NULL
1319 * if keywords is not legal (i.e. empty).
1321 struct GNUNET_FS_Uri *
1322 GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv)
1325 struct GNUNET_FS_Uri *uri;
1326 const char *keyword;
1334 /* allow URI to be given as one and only keyword and
1335 * handle accordingly */
1337 if ((argc == 1) && (strlen (argv[0]) > strlen (GNUNET_FS_URI_PREFIX)) &&
1339 strncmp (argv[0], GNUNET_FS_URI_PREFIX, strlen (GNUNET_FS_URI_PREFIX)))
1340 && (NULL != (uri = GNUNET_FS_uri_parse (argv[0], &emsg))))
1342 GNUNET_free_non_null (emsg);
1343 uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1345 uri->data.ksk.keywordCount = argc;
1346 uri->data.ksk.keywords = GNUNET_malloc (argc * sizeof (char *));
1347 for (i = 0; i < argc; i++)
1350 if (keyword[0] == '+')
1351 val = GNUNET_strdup (keyword);
1353 GNUNET_asprintf (&val, " %s", keyword);
1364 uri->data.ksk.keywords[i] = val;
1371 * Test if two URIs are equal.
1373 * @param u1 one of the URIs
1374 * @param u2 the other URI
1375 * @return GNUNET_YES if the URIs are equal
1378 GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1,
1379 const struct GNUNET_FS_Uri *u2)
1385 GNUNET_assert (u1 != NULL);
1386 GNUNET_assert (u2 != NULL);
1387 if (u1->type != u2->type)
1393 memcmp (&u1->data.chk, &u2->data.chk, sizeof (struct FileIdentifier)))
1398 memcmp (&u1->data.sks.namespace, &u2->data.sks.namespace,
1399 sizeof (GNUNET_HashCode))) &&
1400 (0 == strcmp (u1->data.sks.identifier, u2->data.sks.identifier)))
1405 if (u1->data.ksk.keywordCount != u2->data.ksk.keywordCount)
1407 for (i = 0; i < u1->data.ksk.keywordCount; i++)
1410 for (j = 0; j < u2->data.ksk.keywordCount; j++)
1412 if (0 == strcmp (u1->data.ksk.keywords[i], u2->data.ksk.keywords[j]))
1418 if (ret == GNUNET_NO)
1424 (&u1->data.loc, &u2->data.loc,
1425 sizeof (struct FileIdentifier) +
1426 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
1427 sizeof (struct GNUNET_TIME_Absolute) + sizeof (unsigned short) +
1428 sizeof (unsigned short)) != 0)
1438 * Is this a namespace URI?
1440 * @param uri the uri to check
1441 * @return GNUNET_YES if this is an SKS uri
1444 GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri)
1446 return uri->type == sks;
1451 * Get the ID of a namespace from the given
1454 * @param uri the uri to get the namespace ID from
1455 * @param nsid where to store the ID of the namespace
1456 * @return GNUNET_OK on success
1459 GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri,
1460 GNUNET_HashCode * nsid)
1462 if (!GNUNET_FS_uri_test_sks (uri))
1465 return GNUNET_SYSERR;
1467 *nsid = uri->data.sks.namespace;
1473 * Get the content identifier of an SKS URI.
1475 * @param uri the sks uri
1476 * @return NULL on error (not a valid SKS URI)
1479 GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri)
1481 if (!GNUNET_FS_uri_test_sks (uri))
1486 return GNUNET_strdup (uri->data.sks.identifier);
1491 * Convert namespace URI to a human readable format
1492 * (using the namespace description, if available).
1494 * @param cfg configuration to use
1495 * @param uri SKS uri to convert
1496 * @return NULL on error (not an SKS URI)
1499 GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
1500 const struct GNUNET_FS_Uri *uri)
1505 if (uri->type != sks)
1507 name = GNUNET_PSEUDONYM_id_to_name (cfg, &uri->data.sks.namespace);
1509 return GNUNET_FS_uri_to_string (uri);
1510 GNUNET_asprintf (&ret, "%s: %s", name, uri->data.sks.identifier);
1517 * Is this a keyword URI?
1519 * @param uri the uri
1520 * @return GNUNET_YES if this is a KSK uri
1523 GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri)
1528 if (uri->type == ksk)
1530 for (i = uri->data.ksk.keywordCount - 1; i >= 0; i--)
1531 GNUNET_assert (uri->data.ksk.keywords[i] != NULL);
1534 return uri->type == ksk;
1539 * Is this a file (or directory) URI?
1541 * @param uri the uri to check
1542 * @return GNUNET_YES if this is a CHK uri
1545 GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri)
1547 return uri->type == chk;
1552 * What is the size of the file that this URI
1555 * @param uri the CHK URI to inspect
1556 * @return size of the file as specified in the CHK URI
1559 GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri * uri)
1564 return GNUNET_ntohll (uri->data.chk.file_length);
1566 return GNUNET_ntohll (uri->data.loc.fi.file_length);
1570 return 0; /* unreachable */
1575 * Is this a location URI?
1577 * @param uri the uri to check
1578 * @return GNUNET_YES if this is a LOC uri
1581 GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri)
1583 return uri->type == loc;
1588 * Function called on each value in the meta data.
1589 * Adds it to the URI.
1591 * @param cls URI to update
1592 * @param plugin_name name of the plugin that produced this value;
1593 * special values can be used (i.e. '<zlib>' for zlib being
1594 * used in the main libextractor library and yielding
1596 * @param type libextractor-type describing the meta data
1597 * @param format basic format information about data
1598 * @param data_mime_type mime-type of data (not of the original file);
1599 * can be NULL (if mime-type is not known)
1600 * @param data actual meta-data found
1601 * @param data_len number of bytes in data
1602 * @return 0 (always)
1605 gather_uri_data (void *cls, const char *plugin_name,
1606 enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format,
1607 const char *data_mime_type, const char *data, size_t data_len)
1609 struct GNUNET_FS_Uri *uri = cls;
1613 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
1614 (format != EXTRACTOR_METAFORMAT_C_STRING))
1616 for (j = uri->data.ksk.keywordCount - 1; j >= 0; j--)
1617 if (0 == strcmp (&uri->data.ksk.keywords[j][1], data))
1619 GNUNET_asprintf (&nkword, " %s", /* space to mark as 'non mandatory' */
1621 uri->data.ksk.keywords[uri->data.ksk.keywordCount++] = nkword;
1627 * Construct a keyword-URI from meta-data (take all entries
1628 * in the meta-data and construct one large keyword URI
1629 * that lists all keywords that can be found in the meta-data).
1631 * @param md metadata to use
1632 * @return NULL on error, otherwise a KSK URI
1634 struct GNUNET_FS_Uri *
1635 GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
1638 struct GNUNET_FS_Uri *ret;
1643 ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
1645 ent = GNUNET_CONTAINER_meta_data_iterate (md, NULL, NULL);
1648 ret->data.ksk.keywords = GNUNET_malloc (sizeof (char *) * ent);
1649 GNUNET_CONTAINER_meta_data_iterate (md, &gather_uri_data, ret);
1656 * In URI-encoding, does the given character
1657 * need to be encoded using %-encoding?
1660 needs_percent (char c)
1663 ((isalnum ((unsigned char) c)) || (c == '-') || (c == '_') ||
1664 (c == '.') || (c == '~')));
1669 * Convert a KSK URI to a string.
1671 * @param uri the URI to convert
1672 * @return NULL on error (i.e. keywordCount == 0)
1675 uri_ksk_to_string (const struct GNUNET_FS_Uri *uri)
1678 unsigned int keywordCount;
1685 const char *keyword;
1687 if (uri->type != ksk)
1689 keywords = uri->data.ksk.keywords;
1690 keywordCount = uri->data.ksk.keywordCount;
1691 n = keywordCount + strlen (GNUNET_FS_URI_PREFIX) +
1692 strlen (GNUNET_FS_URI_KSK_INFIX) + 1;
1693 for (i = 0; i < keywordCount; i++)
1695 keyword = keywords[i];
1696 slen = strlen (keyword);
1698 for (j = 0; j < slen; j++)
1700 if ((j == 0) && (keyword[j] == ' '))
1703 continue; /* skip leading space */
1705 if (needs_percent (keyword[j]))
1706 n += 2; /* will use %-encoding */
1709 ret = GNUNET_malloc (n);
1710 strcpy (ret, GNUNET_FS_URI_PREFIX);
1711 strcat (ret, GNUNET_FS_URI_KSK_INFIX);
1712 wpos = strlen (ret);
1713 for (i = 0; i < keywordCount; i++)
1715 keyword = keywords[i];
1716 slen = strlen (keyword);
1717 for (j = 0; j < slen; j++)
1719 if ((j == 0) && (keyword[j] == ' '))
1720 continue; /* skip leading space */
1721 if (needs_percent (keyword[j]))
1723 sprintf (&ret[wpos], "%%%02X", keyword[j]);
1728 ret[wpos++] = keyword[j];
1731 if (i != keywordCount - 1)
1739 * Convert SKS URI to a string.
1741 * @param uri sks uri to convert
1742 * @return NULL on error
1745 uri_sks_to_string (const struct GNUNET_FS_Uri *uri)
1747 const GNUNET_HashCode *namespace;
1748 const char *identifier;
1750 struct GNUNET_CRYPTO_HashAsciiEncoded ns;
1752 if (uri->type != sks)
1754 namespace = &uri->data.sks.namespace;
1755 identifier = uri->data.sks.identifier;
1756 GNUNET_CRYPTO_hash_to_enc (namespace, &ns);
1757 GNUNET_asprintf (&ret, "%s%s%s/%s", GNUNET_FS_URI_PREFIX,
1758 GNUNET_FS_URI_SKS_INFIX, (const char *) &ns, identifier);
1764 * Convert a CHK URI to a string.
1766 * @param uri chk uri to convert
1767 * @return NULL on error
1770 uri_chk_to_string (const struct GNUNET_FS_Uri *uri)
1772 const struct FileIdentifier *fi;
1774 struct GNUNET_CRYPTO_HashAsciiEncoded keyhash;
1775 struct GNUNET_CRYPTO_HashAsciiEncoded queryhash;
1777 if (uri->type != chk)
1779 fi = &uri->data.chk;
1780 GNUNET_CRYPTO_hash_to_enc (&fi->chk.key, &keyhash);
1781 GNUNET_CRYPTO_hash_to_enc (&fi->chk.query, &queryhash);
1783 GNUNET_asprintf (&ret, "%s%s%s.%s.%llu", GNUNET_FS_URI_PREFIX,
1784 GNUNET_FS_URI_CHK_INFIX, (const char *) &keyhash,
1785 (const char *) &queryhash, GNUNET_ntohll (fi->file_length));
1790 * Convert binary data to a string.
1792 * @param data binary data to convert
1793 * @param size number of bytes in data
1794 * @return converted data
1797 bin2enc (const void *data, size_t size)
1800 * 64 characters for encoding, 6 bits per character
1803 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_=";
1811 GNUNET_assert (strlen (tbl) == 64);
1813 if (((size * 8) % 6) != 0)
1815 ret = GNUNET_malloc (len + 1);
1820 for (pos = 0; pos < size; pos++)
1822 bits |= ((((const unsigned char *) data)[pos]) << hbits);
1826 ret[len++] = tbl[bits & 63];
1832 ret[len] = tbl[bits & 63];
1838 * Convert a LOC URI to a string.
1840 * @param uri loc uri to convert
1841 * @return NULL on error
1844 uri_loc_to_string (const struct GNUNET_FS_Uri *uri)
1847 struct GNUNET_CRYPTO_HashAsciiEncoded keyhash;
1848 struct GNUNET_CRYPTO_HashAsciiEncoded queryhash;
1852 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.key, &keyhash);
1853 GNUNET_CRYPTO_hash_to_enc (&uri->data.loc.fi.chk.query, &queryhash);
1855 bin2enc (&uri->data.loc.peer,
1856 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1858 bin2enc (&uri->data.loc.contentSignature,
1859 sizeof (struct GNUNET_CRYPTO_RsaSignature));
1860 GNUNET_asprintf (&ret, "%s%s%s.%s.%llu.%s.%s.%llu", GNUNET_FS_URI_PREFIX,
1861 GNUNET_FS_URI_LOC_INFIX, (const char *) &keyhash,
1862 (const char *) &queryhash,
1863 (unsigned long long) GNUNET_ntohll (uri->data.loc.
1864 fi.file_length), peerId,
1866 (unsigned long long) uri->data.loc.expirationTime.abs_value);
1867 GNUNET_free (peerSig);
1868 GNUNET_free (peerId);
1874 * Convert a URI to a UTF-8 String.
1876 * @param uri uri to convert to a string
1877 * @return the UTF-8 string
1880 GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri)
1890 return uri_ksk_to_string (uri);
1892 return uri_sks_to_string (uri);
1894 return uri_chk_to_string (uri);
1896 return uri_loc_to_string (uri);
1903 /* end of fs_uri.c */