GNUnet  0.11.x
Functions | Variables
gnunet-fs.c File Reference

special file-sharing functions More...

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

Go to the source code of this file.

Functions

static int print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode *file_id)
 Print indexed filenames to stdout. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 The main function to access special file-sharing functions. More...
 

Variables

static int ret
 Return value. More...
 
static struct GNUNET_FS_Handlefs
 Handle to FS service. More...
 
static int list_indexed_files
 Option -i given? More...
 
static unsigned int verbose
 Option -v given? More...
 

Detailed Description

special file-sharing functions

Author
Christian Grothoff

Definition in file gnunet-fs.c.

Function Documentation

◆ print_indexed()

static int print_indexed ( void *  cls,
const char *  filename,
const struct GNUNET_HashCode file_id 
)
static

Print indexed filenames to stdout.

Parameters
clsclosure
filenamethe name of the file
file_idhash of the contents of the indexed file
Returns
GNUNET_OK to continue iteration

Definition at line 58 of file gnunet-fs.c.

References GNUNET_FS_stop(), GNUNET_h2s(), GNUNET_OK, and verbose.

Referenced by run().

61 {
62  if (NULL == filename)
63  {
65  fs = NULL;
66  return GNUNET_OK;
67  }
68  if (verbose)
69  fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
70  else
71  fprintf (stdout, "%s\n", filename);
72  return GNUNET_OK;
73 }
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3216
static unsigned int verbose
Option -v given?
Definition: gnunet-fs.c:46
static char * filename
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
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 cfg 
)
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!)
cfgconfiguration

Definition at line 85 of file gnunet-fs.c.

References GNUNET_FS_FLAGS_NONE, GNUNET_FS_get_indexed_files(), GNUNET_FS_OPTIONS_END, GNUNET_FS_start(), GNUNET_FS_stop(), list_indexed_files, print_indexed(), and ret.

Referenced by main().

89 {
91  {
92  fs = GNUNET_FS_start (cfg,
93  "gnunet-fs",
94  NULL,
95  NULL,
98  if (NULL == fs)
99  {
100  ret = 1;
101  return;
102  }
103  if (NULL == GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL))
104  {
105  ret = 2;
106  GNUNET_FS_stop (fs);
107  fs = NULL;
108  return;
109  }
110  }
111 }
static int list_indexed_files
Option -i given?
Definition: gnunet-fs.c:41
static int print_indexed(void *cls, const char *filename, const struct GNUNET_HashCode *file_id)
Print indexed filenames to stdout.
Definition: gnunet-fs.c:58
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:3216
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:3141
No special flags set.
struct GNUNET_FS_GetIndexedContext * GNUNET_FS_get_indexed_files(struct GNUNET_FS_Handle *h, GNUNET_FS_IndexedFileProcessor iterator, void *iterator_cls)
Iterate over all indexed files.
static int ret
Return value.
Definition: gnunet-fs.c:31
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:36
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 access special file-sharing functions.

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

Definition at line 122 of file gnunet-fs.c.

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

123 {
126  "list-indexed",
127  gettext_noop (
128  "print a list of all indexed files"),
130 
133  };
134 
135  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
136  return 2;
137  ret = (GNUNET_OK ==
138  GNUNET_PROGRAM_run (argc,
139  argv,
140  "gnunet-fs [OPTIONS]",
141  gettext_noop ("Special file-sharing operations"),
142  options,
143  &run,
144  NULL))
145  ? ret
146  : 1;
147  GNUNET_free ((void *) argv);
148  return ret;
149 }
static int list_indexed_files
Option -i given?
Definition: gnunet-fs.c:41
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:1438
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static unsigned int verbose
Option -v given?
Definition: gnunet-fs.c:46
static int ret
Return value.
Definition: gnunet-fs.c:31
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
Definition: gnunet-fs.c:85
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
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_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

Return value.

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

Referenced by main(), and run().

◆ fs

struct GNUNET_FS_Handle* fs
static

◆ list_indexed_files

int list_indexed_files
static

Option -i given?

Definition at line 41 of file gnunet-fs.c.

Referenced by main(), and run().

◆ verbose

unsigned int verbose
static

Option -v given?

Definition at line 46 of file gnunet-fs.c.

Referenced by main(), and print_indexed().