2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file fs/gnunet-search.c
22 * @brief searching for files on GNUnet
23 * @author Christian Grothoff
24 * @author Krista Bennett
25 * @author James Blackwell
26 * @author Igor Wronsky
29 * - add many options (timeout, namespace search, etc.)
32 #include "gnunet_fs_service.h"
36 static const struct GNUNET_CONFIGURATION_Handle *cfg;
38 static struct GNUNET_FS_Handle *ctx;
40 static struct GNUNET_FS_SearchContext *sc;
42 static unsigned int anonymity = 1;
47 item_printer (void *cls,
48 EXTRACTOR_KeywordType type,
51 printf ("\t%20s: %s\n",
52 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
53 EXTRACTOR_getKeywordTypeAsString (type)),
60 * Called by FS client to give information about the progress of an
64 * @param info details about the event, specifying the event type
65 * and various bits about the event
66 * @return client-context (for the next progress call
67 * for this operation; should be set to NULL for
68 * SUSPEND and STOPPED events). The value returned
69 * will be passed to future callbacks in the respective
70 * field in the GNUNET_FS_ProgressInfo struct.
73 progress_cb (void *cls,
74 const struct GNUNET_FS_ProgressInfo *info)
82 case GNUNET_FS_STATUS_SEARCH_START:
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);
88 GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.specifics.result.meta,
92 while (NULL != (dotdot = strstr (filename, "..")))
93 dotdot[0] = dotdot[1] = '_';
94 printf ("gnunet-download -o \"%s\" %s\n",
99 printf ("gnunet-download %s\n", uri);
101 GNUNET_CONTAINER_meta_data_get_contents (info->value.search.specifics.result.meta,
106 GNUNET_free_non_null (filename);
109 case GNUNET_FS_STATUS_SEARCH_UPDATE:
111 case GNUNET_FS_STATUS_SEARCH_ERROR:
113 _("Error searching: %s.\n"),
114 info->value.search.specifics.error.message);
115 GNUNET_FS_search_stop (sc);
117 case GNUNET_FS_STATUS_SEARCH_STOPPED:
118 GNUNET_FS_stop (ctx);
122 _("Unexpected status: %d\n"),
131 * Main function that will be run by the scheduler.
134 * @param sched the scheduler to use
135 * @param args remaining command-line arguments
136 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
137 * @param c configuration
141 struct GNUNET_SCHEDULER_Handle *sched,
144 const struct GNUNET_CONFIGURATION_Handle *c)
146 struct GNUNET_FS_Uri *uri;
150 while (NULL != args[argc])
152 uri = GNUNET_FS_uri_ksk_create_from_args (argc,
153 (const char **) args);
157 _("Could not create keyword URI from arguments.\n"));
159 GNUNET_FS_uri_destroy (uri);
163 ctx = GNUNET_FS_start (sched,
168 GNUNET_FS_FLAGS_NONE,
169 GNUNET_FS_OPTIONS_END);
173 _("Could not initialize `%s' subsystem.\n"),
175 GNUNET_FS_uri_destroy (uri);
176 GNUNET_FS_stop (ctx);
180 sc = GNUNET_FS_search_start (ctx,
184 GNUNET_FS_uri_destroy (uri);
188 _("Could not start searching.\n"));
196 * gnunet-search command line options
198 static struct GNUNET_GETOPT_CommandLineOption options[] = {
199 {'a', "anonymity", "LEVEL",
200 gettext_noop ("set the desired LEVEL of receiver-anonymity"),
201 1, &GNUNET_GETOPT_set_uint, &anonymity},
203 GNUNET_GETOPT_OPTION_END
208 * The main function to search GNUnet.
210 * @param argc number of arguments from the command line
211 * @param argv command line arguments
212 * @return 0 ok, 1 on error
215 main (int argc, char *const *argv)
218 GNUNET_PROGRAM_run (argc,
223 options, &run, NULL)) ? ret : 1;
226 /* end of gnunet-search.c */