[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r4094 - in GNUnet: . doc/man src/applications/fs/ecrs src/a
From: |
grothoff |
Subject: |
[GNUnet-SVN] r4094 - in GNUnet: . doc/man src/applications/fs/ecrs src/applications/fs/tools |
Date: |
Thu, 28 Dec 2006 21:12:38 -0800 (PST) |
Author: grothoff
Date: 2006-12-28 21:12:33 -0800 (Thu, 28 Dec 2006)
New Revision: 4094
Modified:
GNUnet/ChangeLog
GNUnet/doc/man/gnunet-download.1
GNUnet/src/applications/fs/ecrs/directory.c
GNUnet/src/applications/fs/tools/gnunet-download.c
Log:
addressing Mantis #1013
Modified: GNUnet/ChangeLog
===================================================================
--- GNUnet/ChangeLog 2006-12-29 04:34:01 UTC (rev 4093)
+++ GNUnet/ChangeLog 2006-12-29 05:12:33 UTC (rev 4094)
@@ -2,6 +2,7 @@
Hostname resolution with gnunet-peer-info implemented (#1076).
Proper linking of gnunet-pseudonym (#1161).
Drop group permissions when changing user (#1162).
+ gnunet-download support for directory files implemented (#1013).
Thu Dec 28 20:44:45 MST 2006
Hopefully fixing build problems on certain systems with
Modified: GNUnet/doc/man/gnunet-download.1
===================================================================
--- GNUnet/doc/man/gnunet-download.1 2006-12-29 04:34:01 UTC (rev 4093)
+++ GNUnet/doc/man/gnunet-download.1 2006-12-29 05:12:33 UTC (rev 4094)
@@ -14,6 +14,9 @@
\fB\-c \fIFILENAME\fR, \fB\-\-config=FILENAME\fR
use config file (defaults: ~/.gnunet/gnunet.conf)
.TP
+\fB\-d, \fB\-\-directory\fR
+download a GNUnet directory that has already been downloaded. Requires that a
filename of an existing file is specified instead of the URI. The download
will only download the top\-level files in the directory unless the `-R' option
is also specified.
+.TP
\fB\-h\fR, \fB\-\-help\fR
print help page
.TP
Modified: GNUnet/src/applications/fs/ecrs/directory.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/directory.c 2006-12-29 04:34:01 UTC (rev
4093)
+++ GNUnet/src/applications/fs/ecrs/directory.c 2006-12-29 05:12:33 UTC (rev
4094)
@@ -76,8 +76,10 @@
*md = ECRS_deserializeMetaData(ectx,
&data[8 + sizeof(unsigned int)],
mdSize);
- if (*md == NULL)
+ if (*md == NULL) {
+ GE_BREAK(ectx, 0);
return SYSERR; /* malformed !*/
+ }
pos = 8 + sizeof(unsigned int) + mdSize;
}
while (pos < len) {
@@ -89,6 +91,7 @@
pos = align;
if (pos >= len) {
/* malformed */
+ GE_BREAK(ectx, 0);
break;
}
}
@@ -97,14 +100,17 @@
(data[epos] != '\0') )
epos++;
if (epos == len) {
+ GE_BREAK(ectx, 0);
return SYSERR; /* malformed */
}
fi.uri = ECRS_stringToUri(ectx,
&data[pos]);
pos = epos+1;
- if (fi.uri == NULL)
+ if (fi.uri == NULL) {
+ GE_BREAK(ectx, 0);
return SYSERR; /* malformed! */
+ }
if (ECRS_isKeywordUri(fi.uri)) {
ECRS_freeUri(fi.uri);
GE_BREAK(ectx, 0);
@@ -119,6 +125,7 @@
pos += sizeof(unsigned int);
if (pos + mdSize > len) {
ECRS_freeUri(fi.uri);
+ GE_BREAK(ectx, 0);
return SYSERR; /* malformed! */
}
@@ -127,6 +134,7 @@
mdSize);
if (fi.meta == NULL) {
ECRS_freeUri(fi.uri);
+ GE_BREAK(ectx, 0);
return SYSERR; /* malformed !*/
}
pos += mdSize;
Modified: GNUnet/src/applications/fs/tools/gnunet-download.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-download.c 2006-12-29 04:34:01 UTC
(rev 4093)
+++ GNUnet/src/applications/fs/tools/gnunet-download.c 2006-12-29 05:12:33 UTC
(rev 4094)
@@ -37,6 +37,8 @@
static int do_recursive;
+static int do_directory;
+
static char * cfgFilename = DEFAULT_CLIENT_CONFIG_FILE;
static char * filename;
@@ -65,6 +67,9 @@
gettext_noop("set the desired LEVEL of sender-anonymity"),
1, &gnunet_getopt_configure_set_uint, &anonymity },
COMMAND_LINE_OPTION_CFG_FILE(&cfgFilename), /* -c */
+ { 'd', "directory", NULL,
+ gettext_noop("download a GNUnet directory that has already been
downloaded. Requires that a filename of an existing file is specified instead
of the URI. The download will only download the top-level files in the
directory unless the `-R' option is also specified."),
+ 0, &gnunet_getopt_configure_set_one, &do_directory },
COMMAND_LINE_OPTION_HELP(gettext_noop("Download files from GNUnet.")), /* -h
*/
COMMAND_LINE_OPTION_HOSTNAME, /* -H */
COMMAND_LINE_OPTION_LOGGING, /* -L */
@@ -142,6 +147,51 @@
return NULL;
}
+static int
+directoryIterator(const ECRS_FileInfo * fi,
+ const HashCode512 * key,
+ int isRoot,
+ void * cls) {
+ struct FSUI_Context * ctx = cls;
+ struct ECRS_MetaData * meta;
+ char * fn;
+ char * f;
+
+ f = ECRS_getFirstFromMetaData(fi->meta,
+ EXTRACTOR_FILENAME,
+ EXTRACTOR_TITLE,
+ EXTRACTOR_ARTIST,
+ EXTRACTOR_AUTHOR,
+ EXTRACTOR_PUBLISHER,
+ EXTRACTOR_CREATOR,
+ EXTRACTOR_PRODUCER,
+ EXTRACTOR_UNKNOWN,
+ -1);
+ if (f == NULL)
+ f = STRDUP(_("no name given"));
+ fn = MALLOC(strlen(filename) + strlen(f) + 4);
+ strcpy(fn, filename);
+ strcat(fn, "/");
+ strcat(fn, f);
+ if (verbose > 1)
+ printf(_("Starting download `%s'\n"),
+ f);
+ FREE(f);
+ meta = ECRS_createMetaData();
+ FSUI_startDownload(ctx,
+ anonymity,
+ do_recursive,
+ fi->uri,
+ meta,
+ fn,
+ NULL,
+ NULL);
+ ECRS_freeMetaData(meta);
+ FREE(fn);
+ return OK;
+}
+
+
/**
* Main function to download files from GNUnet.
*
@@ -184,18 +234,21 @@
9999,
0,
&verbose);
- uri = ECRS_stringToUri(ectx,
- argv[i]);
- if ( (NULL == uri) ||
- (! (ECRS_isLocationUri(uri) ||
- ECRS_isFileUri(uri)) ) ) {
- GE_LOG(ectx,
- GE_ERROR | GE_BULK | GE_USER,
- _("URI `%s' invalid for gnunet-download.\n"),
- argv[i]);
- errorCode = -1;
- goto quit;
- }
+ uri = NULL;
+ if (! do_directory) {
+ uri = ECRS_stringToUri(ectx,
+ argv[i]);
+ if ( (NULL == uri) ||
+ (! (ECRS_isLocationUri(uri) ||
+ ECRS_isFileUri(uri)) ) ) {
+ GE_LOG(ectx,
+ GE_ERROR | GE_BULK | GE_USER,
+ _("URI `%s' invalid for gnunet-download.\n"),
+ argv[i]);
+ errorCode = -1;
+ goto quit;
+ }
+ }
try_rename = NO;
if (filename == NULL) {
@@ -208,7 +261,7 @@
strlen(ECRS_FILE_INFIX)]);
GE_LOG(ectx,
GE_DEBUG | GE_REQUEST | GE_USER,
- "No filename specified, using `%s' instead (for now).\n",
+ _("No filename specified, using `%s' instead (for now).\n"),
filename);
try_rename = YES;
}
@@ -223,20 +276,77 @@
NULL);
start_time = get_time();
errorCode = 1;
- meta = ECRS_createMetaData();
- dl = FSUI_startDownload(ctx,
- anonymity,
- do_recursive,
- uri,
- meta,
- filename,
- NULL,
- NULL);
- ECRS_freeMetaData(meta);
- if (dl == NULL) {
- FSUI_stop(ctx);
- MUTEX_DESTROY(lock);
- goto quit;
+ if (do_directory) {
+ void * data;
+ struct stat sbuf;
+ int fd;
+ int count;
+ char * efn;
+
+ fd = -1;
+ efn = string_expandFileName(ectx, argv[i]);
+ data = NULL;
+ if ( (0 != STAT(efn,
+ &sbuf)) ||
+ (! S_ISREG(sbuf.st_mode)) ||
+ (0 != ACCESS(efn,
+ R_OK)) ||
+ (-1 == (fd = disk_file_open(ectx,
+ efn,
+ O_LARGEFILE | O_RDONLY)) ) ||
+ (MAP_FAILED == (data = MMAP(NULL,
+ sbuf.st_size,
+ PROT_READ,
+ MAP_SHARED,
+ fd,
+ 0))) ) {
+ if (fd != -1)
+ CLOSE(fd);
+ GE_LOG(ectx,
+ GE_ERROR | GE_IMMEDIATE | GE_USER,
+ _("Could not access gnunet-directory file `%s'\n"),
+ efn);
+ FSUI_stop(ctx);
+ MUTEX_DESTROY(lock);
+ FREE(efn);
+ goto quit;
+ }
+ meta = ECRS_createMetaData();
+ count = ECRS_listDirectory(ectx,
+ data,
+ sbuf.st_size,
+ &meta,
+ &directoryIterator,
+ ctx);
+ ECRS_freeMetaData(meta);
+ MUNMAP(data, sbuf.st_size);
+ CLOSE(fd);
+ FREE(efn);
+ if (verbose > 0) {
+ if (count > 0)
+ printf(_("Downloading %d files from directory `%s'.\n"),
+ count,
+ argv[i]);
+ else
+ printf(_("Did not find any files in directory `%s'\n"),
+ argv[i]);
+ }
+ } else {
+ meta = ECRS_createMetaData();
+ dl = FSUI_startDownload(ctx,
+ anonymity,
+ do_recursive,
+ uri,
+ meta,
+ filename,
+ NULL,
+ NULL);
+ ECRS_freeMetaData(meta);
+ if (dl == NULL) {
+ FSUI_stop(ctx);
+ MUTEX_DESTROY(lock);
+ goto quit;
+ }
}
GNUNET_SHUTDOWN_WAITFOR();
if (errorCode == 1) {
@@ -265,7 +375,8 @@
}
}
FREE(filename);
- ECRS_freeUri(uri);
+ if (uri != NULL)
+ ECRS_freeUri(uri);
quit:
GNUNET_fini(ectx, cfg);
return errorCode;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r4094 - in GNUnet: . doc/man src/applications/fs/ecrs src/applications/fs/tools,
grothoff <=