doxygen fix
[oweals/gnunet.git] / src / fs / fs_uri.c
index f8bd76f5679c6b70dfd771473a47a485ee58a9c8..dc6d195caf44d1d32371a4c9d013a45adc27d6a3 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"));
@@ -1377,15 +1377,16 @@ GNUNET_FS_uri_sks_to_string_fancy (struct GNUNET_CONFIGURATION_Handle *cfg,
                                    const struct GNUNET_FS_Uri *uri)
 {
   char *ret;
-  char *name;
+  char *name, *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 +1405,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 +1500,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 +1546,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
@@ -1597,11 +1619,17 @@ get_keywords_from_parens (const char *s, char **array, int index)
     }
     if (match && (close_paren - open_paren > 1))
     {
+      tmp = close_paren[0];
+      close_paren[0] = '\0';
+      /* Keywords must be at least 3 characters long */
+      if (u8_strcount ((const uint8_t *) &open_paren[1]) <= 2)
+      {
+        close_paren[0] = tmp;
+        continue;
+      }
       if (NULL != array)
       {
         char *normalized;
-        tmp = close_paren[0];
-        close_paren[0] = '\0';
         if (GNUNET_NO == find_duplicate ((const char *) &open_paren[1],
             (const char **) array, index + count))
         {
@@ -1622,10 +1650,10 @@ get_keywords_from_parens (const char *s, char **array, int index)
           }
           GNUNET_free (normalized);
         }
-        close_paren[0] = tmp;
       }
       else
        count++;
+      close_paren[0] = tmp;
     }   
   }
   GNUNET_free (ss);
@@ -1662,6 +1690,9 @@ get_keywords_from_tokens (const char *s, char **array, int index)
   ss = GNUNET_strdup (s);
   for (p = strtok (ss, TOKENS); p != NULL; p = strtok (NULL, TOKENS))
   {
+    /* Keywords must be at least 3 characters long */
+    if (u8_strcount ((const uint8_t *) p) <= 2)
+      continue;
     if (NULL != array)
     {
       char *normalized;
@@ -1721,6 +1752,15 @@ gather_uri_data (void *cls, const char *plugin_name,
   if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
       (format != EXTRACTOR_METAFORMAT_C_STRING))
     return 0;
+  /* Keywords must be at least 3 characters long
+   * If given non-utf8 string it will, most likely, find it to be invalid,
+   * and will return the length of its valid part, skipping the keyword.
+   * If it does - fix the extractor, not this check!
+   */
+  if (u8_strcount ((const uint8_t *) data) <= 2)
+  {
+    return 0;
+  }
   normalized_data = normalize_metadata (format, data, data_len);
   if (!find_duplicate (data, (const char **) uri->data.ksk.keywords, uri->data.ksk.keywordCount))
   {
@@ -1770,7 +1810,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;