-remove trailing whitespace
[oweals/gnunet.git] / src / include / gnunet_env_lib.h
index bde21eaacb10772438210135624baf7c189ee3b7..857ad45c245694e5b9a4cf1f77bbd2291eb10c19 100644 (file)
@@ -1,24 +1,24 @@
 /*
    This file is part of GNUnet.
    (C) 2013 Christian Grothoff (and other contributing authors)
-
    GNUnet is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published
    by the Free Software Foundation; either version 3, or (at your
    option) any later version.
-
    GNUnet is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.
-
    You should have received a copy of the GNU General Public License
    along with GNUnet; see the file COPYING.  If not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
-*/
-
-/** 
* This file is part of GNUnet.
* (C) 2013 Christian Grothoff (and other contributing authors)
+ *
* GNUnet is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 3, or (at your
* option) any later version.
+ *
* GNUnet is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
+ *
* You should have received a copy of the GNU General Public License
* along with GNUnet; see the file COPYING.  If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
+ */
+
+/**
  * @file include/gnunet_env_lib.h
  * @brief Library providing operations for the @e environment of
  *        PSYC and Social messages, and for (de)serializing variable values.
  */
 
 
-/** 
+#ifndef GNUNET_ENV_LIB_H
+#define GNUNET_ENV_LIB_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#if 0                           /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+
+/**
  * Possible operations on PSYC state (persistent) and transient variables (per message).
  */
 enum GNUNET_ENV_Operator
 {
-  /** 
+  /**
    * Set value of a transient variable.
    */
   GNUNET_ENV_OP_SET = ':',
 
-  /** 
+  /**
    * Assign value for a persistent state variable.
    *
    * If an assigned value is NULL, the variable is deleted.
-   * If the variable name that comes with thi operator is empty,
-   * it means a full state reset, the channel state is zeroed.
    */
   GNUNET_ENV_OP_ASSIGN = '=',
 
-  /** 
+  /**
    * Augment state variable.
    *
    * Used for appending strings, adding numbers, and adding new items to a list or dictionary.
    */
   GNUNET_ENV_OP_AUGMENT = '+',
 
-  /** 
+  /**
    * Diminish state variable.
    *
    * Used for subtracting numbers, and removing items from a list or dictionary.
    */
   GNUNET_ENV_OP_DIMINISH = '-',
 
-  /** 
+  /**
    * Update state variable.
    *
    * Used for modifying a single item of a list or dictionary.
@@ -68,7 +78,7 @@ enum GNUNET_ENV_Operator
 };
 
 
-/** 
+/**
  * PSYC variable types.
  */
 enum GNUNET_ENV_Type
@@ -80,33 +90,43 @@ enum GNUNET_ENV_Type
 };
 
 
-/** 
+/**
  * PSYC state modifier.
  */
 struct GNUNET_ENV_Modifier {
-  /** 
+  /**
    * State operation.
    */
-  GNUNET_ENV_Operator oper;
+  enum GNUNET_ENV_Operator oper;
 
-  /** 
+  /**
    * Variable name.
    */
   const char *name;
 
-  /** 
+  /**
    * Size of @a value.
    */
   size_t value_size;
 
-  /** 
+  /**
    * Value of variable.
    */
   const void *value;
+
+  /**
+   * Next modifier.
+   */
+  struct GNUNET_ENV_Modifier *next;
+
+  /**
+   * Previous modifier.
+   */
+  struct GNUNET_ENV_Modifier *prev;
 };
 
 
-/** 
+/**
  * Environment for a message.
  *
  * Contains modifiers.
@@ -114,65 +134,67 @@ struct GNUNET_ENV_Modifier {
 struct GNUNET_ENV_Environment;
 
 
-/** 
+/**
  * Create an environment.
- * 
+ *
  * @return A newly allocated environment.
  */
 struct GNUNET_ENV_Environment *
 GNUNET_ENV_environment_create ();
 
 
-/** 
- * Add an operation on a variable to the environment.
+/**
+ * Add a modifier to the environment.
  *
  * @param env The environment.
  * @param oper Operation to perform.
  * @param name Name of the variable.
- * @param value_size Size of @a value.
  * @param value Value of the variable.
- * 
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error.
+ * @param value_size Size of @a value.
  */
-int
-GNUNET_ENV_environment_operation (struct GNUNET_ENV_Environment *env,
-                                  enum GNUNET_ENV_Operator oper,
-                                  const char *name,
-                                  size_t value_size, const void *value);
+void
+GNUNET_ENV_environment_add_mod (struct GNUNET_ENV_Environment *env,
+                                enum GNUNET_ENV_Operator oper, const char *name,
+                                const void *value, size_t value_size);
 
 
-/** 
- * Get all modifiers in the environment.
+/**
+ * Iterator for modifiers in the environment.
+ *
+ * @param cls Closure.
+ * @param mod Modifier.
  *
- * FIXME: use an iterator instead, as we'll likely use a SList to store the
- *        modifiers in the environment.
+ * @return #GNUNET_YES to continue iterating,
+ *         #GNUNET_NO to stop.
+ */
+typedef int
+(*GNUNET_ENV_Iterator) (void *cls, struct GNUNET_ENV_Modifier *mod);
+
+
+/**
+ * Iterate through all modifiers in the environment.
  *
  * @param env The environment.
- * @param[out] modifier_count Set to the number of returned modifiers.
- * 
- * @return Array of modifiers.
+ * @param it Iterator.
+ * @param it_cls Closure for iterator.
  */
