[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r31791 - in gnunet/src: env include
From: |
gnunet |
Subject: |
[GNUnet-SVN] r31791 - in gnunet/src: env include |
Date: |
Mon, 6 Jan 2014 01:09:40 +0100 |
Author: tg
Date: 2014-01-06 01:09:40 +0100 (Mon, 06 Jan 2014)
New Revision: 31791
Modified:
gnunet/src/env/env.c
gnunet/src/env/test_env.c
gnunet/src/include/gnunet_env_lib.h
Log:
env: added head() and shift()
Modified: gnunet/src/env/env.c
===================================================================
--- gnunet/src/env/env.c 2014-01-06 00:09:37 UTC (rev 31790)
+++ gnunet/src/env/env.c 2014-01-06 00:09:40 UTC (rev 31791)
@@ -64,9 +64,9 @@
* @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_new (struct GNUNET_ENV_Modifier);
mod->oper = oper;
@@ -78,6 +78,67 @@
}
+/**
+ * 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.
*
@@ -91,7 +152,7 @@
{
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);
}
@@ -103,7 +164,7 @@
* @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;
}
Modified: gnunet/src/env/test_env.c
===================================================================
--- gnunet/src/env/test_env.c 2014-01-06 00:09:37 UTC (rev 31790)
+++ gnunet/src/env/test_env.c 2014-01-06 00:09:40 UTC (rev 31791)
@@ -46,15 +46,16 @@
};
int
-iterator (void *cls, struct GNUNET_ENV_Modifier *mod)
+iterator (void *cls, enum GNUNET_ENV_Operator oper,
+ const char *name, const char *value, uint32_t value_size)
{
struct ItCls *it_cls = cls;
struct GNUNET_ENV_Modifier *m = &mods[it_cls->n++];
- GNUNET_assert (mod->oper == m->oper);
- GNUNET_assert (mod->value_size == m->value_size);
- GNUNET_assert (0 == memcmp (mod->name, m->name, strlen (m->name)));
- GNUNET_assert (0 == memcmp (mod->value, m->value, m->value_size));
+ GNUNET_assert (oper == m->oper);
+ GNUNET_assert (value_size == m->value_size);
+ GNUNET_assert (0 == memcmp (name, m->name, strlen (m->name)));
+ GNUNET_assert (0 == memcmp (value, m->value, m->value_size));
return GNUNET_YES;
}
@@ -70,14 +71,24 @@
for (i = 0; i < len; i++)
{
- GNUNET_ENV_environment_add_mod (env, mods[i].oper, mods[i].name,
- mods[i].value, mods[i].value_size);
+ GNUNET_ENV_environment_add (env, mods[i].oper, mods[i].name,
+ mods[i].value, mods[i].value_size);
}
struct ItCls it_cls = { .n = 0 };
GNUNET_ENV_environment_iterate (env, iterator, &it_cls);
GNUNET_assert (len == it_cls.n);
+ for (i = 0; i < len; i++)
+ {
+ enum GNUNET_ENV_Operator oper;
+ const char *name;
+ const void *value;
+ size_t value_size;
+ GNUNET_ENV_environment_shift (env, &oper, &name, &value, &value_size);
+ GNUNET_assert (len - i - 1 == GNUNET_ENV_environment_get_count (env));
+ }
+
GNUNET_ENV_environment_destroy (env);
return 0;
Modified: gnunet/src/include/gnunet_env_lib.h
===================================================================
--- gnunet/src/include/gnunet_env_lib.h 2014-01-06 00:09:37 UTC (rev 31790)
+++ gnunet/src/include/gnunet_env_lib.h 2014-01-06 00:09:40 UTC (rev 31791)
@@ -153,12 +153,31 @@
* @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);
+
/**
+ * Remove a modifier at the beginning of the environment.
+ */
+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);
+
+
+/**
+ * Get the modifier at the beginning of the environment.
+ */
+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);
+
+
+/**
* Iterator for modifiers in the environment.
*
* @param cls Closure.
@@ -193,7 +212,7 @@
* @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);
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r31791 - in gnunet/src: env include,
gnunet <=