- * Closure for "dir_scan_cb".
- */
-struct DirScanCls
-{
- /**
- * Metadata extractors to use.
- */
- struct EXTRACTOR_PluginList *extractors;
-
- /**
- * Function to call on each directory entry.
- */
- GNUNET_FS_FileProcessor proc;
-
- /**
- * Closure for proc.
- */
- void *proc_cls;
-
- /**
- * Scanner to use for subdirectories.
- */
- GNUNET_FS_DirectoryScanner scanner;
-
- /**
- * Closure for scanner.
- */
- void *scanner_cls;
-
- /**
- * Set to an error message (if any).
- */
- char *emsg;
-
- /**
- * Should files be indexed?
- */
- int do_index;
-
- /**
- * Desired anonymity level.
- */
- uint32_t anonymity;
-
- /**
- * Desired publishing priority.
- */
- uint32_t priority;
-
- /**
- * Expiration time for publication.
- */
- struct GNUNET_TIME_Absolute expiration;
-};
-
-
-/**
- * Function called on each entry in a file to
- * cause default-publishing.
- * @param cls closure (struct DirScanCls)
- * @param filename name of the file to be published
- * @return GNUNET_OK on success, GNUNET_SYSERR to abort
- */
-static int
-dir_scan_cb (void *cls,
- const char *filename)
-{
- struct DirScanCls *dsc = cls;
- struct stat sbuf;
- struct GNUNET_FS_FileInformation *fi;
- struct GNUNET_FS_Uri *ksk_uri;
- struct GNUNET_FS_Uri *keywords;
- struct GNUNET_CONTAINER_MetaData *meta;
-
- if (0 != STAT (filename, &sbuf))
- {
- GNUNET_asprintf (&dsc->emsg,
- _("`%s' failed on file `%s': %s"),
- "stat",
- filename,
- STRERROR (errno));
- return GNUNET_SYSERR;
- }
- if (S_ISDIR (sbuf.st_mode))
- {
- fi = GNUNET_FS_file_information_create_from_directory (NULL,
- filename,
- dsc->scanner,
- dsc->scanner_cls,
- dsc->do_index,
- dsc->anonymity,
- dsc->priority,
- dsc->expiration,
- &dsc->emsg);
- if (NULL == fi)
- {
- GNUNET_assert (NULL != dsc->emsg);
- return GNUNET_SYSERR;
- }
- }
- else
- {
- meta = GNUNET_CONTAINER_meta_data_create ();
- GNUNET_CONTAINER_meta_data_extract_from_file (meta,
- filename,
- dsc->extractors);
- // FIXME: remove path from filename in metadata!
- keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta);
- ksk_uri = GNUNET_FS_uri_ksk_canonicalize (keywords);
- fi = GNUNET_FS_file_information_create_from_file (NULL,
- filename,
- ksk_uri,
- meta,
- dsc->do_index,
- dsc->anonymity,
- dsc->priority,
- dsc->expiration);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- GNUNET_FS_uri_destroy (keywords);
- GNUNET_FS_uri_destroy (ksk_uri);
- }
- dsc->proc (dsc->proc_cls,
- filename,
- fi);
- return GNUNET_OK;
-}
-
-
-/**
- * Simple, useful default implementation of a directory scanner
- * (GNUNET_FS_DirectoryScanner). This implementation expects to get a
- * UNIX filename, will publish all files in the directory except hidden
- * files (those starting with a "."). Metadata will be extracted
- * using GNU libextractor; the specific list of plugins should be
- * specified in "cls", passing NULL will disable (!) metadata
- * extraction. Keywords will be derived from the metadata and be
- * subject to default canonicalization. This is strictly a
- * convenience function.