getting mysql to work
[oweals/gnunet.git] / src / fs / fs_uri.c
index 5ddb48f2a1a52dea1edafb825ad6497057bbf1ef..c844bdd3141e25d0085eb174b50f5b5f5bfe68b6 100644 (file)
@@ -4,7 +4,7 @@
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
 
      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 2, or (at your
+     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
      option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
@@ -830,7 +830,7 @@ GNUNET_FS_uri_loc_get_uri (const struct GNUNET_FS_Uri *uri)
  */
 struct GNUNET_FS_Uri *
 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
  */
 struct GNUNET_FS_Uri *
 GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
-                         struct GNUNET_CONFIGURATION_Handle *cfg,
+                         const struct GNUNET_CONFIGURATION_Handle *cfg,
                          struct GNUNET_TIME_Absolute expiration_time)
 {
   struct GNUNET_FS_Uri *uri;
                          struct GNUNET_TIME_Absolute expiration_time)
 {
   struct GNUNET_FS_Uri *uri;
@@ -927,7 +927,7 @@ canonicalize_keyword (const char *in)
   rpos = in;
   while ('\0' != *rpos)
     {
   rpos = in;
   while ('\0' != *rpos)
     {
-      switch (tolower(*rpos))
+      switch (tolower( (unsigned char) *rpos))
        {
        case 'a':
        case 'e':
        {
        case 'a':
        case 'e':
@@ -962,7 +962,7 @@ canonicalize_keyword (const char *in)
        case 'y':
        case 'z':
          /* convert characters listed above to lower case */
        case 'y':
        case 'z':
          /* convert characters listed above to lower case */
-         *wpos = tolower(*rpos);
+         *wpos = tolower( (unsigned char)*rpos);
          wpos++;
        case '!':
        case '.':
          wpos++;
        case '!':
        case '.':
@@ -1032,6 +1032,12 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
   const char *kp;
   char **kl;
 
   const char *kp;
   char **kl;
 
+  if ( (u1 == NULL) && (u2 == NULL) )
+    return NULL;
+  if (u1 == NULL)
+    return GNUNET_FS_uri_dup (u2);
+  if (u2 == NULL)
+    return GNUNET_FS_uri_dup (u1);
   if ( (u1->type != ksk) ||
        (u2->type != ksk) )
     {
   if ( (u1->type != ksk) ||
        (u2->type != ksk) )
     {
@@ -1085,8 +1091,14 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
   switch (ret->type)
     {
     case ksk:
   switch (ret->type)
     {
     case ksk:
+      if (ret->data.ksk.keywordCount >= GNUNET_MAX_MALLOC_CHECKED / sizeof (char*))
+       {
+         GNUNET_break (0);
+         GNUNET_free (ret);
+         return NULL;
+       }
       if (ret->data.ksk.keywordCount > 0)
       if (ret->data.ksk.keywordCount > 0)
-        {
+        {        
           ret->data.ksk.keywords
             = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
           for (i = 0; i < ret->data.ksk.keywordCount; i++)
           ret->data.ksk.keywords
             = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
           for (i = 0; i < ret->data.ksk.keywordCount; i++)
@@ -1149,7 +1161,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
   pos = searchString;
   while ('\0' != *pos)
     {
   pos = searchString;
   while ('\0' != *pos)
     {
-      if ((saw_quote == 0) && (isspace (*pos)))
+      if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
         {
           inWord = 0;
         }
         {
           inWord = 0;
         }
@@ -1180,7 +1192,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
   pos = searchString;
   while ('\0' != *pos)
     {
   pos = searchString;
   while ('\0' != *pos)
     {
-      if ((saw_quote == 0) && (isspace (*pos)))
+      if ((saw_quote == 0) && (isspace ( (unsigned char) *pos)))
         {
           inWord = 0;
           *pos = '\0';
         {
           inWord = 0;
           *pos = '\0';
@@ -1573,7 +1585,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
 static int
 needs_percent (char c)
 {
 static int
 needs_percent (char c)
 {
-  return (!((isalnum (c)) ||
+  return (!((isalnum ( (unsigned char) c)) ||
             (c == '-') || (c == '_') || (c == '.') || (c == '~')));
 }
 
             (c == '-') || (c == '_') || (c == '.') || (c == '~')));
 }
 
@@ -1750,7 +1762,7 @@ bin2enc (const void *data, size_t size)
         }
     }
   if (hbits > 0)
         }
     }
   if (hbits > 0)
-    ret[len++] = tbl[bits & 63];
+    ret[len] = tbl[bits & 63];
   return ret;
 }
 
   return ret;
 }