- fix block validation for DHT PUT requests
authorBart Polot <bart@net.in.tum.de>
Fri, 20 Sep 2013 14:40:31 +0000 (14:40 +0000)
committerBart Polot <bart@net.in.tum.de>
Fri, 20 Sep 2013 14:40:31 +0000 (14:40 +0000)
src/regex/plugin_block_regex.c
src/regex/regex_block_lib.c
src/regex/regex_internal_dht.c

index 5f3825f84d6fffc96bff9bfdfcfcc65a87cb5e84..4dda893c9642b4a002056039910bf92df9a6697f 100644 (file)
@@ -87,7 +87,7 @@ evaluate_block_regex (void *cls, enum GNUNET_BLOCK_Type type,
   }
   else if (NULL != query)
   {
-    /* xquery is required for regex, at least an empty string */
+    /* xquery is required for regex GETs, at least an empty string */
     GNUNET_break_op (0);
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "type %d, query %p, xquery %p\n",
                 type, query, xquery);
index b352082cbb6a6ad079fc8a703134987d19e1bb49..a2de3d4f8ba948948d8f4bbe1f23546173fde9ea 100644 (file)
@@ -211,6 +211,7 @@ REGEX_BLOCK_check (const struct RegexBlock *block,
   struct CheckEdgeContext ctx;
   int res;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Block check\n");
   if (GNUNET_OK != 
       REGEX_BLOCK_get_key (block, size,
                           &key))
@@ -218,16 +219,22 @@ REGEX_BLOCK_check (const struct RegexBlock *block,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  if (0 != memcmp (&key,
-                  query,
-                  sizeof (struct GNUNET_HashCode)))
+  if (NULL != query &&
+      0 != memcmp (&key,
+                   query,
+                   sizeof (struct GNUNET_HashCode)))
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
   if ( (GNUNET_YES == ntohs (block->is_accepting)) &&
        ( (NULL == xquery) || ('\0' == xquery[0]) ) )
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "  out! Is accepting: %u, xquery %p\n",
+       ntohs(block->is_accepting), xquery);
     return GNUNET_OK;
+  }
   ctx.xquery = xquery;
   ctx.found = GNUNET_NO;
   res = REGEX_BLOCK_iterate (block, size, &check_edge, &ctx);
@@ -235,6 +242,7 @@ REGEX_BLOCK_check (const struct RegexBlock *block,
     return GNUNET_SYSERR;
   if (NULL == xquery)
     return GNUNET_YES;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Result %d\n", ctx.found);
   return ctx.found;
 }
 
@@ -312,6 +320,7 @@ REGEX_BLOCK_iterate (const struct RegexBlock *block,
   unsigned int n;
   size_t off;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Block iterate\n");
   if (size < sizeof (struct RegexBlock)) 
   {
     GNUNET_break_op (0);
@@ -347,8 +356,9 @@ REGEX_BLOCK_iterate (const struct RegexBlock *block,
   for (n=0;n<num_edges;n++)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
-        "Edge %u, off %u tokenlen %u\n", n, off,
-        ntohs (edges[n].token_length));
+        " Edge %u/%u, off %u tokenlen %u (%.*s)\n", n+1, num_edges, off,
+        ntohs (edges[n].token_length), ntohs (edges[n].token_length),
+         &aux[off]);
     if (NULL != iterator)
       if (GNUNET_NO == iterator (iter_cls, 
                                 &aux[off], 
index 554d4320b9716d718e2f6cfa0d58f86f838a2775..56477220b454de965eb42547a79a7b6ca7dc42b6 100644 (file)
@@ -595,11 +595,12 @@ regex_next_edge (const struct RegexBlock *block,
   const char *rest;
   int result;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Next edge\n");
   /* Find the longest match for the current string position, 
    * among tokens in the given block */
   ctx->longest_match = 0;
   result = REGEX_BLOCK_iterate (block, size,
-                               &regex_edge_iterator, ctx);
+                                &regex_edge_iterator, ctx);
   GNUNET_break (GNUNET_OK == result);
 
   /* Did anything match? */