gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29562 - in gnunet: . src src/env src/include


From: gnunet
Subject: [GNUnet-SVN] r29562 - in gnunet: . src src/env src/include
Date: Wed, 25 Sep 2013 19:45:59 +0200

Author: tg
Date: 2013-09-25 19:45:59 +0200 (Wed, 25 Sep 2013)
New Revision: 29562

Added:
   gnunet/src/env/
   gnunet/src/env/Makefile.am
   gnunet/src/env/env.c
   gnunet/src/env/test_env.c
Modified:
   gnunet/configure.ac
   gnunet/src/Makefile.am
   gnunet/src/include/gnunet_env_lib.h
Log:
env lib

Modified: gnunet/configure.ac
===================================================================
--- gnunet/configure.ac 2013-09-25 17:45:55 UTC (rev 29561)
+++ gnunet/configure.ac 2013-09-25 17:45:59 UTC (rev 29562)
@@ -1305,6 +1305,7 @@
 src/dns/dns.conf
 src/dv/Makefile
 src/dv/dv.conf
+src/env/Makefile
 src/exit/Makefile
 src/experimentation/Makefile
 src/experimentation/experimentation.conf

Modified: gnunet/src/Makefile.am
===================================================================
--- gnunet/src/Makefile.am      2013-09-25 17:45:55 UTC (rev 29561)
+++ gnunet/src/Makefile.am      2013-09-25 17:45:59 UTC (rev 29562)
@@ -14,6 +14,7 @@
  EXP_DIR = \
   dv \
   multicast \
+  env \
   psyc \
   $(CONSENSUS) \
   $(EXPERIMENTATION)

Added: gnunet/src/env/Makefile.am
===================================================================
--- gnunet/src/env/Makefile.am                          (rev 0)
+++ gnunet/src/env/Makefile.am  2013-09-25 17:45:59 UTC (rev 29562)
@@ -0,0 +1,47 @@
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
+
+pkgcfgdir= $(pkgdatadir)/config.d/
+
+libexecdir= $(pkglibdir)/libexec/
+
+if MINGW
+ WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
+endif
+
+if USE_COVERAGE
+  AM_CFLAGS = --coverage -O0
+  XLIB = -lgcov
+endif
+
+lib_LTLIBRARIES = libgnunetenv.la
+
+libgnunetenv_la_SOURCES = \
+  env.c
+libgnunetenv_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(GN_LIBINTL) $(XLIB)
+libgnunetenv_la_LDFLAGS = \
+  $(GN_LIB_LDFLAGS)  $(WINFLAGS) \
+  -version-info 0:0:0
+libgnunetenv_la_DEPENDENCIES = \
+  $(top_builddir)/src/util/libgnunetutil.la
+
+if HAVE_TESTING
+check_PROGRAMS = \
+ test_env
+endif
+
+if ENABLE_TEST_RUN
+TESTS = $(check_PROGRAMS)
+endif
+
+test_env_SOURCES = \
+ test_env.c
+test_env_LDADD = \
+  libgnunetenv.la \
+  $(top_builddir)/src/testing/libgnunettesting.la \
+  $(top_builddir)/src/util/libgnunetutil.la
+test_env_DEPENDENCIES = \
+  libgnunetenv.la \
+  $(top_builddir)/src/testing/libgnunettesting.la \
+  $(top_builddir)/src/util/libgnunetutil.la

