GNUnet 0.22.2
gnunet-unindex.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
28#include "platform.h"
29
30#include "gnunet_fs_service.h"
31
32static int ret;
33
34static unsigned int verbose;
35
36static const struct GNUNET_CONFIGURATION_Handle *cfg;
37
38static struct GNUNET_FS_Handle *ctx;
39
41
42
43static void
44cleanup_task (void *cls)
45{
47 ctx = NULL;
48}
49
50
51static void
52shutdown_task (void *cls)
53{
55
56 if (uc != NULL)
57 {
58 u = uc;
59 uc = NULL;
61 }
62}
63
64
78static void *
79progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info)
80{
81 const char *s;
82
83 switch (info->status)
84 {
86 break;
87
89 if (verbose)
90 {
91 s = GNUNET_STRINGS_relative_time_to_string (info->value.unindex.eta,
93 fprintf (stdout,
94 _ ("Unindexing at %llu/%llu (%s remaining)\n"),
95 (unsigned long long) info->value.unindex.completed,
96 (unsigned long long) info->value.unindex.size,
97 s);
98 }
99 break;
100
102 fprintf (stderr,
103 _ ("Error unindexing: %s.\n"),
104 info->value.unindex.specifics.error.message);
106 break;
107
109 fprintf (stdout, "%s", _ ("Unindexing done.\n"));
111 break;
112
115 break;
116
117 default:
118 fprintf (stderr, _ ("Unexpected status: %d\n"), info->status);
119 break;
120 }
121 return NULL;
122}
123
124
133static void
134run (void *cls,
135 char *const *args,
136 const char *cfgfile,
137 const struct GNUNET_CONFIGURATION_Handle *c)
138{
139 /* check arguments */
140 if ((args[0] == NULL) || (args[1] != NULL))
141 {
142 printf (_ ("You must specify one and only one filename for unindexing.\n"));
143 ret = -1;
144 return;
145 }
146 cfg = c;
148 "gnunet-unindex",
150 NULL,
153 if (NULL == ctx)
154 {
155 fprintf (stderr, _ ("Could not initialize `%s' subsystem.\n"), "FS");
156 ret = 1;
157 return;
158 }
159 uc = GNUNET_FS_unindex_start (ctx, args[0], NULL);
160 if (NULL == uc)
161 {
162 fprintf (stderr, "%s", _ ("Could not start unindex operation.\n"));
164 return;
165 }
167}
168
169
177int
178main (int argc, char *const *argv)
179{
182
184 };
185
186 ret = (GNUNET_OK ==
189 argc,
190 argv,
191 "gnunet-unindex [OPTIONS] FILENAME",
193 "Unindex a file that was previously indexed with gnunet-publish."),
194 options,
195 &run,
196 NULL))
197 ? ret
198 : 1;
199 return ret;
200}
201
202
203/* end of gnunet-unindex.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static mp_limb_t u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
#define gettext_noop(String)
Definition: gettext.h:74
#define info
static unsigned int verbose
static const struct GNUNET_CONFIGURATION_Handle * cfg
static struct GNUNET_FS_UnindexContext * uc
static void cleanup_task(void *cls)
static void shutdown_task(void *cls)
static int ret
static void * progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info)
Called by FS client to give information about the progress of an operation.
static struct GNUNET_FS_Handle * ctx
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run by the scheduler.
int main(int argc, char *const *argv)
The main function to unindex content.
API for file sharing via GNUnet.
void GNUNET_FS_unindex_stop(struct GNUNET_FS_UnindexContext *uc)
Clean up after completion of an unindex operation.
Definition: fs_unindex.c:838
struct GNUNET_FS_Handle * GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, void *upcb_cls, enum GNUNET_FS_Flags flags,...)
Setup a connection to the file-sharing service.
Definition: fs_api.c:3264
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3330
struct GNUNET_FS_UnindexContext * GNUNET_FS_unindex_start(struct GNUNET_FS_Handle *h, const char *filename, void *cctx)
Unindex a file.
Definition: fs_unindex.c:796
@ GNUNET_FS_FLAGS_NONE
No special flags set.
@ GNUNET_FS_OPTIONS_END
Last option in the VARARG list.
@ GNUNET_FS_STATUS_UNINDEX_PROGRESS
Notification that we made progress unindexing a file.
@ GNUNET_FS_STATUS_UNINDEX_START
Notification that we started to unindex a file.
@ GNUNET_FS_STATUS_UNINDEX_STOPPED
Notification that the unindexing of this file was stopped (final event for this action).
@ GNUNET_FS_STATUS_UNINDEX_COMPLETED
Notification that the unindexing of this file was completed.
@ GNUNET_FS_STATUS_UNINDEX_ERROR
Notification that we encountered an error unindexing a file.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
@ GNUNET_OK
@ GNUNET_YES
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:407
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1339
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1304
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:579
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Master context for most FS operations.
Definition: fs_api.h:1070
Argument given to the progress callback with information about what is going on.
Handle for controlling an unindexing operation.
Definition: fs_api.h:1351
Definition of a command line option.