2 This file is part of GNUnet.
3 (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file fs/gnunet-directory.c
22 * @brief display content of GNUnet directories
23 * @author Christian Grothoff
26 #include "gnunet_fs_service.h"
31 * Print a meta data entry.
34 item_printer (void *cls,
35 EXTRACTOR_KeywordType type,
38 printf ("\t%20s: %s\n",
39 dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN,
40 EXTRACTOR_getKeywordTypeAsString (type)), data);
47 * Print an entry in a directory.
49 * @param cls closure (not used)
50 * @param filename name of the file in the directory
51 * @param uri URI of the file
52 * @param metadata metadata for the file; metadata for
53 * the directory if everything else is NULL/zero
54 * @param length length of the available data for the file
55 * (of type size_t since data must certainly fit
56 * into memory; if files are larger than size_t
57 * permits, then they will certainly not be
58 * embedded with the directory itself).
59 * @param data data available for the file (length bytes)
62 print_entry (void *cls,
64 const struct GNUNET_FS_Uri *uri,
65 const struct GNUNET_CONTAINER_MetaData *meta,
71 string = GNUNET_FS_uri_to_string (uri);
72 printf ("%s:\n", string);
74 GNUNET_CONTAINER_meta_data_get_contents (meta,
81 * Main function that will be run by the scheduler.
84 * @param sched the scheduler to use
85 * @param args remaining command-line arguments
86 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
87 * @param cfg configuration
91 struct GNUNET_SCHEDULER_Handle *sched,
94 const struct GNUNET_CONFIGURATION_Handle *cfg)
96 struct GNUNET_DISK_MapHandle *map;
97 struct GNUNET_DISK_FileHandle *h;
101 const char *filename = args[0];
103 if (NULL == filename)
106 _("You must specify a filename to inspect."));
111 GNUNET_DISK_file_size (filename,
114 (NULL == (h = GNUNET_DISK_file_open (filename,
115 GNUNET_DISK_OPEN_READ))) )
117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
118 _("Failed to read directory `%s'\n"),
124 data = GNUNET_DISK_file_map (h,
126 GNUNET_DISK_MAP_READ,
128 GNUNET_assert (NULL != data);
129 GNUNET_FS_directory_list_contents (len,
134 GNUNET_DISK_file_unmap (map);
135 GNUNET_DISK_file_close (h);
140 * gnunet-directory command line options
142 static struct GNUNET_GETOPT_CommandLineOption options[] = {
144 GNUNET_GETOPT_OPTION_END
149 * The main function to inspect GNUnet directories.
151 * @param argc number of arguments from the command line
152 * @param argv command line arguments
153 * @return 0 ok, 1 on error
156 main (int argc, char *const *argv)
159 GNUNET_PROGRAM_run (argc,
163 ("Display GNUnet directories."),
164 options, &run, NULL)) ? ret : 1;
167 /* end of gnunet-directory.c */