aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-search.c')
-rw-r--r--src/fs/gnunet-search.c47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c
index 462f432c8..33c81c9d7 100644
--- a/src/fs/gnunet-search.c
+++ b/src/fs/gnunet-search.c
@@ -24,9 +24,6 @@
24 * @author Krista Bennett 24 * @author Krista Bennett
25 * @author James Blackwell 25 * @author James Blackwell
26 * @author Igor Wronsky 26 * @author Igor Wronsky
27 *
28 * TODO:
29 * - add many options (timeout, namespace search, etc.)
30 */ 27 */
31#include "platform.h" 28#include "platform.h"
32#include "gnunet_fs_service.h" 29#include "gnunet_fs_service.h"
@@ -41,6 +38,10 @@ static struct GNUNET_FS_Handle *ctx;
41 38
42static struct GNUNET_FS_SearchContext *sc; 39static struct GNUNET_FS_SearchContext *sc;
43 40
41static char *output_filename;
42
43static struct GNUNET_FS_DirectoryBuilder *db;
44
44static unsigned int anonymity = 1; 45static unsigned int anonymity = 1;
45 46
46static int verbose; 47static int verbose;
@@ -64,12 +65,39 @@ item_printer (void *cls,
64 return GNUNET_OK; 65 return GNUNET_OK;
65} 66}
66 67
68
67static void 69static void
68clean_task (void *cls, 70clean_task (void *cls,
69 const struct GNUNET_SCHEDULER_TaskContext *tc) 71 const struct GNUNET_SCHEDULER_TaskContext *tc)
70{ 72{
73 size_t dsize;
74 void *ddata;
75
71 GNUNET_FS_stop (ctx); 76 GNUNET_FS_stop (ctx);
72 ctx = NULL; 77 ctx = NULL;
78 if (output_filename == NULL)
79 return;
80 if (GNUNET_OK !=
81 GNUNET_FS_directory_builder_finish (db,
82 &dsize,
83 &ddata))
84 {
85 GNUNET_break (0);
86 GNUNET_free (output_filename);
87 return;
88 }
89 if (dsize !=
90 GNUNET_DISK_fn_write (output_filename,
91 ddata,
92 dsize,
93 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE))
94 {
95 fprintf (stderr,
96 _("Failed to write directory with search results to `%s'\n"),
97 output_filename);
98 }
99 GNUNET_free_non_null (ddata);
100 GNUNET_free (output_filename);
73} 101}
74 102
75 103
@@ -99,6 +127,11 @@ progress_cb (void *cls,
99 case GNUNET_FS_STATUS_SEARCH_START: 127 case GNUNET_FS_STATUS_SEARCH_START:
100 break; 128 break;
101 case GNUNET_FS_STATUS_SEARCH_RESULT: 129 case GNUNET_FS_STATUS_SEARCH_RESULT:
130 if (db != NULL)
131 GNUNET_FS_directory_builder_add (db,
132 info->value.search.specifics.result.uri,
133 info->value.search.specifics.result.meta,
134 NULL);
102 uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); 135 uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
103 printf ("%s:\n", uri); 136 printf ("%s:\n", uri);
104 filename = 137 filename =
@@ -135,7 +168,6 @@ progress_cb (void *cls,
135 GNUNET_SCHEDULER_shutdown (sched); 168 GNUNET_SCHEDULER_shutdown (sched);
136 break; 169 break;
137 case GNUNET_FS_STATUS_SEARCH_STOPPED: 170 case GNUNET_FS_STATUS_SEARCH_STOPPED:
138 sc = NULL;
139 GNUNET_SCHEDULER_add_continuation (sched, 171 GNUNET_SCHEDULER_add_continuation (sched,
140 &clean_task, 172 &clean_task,
141 NULL, 173 NULL,
@@ -214,6 +246,8 @@ run (void *cls,
214 ret = 1; 246 ret = 1;
215 return; 247 return;
216 } 248 }
249 if (output_filename != NULL)
250 db = GNUNET_FS_directory_builder_create (NULL);
217 sc = GNUNET_FS_search_start (ctx, 251 sc = GNUNET_FS_search_start (ctx,
218 uri, 252 uri,
219 anonymity, 253 anonymity,
@@ -241,7 +275,10 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
241 {'a', "anonymity", "LEVEL", 275 {'a', "anonymity", "LEVEL",
242 gettext_noop ("set the desired LEVEL of receiver-anonymity"), 276 gettext_noop ("set the desired LEVEL of receiver-anonymity"),
243 1, &GNUNET_GETOPT_set_uint, &anonymity}, 277 1, &GNUNET_GETOPT_set_uint, &anonymity},
244 // FIXME: options! 278 {'o', "output", "PREFIX",
279 gettext_noop
280 ("write search results to file starting with PREFIX"),
281 1, &GNUNET_GETOPT_set_string, &output_filename},
245 GNUNET_GETOPT_OPTION_END 282 GNUNET_GETOPT_OPTION_END
246}; 283};
247 284