add completion callback for overlay topology configure functions
[oweals/gnunet.git] / src / regex / regex.c
index 0a2671fa0f24e2c8fe492ab69d80c222fa948ba3..ad8e56b97e91007b744388efda3c5a607bd44f37 100644 (file)
@@ -20,8 +20,7 @@
 /**
  * @file src/regex/regex.c
  * @brief library to create Deterministic Finite Automatons (DFAs) from regular
- * expressions (regexes). Used by mesh for announcing regexes in the network and
- * matching strings against published regexes.
+ * expressions (regexes).
  * @author Maximilian Szengel
  */
 #include "platform.h"
@@ -3479,7 +3478,6 @@ GNUNET_REGEX_iterate_all_edges (struct GNUNET_REGEX_Automaton *a,
                         NULL, a->start, iterator, iterator_cls);
 }
 
-
 /**
  * Create a string with binary IP notation for the given 'addr' in 'str'.
  *
@@ -3493,37 +3491,37 @@ static void
 iptobinstr (const int af, const void *addr, char *str)
 {
   int i;
-
+  
   switch (af)
   {
-  case AF_INET:
-  {
-    uint32_t b = htonl (((struct in_addr *) addr)->s_addr);
-
-    str[32] = '\0';
-    str += 31;
-    for (i = 31; i >= 0; i--)
+    case AF_INET:
     {
-      *str = (b & 1) + '0';
-      str--;
-      b >>= 1;
+      uint32_t b = htonl (((struct in_addr *) addr)->s_addr);
+      
+      str[32] = '\0';
+          str += 31;
+          for (i = 31; i >= 0; i--)
+          {
+            *str = (b & 1) + '0';
+            str--;
+            b >>= 1;
+          }
+              break;
     }
-    break;
-  }
-  case AF_INET6:
-  {
-    struct in6_addr b = *(const struct in6_addr *) addr;
-
-    str[128] = '\0';
-    str += 127;
-    for (i = 127; i >= 0; i--)
+    case AF_INET6:
     {
-      *str = (b.s6_addr[i / 8] & 1) + '0';
-      str--;
-      b.s6_addr[i / 8] >>= 1;
+      struct in6_addr b = *(const struct in6_addr *) addr;
+      
+      str[128] = '\0';
+            str += 127;
+            for (i = 127; i >= 0; i--)
+            {
+              *str = (b.s6_addr[i / 8] & 1) + '0';
+            str--;
+            b.s6_addr[i / 8] >>= 1;
+            }
+                break;
     }
-    break;
-  }
   }
 }
 
@@ -3541,7 +3539,7 @@ ipv4netmasktoprefixlen (const char *netmask)
   struct in_addr a;
   unsigned int len;
   uint32_t t;
-
+  
   if (1 != inet_pton (AF_INET, netmask, &a))
     return 0;
   len = 32;
@@ -3564,12 +3562,12 @@ GNUNET_REGEX_ipv4toregex (const struct in_addr *ip, const char *netmask,
                           char *rxstr)
 {
   unsigned int pfxlen;
-
+  
   pfxlen = ipv4netmasktoprefixlen (netmask);
   iptobinstr (AF_INET, ip, rxstr);
   rxstr[pfxlen] = '\0';
-  if (pfxlen < 32)
-    strcat (rxstr, "(0|1)+");
+            if (pfxlen < 32)
+              strcat (rxstr, "(0|1)+");
 }
 
 
@@ -3587,136 +3585,9 @@ GNUNET_REGEX_ipv6toregex (const struct in6_addr *ipv6, unsigned int prefixlen,
 {
   iptobinstr (AF_INET6, ipv6, rxstr);
   rxstr[prefixlen] = '\0';
-  if (prefixlen < 128)
-    strcat (rxstr, "(0|1)+");
-}
-
-
-struct RegexCombineCtx {
-  struct RegexCombineCtx *next;
-  struct RegexCombineCtx *prev;
-
-  struct RegexCombineCtx *head;
-  struct RegexCombineCtx *tail;
-
-  char *s;
-};
-
-
-static char *
-regex_combine (struct RegexCombineCtx *ctx)
-{
-  struct RegexCombineCtx *p;
-  size_t len;
-  char *regex;
-  char *tmp;
-  char *s;
-
-  if (NULL != ctx->s)
-    GNUNET_asprintf (&regex, "%s(", ctx->s);
-  else
-    regex = GNUNET_strdup ("(");
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "prefix: %s\n", regex);
-
-  for (p = ctx->head; NULL != p; p = p->next)
-  {
-    s = regex_combine (p);
-    GNUNET_asprintf (&tmp, "%s%s|", regex, s);
-    GNUNET_free_non_null (s);
-    GNUNET_free_non_null (regex);
-    regex = tmp;
-  }
-  len = strlen (regex);
-  if (1 == len)
-    return GNUNET_strdup ("");
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "pre-partial: %s\n", regex);
-  if ('|' == regex[len - 1])
-    regex[len - 1] = ')';
-  if ('(' == regex[len - 1])
-    regex[len - 1] = '\0';
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "partial: %s\n", regex);
-  return regex;
-}
-
-static void
-regex_add (struct RegexCombineCtx *ctx, const char *regex)
-{
-  struct RegexCombineCtx *p;
-  const char *rest;
-
-  rest = &regex[1];
-  for (p = ctx->head; NULL != p; p = p->next)
-  {
-    if (p->s[0] == regex[0])
-    {
-      if (1 == strlen(p->s))
-      {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "common char %s\n", p->s);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "adding %s\n", rest);
-        regex_add (p, rest);
-      }
-      else
-      {
-        struct RegexCombineCtx *new;
-        new = GNUNET_malloc (sizeof (struct RegexCombineCtx));
-        new->s = GNUNET_strdup (&p->s[1]);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " p has now %s\n", p->s);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " p will have %.1s\n", p->s);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex is %s\n", regex);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " new has now %s\n", new->s);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " rest is now %s\n", rest);
-        p->s[1] = '\0'; /* dont realloc */
-        GNUNET_CONTAINER_DLL_insert (p->head, p->tail, new);
-        regex_add (p, rest);
-      }
-      return;
-    }
-  }
-  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);
-  p = GNUNET_malloc (sizeof (struct RegexCombineCtx));
-  p->s = GNUNET_strdup (regex);
-  GNUNET_CONTAINER_DLL_insert (ctx->head, ctx->tail, p);
+    if (prefixlen < 128)
+      strcat (rxstr, "(0|1)+");
 }
-/*
-static void
-debug (struct RegexCombineCtx *ctx, int lvl)
-{
-  struct RegexCombineCtx *p;
-  unsigned int i;
-
-  for (i = 0; i < lvl; i++) fprintf (stderr, " ");
-  fprintf (stderr, "%s\n", ctx->s);
-
-  for (p = ctx->head; NULL != p; p = p->next)
-  {
-    debug (p, lvl + 2);
-  }
-}*/
 
-char *
-GNUNET_REGEX_combine (char * const regexes[])
-{
-  unsigned int i;
-  char *combined;
-  const char *current;
-  struct RegexCombineCtx ctx;
-
-  memset (&ctx, 0, sizeof (struct RegexCombineCtx));
-  for (i = 0; regexes[i]; i++)
-  {
-    current = regexes[i];
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Regex %u: %s\n", i, current);
-    regex_add (&ctx, current);
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\nCombining...\n");
-
-  combined = regex_combine (&ctx);
-
-  return combined;
-}
 
 /* end of regex.c */