GNUnet  0.10.x
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 #include "gnunet_fs_service.h"
30 
31 static int ret;
32 
33 static unsigned int verbose;
34 
35 static const struct GNUNET_CONFIGURATION_Handle *cfg;
36 
37 static struct GNUNET_FS_Handle *ctx;
38 
40 
41 
42 static void
43 cleanup_task(void *cls)
44 {
45  GNUNET_FS_stop(ctx);
46  ctx = NULL;
47 }
48 
49 
50 static void
51 shutdown_task(void *cls)
52 {
53  struct GNUNET_FS_UnindexContext *u;
54 
55  if (uc != NULL)
56  {
57  u = uc;
58  uc = NULL;
60  }
61 }
62 
76 static void *
77 progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *info)
78 {
79  const char *s;
80 
81  switch (info->status)
82  {
84  break;
85 
87  if (verbose)
88  {
90  GNUNET_YES);
91  fprintf(stdout,
92  _("Unindexing at %llu/%llu (%s remaining)\n"),
93  (unsigned long long)info->value.unindex.completed,
94  (unsigned long long)info->value.unindex.size,
95  s);
96  }
97  break;
98 
100  fprintf(stderr,
101  _("Error unindexing: %s.\n"),
102  info->value.unindex.specifics.error.message);
104  break;
105 
107  fprintf(stdout, "%s", _("Unindexing done.\n"));
109  break;
110 
113  break;
114 
115  default:
116  fprintf(stderr, _("Unexpected status: %d\n"), info->status);
117  break;
118  }
119  return NULL;
120 }
121 
122 
131 static void
132 run(void *cls,
133  char *const *args,
134  const char *cfgfile,
135  const struct GNUNET_CONFIGURATION_Handle *c)
136 {
137  /* check arguments */
138  if ((args[0] == NULL) || (args[1] != NULL))
139  {
140  printf(_("You must specify one and only one filename for unindexing.\n"));
141  ret = -1;
142  return;
143  }
144  cfg = c;
145  ctx = GNUNET_FS_start(cfg,
146  "gnunet-unindex",
147  &progress_cb,
148  NULL,
151  if (NULL == ctx)
152  {
153  fprintf(stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
154  ret = 1;
155  return;
156  }
157  uc = GNUNET_FS_unindex_start(ctx, args[0], NULL);
158  if (NULL == uc)
159  {
160  fprintf(stderr, "%s", _("Could not start unindex operation.\n"));
161  GNUNET_FS_stop(ctx);
162  return;
163  }
165 }
166 
167 
175 int
176 main(int argc, char *const *argv)
177 {
178  struct GNUNET_GETOPT_CommandLineOption options[] = {
180 
182  };
183 
184  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
185  return 2;
186 
187  ret = (GNUNET_OK ==
189  argc,
190  argv,
191  "gnunet-unindex [OPTIONS] FILENAME",
192  gettext_noop(
193  "Unindex a file that was previously indexed with gnunet-publish."),
194  options,
195  &run,
196  NULL))
197  ? ret
198  : 1;
199  GNUNET_free((void *)argv);
200  return ret;
201 }
202 
203 /* end of gnunet-unindex.c */
static int ret
void GNUNET_FS_unindex_stop(struct GNUNET_FS_UnindexContext *uc)
Clean up after completion of an unindex operation.
Definition: fs_unindex.c:835
Notification that we started to unindex a file.
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.
Notification that we made progress unindexing a file.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
Master context for most FS operations.
Definition: fs_api.h:1056
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the &#39;-V&#39; verbosity option.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
static struct GNUNET_FS_UnindexContext * uc
Last option in the VARARG list.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3215
Handle for controlling an unindexing operation.
Definition: fs_api.h:1334
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static void shutdown_task(void *cls)
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:3140
No special flags set.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
union GNUNET_FS_ProgressInfo::@28 value
Values that depend on the event type.
static unsigned int verbose
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:793
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:1264
enum GNUNET_FS_Status status
Specific status code (determines the event type).
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:686
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.
static struct GNUNET_FS_Handle * ctx
Notification that the unindexing of this file was stopped (final event for this action).
Notification that the unindexing of this file was completed.
int main(int argc, char *const *argv)
The main function to unindex content.
configuration data
Definition: configuration.c:83
int GNUNET_PROGRAM_run(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, parse options).
Definition: program.c:367
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_FS_ProgressInfo::@28::@32 unindex
Values for all "GNUNET_FS_STATUS_UNINDEX_*" events.
Notification that we encountered an error unindexing a file.
static const struct GNUNET_CONFIGURATION_Handle * cfg
#define GNUNET_free(ptr)
Wrapper around free.
Argument given to the progress callback with information about what is going on.
static void cleanup_task(void *cls)
#define gettext_noop(String)
Definition: gettext.h:69