gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r29161 - gnunet-gtk/src/fs


From: gnunet
Subject: [GNUnet-SVN] r29161 - gnunet-gtk/src/fs
Date: Tue, 10 Sep 2013 14:26:30 +0200

Author: grothoff
Date: 2013-09-10 14:26:29 +0200 (Tue, 10 Sep 2013)
New Revision: 29161

Modified:
   gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
   gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.h
Log:
-handle embedded URIs -- sks and ksk and others -- nicely

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c     2013-09-10 12:18:07 UTC 
(rev 29160)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c     2013-09-10 12:26:29 UTC 
(rev 29161)
@@ -28,6 +28,7 @@
 #include "gnunet-fs-gtk_download-save-as.h"
 #include "gnunet-fs-gtk_event-handler.h"
 #include "gnunet-fs-gtk_unindex.h"
+#include "gnunet-fs-gtk_open-uri.h"
 
 
 /**
@@ -873,25 +874,28 @@
 
 
 /**
- * "Get root element of associated namespace X" was selected in the current 
search
- * context menu.
+ * "Get root element of associated namespace X" was selected in the
+ * current search context menu.  Handle the respective URI by
+ * displaying it in the search bar.
  *
  * @param item the menu item that was selected
- * @param user_data the 'struct SearchListPopupContext' of the menu
+ * @param user_data NULL
  */
 static void
-start_download_associated_ns_ctx_menu (GtkMenuItem *item, gpointer user_data)
+handle_uri_from_ctx_menu (GtkMenuItem *item, gpointer user_data)
 {
   struct GNUNET_FS_Uri *uri;
-  uri = g_object_get_data (G_OBJECT (item), "sks-uri");
+  char *uris;
 
+  uri = g_object_get_data (G_OBJECT (item), "fs-uri");
   if (NULL == uri)
     return;
-
-  /* start search */
-  GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (),
-                         uri, (uintptr_t) user_data,
-                          GNUNET_FS_SEARCH_OPTION_NONE, NULL);
+  uris = GNUNET_FS_uri_to_string (uri);
+  if (NULL == uris)
+    return;
+  GNUNET_break (GNUNET_OK ==
+               GNUNET_FS_GTK_handle_uri_string (uris, 1));
+  GNUNET_free (uris);
   /* GObject will clean up the URI */
 }
 
@@ -949,7 +953,7 @@
  * Copy current URI to clipboard was selected in the current context menu.
  * 
  * @param item the 'copy-to-clipboard' menu item
- * @param user_data the 'struct SearchListPopupContext' of the menu
+ * @param user_data the `struct SearchListPopupContext` of the menu
  */
 static void
 copy_search_uri_to_clipboard_ctx_menu (GtkMenuItem *item, gpointer user_data)
@@ -991,145 +995,164 @@
 
 
 /**
- * Called for each embedded sks. 
+ * Callback invoked for each embedded URIs. 
  *
  * @return #GNUNET_OK to continue iteration
  */
-typedef int (*EmbeddedSksCallback) (void *cls, 
-                                     const struct GNUNET_FS_Uri *sks_uri,
-                                     const char *sks_uri_string,
-                                     const struct GNUNET_CRYPTO_EccPublicKey 
*nsid);
+typedef int (*EmbeddedUriCallback) (void *cls, 
+                                   const struct GNUNET_FS_Uri *uri);
 
 
-struct sks_scanner_callback_context
+/**
+ * Closure for #check_for_embedded_uri.
+ */
+struct UriScannerCallbackContext
 {
-  EmbeddedSksCallback cb;
+  /**
+   * Function to call with URIs that were found.
+   */
+  EmbeddedUriCallback cb;
+
+  /**
+   * Closure for @e cb
+   */
   void *cls;
 };
 
 
 /**
- * Metadata callback. Checks metadata item for being an SKS URI,
+ * Metadata callback. Checks metadata item for being an FS URI,
  * invokes the callback if so.
  *
- * @param cls 
- * @param plugin_name 
- * @param type 
- * @param format 
- * @param data_mime_type 
- * @param data 
- * @param data_size 
+ * @param cls the `struct UriScannerCallbackContext`
+ * @param plugin_name name of the plugin that did the extraction (ignored)
+ * @param type type of meta data
+ * @param format format of the meta data
+ * @param data_mime_type mime type of the meta data
+ * @param data the meta data value
+ * @param data_size number of bytes in @a data
  * @return #GNUNET_OK if we did not invoke the callback, otherwise
  *         whatever the callback returned
  */
 static int
