{
struct GNUNET_MessageHeader hdr;
+#if 0
+ fprintf (stderr, "Helper sends %u-byte message of type %u\n",
+ (unsigned int) (sizeof (struct GNUNET_MessageHeader) + data_length),
+ (unsigned int) message_type);
+#endif
hdr.type = htons (message_type);
hdr.size = htons (sizeof (struct GNUNET_MessageHeader) + data_length);
if ( (GNUNET_OK !=
* the scan. Does NOT yet add any metadata.
*
* @param filename file or directory to scan
- * @param dst where to store the resulting share tree item
+ * @param dst where to store the resulting share tree item;
+ * NULL is stored in 'dst' upon recoverable errors (GNUNET_OK is returned)
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
static int
rc->stop = GNUNET_YES;
return GNUNET_SYSERR;
}
+ if (NULL == chld)
+ return GNUNET_OK;
chld->parent = rc->parent;
GNUNET_CONTAINER_DLL_insert (rc->parent->children_head,
rc->parent->children_tail,
* the scan. Does NOT yet add any metadata.
*
* @param filename file or directory to scan
- * @param dst where to store the resulting share tree item
+ * @param dst where to store the resulting share tree item;
+ * NULL is stored in 'dst' upon recoverable errors (GNUNET_OK is returned)
* @return GNUNET_OK on success, GNUNET_SYSERR on error
*/
static int
write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE,
filename, strlen (filename) + 1))
return GNUNET_SYSERR;
+ /* recoverable error, store 'NULL' in *dst */
+ *dst = NULL;
return GNUNET_OK;
}
item->filename = GNUNET_strdup (filename);
item->is_directory = (S_ISDIR (sbuf.st_mode)) ? GNUNET_YES : GNUNET_NO;
item->file_size = fsize;
- if (item->is_directory == GNUNET_YES)
+ if (GNUNET_YES == item->is_directory)
{
struct RecursionContext rc;
GNUNET_DISK_directory_scan (filename,
&scan_callback,
&rc);
- if ( (rc.stop == GNUNET_YES) ||
+ if ( (GNUNET_YES == rc.stop) ||
(GNUNET_OK !=
write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY,
"..", 3)) )
ssize_t size;
size_t slen;
- if (item->is_directory == GNUNET_YES)
+ if (GNUNET_YES == item->is_directory)
{
/* for directories, we simply only descent, no extraction, no
progress reporting */
/* this is the expensive operation, *afterwards* we'll check for aborts */
meta = GNUNET_CONTAINER_meta_data_create ();
- if (NULL != plugins)
- EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta);
+ EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta);
slen = strlen (item->filename) + 1;
size = GNUNET_CONTAINER_meta_data_get_serialized_size (meta);
if (-1 == size)
return GNUNET_SYSERR;
return GNUNET_OK;
}
+ else if (size > (UINT16_MAX - sizeof (struct GNUNET_MessageHeader) - slen))
+ {
+ /* We can't transfer more than 64k bytes in one message. */
+ size = UINT16_MAX - sizeof (struct GNUNET_MessageHeader) - slen;
+ }
{
char buf[size + slen];
char *dst = &buf[slen];
memcpy (buf, item->filename, slen);
size = GNUNET_CONTAINER_meta_data_serialize (meta,
- &dst, size - slen,
+ &dst, size,
GNUNET_CONTAINER_META_DATA_SERIALIZE_PART);
+ if (size < 0)
+ {
+ GNUNET_break (0);
+ size = 0;
+ }
GNUNET_CONTAINER_meta_data_destroy (meta);
if (GNUNET_OK !=
write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
}
+#ifndef WINDOWS
+/**
+ * Install a signal handler to ignore SIGPIPE.
+ */
+static void
+ignore_sigpipe ()
+{
+ struct sigaction oldsig;
+ struct sigaction sig;
+
+ memset (&sig, 0, sizeof (struct sigaction));
+ sig.sa_handler = SIG_IGN;
+ sigemptyset (&sig.sa_mask);
+#ifdef SA_INTERRUPT
+ sig.sa_flags = SA_INTERRUPT; /* SunOS */
+#else
+ sig.sa_flags = SA_RESTART;
+#endif
+ if (0 != sigaction (SIGPIPE, &sig, &oldsig))
+ fprintf (stderr,
+ "Failed to install SIGPIPE handler: %s\n", strerror (errno));
+}
+#endif
+
+
/**
* Main function of the helper process to extract meta data.
*
* @return 0 on success
*/
int main(int argc,
- char **argv)
+ char *const *argv)
{
const char *filename_expanded;
const char *ex;
* binary mode.
*/
_setmode (1, _O_BINARY);
+ /* Get utf-8-encoded arguments */
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ return 5;
+#else
+ ignore_sigpipe ();
#endif
/* parse command line */
- if ( (argc != 3) && (argc != 2) )
+ if ( (3 != argc) && (2 != argc) )
{
FPRINTF (stderr,
"%s",
"gnunet-helper-fs-publish needs exactly one or two arguments\n");
+#if WINDOWS
+ GNUNET_free ((void*) argv);
+#endif
return 1;
}
filename_expanded = argv[1];
ex = argv[2];
- if ( (ex == NULL) ||
+ if ( (NULL == ex) ||
(0 != strcmp (ex, "-")) )
{
plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY);
&root))
{
(void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0);
+ EXTRACTOR_plugin_remove_all (plugins);
+#if WINDOWS
+ GNUNET_free ((void*) argv);
+#endif
return 2;
}
/* signal that we're done counting files, so that a percentage of
progress can now be calculated */
if (GNUNET_OK !=
write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE, NULL, 0))
+ {
+ EXTRACTOR_plugin_remove_all (plugins);
+#if WINDOWS
+ GNUNET_free ((void*) argv);
+#endif
return 3;
- if (GNUNET_OK !=
- extract_files (root))
+ }
+ if (NULL != root)
{
- (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0);
+ if (GNUNET_OK !=
+ extract_files (root))
+ {
+ (void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0);
+ free_tree (root);
+ EXTRACTOR_plugin_remove_all (plugins);
+#if WINDOWS
+ GNUNET_free ((void*) argv);
+#endif
+ return 4;
+ }
free_tree (root);
- return 4;
}
- free_tree (root);
/* enable "clean" shutdown by telling parent that we are done */
(void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, NULL, 0);
- if (NULL != plugins)
- EXTRACTOR_plugin_remove_all (plugins);
-
+ EXTRACTOR_plugin_remove_all (plugins);
+#if WINDOWS
+ GNUNET_free ((void*) argv);
+#endif
return 0;
}