GNUnet  0.11.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,
59  const char *filename,
60  const struct GNUNET_HashCode *file_id)
61 {
62  if (NULL == filename)
63  {
64  GNUNET_FS_stop (fs);
65  fs = NULL;
66  return GNUNET_OK;
67  }
68  if (verbose)
69  fprintf (stdout, "%s: %s\n", GNUNET_h2s (file_id), filename);
70  else
71  fprintf (stdout, "%s\n", filename);
72  return GNUNET_OK;
73 }
74 
75 
84 static void
85 run (void *cls,
86  char *const *args,
87  const char *cfgfile,
88  const struct GNUNET_CONFIGURATION_Handle *cfg)
89 {
91  {
92  fs = GNUNET_FS_start (cfg,
93  "gnunet-fs",
94  NULL,
95  NULL,
98  if (NULL == fs)
99  {
100  ret = 1;
101  return;
102  }
103  if (NULL == GNUNET_FS_get_indexed_files (fs, &print_indexed, NULL))
104  {
105  ret = 2;
106  GNUNET_FS_stop (fs);
107  fs = NULL;
108  return;
109  }
110  }
111 }
112 
113 
121 int
122 main (int argc, char *const *argv)
123 {
124  struct GNUNET_GETOPT_CommandLineOption options[] = {
126  "list-indexed",
127  gettext_noop (
128  "print a list of all indexed files"),
130 
133  };
134 
135  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
136  return 2;
137  ret = (GNUNET_OK ==
138  GNUNET_PROGRAM_run (argc,
139  argv,
140  "gnunet-fs [OPTIONS]",
141  gettext_noop ("Special file-sharing operations"),
142  options,
143  &run,
144  NULL))
145  ? ret
146  : 1;
147  GNUNET_free ((void *) argv);
148  return ret;
149 }
150 
151 
152 /* end of gnunet-fs.c */
static int list_indexed_files
Option -i given?
Definition: gnunet-fs.c:41
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
Master context for most FS operations.
Definition: fs_api.h:1068
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:1438
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:75
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:3216
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:3141
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.
int main(int argc, char *const *argv)
The main function to access special file-sharing functions.
Definition: gnunet-fs.c:122
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:85
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:367
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69