aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-directory.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/gnunet-directory.c
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/fs/gnunet-directory.c')
-rw-r--r--src/fs/gnunet-directory.c125
1 files changed, 53 insertions, 72 deletions
diff --git a/src/fs/gnunet-directory.c b/src/fs/gnunet-directory.c
index 9bd5ed9c1..a6fa42664 100644
--- a/src/fs/gnunet-directory.c
+++ b/src/fs/gnunet-directory.c
@@ -41,21 +41,19 @@ static int ret;
41 */ 41 */
42static int 42static int
43item_printer (void *cls, 43item_printer (void *cls,
44 const char *plugin_name, 44 const char *plugin_name,
45 enum EXTRACTOR_MetaType type, 45 enum EXTRACTOR_MetaType type,
46 enum EXTRACTOR_MetaFormat format, 46 enum EXTRACTOR_MetaFormat format,
47 const char *data_mime_type, 47 const char *data_mime_type, const char *data, size_t data_size)
48 const char *data,
49 size_t data_size)
50{ 48{
51 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA) 49 if (type == EXTRACTOR_METATYPE_GNUNET_FULL_DATA)
52 { 50 {
53 printf(_("\t<original file embedded in %u bytes of meta data>\n"), 51 printf (_("\t<original file embedded in %u bytes of meta data>\n"),
54 (unsigned int) data_size); 52 (unsigned int) data_size);
55 return 0; 53 return 0;
56 } 54 }
57 if ( (format != EXTRACTOR_METAFORMAT_UTF8) && 55 if ((format != EXTRACTOR_METAFORMAT_UTF8) &&
58 (format != EXTRACTOR_METAFORMAT_C_STRING) ) 56 (format != EXTRACTOR_METAFORMAT_C_STRING))
59 return 0; 57 return 0;
60 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) 58 if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME)
61 return 0; 59 return 0;
@@ -84,36 +82,29 @@ item_printer (void *cls,
84 */ 82 */
85static void 83static void
86print_entry (void *cls, 84print_entry (void *cls,
87 const char *filename, 85 const char *filename,
88 const struct GNUNET_FS_Uri *uri, 86 const struct GNUNET_FS_Uri *uri,
89 const struct GNUNET_CONTAINER_MetaData *meta, 87 const struct GNUNET_CONTAINER_MetaData *meta,
90 size_t length, 88 size_t length, const void *data)
91 const void *data)
92{ 89{
93 char *string; 90 char *string;
94 char *name; 91 char *name;
95 92
96 name = GNUNET_CONTAINER_meta_data_get_by_type (meta, 93 name = GNUNET_CONTAINER_meta_data_get_by_type (meta,
97 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 94 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
98 if (uri == NULL) 95 if (uri == NULL)
99 { 96 {
100 printf (_("Directory `%s' meta data:\n"), 97 printf (_("Directory `%s' meta data:\n"), name);
101 name); 98 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
102 GNUNET_CONTAINER_meta_data_iterate (meta, 99 printf ("\n");
103 &item_printer, 100 printf (_("Directory `%s' contents:\n"), name);
104 NULL); 101 GNUNET_free (name);
105 printf ("\n"); 102 return;
106 printf (_("Directory `%s' contents:\n"), 103 }
107 name);
108 GNUNET_free (name);
109 return;
110 }
111 string = GNUNET_FS_uri_to_string (uri); 104 string = GNUNET_FS_uri_to_string (uri);
112 printf ("%s (%s):\n", name, string); 105 printf ("%s (%s):\n", name, string);
113 GNUNET_free (string); 106 GNUNET_free (string);
114 GNUNET_CONTAINER_meta_data_iterate (meta, 107 GNUNET_CONTAINER_meta_data_iterate (meta, &item_printer, NULL);
115 &item_printer,
116 NULL);
117 printf ("\n"); 108 printf ("\n");
118 GNUNET_free (name); 109 GNUNET_free (name);
119} 110}
@@ -130,8 +121,7 @@ print_entry (void *cls,
130static void 121static void
131run (void *cls, 122run (void *cls,
132 char *const *args, 123 char *const *args,
133 const char *cfgfile, 124 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
134 const struct GNUNET_CONFIGURATION_Handle *cfg)
135{ 125{
136 struct GNUNET_DISK_MapHandle *map; 126 struct GNUNET_DISK_MapHandle *map;
137 struct GNUNET_DISK_FileHandle *h; 127 struct GNUNET_DISK_FileHandle *h;
@@ -142,44 +132,35 @@ run (void *cls,
142 int i; 132 int i;
143 133
144 if (NULL == args[0]) 134 if (NULL == args[0])
145 { 135 {
146 fprintf (stderr, 136 fprintf (stderr, _("You must specify a filename to inspect."));
147 _("You must specify a filename to inspect.")); 137 ret = 1;
148 ret = 1; 138 return;
149 return; 139 }
150 }
151 i = 0; 140 i = 0;
152 while (NULL != (filename = args[i++])) 141 while (NULL != (filename = args[i++]))
142 {
143 if ((GNUNET_OK !=
144 GNUNET_DISK_file_size (filename,
145 &size,
146 GNUNET_YES)) ||
147 (NULL == (h = GNUNET_DISK_file_open (filename,
148 GNUNET_DISK_OPEN_READ,
149 GNUNET_DISK_PERM_NONE))))
153 { 150 {
154 if ( (GNUNET_OK != 151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 GNUNET_DISK_file_size (filename, 152 _("Failed to read directory `%s'\n"), filename);
156 &size, 153 ret = 1;
157 GNUNET_YES)) || 154 continue;
158 (NULL == (h = GNUNET_DISK_file_open (filename,
159 GNUNET_DISK_OPEN_READ,
160 GNUNET_DISK_PERM_NONE))) )
161 {
162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 _("Failed to read directory `%s'\n"),
164 filename);
165 ret = 1;
166 continue;
167 }
168 len = (size_t) size;
169 data = GNUNET_DISK_file_map (h,
170 &map,
171 GNUNET_DISK_MAP_TYPE_READ,
172 len);
173 GNUNET_assert (NULL != data);
174 GNUNET_FS_directory_list_contents (len,
175 data,
176 0,
177 &print_entry,
178 NULL);
179 printf ("\n");
180 GNUNET_DISK_file_unmap (map);
181 GNUNET_DISK_file_close (h);
182 } 155 }
156 len = (size_t) size;
157 data = GNUNET_DISK_file_map (h, &map, GNUNET_DISK_MAP_TYPE_READ, len);
158 GNUNET_assert (NULL != data);
159 GNUNET_FS_directory_list_contents (len, data, 0, &print_entry, NULL);
160 printf ("\n");
161 GNUNET_DISK_file_unmap (map);
162 GNUNET_DISK_file_close (h);
163 }
183} 164}
184 165
185/** 166/**