-check_for_embedded_sks (void *cls, 
+check_for_embedded_uri (void *cls, 
                        const char *plugin_name, 
                        enum EXTRACTOR_MetaType type,
                        enum EXTRACTOR_MetaFormat format,
                        const char *data_mime_type,
                        const char *data, size_t data_size)
 {
-  struct sks_scanner_callback_context *ctx = cls;
+  struct UriScannerCallbackContext *ctx = cls;
   int result;
+  char *emsg;
+  struct GNUNET_FS_Uri *uri;
 
-  result = GNUNET_OK;
-  if ((EXTRACTOR_METATYPE_URI == type) &&
-      (EXTRACTOR_METAFORMAT_UTF8 == format) &&
-      (data_mime_type && (0 == strcmp ("text/plain", data_mime_type))))
+  if ((EXTRACTOR_METATYPE_URI != type) ||
+      (EXTRACTOR_METAFORMAT_UTF8 != format) ||
+      (NULL == data_mime_type) ||
+      (0 != strcmp ("text/plain", data_mime_type)) ||
+      (0 == data_size) ||
+      ('\0' != data[data_size - 1]) )
+    return GNUNET_OK; 
+  emsg = NULL;
+  uri = GNUNET_FS_uri_parse (data, &emsg);
+  if (NULL == uri)
   {
-    struct GNUNET_FS_Uri *sks_uri;
-    char *emsg;
-
-    emsg = NULL;
-    sks_uri = GNUNET_FS_uri_parse (data, &emsg);
-    if (NULL != sks_uri)
-    {
-      if (GNUNET_FS_uri_test_sks (sks_uri))
-      {
-        char *id = GNUNET_FS_uri_sks_get_content_id (sks_uri);
-        if (NULL != id)
-        {
-          struct GNUNET_CRYPTO_EccPublicKey nsid;
-
-          if ((0 == strcmp (id, "/")) &&
-              (GNUNET_OK == GNUNET_FS_uri_sks_get_namespace (sks_uri, &nsid)))
-            result = ctx->cb (ctx->cls, sks_uri, data, &nsid);
-          GNUNET_free (id);
-        }
-      }
-      GNUNET_FS_uri_destroy (sks_uri);
-    }
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+               _("Failed to parse URI `%.*s': %s\n"),
+               (int) data_size,
+               data,
+               emsg);
     GNUNET_free_non_null (emsg);
+    return GNUNET_OK;
   }
+  result = ctx->cb (ctx->cls, uri);
+  GNUNET_FS_uri_destroy (uri);
   return result;
 }
 
 
 /**
- * Search metadata for SKS URIs, invoke the callback for each one.  
+ * Search metadata for URIs, invoke the callback for each one.  
  * 
- * @param meta 
- * @param cb 
- * @param cls 
+ * @param meta meta data to inspect
+ * @param cb function to call on URIs that were found
+ * @param cls closure for @a cb
  */
 static void
-find_embedded_sks (const struct GNUNET_CONTAINER_MetaData *meta, 
-                  EmbeddedSksCallback cb, void *cls)
+find_embedded_uris (const struct GNUNET_CONTAINER_MetaData *meta, 
+                   EmbeddedUriCallback cb, void *cls)
 {
-  struct sks_scanner_callback_context ctx;
+  struct UriScannerCallbackContext ctx;
 
   ctx.cb = cb;
   ctx.cls = cls;
   GNUNET_CONTAINER_meta_data_iterate (meta, 
-                                     &check_for_embedded_sks, &ctx);
+                                     &check_for_embedded_uri, &ctx);
 }
 
 
-struct SksPopulationContext
+/**
+ * Closure for #populate_popup_with_uri_items
+ */
+struct UriPopulationContext
 {
+  /**
+   * Popup menu we are populating.
+   */
   GtkMenu *menu;
+
+  /**
+   * Counter used to limit the number of entries we add.
+   */
   int counter;
-  uintptr_t anonymity_level;
+
 };
 
 
 /**
- * Called for every SKS URI in metadata. Adds up to 3 menu items
- * that will initiate downloads for these SKS URIs
+ * Called for every URI in metadata. Adds up to 3 menu items
+ * that will initiate downloads for these URIs
  * 
- * @param cls 
- * @param sks_uri 
- * @param sks_uri_string 
- * @param nsid 
- * 
- * @return 
+ * @param cls the `struct UriPopulationContext`
+ * @param uri URI to download
+ * @return #GNUNET_OK if we might add more iterms,
+ *         #GNUNET_SYSERR if we have reached the limit
  */
 static int
