GNUnet  0.10.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.

Functions

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...
 

Variables

static int ret
 

Detailed Description

display content of GNUnet directories

Author
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 
)
static

Print a meta data entry.

Parameters
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
Returns
always 0 (to continue iterating)

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

References _, dgettext, EXTRACTOR_METAFORMAT_C_STRING, EXTRACTOR_METAFORMAT_UTF8, EXTRACTOR_METATYPE_GNUNET_FULL_DATA, EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME, and LIBEXTRACTOR_GETTEXT_DOMAIN.

Referenced by print_entry().

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;
62 #if HAVE_LIBEXTRACTOR
63  printf ("\t%20s: %s\n",
65  EXTRACTOR_metatype_to_string (type)),
66  data);
67 #else
68  printf ("\t%20d: %s\n",
69  type,
70  data);
71 #endif
72  return 0;
73 }
0-terminated, UTF-8 encoded string.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define dgettext(Domainname, Msgid)
Definition: gettext.h:46
#define LIBEXTRACTOR_GETTEXT_DOMAIN
Definition: platform.h:209
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
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 
)
static

Print an entry in a directory.

Parameters
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 93 of file gnunet-directory.c.

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

Referenced by run().

96 {
97  char *string;
98  char *name;
99 
100  name =
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_non_null (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_non_null (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.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:1988
const char * name
int GNUNET_CONTAINER_meta_data_iterate(const struct GNUNET_CONTAINER_MetaData *md, EXTRACTOR_MetaDataProcessor iter, void *iter_cls)
Iterate over MD entries.
#define GNUNET_free(ptr)
Wrapper around free.
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 
)
static

Main function that will be run by the scheduler.

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

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

References _, data, filename, FPRINTF, 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().

132 {
133  struct GNUNET_DISK_MapHandle *map;
134  struct GNUNET_DISK_FileHandle *h;
135  void *data;
136  size_t len;
137  uint64_t size;
138  const char *filename;
139  int i;
140 
141  if (NULL == args[0])
142  {
143  FPRINTF (stderr, "%s", _("You must specify a filename to inspect.\n"));
144  ret = 1;
145  return;
146  }
147  i = 0;
148  while (NULL != (filename = args[i++]))
149  {
150  if ((GNUNET_OK != GNUNET_DISK_file_size (filename, &size, GNUNET_YES, GNUNET_YES)) ||
151  (NULL ==
152  (h =
155  {
156  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to read directory `%s'\n"),
157  filename);
158  ret = 1;
159  continue;
160  }
161  len = (size_t) size;
162  data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
163  GNUNET_assert (NULL != data);
164  if (GNUNET_OK != GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL))
165  fprintf (stdout, _("`%s' is not a GNUnet directory\n"),
166  filename);
167  else
168  printf ("\n");
171  }
172 }
Open the file for reading.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
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.
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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:2020
Nobody is allowed to do anything to the file.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
static struct GNUNET_CONTAINER_MultiPeerMap * map
Handle to the map used to store old latency values for peers.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
Read-only memory map.
static char * filename
static unsigned int size
Size of the "table".
Definition: peer.c:67
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:2100
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:179
int 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:289
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
static int ret
uint32_t data
The data value.
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:1673
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1985
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
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.

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

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

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

183 {
184  static struct GNUNET_GETOPT_CommandLineOption options[] = {
186  };
187 
188  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
189  return 2;
190 
191  ret = (GNUNET_OK ==
192  GNUNET_PROGRAM_run (argc, argv, "gnunet-directory [OPTIONS] FILENAME",
194  ("Display contents of a GNUnet directory"),
195  options, &run, NULL)) ? ret : 1;
196  GNUNET_free ((void*) argv);
197  return ret;
198 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
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 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, parse options).
Definition: program.c:361
static int ret
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

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

Referenced by main(), and run().