getting mysql to work
[oweals/gnunet.git] / src / fs / fs_uri.c
index 5c95f0e7a2269d32faa4b9ad05f4835bea78d351..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
-     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
@@ -361,7 +361,7 @@ uri_sks_parse (const char *s, char **emsg)
        (0 != strncmp (s, GNUNET_FS_URI_PREFIX GNUNET_FS_URI_SKS_INFIX, 
                      pos) ) )
     return NULL; /* not an SKS URI */
-  if ( (slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) + 1) ||
+  if ( (slen < pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) ||
        (s[pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] != '/') )
     {
       *emsg = GNUNET_strdup (_("Malformed SKS URI"));
@@ -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_CONFIGURATION_Handle *cfg,
+                         const struct GNUNET_CONFIGURATION_Handle *cfg,
                          struct GNUNET_TIME_Absolute expiration_time)
 {
   struct GNUNET_FS_Uri *uri;
@@ -881,6 +881,34 @@ GNUNET_FS_uri_loc_create (const struct GNUNET_FS_Uri *baseUri,
 }
 
 
+/**
+ * Create an SKS URI from a namespace and an identifier.
+ *
+ * @param ns namespace
+ * @param id identifier
+ * @param emsg where to store an error message
+ * @return an FS URI for the given namespace and identifier
+ */
+struct GNUNET_FS_Uri *
+GNUNET_FS_uri_sks_create (struct GNUNET_FS_Namespace *ns,
+                         const char *id,
+                         char **emsg)
+{
+  struct GNUNET_FS_Uri *ns_uri;
+  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk;
+             
+  ns_uri = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
+  ns_uri->type = sks;
+  GNUNET_CRYPTO_rsa_key_get_public (ns->key,
+                                   &pk);
+  GNUNET_CRYPTO_hash (&pk,
+                     sizeof (pk),
+                     &ns_uri->data.sks.namespace);
+  ns_uri->data.sks.identifier = GNUNET_strdup (id);
+  return ns_uri;
+}
+
+
 /**
  * Canonicalize a keyword.
  * 
@@ -899,7 +927,7 @@ canonicalize_keyword (const char *in)
   rpos = in;
   while ('\0' != *rpos)
     {
-      switch (tolower(*rpos))
+      switch (tolower( (unsigned char) *rpos))
        {
        case 'a':
        case 'e':
@@ -934,7 +962,7 @@ canonicalize_keyword (const char *in)
        case 'y':
        case 'z':
          /* convert characters listed above to lower case */
-         *wpos = tolower(*rpos);
+         *wpos = tolower( (unsigned char)*rpos);
          wpos++;
        case '!':
        case '.':
@@ -1004,6 +1032,12 @@ GNUNET_FS_uri_ksk_merge (const struct GNUNET_FS_Uri *u1,
   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) )
     {
@@ -1057,8 +1091,14 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
   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)
-        {
+        {        
           ret->data.ksk.keywords
             = GNUNET_malloc (ret->data.ksk.keywordCount * sizeof (char *));
           for (i = 0; i < ret->data.ksk.keywordCount; i++)
@@ -1121,7 +1161,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
   pos = searchString;
   while ('\0' != *pos)
     {
-      if ((saw_quote == 0) && (isspace (*pos)))
+      if ((saw_quote == 0) && (isspace ((unsigned char) *pos)))
         {
           inWord = 0;
         }
@@ -1152,7 +1192,7 @@ GNUNET_FS_uri_ksk_create (const char *keywords,
   pos = searchString;
   while ('\0' != *pos)
     {
-      if ((saw_quote == 0) && (isspace (*pos)))
+      if ((saw_quote == 0) && (isspace ( (unsigned char) *pos)))
         {
           inWord = 0;
           *pos = '\0';
@@ -1545,7 +1585,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
 static int
 needs_percent (char c)
 {
-  return (!((isalnum (c)) ||
+  return (!((isalnum ( (unsigned char) c)) ||
             (c == '-') || (c == '_') || (c == '.') || (c == '~')));
 }
 
@@ -1722,7 +1762,7 @@ bin2enc (const void *data, size_t size)
         }
     }
   if (hbits > 0)
-    ret[len++] = tbl[bits & 63];
+    ret[len] = tbl[bits & 63];
   return ret;
 }