#include "gnunet_bio_lib.h"
/**
- * FIXME
+ * Name of the directory which stores meta data for pseudonym
*/
-#define PS_METADATA_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonyms/metadata" DIR_SEPARATOR_STR
+#define PS_METADATA_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonyms" DIR_SEPARATOR_STR "metadata" DIR_SEPARATOR_STR
/**
- * FIXME
+ * Name of the directory which stores names for pseudonyms
*/
-#define PS_NAMES_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonyms/names" DIR_SEPARATOR_STR
+#define PS_NAMES_DIR DIR_SEPARATOR_STR "data" DIR_SEPARATOR_STR "pseudonyms" DIR_SEPARATOR_STR "names" DIR_SEPARATOR_STR
/**
- * FIXME
+ * Registered callbacks for discovery of pseudonyms.
*/
struct DiscoveryCallback
{
-
/**
- * FIXME
+ * This is a linked list.
*/
struct DiscoveryCallback *next;
/**
- * FIXME
+ * Function to call each time a pseudonym is discovered.
*/
GNUNET_PSEUDONYM_Iterator callback;
/**
- * FIXME
+ * Closure for callback.
*/
void *closure;
};
/**
- * FIXME
+ * Head of the linked list of functions to call when
+ * new pseudonyms are added.
*/
static struct DiscoveryCallback *head;
/**
* Internal notification about new tracked URI.
- *
- * FIXME
+ * @param id a point to the hash code of pseudonym
+ * @param md meta data to be written
+ * @param rating rating of pseudonym
*/
static void
internal_notify (const GNUNET_HashCode * id,
/**
* Register callback to be invoked whenever we discover
* a new pseudonym.
- *
- * FIXME
+ * @param cfg configuration to use
+ * @param iterator iterator over pseudonym
+ * @param closure point to a closure
*/
int
GNUNET_PSEUDONYM_discovery_callback_register (const struct
/**
* Unregister pseudonym discovery callback.
- *
- * FIXME
+ * @param iterator iterator over pseudonym
+ * @param closure point to a closure
*/
int
GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
/**
* Get the filename (or directory name) for the given
* pseudonym identifier and directory prefix.
- *
- * FIXME
+ * @param cfg configuration to use
+ * @param prefix path components to append to the private directory name
+ * @param psid hash code of pseudonym, can be NULL
+ * @return filename of the pseudonym (if psid != NULL) or directory with the data (if psid == NULL)
*/
static char *
get_data_filename (const struct GNUNET_CONFIGURATION_Handle
/**
- * FIXME
+ * Write the pseudonym infomation into a file
+ * @param cfg configuration to use
+ * @param nsid hash code of a pseudonym
+ * @param meta meta data to be written into a file
+ * @param ranking ranking of a pseudonym
+ * @param ns_name name of a pseudonym
*/
static void
write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
int32_t ranking, const char *ns_name)
{
char *fn;
+ struct GNUNET_BIO_WriteHandle *fileW;
fn = get_data_filename (cfg, PS_METADATA_DIR, nsid);
GNUNET_assert (fn != NULL);
- struct GNUNET_BIO_WriteHandle *fileW;
fileW = GNUNET_BIO_write_open(fn);
- GNUNET_assert (NULL != fileW);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int32(fileW, ranking));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string(fileW, ns_name));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data(fileW, meta));
- GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_close(fileW));
+ if (NULL != fileW)
+ {
+ if ( (GNUNET_OK != GNUNET_BIO_write_int32(fileW, ranking)) ||
+ (GNUNET_OK != GNUNET_BIO_write_string(fileW, ns_name)) ||
+ (GNUNET_OK != GNUNET_BIO_write_meta_data(fileW, meta)) )
+ {
+ (void) GNUNET_BIO_write_close(fileW);
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
+ GNUNET_free (fn);
+ return;
+ }
+ if (GNUNET_OK != GNUNET_BIO_write_close(fileW))
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
+ GNUNET_free (fn);
+ return;
+ }
+ }
GNUNET_free (fn);
/* create entry for pseudonym name in names */
+ /* FIXME: 90% of what this call does is not needed
+ here => refactor code to only create the entry! */
GNUNET_free_non_null (GNUNET_PSEUDONYM_id_to_name (cfg, nsid));
}
/**
- * FIXME
+ * read the pseudonym infomation from a file
+ * @param cfg configuration to use
+ * @param nsid hash code of a pseudonym
+ * @param meta meta data to be read from a file
+ * @param ranking ranking of a pseudonym
+ * @param ns_name name of a pseudonym
*/
static int
read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
{
char *fn;
char *emsg;
+ struct GNUNET_BIO_ReadHandle *fileR;
fn = get_data_filename (cfg, PS_METADATA_DIR, nsid);
GNUNET_assert (fn != NULL);
- struct GNUNET_BIO_ReadHandle *fileR;
fileR = GNUNET_BIO_read_open(fn);
- GNUNET_assert (NULL != fileR);
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int32__(fileR, "Read int32 error!", ranking));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_string(fileR, "Read string error!", ns_name, 200));
- GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_meta_data(fileR, "Read meta data error!", meta));
- GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_close(fileR, &emsg));
+ if (fileR == NULL)
+ {
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
+ if ( (GNUNET_OK != GNUNET_BIO_read_int32__(fileR, "Read int32 error!", ranking)) ||
+ (GNUNET_OK != GNUNET_BIO_read_string(fileR, "Read string error!", ns_name, 200)) ||
+ (GNUNET_OK != GNUNET_BIO_read_meta_data(fileR, "Read meta data error!", meta)) )
+ {
+ GNUNET_BIO_read_close(fileR, &emsg);
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
+ emsg = NULL;
+ if (GNUNET_OK != GNUNET_BIO_read_close(fileR, &emsg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to parse metadata about pseudonym from file `%s': %s\n"),
+ fn,
+ emsg);
+ GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
+ GNUNET_free_non_null (emsg);
+ GNUNET_free (fn);
+ return GNUNET_SYSERR;
+ }
GNUNET_free (fn);
return GNUNET_OK;
}
{
if ((meta != NULL) && (name == NULL))
name = GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
- EXTRACTOR_TITLE,
- EXTRACTOR_FILENAME,
- EXTRACTOR_DESCRIPTION,
- EXTRACTOR_SUBJECT,
- EXTRACTOR_PUBLISHER,
- EXTRACTOR_AUTHOR,
- EXTRACTOR_COMMENT,
- EXTRACTOR_SUMMARY,
- EXTRACTOR_OWNER,
+ EXTRACTOR_METATYPE_TITLE,
+ EXTRACTOR_METATYPE_FILENAME,
+ EXTRACTOR_METATYPE_DESCRIPTION,
+ EXTRACTOR_METATYPE_SUBJECT,
+ EXTRACTOR_METATYPE_PUBLISHER,
+ EXTRACTOR_METATYPE_AUTHOR_NAME,
+ EXTRACTOR_METATYPE_COMMENT,
+ EXTRACTOR_METATYPE_SUMMARY,
-1);
if (meta != NULL)
{
/**
- * FIXME
+ * struct used to list the pseudonym
*/
struct ListPseudonymClosure
{
/**
- * FIXME
+ * iterator over pseudonym
*/
GNUNET_PSEUDONYM_Iterator iterator;
/**
- * FIXME
+ * Closure for iterator.
*/
void *closure;
/**
- * FIXME
+ * Configuration to use.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
};
/**
- * FIXME
+ * the help function to list all available pseudonyms
+ * @param cls point to a struct ListPseudonymClosure
+ * @param fullname name of pseudonym
*/
static int
list_pseudonym_helper (void *cls, const char *fullname)
int rating;
struct GNUNET_CONTAINER_MetaData *meta;
const char *fn;
- const char *str = "not null";
+ char *str;
if (strlen (fullname) < sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))
return GNUNET_OK;
ret = GNUNET_OK;
if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (fn, &id))
return GNUNET_OK; /* invalid name */
+ str = NULL;
if (GNUNET_OK != read_info (c->cfg, &id, &meta, &rating, &str))
return GNUNET_OK; /* ignore entry */
+ GNUNET_free_non_null (str);
if (c->iterator != NULL)
ret = c->iterator (c->closure, &id, meta, rating);
GNUNET_CONTAINER_meta_data_destroy (meta);
return ret;
}
+
/**
* Change the ranking of a pseudonym.
*
return ranking;
}
+
/**
* Insert metadata into existing MD record (passed as cls).
*
* @param cls metadata to add to
+ * @param plugin_name name of the plugin that generated the meta data
* @param type type of entry to insert
- * @param data value of entry to insert
+ * @param format format of data
+ * @param data_mime_type mime type of data
+ * @param data value of the meta data
+ * @param data_len number of bytes in data
+ * @return always 0
*/
static int
-merge_meta_helper (void *cls, EXTRACTOR_KeywordType type, const char *data)
+merge_meta_helper (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)
{
struct GNUNET_CONTAINER_MetaData *meta = cls;
- GNUNET_CONTAINER_meta_data_insert (meta, type, data);
- return GNUNET_OK;
+
+ (void) GNUNET_CONTAINER_meta_data_insert (meta, plugin_name,
+ type, format,
+ data_mime_type,
+ data, data_len);
+ return 0;
}
if ((0 == STAT (fn, &sbuf)) &&
(GNUNET_OK == read_info (cfg, id, &old, &ranking, &name)))
{
- GNUNET_CONTAINER_meta_data_get_contents (meta, &merge_meta_helper, old);
+ GNUNET_CONTAINER_meta_data_iterate (meta, &merge_meta_helper, old);
write_pseudonym_info (cfg, id, old, ranking, name);
GNUNET_CONTAINER_meta_data_destroy (old);
GNUNET_free_non_null (name);
}
-
-
-
/* end of pseudonym.c */