GNUnet  0.10.x
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 #include "gnunet_fs_service.h"
27 
31 static int ret;
32 
36 static struct GNUNET_FS_Handle *fs;
37 
41 static int list_indexed_files;
42 
46 static unsigned int verbose;
47 
48 
57 static int
58 print_indexed (void *cls, const char *filename, const struct GNUNET_HashCode * file_id)
59 {
60  if (NULL == filename)
61  {
62  GNUNET_FS_stop (fs);
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 }
72 
73 
82 static void
83 run (void *cls, char *const *args, const char *cfgfile,
84  const struct GNUNET_CONFIGURATION_Handle *cfg)
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;
98  GNUNET_FS_stop (fs);
99  fs = NULL;
100  return;
101  }
102  }
103 }
104 
112 int
113 main (int argc, char *const *argv)
114 {
115  struct GNUNET_GETOPT_CommandLineOption options[] = {
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 }
135 
136 /* end of gnunet-fs.c */
static int list_indexed_files
Option -i given?
Definition: gnunet-fs.c:41
#define FPRINTF
Definition: plibc.h:683
Master context for most FS operations.
Definition: fs_api.h:1087
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_verbose(unsigned int *level)
Define the &#39;-V&#39; verbosity option.
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
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
Last option in the VARARG list.
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
Definition of a command line option.
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3163
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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.
static unsigned int verbose
Option -v given?
Definition: gnunet-fs.c:46
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 char * filename
A 512-bit hashcode.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
int main(int argc, char *const *argv)
The main function to access special file-sharing functions.
Definition: gnunet-fs.c:113
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
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
configuration data
Definition: configuration.c:85
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