GNUnet 0.21.0
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 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 64 of file gnunet-fs.c.

67{
68 if (NULL == filename)
69 {
70 gic = NULL;
72 return GNUNET_OK;
73 }
74 if (verbose)
75 fprintf (stdout,
76 "%s: %s\n",
77 GNUNET_h2s (file_id),
78 filename);
79 else
80 fprintf (stdout,
81 "%s\n",
82 filename);
83 return GNUNET_OK;
84}
static char * filename
static struct GNUNET_FS_GetIndexedContext * gic
Handle for the index listing operation.
Definition: gnunet-fs.c:42
static unsigned int verbose
Option -v given?
Definition: gnunet-fs.c:52
@ 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:562

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

94{
95 (void) cls;
96 if (NULL != gic)
97 {
99 gic = NULL;
100 }
101 if (NULL != fs)
102 {
104 fs = NULL;
105 }
106}
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:37
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:3310

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

122{
123 if (! list_indexed_files)
124 return;
126 NULL);
128 "gnunet-fs",
129 NULL,
130 NULL,
133 if (NULL == fs)
134 {
135 ret = 1;
136 return;
137 }
140 NULL);
141 if (NULL == gic)
142 {
143 ret = 2;
145 return;
146 }
147}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static int ret
Return value.
Definition: gnunet-fs.c:32
static void do_shutdown(void *cls)
Function run on shutdown.
Definition: gnunet-fs.c:93
static int list_indexed_files
Option -i given?
Definition: gnunet-fs.c:47
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:64
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:3244
@ 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:1334

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

160{
163 "list-indexed",
165 "print a list of all indexed files"),
167
170 };
171
172 if (GNUNET_OK !=
174 &argc, &argv))
175 return 2;
176 ret = (GNUNET_OK ==
177 GNUNET_PROGRAM_run (argc,
178 argv,
179 "gnunet-fs [OPTIONS]",
180 gettext_noop ("Special file-sharing operations"),
181 options,
182 &run,
183 NULL))
184 ? ret
185 : 1;
186 GNUNET_free_nz ((void *) argv);
187 return ret;
188}
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:70
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:118
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:1230
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 32 of file gnunet-fs.c.

Referenced by main(), and run().

◆ fs

struct GNUNET_FS_Handle* fs
static

◆ gic

◆ list_indexed_files

int list_indexed_files
static

Option -i given?

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

Referenced by main(), and run().

◆ verbose

unsigned int verbose
static

Option -v given?

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

Referenced by main(), and print_indexed().