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", type, data);
69 #endif
70  return 0;
71 }
0-terminated, UTF-8 encoded string.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
#define dgettext(Domainname, Msgid)
Definition: gettext.h:46
#define LIBEXTRACTOR_GETTEXT_DOMAIN
Definition: platform.h:182
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 90 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 
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_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:181
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2024
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, 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().

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;
142 
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 !=
153  GNUNET_DISK_file_size(filename, &size, GNUNET_YES, GNUNET_YES)) ||
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;
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");
174  }
175 }
Open the file for reading.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1339
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 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:1433
Nobody is allowed to do anything to the file.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:181
Read-only memory map.
static char * filename
static unsigned int size
Size of the "table".
Definition: peer.c:66
int GNUNET_DISK_file_unmap(struct GNUNET_DISK_MapHandle *h)
Unmap a file.
Definition: disk.c:1469
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:177
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:254
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
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:1262
Handle used to access files (and pipes).
Handle for a memory-mapping operation.
Definition: disk.c:1406
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 185 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().

186 {
187  static struct GNUNET_GETOPT_CommandLineOption options[] = {
189  };
190 
191  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
192  return 2;
193 
194  ret = (GNUNET_OK ==
195  GNUNET_PROGRAM_run(argc,
196  argv,
197  "gnunet-directory [OPTIONS] FILENAME",
198  gettext_noop(
199  "Display contents of a GNUnet directory"),
200  options,
201  &run,
202  NULL))
203  ? ret
204  : 1;
205  GNUNET_free((void *)argv);
206  return ret;
207 }
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:1439
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:367
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().