GNUnet 0.21.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 "platform.h"
26
27#include "gnunet_fs_service.h"
28
32static int ret;
33
37static struct GNUNET_FS_Handle *fs;
38
43
48
52static unsigned int verbose;
53
54
64print_indexed (void *cls,
65 const char *filename,
66 const struct GNUNET_HashCode *file_id)
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}
85
86
92static void
93do_shutdown (void *cls)
94{
95 (void) cls;
96 if (NULL != gic)
97 {
99 gic = NULL;
100 }
101 if (NULL != fs)
102 {
104 fs = NULL;
105 }
106}
107
108
117static void
118run (void *cls,
119 char *const *args,
120 const char *cfgfile,
121 const struct GNUNET_CONFIGURATION_Handle *cfg)
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}
148
149
157int
158main (int argc,
159 char *const *argv)
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}
189
190
191/* 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:70
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
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
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 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
int main(int argc, char *const *argv)
The main function to access special file-sharing functions.
Definition: gnunet-fs.c:158
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
static struct GNUNET_FS_Handle * fs
Handle to FS service.
Definition: gnunet-fs.c:37
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:3244
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3310
@ 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:562
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
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
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.