2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file fs/gnunet-unindex.c
22 * @brief unindex files published on GNUnet
23 * @author Christian Grothoff
24 * @author Krista Bennett
25 * @author James Blackwell
26 * @author Igor Wronsky
29 #include "gnunet_fs_service.h"
33 static unsigned int verbose;
35 static const struct GNUNET_CONFIGURATION_Handle *cfg;
37 static struct GNUNET_FS_Handle *ctx;
39 static struct GNUNET_FS_UnindexContext *uc;
43 cleanup_task(void *cls)
51 shutdown_task(void *cls)
53 struct GNUNET_FS_UnindexContext *u;
59 GNUNET_FS_unindex_stop(u);
64 * Called by FS client to give information about the progress of an
68 * @param info details about the event, specifying the event type
69 * and various bits about the event
70 * @return client-context (for the next progress call
71 * for this operation; should be set to NULL for
72 * SUSPEND and STOPPED events). The value returned
73 * will be passed to future callbacks in the respective
74 * field in the GNUNET_FS_ProgressInfo struct.
77 progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info)
83 case GNUNET_FS_STATUS_UNINDEX_START:
86 case GNUNET_FS_STATUS_UNINDEX_PROGRESS:
89 s = GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta,
92 _("Unindexing at %llu/%llu (%s remaining)\n"),
93 (unsigned long long)info->value.unindex.completed,
94 (unsigned long long)info->value.unindex.size,
99 case GNUNET_FS_STATUS_UNINDEX_ERROR:
101 _("Error unindexing: %s.\n"),
102 info->value.unindex.specifics.error.message);
103 GNUNET_SCHEDULER_shutdown();
106 case GNUNET_FS_STATUS_UNINDEX_COMPLETED:
107 fprintf(stdout, "%s", _("Unindexing done.\n"));
108 GNUNET_SCHEDULER_shutdown();
111 case GNUNET_FS_STATUS_UNINDEX_STOPPED:
112 GNUNET_SCHEDULER_add_now(&cleanup_task, NULL);
116 fprintf(stderr, _("Unexpected status: %d\n"), info->status);
124 * Main function that will be run by the scheduler.
127 * @param args remaining command-line arguments
128 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
129 * @param c configuration
135 const struct GNUNET_CONFIGURATION_Handle *c)
137 /* check arguments */
138 if ((args[0] == NULL) || (args[1] != NULL))
140 printf(_("You must specify one and only one filename for unindexing.\n"));
145 ctx = GNUNET_FS_start(cfg,
149 GNUNET_FS_FLAGS_NONE,
150 GNUNET_FS_OPTIONS_END);
153 fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
157 uc = GNUNET_FS_unindex_start(ctx, args[0], NULL);
160 fprintf(stderr, "%s", _("Could not start unindex operation.\n"));
164 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
169 * The main function to unindex content.
171 * @param argc number of arguments from the command line
172 * @param argv command line arguments
173 * @return 0 ok, 1 on error
176 main(int argc, char *const *argv)
178 struct GNUNET_GETOPT_CommandLineOption options[] = {
179 GNUNET_GETOPT_option_verbose(&verbose),
181 GNUNET_GETOPT_OPTION_END
184 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
191 "gnunet-unindex [OPTIONS] FILENAME",
193 "Unindex a file that was previously indexed with gnunet-publish."),
199 GNUNET_free((void *)argv);
203 /* end of gnunet-unindex.c */