GNUnet  0.10.x
Functions | Variables
gnunet-unindex.c File Reference

unindex files published on GNUnet More...

#include "platform.h"
#include "gnunet_fs_service.h"
Include dependency graph for gnunet-unindex.c:

Go to the source code of this file.

Functions

static void cleanup_task (void *cls)
 
static void shutdown_task (void *cls)
 
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. More...
 
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. More...
 
int main (int argc, char *const *argv)
 The main function to unindex content. More...
 

Variables

static int ret
 
static unsigned int verbose
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 
static struct GNUNET_FS_Handlectx
 
static struct GNUNET_FS_UnindexContextuc
 

Detailed Description

unindex files published on GNUnet

Author
Christian Grothoff
Krista Bennett
James Blackwell
Igor Wronsky

Definition in file gnunet-unindex.c.

Function Documentation

◆ cleanup_task()

static void cleanup_task ( void *  cls)
static

Definition at line 43 of file gnunet-unindex.c.

References GNUNET_FS_stop().

Referenced by progress_cb().

44 {
46  ctx = NULL;
47 }
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3163
static struct GNUNET_FS_Handle * ctx
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Definition at line 51 of file gnunet-unindex.c.

References GNUNET_FS_unindex_stop(), and uc.

Referenced by run().

52 {
53  struct GNUNET_FS_UnindexContext *u;
54 
55  if (uc != NULL)
56  {
57  u = uc;
58  uc = NULL;
60  }
61 }
void GNUNET_FS_unindex_stop(struct GNUNET_FS_UnindexContext *uc)
Clean up after completion of an unindex operation.
Definition: fs_unindex.c:833
static struct GNUNET_FS_UnindexContext * uc
Handle for controlling an unindexing operation.
Definition: fs_api.h:1369
Here is the call graph for this function:
Here is the caller graph for this function:

◆ progress_cb()

static void* progress_cb ( void *  cls,
const struct GNUNET_FS_ProgressInfo info 
)
static

Called by FS client to give information about the progress of an operation.

Parameters
clsclosure
infodetails about the event, specifying the event type and various bits about the event
Returns
client-context (for the next progress call for this operation; should be set to NULL for SUSPEND and STOPPED events). The value returned will be passed to future callbacks in the respective field in the GNUNET_FS_ProgressInfo struct.

Definition at line 77 of file gnunet-unindex.c.

References _, cleanup_task(), FPRINTF, GNUNET_FS_STATUS_UNINDEX_COMPLETED, GNUNET_FS_STATUS_UNINDEX_ERROR, GNUNET_FS_STATUS_UNINDEX_PROGRESS, GNUNET_FS_STATUS_UNINDEX_START, GNUNET_FS_STATUS_UNINDEX_STOPPED, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, GNUNET_FS_ProgressInfo::status, GNUNET_FS_ProgressInfo::unindex, GNUNET_FS_ProgressInfo::value, and verbose.

Referenced by run().

78 {
79  const char *s;
80 
81  switch (info->status)
82  {
84  break;
86  if (verbose)
87  {
89  FPRINTF (stdout, _("Unindexing at %llu/%llu (%s remaining)\n"),
90  (unsigned long long) info->value.unindex.completed,
91  (unsigned long long) info->value.unindex.size, s);
92  }
93  break;
95  FPRINTF (stderr, _("Error unindexing: %s.\n"),
96  info->value.unindex.specifics.error.message);
98  break;
100  FPRINTF (stdout, "%s", _("Unindexing done.\n"));
102  break;
105  break;
106  default:
107  FPRINTF (stderr, _("Unexpected status: %d\n"), info->status);
108  break;
109  }
110  return NULL;
111 }
Notification that we started to unindex a file.
#define FPRINTF
Definition: plibc.h:683
Notification that we made progress unindexing a file.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
union GNUNET_FS_ProgressInfo::@28 value
Values that depend on the event type.
static unsigned int verbose
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:1273
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:727
Notification that the unindexing of this file was stopped (final event for this action).
Notification that the unindexing of this file was completed.
#define GNUNET_YES
Definition: gnunet_common.h:80
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 void cleanup_task(void *cls)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 123 of file gnunet-unindex.c.

References _, FPRINTF, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END, GNUNET_FS_start(), GNUNET_FS_stop(), GNUNET_FS_unindex_start(), GNUNET_SCHEDULER_add_shutdown(), progress_cb(), ret, and shutdown_task().

Referenced by main().

125 {
126  /* check arguments */
127  if ((args[0] == NULL) || (args[1] != NULL))
128  {
129  printf (_("You must specify one and only one filename for unindexing.\n"));
130  ret = -1;
131  return;
132  }
133  cfg = c;
134  ctx =
135  GNUNET_FS_start (cfg, "gnunet-unindex", &progress_cb, NULL,
137  if (NULL == ctx)
138  {
139  FPRINTF (stderr, _("Could not initialize `%s' subsystem.\n"), "FS");
140  ret = 1;
141  return;
142  }
143  uc = GNUNET_FS_unindex_start (ctx, args[0], NULL);
144  if (NULL == uc)
145  {
146  FPRINTF (stderr, "%s", _("Could not start unindex operation.\n"));
148  return;
149  }
151  NULL);
152 }
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.
#define FPRINTF
Definition: plibc.h:683
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:1293
static struct GNUNET_FS_UnindexContext * uc
Last option in the VARARG list.
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3163
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:3097
No special flags set.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
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:791
static struct GNUNET_FS_Handle * ctx
static const struct GNUNET_CONFIGURATION_Handle * cfg
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function to unindex content.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 163 of file gnunet-unindex.c.

References gettext_noop, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_verbose(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), ret, run(), and verbose.

164 {
166 
168 
170  };
171 
172  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
173  return 2;
174 
175  ret = (GNUNET_OK ==
176  GNUNET_PROGRAM_run (argc, argv, "gnunet-unindex [OPTIONS] FILENAME",
178  ("Unindex a file that was previously indexed with gnunet-publish."),
179  options, &run, NULL)) ? ret : 1;
180  GNUNET_free ((void*) argv);
181  return ret;
182 }
static int ret
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' 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:1521
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static unsigned int verbose
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 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:361
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

Definition at line 31 of file gnunet-unindex.c.

Referenced by main(), and run().

◆ verbose

unsigned int verbose
static

Definition at line 33 of file gnunet-unindex.c.

Referenced by main(), and progress_cb().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Definition at line 35 of file gnunet-unindex.c.

◆ ctx

struct GNUNET_FS_Handle* ctx
static

Definition at line 37 of file gnunet-unindex.c.

◆ uc

struct GNUNET_FS_UnindexContext* uc
static