aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-09-05 16:36:00 +0000
committerChristian Grothoff <christian@grothoff.org>2013-09-05 16:36:00 +0000
commitb4b5aee70b665e97911adcda5c706a8e3811411a (patch)
tree059ed6c9064bd4c336cd89ccb793ed6c299ab6a0
parent28eb16f43c47a7ce9d15f5cbf632d8bcc0c6c763 (diff)
downloadgnunet-gtk-b4b5aee70b665e97911adcda5c706a8e3811411a.tar.gz
gnunet-gtk-b4b5aee70b665e97911adcda5c706a8e3811411a.zip
-towards fixing #1952 with GNS/FS integration
-rw-r--r--contrib/gnunet_fs_gtk_main_window.glade2
-rw-r--r--src/fs/Makefile.am3
-rw-r--r--src/fs/gnunet-fs-gtk.c102
-rw-r--r--src/fs/gnunet-fs-gtk.h95
-rw-r--r--src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c193
-rw-r--r--src/fs/gnunet-fs-gtk_main-window-search.c204
6 files changed, 356 insertions, 243 deletions
diff --git a/contrib/gnunet_fs_gtk_main_window.glade b/contrib/gnunet_fs_gtk_main_window.glade
index 58cde428..56499440 100644
--- a/contrib/gnunet_fs_gtk_main_window.glade
+++ b/contrib/gnunet_fs_gtk_main_window.glade
@@ -289,7 +289,6 @@
289 <property name="spacing">4</property> 289 <property name="spacing">4</property>
290 <child> 290 <child>
291 <object class="GtkLabel" id="main_window_search_namespace_label"> 291 <object class="GtkLabel" id="main_window_search_namespace_label">
292 <property name="visible">True</property>
293 <property name="can_focus">False</property> 292 <property name="can_focus">False</property>
294 <property name="label" translatable="yes">Namespace:</property> 293 <property name="label" translatable="yes">Namespace:</property>
295 </object> 294 </object>
@@ -301,7 +300,6 @@
301 </child> 300 </child>
302 <child> 301 <child>
303 <object class="GtkComboBox" id="main_window_search_namespace_combobox"> 302 <object class="GtkComboBox" id="main_window_search_namespace_combobox">
304 <property name="visible">True</property>
305 <property name="can_focus">False</property> 303 <property name="can_focus">False</property>
306 <property name="model">namespace_label_liststore</property> 304 <property name="model">namespace_label_liststore</property>
307 <property name="button_sensitivity">off</property> 305 <property name="button_sensitivity">off</property>
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index d17d5dd2..5d2bfab6 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -20,7 +20,6 @@ gnunet_fs_gtk_SOURCES = \
20 gnunet-fs-gtk_download-save-as.c gnunet-fs-gtk_download-save-as.h \ 20 gnunet-fs-gtk_download-save-as.c gnunet-fs-gtk_download-save-as.h \
21 gnunet-fs-gtk_event-handler.c gnunet-fs-gtk_event-handler.h \ 21 gnunet-fs-gtk_event-handler.c gnunet-fs-gtk_event-handler.h \
22 gnunet-fs-gtk_main-window-connection.c \ 22 gnunet-fs-gtk_main-window-connection.c \
23 gnunet-fs-gtk_main-window-meta-data-context-menu.c \
24 gnunet-fs-gtk_main-window-namespace-dropdown.c \ 23 gnunet-fs-gtk_main-window-namespace-dropdown.c \
25 gnunet-fs-gtk_main-window-search.c \ 24 gnunet-fs-gtk_main-window-search.c \
26 gnunet-fs-gtk_main-window-view-toggles.c \ 25 gnunet-fs-gtk_main-window-view-toggles.c \
@@ -38,6 +37,8 @@ gnunet_fs_gtk_LDADD = \
38 -lgnunetutil \ 37 -lgnunetutil \
39 -lgnunetarm \ 38 -lgnunetarm \
40 -lgnunetfs \ 39 -lgnunetfs \
40 -lgnunetgns \
41 -lgnunetnamestore \
41 -lgnunetidentity \ 42 -lgnunetidentity \
42 $(INTLLIBS) 43 $(INTLLIBS)
43gnunet_fs_gtk_LDFLAGS = \ 44gnunet_fs_gtk_LDFLAGS = \
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index a05486e8..ee64b05f 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -81,6 +81,7 @@ static struct GNUNET_GTK_MainWindowContext main_context;
81static UniqueApp *unique_app; 81static UniqueApp *unique_app;
82#endif 82#endif
83 83
84
84struct GNUNET_GTK_MainWindowContext * 85struct GNUNET_GTK_MainWindowContext *
85GNUNET_FS_GTK_get_main_context () 86GNUNET_FS_GTK_get_main_context ()
86{ 87{
@@ -230,6 +231,8 @@ GNUNET_GTK_main_window_configure_event_cb (GtkWidget *main_window,
230static void 231static void
231shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 232shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
232{ 233{
234 struct SearchLookup *sl;
235
233 GNUNET_GTK_tray_icon_destroy (); 236 GNUNET_GTK_tray_icon_destroy ();
234 if (fs != NULL) 237 if (fs != NULL)
235 { 238 {
@@ -248,8 +251,37 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
248 } 251 }
249 GNUNET_FS_GTK_close_uri_tab_ (); 252 GNUNET_FS_GTK_close_uri_tab_ ();
250 if (NULL != ml) 253 if (NULL != ml)
254 {
251 GNUNET_GTK_main_loop_quit (ml); 255 GNUNET_GTK_main_loop_quit (ml);
252 ml = NULL; 256 ml = NULL;
257 }
258 if (NULL != main_context.id_op)
259 {
260 GNUNET_IDENTITY_cancel (main_context.id_op);
261 main_context.id_op = NULL;
262 }
263 if (NULL != main_context.identity)
264 {
265 GNUNET_IDENTITY_disconnect (main_context.identity);
266 main_context.identity = NULL;
267 }
268 while (NULL != (sl = main_context.sl_head))
269 abort_search_lookup (sl);
270 if (NULL != main_context.zm)
271 {
272 GNUNET_NAMESTORE_zone_monitor_stop (main_context.zm);
273 main_context.zm = NULL;
274 }
275 if (NULL != main_context.gns)
276 {
277 GNUNET_GNS_disconnect (main_context.gns);
278 main_context.gns = NULL;
279 }
280 if (NULL != main_context.sks_zone)
281 {
282 GNUNET_free (main_context.sks_zone);
283 main_context.sks_zone = NULL;
284 }
253} 285}
254 286
255 287
@@ -408,6 +440,7 @@ unique_app_message_cb (UniqueApp *app,
408} 440}
409#endif 441#endif
410 442
443
411static char * 444static char *
412format_service_list (unsigned int count, const char *const*list) 445format_service_list (unsigned int count, const char *const*list)
413{ 446{
@@ -514,6 +547,67 @@ service_status_change (void *cls,
514 547
515 548
516/** 549/**
550 * Process a record that was stored in the namestore in the
551 * "sks_zone". Adds (or removes) the respective label to the
552 * drop-down menu for the SKS search by manipulating the
553 * "namespace_label_liststore".
554 *
555 * @param cls closure
556 * @param zone private key of the zone
557 * @param label label of the records
558 * @param rd_count number of entries in @a rd array
559 * @param rd array of records with data to store
560 */
561static void
562monitor_zone_records (void *cls,
563 const struct GNUNET_CRYPTO_EccPrivateKey *zone,
564 const char *label,
565 unsigned int rd_count,
566 const struct GNUNET_NAMESTORE_RecordData *rd)
567{
568 GNUNET_break (0); // not implemented
569}
570
571
572/**
573 * The identity service has given us the ego we should use for resolving
574 * namepace names.
575 *
576 * @param cls closure
577 * @param ego ego handle, NULL for none
578 * @param ctx context for application to store data for this ego
579 * (during the lifetime of this process, initially NULL)
580 * @param name name assigned by the user for this ego,
581 * NULL if the user just deleted the ego and it
582 * must thus no longer be used
583 */
584static void
585handle_sks_zone_identity (void *cls,
586 struct GNUNET_IDENTITY_Ego *ego,
587 void **ctx,
588 const char *name)
589{
590 main_context.id_op = NULL;
591
592 if (NULL == ego)
593 {
594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
595 _("No default ego specified for `fs-sks` service, will not enable namespace search.\n"));
596 return;
597 }
598 main_context.sks_zone = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
599 *main_context.sks_zone = *GNUNET_IDENTITY_ego_get_private_key (ego);
600 gtk_widget_show (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("main_window_search_namespace_label")));
601 gtk_widget_show (GTK_WIDGET (GNUNET_FS_GTK_get_main_window_object ("main_window_search_namespace_combobox")));
602 main_context.zm = GNUNET_NAMESTORE_zone_monitor_start (main_context.cfg,
603 main_context.sks_zone,
604 &monitor_zone_records,
605 NULL,
606 NULL);
607}
608
609
610/**
517 * Actual main function run right after GNUnet's scheduler 611 * Actual main function run right after GNUnet's scheduler
518 * is initialized. Initializes up GTK and Glade. 612 * is initialized. Initializes up GTK and Glade.
519 * 613 *
@@ -635,7 +729,11 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
635 } 729 }
636 arm = GNUNET_ARM_connect (main_context.cfg, &arm_connection_state_change, &main_context); 730 arm = GNUNET_ARM_connect (main_context.cfg, &arm_connection_state_change, &main_context);
637 armon = GNUNET_ARM_monitor (main_context.cfg, service_status_change, &main_context); 731 armon = GNUNET_ARM_monitor (main_context.cfg, service_status_change, &main_context);
638 732 main_context.identity = GNUNET_IDENTITY_connect (main_context.cfg, NULL, NULL);
733 main_context.id_op = GNUNET_IDENTITY_get (main_context.identity,
734 "fs-sks",
735 &handle_sks_zone_identity,
736 NULL);
639 GNUNET_GTK_main_window_refresh_ns_list (&main_context); 737 GNUNET_GTK_main_window_refresh_ns_list (&main_context);
640#if HAVE_LIBUNIQUE 738#if HAVE_LIBUNIQUE
641 unique_app_watch_window (unique_app, GTK_WINDOW (main_context.main_window)); 739 unique_app_watch_window (unique_app, GTK_WINDOW (main_context.main_window));
diff --git a/src/fs/gnunet-fs-gtk.h b/src/fs/gnunet-fs-gtk.h
index abf1844e..be54953a 100644
--- a/src/fs/gnunet-fs-gtk.h
+++ b/src/fs/gnunet-fs-gtk.h
@@ -28,10 +28,68 @@
28 28
29#include "gnunet_gtk.h" 29#include "gnunet_gtk.h"
30#include <gnunet/gnunet_fs_service.h> 30#include <gnunet/gnunet_fs_service.h>
31#include <gnunet/gnunet_gns_service.h>
32#include <gnunet/gnunet_identity_service.h>
33#include <gnunet/gnunet_namestore_service.h>
31#include <extractor.h> 34#include <extractor.h>
32 35
36
37/**
38 * Context for a GNS lookup for starting a search.
39 */
40struct SearchLookup
41{
42
43 /**
44 * This is a DLL.
45 */
46 struct SearchLookup *prev;
47
48 /**
49 * This is a DLL.
50 */
51 struct SearchLookup *next;
52
53 /**
54 * Our active request with GNS.
55 */
56 struct GNUNET_GNS_LookupRequest *gns;
57
58 /**
59 * Keywords to use.
60 */
61 gchar *keywords;
62
63 /**
64 * Task to trigger timeout.
65 */
66 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
67
68 /**
69 * Desired anonymity level.
70 */
71 guint anonymity_level;
72
73};
74
75
76/**
77 * Abort the given search lookup.
78 *
79 * @param sl lookup to abort.
80 */
81void
82abort_search_lookup (struct SearchLookup *sl);
83
84
85/**
86 * Context for the main window.
87 */
33struct GNUNET_GTK_MainWindowContext 88struct GNUNET_GTK_MainWindowContext
34{ 89{
90 /**
91 * Builder that loaded the main window.
92 */
35 GtkBuilder *builder; 93 GtkBuilder *builder;
36 94
37 const struct GNUNET_CONFIGURATION_Handle *cfg; 95 const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -72,6 +130,43 @@ struct GNUNET_GTK_MainWindowContext
72 GtkNotebook *notebook; 130 GtkNotebook *notebook;
73 131
74 GtkImage *connection_indicator; 132 GtkImage *connection_indicator;
133
134 /**
135 * Handle to the GNS service.
136 */
137 struct GNUNET_GNS_Handle *gns;
138
139 /**
140 * Handle to a zone monitor to update the namespace's drop-down list store.
141 * Monitors the @e sks_zone. Can be NULL.
142 */
143 struct GNUNET_NAMESTORE_ZoneMonitor *zm;
144
145 /**
146 * This is a DLL.
147 */
148 struct SearchLookup *sl_head;
149
150 /**
151 * This is a DLL.
152 */
153 struct SearchLookup *sl_tail;
154
155 /**
156 * Handle to identity service.
157 */
158 struct GNUNET_IDENTITY_Handle *identity;
159
160 /**
161 * Operation we use to determine namespace resolution domain.
162 */
163 struct GNUNET_IDENTITY_Operation *id_op;
164
165 /**
166 * Our zone for SKS operations. Can be NULL.
167 */
168 struct GNUNET_CRYPTO_EccPrivateKey *sks_zone;
169
75}; 170};
76 171
77 172
diff --git a/src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c b/src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c
deleted file mode 100644
index 06e58b67..00000000
--- a/src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c
+++ /dev/null
@@ -1,193 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/fs/gnunet-fs-gtk_main-window-meta-data-context-menu.c
23 * @brief context menu for the 'meta data' tree view in the main window
24 * @author Christian Grothoff
25 */
26#include "gnunet-fs-gtk.h"
27#include "gnunet-fs-gtk_download-save-as.h"
28#include "gnunet-fs-gtk_event-handler.h"
29#include <string.h>
30
31
32
33/**
34 * Helper function of GNUNET_GTK_FS_metadata_copy_selection_activated
35 * which copies the (selected) entries from the tree view to the
36 * GList.
37 *
38 * @param model the tree model with the data
39 * @param path unused
40 * @param iter position in the model to access
41 * @param user_data 'GList**' where we should store the types and values found
42 */
43static void
44copy_metadata_to_clipboard (GtkTreeModel * model, GtkTreePath * path,
45 GtkTreeIter * iter, gpointer user_data)
46{
47 GList **l = user_data;
48 gchar *type;
49 gchar *value;
50
51 gtk_tree_model_get (model, iter,
52 GNUNET_GTK_FS_MAIN_WINDOW_META_DATA_MC_META_TYPE_STRING,
53 &type,
54 GNUNET_GTK_FS_MAIN_WINDOW_META_DATA_MC_META_VALUE,
55 &value,
56 -1);
57 *l = g_list_prepend (*l, type);
58 *l = g_list_prepend (*l, value);
59}
60
61
62/**
63 * User activated metadata pop up menu "Copy selection" entry.
64 *
65 * @param menuitem the 'copy selection' menu item
66 * @param user_data the GtkBuilder of the main window
67 */
68void
69GNUNET_GTK_FS_metadata_copy_selection_activated (GtkMenuItem * menuitem,
70 gpointer user_data)
71{
72 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
73 GtkTreeView *tree;
74 GtkClipboard *cb;
75 GList *pairs;
76 GList *pos;
77 GList *value;
78 GList *type;
79 guint total_len;
80 gchar *s;
81 gchar *p;
82
83 tree = main_ctx->md_treeview;
84 pairs = NULL;
85 gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (tree),
86 &copy_metadata_to_clipboard, &pairs);
87 if (NULL == pairs)
88 return; /* nothing selected */
89 total_len = 0;
90 pairs = g_list_reverse (pairs);
91 for (pos = pairs; NULL != pos; pos = value->next)
92 {
93 type = pos;
94 value = pos->next;
95 GNUNET_assert (NULL != value);
96 total_len +=
97 strlen ((gchar *) type->data) + strlen ((gchar *) value->data) +
98 2 /* ": " */ + ((NULL != value->next) ? 1 : 0) /* "\n" */ ;
99 }
100 GNUNET_assert (total_len > 0);
101 total_len++; /* "\0" */
102 s = g_new0 (gchar, total_len);
103 if (NULL == s)
104 {
105 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
106 return;
107 }
108 p = s;
109 for (pos = pairs; NULL != pos; pos = value->next)
110 {
111 type = pos;
112 value = pos->next;
113 GNUNET_assert (NULL != value);
114 p = g_stpcpy (p, (gchar *) type->data);
115 p = g_stpcpy (p, ": ");
116 p = g_stpcpy (p, (gchar *) value->data);
117 if (NULL != value->next)
118 p = g_stpcpy (p, "\n");
119 }
120 g_list_foreach (pairs, (GFunc) &g_free, NULL);
121 g_list_free (pairs);
122 cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
123 gtk_clipboard_set_text (cb, s, -1);
124 gtk_clipboard_store (cb);
125 g_free (s);
126}
127
128
129/**
130 * Got asked to pop up the context menu in the metadata treeview in
131 * the main window. Do it.
132 *
133 * @param button which button caused the event (0 for none)
134 * @param event_time time of the event (current time or 'event->time')
135 * @param user_data the context of the main window
136 */
137static void
138do_metadata_popup_menu (int button,
139 int event_time,
140 gpointer user_data)
141{
142 GtkMenu *menu;
143 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
144
145 menu = GTK_MENU (gtk_builder_get_object (main_ctx->builder, "metadata_popup_menu"));
146 gtk_menu_popup (menu, NULL, NULL, NULL, main_ctx, button, event_time);
147}
148
149
150/**
151 * Got a button press event on the metadata treeview in the main window.
152 * If it was a right click, pop up the context menu.
153 *
154 * @param widget the tree view widget
155 * @param user_data the gtk builder of the main window
156 */
157gboolean
158GNUNET_GTK_main_window_metadata_treeview_button_press_event_cb (GtkWidget *
159 widget,
160 GdkEventButton *
161 event,
162 gpointer
163 user_data)
164{
165 /* Ignore double-clicks and triple-clicks */
166 if ( (event->button != 3) || (event->type != GDK_BUTTON_PRESS) )
167 return FALSE;
168 do_metadata_popup_menu (event->button,
169 event->time,
170 user_data);
171 return FALSE;
172}
173
174
175/**
176 * Metadata treeview in the main window got the 'popup-menu' signal.
177 * Pop up the menu.
178 *
179 * @param widget the tree view widget
180 * @param user_data the gtk builder of the main window
181 * @return TRUE we did it
182 */
183gboolean
184GNUNET_GTK_main_window_metadata_treeview_popup_menu_cb (GtkWidget * widget,
185 gpointer user_data)
186{
187 do_metadata_popup_menu (0 /* no button */,
188 gtk_get_current_event_time (),
189 user_data);
190 return TRUE;
191}
192
193/* end of gnunet-fs-gtk_meta-data-context-menu.c */
diff --git a/src/fs/gnunet-fs-gtk_main-window-search.c b/src/fs/gnunet-fs-gtk_main-window-search.c
index 6b621a1a..3296151d 100644
--- a/src/fs/gnunet-fs-gtk_main-window-search.c
+++ b/src/fs/gnunet-fs-gtk_main-window-search.c
@@ -29,9 +29,120 @@
29 29
30 30
31/** 31/**
32 * How long until we decide a SKS namespace GNS lookup has failed?
33 */
34#define LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
35
36/**
32 * Start a search. 37 * Start a search.
33 * 38 *
34 * @param builder the main window context 39 * @param uri uri to search for, freed in this function
40 * @param anonymity_level degree of anonymity to apply for the search
41 */
42static void
43search_for_uri (struct GNUNET_FS_Uri *uri,
44 guint anonymity_level)
45{
46 /* start search */
47 GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (),
48 uri, anonymity_level,
49 GNUNET_FS_SEARCH_OPTION_NONE, NULL);
50 GNUNET_FS_uri_destroy (uri);
51}
52
53
54
55
56/**
57 * Abort the given search lookup.
58 *
59 * @param sl lookup to abort.
60 */
61void
62abort_search_lookup (struct SearchLookup *sl)
63{
64 struct GNUNET_GTK_MainWindowContext *main_ctx = GNUNET_FS_GTK_get_main_context ();
65
66 GNUNET_CONTAINER_DLL_remove (main_ctx->sl_head,
67 main_ctx->sl_tail,
68 sl);
69 if (GNUNET_SCHEDULER_NO_TASK != sl->timeout_task)
70 {
71 GNUNET_SCHEDULER_cancel (sl->timeout_task);
72 sl->timeout_task = GNUNET_SCHEDULER_NO_TASK;
73 }
74 if (NULL != sl->gns)
75 {
76 GNUNET_GNS_lookup_cancel (sl->gns);
77 sl->gns = NULL;
78 }
79 g_free (sl->keywords);
80 GNUNET_free (sl);
81}
82
83
84/**
85 * Task run when the GNS timeout during the resolution of
86 * the GNS namespace times out.
87 *
88 * @param cls the 'struct SearchLookup'
89 * @param tc scheduler context
90 */
91static void
92timeout_search_lookup (void *cls,
93 const struct GNUNET_SCHEDULER_TaskContext *tc)
94{
95 struct SearchLookup *sl = cls;
96
97 sl->timeout_task = GNUNET_SCHEDULER_NO_TASK;
98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
99 _("Failed to resolve namespace in time\n"));
100 abort_search_lookup (sl);
101}
102
103
104
105/**
106 * Iterator called on obtained result for a GNS lookup for
107 * the public key of a namespace identifier.
108 *
109 * @param cls closure
110 * @param rd_count number of records in @a rd
111 * @param rd the records in reply
112 */
113static void
114handle_gns_result (void *cls,
115 uint32_t rd_count,
116 const struct GNUNET_NAMESTORE_RecordData *rd)
117{
118 struct SearchLookup *sl = cls;
119 unsigned int i;
120 struct GNUNET_FS_Uri *uri;
121
122 sl->gns = NULL;
123 for (i=0;i<rd_count;i++)
124 {
125 if (GNUNET_NAMESTORE_TYPE_PKEY != rd[i].record_type)
126 continue;
127 if (sizeof (struct GNUNET_CRYPTO_EccPublicKey) != rd[i].data_size)
128 {
129 GNUNET_break_op (0);
130 continue;
131 }
132 uri = GNUNET_FS_uri_sks_create (rd[i].data, sl->keywords);
133 search_for_uri (uri, sl->anonymity_level);
134 abort_search_lookup (sl);
135 return;
136 }
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
138 _("Failed to resolve namespace in time\n"));
139 abort_search_lookup (sl);
140}
141
142/**
143 * Start a search.
144 *
145 * @param main_ctx the main window context
35 */ 146 */
36static void 147static void
37start_search (struct GNUNET_GTK_MainWindowContext *main_ctx) 148start_search (struct GNUNET_GTK_MainWindowContext *main_ctx)
@@ -39,8 +150,11 @@ start_search (struct GNUNET_GTK_MainWindowContext *main_ctx)
39 guint anonymity_level; 150 guint anonymity_level;
40 gchar *keywords; 151 gchar *keywords;
41 gchar *mime_keyword; 152 gchar *mime_keyword;
42 struct GNUNET_CRYPTO_EccPublicKey *nsid; 153 const char *nsid;
43 struct GNUNET_FS_Uri *uri; 154 struct GNUNET_FS_Uri *uri;
155 struct GNUNET_CRYPTO_EccPublicKey pub_sks_zone;
156 struct SearchLookup *sl;
157 char *emsg;
44 158
45 /* get anonymity level */ 159 /* get anonymity level */
46 if (!GNUNET_GTK_get_selected_anonymity_level 160 if (!GNUNET_GTK_get_selected_anonymity_level
@@ -73,28 +187,17 @@ start_search (struct GNUNET_GTK_MainWindowContext *main_ctx)
73 mime_keyword = NULL; 187 mime_keyword = NULL;
74 } 188 }
75 } 189 }
76
77 /* get selected namespace */
78 { 190 {
79 GtkTreeRowReference *ref; 191 GtkComboBox *namespace_box;
80 GtkTreeIter iter; 192
81 193 namespace_box = GTK_COMBO_BOX (GNUNET_FS_GTK_get_main_window_object ("main_window_search_namespace_combobox"));
82 nsid = NULL; 194 nsid = gtk_entry_get_text (GTK_ENTRY (gtk_bin_get_child (GTK_BIN (namespace_box))));
83 ref = main_ctx->selected_ns_row; 195 if ( (NULL != nsid) &&
84 if (NULL != ref) 196 ( (0 == strcasecmp (nsid,
85 { 197 "<none>")) ||
86 GtkTreePath *namespace_treepath; 198 (0 == strcasecmp (nsid,
87 GtkTreeModel *namespace_model; 199 _("<none>"))) ) )
88 200 nsid = NULL;
89 namespace_model = gtk_tree_row_reference_get_model (ref);
90 namespace_treepath = gtk_tree_row_reference_get_path (ref);
91 if ( (NULL != namespace_treepath) &&
92 (gtk_tree_model_get_iter (namespace_model, &iter, namespace_treepath)))
93 gtk_tree_model_get (namespace_model, &iter,
94 GNUNET_GTK_FS_MAIN_WINDOW_SEARCH_MIME_MC_TYPE,
95 &nsid,
96 -1);
97 }
98 } 201 }
99 202
100 /* get keywords and compose keyword string */ 203 /* get keywords and compose keyword string */
@@ -117,31 +220,41 @@ start_search (struct GNUNET_GTK_MainWindowContext *main_ctx)
117 220
118 /* build KSK/SKS URI */ 221 /* build KSK/SKS URI */
119 if (NULL != nsid) 222 if (NULL != nsid)
120 { 223 {
121 uri = GNUNET_FS_uri_sks_create (nsid, keywords); 224 sl = GNUNET_new (struct SearchLookup);
122 GNUNET_assert (uri != NULL); 225 sl->keywords = keywords;
226 sl->anonymity_level = anonymity_level;
227 sl->timeout_task = GNUNET_SCHEDULER_add_delayed (LOOKUP_TIMEOUT,
228 &timeout_search_lookup, sl);
229 GNUNET_CRYPTO_ecc_key_get_public (main_ctx->sks_zone,
230 &pub_sks_zone);
231 sl->gns = GNUNET_GNS_lookup (main_ctx->gns,
232 nsid,
233 &pub_sks_zone,
234 GNUNET_NAMESTORE_TYPE_PKEY,
235 GNUNET_NO,
236 NULL /* no shortening */,
237 &handle_gns_result,
238 sl);
239 GNUNET_CONTAINER_DLL_insert (main_ctx->sl_head,
240 main_ctx->sl_tail,
241 sl);
242 return;
123 } 243 }
124 else
125 {
126 char *emsg = NULL;
127 244
128 uri = GNUNET_FS_uri_ksk_create (keywords, &emsg); 245 emsg = NULL;
129 if (NULL == uri) 246 uri = GNUNET_FS_uri_ksk_create (keywords, &emsg);
130 { 247 if (NULL == uri)
131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid keyword string `%s': %s"), 248 {
132 keywords, emsg); 249 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
133 g_free (keywords); 250 _("Invalid keyword string `%s': %s"),
134 GNUNET_free_non_null (emsg); 251 keywords, emsg);
135 return; 252 g_free (keywords);
136 } 253 GNUNET_free_non_null (emsg);
137 } 254 return;
255 }
138 g_free (keywords); 256 g_free (keywords);
139 257 search_for_uri (uri, anonymity_level);
140 /* start search */
141 GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (),
142 uri, anonymity_level,
143 GNUNET_FS_SEARCH_OPTION_NONE, NULL);
144 GNUNET_FS_uri_destroy (uri);
145} 258}
146 259
147 260
@@ -156,6 +269,7 @@ main_window_search_button_clicked_cb (GtkButton * button,
156 gpointer user_data) 269 gpointer user_data)
157{ 270{
158 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data; 271 struct GNUNET_GTK_MainWindowContext *main_ctx = user_data;
272
159 start_search (main_ctx); 273 start_search (main_ctx);
160} 274}
161 275