GNUnet  0.11.x
Functions | Variables
gnunet-directory.c File Reference

display content of GNUnet directories More...

#include "platform.h"
#include "gnunet_fs_service.h"
Include dependency graph for gnunet-directory.c:

Go to the source code of this file.


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. More...
static void print_entry (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, const struct GNUNET_CONTAINER_MetaData *meta, size_t length, const void *data)
 Print an entry in a directory. More...
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. More...
int main (int argc, char *const *argv)
 The main function to inspect GNUnet directories. More...


static int ret

Detailed Description

display content of GNUnet directories

Christian Grothoff

Definition in file gnunet-directory.c.

Function Documentation

◆ item_printer()

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.

clsclosure (unused)
plugin_namename of the plugin that generated the meta data
typetype of the keyword
formatformat of data
data_mime_typemime type of data
datavalue of the meta data
data_sizenumber of bytes in data
always 0 (to continue iterating)

Definition at line 43 of file gnunet-directory.c.

50 {
52  {
53  printf (_ ("\t<original file embedded in %u bytes of meta data>\n"),
54  (unsigned int) data_size);
55  return 0;
56  }
57  if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
59  return 0;
61  return 0;
63  printf ("\t%20s: %s\n",
65  EXTRACTOR_metatype_to_string (type)),
66  data);
67 #else
68  printf ("\t%20d: %s\n", type, data);
69 #endif
70  return 0;
71 }
#define dgettext(Domainname, Msgid)
Definition: gettext.h:46
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
0-terminated string.
0-terminated, UTF-8 encoded string.
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
Definition: platform.h:178
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model


Referenced by print_entry().

Here is the caller graph for this function:

◆ print_entry()

static void print_entry ( void *  cls,
const char *  filename,
const struct GNUNET_FS_Uri uri,
const struct GNUNET_CONTAINER_MetaData meta,
size_t  length,
const void *  data 

Print an entry in a directory.

clsclosure (not used)
filenamename of the file in the directory
uriURI of the file
metametadata for the file; metadata for the directory if everything else is NULL/zero
lengthlength of the available data for the file (of type size_t since data must certainly fit into memory; if files are larger than size_t permits, then they will certainly not be embedded with the directory itself).
datadata available for the file (length bytes)

Definition at line 90 of file gnunet-directory.c.

96 {
97  char *string;
98  char *name;
101  meta,
103  if (uri == NULL)
104  {
105  printf (_ ("Directory `%s' meta data:\n"), name ? name : "");
107  printf ("\n");
108  printf (_ ("Directory `%s' contents:\n"), name ? name : "");
109  GNUNET_free (name);
110  return;
111  }
112  string = GNUNET_FS_uri_to_string (uri);
113  printf ("%s (%s):\n", name ? name : "", string);
114  GNUNET_free (string);
116  printf ("\n");
117  GNUNET_free (name);
118 }
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 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_CONTAINER_MetaData * meta
Meta-data provided via command-line option.
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2027
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_CONTAINER_meta_data_get_by_type(const struct GNUNET_CONTAINER_MetaData *md, enum EXTRACTOR_MetaType type)
Get the first MD entry of the given type.
int GNUNET_CONTAINER_meta_data_iterate(const struct GNUNET_CONTAINER_MetaData *md, EXTRACTOR_MetaDataProcessor iter, void *iter_cls)
Iterate over MD entries.
const char * name

References _, EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, GNUNET_CONTAINER_meta_data_get_by_type(), GNUNET_CONTAINER_meta_data_iterate(), GNUNET_free, GNUNET_FS_uri_to_string(), item_printer(), meta, name, and uri.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

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.

argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)

Definition at line 130 of file gnunet-directory.c.

134 {
135  struct GNUNET_DISK_MapHandle *map;
136  struct GNUNET_DISK_FileHandle *h;
137  void *data;
138  size_t len;
139  uint64_t size;
140  const char *filename;
141  int i;
143  if (NULL == args[0])
144  {
145  fprintf (stderr, "%s", _ ("You must specify a filename to inspect.\n"));
146  ret = 1;
147  return;
148  }
149  i = 0;
150  while (NULL != (filename = args[i++]))
151  {
152  if ((GNUNET_OK !=
154  (NULL == (h = GNUNET_DISK_file_open (filename,
157  {
159  _ ("Failed to read directory `%s'\n"),
160  filename);
161  ret = 1;
162  continue;
163  }
164  len = (size_t) size;
166  GNUNET_assert (NULL != data);
167  if (GNUNET_OK !=
169  fprintf (stdout, _ ("`%s' is not a GNUnet directory\n"), filename);
170  else
171  printf ("\n");
174  }
175 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
static int ret
static void print_entry(void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, const struct GNUNET_CONTAINER_MetaData *meta, size_t length, const void *data)
Print an entry in a directory.
static char * filename
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
#define GNUNET_log(kind,...)
Definition: gnunet_common.h:95
Definition: gnunet_common.h:97
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:1235
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
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:1378
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1306
enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1409
Open the file for reading.
Nobody is allowed to do anything to the file.
Read-only memory map.
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:181
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static unsigned int size
Size of the "table".
Definition: peer.c:67
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1359

References _, consensus-simulation::args, data, filename, GNUNET_assert, GNUNET_DISK_file_close(), GNUNET_DISK_file_map(), GNUNET_DISK_file_open(), GNUNET_DISK_file_size(), GNUNET_DISK_file_unmap(), GNUNET_DISK_MAP_TYPE_READ, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE, GNUNET_ERROR_TYPE_ERROR, GNUNET_FS_directory_list_contents(), GNUNET_log, GNUNET_OK, GNUNET_YES, h, len, map, print_entry(), ret, and size.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 

The main function to inspect GNUnet directories.

argcnumber of arguments from the command line
argvcommand line arguments
0 ok, 1 on error

Definition at line 186 of file gnunet-directory.c.

187 {
188  static struct GNUNET_GETOPT_CommandLineOption options[] = {
190  };
192  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
193  return 2;
195  ret = (GNUNET_OK ==
196  GNUNET_PROGRAM_run (argc,
197  argv,
198  "gnunet-directory [OPTIONS] FILENAME",
199  gettext_noop (
200  "Display contents of a GNUnet directory"),
201  options,
202  &run,
203  NULL))
204  ? ret
205  : 1;
206  GNUNET_free_nz ((void *) argv);
207  return ret;
208 }
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:69
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.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue 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,...
Definition: program.c:364
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1209
Definition of a command line option.

References gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), options, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret

Definition at line 28 of file gnunet-directory.c.

Referenced by main(), and run().