GNUnet 0.22.2
gnunet-directory.c
Go to the documentation of this file.
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 */
25#include "platform.h"
26
27#include "gnunet_fs_service.h"
28
29static int ret;
30
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;
62 return 0;
63#if HAVE_LIBEXTRACTOR
64 printf ("\t%20s: %s\n",
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
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
102 meta,
104 if (uri == NULL)
105 {
106 printf (_ ("Directory `%s' meta data:\n"), name ? name : "");
108 printf ("\n");
109 printf (_ ("Directory `%s' contents:\n"), name ? name : "");
111 return;
112 }
113 string = GNUNET_FS_uri_to_string (uri);
114 printf ("%s (%s):\n", name ? name : "", string);
115 GNUNET_free (string);
117 printf ("\n");
119}
120
121
130static void
131run (void *cls,
132 char *const *args,
133 const char *cfgfile,
134 const struct GNUNET_CONFIGURATION_Handle *cfg)
135{
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 !=
155 (NULL == (h = GNUNET_DISK_file_open (filename,
158 {
160 _ ("Failed to read directory `%s'\n"),
161 filename);
162 ret = 1;
163 continue;
164 }
165 len = (size_t) size;
167 GNUNET_assert (NULL != data);
168 if (GNUNET_OK !=
170 fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename);
171 else
172 printf ("\n");
175 }
176}
177
178
186int
187main (int argc, char *const *argv)
188{
189 static struct GNUNET_GETOPT_CommandLineOption options[] = {
191 };
192
193 ret = (GNUNET_OK ==
195 argc,
196 argv,
197 "gnunet-directory [OPTIONS] FILENAME",
199 "Display contents of a GNUnet directory"),
200 options,
201 &run,
202 NULL))
203 ? ret
204 : 1;
205 return ret;
206}
207
208
209/* end of gnunet-directory.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
#define dgettext(Domainname, Msgid)
Definition: gettext.h:51
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:98
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static char * plugin_name
Name of our plugin.
static char * data
The data to insert into the dht.
static void print_entry(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *meta, size_t length, const void *data)
Print an entry in a directory.
static int ret
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.
int main(int argc, char *const *argv)
The main function to inspect GNUnet directories.
static int item_printer(void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_size)
Print a meta data entry.
static char * filename
static char * name
Name (label) of the records to list.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
API for file sharing via GNUnet.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1234
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:222
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
void * GNUNET_DISK_file_map(const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, enum GNUNET_DISK_MapType access, size_t len)
Map a file into memory.
Definition: disk.c:1380
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1411
@ GNUNET_DISK_OPEN_READ
Open the file for reading.
@ GNUNET_DISK_PERM_NONE
Nobody is allowed to do anything to the file.
@ GNUNET_DISK_MAP_TYPE_READ
Read-only memory map.
#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
int GNUNET_FS_directory_list_contents(size_t size, const void *data, uint64_t offset, GNUNET_FS_DirectoryEntryProcessor dep, void *dep_cls)
Iterate over all entries in a directory.
Definition: fs_directory.c:182
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2034
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_FS_meta_data_iterate(const struct GNUNET_FS_MetaData *md, EXTRACTOR_MetaDataProcessor iter, void *iter_cls)
Iterate over MD entries.
Definition: meta_data.c:418
char * GNUNET_FS_meta_data_get_by_type(const struct GNUNET_FS_MetaData *md, enum EXTRACTOR_MetaType type)
Get the first MD entry of the given type.
Definition: meta_data.c:438
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, 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,...
Definition: program.c:407
static struct GNUNET_CONTAINER_MultiPeerMap * map
Peermap of PeerIdentities to "struct PeerEntry" (for fast lookup).
Definition: peer.c:63
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
#define LIBEXTRACTOR_GETTEXT_DOMAIN
Definition: platform.h:180
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1361
Meta data to associate with a file, directory or namespace.
Definition: meta_data.c:92
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:167
Definition of a command line option.