aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-directory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-directory.c')
-rw-r--r--src/fs/gnunet-directory.c212
1 files changed, 0 insertions, 212 deletions
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c
deleted file mode 100644
index ab9f2905a..000000000
--- a/src/fs/gnunet-directory.c
+++ /dev/null
@@ -1,212 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 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 */
20/**
21 * @file fs/gnunet-directory.c
22 * @brief display content of GNUnet directories
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26
27#include "gnunet_fs_service.h"
28
29static int ret;
30
31/**
32 * Print a meta data entry.
33 *
34 * @param cls closure (unused)
35 * @param plugin_name name of the plugin that generated the meta data
36 * @param type type of the keyword
37 * @param format format of data
38 * @param data_mime_type mime type of data
39 * @param data value of the meta data
40 * @param data_size number of bytes in @a data
41 * @return always 0 (to continue iterating)
42 */
43static int
44item_printer (void *cls,
45 const char *plugin_name,
46 enum EXTRACTOR_MetaType type,
47 enum EXTRACTOR_MetaFormat format,
48 const char *data_mime_type,
49 const char *data,
50 size_t data_size)
51{
52 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
53 {
54 printf (_ ("\t<original file embedded in %u bytes of meta data>\n"),
55 (unsigned int) data_size);
56 return 0;
57 }
58 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
59 (format != EXTRACTOR_METAFORMAT_C_STRING))
60 return 0;
61 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
62 return 0;
63#if HAVE_LIBEXTRACTOR
64 printf ("\t%20s: %s\n",
65 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
66 EXTRACTOR_metatype_to_string (type)),
67 data);
68#else
69 printf ("\t%20d: %s\n", type, data);
70#endif
71 return 0;
72}
73
74
75/**
76 * Print an entry in a directory.
77 *
78 * @param cls closure (not used)
79 * @param filename name of the file in the directory
80 * @param uri URI of the file
81 * @param meta metadata for the file; metadata for
82 * the directory if everything else is NULL/zero
83 * @param length length of the available data for the file
84 * (of type size_t since data must certainly fit
85 * into memory; if files are larger than size_t
86 * permits, then they will certainly not be
87 * embedded with the directory itself).
88 * @param data data available for the file (length bytes)
89 */
90static void
91print_entry (void *cls,
92 const char *filename,
93 const struct GNUNET_FS_Uri *uri,
94 const struct GNUNET_FS_MetaData *meta,
95 size_t length,
96 const void *data)
97{
98 char *string;
99 char *name;
100
101 name = GNUNET_FS_meta_data_get_by_type (
102 meta,
103 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
104 if (uri == NULL)
105 {
106 printf (_ ("Directory `%s' meta data:\n"), name ? name : "");
107 GNUNET_FS_meta_data_iterate (meta, &item_printer, NULL);
108 printf ("\n");
109 printf (_ ("Directory `%s' contents:\n"), name ? name : "");
110 GNUNET_free (name);
111 return;
112 }
113 string = GNUNET_FS_uri_to_string (uri);
114 printf ("%s (%s):\n", name ? name : "", string);
115 GNUNET_free (string);
116 GNUNET_FS_meta_data_iterate (meta, &item_printer, NULL);
117 printf ("\n");
118 GNUNET_free (name);
119}
120
121
122/**
123 * Main function that will be run by the scheduler.
124 *
125 * @param cls closure
126 * @param args remaining command-line arguments
127 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
128 * @param cfg configuration
129 */
130static void
131run (void *cls,
132 char *const *args,
133 const char *cfgfile,
134 const struct GNUNET_CONFIGURATION_Handle *cfg)
135{
136 struct GNUNET_DISK_MapHandle *map;
137 struct GNUNET_DISK_FileHandle *h;
138 void *data;
139 size_t len;
140 uint64_t size;
141 const char *filename;
142 int i;
143
144 if (NULL == args[0])
145 {
146 fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n"));
147 ret = 1;
148 return;
149 }
150 i = 0;
151 while (NULL != (filename = args[i++]))
152 {
153 if ((GNUNET_OK !=
154 GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) ||
155 (NULL == (h = GNUNET_DISK_file_open (filename,
156 GNUNET_DISK_OPEN_READ,
157 GNUNET_DISK_PERM_NONE))))
158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 _ ("Failed to read directory `%s'\n"),
161 filename);
162 ret = 1;
163 continue;
164 }
165 len = (size_t) size;
166 data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
167 GNUNET_assert (NULL != data);
168 if (GNUNET_OK !=
169 GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL))
170 fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename);
171 else
172 printf ("\n");
173 GNUNET_DISK_file_unmap (map);
174 GNUNET_DISK_file_close (h);
175 }
176}
177
178
179/**
180 * The main function to inspect GNUnet directories.
181 *
182 * @param argc number of arguments from the command line
183 * @param argv command line arguments
184 * @return 0 ok, 1 on error
185 */
186int
187main (int argc, char *const *argv)
188{
189 static struct GNUNET_GETOPT_CommandLineOption options[] = {
190 GNUNET_GETOPT_OPTION_END
191 };
192
193 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
194 return 2;
195
196 ret = (GNUNET_OK ==
197 GNUNET_PROGRAM_run (argc,
198 argv,
199 "gnunet-directory [OPTIONS] FILENAME",
200 gettext_noop (
201 "Display contents of a GNUnet directory"),
202 options,
203 &run,
204 NULL))
205 ? ret
206 : 1;
207 GNUNET_free_nz ((void *) argv);
208 return ret;
209}
210
211
212/* end of gnunet-directory.c */