Added: gnunet/src/env/env.c
===================================================================
--- gnunet/src/env/env.c                                (rev 0)
+++ gnunet/src/env/env.c        2013-09-25 17:45:59 UTC (rev 29562)
@@ -0,0 +1,131 @@
+/*
+ * 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 env/env.c
+ * @brief Library providing operations for the @e environment of
+ *        PSYC and Social messages, and for (de)serializing variable values.
+ * @author Gabor X Toth
+ */
+
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_env_lib.h"
+
+/** 
+ * Environment for a message.
+ *
+ * Contains modifiers.
+ */
+struct GNUNET_ENV_Environment
+{
+  struct GNUNET_ENV_Modifier *mod_head;
+  struct GNUNET_ENV_Modifier *mod_tail;
+  size_t mod_count;
+};
+
+
+/** 
+ * Create an environment.
+ * 
+ * @return A newly allocated environment.
+ */
+struct GNUNET_ENV_Environment *
+GNUNET_ENV_environment_create ()
+{
+  return GNUNET_new (struct GNUNET_ENV_Environment);
+}
+
+
+/** 
+ * Add a modifier to the environment.
+ *
+ * @param env The environment.
+ * @param oper Operation to perform.
+ * @param name Name of the variable.
+ * @param value Value of the variable.
+ * @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)
+{
+  struct GNUNET_ENV_Modifier *mod = GNUNET_malloc (sizeof (*mod));
+  mod->oper = oper;
+  mod->name = name;
+  mod->value = value;
+  mod->value_size = value_size;
+  GNUNET_CONTAINER_DLL_insert_tail (env->mod_head, env->mod_tail, mod);
+  env->mod_count++;
+}
+
+
+/** 
+ * Iterate through all modifiers in the environment.
+ *
+ * @param env The environment.
+ * @param it Iterator.
+ * @param it_cls Closure for iterator.
+ */
+void
+GNUNET_ENV_environment_iterate (const struct GNUNET_ENV_Environment *env,
+                                GNUNET_ENV_Iterator it, void *it_cls)
+{
+  struct GNUNET_ENV_Modifier *mod;
+  for (mod = env->mod_head; NULL != mod; mod = mod->next)
+    it (it_cls, mod);
+}
+
+
+/** 
+ * Get the number of modifiers in the environment.
+ *
+ * @param env The environment.
+ *
+ * @return Number of modifiers.
+ */
+size_t
+GNUNET_ENV_environment_get_mod_count (const struct GNUNET_ENV_Environment *env)
+{
+  return env->mod_count;
+}
+
+
+/** 
+ * Destroy an environment.
+ *
+ * @param env The environment to destroy.
+ */
+void
+GNUNET_ENV_environment_destroy (struct GNUNET_ENV_Environment *env)
+{
+  struct GNUNET_ENV_Modifier *mod, *prev = NULL;
+  for (mod = env->mod_head; NULL != mod; mod = mod->next)
+  {
+    if (NULL != prev)
+      GNUNET_free (prev);
+    prev = mod;
+  }
+  if (NULL != prev)
+    GNUNET_free (prev);
+
+  GNUNET_free (env);
+}

Added: gnunet/src/env/test_env.c
===================================================================
--- gnunet/src/env/test_env.c                           (rev 0)
+++ gnunet/src/env/test_env.c   2013-09-25 17:45:59 UTC (rev 29562)
@@ -0,0 +1,85 @@
+/*
+ * 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 env/test_env.c
+ * @brief Tests for the environment library.
+ * @author Gabor X Toth
+ */
+
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_env_lib.h"
+
+struct GNUNET_ENV_Modifier mods[] = {
+  { .oper = GNUNET_ENV_OP_SET,
+    .name = "_foo", .value = "foo", .value_size = 3 },
+
+  { .oper = GNUNET_ENV_OP_ASSIGN,
+    .name = "_foo_bar", .value = "foo bar", .value_size = 7 },
+
+  { .oper = GNUNET_ENV_OP_AUGMENT,
+    .name = "_foo_bar_baz", .value = "foo bar baz", .value_size = 11 }
+};
+
+struct ItCls
+{
+  size_t n;
+};
+
+int
+iterator (void *cls, struct GNUNET_ENV_Modifier *mod)
+{
+  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));
+
+  return GNUNET_YES;
+}
+
+int
+main (int argc, char *argv[])
+{
+  GNUNET_log_setup ("test-env", "WARNING", NULL);
+
+  struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
+  GNUNET_assert (NULL != env);
+  int i, len = 3;
+
+  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);
+  }
+
+  struct ItCls it_cls = { .n = 0 };
+  GNUNET_ENV_environment_iterate (env, iterator, &it_cls);
+  GNUNET_assert (len == it_cls.n);
+
+  GNUNET_ENV_environment_destroy (env);
+
+  return 0;
+}

Modified: gnunet/src/include/gnunet_env_lib.h
===================================================================
--- gnunet/src/include/gnunet_env_lib.h 2013-09-25 17:45:55 UTC (rev 29561)
+++ gnunet/src/include/gnunet_env_lib.h 2013-09-25 17:45:59 UTC (rev 29562)
@@ -1,23 +1,23 @@
 /*
-     This file is part of GNUnet.
-     (C) 2013 Christian Grothoff (and other contributing authors)
+ * 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.
+ */
 
-     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
@@ -113,6 +113,16 @@
    * Value of variable.
    */
   const void *value;
+
+  /**
+   * Next modifier.
+   */
+  struct GNUNET_ENV_Modifier *next;
+
+  /**
+   * Previous modifier.
+   */
+  struct GNUNET_ENV_Modifier *prev;
 };
 
 
@@ -134,52 +144,54 @@
 
 
 /** 
- * 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 Value 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.
  */
-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.
  *
- * FIXME: use an iterator instead, as we'll likely use a SList to store the
- *        modifiers in the environment.
+ * @param cls Closure.
+ * @param mod Modifier.
  *
+ * @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);
 
 
 /** 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]