summaryrefslogtreecommitdiff
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.c173
1 files changed, 94 insertions, 79 deletions
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c
index 3995b1b5b..7d6ff4c6b 100644
--- a/src/fs/gnunet-search.c
+++ b/src/fs/gnunet-search.c
@@ -92,11 +92,10 @@ item_printer (void *cls,
#if HAVE_LIBEXTRACTOR
printf ("\t%20s: %s\n",
dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
- EXTRACTOR_metatype_to_string (type)), data);
-#else
- printf ("\t%20d: %s\n",
- type,
+ EXTRACTOR_metatype_to_string (type)),
data);
+#else
+ printf ("\t%20d: %s\n", type, data);
#endif
return 0;
}
@@ -118,13 +117,14 @@ clean_task (void *cls)
GNUNET_free (output_filename);
return;
}
- if (dsize !=
- GNUNET_DISK_fn_write (output_filename, ddata, dsize,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))
+ if (dsize != GNUNET_DISK_fn_write (output_filename,
+ ddata,
+ dsize,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))
{
- FPRINTF (stderr,
- _("Failed to write directory with search results to `%s'\n"),
+ fprintf (stderr,
+ _ ("Failed to write directory with search results to `%s'\n"),
output_filename);
}
GNUNET_free_non_null (ddata);
@@ -165,31 +165,35 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
NULL);
uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri);
printf ("#%u:\n", ++cnt);
- filename =
- GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.
- specifics.result.meta,
- EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
- is_directory =
- GNUNET_FS_meta_data_test_for_directory (info->value.search.
- specifics.result.meta);
+ filename = GNUNET_CONTAINER_meta_data_get_by_type (
+ info->value.search.specifics.result.meta,
+ EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
+ is_directory = GNUNET_FS_meta_data_test_for_directory (
+ info->value.search.specifics.result.meta);
if (NULL != filename)
{
- while ( (filename[0] != '\0') &&
- ('/' == filename[strlen(filename)-1]) )
- filename[strlen(filename)-1] = '\0';
+ while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1]))
+ filename[strlen (filename) - 1] = '\0';
GNUNET_DISK_filename_canonicalize (filename);
if (GNUNET_YES == is_directory)
- printf ("gnunet-download -o \"%s%s\" -R %s\n", filename, GNUNET_FS_DIRECTORY_EXT, uri);
+ printf ("gnunet-download -o \"%s%s\" -R %s\n",
+ filename,
+ GNUNET_FS_DIRECTORY_EXT,
+ uri);
else
printf ("gnunet-download -o \"%s\" %s\n", filename, uri);
}
else if (GNUNET_YES == is_directory)
- printf ("gnunet-download -o \"collection%s\" -R %s\n", GNUNET_FS_DIRECTORY_EXT, uri);
+ printf ("gnunet-download -o \"collection%s\" -R %s\n",
+ GNUNET_FS_DIRECTORY_EXT,
+ uri);
else
printf ("gnunet-download %s\n", uri);
if (verbose)
- GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.
- result.meta, &item_printer, NULL);
+ GNUNET_CONTAINER_meta_data_iterate (info->value.search.specifics.result
+ .meta,
+ &item_printer,
+ NULL);
printf ("\n");
fflush (stdout);
GNUNET_free_non_null (filename);
@@ -204,7 +208,8 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
/* ignore */
break;
case GNUNET_FS_STATUS_SEARCH_ERROR:
- FPRINTF (stderr, _("Error searching: %s.\n"),
+ fprintf (stderr,
+ _ ("Error searching: %s.\n"),
info->value.search.specifics.error.message);
GNUNET_SCHEDULER_shutdown ();
break;
@@ -212,7 +217,7 @@ progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
GNUNET_SCHEDULER_add_now (&clean_task, NULL);
break;
default:
- FPRINTF (stderr, _("Unexpected status: %d\n"), info->status);
+ fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
break;
}
return NULL;
@@ -247,7 +252,9 @@ timeout_task (void *cls)
* @param c configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_FS_Uri *uri;
@@ -260,17 +267,22 @@ run (void *cls, char *const *args, const char *cfgfile,
uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args);
if (NULL == uri)
{
- FPRINTF (stderr, "%s", _("Could not create keyword URI from arguments.\n"));
+ fprintf (stderr,
+ "%s",
+ _ ("Could not create keyword URI from arguments.\n"));
ret = 1;
return;
}
cfg = c;
- ctx =
- GNUNET_FS_start (cfg, "gnunet-search", &progress_cb, NULL,
- GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
+ ctx = GNUNET_FS_start (cfg,
+ "gnunet-search",
+ &progress_cb,
+ NULL,
+ GNUNET_FS_FLAGS_NONE,
+ GNUNET_FS_OPTIONS_END);
if (NULL == ctx)
{
- FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
+ fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
GNUNET_FS_uri_destroy (uri);
ret = 1;
return;
@@ -284,17 +296,14 @@ run (void *cls, char *const *args, const char *cfgfile,
GNUNET_FS_uri_destroy (uri);
if (NULL == sc)
{
- FPRINTF (stderr, "%s", _("Could not start searching.\n"));
+ fprintf (stderr, "%s", _ ("Could not start searching.\n"));
GNUNET_FS_stop (ctx);
ret = 1;
return;
}
if (0 != timeout.rel_value_us)
- tt = GNUNET_SCHEDULER_add_delayed (timeout,
- &timeout_task,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
@@ -308,49 +317,55 @@ run (void *cls, char *const *args, const char *cfgfile,
int
main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_uint ('a',
- "anonymity",
- "LEVEL",
- gettext_noop ("set the desired LEVEL of receiver-anonymity"),
- &anonymity),
- GNUNET_GETOPT_option_flag ('n',
- "no-network",
- gettext_noop ("only search the local peer (no P2P network search)"),
- &local_only),
- GNUNET_GETOPT_option_string ('o',
- "output",
- "PREFIX",
- gettext_noop ("write search results to file starting with PREFIX"),
- &output_filename),
- GNUNET_GETOPT_option_relative_time ('t',
- "timeout",
- "DELAY",
- gettext_noop ("automatically terminate search after DELAY"),
- &timeout),
- GNUNET_GETOPT_option_verbose (&verbose),
- GNUNET_GETOPT_option_uint ('N',
- "results",
- "VALUE",
- gettext_noop ("automatically terminate search "
- "after VALUE results are found"),
- &results_limit),
- GNUNET_GETOPT_OPTION_END
- };
-
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_uint ('a',
+ "anonymity",
+ "LEVEL",
+ gettext_noop (
+ "set the desired LEVEL of receiver-anonymity"),
+ &anonymity),
+ GNUNET_GETOPT_option_flag (
+ 'n',
+ "no-network",
+ gettext_noop ("only search the local peer (no P2P network search)"),
+ &local_only),
+ GNUNET_GETOPT_option_string (
+ 'o',
+ "output",
+ "PREFIX",
+ gettext_noop ("write search results to file starting with PREFIX"),
+ &output_filename),
+ GNUNET_GETOPT_option_relative_time (
+ 't',
+ "timeout",
+ "DELAY",
+ gettext_noop ("automatically terminate search after DELAY"),
+ &timeout),
+ GNUNET_GETOPT_option_verbose (&verbose),
+ GNUNET_GETOPT_option_uint ('N',
+ "results",
+ "VALUE",
+ gettext_noop ("automatically terminate search "
+ "after VALUE results are found"),
+ &results_limit),
+ GNUNET_GETOPT_OPTION_END};
+
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-search [OPTIONS] KEYWORD",
- gettext_noop
- ("Search GNUnet for files that were published on GNUnet"),
- options, &run, NULL)) ? ret : 1;
- GNUNET_free ((void*) argv);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-search [OPTIONS] KEYWORD",
+ gettext_noop (
+ "Search GNUnet for files that were published on GNUnet"),
+ options,
+ &run,
+ NULL))
+ ? ret
+ : 1;
+ GNUNET_free ((void *) argv);
return ret;
}