Parses and produces uri strings. More...
#include "platform.h"
#include "gnunet_fs_service.h"
#include "gnunet_signatures.h"
#include "fs_api.h"
#include <unitypes.h>
#include <unicase.h>
#include <uniconv.h>
#include <unistr.h>
#include <unistdio.h>
Go to the source code of this file.
Data Structures | |
struct | LocUriAssembly |
Structure that defines how the contents of a location URI must be assembled in memory to create or verify the signature of a location URI. More... | |
Macros | |
#define | GNUNET_FS_URI_KSK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_KSK_INFIX |
#define | GNUNET_FS_URI_SKS_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX |
#define | GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX |
#define | GNUNET_FS_URI_LOC_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX |
#define | SIGNATURE_ASCII_LENGTH 103 |
#define | TOKENS "_. /-!?#&+@\"\'\\;:,()[]{}$<>|" |
Where to break up keywords. More... | |
Functions | |
int | GNUNET_FS_uri_to_key (const struct GNUNET_FS_Uri *uri, struct GNUNET_HashCode *key) |
Get a unique key from a URI. More... | |
char * | GNUNET_FS_uri_ksk_to_string_fancy (const struct GNUNET_FS_Uri *uri) |
Convert keyword URI to a human readable format (i.e. More... | |
static char * | percent_decode_keyword (const char *in, char **emsg) |
Given a keyword with %-encoding (and possibly quotes to protect spaces), return a copy of the keyword without %-encoding and without double-quotes (%22). More... | |
static struct GNUNET_FS_Uri * | uri_ksk_parse (const char *s, char **emsg) |
Parse a KSK URI. More... | |
static struct GNUNET_FS_Uri * | uri_sks_parse (const char *s, char **emsg) |
Parse an SKS URI. More... | |
static struct GNUNET_FS_Uri * | uri_chk_parse (const char *s, char **emsg) |
Parse a CHK URI. More... | |
static struct GNUNET_FS_Uri * | uri_loc_parse (const char *s, char **emsg) |
Parse a LOC URI. More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_parse (const char *uri, char **emsg) |
Convert a UTF-8 String to a URI. More... | |
void | GNUNET_FS_uri_destroy (struct GNUNET_FS_Uri *uri) |
Free URI. More... | |
unsigned int | GNUNET_FS_uri_ksk_get_keyword_count (const struct GNUNET_FS_Uri *uri) |
How many keywords are ANDed in this keyword URI? More... | |
int | GNUNET_FS_uri_ksk_get_keywords (const struct GNUNET_FS_Uri *uri, GNUNET_FS_KeywordIterator iterator, void *iterator_cls) |
Iterate over all keywords in this keyword URI. More... | |
void | GNUNET_FS_uri_ksk_add_keyword (struct GNUNET_FS_Uri *uri, const char *keyword, int is_mandatory) |
Add the given keyword to the set of keywords represented by the URI. More... | |
void | GNUNET_FS_uri_ksk_remove_keyword (struct GNUNET_FS_Uri *uri, const char *keyword) |
Remove the given keyword from the set of keywords represented by the URI. More... | |
int | GNUNET_FS_uri_loc_get_peer_identity (const struct GNUNET_FS_Uri *uri, struct GNUNET_PeerIdentity *peer) |
Obtain the identity of the peer offering the data. More... | |
struct GNUNET_TIME_Absolute | GNUNET_FS_uri_loc_get_expiration (const struct GNUNET_FS_Uri *uri) |
Obtain the expiration of the LOC URI. More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri) |
Obtain the URI of the content itself. More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *base_uri, const struct GNUNET_CRYPTO_EddsaPrivateKey *sign_key, struct GNUNET_TIME_Absolute expiration_time) |
Construct a location URI (this peer will be used for the location). More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_sks_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *ns, const char *id) |
Create an SKS URI from a namespace ID and an identifier. More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1, const struct GNUNET_FS_Uri *u2) |
Merge the sets of keywords from two KSK URIs. More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri) |
Duplicate URI. More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_ksk_create (const char *keywords, char **emsg) |
Create an FS URI from a single user-supplied string of keywords. More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_ksk_create_from_args (unsigned int argc, const char **argv) |
Create an FS URI from a user-supplied command line of keywords. More... | |
int | GNUNET_FS_uri_test_equal (const struct GNUNET_FS_Uri *u1, const struct GNUNET_FS_Uri *u2) |
Test if two URIs are equal. More... | |
int | GNUNET_FS_uri_test_sks (const struct GNUNET_FS_Uri *uri) |
Is this a namespace URI? More... | |
int | GNUNET_FS_uri_sks_get_namespace (const struct GNUNET_FS_Uri *uri, struct GNUNET_CRYPTO_EcdsaPublicKey *pseudonym) |
Get the ID of a namespace from the given namespace URI. More... | |
char * | GNUNET_FS_uri_sks_get_content_id (const struct GNUNET_FS_Uri *uri) |
Get the content identifier of an SKS URI. More... | |
int | GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri) |
Is this a keyword URI? More... | |
int | GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri) |
Is this a file (or directory) URI? More... | |
uint64_t | GNUNET_FS_uri_chk_get_file_size (const struct GNUNET_FS_Uri *uri) |
What is the size of the file that this URI refers to? More... | |
const struct GNUNET_HashCode * | GNUNET_FS_uri_chk_get_file_hash (const struct GNUNET_FS_Uri *uri) |
What is the hash of the original file's content that this URI refers to? More... | |
int | GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri) |
Is this a location URI? More... | |
static void | insert_non_mandatory_keyword (const char *s, char **array, int index) |
Add a keyword as non-mandatory (with ' '-prefix) to the given keyword list at offset 'index'. More... | |
static int | find_duplicate (const char *s, const char **array, int array_length) |
Test if the given keyword s is already present in the given array, ignoring the '+'-mandatory prefix in the array. More... | |
static char * | normalize_metadata (enum EXTRACTOR_MetaFormat format, const char *data, size_t data_len) |
FIXME: comment. More... | |
static size_t | u8_strcount (const uint8_t *s) |
Counts the number of UTF-8 characters (not bytes) in the string, returns that count. More... | |
static int | get_keywords_from_parens (const char *s, char **array, int index) |
Break the filename up by matching [], () and {} pairs to make keywords. More... | |
static int | get_keywords_from_tokens (const char *s, char **array, int index) |
Break the filename up by TOKENS to make keywords. More... | |
static int | gather_uri_data (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_len) |
Function called on each value in the meta data. More... | |
struct GNUNET_FS_Uri * | GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_FS_MetaData *md) |
Construct a keyword-URI from meta-data (take all entries in the meta-data and construct one large keyword URI that lists all keywords that can be found in the meta-data). More... | |
static int | needs_percent (char c) |
In URI-encoding, does the given character need to be encoded using %-encoding? More... | |
static char * | uri_ksk_to_string (const struct GNUNET_FS_Uri *uri) |
Convert a KSK URI to a string. More... | |
static char * | uri_sks_to_string (const struct GNUNET_FS_Uri *uri) |
Convert SKS URI to a string. More... | |
static char * | uri_chk_to_string (const struct GNUNET_FS_Uri *uri) |
Convert a CHK URI to a string. More... | |
static char * | uri_loc_to_string (const struct GNUNET_FS_Uri *uri) |
Convert a LOC URI to a string. More... | |
char * | GNUNET_FS_uri_to_string (const struct GNUNET_FS_Uri *uri) |
Convert a URI to a UTF-8 String. More... | |
Parses and produces uri strings.
GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER". The specific structure of "IDENTIFIER" depends on the module and maybe differentiated into additional subcategories if applicable. This module only deals with fs identifiers (MODULE = "fs").
This module only parses URIs for the AFS module. The FS URIs fall into four categories, "chk", "sks", "ksk" and "loc". The first three categories were named in analogy (!) to Freenet, but they do NOT work in exactly the same way. They are very similar from the user's point of view (unique file identifier, subspace, keyword), but the implementation is rather different in pretty much every detail. The concrete URI formats are:
First, there are URIs that identify a file. They have the format "gnunet://fs/chk/HEX1.HEX2.SIZE". These URIs can be used to download the file. The description, filename, mime-type and other meta-data is NOT part of the file-URI since a URI uniquely identifies a resource (and the contents of the file would be the same even if it had a different description).
The second category identifies entries in a namespace. The format is "gnunet://fs/sks/NAMESPACE/IDENTIFIER" where the namespace should be given in HEX. Applications may allow using a nickname for the namespace if the nickname is not ambiguous. The identifier can be either an ASCII sequence or a HEX-encoding. If the identifier is in ASCII but the format is ambiguous and could denote a HEX-string a "/" is appended to indicate ASCII encoding.
The third category identifies ordinary searches. The format is "gnunet://fs/ksk/KEYWORD[+KEYWORD]*". Using the "+" syntax it is possible to encode searches with the boolean "AND" operator. "+" is used since it indicates a commutative 'and' operation and is unlikely to be used in a keyword by itself.
The last category identifies a datum on a specific machine. The format is "gnunet://fs/loc/HEX1.HEX2.SIZE.PEER.SIG.EXPTIME". PEER is the BinName of the public key of the peer storing the datum. The signature (SIG) certifies that this peer has this content. HEX1, HEX2 and SIZE correspond to a 'chk' URI.
The encoding for hexadecimal values is defined in the hashing.c module in the gnunetutil library and discussed there.
Definition in file fs_uri.c.
#define GNUNET_FS_URI_KSK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_KSK_INFIX |
#define GNUNET_FS_URI_SKS_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX |
#define GNUNET_FS_URI_CHK_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_CHK_INFIX |
#define GNUNET_FS_URI_LOC_PREFIX GNUNET_FS_URI_PREFIX GNUNET_FS_URI_LOC_INFIX |
#define TOKENS "_. /-!?#&+@\"\'\\;:,()[]{}$<>|" |
|
static |
Given a keyword with %-encoding (and possibly quotes to protect spaces), return a copy of the keyword without %-encoding and without double-quotes (%22).
Also, add a space at the beginning if there is not a '+'.
in | string with %-encoding |
emsg | where to store the parser error message (if any) |
Definition at line 212 of file fs_uri.c.
References _, GNUNET_free, GNUNET_malloc, GNUNET_strdup, and ret.
Referenced by uri_ksk_parse().
|
static |
Parse a KSK URI.
s | an uri string |
emsg | where to store the parser error message (if any) |
Definition at line 272 of file fs_uri.c.
References _, GNUNET_assert, GNUNET_free, GNUNET_FS_URI_KSK, GNUNET_FS_URI_KSK_PREFIX, GNUNET_new, GNUNET_new_array, GNUNET_strdup, consensus-simulation::int, GNUNET_FS_Uri::keywords, max, percent_decode_keyword(), and ret.
Referenced by GNUNET_FS_uri_parse().
|
static |
Parse an SKS URI.
s | an uri string |
emsg | where to store the parser error message (if any) |
Definition at line 366 of file fs_uri.c.
References _, end, GNUNET_FS_URI_SKS, GNUNET_FS_URI_SKS_PREFIX, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_string_to_data(), ns, and ret.
Referenced by GNUNET_FS_uri_parse().
|
static |
Parse a CHK URI.
s | an uri string |
emsg | where to store the parser error message (if any) |
Definition at line 406 of file fs_uri.c.
References _, FileIdentifier::chk, FileIdentifier::file_length, GNUNET_CRYPTO_hash_from_string, GNUNET_FS_URI_CHK, GNUNET_FS_URI_CHK_PREFIX, GNUNET_htonll(), GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_strdup, ContentHashKey::key, ContentHashKey::query, and ret.
Referenced by GNUNET_FS_uri_parse().
|
static |
Parse a LOC URI.
Also verifies validity of the location URI.
s | an uri string |
emsg | where to store the parser error message (if any) |
Definition at line 496 of file fs_uri.c.
References _, GNUNET_TIME_Absolute::abs_value_us, FileIdentifier::chk, Location::contentSignature, GNUNET_FS_Uri::data, Location::expirationTime, LocUriAssembly::exptime, Location::fi, LocUriAssembly::fi, FileIdentifier::file_length, GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_CRYPTO_eddsa_verify, GNUNET_CRYPTO_hash_from_string, GNUNET_CRYPTO_PKEY_ASCII_LENGTH, GNUNET_FS_URI_LOC, GNUNET_FS_URI_LOC_PREFIX, GNUNET_htonll(), GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT, GNUNET_strdup, GNUNET_STRINGS_string_to_data(), GNUNET_TIME_absolute_hton(), ContentHashKey::key, GNUNET_FS_Uri::loc, Location::peer, LocUriAssembly::peer, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, LocUriAssembly::purpose, ContentHashKey::query, SIGNATURE_ASCII_LENGTH, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_FS_Uri::type, and uri.
Referenced by GNUNET_FS_uri_parse().
|
static |
Add a keyword as non-mandatory (with ' '-prefix) to the given keyword list at offset 'index'.
The array is guaranteed to be long enough.
s | keyword to add |
array | array to add the keyword to |
index | offset where to add the keyword |
Definition at line 1417 of file fs_uri.c.
References GNUNET_asprintf().
Referenced by gather_uri_data(), get_keywords_from_parens(), and get_keywords_from_tokens().
|
static |
Test if the given keyword s is already present in the given array, ignoring the '+'-mandatory prefix in the array.
s | keyword to test |
array | keywords to test against, with ' ' or '+' prefix to ignore |
array_length | length of the array |
Definition at line 1438 of file fs_uri.c.
References GNUNET_NO, and GNUNET_YES.
Referenced by gather_uri_data(), get_keywords_from_parens(), and get_keywords_from_tokens().
|
static |
FIXME: comment.
Definition at line 1453 of file fs_uri.c.
References data, GNUNET_malloc, and GNUNET_memcpy.
Referenced by gather_uri_data(), get_keywords_from_parens(), and get_keywords_from_tokens().
|
static |
Counts the number of UTF-8 characters (not bytes) in the string, returns that count.
Definition at line 1509 of file fs_uri.c.
References GNUNET_assert.
Referenced by gather_uri_data(), get_keywords_from_parens(), and get_keywords_from_tokens().
|
static |
Break the filename up by matching [], () and {} pairs to make keywords.
In case of nesting parentheses only the inner pair counts. You can't escape parentheses to scan something like "[blah\{foo]" to make a "blah{foo" keyword, this function is only a heuristic!
s | string to break down. |
array | array to fill with enclosed tokens. If NULL, then tokens are only counted. |
index | index at which to start filling the array (entries prior to it are used to check for duplicates). ignored if array == NULL. |
Definition at line 1540 of file fs_uri.c.
References find_duplicate(), GNUNET_free, GNUNET_NO, GNUNET_strdup, insert_non_mandatory_keyword(), normalize_metadata(), and u8_strcount().
Referenced by GNUNET_FS_uri_ksk_create_from_meta_data().
|
static |
Break the filename up by TOKENS to make keywords.
s | string to break down. |
array | array to fill with tokens. If NULL, then tokens are only counted. |
index | index at which to start filling the array (entries prior to it are used to check for duplicates). ignored if array == NULL. |
Definition at line 1648 of file fs_uri.c.
References find_duplicate(), GNUNET_free, GNUNET_NO, GNUNET_strdup, insert_non_mandatory_keyword(), normalize_metadata(), p, TOKENS, and u8_strcount().
Referenced by GNUNET_FS_uri_ksk_create_from_meta_data().
|
static |
Function called on each value in the meta data.
Adds it to the URI.
cls | URI to update |
plugin_name | name of the plugin that produced this value; special values can be used (e.g. '<zlib>' for zlib being used in the main libextractor library and yielding meta data). |
type | libextractor-type describing the meta data |
format | basic format information about data |
data_mime_type | mime-type of data (not of the original file); can be NULL (if mime-type is not known) |
data | actual meta-data found |
data_len | number of bytes in data |
Definition at line 1713 of file fs_uri.c.
References data, GNUNET_FS_Uri::data, find_duplicate(), GNUNET_asprintf(), GNUNET_free, insert_non_mandatory_keyword(), GNUNET_FS_Uri::keywordCount, GNUNET_FS_Uri::keywords, GNUNET_FS_Uri::ksk, normalize_metadata(), type, u8_strcount(), and uri.
Referenced by GNUNET_FS_uri_ksk_create_from_meta_data().
|
static |
In URI-encoding, does the given character need to be encoded using %-encoding?
Definition at line 1845 of file fs_uri.c.
Referenced by uri_ksk_to_string().
|
static |
Convert a KSK URI to a string.
uri | the URI to convert |
Definition at line 1859 of file fs_uri.c.
References GNUNET_FS_Uri::data, GNUNET_FS_URI_KSK, GNUNET_FS_URI_KSK_INFIX, GNUNET_FS_URI_PREFIX, GNUNET_malloc, GNUNET_FS_Uri::keywordCount, GNUNET_FS_Uri::keywords, GNUNET_FS_Uri::ksk, needs_percent(), ret, GNUNET_FS_Uri::type, and uri.
Referenced by GNUNET_FS_uri_to_string().
|
static |
Convert SKS URI to a string.
uri | sks uri to convert |
Definition at line 1929 of file fs_uri.c.
References GNUNET_FS_Uri::data, GNUNET_asprintf(), GNUNET_assert, GNUNET_FS_URI_PREFIX, GNUNET_FS_URI_SKS, GNUNET_FS_URI_SKS_INFIX, GNUNET_STRINGS_data_to_string(), GNUNET_FS_Uri::identifier, GNUNET_FS_Uri::ns, ret, GNUNET_FS_Uri::sks, GNUNET_FS_Uri::type, and uri.
Referenced by GNUNET_FS_uri_to_string().
|
static |
Convert a CHK URI to a string.
uri | chk uri to convert |
Definition at line 1960 of file fs_uri.c.
References FileIdentifier::chk, GNUNET_FS_Uri::chk, GNUNET_FS_Uri::data, FileIdentifier::file_length, GNUNET_asprintf(), GNUNET_CRYPTO_hash_to_enc(), GNUNET_FS_URI_CHK, GNUNET_FS_URI_CHK_INFIX, GNUNET_FS_URI_PREFIX, GNUNET_ntohll(), ContentHashKey::key, ContentHashKey::query, ret, GNUNET_FS_Uri::type, and uri.
Referenced by GNUNET_FS_uri_to_string().
|
static |
Convert a LOC URI to a string.
uri | loc uri to convert |
Definition at line 1991 of file fs_uri.c.
References GNUNET_TIME_Absolute::abs_value_us, FileIdentifier::chk, Location::contentSignature, GNUNET_FS_Uri::data, Location::expirationTime, Location::fi, FileIdentifier::file_length, GNUNET_asprintf(), GNUNET_assert, GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_CRYPTO_hash_to_enc(), GNUNET_free, GNUNET_FS_URI_LOC_INFIX, GNUNET_FS_URI_PREFIX, GNUNET_ntohll(), GNUNET_STRINGS_data_to_string(), ContentHashKey::key, GNUNET_FS_Uri::loc, Location::peer, peer_id, GNUNET_PeerIdentity::public_key, ContentHashKey::query, ret, SIGNATURE_ASCII_LENGTH, and uri.
Referenced by GNUNET_FS_uri_to_string().