GNUnet  0.10.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 FPRINTF, GNUNET_FS_stop(), GNUNET_h2s(), GNUNET_OK, and verbose.

Referenced by run().

59 {
60  if (NULL == filename)
61  {
63  fs = NULL;
64  return GNUNET_OK;
65  }
66  if (verbose)
67  FPRINTF (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
68  else
69  FPRINTF (stdout, "%s\n", filename);
70  return GNUNET_OK;
71 }
#define FPRINTF
Definition: plibc.h:683
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:78
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3163
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 83 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().

85 {
87  {
88  fs = GNUNET_FS_start (cfg, "gnunet-fs", NULL, NULL, GNUNET_FS_FLAGS_NONE,
90  if (NULL == fs)
91  {
92  ret = 1;
93  return;
94  }
95  if (NULL == GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL))
96  {
97  ret = 2;
99  fs = NULL;
100  return;
101  }
102  }
103 }
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:3163
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.
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 113 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.

114 {
116 
118  "list-indexed",
119  gettext_noop ("print a list of all indexed files"),
121 
124  };
125 
126  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
127  return 2;
128  ret = (GNUNET_OK ==
129  GNUNET_PROGRAM_run (argc, argv, "gnunet-fs [OPTIONS]",
130  gettext_noop ("Special file-sharing operations"),
131  options, &run, NULL)) ? ret : 1;
132  GNUNET_free ((void*) argv);
133  return ret;
134 }
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: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
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:83
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: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

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().