- minor renamings
[oweals/gnunet.git] / src / env / env.c
index c977572abf0f4fa8359f828dac7151f49fb510a0..107be8827aff193f2f961c40f2a0a7a60c7ffe95 100644 (file)
@@ -18,7 +18,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
-/** 
+/**
  * @file env/env.c
  * @brief Library providing operations for the @e environment of
  *        PSYC and Social messages, and for (de)serializing variable values.
@@ -29,7 +29,7 @@
 #include "gnunet_util_lib.h"
 #include "gnunet_env_lib.h"
 
-/** 
+/**
  * Environment for a message.
  *
  * Contains modifiers.
@@ -42,9 +42,9 @@ struct GNUNET_ENV_Environment
 };
 
 
-/** 
+/**
  * Create an environment.
- * 
+ *
  * @return A newly allocated environment.
  */
 struct GNUNET_ENV_Environment *
@@ -54,7 +54,7 @@ GNUNET_ENV_environment_create ()
 }
 
 
-/** 
+/**
  * Add a modifier to the environment.
  *
  * @param env The environment.
@@ -64,11 +64,11 @@ GNUNET_ENV_environment_create ()
  * @param value_size Size of @a 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)
+GNUNET_ENV_environment_add (struct GNUNET_ENV_Environment *env,
+                            enum GNUNET_ENV_Operator oper, const char *name,
+                            const void *value, size_t value_size)
 {
-  struct GNUNET_ENV_Modifier *mod = GNUNET_malloc (sizeof (*mod));
+  struct GNUNET_ENV_Modifier *mod = GNUNET_new (struct GNUNET_ENV_Modifier);
   mod->oper = oper;
   mod->name = name;
   mod->value = value;
@@ -79,6 +79,67 @@ GNUNET_ENV_environment_add_mod (struct GNUNET_ENV_Environment *env,
 
 
 /** 
+ * Get the modifier at the beginning of an environment.
+ *
+ * @param env 
+ * @param oper 
+ * @param name 
+ * @param value 
+ * @param value_size 
+ * 
+ * @return 
+ */
+int
+GNUNET_ENV_environment_head (struct GNUNET_ENV_Environment *env,
+                              enum GNUNET_ENV_Operator *oper, const char **name,
+                              const void **value, size_t *value_size)
+{
+  if (NULL == env->mod_head)
+    return GNUNET_NO;
+
+  struct GNUNET_ENV_Modifier *mod = env->mod_head;
+  *oper = mod->oper;
+  *name = mod->name;
+  *value = mod->value;
+  *value_size = mod->value_size;
+  return GNUNET_YES;
+}
+
+
+/** 
+ * Get the modifier at the beginning of an environment and remove it.
+ *
+ * @param env 
+ * @param oper 
+ * @param name 
+ * @param value 
+ * @param value_size 
+ * 
+ * @return 
+ */
+int
+GNUNET_ENV_environment_shift (struct GNUNET_ENV_Environment *env,
+                              enum GNUNET_ENV_Operator *oper, const char **name,
+                              const void **value, size_t *value_size)
+{
+  if (NULL == env->mod_head)
+    return GNUNET_NO;
+
+  struct GNUNET_ENV_Modifier *mod = env->mod_head;
+  *oper = mod->oper;
+  *name = mod->name;
+  *value = mod->value;
+  *value_size = mod->value_size;
+
+  GNUNET_CONTAINER_DLL_remove (env->mod_head, env->mod_tail, mod);
+  GNUNET_free (mod);
+  env->mod_count--;
+
+  return GNUNET_YES;
+}
+
+
+/**
  * Iterate through all modifiers in the environment.
  *
  * @param env The environment.
@@ -91,11 +152,11 @@ GNUNET_ENV_environment_iterate (const struct GNUNET_ENV_Environment *env,
 {
   struct GNUNET_ENV_Modifier *mod;
   for (mod = env->mod_head; NULL != mod; mod = mod->next)
-    it (it_cls, mod);
+    it (it_cls, mod->oper, mod->name, mod->value, mod->value_size);
 }
 
 
-/** 
+/**
  * Get the number of modifiers in the environment.
  *
  * @param env The environment.
@@ -103,13 +164,13 @@ GNUNET_ENV_environment_iterate (const struct GNUNET_ENV_Environment *env,
  * @return Number of modifiers.
  */
 size_t
-GNUNET_ENV_environment_get_mod_count (const struct GNUNET_ENV_Environment *env)
+GNUNET_ENV_environment_get_count (const struct GNUNET_ENV_Environment *env)
 {
   return env->mod_count;
 }
 
 
-/** 
+/**
  * Destroy an environment.
  *
  * @param env The environment to destroy.