fix
[oweals/gnunet.git] / src / fs / fs_uri.c
index 16b6e26e980f082ad5b1762f13e30c09e4706613..f2c291784a5ce2c0f5c3e66e079783362e146c19 100644 (file)
@@ -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"));
@@ -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) )
     {
@@ -1050,6 +1084,8 @@ GNUNET_FS_uri_dup (const struct GNUNET_FS_Uri *uri)
   struct GNUNET_FS_Uri *ret;
   unsigned int i;
 
+  if (uri == NULL)
+    return NULL;
   ret = GNUNET_malloc (sizeof (struct GNUNET_FS_Uri));
   memcpy (ret, uri, sizeof (struct GNUNET_FS_Uri));
   switch (ret->type)
@@ -1119,7 +1155,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;
         }
@@ -1150,7 +1186,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';
@@ -1470,7 +1506,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri)
  *
  * @param cls URI to update
  * @param plugin_name name of the plugin that produced this value;
- *        special values can be used (i.e. '<zlib>' for zlib being
+ *        special values can be used (i.e. '&lt;zlib&gt;' for zlib being
  *        used in the main libextractor library and yielding
  *        meta data).
  * @param type libextractor-type describing the meta data
@@ -1543,7 +1579,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 == '~')));
 }
 
@@ -1720,7 +1756,7 @@ bin2enc (const void *data, size_t size)
         }
     }
   if (hbits > 0)
-    ret[len++] = tbl[bits & 63];
+    ret[len] = tbl[bits & 63];
   return ret;
 }