-populate_popup_with_sks_items (void *cls,
-                              const struct GNUNET_FS_Uri *sks_uri,
-                              const char *sks_uri_string, 
-                              const struct GNUNET_CRYPTO_EccPublicKey *nsid)
+populate_popup_with_uri_items (void *cls,
+                              const struct GNUNET_FS_Uri *uri)
 {
-  struct SksPopulationContext *ctx = cls;
+  struct UriPopulationContext *ctx = cls;
   GtkWidget *child;
   char *label;
   GtkWidget *ns_association_icon;
+  char *uris;
 
-  label = NULL;
-  ctx->counter += 1;
-  GNUNET_asprintf (&label, _("Get root element of associated namespace #%d"), 
ctx->counter);
+  ctx->counter++;
+  uris = GNUNET_FS_uri_to_string (uri);
+  GNUNET_asprintf (&label, 
+                  _("URI #%d: %s"),               
+                  ctx->counter,
+                  uris);
+  GNUNET_free (uris);
   child = gtk_image_menu_item_new_with_label (label);
   GNUNET_free (label);
 
-  ns_association_icon = gtk_image_new_from_icon_name 
("gnunet-fs-gtk-ns-association", GTK_ICON_SIZE_MENU);
+  ns_association_icon = gtk_image_new_from_icon_name 
("gnunet-fs-gtk-ns-association", 
+                                                     GTK_ICON_SIZE_MENU);
 
   /* Takes ownership of the icon */
-  gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (child), 
ns_association_icon);
+  gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (child), 
+                                ns_association_icon);
 
-  g_object_set_data_full (G_OBJECT (child), "sks-uri", GNUNET_FS_uri_dup 
(sks_uri), (GDestroyNotify) GNUNET_FS_uri_destroy);
+  g_object_set_data_full (G_OBJECT (child), 
+                         "fs-uri", 
+                         GNUNET_FS_uri_dup (uri), 
+                         (GDestroyNotify) &GNUNET_FS_uri_destroy);
   g_signal_connect (child, "activate",
-      G_CALLBACK (start_download_associated_ns_ctx_menu), (gpointer) 
ctx->anonymity_level);
+                   G_CALLBACK (handle_uri_from_ctx_menu), 
+                   NULL);
   gtk_widget_show (child);
   gtk_menu_shell_append (GTK_MENU_SHELL (ctx->menu), child);
 
@@ -1165,7 +1188,7 @@
   struct SearchListPopupContext *spc;
   struct GNUNET_CONTAINER_MetaData *meta;
   int is_directory = GNUNET_NO;
-  struct SksPopulationContext sks_pop_ctx;
+  struct UriPopulationContext uri_pop_ctx;
 
   spc = GNUNET_new (struct SearchListPopupContext);
   spc->tab = tab;
@@ -1223,14 +1246,13 @@
   gtk_widget_show (child);
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), child);
 
-  /* check for embedded SKS URIs */
-  sks_pop_ctx.counter = 0;
-  sks_pop_ctx.menu = menu;
-  /* TODO: make this configurable, or inherit it from the search? */
-  sks_pop_ctx.anonymity_level = 1;
-  find_embedded_sks (meta, populate_popup_with_sks_items,
-      &sks_pop_ctx);
-  if (0 < sks_pop_ctx.counter)
+  /* check for embedded URIs */
+  uri_pop_ctx.counter = 0;
+  uri_pop_ctx.menu = menu;
+  find_embedded_uris (meta, 
+                     &populate_popup_with_uri_items,
+                     &uri_pop_ctx);
+  if (0 < uri_pop_ctx.counter)
   {
     /* Insert another separator */
     child = gtk_separator_menu_item_new ();
@@ -2217,11 +2239,16 @@
 }
 
 
+/** 
+ * If called, sets the `gboolean` pointer in @a cls to TRUE.
+ * 
+ * @param cls pointer to a `gboolean`
+ * @param sks_uri a URI
+ * @return #GNUNET_SYSERR (abort iteration)
+ */
 static int
-see_if_there_are_any_sks_uris (void *cls,
-                              const struct GNUNET_FS_Uri *sks_uri,
-                              const char *sks_uri_string, 
-                              const struct GNUNET_CRYPTO_EccPublicKey *nsid)
+see_if_there_are_any_uris (void *cls,
+                          const struct GNUNET_FS_Uri *sks_uri)
 {
   gboolean *gb = cls;
 
@@ -2273,15 +2300,15 @@
   GtkTreeStore *ts;
   uint64_t fsize;
   int desc_is_a_dup;
-  gboolean show_ns_association;
+  gboolean show_uri_association;
 
-  show_ns_association = FALSE;
+  show_uri_association = FALSE;
   if (NULL == uri)
   {
     /* opened directory file */
     fsize = 0;
     status_colour = "gray";
-    mime = NULL; /* FIXME-FEATURE-MAYBE: should we set mime to directory? */
+    mime = GNUNET_strdup (GNUNET_FS_DIRECTORY_MIME);
     uris = GNUNET_strdup (_("no URI"));
   }
   else
@@ -2295,24 +2322,18 @@
     }
     else
     {
-      /* FIXME-FEATURE-MAYBE: create mime type for namespaces? */
-      /* FIXME-BUG-MAYBE: can we encounter ksk URIs here too? */
       fsize = 0;
-      mime = GNUNET_strdup ("GNUnet namespace"); 
+      mime = GNUNET_strdup ("gnunet/namespace"); 
       status_colour = "lightgreen";
-      /* FIXME: maybe do this? Would it confuse users?
-      show_ns_association = TRUE;
-      */
     }
     uris = GNUNET_FS_uri_to_string (uri);
   }
   desc = GNUNET_FS_GTK_get_description_from_metadata (meta, &desc_is_a_dup);
   pixbuf = GNUNET_FS_GTK_get_thumbnail_from_meta_data (meta);
