88static struct EXTRACTOR_PluginList *
plugins;
118 enum EXTRACTOR_MetaType
type,
119 enum EXTRACTOR_MetaFormat format,
120 const char *data_mime_type,
126 if (((EXTRACTOR_METAFORMAT_UTF8 == format) ||
127 (EXTRACTOR_METAFORMAT_C_STRING == format)) &&
128 (
'\0' !=
data[data_len - 1]))
130 char zdata[data_len + 1];
132 zdata[data_len] =
'\0';
189 const char *cbuf = buf;
200 while ((wr > 0) && (total <
size));
203 "Failed to write to stdout: %s\n",
224 "Helper sends %u-byte message of type %u\n",
226 (
unsigned int) message_type);
228 hdr.
type = htons (message_type);
315 if ((0 != stat (
filename, &sbuf)) ||
316 ((! S_ISDIR (sbuf.st_mode)) &&
417 char buf[
size + slen];
418 char *dst = &buf[slen];
448 struct sigaction oldsig;
449 struct sigaction sig;
451 memset (&sig, 0,
sizeof(
struct sigaction));
452 sig.sa_handler = SIG_IGN;
453 sigemptyset (&sig.sa_mask);
455 sig.sa_flags = SA_INTERRUPT;
457 sig.sa_flags = SA_RESTART;
459 if (0 != sigaction (SIGPIPE, &sig, &oldsig))
461 "Failed to install SIGPIPE handler: %s\n",
478 z = open (
"/dev/null", flags);
498main (
int argc,
char *
const *argv)
500 const char *filename_expanded;
512 if ((3 != argc) && (2 != argc))
516 "gnunet-helper-fs-publish needs exactly one or two arguments\n");
519 filename_expanded = argv[1];
521 if ((NULL == ex) || (0 != strcmp (ex,
"-")))
524 plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY);
528 EXTRACTOR_OPTION_DEFAULT_POLICY);
537 EXTRACTOR_plugin_remove_all (
plugins);
549 EXTRACTOR_plugin_remove_all (
plugins);
562 EXTRACTOR_plugin_remove_all (
plugins);
573 EXTRACTOR_plugin_remove_all (
plugins);
static char * plugin_name
Name of our plugin.
static char * data
The data to insert into the dht.
static int write_all(const void *buf, size_t size)
Write size bytes from buf into the output_stream.
static int output_stream
File descriptor we use for IPC with the parent.
static int scan_callback(void *cls, const char *filename)
Function called by the directory iterator to (recursively) add all of the files in the directory to t...
static void free_tree(struct ScanTreeNode *tree)
Free memory of the tree structure.
static int write_message(uint16_t message_type, const char *data, size_t data_length)
Write message to the master process.
int main(int argc, char *const *argv)
Main function of the helper process to extract meta data.
static void make_dev_zero(int fd, int flags)
Turn the given file descriptor in to '/dev/null'.
static void ignore_sigpipe()
Install a signal handler to ignore SIGPIPE.
static int preprocess_file(const char *filename, struct ScanTreeNode **dst)
Function called to (recursively) add all of the files in the directory to the tree.
static int extract_files(struct ScanTreeNode *item)
Extract metadata from files.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_FS_MetaData * meta
Meta-data provided via command-line option.
API for file sharing via GNUnet.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_DIRECTORY
Progress information from the helper: found a directory.
#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_FINISHED
Signal that helper is done.
#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_META_DATA
Extracted meta data from the helper.
#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_ERROR
Error signal from the helper.
#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_SKIP_FILE
Signal that helper skipped a file.
#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_COUNTING_DONE
Signal that helper is done scanning the directory tree.
#define GNUNET_MESSAGE_TYPE_FS_PUBLISH_HELPER_PROGRESS_FILE
Progress information from the helper: found a file.
static unsigned int size
Size of the "table".
static struct PluginList * plugins
List of plugins we have loaded.
Closure for the 'scan_callback'.
struct ScanTreeNode * parent
Parent to add the files to.
int stop
Flag to set to GNUNET_YES on serious errors.
A node of a directory tree.
struct ScanTreeNode * children_head
This is a doubly-linked tree NULL for files and empty directories.
char * filename
Name of the file/directory.
struct ScanTreeNode * next
This is a doubly-linked list.
struct ScanTreeNode * prev
This is a doubly-linked list.
uint64_t file_size
Size of the file (if it is a file), in bytes.
struct ScanTreeNode * parent
Parent of this node, NULL for top-level entries.
int is_directory
GNUNET_YES if this is a directory
struct ScanTreeNode * children_tail
This is a doubly-linked tree NULL for files and empty directories.