diff options
Diffstat (limited to 'src/fs/gnunet-search.c')
-rw-r--r-- | src/fs/gnunet-search.c | 104 |
1 files changed, 98 insertions, 6 deletions
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 10a3c82fd..b744d2e1a 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c | |||
@@ -26,7 +26,7 @@ | |||
26 | * @author Igor Wronsky | 26 | * @author Igor Wronsky |
27 | * | 27 | * |
28 | * TODO: | 28 | * TODO: |
29 | * - all | 29 | * - add many options (timeout, namespace search, etc.) |
30 | */ | 30 | */ |
31 | #include "platform.h" | 31 | #include "platform.h" |
32 | #include "gnunet_fs_service.h" | 32 | #include "gnunet_fs_service.h" |
@@ -37,10 +37,24 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
37 | 37 | ||
38 | static struct GNUNET_FS_Handle *ctx; | 38 | static struct GNUNET_FS_Handle *ctx; |
39 | 39 | ||
40 | static struct GNUNET_TIME_Absolute start_time; | 40 | static struct GNUNET_FS_SearchContext *sc; |
41 | 41 | ||
42 | static unsigned int anonymity = 1; | 42 | static unsigned int anonymity = 1; |
43 | 43 | ||
44 | static int verbose; | ||
45 | |||
46 | static int | ||
47 | item_printer (void *cls, | ||
48 | EXTRACTOR_KeywordType type, | ||
49 | const char *data) | ||
50 | { | ||
51 | printf ("\t%20s: %s\n", | ||
52 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, | ||
53 | EXTRACTOR_getKeywordTypeAsString (type)), | ||
54 | data); | ||
55 | return GNUNET_OK; | ||
56 | } | ||
57 | |||
44 | 58 | ||
45 | /** | 59 | /** |
46 | * Called by FS client to give information about the progress of an | 60 | * Called by FS client to give information about the progress of an |
@@ -59,6 +73,56 @@ static void * | |||
59 | progress_cb (void *cls, | 73 | progress_cb (void *cls, |
60 | const struct GNUNET_FS_ProgressInfo *info) | 74 | const struct GNUNET_FS_ProgressInfo *info) |
61 | { | 75 | { |
76 | char *uri; | ||
77 | char *dotdot; | ||
78 | char *filename; | ||
79 | |||
80 | switch (info->status) | ||
81 | { | ||
82 | case GNUNET_FS_STATUS_SEARCH_START: | ||
83 | break; | ||
84 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
85 | uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); | ||
86 | printf ("%s:\n", uri); | ||
87 | filename = | ||
88 | GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.specifics.result.meta, | ||
89 | EXTRACTOR_FILENAME); | ||
90 | if (filename != NULL) | ||
91 | { | ||
92 | while (NULL != (dotdot = strstr (filename, ".."))) | ||
93 | dotdot[0] = dotdot[1] = '_'; | ||
94 | printf ("gnunet-download -o \"%s\" %s\n", | ||
95 | filename, | ||
96 | uri); | ||
97 | } | ||
98 | else | ||
99 | printf ("gnunet-download %s\n", uri); | ||
100 | if (verbose) | ||
101 | GNUNET_CONTAINER_meta_data_get_contents (info->value.search.specifics.result.meta, | ||
102 | &item_printer, | ||
103 | NULL); | ||
104 | printf ("\n"); | ||
105 | fflush(stdout); | ||
106 | GNUNET_free_non_null (filename); | ||
107 | GNUNET_free (uri); | ||
108 | break; | ||
109 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
110 | break; | ||
111 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
112 | fprintf (stderr, | ||
113 | _("Error searching: %s.\n"), | ||
114 | info->value.search.specifics.error.message); | ||
115 | GNUNET_FS_search_stop (sc); | ||
116 | break; | ||
117 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
118 | GNUNET_FS_stop (ctx); | ||
119 | break; | ||
120 | default: | ||
121 | fprintf (stderr, | ||
122 | _("Unexpected status: %d\n"), | ||
123 | info->status); | ||
124 | break; | ||
125 | } | ||
62 | return NULL; | 126 | return NULL; |
63 | } | 127 | } |
64 | 128 | ||
@@ -79,23 +143,51 @@ run (void *cls, | |||
79 | const char *cfgfile, | 143 | const char *cfgfile, |
80 | const struct GNUNET_CONFIGURATION_Handle *c) | 144 | const struct GNUNET_CONFIGURATION_Handle *c) |
81 | { | 145 | { |
82 | /* FIXME: check arguments */ | 146 | struct GNUNET_FS_Uri *uri; |
147 | unsigned int argc; | ||
148 | |||
149 | argc = 0; | ||
150 | while (NULL != args[argc]) | ||
151 | argc++; | ||
152 | uri = GNUNET_FS_uri_ksk_create_from_args (argc, | ||
153 | (const char **) args); | ||
154 | if (NULL == uri) | ||
155 | { | ||
156 | fprintf (stderr, | ||
157 | _("Could not create keyword URI from arguments.\n")); | ||
158 | ret = 1; | ||
159 | GNUNET_FS_uri_destroy (uri); | ||
160 | return; | ||
161 | } | ||
83 | cfg = c; | 162 | cfg = c; |
84 | ctx = GNUNET_FS_start (sched, | 163 | ctx = GNUNET_FS_start (sched, |
85 | cfg, | 164 | cfg, |
86 | "gnunet-search", | 165 | "gnunet-search", |
87 | &progress_cb, | 166 | &progress_cb, |
88 | NULL); | 167 | NULL, |
168 | GNUNET_FS_FLAGS_NONE, | ||
169 | GNUNET_FS_OPTIONS_END); | ||
89 | if (NULL == ctx) | 170 | if (NULL == ctx) |
90 | { | 171 | { |
91 | fprintf (stderr, | 172 | fprintf (stderr, |
92 | _("Could not initialize `%s' subsystem.\n"), | 173 | _("Could not initialize `%s' subsystem.\n"), |
93 | "FS"); | 174 | "FS"); |
175 | GNUNET_FS_uri_destroy (uri); | ||
176 | GNUNET_FS_stop (ctx); | ||
177 | ret = 1; | ||
178 | return; | ||
179 | } | ||
180 | sc = GNUNET_FS_search_start (ctx, | ||
181 | uri, | ||
182 | anonymity); | ||
183 | GNUNET_FS_uri_destroy (uri); | ||
184 | if (NULL == sc) | ||
185 | { | ||
186 | fprintf (stderr, | ||
187 | _("Could not start searching.\n")); | ||
94 | ret = 1; | 188 | ret = 1; |
95 | return; | 189 | return; |
96 | } | 190 | } |
97 | start_time = GNUNET_TIME_absolute_get (); | ||
98 | // FIXME: start search | ||
99 | } | 191 | } |
100 | 192 | ||
101 | 193 | ||