-fixing 2352
[oweals/gnunet.git] / src / fs / fs_uri.c
index 157295b091f3e5e59f7b53d0b666494732eb2b81..0c2d64caca85186b4c5247e039e62ac935c994e1 100644 (file)
@@ -214,7 +214,7 @@ percent_decode_keyword (const char *in, char **emsg)
   {
     if (out[rpos] == '%')
     {
-      if (1 != sscanf (&out[rpos + 1], "%2X", &hx))
+      if (1 != SSCANF (&out[rpos + 1], "%2X", &hx))
       {
         GNUNET_free (out);
         *emsg = GNUNET_strdup (_("`%' must be followed by HEX number"));
@@ -1378,14 +1378,16 @@ GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
 {
   char *ret;
   char *name;
+  char *unique_name;
 
   if (uri->type != sks)
     return NULL;
-  name = GNUNET_PSEUDONYM_id_to_name (cfg, &uri->data.sks.namespace);
-  if (name == NULL)
-    return GNUNET_FS_uri_to_string (uri);
-  GNUNET_asprintf (&ret, "%s: %s", name, uri->data.sks.identifier);
+  (void) GNUNET_PSEUDONYM_get_info (cfg, &uri->data.sks.namespace,
+                                   NULL, NULL, &name, NULL);
+  unique_name = GNUNET_PSEUDONYM_name_uniquify (cfg, &uri->data.sks.namespace, name, NULL);
   GNUNET_free (name);
+  GNUNET_asprintf (&ret, "%s: %s", unique_name, uri->data.sks.identifier);
+  GNUNET_free (unique_name);
   return ret;
 }
 
@@ -1404,7 +1406,7 @@ GNUNET_FS_uri_test_ksk (const struct GNUNET_FS_Uri *uri)
 
   if (uri->type == ksk)
   {
-    for (i = uri->data.ksk.keywordCount - 1; i >= 0; i--)
+    for (i=0;i < uri->data.ksk.keywordCount; i++)
       GNUNET_assert (uri->data.ksk.keywords[i] != NULL);
   }
 #endif
@@ -1499,6 +1501,10 @@ find_duplicate (const char *s, const char **array, int array_length)
   return GNUNET_NO;
 }
 
+
+/**
+ * FIXME: comment
+ */
 static char *
 normalize_metadata (enum EXTRACTOR_MetaFormat format, const char *data,
     size_t data_len)
@@ -1541,6 +1547,23 @@ normalize_metadata (enum EXTRACTOR_MetaFormat format, const char *data,
   return (char *) normalized;
 }
 
+/**
+ * Counts the number of UTF-8 characters (not bytes) in the string,
+ * returns that count.
+ */
+static size_t
+u8_strcount (const uint8_t *s)
+{
+  size_t count;
+  ucs4_t c;
+  GNUNET_assert (s != NULL);
+  if (s[0] == 0)
+    return 0;
+  for (count = 0; s != NULL; count++)
+    s = u8_next (&c, s);
+  return count - 1;
+}
+
 
 /**
  * Break the filename up by matching [], () and {} pairs to make
@@ -1600,7 +1623,7 @@ get_keywords_from_parens (const char *s, char **array, int index)
       tmp = close_paren[0];
       close_paren[0] = '\0';
       /* Keywords must be at least 3 characters long */
-      if (u8_strlen ((const uint8_t *) &open_paren[1]) <= 2)
+      if (u8_strcount ((const uint8_t *) &open_paren[1]) <= 2)
       {
         close_paren[0] = tmp;
         continue;
@@ -1669,7 +1692,7 @@ get_keywords_from_tokens (const char *s, char **array, int index)
   for (p = strtok (ss, TOKENS); p != NULL; p = strtok (NULL, TOKENS))
   {
     /* Keywords must be at least 3 characters long */
-    if (u8_strlen ((const uint8_t *) p) <= 2)
+    if (u8_strcount ((const uint8_t *) p) <= 2)
       continue;
     if (NULL != array)
     {
@@ -1735,7 +1758,7 @@ gather_uri_data (void *cls, const char *plugin_name,
    * and will return the length of its valid part, skipping the keyword.
    * If it does - fix the extractor, not this check!
    */
-  if (u8_strlen ((const uint8_t *) data) <= 2)
+  if (u8_strcount ((const uint8_t *) data) <= 2)
   {
     return 0;
   }
@@ -1788,7 +1811,7 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
   if (ent > 0)
   {
     full_name = GNUNET_CONTAINER_meta_data_get_first_by_types (md,
-        EXTRACTOR_METATYPE_FILENAME, -1);
+        EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, -1);
     if (NULL != full_name)
     {
       filename = full_name;