- ret->anonymity = anonymity;
- ret->priority = priority;
- return ret;
-}
-
-
-/**
- * Closure for "dir_scan_cb".
- */
-struct DirScanCls
-{
- /**
- * Metadata extractors to use.
- */
- struct EXTRACTOR_PluginList *extractors;
-
- /**
- * Master context.
- */
- struct GNUNET_FS_Handle *h;
-
- /**
- * 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 (dsc->h,
- 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_FS_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 (dsc->h,
- 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.
- *
- * @param cls must be of type "struct EXTRACTOR_Extractor*"
- * @param h handle to the file sharing subsystem
- * @param dirname name of the directory to scan
- * @param do_index should files be indexed or inserted
- * @param anonymity desired anonymity level
- * @param priority priority for publishing
- * @param expirationTime expiration for publication
- * @param proc function called on each entry
- * @param proc_cls closure for proc
- * @param emsg where to store an error message (on errors)
- * @return GNUNET_OK on success
- */
-int
-GNUNET_FS_directory_scanner_default (void *cls,
- struct GNUNET_FS_Handle *h,
- const char *dirname,
- int do_index,
- uint32_t anonymity,
- uint32_t priority,
- struct GNUNET_TIME_Absolute expirationTime,
- GNUNET_FS_FileProcessor proc,
- void *proc_cls,
- char **emsg)
-{
- struct EXTRACTOR_PluginList *ex = cls;
- struct DirScanCls dsc;
-
- dsc.h = h;
- dsc.extractors = ex;
- dsc.proc = proc;
- dsc.proc_cls = proc_cls;
- dsc.scanner = &GNUNET_FS_directory_scanner_default;
- dsc.scanner_cls = cls;
- dsc.do_index = do_index;
- dsc.anonymity = anonymity;
- dsc.priority = priority;
- dsc.expiration = expirationTime;
- if (-1 == GNUNET_DISK_directory_scan (dirname,
- &dir_scan_cb,
- &dsc))
- {
- GNUNET_assert (NULL != dsc.emsg);
- *emsg = dsc.emsg;
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Closure for dirproc function.
- */
-struct EntryProcCls
-{
- /**
- * Linked list of directory entries that is being
- * created.
- */
- struct GNUNET_FS_FileInformation *entries;
-
-};
-
-
-/**
- * Function that processes a directory entry that
- * was obtained from the scanner.
- * @param cls our closure
- * @param filename name of the file (unused, why there???)
- * @param fi information for publishing the file
- */
-static void
-dirproc (void *cls,
- const char *filename,
- struct GNUNET_FS_FileInformation *fi)
-{
- struct EntryProcCls *dc = cls;
-
- GNUNET_assert (fi->next == NULL);
- GNUNET_assert (fi->dir == NULL);
- fi->next = dc->entries;
- dc->entries = fi;
-}
-
-
-/**
- * Create a publish-structure from an existing file hierarchy, inferring
- * and organizing keywords and metadata as much as possible. This
- * function primarily performs the recursive build and re-organizes
- * keywords and metadata; for automatically getting metadata
- * extraction, scanning of directories and creation of the respective
- * GNUNET_FS_FileInformation entries the default scanner should be
- * passed (GNUNET_FS_directory_scanner_default). This is strictly a
- * convenience function.
- *
- * @param h handle to the file sharing subsystem
- * @param client_info initial value for the client-info value for this entry
- * @param filename name of the top-level file or directory
- * @param scanner function used to get a list of files in a directory
- * @param scanner_cls closure for scanner
- * @param do_index should files in the hierarchy be indexed?
- * @param anonymity what is the desired anonymity level for sharing?
- * @param priority what is the priority for OUR node to
- * keep this file available? Use 0 for maximum anonymity and
- * minimum reliability...
- * @param expirationTime when should this content expire?
- * @param emsg where to store an error message
- * @return publish structure entry for the directory, NULL on error
- */
-struct GNUNET_FS_FileInformation *
-GNUNET_FS_file_information_create_from_directory (struct GNUNET_FS_Handle *h,
- void *client_info,
- const char *filename,
- GNUNET_FS_DirectoryScanner scanner,
- void *scanner_cls,
- int do_index,
- uint32_t anonymity,
- uint32_t priority,
- struct GNUNET_TIME_Absolute expirationTime,
- char **emsg)
-{
- struct GNUNET_FS_FileInformation *ret;
- struct EntryProcCls dc;
- struct GNUNET_FS_Uri *ksk;
- struct GNUNET_CONTAINER_MetaData *meta;
- const char *fn;
- const char *ss;
-
- dc.entries = NULL;
- meta = GNUNET_CONTAINER_meta_data_create ();
- GNUNET_FS_meta_data_make_directory (meta);
- scanner (scanner_cls,
- h,
- filename,
- do_index,
- anonymity,
- priority,
- expirationTime,
- &dirproc,
- &dc,
- emsg);
- ksk = NULL; // FIXME...
- // FIXME: create meta!
- ret = GNUNET_FS_file_information_create_empty_directory (h,
- client_info,
- ksk,
- meta,
- anonymity,
- priority,
- expirationTime);
- GNUNET_CONTAINER_meta_data_destroy (meta);
- ret->data.dir.entries = dc.entries;
- while (dc.entries != NULL)
- {
- dc.entries->dir = ret;
- dc.entries = dc.entries->next;
- }
- fn = filename;
- while ( (NULL != (ss = strstr (fn,
- DIR_SEPARATOR_STR))) &&
- (strlen (ss) > 1) )
- fn = ss + 1;
- GNUNET_CONTAINER_meta_data_insert (ret->meta,
- "<gnunet>",
- EXTRACTOR_METATYPE_FILENAME,
- EXTRACTOR_METAFORMAT_C_STRING,
- "text/plain",
- fn,
- strlen (fn) + 1);
- ret->filename = GNUNET_strdup (filename);