-const struct GNUNET_ENV_Modifier *
-GNUNET_ENV_environment_get_modifiers (const struct GNUNET_ENV_Environment *env,
-                                      size_t *modifier_count);
+void
+GNUNET_ENV_environment_iterate (const struct GNUNET_ENV_Environment *env,
+                                GNUNET_ENV_Iterator it, void *it_cls);
 
 
-/** 
- * Add list of modifiers to the environment.
+/**
+ * Get the number of modifiers in the environment.
  *
  * @param env The environment.
- * @param modifier_count Number of @a modifiers.
- * @param modifiers Array of modifiers to add.
- * 
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error.
+ *
+ * @return Number of modifiers.
  */
-int
-GNUNET_ENV_environment_set_modifiers (const struct GNUNET_ENV_Environment *env,
-                                      size_t modifier_count,
-                                      const struct GNUNET_ENV_Modifier *modifiers);
+size_t
+GNUNET_ENV_environment_get_mod_count (const struct GNUNET_ENV_Environment *env);
 
 
-/** 
+/**
  * Destroy an environment.
  *
  * @param env The environment to destroy.
@@ -181,18 +203,38 @@ void
 GNUNET_ENV_environment_destroy (struct GNUNET_ENV_Environment *env);
 
 
-/** 
+/**
  * Get the type of variable.
  *
  * @param name Name of the variable.
- * 
+ *
  * @return Variable type.
  */
 enum GNUNET_ENV_Type
 GNUNET_ENV_var_get_type (char *name);
 
 
-/** 
+/**
+ * Perform an operation on a variable.
+ *
+ * @param name Name of variable.
+ * @param current_value Current value of variable.
+ * @param current_value_size Size of @a current_value.
+ * @param oper Operator.
+ * @param args Arguments for the operation.
+ * @param args_size Size of @a args.
+ * @param return_value Return value.
+ * @param return_value_size Size of @a return_value.
+ *
+ * @return #GNUNET_OK on success, else #GNUNET_SYSERR
+ */
+int
+GNUNET_ENV_operation (char *name, void *current_value, size_t current_value_size,
+                      enum GNUNET_ENV_Operator oper, void *args, size_t args_size,
+                      void **return_value, size_t *return_value_size);
+
+
+/**
  * Get the variable's value as an integer.
  *
  * @param size Size of value.
@@ -205,7 +247,7 @@ int
 GNUNET_ENV_value_to_number (size_t size, const void *value, int64_t *number);
 
 
-/** 
+/**
  * Get the variable's value as a list.
  *
  * @param size Size of value.
@@ -215,10 +257,10 @@ GNUNET_ENV_value_to_number (size_t size, const void *value, int64_t *number);
  * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
  */
 int
-GNUNET_ENV_value_to_list (size_t size, const void *value, GNUNET_CONTAINER_SList **list);
+GNUNET_ENV_value_to_list (size_t size, const void *value, struct GNUNET_CONTAINER_SList **list);
 
 
-/** 
+/**
  * Get the variable's value as a dictionary.
  *
  * @param size Size of value.
@@ -228,40 +270,52 @@ GNUNET_ENV_value_to_list (size_t size, const void *value, GNUNET_CONTAINER_SList
  * @return #GNUNET_OK on success, #GNUNET_SYSERR if an error occurred (e.g. the value is invalid).
  */
 int
-GNUNET_ENV_value_to_dict (size_t size, const void *value, GNUNET_CONTAINER_MultiHashMap **dict);
+GNUNET_ENV_value_to_dict (size_t size, const void *value, struct GNUNET_CONTAINER_MultiHashMap **dict);
 
 
-/** 
+/**
  * Create a PSYC variable value from an integer.
  *
  * @param number The number to convert.
  * @param[out] value_size Size of returned value.
- * 
+ *
  * @return A newly allocated value or NULL on error.
  */
 void *
 GNUNET_ENV_value_from_number (int64_t number, size_t *value_size);
 
 
-/** 
+/**
  * Create a PSYC variable value from a list.
  *
  * @param list The list to convert.
  * @param[out] value_size Size of returned value.
- * 
+ *
  * @return A newly allocated value or NULL on error.
  */
 void *
-GNUNET_ENV_value_from_list (GNUNET_CONTAINER_SList *list, size_t *value_size);
+GNUNET_ENV_value_from_list (struct GNUNET_CONTAINER_SList *list, size_t *value_size);
 
 
-/** 
+/**
  * Create a PSYC variable value from a dictionary.
  *
  * @param dict The dict to convert.
  * @param[out] value_size Size of returned value.
- * 
+ *
  * @return A newly allocated value or NULL on error.
  */
 void *
-GNUNET_ENV_value_from_dict (GNUNET_CONTAINER_MultiHashMap *dict, size_t *value_size);
+GNUNET_ENV_value_from_dict (struct GNUNET_CONTAINER_MultiHashMap *dict, size_t *value_size);
+
+
+#if 0                           /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+/* ifndef GNUNET_ENV_LIB_H */
+#endif
+/* end of gnunet_env_lib.h */