+  find_embedded_uris (meta, 
+                     &see_if_there_are_any_uris,
+                     &show_uri_association);
 
-  find_embedded_sks (meta, 
-                    &see_if_there_are_any_sks_uris,
-                    &show_ns_association);
-
   sr = GNUNET_new (struct SearchResult);
   sr->result = result;
   if (NULL == result)
@@ -2325,7 +2346,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Allocated a search result SR=%p\n",
              sr);
-  if (parent_rr != NULL)
+  if (NULL != parent_rr)
   {
     /* get piter from parent */
     path = gtk_tree_row_reference_get_path (parent_rr);
@@ -2373,9 +2394,9 @@
                                      SEARCH_TAB_MC_COMPLETED, (guint64) 0,
                                      SEARCH_TAB_MC_DOWNLOADED_FILENAME, NULL,
                                      SEARCH_TAB_MC_DOWNLOADED_ANONYMITY, 
(guint) -1,
-                                     SEARCH_TAB_MC_SHOW_NS_ASSOCIATION, 
show_ns_association,
+                                     SEARCH_TAB_MC_SHOW_NS_ASSOCIATION, 
show_uri_association,
                                      -1);
-  if (pixbuf != NULL)
+  if (NULL != pixbuf)
     g_object_unref (pixbuf);
   GNUNET_free (uris);
   GNUNET_free (desc);
@@ -2388,7 +2409,7 @@
 
   /* move up to the outermost tab, in case this is an 'inner'
      search (namespace update case) */
-  while (tab->parent != NULL)
+  while (NULL != tab->parent)
     tab = tab->parent->tab;
   tab->num_results++;
   
@@ -2540,7 +2561,7 @@
     animation_searching_sources = load_animation ("searching_sources");
     animation_found_sources = load_animation ("found_source");
   }
-  tab = GNUNET_malloc (sizeof (struct SearchTab));
+  tab = GNUNET_new (struct SearchTab);
   GNUNET_CONTAINER_DLL_insert (search_tab_head, search_tab_tail, tab);
   tab->sc = sc;
   if (query == NULL)
@@ -3071,7 +3092,7 @@
   if (NULL == de)
   {
     /* no existing download entry to build on, create a fresh one */
-    de = GNUNET_malloc (sizeof (struct DownloadEntry));
+    de = GNUNET_new (struct DownloadEntry);
     de->uri = GNUNET_FS_uri_dup (uri);
   }
   else
@@ -3447,7 +3468,7 @@
   if (NULL == publish_tab)
   {
     /* create new tab */
-    publish_tab = GNUNET_malloc (sizeof (struct PublishTab));
+    publish_tab = GNUNET_new (struct PublishTab);
     publish_tab->builder =
       GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade",
                                  publish_tab);
@@ -3507,7 +3528,7 @@
     animation_published = load_animation ("published");
   }
   /* create entry and perform insertion */
-  ent = GNUNET_malloc (sizeof (struct PublishEntry));
+  ent = GNUNET_new (struct PublishEntry);
   ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO;
   ent->tab = publish_tab;
   ent->pc = pc;
@@ -3652,7 +3673,7 @@
     return FALSE;
   }
 
-  ppc = GNUNET_malloc (sizeof (struct PublishListPopupContext));
+  ppc = GNUNET_new (struct PublishListPopupContext);
   ppc->tab = tab;
   path = gtk_tree_model_get_path (tm, iter);
   ppc->rr = gtk_tree_row_reference_new (tm, path);

Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.h  2013-09-10 12:18:07 UTC (rev 
29160)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.h  2013-09-10 12:26:29 UTC (rev 
29161)
@@ -31,8 +31,9 @@
  *
  * @param uris string we got
  * @param anonymity_level anonymity level to use
- * @return GNUNET_OK on success, GNUNET_NO if the URI type is not supported, 
GNUNET_SYSERR if we failed to
- *         parse the URI
+ * @return #GNUNET_OK on success, 
+ *         #GNUNET_NO if the URI type is not supported, 
+ *         #GNUNET_SYSERR if we failed to parse the URI
  */
 int
 GNUNET_FS_GTK_handle_uri_string (const char *uris,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]