diff options
author | LRN <lrn1986@gmail.com> | 2013-03-03 01:57:19 +0000 |
---|---|---|
committer | LRN <lrn1986@gmail.com> | 2013-03-03 01:57:19 +0000 |
commit | 5c2efc1952243768786f67d9fe8733cba1be0c2b (patch) | |
tree | 5f8acaa0aea14419f5dc6e317cb1c9d3ce89bfa4 /src/fs | |
parent | 27d46ea3f6ceaef7f089d674f5634eeafa5e133a (diff) | |
download | gnunet-5c2efc1952243768786f67d9fe8733cba1be0c2b.tar.gz gnunet-5c2efc1952243768786f67d9fe8733cba1be0c2b.zip |
Be able to open existing namespaces
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/fs_namespace.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/fs/fs_namespace.c b/src/fs/fs_namespace.c index 177af7efc..3558b0ae6 100644 --- a/src/fs/fs_namespace.c +++ b/src/fs/fs_namespace.c | |||
@@ -305,6 +305,49 @@ GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name) | |||
305 | 305 | ||
306 | 306 | ||
307 | /** | 307 | /** |
308 | * Open the namespace with the given name; if it does not exist, | ||
309 | * or the key file is corrupted, the function fails. | ||
310 | * | ||
311 | * @param h handle to the file sharing subsystem | ||
312 | * @param name name of the namespace | ||
313 | * @return handle to the namespace, | ||
314 | * NULL on error (i.e. invalid filename, non-existent filename) | ||
315 | */ | ||
316 | struct GNUNET_FS_Namespace * | ||
317 | GNUNET_FS_namespace_open_existing (struct GNUNET_FS_Handle *h, const char *name) | ||
318 | { | ||
319 | char *dn; | ||
320 | char *fn; | ||
321 | struct GNUNET_FS_Namespace *ret; | ||
322 | |||
323 | dn = get_namespace_directory (h); | ||
324 | if (NULL == dn) | ||
325 | { | ||
326 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
327 | _("Can't determine where namespace directory is\n")); | ||
328 | return NULL; | ||
329 | } | ||
330 | GNUNET_asprintf (&fn, "%s%s%s", dn, DIR_SEPARATOR_STR, name); | ||
331 | GNUNET_free (dn); | ||
332 | ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace)); | ||
333 | ret->h = h; | ||
334 | ret->rc = 1; | ||
335 | ret->key = GNUNET_CRYPTO_rsa_key_create_from_existing_file (fn); | ||
336 | if (NULL == ret->key) | ||
337 | { | ||
338 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
339 | _("Failed to read private key for namespace `%s'\n"), name); | ||
340 | GNUNET_free (ret); | ||
341 | GNUNET_free (fn); | ||
342 | return NULL; | ||
343 | } | ||
344 | ret->name = GNUNET_strdup (name); | ||
345 | ret->filename = fn; | ||
346 | return ret; | ||
347 | } | ||
348 | |||
349 | |||
350 | /** | ||
308 | * Function called upon completion of 'GNUNET_CRYPTO_rsa_key_create_start'. | 351 | * Function called upon completion of 'GNUNET_CRYPTO_rsa_key_create_start'. |
309 | * | 352 | * |
310 | * @param cls closure | 353 | * @param cls closure |