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.c171
1 files changed, 86 insertions, 85 deletions
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c
index 4cce69d72..f33db109f 100644
--- a/src/fs/gnunet-directory.c
+++ b/src/fs/gnunet-directory.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file fs/gnunet-directory.c 21 * @file fs/gnunet-directory.c
22 * @brief display content of GNUnet directories 22 * @brief display content of GNUnet directories
@@ -40,32 +40,32 @@ static int ret;
40 * @return always 0 (to continue iterating) 40 * @return always 0 (to continue iterating)
41 */ 41 */
42static int 42static int
43item_printer (void *cls, 43item_printer(void *cls,
44 const char *plugin_name, 44 const char *plugin_name,
45 enum EXTRACTOR_MetaType type, 45 enum EXTRACTOR_MetaType type,
46 enum EXTRACTOR_MetaFormat format, 46 enum EXTRACTOR_MetaFormat format,
47 const char *data_mime_type, 47 const char *data_mime_type,
48 const char *data, 48 const char *data,
49 size_t data_size) 49 size_t data_size)
50{ 50{
51 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 51 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
52 { 52 {
53 printf (_ ("\t<original file embedded in %u bytes of meta data>\n"), 53 printf(_("\t<original file embedded in %u bytes of meta data>\n"),
54 (unsigned int) data_size); 54 (unsigned int)data_size);
55 return 0; 55 return 0;
56 } 56 }
57 if ((format != EXTRACTOR_METAFORMAT_UTF8) && 57 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
58 (format != EXTRACTOR_METAFORMAT_C_STRING)) 58 (format != EXTRACTOR_METAFORMAT_C_STRING))
59 return 0; 59 return 0;
60 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) 60 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
61 return 0; 61 return 0;
62#if HAVE_LIBEXTRACTOR 62#if HAVE_LIBEXTRACTOR
63 printf ("\t%20s: %s\n", 63 printf("\t%20s: %s\n",
64 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, 64 dgettext(LIBEXTRACTOR_GETTEXT_DOMAIN,
65 EXTRACTOR_metatype_to_string (type)), 65 EXTRACTOR_metatype_to_string(type)),
66 data); 66 data);
67#else 67#else
68 printf ("\t%20d: %s\n", type, data); 68 printf("\t%20d: %s\n", type, data);
69#endif 69#endif
70 return 0; 70 return 0;
71} 71}
@@ -87,34 +87,34 @@ item_printer (void *cls,
87 * @param data data available for the file (length bytes) 87 * @param data data available for the file (length bytes)
88 */ 88 */
89static void 89static void
90print_entry (void *cls, 90print_entry(void *cls,
91 const char *filename, 91 const char *filename,
92 const struct GNUNET_FS_Uri *uri, 92 const struct GNUNET_FS_Uri *uri,
93 const struct GNUNET_CONTAINER_MetaData *meta, 93 const struct GNUNET_CONTAINER_MetaData *meta,
94 size_t length, 94 size_t length,
95 const void *data) 95 const void *data)
96{ 96{
97 char *string; 97 char *string;
98 char *name; 98 char *name;
99 99
100 name = GNUNET_CONTAINER_meta_data_get_by_type ( 100 name = GNUNET_CONTAINER_meta_data_get_by_type(
101 meta, 101 meta,
102 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 102 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
103 if (uri == NULL) 103 if (uri == NULL)
104 { 104 {
105 printf (_ ("Directory `%s' meta data:\n"), name ? name : ""); 105 printf(_("Directory `%s' meta data:\n"), name ? name : "");
106 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); 106 GNUNET_CONTAINER_meta_data_iterate(meta, &item_printer, NULL);
107 printf ("\n"); 107 printf("\n");
108 printf (_ ("Directory `%s' contents:\n"), name ? name : ""); 108 printf(_("Directory `%s' contents:\n"), name ? name : "");
109 GNUNET_free_non_null (name); 109 GNUNET_free_non_null(name);
110 return; 110 return;
111 } 111 }
112 string = GNUNET_FS_uri_to_string (uri); 112 string = GNUNET_FS_uri_to_string(uri);
113 printf ("%s (%s):\n", name ? name : "", string); 113 printf("%s (%s):\n", name ? name : "", string);
114 GNUNET_free (string); 114 GNUNET_free(string);
115 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL); 115 GNUNET_CONTAINER_meta_data_iterate(meta, &item_printer, NULL);
116 printf ("\n"); 116 printf("\n");
117 GNUNET_free_non_null (name); 117 GNUNET_free_non_null(name);
118} 118}
119 119
120 120
@@ -127,10 +127,10 @@ print_entry (void *cls,
127 * @param cfg configuration 127 * @param cfg configuration
128 */ 128 */
129static void 129static void
130run (void *cls, 130run(void *cls,
131 char *const *args, 131 char *const *args,
132 const char *cfgfile, 132 const char *cfgfile,
133 const struct GNUNET_CONFIGURATION_Handle *cfg) 133 const struct GNUNET_CONFIGURATION_Handle *cfg)
134{ 134{
135 struct GNUNET_DISK_MapHandle *map; 135 struct GNUNET_DISK_MapHandle *map;
136 struct GNUNET_DISK_FileHandle *h; 136 struct GNUNET_DISK_FileHandle *h;
@@ -141,37 +141,37 @@ run (void *cls,
141 int i; 141 int i;
142 142
143 if (NULL == args[0]) 143 if (NULL == args[0])
144 { 144 {
145 fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n")); 145 fprintf(stderr, "%s", _("You must specify a filename to inspect.\n"));
146 ret = 1; 146 ret = 1;
147 return; 147 return;
148 } 148 }
149 i = 0; 149 i = 0;
150 while (NULL != (filename = args[i++])) 150 while (NULL != (filename = args[i++]))
151 {
152 if ((GNUNET_OK !=
153 GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) ||
154 (NULL == (h = GNUNET_DISK_file_open (filename,
155 GNUNET_DISK_OPEN_READ,
156 GNUNET_DISK_PERM_NONE))))
157 { 151 {
158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 152 if ((GNUNET_OK !=
159 _ ("Failed to read directory `%s'\n"), 153 GNUNET_DISK_file_size(filename, &size, GNUNET_YES, GNUNET_YES)) ||
160 filename); 154 (NULL == (h = GNUNET_DISK_file_open(filename,
161 ret = 1; 155 GNUNET_DISK_OPEN_READ,
162 continue; 156 GNUNET_DISK_PERM_NONE))))
157 {
158 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
159 _("Failed to read directory `%s'\n"),
160 filename);
161 ret = 1;
162 continue;
163 }
164 len = (size_t)size;
165 data = GNUNET_DISK_file_map(h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
166 GNUNET_assert(NULL != data);
167 if (GNUNET_OK !=
168 GNUNET_FS_directory_list_contents(len, data, 0, &print_entry, NULL))
169 fprintf(stdout, _("`%s' is not a GNUnet directory\n"), filename);
170 else
171 printf("\n");
172 GNUNET_DISK_file_unmap(map);
173 GNUNET_DISK_file_close(h);
163 } 174 }
164 len = (size_t) size;
165 data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
166 GNUNET_assert (NULL != data);
167 if (GNUNET_OK !=
168 GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL))
169 fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename);
170 else
171 printf ("\n");
172 GNUNET_DISK_file_unmap (map);
173 GNUNET_DISK_file_close (h);
174 }
175} 175}
176 176
177/** 177/**
@@ -182,26 +182,27 @@ run (void *cls,
182 * @return 0 ok, 1 on error 182 * @return 0 ok, 1 on error
183 */ 183 */
184int 184int
185main (int argc, char *const *argv) 185main(int argc, char *const *argv)
186{ 186{
187 static struct GNUNET_GETOPT_CommandLineOption options[] = { 187 static struct GNUNET_GETOPT_CommandLineOption options[] = {
188 GNUNET_GETOPT_OPTION_END}; 188 GNUNET_GETOPT_OPTION_END
189 };
189 190
190 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 191 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
191 return 2; 192 return 2;
192 193
193 ret = (GNUNET_OK == 194 ret = (GNUNET_OK ==
194 GNUNET_PROGRAM_run (argc, 195 GNUNET_PROGRAM_run(argc,
195 argv, 196 argv,
196 "gnunet-directory [OPTIONS] FILENAME", 197 "gnunet-directory [OPTIONS] FILENAME",
197 gettext_noop ( 198 gettext_noop(
198 "Display contents of a GNUnet directory"), 199 "Display contents of a GNUnet directory"),
199 options, 200 options,
200 &run, 201 &run,
201 NULL)) 202 NULL))
202 ? ret 203 ? ret
203 : 1; 204 : 1;
204 GNUNET_free ((void *) argv); 205 GNUNET_free((void *)argv);
205 return ret; 206 return ret;
206} 207}
207 208