-}
-
-
-/**
- * Create a namespace with the given name; if one already
- * exists, return a handle to the existing namespace.
- *
- * @param h handle to the file sharing subsystem
- * @param name name to use for the namespace
- * @return handle to the namespace, NULL on error (i.e. invalid filename)
- */
-struct GNUNET_FS_Namespace *
-GNUNET_FS_namespace_create (struct GNUNET_FS_Handle *h, const char *name)
-{
- char *dn;
- char *fn;
- struct GNUNET_FS_Namespace *ret;
-
- dn = get_namespace_directory (h);
- GNUNET_asprintf (&fn, "%s%s%s", dn, DIR_SEPARATOR_STR, name);
- GNUNET_free (dn);
- ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Namespace));
- ret->h = h;
- ret->rc = 1;
- ret->key = GNUNET_CRYPTO_rsa_key_create_from_file (fn);
- if (NULL == ret->key)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to create or read private key for namespace `%s'\n"),
- name);
- GNUNET_free (ret);
- GNUNET_free (fn);
- return NULL;
- }
- ret->name = GNUNET_strdup (name);
- ret->filename = fn;
- return ret;
-}
-
-
-/**
- * Duplicate a namespace handle.
- *
- * @param ns namespace handle
- * @return duplicated handle to the namespace
- */
-struct GNUNET_FS_Namespace *
-GNUNET_FS_namespace_dup (struct GNUNET_FS_Namespace *ns)
-{
- ns->rc++;
- return ns;
-}
-
-
-/**
- * Delete a namespace handle. Can be used for a clean shutdown (free
- * memory) or also to freeze the namespace to prevent further
- * insertions by anyone.
- *
- * @param ns handle to the namespace that should be deleted / freed
- * @param freeze prevents future insertions; creating a namespace
- * with the same name again will create a fresh namespace instead
- *
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int
-GNUNET_FS_namespace_delete (struct GNUNET_FS_Namespace *ns, int freeze)
-{
- unsigned int i;
- struct NamespaceUpdateNode *nsn;
-
- ns->rc--;
- if (freeze)
- {
- if (0 != UNLINK (ns->filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "unlink",
- ns->filename);
- }
- if (0 != ns->rc)
- return GNUNET_OK;
- GNUNET_CRYPTO_rsa_key_free (ns->key);
- GNUNET_free (ns->filename);
- GNUNET_free (ns->name);
- for (i = 0; i < ns->update_node_count; i++)
- {
- nsn = ns->update_nodes[i];
- GNUNET_CONTAINER_meta_data_destroy (nsn->md);
- GNUNET_FS_uri_destroy (nsn->uri);
- GNUNET_free (nsn->id);
- GNUNET_free (nsn->update);
- GNUNET_free (nsn);
- }
- GNUNET_array_grow (ns->update_nodes, ns->update_node_count,
- 0);
- if (ns->update_map != NULL)
- GNUNET_CONTAINER_multihashmap_destroy (ns->update_map);
- GNUNET_free (ns);
- return GNUNET_OK;
-}
-
-
-/**
- * Context for the 'process_namespace' callback.
- * Specifies a function to call on each namespace.
- */
-struct ProcessNamespaceContext
-{
- /**
- * Function to call.
- */
- GNUNET_FS_NamespaceInfoProcessor cb;
-
- /**
- * Closure for 'cb'.
- */
- void *cb_cls;
-};
-
-
-/**
- * Function called with a filename of a namespace. Reads the key and
- * calls the callback.
- *
- * @param cls closure (struct ProcessNamespaceContext)
- * @param filename complete filename (absolute path)
- * @return GNUNET_OK to continue to iterate,
- * GNUNET_SYSERR to abort iteration with error!
- */
-static int
-process_namespace (void *cls, const char *filename)
-{
- struct ProcessNamespaceContext *pnc = cls;
- struct GNUNET_CRYPTO_RsaPrivateKey *key;
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk;
- struct GNUNET_HashCode id;
- const char *name;
- const char *t;
-
- key = GNUNET_CRYPTO_rsa_key_create_from_file (filename);
- if (NULL == key)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("Failed to read namespace private key file `%s', deleting it!\n"),
- filename);
- if (0 != UNLINK (filename))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", filename);
- return GNUNET_OK;
- }
- GNUNET_CRYPTO_rsa_key_get_public (key, &pk);
- GNUNET_CRYPTO_rsa_key_free (key);
- GNUNET_CRYPTO_hash (&pk, sizeof (pk), &id);
- name = filename;
- while (NULL != (t = strstr (name, DIR_SEPARATOR_STR)))
- name = t + 1;
- pnc->cb (pnc->cb_cls, name, &id);
- return GNUNET_OK;
-}
-
-
-/**
- * Build a list of all available local (!) namespaces The returned
- * names are only the nicknames since we only iterate over the local
- * namespaces.
- *
- * @param h handle to the file sharing subsystem
- * @param cb function to call on each known namespace
- * @param cb_cls closure for cb
- */
-void
-GNUNET_FS_namespace_list (struct GNUNET_FS_Handle *h,
- GNUNET_FS_NamespaceInfoProcessor cb, void *cb_cls)
-{
- char *dn;
- struct ProcessNamespaceContext ctx;
-
- dn = get_namespace_directory (h);
- if (NULL == dn)
- return;
- ctx.cb = cb;
- ctx.cb_cls = cb_cls;
- GNUNET_DISK_directory_scan (dn, &process_namespace, &ctx);
- GNUNET_free (dn);