GNUnet 0.22.0
gnunet-fs.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
25#include "gnunet_fs_service.h"
26
30static int ret;
31
35static struct GNUNET_FS_Handle *fs;
36
41
46
50static unsigned int verbose;
51
52
62print_indexed (void *cls,
63 const char *filename,
64 const struct GNUNET_HashCode *file_id)
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}
83
84
90static void
91do_shutdown (void *cls)
92{
93 (void) cls;
94 if (NULL != gic)
95 {
97 gic = NULL;
98 }
99 if (NULL != fs)
100 {
102 fs = NULL;
103 }
104}
105
106
115static void
116run (void *cls,
117 char *const *args,
118 const char *cfgfile,
119 const struct GNUNET_CONFIGURATION_Handle *cfg)
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}
146
147
155int
156main (int argc,
157 char *const *argv)
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}
187
188
189/* end of gnunet-fs.c */
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 struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
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
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 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
int main(int argc, char *const *argv)
The main function to access special file-sharing functions.
Definition: gnunet-fs.c:156
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
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:35
API for file sharing via GNUnet.
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.
void GNUNET_FS_get_indexed_files_cancel(struct GNUNET_FS_GetIndexedContext *gic)
Cancel iteration 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
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3330
@ GNUNET_FS_FLAGS_NONE
No special flags set.
@ GNUNET_FS_OPTIONS_END
Last option in the VARARG list.
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.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#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
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:566
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
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
Context for GNUNET_FS_get_indexed_files().
Master context for most FS operations.
Definition: fs_api.h:1070
Definition of a command line option.
A 512-bit hashcode.