SHUTDOWN
[oweals/gnunet.git] / src / include / gnunet_container_lib.h
index 60403895513f2897f5255bb229821f81486af2a1..26579809dd6659ce33214410f4daa5d1bb3e31e4 100644 (file)
 #include "gnunet_crypto_lib.h"
 #include <extractor.h>
 
+#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
+/* hack for LE < 0.6.3 */
+#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
+#endif
+
 #ifdef __cplusplus
 extern "C"
 {
@@ -60,6 +65,7 @@ struct GNUNET_CONTAINER_BloomFilter;
 typedef int (*GNUNET_HashCodeIterator) (void *cls,
                                        GNUNET_HashCode * next);
 
+
 /**
  * Load a bloom-filter from a file.
  *
@@ -80,6 +86,7 @@ GNUNET_CONTAINER_bloomfilter_load (const
                                   int
                                   k);
 
+
 /**
  * Create a bloom filter from raw bits.
  *
@@ -103,6 +110,7 @@ GNUNET_CONTAINER_bloomfilter_init (const
                                   int
                                   k);
 
+
 /**
  * Copy the raw data of this bloomfilter into
  * the given data array.
@@ -111,20 +119,22 @@ GNUNET_CONTAINER_bloomfilter_init (const
  * @param size the size of the given data array
  * @return GNUNET_SYSERR if the data array of the wrong size
  */
-int GNUNET_CONTAINER_bloomfilter_get_raw_data (struct
+int GNUNET_CONTAINER_bloomfilter_get_raw_data (const struct
                                                GNUNET_CONTAINER_BloomFilter
                                                *bf, char *data,
                                                size_t size);
 
+
 /**
  * Test if an element is in the filter.
  * @param e the element
  * @param bf the filter
  * @return GNUNET_YES if the element is in the filter, GNUNET_NO if not
  */
-int GNUNET_CONTAINER_bloomfilter_test (struct GNUNET_CONTAINER_BloomFilter
+int GNUNET_CONTAINER_bloomfilter_test (const struct GNUNET_CONTAINER_BloomFilter
                                        *bf, const GNUNET_HashCode * e);
 
+
 /**
  * Add an element to the filter
  * @param bf the filter
@@ -133,6 +143,7 @@ int GNUNET_CONTAINER_bloomfilter_test (struct GNUNET_CONTAINER_BloomFilter
 void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter
                                        *bf, const GNUNET_HashCode * e);
 
+
 /**
  * Remove an element from the filter.
  * @param bf the filter
@@ -141,6 +152,18 @@ void GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter
 void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter
                                           *bf, const GNUNET_HashCode * e);
 
+
+/**
+ * Create a copy of a bloomfilter.
+ *
+ * @param bf the filter
+ * @return copy of bf
+ */
+struct GNUNET_CONTAINER_BloomFilter *
+GNUNET_CONTAINER_bloomfilter_copy (const struct GNUNET_CONTAINER_BloomFilter *bf);
+
+
+
 /**
  * Free the space associcated with a filter
  * in memory, flush to drive if needed (do not
@@ -150,6 +173,18 @@ void GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter
 void GNUNET_CONTAINER_bloomfilter_free (struct GNUNET_CONTAINER_BloomFilter
                                         *bf);
 
+
+/**
+ * Get size of the bloom filter.
+ *
+ * @param bf the filter
+ * @return number of bytes used for the data of the bloom filter
+ */
+size_t 
+GNUNET_CONTAINER_bloomfilter_get_size (const struct GNUNET_CONTAINER_BloomFilter
+                                      *bf);
+
+
 /**
  * Reset a bloom filter to empty.
  * @param bf the filter
@@ -171,6 +206,21 @@ void GNUNET_CONTAINER_bloomfilter_clear (struct GNUNET_CONTAINER_BloomFilter
 int GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
                                      const char *data, size_t size);
 
+/**
+ * Or the entries of the given raw data array with the
+ * data of the given bloom filter.  Assumes that
+ * the size of the data array and the current filter
+ * match.
+ *
+ * @param bf the filter
+ * @param to_or the bloomfilter to or-in
+ * @param size number of bytes in data
+ */
+int
+GNUNET_CONTAINER_bloomfilter_or2 (struct GNUNET_CONTAINER_BloomFilter *bf,
+                                  const struct GNUNET_CONTAINER_BloomFilter *to_or,
+                                  size_t size);
+
 /**
  * Resize a bloom filter.  Note that this operation
  * is pretty costly.  Essentially, the bloom filter
@@ -294,6 +344,15 @@ GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
                                   size_t data_len);
 
 
+/**
+ * Remove all items in the container.
+ *
+ * @param md metadata to manipulate
+ */
+void 
+GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
+
+
 /**
  * Add the current time as the publication date
  * to the meta-data.
@@ -365,21 +424,6 @@ GNUNET_CONTAINER_meta_data_get_thumbnail (const struct
                                          GNUNET_CONTAINER_MetaData
                                          *md, unsigned char **thumb);
 
-/**
- * Extract meta-data from a file.
- *
- * @param md metadata to set
- * @param filename name of file to inspect
- * @param extractors plugins to use
- * @return GNUNET_SYSERR on error, otherwise the number
- *   of meta-data items obtained
- */
-int 
-GNUNET_CONTAINER_meta_data_extract_from_file (struct
-                                             GNUNET_CONTAINER_MetaData
-                                             *md, const char *filename,
-                                             struct EXTRACTOR_PluginList *
-                                             extractors);
 
 
 /**
@@ -419,13 +463,14 @@ enum GNUNET_CONTAINER_MetaDataSerializationOptions
  *         -1 on error (typically: not enough
  *         space)
  */
-ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct
-                                             GNUNET_CONTAINER_MetaData *md,
-                                             char **target, 
-                                             size_t max,
-                                             enum
-                                          GNUNET_CONTAINER_MetaDataSerializationOptions
-                                          opt);
+ssize_t 
+GNUNET_CONTAINER_meta_data_serialize (const struct
+                                     GNUNET_CONTAINER_MetaData *md,
+                                     char **target, 
+                                     size_t max,
+                                     enum
+                                     GNUNET_CONTAINER_MetaDataSerializationOptions
+                                     opt);
 
 
 /**
@@ -434,9 +479,10 @@ ssize_t GNUNET_CONTAINER_meta_data_serialize (const struct
  * @param md metadata to inspect
  * @return number of bytes needed for serialization, -1 on error
  */
-ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
-                                                       GNUNET_CONTAINER_MetaData
-                                                       *md);
+ssize_t 
+GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
+                                               GNUNET_CONTAINER_MetaData
+                                               *md);
 
 
 /**
@@ -447,9 +493,9 @@ ssize_t GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
  * @return MD on success, NULL on error (i.e.
  *         bad format)
  */
