diff options
Diffstat (limited to 'src/fs/gnunet-helper-fs-publish.c')
-rw-r--r-- | src/fs/gnunet-helper-fs-publish.c | 404 |
1 files changed, 201 insertions, 203 deletions
diff --git a/src/fs/gnunet-helper-fs-publish.c b/src/fs/gnunet-helper-fs-publish.c index dcb4b47cd..db74e65aa 100644 --- a/src/fs/gnunet-helper-fs-publish.c +++ b/src/fs/gnunet-helper-fs-publish.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file src/fs/gnunet-helper-fs-publish.c | 22 | * @file src/fs/gnunet-helper-fs-publish.c |
@@ -33,9 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * A node of a directory tree. | 34 | * A node of a directory tree. |
35 | */ | 35 | */ |
36 | struct ScanTreeNode | 36 | struct ScanTreeNode { |
37 | { | ||
38 | |||
39 | /** | 37 | /** |
40 | * This is a doubly-linked list | 38 | * This is a doubly-linked list |
41 | */ | 39 | */ |
@@ -113,41 +111,41 @@ static int output_stream; | |||
113 | * @return always 0 to continue extracting | 111 | * @return always 0 to continue extracting |
114 | */ | 112 | */ |
115 | static int | 113 | static int |
116 | add_to_md (void *cls, | 114 | add_to_md(void *cls, |
117 | const char *plugin_name, | 115 | const char *plugin_name, |
118 | enum EXTRACTOR_MetaType type, | 116 | enum EXTRACTOR_MetaType type, |
119 | enum EXTRACTOR_MetaFormat format, | 117 | enum EXTRACTOR_MetaFormat format, |
120 | const char *data_mime_type, | 118 | const char *data_mime_type, |
121 | const char *data, | 119 | const char *data, |
122 | size_t data_len) | 120 | size_t data_len) |
123 | { | 121 | { |
124 | struct GNUNET_CONTAINER_MetaData *md = cls; | 122 | struct GNUNET_CONTAINER_MetaData *md = cls; |
125 | 123 | ||
126 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || | 124 | if (((EXTRACTOR_METAFORMAT_UTF8 == format) || |
127 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && | 125 | (EXTRACTOR_METAFORMAT_C_STRING == format)) && |
128 | ('\0' != data[data_len - 1])) | 126 | ('\0' != data[data_len - 1])) |
129 | { | 127 | { |
130 | char zdata[data_len + 1]; | 128 | char zdata[data_len + 1]; |
131 | GNUNET_memcpy (zdata, data, data_len); | 129 | GNUNET_memcpy(zdata, data, data_len); |
132 | zdata[data_len] = '\0'; | 130 | zdata[data_len] = '\0'; |
133 | (void) GNUNET_CONTAINER_meta_data_insert (md, | 131 | (void)GNUNET_CONTAINER_meta_data_insert(md, |
134 | plugin_name, | 132 | plugin_name, |
135 | type, | 133 | type, |
136 | format, | 134 | format, |
137 | data_mime_type, | 135 | data_mime_type, |
138 | zdata, | 136 | zdata, |
139 | data_len + 1); | 137 | data_len + 1); |
140 | } | 138 | } |
141 | else | 139 | else |
142 | { | 140 | { |
143 | (void) GNUNET_CONTAINER_meta_data_insert (md, | 141 | (void)GNUNET_CONTAINER_meta_data_insert(md, |
144 | plugin_name, | 142 | plugin_name, |
145 | type, | 143 | type, |
146 | format, | 144 | format, |
147 | data_mime_type, | 145 | data_mime_type, |
148 | data, | 146 | data, |
149 | data_len); | 147 | data_len); |
150 | } | 148 | } |
151 | return 0; | 149 | return 0; |
152 | } | 150 | } |
153 | #endif | 151 | #endif |
@@ -159,18 +157,18 @@ add_to_md (void *cls, | |||
159 | * @param tree tree to free | 157 | * @param tree tree to free |
160 | */ | 158 | */ |
161 | static void | 159 | static void |
162 | free_tree (struct ScanTreeNode *tree) | 160 | free_tree(struct ScanTreeNode *tree) |
163 | { | 161 | { |
164 | struct ScanTreeNode *pos; | 162 | struct ScanTreeNode *pos; |
165 | 163 | ||
166 | while (NULL != (pos = tree->children_head)) | 164 | while (NULL != (pos = tree->children_head)) |
167 | free_tree (pos); | 165 | free_tree(pos); |
168 | if (NULL != tree->parent) | 166 | if (NULL != tree->parent) |
169 | GNUNET_CONTAINER_DLL_remove (tree->parent->children_head, | 167 | GNUNET_CONTAINER_DLL_remove(tree->parent->children_head, |
170 | tree->parent->children_tail, | 168 | tree->parent->children_tail, |
171 | tree); | 169 | tree); |
172 | GNUNET_free (tree->filename); | 170 | GNUNET_free(tree->filename); |
173 | GNUNET_free (tree); | 171 | GNUNET_free(tree); |
174 | } | 172 | } |
175 | 173 | ||
176 | 174 | ||
@@ -182,7 +180,7 @@ free_tree (struct ScanTreeNode *tree) | |||
182 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 180 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
183 | */ | 181 | */ |
184 | static int | 182 | static int |
185 | write_all (const void *buf, size_t size) | 183 | write_all(const void *buf, size_t size) |
186 | { | 184 | { |
187 | const char *cbuf = buf; | 185 | const char *cbuf = buf; |
188 | size_t total; | 186 | size_t total; |
@@ -190,15 +188,16 @@ write_all (const void *buf, size_t size) | |||
190 | 188 | ||
191 | total = 0; | 189 | total = 0; |
192 | do | 190 | do |
193 | { | 191 | { |
194 | wr = write (output_stream, &cbuf[total], size - total); | 192 | wr = write(output_stream, &cbuf[total], size - total); |
195 | if (wr > 0) | 193 | if (wr > 0) |
196 | total += wr; | 194 | total += wr; |
197 | } while ((wr > 0) && (total < size)); | 195 | } |
196 | while ((wr > 0) && (total < size)); | ||
198 | if (wr <= 0) | 197 | if (wr <= 0) |
199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 198 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
200 | "Failed to write to stdout: %s\n", | 199 | "Failed to write to stdout: %s\n", |
201 | strerror (errno)); | 200 | strerror(errno)); |
202 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; | 201 | return (total == size) ? GNUNET_OK : GNUNET_SYSERR; |
203 | } | 202 | } |
204 | 203 | ||
@@ -212,20 +211,20 @@ write_all (const void *buf, size_t size) | |||
212 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) | 211 | * @return #GNUNET_SYSERR to stop scanning (the pipe was broken somehow) |
213 | */ | 212 | */ |
214 | static int | 213 | static int |
215 | write_message (uint16_t message_type, const char *data, size_t data_length) | 214 | write_message(uint16_t message_type, const char *data, size_t data_length) |
216 | { | 215 | { |
217 | struct GNUNET_MessageHeader hdr; | 216 | struct GNUNET_MessageHeader hdr; |
218 | 217 | ||
219 | #if 0 | 218 | #if 0 |
220 | fprintf (stderr, | 219 | fprintf(stderr, |
221 | "Helper sends %u-byte message of type %u\n", | 220 | "Helper sends %u-byte message of type %u\n", |
222 | (unsigned int) (sizeof (struct GNUNET_MessageHeader) + data_length), | 221 | (unsigned int)(sizeof(struct GNUNET_MessageHeader) + data_length), |
223 | (unsigned int) message_type); | 222 | (unsigned int)message_type); |
224 | #endif | 223 | #endif |
225 | hdr.type = htons (message_type); | 224 | hdr.type = htons(message_type); |
226 | hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length); | 225 | hdr.size = htons(sizeof(struct GNUNET_MessageHeader) + data_length); |
227 | if ((GNUNET_OK != write_all (&hdr, sizeof (hdr))) || | 226 | if ((GNUNET_OK != write_all(&hdr, sizeof(hdr))) || |
228 | (GNUNET_OK != write_all (data, data_length))) | 227 | (GNUNET_OK != write_all(data, data_length))) |
229 | return GNUNET_SYSERR; | 228 | return GNUNET_SYSERR; |
230 | return GNUNET_OK; | 229 | return GNUNET_OK; |
231 | } | 230 | } |
@@ -242,14 +241,13 @@ write_message (uint16_t message_type, const char *data, size_t data_length) | |||
242 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 241 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
243 | */ | 242 | */ |
244 | static int | 243 | static int |
245 | preprocess_file (const char *filename, struct ScanTreeNode **dst); | 244 | preprocess_file(const char *filename, struct ScanTreeNode **dst); |
246 | 245 | ||
247 | 246 | ||
248 | /** | 247 | /** |
249 | * Closure for the 'scan_callback' | 248 | * Closure for the 'scan_callback' |
250 | */ | 249 | */ |
251 | struct RecursionContext | 250 | struct RecursionContext { |
252 | { | ||
253 | /** | 251 | /** |
254 | * Parent to add the files to. | 252 | * Parent to add the files to. |
255 | */ | 253 | */ |
@@ -272,22 +270,22 @@ struct RecursionContext | |||
272 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 270 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
273 | */ | 271 | */ |
274 | static int | 272 | static int |
275 | scan_callback (void *cls, const char *filename) | 273 | scan_callback(void *cls, const char *filename) |
276 | { | 274 | { |
277 | struct RecursionContext *rc = cls; | 275 | struct RecursionContext *rc = cls; |
278 | struct ScanTreeNode *chld; | 276 | struct ScanTreeNode *chld; |
279 | 277 | ||
280 | if (GNUNET_OK != preprocess_file (filename, &chld)) | 278 | if (GNUNET_OK != preprocess_file(filename, &chld)) |
281 | { | 279 | { |
282 | rc->stop = GNUNET_YES; | 280 | rc->stop = GNUNET_YES; |
283 | return GNUNET_SYSERR; | 281 | return GNUNET_SYSERR; |
284 | } | 282 | } |
285 | if (NULL == chld) | 283 | if (NULL == chld) |
286 | return GNUNET_OK; | 284 | return GNUNET_OK; |
287 | chld->parent = rc->parent; | 285 | chld->parent = rc->parent; |
288 | GNUNET_CONTAINER_DLL_insert (rc->parent->children_head, | 286 | GNUNET_CONTAINER_DLL_insert(rc->parent->children_head, |
289 | rc->parent->children_tail, | 287 | rc->parent->children_tail, |
290 | chld); | 288 | chld); |
291 | return GNUNET_OK; | 289 | return GNUNET_OK; |
292 | } | 290 | } |
293 | 291 | ||
@@ -303,60 +301,60 @@ scan_callback (void *cls, const char *filename) | |||
303 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 301 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
304 | */ | 302 | */ |
305 | static int | 303 | static int |
306 | preprocess_file (const char *filename, struct ScanTreeNode **dst) | 304 | preprocess_file(const char *filename, struct ScanTreeNode **dst) |
307 | { | 305 | { |
308 | struct ScanTreeNode *item; | 306 | struct ScanTreeNode *item; |
309 | struct stat sbuf; | 307 | struct stat sbuf; |
310 | uint64_t fsize = 0; | 308 | uint64_t fsize = 0; |
311 | 309 | ||
312 | if ((0 != stat (filename, &sbuf)) || | 310 | if ((0 != stat(filename, &sbuf)) || |
313 | ((! S_ISDIR (sbuf.st_mode)) && | 311 | ((!S_ISDIR(sbuf.st_mode)) && |
314 | (GNUNET_OK != | 312 | (GNUNET_OK != |
315 | GNUNET_DISK_file_size (filename, &fsize, GNUNET_NO, GNUNET_YES)))) | 313 | GNUNET_DISK_file_size(filename, &fsize, GNUNET_NO, GNUNET_YES)))) |
316 | { | 314 | { |
317 | /* If the file doesn't exist (or is not stat-able for any other reason) | 315 | /* If the file doesn't exist (or is not stat-able for any other reason) |
318 | skip it (but report it), but do continue. */ | 316 | skip it (but report it), but do continue. */ |
319 | if (GNUNET_OK != | 317 | if (GNUNET_OK != |
320 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, | 318 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE, |
321 | filename, | 319 | filename, |
322 | strlen (filename) + 1)) | 320 | strlen(filename) + 1)) |
323 | return GNUNET_SYSERR; | 321 | return GNUNET_SYSERR; |
324 | /* recoverable error, store 'NULL' in *dst */ | 322 | /* recoverable error, store 'NULL' in *dst */ |
325 | *dst = NULL; | 323 | *dst = NULL; |
326 | return GNUNET_OK; | 324 | return GNUNET_OK; |
327 | } | 325 | } |
328 | 326 | ||
329 | /* Report the progress */ | 327 | /* Report the progress */ |
330 | if ( | 328 | if ( |
331 | GNUNET_OK != | 329 | GNUNET_OK != |
332 | write_message (S_ISDIR (sbuf.st_mode) | 330 | write_message(S_ISDIR(sbuf.st_mode) |
333 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY | 331 | ? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY |
334 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, | 332 | : GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE, |
335 | filename, | 333 | filename, |
336 | strlen (filename) + 1)) | 334 | strlen(filename) + 1)) |
337 | return GNUNET_SYSERR; | 335 | return GNUNET_SYSERR; |
338 | item = GNUNET_new (struct ScanTreeNode); | 336 | item = GNUNET_new(struct ScanTreeNode); |
339 | item->filename = GNUNET_strdup (filename); | 337 | item->filename = GNUNET_strdup(filename); |
340 | item->is_directory = (S_ISDIR (sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; | 338 | item->is_directory = (S_ISDIR(sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO; |
341 | item->file_size = fsize; | 339 | item->file_size = fsize; |
342 | if (GNUNET_YES == item->is_directory) | 340 | if (GNUNET_YES == item->is_directory) |
343 | { | ||
344 | struct RecursionContext rc; | ||
345 | |||
346 | rc.parent = item; | ||
347 | rc.stop = GNUNET_NO; | ||
348 | GNUNET_DISK_directory_scan (filename, &scan_callback, &rc); | ||
349 | if ( | ||
350 | (GNUNET_YES == rc.stop) || | ||
351 | (GNUNET_OK != | ||
352 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, | ||
353 | "..", | ||
354 | 3))) | ||
355 | { | 341 | { |
356 | free_tree (item); | 342 | struct RecursionContext rc; |
357 | return GNUNET_SYSERR; | 343 | |
344 | rc.parent = item; | ||
345 | rc.stop = GNUNET_NO; | ||
346 | GNUNET_DISK_directory_scan(filename, &scan_callback, &rc); | ||
347 | if ( | ||
348 | (GNUNET_YES == rc.stop) || | ||
349 | (GNUNET_OK != | ||
350 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY, | ||
351 | "..", | ||
352 | 3))) | ||
353 | { | ||
354 | free_tree(item); | ||
355 | return GNUNET_SYSERR; | ||
356 | } | ||
358 | } | 357 | } |
359 | } | ||
360 | *dst = item; | 358 | *dst = item; |
361 | return GNUNET_OK; | 359 | return GNUNET_OK; |
362 | } | 360 | } |
@@ -369,67 +367,67 @@ preprocess_file (const char *filename, struct ScanTreeNode **dst) | |||
369 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors | 367 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on fatal errors |
370 | */ | 368 | */ |
371 | static int | 369 | static int |
372 | extract_files (struct ScanTreeNode *item) | 370 | extract_files(struct ScanTreeNode *item) |
373 | { | 371 | { |
374 | struct GNUNET_CONTAINER_MetaData *meta; | 372 | struct GNUNET_CONTAINER_MetaData *meta; |
375 | ssize_t size; | 373 | ssize_t size; |
376 | size_t slen; | 374 | size_t slen; |
377 | 375 | ||
378 | if (GNUNET_YES == item->is_directory) | 376 | if (GNUNET_YES == item->is_directory) |
379 | { | 377 | { |
380 | /* for directories, we simply only descent, no extraction, no | 378 | /* for directories, we simply only descent, no extraction, no |
381 | progress reporting */ | 379 | progress reporting */ |
382 | struct ScanTreeNode *pos; | 380 | struct ScanTreeNode *pos; |
383 | 381 | ||
384 | for (pos = item->children_head; NULL != pos; pos = pos->next) | 382 | for (pos = item->children_head; NULL != pos; pos = pos->next) |
385 | if (GNUNET_OK != extract_files (pos)) | 383 | if (GNUNET_OK != extract_files(pos)) |
386 | return GNUNET_SYSERR; | 384 | return GNUNET_SYSERR; |
387 | return GNUNET_OK; | 385 | return GNUNET_OK; |
388 | } | 386 | } |
389 | 387 | ||
390 | /* this is the expensive operation, *afterwards* we'll check for aborts */ | 388 | /* this is the expensive operation, *afterwards* we'll check for aborts */ |
391 | meta = GNUNET_CONTAINER_meta_data_create (); | 389 | meta = GNUNET_CONTAINER_meta_data_create(); |
392 | #if HAVE_LIBEXTRACTOR | 390 | #if HAVE_LIBEXTRACTOR |
393 | EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta); | 391 | EXTRACTOR_extract(plugins, item->filename, NULL, 0, &add_to_md, meta); |
394 | #endif | 392 | #endif |
395 | slen = strlen (item->filename) + 1; | 393 | slen = strlen(item->filename) + 1; |
396 | size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta); | 394 | size = GNUNET_CONTAINER_meta_data_get_serialized_size(meta); |
397 | if (-1 == size) | 395 | if (-1 == size) |
398 | { | 396 | { |
399 | /* no meta data */ | 397 | /* no meta data */ |
400 | GNUNET_CONTAINER_meta_data_destroy (meta); | 398 | GNUNET_CONTAINER_meta_data_destroy(meta); |
401 | if (GNUNET_OK != | 399 | if (GNUNET_OK != |
402 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 400 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
403 | item->filename, | 401 | item->filename, |
404 | slen)) | 402 | slen)) |
405 | return GNUNET_SYSERR; | 403 | return GNUNET_SYSERR; |
406 | return GNUNET_OK; | 404 | return GNUNET_OK; |
407 | } | 405 | } |
408 | else if (size > (UINT16_MAX - sizeof (struct GNUNET_MessageHeader) - slen)) | 406 | else if (size > (UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen)) |
409 | { | 407 | { |
410 | /* We can't transfer more than 64k bytes in one message. */ | 408 | /* We can't transfer more than 64k bytes in one message. */ |
411 | size = UINT16_MAX - sizeof (struct GNUNET_MessageHeader) - slen; | 409 | size = UINT16_MAX - sizeof(struct GNUNET_MessageHeader) - slen; |
412 | } | 410 | } |
413 | { | 411 | { |
414 | char buf[size + slen]; | 412 | char buf[size + slen]; |
415 | char *dst = &buf[slen]; | 413 | char *dst = &buf[slen]; |
416 | 414 | ||
417 | GNUNET_memcpy (buf, item->filename, slen); | 415 | GNUNET_memcpy(buf, item->filename, slen); |
418 | size = GNUNET_CONTAINER_meta_data_serialize ( | 416 | size = GNUNET_CONTAINER_meta_data_serialize( |
419 | meta, | 417 | meta, |
420 | &dst, | 418 | &dst, |
421 | size, | 419 | size, |
422 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); | 420 | GNUNET_CONTAINER_META_DATA_SERIALIZE_PART); |
423 | if (size < 0) | 421 | if (size < 0) |
424 | { | 422 | { |
425 | GNUNET_break (0); | 423 | GNUNET_break(0); |
426 | size = 0; | 424 | size = 0; |
427 | } | 425 | } |
428 | GNUNET_CONTAINER_meta_data_destroy (meta); | 426 | GNUNET_CONTAINER_meta_data_destroy(meta); |
429 | if (GNUNET_OK != | 427 | if (GNUNET_OK != |
430 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, | 428 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA, |
431 | buf, | 429 | buf, |
432 | slen + size)) | 430 | slen + size)) |
433 | return GNUNET_SYSERR; | 431 | return GNUNET_SYSERR; |
434 | } | 432 | } |
435 | return GNUNET_OK; | 433 | return GNUNET_OK; |
@@ -441,23 +439,23 @@ extract_files (struct ScanTreeNode *item) | |||
441 | * Install a signal handler to ignore SIGPIPE. | 439 | * Install a signal handler to ignore SIGPIPE. |
442 | */ | 440 | */ |
443 | static void | 441 | static void |
444 | ignore_sigpipe () | 442 | ignore_sigpipe() |
445 | { | 443 | { |
446 | struct sigaction oldsig; | 444 | struct sigaction oldsig; |
447 | struct sigaction sig; | 445 | struct sigaction sig; |
448 | 446 | ||
449 | memset (&sig, 0, sizeof (struct sigaction)); | 447 | memset(&sig, 0, sizeof(struct sigaction)); |
450 | sig.sa_handler = SIG_IGN; | 448 | sig.sa_handler = SIG_IGN; |
451 | sigemptyset (&sig.sa_mask); | 449 | sigemptyset(&sig.sa_mask); |
452 | #ifdef SA_INTERRUPT | 450 | #ifdef SA_INTERRUPT |
453 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ | 451 | sig.sa_flags = SA_INTERRUPT; /* SunOS */ |
454 | #else | 452 | #else |
455 | sig.sa_flags = SA_RESTART; | 453 | sig.sa_flags = SA_RESTART; |
456 | #endif | 454 | #endif |
457 | if (0 != sigaction (SIGPIPE, &sig, &oldsig)) | 455 | if (0 != sigaction(SIGPIPE, &sig, &oldsig)) |
458 | fprintf (stderr, | 456 | fprintf(stderr, |
459 | "Failed to install SIGPIPE handler: %s\n", | 457 | "Failed to install SIGPIPE handler: %s\n", |
460 | strerror (errno)); | 458 | strerror(errno)); |
461 | } | 459 | } |
462 | 460 | ||
463 | 461 | ||
@@ -468,17 +466,17 @@ ignore_sigpipe () | |||
468 | * @param flags flags to use (O_RDONLY or O_WRONLY) | 466 | * @param flags flags to use (O_RDONLY or O_WRONLY) |
469 | */ | 467 | */ |
470 | static void | 468 | static void |
471 | make_dev_zero (int fd, int flags) | 469 | make_dev_zero(int fd, int flags) |
472 | { | 470 | { |
473 | int z; | 471 | int z; |
474 | 472 | ||
475 | GNUNET_assert (0 == close (fd)); | 473 | GNUNET_assert(0 == close(fd)); |
476 | z = open ("/dev/null", flags); | 474 | z = open("/dev/null", flags); |
477 | GNUNET_assert (-1 != z); | 475 | GNUNET_assert(-1 != z); |
478 | if (z == fd) | 476 | if (z == fd) |
479 | return; | 477 | return; |
480 | GNUNET_break (fd == dup2 (z, fd)); | 478 | GNUNET_break(fd == dup2(z, fd)); |
481 | GNUNET_assert (0 == close (z)); | 479 | GNUNET_assert(0 == close(z)); |
482 | } | 480 | } |
483 | 481 | ||
484 | #endif | 482 | #endif |
@@ -495,7 +493,7 @@ make_dev_zero (int fd, int flags) | |||
495 | * @return 0 on success | 493 | * @return 0 on success |
496 | */ | 494 | */ |
497 | int | 495 | int |
498 | main (int argc, char *const *argv) | 496 | main(int argc, char *const *argv) |
499 | { | 497 | { |
500 | const char *filename_expanded; | 498 | const char *filename_expanded; |
501 | const char *ex; | 499 | const char *ex; |
@@ -505,98 +503,98 @@ main (int argc, char *const *argv) | |||
505 | /* We're using stdout to communicate binary data back to the parent; use | 503 | /* We're using stdout to communicate binary data back to the parent; use |
506 | * binary mode. | 504 | * binary mode. |
507 | */ | 505 | */ |
508 | _setmode (1, _O_BINARY); | 506 | _setmode(1, _O_BINARY); |
509 | /* Get utf-8-encoded arguments */ | 507 | /* Get utf-8-encoded arguments */ |
510 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 508 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
511 | return 5; | 509 | return 5; |
512 | output_stream = 1; /* stdout */ | 510 | output_stream = 1; /* stdout */ |
513 | #else | 511 | #else |
514 | ignore_sigpipe (); | 512 | ignore_sigpipe(); |
515 | /* move stdout to some other FD for IPC, bind | 513 | /* move stdout to some other FD for IPC, bind |
516 | stdout/stderr to /dev/null */ | 514 | stdout/stderr to /dev/null */ |
517 | output_stream = dup (1); | 515 | output_stream = dup(1); |
518 | make_dev_zero (1, O_WRONLY); | 516 | make_dev_zero(1, O_WRONLY); |
519 | make_dev_zero (2, O_WRONLY); | 517 | make_dev_zero(2, O_WRONLY); |
520 | #endif | 518 | #endif |
521 | 519 | ||
522 | /* parse command line */ | 520 | /* parse command line */ |
523 | if ((3 != argc) && (2 != argc)) | 521 | if ((3 != argc) && (2 != argc)) |
524 | { | 522 | { |
525 | fprintf (stderr, | 523 | fprintf(stderr, |
526 | "%s", | 524 | "%s", |
527 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); | 525 | "gnunet-helper-fs-publish needs exactly one or two arguments\n"); |
528 | #if WINDOWS | 526 | #if WINDOWS |
529 | GNUNET_free ((void *) argv); | 527 | GNUNET_free((void *)argv); |
530 | #endif | 528 | #endif |
531 | return 1; | 529 | return 1; |
532 | } | 530 | } |
533 | filename_expanded = argv[1]; | 531 | filename_expanded = argv[1]; |
534 | ex = argv[2]; | 532 | ex = argv[2]; |
535 | if ((NULL == ex) || (0 != strcmp (ex, "-"))) | 533 | if ((NULL == ex) || (0 != strcmp(ex, "-"))) |
536 | { | 534 | { |
537 | #if HAVE_LIBEXTRACTOR | 535 | #if HAVE_LIBEXTRACTOR |
538 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); | 536 | plugins = EXTRACTOR_plugin_add_defaults(EXTRACTOR_OPTION_DEFAULT_POLICY); |
539 | if (NULL != ex) | 537 | if (NULL != ex) |
540 | plugins = EXTRACTOR_plugin_add_config (plugins, | 538 | plugins = EXTRACTOR_plugin_add_config(plugins, |
541 | ex, | 539 | ex, |
542 | EXTRACTOR_OPTION_DEFAULT_POLICY); | 540 | EXTRACTOR_OPTION_DEFAULT_POLICY); |
543 | #endif | 541 | #endif |
544 | } | 542 | } |
545 | 543 | ||
546 | /* scan tree to find out how much work there is to be done */ | 544 | /* scan tree to find out how much work there is to be done */ |
547 | if (GNUNET_OK != preprocess_file (filename_expanded, &root)) | 545 | if (GNUNET_OK != preprocess_file(filename_expanded, &root)) |
548 | { | 546 | { |
549 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); | 547 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0); |
550 | #if HAVE_LIBEXTRACTOR | 548 | #if HAVE_LIBEXTRACTOR |
551 | EXTRACTOR_plugin_remove_all (plugins); | 549 | EXTRACTOR_plugin_remove_all(plugins); |
552 | #endif | 550 | #endif |
553 | #if WINDOWS | 551 | #if WINDOWS |
554 | GNUNET_free ((void *) argv); | 552 | GNUNET_free((void *)argv); |
555 | #endif | 553 | #endif |
556 | return 2; | 554 | return 2; |
557 | } | 555 | } |
558 | /* signal that we're done counting files, so that a percentage of | 556 | /* signal that we're done counting files, so that a percentage of |
559 | progress can now be calculated */ | 557 | progress can now be calculated */ |
560 | if (GNUNET_OK != | 558 | if (GNUNET_OK != |
561 | write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, | 559 | write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, |
562 | NULL, | 560 | NULL, |
563 | 0)) | 561 | 0)) |
564 | { | 562 | { |
565 | #if HAVE_LIBEXTRACTOR | 563 | #if HAVE_LIBEXTRACTOR |
566 | EXTRACTOR_plugin_remove_all (plugins); | 564 | EXTRACTOR_plugin_remove_all(plugins); |
567 | #endif | 565 | #endif |
568 | #if WINDOWS | 566 | #if WINDOWS |
569 | GNUNET_free ((void *) argv); | 567 | GNUNET_free((void *)argv); |
570 | #endif | 568 | #endif |
571 | return 3; | 569 | return 3; |
572 | } | 570 | } |
573 | if (NULL != root) | 571 | if (NULL != root) |
574 | { | ||
575 | if (GNUNET_OK != extract_files (root)) | ||
576 | { | 572 | { |
577 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, | 573 | if (GNUNET_OK != extract_files(root)) |
578 | NULL, | 574 | { |
579 | 0); | 575 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, |
580 | free_tree (root); | 576 | NULL, |
577 | 0); | ||
578 | free_tree(root); | ||
581 | #if HAVE_LIBEXTRACTOR | 579 | #if HAVE_LIBEXTRACTOR |
582 | EXTRACTOR_plugin_remove_all (plugins); | 580 | EXTRACTOR_plugin_remove_all(plugins); |
583 | #endif | 581 | #endif |
584 | #if WINDOWS | 582 | #if WINDOWS |
585 | GNUNET_free ((void *) argv); | 583 | GNUNET_free((void *)argv); |
586 | #endif | 584 | #endif |
587 | return 4; | 585 | return 4; |
586 | } | ||
587 | free_tree(root); | ||
588 | } | 588 | } |
589 | free_tree (root); | ||
590 | } | ||
591 | /* enable "clean" shutdown by telling parent that we are done */ | 589 | /* enable "clean" shutdown by telling parent that we are done */ |
592 | (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, | 590 | (void)write_message(GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, |
593 | NULL, | 591 | NULL, |
594 | 0); | 592 | 0); |
595 | #if HAVE_LIBEXTRACTOR | 593 | #if HAVE_LIBEXTRACTOR |
596 | EXTRACTOR_plugin_remove_all (plugins); | 594 | EXTRACTOR_plugin_remove_all(plugins); |
597 | #endif | 595 | #endif |
598 | #if WINDOWS | 596 | #if WINDOWS |
599 | GNUNET_free ((void *) argv); | 597 | GNUNET_free((void *)argv); |
600 | #endif | 598 | #endif |
601 | return 0; | 599 | return 0; |
602 | } | 600 | } |