Fixed compile warnings under windows
[oweals/gnunet.git] / src / util / pseudonym.c
index 85913d17811309dc3f54c2de87b359d2eab0fab1..6693dadd2e8b5c6ce724b3ec4374321065767d9d 100644 (file)
 #include "gnunet_bio_lib.h"
 
 /** 
- * the directory which stores meta data for pseudonym
+ * 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
 
 /** 
- * the directory which stores name for pseudonym
+ * 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
 
 
 /** 
- * link list struct DiscoveryCallback
+ * Registered callbacks for discovery of pseudonyms.
  */
 struct DiscoveryCallback
 {
   /** 
-   * the point which points address of the next DiscoveryCallback
+   * This is a linked list.
    */
   struct DiscoveryCallback *next;
 
   /** 
-   * Iterator over pseudonym
+   * Function to call each time a pseudonym is discovered.
    */
   GNUNET_PSEUDONYM_Iterator callback;
 
   /** 
-   * a point to closure
+   * Closure for callback.
    */
   void *closure;
 };
 
 
 /** 
- * declare a point to a static stuct DiscoveryCallback
+ * Head of the linked list of functions to call when 
+ * new pseudonyms are added.
  */
 static struct DiscoveryCallback *head;
 
@@ -150,7 +151,8 @@ GNUNET_PSEUDONYM_discovery_callback_unregister (GNUNET_PSEUDONYM_Iterator
  * pseudonym identifier and directory prefix.
  * @param cfg configuration to use
  * @param prefix path components to append to the private directory name
- * @param psid hash code of pseudonym
+ * @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
@@ -195,7 +197,7 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
           (GNUNET_OK != GNUNET_BIO_write_string(fileW, ns_name)) ||
           (GNUNET_OK != GNUNET_BIO_write_meta_data(fileW, meta)) )
        {
-         GNUNET_BIO_write_close(fileW);
+         (void) GNUNET_BIO_write_close(fileW);
          GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove (fn));
          GNUNET_free (fn);
          return;
@@ -209,6 +211,8 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
     }
   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));
 }
 
@@ -239,16 +243,17 @@ read_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
       GNUNET_free (fn);
       return GNUNET_SYSERR;
     }
-  if ( (GNUNET_OK != GNUNET_BIO_read_int32__(fileR, "Read int32 error!", ranking)) ||
+  emsg = NULL;
+  if ( (GNUNET_OK != GNUNET_BIO_read_int32 (fileR, 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_free_non_null (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,
@@ -296,15 +301,14 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
     {
       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)
         {
@@ -425,12 +429,12 @@ struct ListPseudonymClosure
   GNUNET_PSEUDONYM_Iterator iterator;
 
   /**
-   * point to closure
+   * Closure for iterator.
    */
   void *closure;
 
   /**
-   * cfg configuration to use
+   * Configuration to use.
    */
   const struct GNUNET_CONFIGURATION_Handle *cfg;
 };
@@ -501,6 +505,7 @@ GNUNET_PSEUDONYM_list_all (const struct GNUNET_CONFIGURATION_Handle *cfg,
   return ret;
 }
 
+
 /**
  * Change the ranking of a pseudonym.
  *
@@ -533,22 +538,6 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
   return ranking;
 }
 
-/**
- * Insert metadata into existing MD record (passed as cls).
- *
- * @param cls metadata to add to
- * @param type type of entry to insert
- * @param data value of entry to insert
- */
-static int
-merge_meta_helper (void *cls, EXTRACTOR_KeywordType type, const char *data)
-{
-  struct GNUNET_CONTAINER_MetaData *meta = cls;
-  GNUNET_CONTAINER_meta_data_insert (meta, type, data);
-  return GNUNET_OK;
-}
-
-
 
 /**
  * Add a pseudonym to the set of known pseudonyms.
@@ -577,7 +566,7 @@ GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
   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_merge (old, meta);
       write_pseudonym_info (cfg, id, old, ranking, name);
       GNUNET_CONTAINER_meta_data_destroy (old);
       GNUNET_free_non_null (name);
@@ -591,7 +580,4 @@ GNUNET_PSEUDONYM_add (const struct GNUNET_CONFIGURATION_Handle *cfg,
 }
 
 
-
-
-
 /* end of pseudonym.c */