-struct GNUNET_CONTAINER_MetaData
-  *GNUNET_CONTAINER_meta_data_deserialize (const char *input,
-                                           size_t size);
+struct GNUNET_CONTAINER_MetaData *
+GNUNET_CONTAINER_meta_data_deserialize (const char *input,
+                                       size_t size);
 
 
 /* ******************************* HashMap **************************** */
@@ -504,7 +550,7 @@ enum GNUNET_CONTAINER_MultiHashMapOption
  *         GNUNET_NO if not.
  */
 typedef int (*GNUNET_CONTAINER_HashMapIterator) (void *cls,
-                                                const GNUNET_HashCode * key,
+                                                 const GNUNET_HashCode * key,
                                                  void *value);
 
 
@@ -588,6 +634,23 @@ int GNUNET_CONTAINER_multihashmap_contains (const struct
                                             const GNUNET_HashCode * key);
 
 
+/**
+ * Check if the map contains the given value under the given
+ * key.
+ *
+ * @param map the map
+ * @param key the key to test if a value exists for it
+ * @param value value to test for
+ * @return GNUNET_YES if such a value exists,
+ *         GNUNET_NO if not
+ */
+int GNUNET_CONTAINER_multihashmap_contains_value (const struct
+                                                 GNUNET_CONTAINER_MultiHashMap
+                                                 *map,
+                                                 const GNUNET_HashCode * key,
+                                                 const void *value);
+
+
 /**
  * Store a key-value pair in the map.
  *
@@ -662,6 +725,8 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
  * @param element element to insert
  */
 #define GNUNET_CONTAINER_DLL_insert(head,tail,element) do { \
+  GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
+  GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
   (element)->next = (head); \
   (element)->prev = NULL; \
   if ((tail) == NULL) \
@@ -670,6 +735,27 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
     (head)->prev = element; \
   (head) = (element); } while (0)
 
+
+/**
+ * Insert an element at the tail of a DLL. Assumes that head, tail and
+ * element are structs with prev and next fields.
+ *
+ * @param head pointer to the head of the DLL
+ * @param tail pointer to the tail of the DLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_DLL_insert_tail(head,tail,element) do { \
+  GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
+  GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
+  (element)->prev = (tail); \
+  (element)->next = NULL; \
+  if ((head) == NULL) \
+    (head) = element; \
+  else \
+    (tail)->next = element; \
+  (tail) = (element); } while (0)
+
+
 /**
  * Insert an element into a DLL after the given other element.  Insert
  * at the head if the other element is NULL.
@@ -680,6 +766,8 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
  * @param element element to insert
  */
 #define GNUNET_CONTAINER_DLL_insert_after(head,tail,other,element) do { \
