gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r24019 - gnunet/src/regex


From: gnunet
Subject: [GNUnet-SVN] r24019 - gnunet/src/regex
Date: Wed, 26 Sep 2012 16:46:32 +0200

Author: szengel
Date: 2012-09-26 16:46:32 +0200 (Wed, 26 Sep 2012)
New Revision: 24019

Modified:
   gnunet/src/regex/regex.c
   gnunet/src/regex/test_regex_iterate_api.c
Log:
fixes

Modified: gnunet/src/regex/regex.c
===================================================================
--- gnunet/src/regex/regex.c    2012-09-26 13:55:19 UTC (rev 24018)
+++ gnunet/src/regex/regex.c    2012-09-26 14:46:32 UTC (rev 24019)
@@ -2816,7 +2816,9 @@
   struct GNUNET_REGEX_Transition *t;
   unsigned int num_edges = state->transition_count;
   struct GNUNET_REGEX_Edge edges[num_edges];
+  struct GNUNET_REGEX_Edge edge[1];
   struct GNUNET_HashCode hash;
+  struct GNUNET_HashCode hash_new;
 
   unsigned int cur_len;
 
@@ -2825,9 +2827,8 @@
   else
     cur_len = 0;
 
-  if (cur_len > min_len && NULL != consumed_string)
+  if (cur_len >= min_len && cur_len > 0 && NULL != consumed_string)
   {
-
     if (cur_len <= max_len)
     {
       for (i = 0, t = state->transitions_head; NULL != t && i < num_edges;
@@ -2841,27 +2842,28 @@
       iterator (iterator_cls, &hash, consumed_string, state->accepting,
                 num_edges, edges);
 
-      // Special case for regex consisting of just a string that is shorter 
than max_len
+      // Special case for regex consisting of just a string that is shorter 
than
+      // max_len
       if (GNUNET_YES == state->accepting && cur_len > 1 &&
-          state->transition_count < 1)
+          state->transition_count < 1 && cur_len < max_len)
       {
-        edges[0].label = &consumed_string[cur_len - 1];
-        edges[0].destination = state->hash;
+        edge[0].label = &consumed_string[cur_len - 1];
+        edge[0].destination = state->hash;
         temp = GNUNET_strdup (consumed_string);
         temp[cur_len - 1] = '\0';
-        GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash);
-        iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edges);
+        GNUNET_CRYPTO_hash (temp, cur_len - 1, &hash_new);
+        iterator (iterator_cls, &hash_new, temp, GNUNET_NO, 1, edge);
         GNUNET_free (temp);
       }
     }
-    else
+    else if (max_len < cur_len)
     {
-      edges[0].label = &consumed_string[max_len];
-      edges[0].destination = state->hash;
+      edge[0].label = &consumed_string[max_len];
+      edge[0].destination = state->hash;
       temp = GNUNET_strdup (consumed_string);
       temp[max_len] = '\0';
       GNUNET_CRYPTO_hash (temp, max_len, &hash);
-      iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edges);
+      iterator (iterator_cls, &hash, temp, GNUNET_NO, 1, edge);
       GNUNET_free (temp);
     }
   }

Modified: gnunet/src/regex/test_regex_iterate_api.c
===================================================================
--- gnunet/src/regex/test_regex_iterate_api.c   2012-09-26 13:55:19 UTC (rev 
24018)
+++ gnunet/src/regex/test_regex_iterate_api.c   2012-09-26 14:46:32 UTC (rev 
24019)
@@ -85,15 +85,20 @@
       transition_counter++;
   }
 
-  GNUNET_free (state_id);
-
   for (i = 0; i < ctx->string_count; i++)
   {
     if (0 == strcmp (proof, ctx->strings[i]))
       ctx->match_count++;
   }
 
-  ctx->error += (GNUNET_OK == GNUNET_REGEX_check_proof (proof, key)) ? 0 : 1;
+  if (GNUNET_OK != GNUNET_REGEX_check_proof (proof, key))
+  {
+    ctx->error++;
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Proof check failed: proof: %s key: %s\n", proof, state_id);
+  }
+
+  GNUNET_free (state_id);
 }
 
 int
@@ -111,12 +116,12 @@
   struct GNUNET_REGEX_Automaton *dfa;
   unsigned int i;
   unsigned int num_transitions;
-  struct IteratorContext ctx = { 0, 0, NULL };
   char *filename = NULL;
+  struct IteratorContext ctx = { 0, 0, NULL, 0, NULL, 0 };
 
   error = 0;
 
-  const struct RegexStringPair rxstr[10] = {
+  const struct RegexStringPair rxstr[14] = {
     {"ab(c|d)+c*(a(b|c)+d)+(bla)+", 2, {"abcdcdca", "abcabdbl"}},
     {"abcdefghijklmnop*qst", 1, {"abcdefgh"}},
     {"VPN-4-1(0|1)*", 2, {"VPN-4-10", "VPN-4-11"}},
@@ -128,13 +133,17 @@
     {"xyz*", 2, {"xy", "xyz"}},
     {"ab", 1, {"a"}},
     
{"abcd:(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1):(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)(0|1)",
 2, {"abcd:000", "abcd:101"}},
-    {"x*|(0|1|2)(a|b|c|d)", 2, {"xxxxxxxx", "0a"}}
+    {"x*|(0|1|2)(a|b|c|d)", 2, {"xxxxxxxx", "0a"}},
+    {"(0|1)(0|1)23456789ABC", 1, {"11234567"}},
+    {"0*123456789ABC*", 3, {"00123456", "00000000", "12345678"}},
+    {"0123456789A*BC", 1, {"01234567"}},
+    {"GNUNETVPN000100000IPEX6-fc5a:4e1:c2ba::1", 1, {"GNUNETVP"}}
   };
 
   const char *graph_start_str = "digraph G {\nrankdir=LR\n";
   const char *graph_end_str = "\n}\n";
 
-  for (i = 0; i < 10; i++)
+  for (i = 0; i < 14; i++)
   {
     // Create graph
     if (GNUNET_YES == GNUNET_REGEX_ITERATE_SAVE_DEBUG_GRAPH)
@@ -158,6 +167,7 @@
     else
     {
       ctx.should_save_graph = GNUNET_NO;
+      ctx.graph_filep = NULL;
     }
 
     // Iterate over DFA edges
@@ -187,7 +197,7 @@
     else if (ctx.match_count > ctx.string_count)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Doublicate initial transitions for regex %s\n",
+                  "Duplicate initial transitions for regex %s\n",
                   rxstr[i].regex);
       error += (ctx.string_count - ctx.match_count);
     }
@@ -207,6 +217,10 @@
 
   for (i = 0; i < 10; i++)
   {
+    ctx.string_count = rxstr[i].string_count;
+    ctx.strings = rxstr[i].strings;
+    ctx.match_count = 0;
+
     dfa = GNUNET_REGEX_construct_dfa (rxstr[i].regex, strlen (rxstr[i].regex));
     GNUNET_REGEX_dfa_add_multi_strides (NULL, dfa, 2);
     GNUNET_REGEX_iterate_all_edges (dfa, key_iterator, &ctx);




reply via email to

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