uint64_t file_size;
/**
- * GNUNET_YES if this is a directory
+ * #GNUNET_YES if this is a directory
*/
int is_directory;
* @param data_mime_type mime-type of data (not of the original file);
* can be NULL (if mime-type is not known)
* @param data actual meta-data found
- * @param data_len number of bytes in data
+ * @param data_len number of bytes in @a data
* @return always 0 to continue extracting
*/
static int
{
struct GNUNET_CONTAINER_MetaData *md = cls;
- (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
- data_mime_type, data, data_len);
+ if ( ((EXTRACTOR_METAFORMAT_UTF8 == format) ||
+ (EXTRACTOR_METAFORMAT_C_STRING == format)) &&
+ ('\0' != data[data_len - 1]) )
+ {
+ char zdata[data_len + 1];
+ memcpy (zdata, data, data_len);
+ zdata[data_len] = '\0';
+ (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
+ data_mime_type, zdata, data_len + 1);
+ }
+ else
+ {
+ (void) GNUNET_CONTAINER_meta_data_insert (md, plugin_name, type, format,
+ data_mime_type, data, data_len);
+ }
return 0;
}
/**
- * Free memory of the 'tree' structure
+ * Free memory of the @a tree structure
*
* @param tree tree to free
*/
-static void
+static void
free_tree (struct ScanTreeNode *tree)
{
struct ScanTreeNode *pos;
if (NULL != tree->parent)
GNUNET_CONTAINER_DLL_remove (tree->parent->children_head,
tree->parent->children_tail,
- tree);
+ tree);
GNUNET_free (tree->filename);
GNUNET_free (tree);
}
struct GNUNET_MessageHeader hdr;
#if 0
- fprintf (stderr,
+ fprintf (stderr,
"Helper sends %u-byte message of type %u\n",
(unsigned int) (sizeof (struct GNUNET_MessageHeader) + data_length),
(unsigned int) message_type);
*
* @param filename file or directory to scan
* @param dst where to store the resulting share tree item;
- * NULL is stored in @a dst upon recoverable errors (#GNUNET_OK is returned)
+ * NULL is stored in @a dst upon recoverable errors (#GNUNET_OK is returned)
* @return #GNUNET_OK on success, #GNUNET_SYSERR on error
*/
static int
/* Report the progress */
if (GNUNET_OK !=
- write_message (S_ISDIR (sbuf.st_mode)
+ write_message (S_ISDIR (sbuf.st_mode)
? GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY
: GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE,
filename, strlen (filename) + 1))
rc.parent = item;
rc.stop = GNUNET_NO;
- GNUNET_DISK_directory_scan (filename,
- &scan_callback,
- &rc);
+ GNUNET_DISK_directory_scan (filename,
+ &scan_callback,
+ &rc);
if ( (GNUNET_YES == rc.stop) ||
(GNUNET_OK !=
write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY,
*/
static int
extract_files (struct ScanTreeNode *item)
-{
+{
struct GNUNET_CONTAINER_MetaData *meta;
ssize_t size;
size_t slen;
return GNUNET_SYSERR;
return GNUNET_OK;
}
-
+
/* this is the expensive operation, *afterwards* we'll check for aborts */
meta = GNUNET_CONTAINER_meta_data_create ();
EXTRACTOR_extract (plugins, item->filename, NULL, 0, &add_to_md, meta);
if (GNUNET_OK !=
write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
item->filename, slen))
- return GNUNET_SYSERR;
+ return GNUNET_SYSERR;
return GNUNET_OK;
}
else if (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,
GNUNET_CONTAINER_meta_data_destroy (meta);
if (GNUNET_OK !=
write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA,
- buf,
+ buf,
slen + size))
return GNUNET_SYSERR;
}
* @param flags flags to use (O_RDONLY or O_WRONLY)
*/
static void
-make_dev_zero (int fd,
+make_dev_zero (int fd,
int flags)
{
int z;
* otherwise custom plugins to load from LE
* @return 0 on success
*/
-int
+int
main (int argc,
char *const *argv)
{
output_stream = 1; /* stdout */
#else
ignore_sigpipe ();
- /* move stdout to some other FD for IPC, bind
+ /* move stdout to some other FD for IPC, bind
stdout/stderr to /dev/null */
output_stream = dup (1);
make_dev_zero (1, O_WRONLY);
/* parse command line */
if ( (3 != argc) && (2 != argc) )
{
- FPRINTF (stderr,
+ FPRINTF (stderr,
"%s",
"gnunet-helper-fs-publish needs exactly one or two arguments\n");
#if WINDOWS
}
/* scan tree to find out how much work there is to be done */
- if (GNUNET_OK != preprocess_file (filename_expanded,
+ if (GNUNET_OK != preprocess_file (filename_expanded,
&root))
{
(void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR, NULL, 0);
#endif
return 2;
}
- /* signal that we're done counting files, so that a percentage of
+ /* 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))
#if WINDOWS
GNUNET_free ((void*) argv);
#endif
- return 3;
+ return 3;
}
if (NULL != root)
{
(void) write_message (GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED, NULL, 0);
EXTRACTOR_plugin_remove_all (plugins);
#if WINDOWS
- GNUNET_free ((void*) argv);
+ GNUNET_free ((void*) argv);
#endif
return 0;
}