+  GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
+  GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
   (element)->prev = (other); \
   if (NULL == other) \
     { \
@@ -697,6 +785,33 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
     (element)->next->prev = (element); } while (0)
 
 
+/**
+ * Insert an element into a DLL before the given other element.  Insert
+ * at the tail if the other element is NULL.
+ *
+ * @param head pointer to the head of the DLL
+ * @param tail pointer to the tail of the DLL
+ * @param other prior element, NULL for insertion at head of DLL
+ * @param element element to insert
+ */
+#define GNUNET_CONTAINER_DLL_insert_before(head,tail,other,element) do { \
+  GNUNET_assert ( ( (element)->prev == NULL) && ((head) != (element))); \
+  GNUNET_assert ( ( (element)->next == NULL) && ((tail) != (element))); \
+  (element)->next = (other); \
+  if (NULL == other) \
+    { \
+      (element)->prev = (tail); \
+      (tail) = (element); \
+    } \
+  else \
+    { \
+      (element)->prev = (other)->prev; \
+      (other)->prev = (element); \
+    } \
+  if (NULL == (element)->prev) \
+    (head) = (element); \
+  else \
+    (element)->prev->next = (element); } while (0)
 
 
 /**
@@ -709,6 +824,8 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
  * @param element element to remove
  */
 #define GNUNET_CONTAINER_DLL_remove(head,tail,element) do { \
+  GNUNET_assert ( ( (element)->prev != NULL) || ((head) == (element))); \
+  GNUNET_assert ( ( (element)->next != NULL) || ((tail) == (element))); \
   if ((element)->prev == NULL) \
     (head) = (element)->next;  \
   else \
@@ -716,7 +833,9 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
   if ((element)->next == NULL) \
     (tail) = (element)->prev;  \
   else \
-    (element)->next->prev = (element)->prev; } while (0)
+    (element)->next->prev = (element)->prev; \
+  (element)->next = NULL; \
+  (element)->prev = NULL; } while (0)
 
 
 
@@ -799,6 +918,15 @@ unsigned int
 GNUNET_CONTAINER_heap_get_size (const struct GNUNET_CONTAINER_Heap *heap);
 
 
+/**
+ * Get the current cost of the node
+ *
+ * @param node the node to get the cost of
+ * @return cost of the node
+ */
+GNUNET_CONTAINER_HeapCostType
+GNUNET_CONTAINER_heap_node_get_cost (const struct GNUNET_CONTAINER_HeapNode *node);
+
 /**
  * Iterator for heap
  *
@@ -841,7 +969,9 @@ GNUNET_CONTAINER_heap_iterate (const struct GNUNET_CONTAINER_Heap *heap,
  *
  */
 void *
-GNUNET_CONTAINER_heap_get_random (struct GNUNET_CONTAINER_Heap *heap, uint32_t max);
+GNUNET_CONTAINER_heap_get_random (struct GNUNET_CONTAINER_Heap *heap, 
+                                 uint32_t max);
+
 
 /**
  * Perform a random walk of the tree.  The walk is biased
@@ -885,13 +1015,11 @@ GNUNET_CONTAINER_heap_remove_root (struct GNUNET_CONTAINER_Heap *heap);
 /**
  * Removes a node from the heap.
  * 
- * @param heap heap to modify
  * @param node node to remove
  * @return element data stored at the node, NULL if heap is empty
  */
 void *
-GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_Heap *heap,
-                                  struct GNUNET_CONTAINER_HeapNode *node);
+GNUNET_CONTAINER_heap_remove_node (struct GNUNET_CONTAINER_HeapNode *node);
 
 
 /**
@@ -956,6 +1084,18 @@ void GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
                                 const void *buf, size_t len);
 
 
+/**
+ * Add a new element to the end of the list
+ * @param l list
+ * @param disp memory disposition
+ * @param buf payload buffer
+ * @param len length of the buffer
+ */
+void GNUNET_CONTAINER_slist_add_end (struct GNUNET_CONTAINER_SList *l,
+                                enum GNUNET_CONTAINER_SListDisposition disp,
+                                const void *buf, size_t len);
+
+
 /**
  * Append a singly linked list to another
  * @param dst list to append to