GNUnet 0.22.0
gnunet-fs.c File Reference

special file-sharing functions More...

Include dependency graph for gnunet-fs.c:

Go to the source code of this file.

Functions

static enum GNUNET_GenericReturnValue print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode *file_id)
 Print indexed filenames to stdout. More...
 
static void do_shutdown (void *cls)
 Function run on shutdown. 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 struct GNUNET_FS_GetIndexedContextgic
 Handle for the index listing operation. 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 enum GNUNET_GenericReturnValue 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 62 of file gnunet-fs.c.

65{
66 if (NULL == filename)
67 {
68 gic = NULL;
70 return GNUNET_OK;
71 }
72 if (verbose)
73 fprintf (stdout,
74 "%s: %s\n",
75 GNUNET_h2s (file_id),
76 filename);
77 else
78 fprintf (stdout,
79 "%s\n",
80 filename);
81 return GNUNET_OK;
82}
static char * filename
static struct GNUNET_FS_GetIndexedContext * gic
Handle for the index listing operation.
Definition: gnunet-fs.c:40
static unsigned int verbose
Option -v given?
Definition: gnunet-fs.c:50
@ GNUNET_OK
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:566

References filename, gic, GNUNET_h2s(), GNUNET_OK, GNUNET_SCHEDULER_shutdown(), and verbose.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Function run on shutdown.

Parameters
clsNULL

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

92{
93 (void) cls;
94 if (NULL != gic)
95 {
97 gic = NULL;
98 }
99 if (NULL != fs)
100 {
102 fs = NULL;
103 }
104}
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:35
void GNUNET_FS_get_indexed_files_cancel(struct GNUNET_FS_GetIndexedContext *gic)
Cancel iteration over all indexed files.
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3330

References fs, gic, GNUNET_FS_get_indexed_files_cancel(), and GNUNET_FS_stop().

Referenced by run().

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 116 of file gnunet-fs.c.

120{
121 if (! list_indexed_files)
122 return;
124 NULL);
126 "gnunet-fs",
127 NULL,
128 NULL,
131 if (NULL == fs)
132 {
133 ret = 1;
134 return;
135 }
138 NULL);
139 if (NULL == gic)
140 {
141 ret = 2;
143 return;
144 }
145}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static int ret
Return value.
Definition: gnunet-fs.c:30
static void do_shutdown(void *cls)
Function run on shutdown.
Definition: gnunet-fs.c:91
static int list_indexed_files
Option -i given?
Definition: gnunet-fs.c:45
static enum GNUNET_GenericReturnValue print_indexed(void *cls, const char *filename, const struct GNUNET_HashCode *file_id)
Print indexed filenames to stdout.
Definition: gnunet-fs.c:62
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.
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
@ GNUNET_FS_FLAGS_NONE
No special flags set.
@ GNUNET_FS_OPTIONS_END
Last option in the VARARG list.
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:1338

References cfg, do_shutdown(), fs, gic, GNUNET_FS_FLAGS_NONE, GNUNET_FS_get_indexed_files(), GNUNET_FS_OPTIONS_END, GNUNET_FS_start(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), list_indexed_files, print_indexed(), and ret.

Referenced by main().

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 156 of file gnunet-fs.c.

158{
161 "list-indexed",
163 "print a list of all indexed files"),
165
168 };
169
170 if (GNUNET_OK !=
172 &argc, &argv))
173 return 2;
174 ret = (GNUNET_OK ==
175 GNUNET_PROGRAM_run (argc,
176 argv,
177 "gnunet-fs [OPTIONS]",
178 gettext_noop ("Special file-sharing operations"),
179 options,
180 &run,
181 NULL))
182 ? ret
183 : 1;
184 GNUNET_free_nz ((void *) argv);
185 return ret;
186}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
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:116
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the '-V' verbosity option.
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.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue 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,...
Definition: program.c:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1253
Definition of a command line option.

References gettext_noop, GNUNET_free_nz, 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, options, ret, run(), and verbose.

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

Return value.

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

Referenced by main(), and run().

◆ fs

struct GNUNET_FS_Handle* fs
static

Handle to FS service.

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

Referenced by do_shutdown(), get_topo_string_from_file(), GNUNET_CONFIGURATION_parse(), print_key(), publish_inspector(), and run().

◆ gic

◆ list_indexed_files

int list_indexed_files
static

Option -i given?

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

Referenced by main(), and run().

◆ verbose

unsigned int verbose
static

Option -v given?

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

Referenced by main(), and print_indexed().