-improve UDP logging
[oweals/gnunet.git] / src / regex / regex_test_lib.c
index dbb864370429b8abb9dab997f152485aa8224ab1..bc4f78ba8c16c4fde4c1c462bb9a87551673087e 100644 (file)
@@ -1,17 +1,17 @@
 /*
  *  This file is part of GNUnet
- *  (C) 2012 Christian Grothoff (and other contributing authors)
- * 
+ *  Copyright (C) 2012 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,
@@ -21,7 +21,7 @@
  * @file src/regex/regex_test_lib.c
  * @brief library to read regexes representing IP networks from a file.
  *        and simplyfinying the into one big regex, in order to run
- *        tests (regex performance, mesh profiler).
+ *        tests (regex performance, cadet profiler).
  * @author Bartlomiej Polot
  */
 
@@ -130,7 +130,7 @@ regex_combine (struct RegexCombineCtx *ctx)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "empty, returning ''\n");
     GNUNET_free (regex);
-    return GNUNET_strdup (ctx->s);
+    return NULL == ctx->s ? NULL : GNUNET_strdup (ctx->s);
   }
 
   if ('|' == regex[len - 1])
@@ -153,10 +153,10 @@ regex_combine (struct RegexCombineCtx *ctx)
 
 /**
  * Get the number of matching characters on the prefix of both strings.
- * 
+ *
  * @param s1 String 1.
  * @param s2 String 2.
- * 
+ *
  * @return Number of characters of matching prefix.
  */
 static unsigned int
@@ -183,10 +183,10 @@ get_prefix_length (const char *s1, const char *s2)
 /**
  * Return the child context with the longest prefix match with the regex.
  * Usually only one child will match, search all just in case.
- * 
+ *
  * @param ctx Context whose children to search.
  * @param regex String to match.
- * 
+ *
  * @return Child with the longest prefix, NULL if no child matches.
  */
 static struct RegexCombineCtx *
@@ -245,7 +245,7 @@ regex_add (struct RegexCombineCtx *ctx, const char *regex)
     len = strlen (p->s);
     if (prefix_l < len) /* only partial match, split existing state */
     {
-      newctx = GNUNET_malloc (sizeof (struct RegexCombineCtx));
+      newctx = GNUNET_new (struct RegexCombineCtx);
       newctx->head = p->head;
       newctx->tail = p->tail;
       newctx->s = GNUNET_malloc(len - prefix_l + 1);
@@ -262,14 +262,14 @@ regex_add (struct RegexCombineCtx *ctx, const char *regex)
   if (NULL == ctx->head && NULL != ctx->s)
   {
     /* this was the end before, add empty string */
-    newctx = GNUNET_malloc (sizeof (struct RegexCombineCtx));
+    newctx = GNUNET_new (struct RegexCombineCtx);
     newctx->s = GNUNET_strdup ("");
     GNUNET_CONTAINER_DLL_insert (ctx->head, ctx->tail, newctx);
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " no match\n");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " new state %s\n", regex);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " under %s\n", ctx->s);
-  newctx = GNUNET_malloc (sizeof (struct RegexCombineCtx));
+  newctx = GNUNET_new (struct RegexCombineCtx);
   newctx->s = GNUNET_strdup (regex);
   GNUNET_CONTAINER_DLL_insert (ctx->head, ctx->tail, newctx);
 }
@@ -305,14 +305,14 @@ regex_ctx_destroy (struct RegexCombineCtx *ctx)
  *          This function DOES NOT support arbitrary regex combining.
  */
 char *
-REGEX_ITERNAL_combine (char * const regexes[])
+REGEX_TEST_combine (char * const regexes[])
 {
   unsigned int i;
   char *combined;
   const char *current;
   struct RegexCombineCtx *ctx;
 
-  ctx = GNUNET_malloc (sizeof (struct RegexCombineCtx));
+  ctx = GNUNET_new (struct RegexCombineCtx);
   for (i = 0; regexes[i]; i++)
   {
     current = regexes[i];
@@ -333,20 +333,20 @@ REGEX_ITERNAL_combine (char * const regexes[])
 
 /**
  * Read a set of regexes from a file, one per line and return them in an array
- * suitable for REGEX_ITERNAL_combine.
- * The array must be free'd using REGEX_ITERNAL_free_from_file.
+ * suitable for REGEX_TEST_combine.
+ * The array must be free'd using REGEX_TEST_free_from_file.
  *
  * @param filename Name of the file containing the regexes.
  *
  * @return A newly allocated, NULL terminated array of regexes.
  */
 char **
-REGEX_ITERNAL_read_from_file (const char *filename)
+REGEX_TEST_read_from_file (const char *filename)
 {
   struct GNUNET_DISK_FileHandle *f;
   unsigned int nr;
   unsigned int offset;
-  OFF_T size;
+  off_t size;
   size_t len;
   char *buffer;
   char *regex;
@@ -390,17 +390,7 @@ REGEX_ITERNAL_read_from_file (const char *filename)
     offset += len + 1;
     if (len < 1)
       continue;
-    if (len < 6 || strncmp (&regex[len - 6], "(0|1)*", 6) != 0)
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "%s (line %u) does not end in \"(0|1)*\"\n",
-                  buffer, nr);
-    }
-    else
-    {
-      len -= 6;
-      regex[len] = '\0';
-    }
+    regex[len] = '\0';
     regex = GNUNET_realloc (regex, len + 1);
     GNUNET_array_grow (regexes, nr, nr + 1);
     GNUNET_assert (NULL == regexes[nr - 2]);
@@ -421,7 +411,7 @@ REGEX_ITERNAL_read_from_file (const char *filename)
  * @param regexes NULL-terminated array of regexes.
  */
 void
-REGEX_ITERNAL_free_from_file (char **regexes)
+REGEX_TEST_free_from_file (char **regexes)
 {
   unsigned int i;