aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-01-06 16:37:32 +0100
committerChristian Grothoff <christian@grothoff.org>2018-01-06 16:37:32 +0100
commit6ddfa55804cca3706e4f9fe803a76b7bc5310d47 (patch)
tree74680ea76c9ffa05ce8be2b837df97e199e61586 /src/fs
parentd3e5196f514ff1f76c137fa9db771a32765681f2 (diff)
downloadgnunet-6ddfa55804cca3706e4f9fe803a76b7bc5310d47.tar.gz
gnunet-6ddfa55804cca3706e4f9fe803a76b7bc5310d47.zip
fix indentation and use after free in tcp plugin
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs_download.c3
-rw-r--r--src/fs/gnunet-download.c145
2 files changed, 90 insertions, 58 deletions
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index ce852f2d0..c2a3d4c5d 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -37,7 +37,8 @@ static int
37is_recursive_download (struct GNUNET_FS_DownloadContext *dc) 37is_recursive_download (struct GNUNET_FS_DownloadContext *dc)
38{ 38{
39 return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) && 39 return (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE)) &&
40 ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (dc->meta)) || 40 ( (GNUNET_YES ==
41 GNUNET_FS_meta_data_test_for_directory (dc->meta)) ||
41 ( (NULL == dc->meta) && 42 ( (NULL == dc->meta) &&
42 ( (NULL == dc->filename) || 43 ( (NULL == dc->filename) ||
43 ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) && 44 ( (strlen (dc->filename) >= strlen (GNUNET_FS_DIRECTORY_EXT)) &&
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c
index 83c1eb505..27266a18a 100644
--- a/src/fs/gnunet-download.c
+++ b/src/fs/gnunet-download.c
@@ -124,7 +124,8 @@ display_bar (unsigned long long x,
124 * field in the `struct GNUNET_FS_ProgressInfo` 124 * field in the `struct GNUNET_FS_ProgressInfo`
125 */ 125 */
126static void * 126static void *
127progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) 127progress_cb (void *cls,
128 const struct GNUNET_FS_ProgressInfo *info)
128{ 129{
129 char *s; 130 char *s;
130 const char *s2; 131 const char *s2;
@@ -134,7 +135,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
134 { 135 {
135 case GNUNET_FS_STATUS_DOWNLOAD_START: 136 case GNUNET_FS_STATUS_DOWNLOAD_START:
136 if (verbose > 1) 137 if (verbose > 1)
137 FPRINTF (stderr, _("Starting download `%s'.\n"), 138 FPRINTF (stderr,
139 _("Starting download `%s'.\n"),
138 info->value.download.filename); 140 info->value.download.filename);
139 break; 141 break;
140 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: 142 case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS:
@@ -146,8 +148,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
146 == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 148 == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
147 s2 = _("<unknown time>"); 149 s2 = _("<unknown time>");
148 else 150 else
149 s2 = GNUNET_STRINGS_relative_time_to_string ( 151 s2 = GNUNET_STRINGS_relative_time_to_string (info->value.download.specifics.progress.block_download_duration,
150 info->value.download.specifics.progress.block_download_duration,
151 GNUNET_YES); 152 GNUNET_YES);
152 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed * 153 t = GNUNET_STRINGS_byte_size_fancy (info->value.download.completed *
153 1000LL / 154 1000LL /
@@ -157,7 +158,10 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
157 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"), 158 _("Downloading `%s' at %llu/%llu (%s remaining, %s/s). Block took %s to download\n"),
158 info->value.download.filename, 159 info->value.download.filename,
159 (unsigned long long) info->value.download.completed, 160 (unsigned long long) info->value.download.completed,
160 (unsigned long long) info->value.download.size, s, t, s2); 161 (unsigned long long) info->value.download.size,
162 s,
163 t,
164 s2);
161 GNUNET_free (s); 165 GNUNET_free (s);
162 GNUNET_free (t); 166 GNUNET_free (t);
163 } 167 }
@@ -173,7 +177,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
173 if (0 != isatty (1)) 177 if (0 != isatty (1))
174 fprintf (stdout, "\n"); 178 fprintf (stdout, "\n");
175#else 179#else
176 if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) 180 if (FILE_TYPE_CHAR ==
181 GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
177 fprintf (stdout, "\n"); 182 fprintf (stdout, "\n");
178#endif 183#endif
179 FPRINTF (stderr, _("Error downloading: %s.\n"), 184 FPRINTF (stderr, _("Error downloading: %s.\n"),
@@ -188,10 +193,12 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
188 if (0 != isatty (1)) 193 if (0 != isatty (1))
189 fprintf (stdout, "\n"); 194 fprintf (stdout, "\n");
190#else 195#else
191 if (FILE_TYPE_CHAR == GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) 196 if (FILE_TYPE_CHAR ==
197 GetFileType (GetStdHandle (STD_OUTPUT_HANDLE)))
192 fprintf (stdout, "\n"); 198 fprintf (stdout, "\n");
193#endif 199#endif
194 FPRINTF (stdout, _("Downloading `%s' done (%s/s).\n"), 200 FPRINTF (stdout,
201 _("Downloading `%s' done (%s/s).\n"),
195 info->value.download.filename, s); 202 info->value.download.filename, s);
196 GNUNET_free (s); 203 GNUNET_free (s);
197 if (info->value.download.dc == dc) 204 if (info->value.download.dc == dc)
@@ -205,7 +212,9 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
205 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: 212 case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE:
206 break; 213 break;
207 default: 214 default:
208 FPRINTF (stderr, _("Unexpected status: %d\n"), info->status); 215 FPRINTF (stderr,
216 _("Unexpected status: %d\n"),
217 info->status);
209 break; 218 break;
210 } 219 }
211 return NULL; 220 return NULL;
@@ -221,7 +230,9 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
221 * @param c configuration 230 * @param c configuration
222 */ 231 */
223static void 232static void
224run (void *cls, char *const *args, const char *cfgfile, 233run (void *cls,
234 char *const *args,
235 const char *cfgfile,
225 const struct GNUNET_CONFIGURATION_Handle *c) 236 const struct GNUNET_CONFIGURATION_Handle *c)
226{ 237{
227 struct GNUNET_FS_Uri *uri; 238 struct GNUNET_FS_Uri *uri;
@@ -230,41 +241,55 @@ run (void *cls, char *const *args, const char *cfgfile,
230 241
231 if (NULL == args[0]) 242 if (NULL == args[0])
232 { 243 {
233 FPRINTF (stderr, "%s", _("You need to specify a URI argument.\n")); 244 FPRINTF (stderr,
245 "%s",
246 _("You need to specify a URI argument.\n"));
234 return; 247 return;
235 } 248 }
236 uri = GNUNET_FS_uri_parse (args[0], &emsg); 249 uri = GNUNET_FS_uri_parse (args[0], &emsg);
237 if (NULL == uri) 250 if (NULL == uri)
238 { 251 {
239 FPRINTF (stderr, _("Failed to parse URI: %s\n"), emsg); 252 FPRINTF (stderr,
253 _("Failed to parse URI: %s\n"),
254 emsg);
240 GNUNET_free (emsg); 255 GNUNET_free (emsg);
241 ret = 1; 256 ret = 1;
242 return; 257 return;
243 } 258 }
244 if ((!GNUNET_FS_uri_test_chk (uri)) && (!GNUNET_FS_uri_test_loc (uri))) 259 if ( (! GNUNET_FS_uri_test_chk (uri)) &&
260 (! GNUNET_FS_uri_test_loc (uri)))
245 { 261 {
246 FPRINTF (stderr, "%s", _("Only CHK or LOC URIs supported.\n")); 262 FPRINTF (stderr,
263 "%s",
264 _("Only CHK or LOC URIs supported.\n"));
247 ret = 1; 265 ret = 1;
248 GNUNET_FS_uri_destroy (uri); 266 GNUNET_FS_uri_destroy (uri);
249 return; 267 return;
250 } 268 }
251 if (NULL == filename) 269 if (NULL == filename)
252 { 270 {
253 FPRINTF (stderr, "%s", _("Target filename must be specified.\n")); 271 FPRINTF (stderr,
272 "%s",
273 _("Target filename must be specified.\n"));
254 ret = 1; 274 ret = 1;
255 GNUNET_FS_uri_destroy (uri); 275 GNUNET_FS_uri_destroy (uri);
256 return; 276 return;
257 } 277 }
258 cfg = c; 278 cfg = c;
259 ctx = 279 ctx = GNUNET_FS_start (cfg,
260 GNUNET_FS_start (cfg, "gnunet-download", &progress_cb, NULL, 280 "gnunet-download",
261 GNUNET_FS_FLAGS_NONE, 281 &progress_cb, NULL,
262 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM, parallelism, 282 GNUNET_FS_FLAGS_NONE,
263 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM, 283 GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM,
264 request_parallelism, GNUNET_FS_OPTIONS_END); 284 parallelism,
285 GNUNET_FS_OPTIONS_REQUEST_PARALLELISM,
286 request_parallelism,
287 GNUNET_FS_OPTIONS_END);
265 if (NULL == ctx) 288 if (NULL == ctx)
266 { 289 {
267 FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); 290 FPRINTF (stderr,
291 _("Could not initialize `%s' subsystem.\n"),
292 "FS");
268 GNUNET_FS_uri_destroy (uri); 293 GNUNET_FS_uri_destroy (uri);
269 ret = 1; 294 ret = 1;
270 return; 295 return;
@@ -274,9 +299,17 @@ run (void *cls, char *const *args, const char *cfgfile,
274 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; 299 options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE;
275 if (local_only) 300 if (local_only)
276 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; 301 options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY;
277 dc = GNUNET_FS_download_start (ctx, uri, NULL, filename, NULL, 0, 302 dc = GNUNET_FS_download_start (ctx,
303 uri,
304 NULL,
305 filename,
306 NULL,
307 0,
278 GNUNET_FS_uri_chk_get_file_size (uri), 308 GNUNET_FS_uri_chk_get_file_size (uri),
279 anonymity, options, NULL, NULL); 309 anonymity,
310 options,
311 NULL,
312 NULL);
280 GNUNET_FS_uri_destroy (uri); 313 GNUNET_FS_uri_destroy (uri);
281 if (dc == NULL) 314 if (dc == NULL)
282 { 315 {
@@ -301,60 +334,58 @@ main (int argc, char *const *argv)
301{ 334{
302 struct GNUNET_GETOPT_CommandLineOption options[] = { 335 struct GNUNET_GETOPT_CommandLineOption options[] = {
303 GNUNET_GETOPT_option_uint ('a', 336 GNUNET_GETOPT_option_uint ('a',
304 "anonymity", 337 "anonymity",
305 "LEVEL", 338 "LEVEL",
306 gettext_noop ("set the desired LEVEL of receiver-anonymity"), 339 gettext_noop ("set the desired LEVEL of receiver-anonymity"),
307 &anonymity), 340 &anonymity),
308 341
309 GNUNET_GETOPT_option_flag ('D', 342 GNUNET_GETOPT_option_flag ('D',
310 "delete-incomplete", 343 "delete-incomplete",
311 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), 344 gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"),
312 &delete_incomplete), 345 &delete_incomplete),
313 346
314 GNUNET_GETOPT_option_flag ('n', 347 GNUNET_GETOPT_option_flag ('n',
315 "no-network", 348 "no-network",
316 gettext_noop ("only search the local peer (no P2P network search)"), 349 gettext_noop ("only search the local peer (no P2P network search)"),
317 &local_only), 350 &local_only),
318
319 GNUNET_GETOPT_option_string ('o', 351 GNUNET_GETOPT_option_string ('o',
320 "output", 352 "output",
321 "FILENAME", 353 "FILENAME",
322 gettext_noop ("write the file to FILENAME"), 354 gettext_noop ("write the file to FILENAME"),
323 &filename), 355 &filename),
324
325 GNUNET_GETOPT_option_uint ('p', 356 GNUNET_GETOPT_option_uint ('p',
326 "parallelism", 357 "parallelism",
327 "DOWNLOADS", 358 "DOWNLOADS",
328 gettext_noop ("set the maximum number of parallel downloads that is allowed"), 359 gettext_noop ("set the maximum number of parallel downloads that is allowed"),
329 &parallelism), 360 &parallelism),
330
331 GNUNET_GETOPT_option_uint ('r', 361 GNUNET_GETOPT_option_uint ('r',
332 "request-parallelism", 362 "request-parallelism",
333 "REQUESTS", 363 "REQUESTS",
334 gettext_noop ("set the maximum number of parallel requests for blocks that is allowed"), 364 gettext_noop ("set the maximum number of parallel requests for blocks that is allowed"),
335 &request_parallelism), 365 &request_parallelism),
336
337 GNUNET_GETOPT_option_flag ('R', 366 GNUNET_GETOPT_option_flag ('R',
338 "recursive", 367 "recursive",
339 gettext_noop ("download a GNUnet directory recursively"), 368 gettext_noop ("download a GNUnet directory recursively"),
340 &do_recursive), 369 &do_recursive),
341
342 GNUNET_GETOPT_option_increment_uint ('V', 370 GNUNET_GETOPT_option_increment_uint ('V',
343 "verbose", 371 "verbose",
344 gettext_noop ("be verbose (print progress information)"), 372 gettext_noop ("be verbose (print progress information)"),
345 &verbose), 373 &verbose),
346
347 GNUNET_GETOPT_OPTION_END 374 GNUNET_GETOPT_OPTION_END
348 }; 375 };
349 376
350 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 377 if (GNUNET_OK !=
378 GNUNET_STRINGS_get_utf8_args (argc, argv,
379 &argc, &argv))
351 return 2; 380 return 2;
352 381
353 ret = (GNUNET_OK == 382 ret = (GNUNET_OK ==
354 GNUNET_PROGRAM_run (argc, argv, "gnunet-download [OPTIONS] URI", 383 GNUNET_PROGRAM_run (argc, argv,
384 "gnunet-download [OPTIONS] URI",
355 gettext_noop 385 gettext_noop
356 ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"), 386 ("Download files from GNUnet using a GNUnet CHK or LOC URI (gnunet://fs/chk/...)"),
357 options, &run, NULL)) ? ret : 1; 387 options,
388 &run, NULL)) ? ret : 1;
358 GNUNET_free ((void*) argv); 389 GNUNET_free ((void*) argv);
359 return ret; 390 return ret;
360} 391}